LCOV - code coverage report
Current view: top level - src/backend/parser - gram.y (source / functions) Hit Total Coverage
Test: PostgreSQL 19devel Lines: 6791 7500 90.5 %
Date: 2025-07-21 05:18:46 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             : 
     322             : %type <node>  alter_column_default opclass_item opclass_drop alter_using
     323             : %type <ival>  add_drop opt_asc_desc opt_nulls_order
     324             : 
     325             : %type <node>  alter_table_cmd alter_type_cmd opt_collate_clause
     326             :        replica_identity partition_cmd index_partition_cmd
     327             : %type <list>  alter_table_cmds alter_type_cmds
     328             : %type <list>    alter_identity_column_option_list
     329             : %type <defelt>  alter_identity_column_option
     330             : %type <node>  set_statistics_value
     331             : %type <str>       set_access_method_name
     332             : 
     333             : %type <list>  createdb_opt_list createdb_opt_items copy_opt_list
     334             :                 transaction_mode_list
     335             :                 create_extension_opt_list alter_extension_opt_list
     336             : %type <defelt>    createdb_opt_item copy_opt_item
     337             :                 transaction_mode_item
     338             :                 create_extension_opt_item alter_extension_opt_item
     339             : 
     340             : %type <ival>  opt_lock lock_type cast_context
     341             : %type <str>       utility_option_name
     342             : %type <defelt>    utility_option_elem
     343             : %type <list>  utility_option_list
     344             : %type <node>  utility_option_arg
     345             : %type <defelt>    drop_option
     346             : %type <boolean>   opt_or_replace opt_no
     347             :                 opt_grant_grant_option
     348             :                 opt_nowait opt_if_exists opt_with_data
     349             :                 opt_transaction_chain
     350             : %type <list>  grant_role_opt_list
     351             : %type <defelt>    grant_role_opt
     352             : %type <node>  grant_role_opt_value
     353             : %type <ival>  opt_nowait_or_skip
     354             : 
     355             : %type <list>  OptRoleList AlterOptRoleList
     356             : %type <defelt>    CreateOptRoleElem AlterOptRoleElem
     357             : 
     358             : %type <str>       opt_type
     359             : %type <str>       foreign_server_version opt_foreign_server_version
     360             : %type <str>       opt_in_database
     361             : 
     362             : %type <str>       parameter_name
     363             : %type <list>  OptSchemaEltList parameter_name_list
     364             : 
     365             : %type <chr>       am_type
     366             : 
     367             : %type <boolean> TriggerForSpec TriggerForType
     368             : %type <ival>  TriggerActionTime
     369             : %type <list>  TriggerEvents TriggerOneEvent
     370             : %type <node>  TriggerFuncArg
     371             : %type <node>  TriggerWhen
     372             : %type <str>       TransitionRelName
     373             : %type <boolean>   TransitionRowOrTable TransitionOldOrNew
     374             : %type <node>  TriggerTransition
     375             : 
     376             : %type <list>  event_trigger_when_list event_trigger_value_list
     377             : %type <defelt>    event_trigger_when_item
     378             : %type <chr>       enable_trigger
     379             : 
     380             : %type <str>       copy_file_name
     381             :                 access_method_clause attr_name
     382             :                 table_access_method_clause name cursor_name file_name
     383             :                 cluster_index_specification
     384             : 
     385             : %type <list>  func_name handler_name qual_Op qual_all_Op subquery_Op
     386             :                 opt_inline_handler opt_validator validator_clause
     387             :                 opt_collate
     388             : 
     389             : %type <range> qualified_name insert_target OptConstrFromTable
     390             : 
     391             : %type <str>       all_Op MathOp
     392             : 
     393             : %type <str>       row_security_cmd RowSecurityDefaultForCmd
     394             : %type <boolean> RowSecurityDefaultPermissive
     395             : %type <node>  RowSecurityOptionalWithCheck RowSecurityOptionalExpr
     396             : %type <list>  RowSecurityDefaultToRole RowSecurityOptionalToRole
     397             : 
     398             : %type <str>       iso_level opt_encoding
     399             : %type <rolespec> grantee
     400             : %type <list>  grantee_list
     401             : %type <accesspriv> privilege
     402             : %type <list>  privileges privilege_list
     403             : %type <privtarget> privilege_target
     404             : %type <objwithargs> function_with_argtypes aggregate_with_argtypes operator_with_argtypes
     405             : %type <list>  function_with_argtypes_list aggregate_with_argtypes_list operator_with_argtypes_list
     406             : %type <ival>  defacl_privilege_target
     407             : %type <defelt>    DefACLOption
     408             : %type <list>  DefACLOptionList
     409             : %type <ival>  import_qualification_type
     410             : %type <importqual> import_qualification
     411             : %type <node>  vacuum_relation
     412             : %type <selectlimit> opt_select_limit select_limit limit_clause
     413             : 
     414             : %type <list>  parse_toplevel stmtmulti routine_body_stmt_list
     415             :                 OptTableElementList TableElementList OptInherit definition
     416             :                 OptTypedTableElementList TypedTableElementList
     417             :                 reloptions opt_reloptions
     418             :                 OptWith opt_definition func_args func_args_list
     419             :                 func_args_with_defaults func_args_with_defaults_list
     420             :                 aggr_args aggr_args_list
     421             :                 func_as createfunc_opt_list opt_createfunc_opt_list alterfunc_opt_list
     422             :                 old_aggr_definition old_aggr_list
     423             :                 oper_argtypes RuleActionList RuleActionMulti
     424             :                 opt_column_list columnList opt_name_list
     425             :                 sort_clause opt_sort_clause sortby_list index_params
     426             :                 stats_params
     427             :                 opt_include opt_c_include index_including_params
     428             :                 name_list role_list from_clause from_list opt_array_bounds
     429             :                 qualified_name_list any_name any_name_list type_name_list
     430             :                 any_operator expr_list attrs
     431             :                 distinct_clause opt_distinct_clause
     432             :                 target_list opt_target_list insert_column_list set_target_list
     433             :                 merge_values_clause
     434             :                 set_clause_list set_clause
     435             :                 def_list operator_def_list indirection opt_indirection
     436             :                 reloption_list TriggerFuncArgs opclass_item_list opclass_drop_list
     437             :                 opclass_purpose opt_opfamily transaction_mode_list_or_empty
     438             :                 OptTableFuncElementList TableFuncElementList opt_type_modifiers
     439             :                 prep_type_clause
     440             :                 execute_param_clause using_clause
     441             :                 returning_with_clause returning_options
     442             :                 opt_enum_val_list enum_val_list table_func_column_list
     443             :                 create_generic_options alter_generic_options
     444             :                 relation_expr_list dostmt_opt_list
     445             :                 transform_element_list transform_type_list
     446             :                 TriggerTransitions TriggerReferencing
     447             :                 vacuum_relation_list opt_vacuum_relation_list
     448             :                 drop_option_list pub_obj_list
     449             : 
     450             : %type <retclause> returning_clause
     451             : %type <node>  returning_option
     452             : %type <retoptionkind> returning_option_kind
     453             : %type <node>  opt_routine_body
     454             : %type <groupclause> group_clause
     455             : %type <list>  group_by_list
     456             : %type <node>  group_by_item empty_grouping_set rollup_clause cube_clause
     457             : %type <node>  grouping_sets_clause
     458             : 
     459             : %type <list>  opt_fdw_options fdw_options
     460             : %type <defelt>    fdw_option
     461             : 
     462             : %type <range> OptTempTableName
     463             : %type <into>  into_clause create_as_target create_mv_target
     464             : 
     465             : %type <defelt>    createfunc_opt_item common_func_opt_item dostmt_opt_item
     466             : %type <fun_param> func_arg func_arg_with_default table_func_column aggr_arg
     467             : %type <fun_param_mode> arg_class
     468             : %type <typnam>    func_return func_type
     469             : 
     470             : %type <boolean>  opt_trusted opt_restart_seqs
     471             : %type <ival>   OptTemp
     472             : %type <ival>   OptNoLog
     473             : %type <oncommit> OnCommitOption
     474             : 
     475             : %type <ival>  for_locking_strength
     476             : %type <node>  for_locking_item
     477             : %type <list>  for_locking_clause opt_for_locking_clause for_locking_items
     478             : %type <list>  locked_rels_list
     479             : %type <setquantifier> set_quantifier
     480             : 
     481             : %type <node>  join_qual
     482             : %type <jtype> join_type
     483             : 
     484             : %type <list>  extract_list overlay_list position_list
     485             : %type <list>  substr_list trim_list
     486             : %type <list>  opt_interval interval_second
     487             : %type <str>       unicode_normal_form
     488             : 
     489             : %type <boolean> opt_instead
     490             : %type <boolean> opt_unique opt_verbose opt_full
     491             : %type <boolean> opt_freeze opt_analyze opt_default
     492             : %type <defelt>    opt_binary copy_delimiter
     493             : 
     494             : %type <boolean> copy_from opt_program
     495             : 
     496             : %type <ival>  event cursor_options opt_hold opt_set_data
     497             : %type <objtype>   object_type_any_name object_type_name object_type_name_on_any_name
     498             :                 drop_type_name
     499             : 
     500             : %type <node>  fetch_args select_limit_value
     501             :                 offset_clause select_offset_value
     502             :                 select_fetch_first_value I_or_F_const
     503             : %type <ival>  row_or_rows first_or_next
     504             : 
     505             : %type <list>  OptSeqOptList SeqOptList OptParenthesizedSeqOptList
     506             : %type <defelt>    SeqOptElem
     507             : 
     508             : %type <istmt> insert_rest
     509             : %type <infer> opt_conf_expr
     510             : %type <onconflict> opt_on_conflict
     511             : %type <mergewhen> merge_insert merge_update merge_delete
     512             : 
     513             : %type <mergematch> merge_when_tgt_matched merge_when_tgt_not_matched
     514             : %type <node>  merge_when_clause opt_merge_when_condition
     515             : %type <list>  merge_when_list
     516             : 
     517             : %type <vsetstmt> generic_set set_rest set_rest_more generic_reset reset_rest
     518             :                  SetResetClause FunctionSetResetClause
     519             : 
     520             : %type <node>  TableElement TypedTableElement ConstraintElem DomainConstraintElem TableFuncElement
     521             : %type <node>  columnDef columnOptions optionalPeriodName
     522             : %type <defelt>    def_elem reloption_elem old_aggr_elem operator_def_elem
     523             : %type <node>  def_arg columnElem where_clause where_or_current_clause
     524             :                 a_expr b_expr c_expr AexprConst indirection_el opt_slice_bound
     525             :                 columnref having_clause func_table xmltable array_expr
     526             :                 OptWhereClause operator_def_arg
     527             : %type <list>  opt_column_and_period_list
     528             : %type <list>  rowsfrom_item rowsfrom_list opt_col_def_list
     529             : %type <boolean> opt_ordinality opt_without_overlaps
     530             : %type <list>  ExclusionConstraintList ExclusionConstraintElem
     531             : %type <list>  func_arg_list func_arg_list_opt
     532             : %type <node>  func_arg_expr
     533             : %type <list>  row explicit_row implicit_row type_list array_expr_list
     534             : %type <node>  case_expr case_arg when_clause case_default
     535             : %type <list>  when_clause_list
     536             : %type <node>  opt_search_clause opt_cycle_clause
     537             : %type <ival>  sub_type opt_materialized
     538             : %type <node>  NumericOnly
     539             : %type <list>  NumericOnly_list
     540             : %type <alias> alias_clause opt_alias_clause opt_alias_clause_for_join_using
     541             : %type <list>  func_alias_clause
     542             : %type <sortby>    sortby
     543             : %type <ielem> index_elem index_elem_options
     544             : %type <selem> stats_param
     545             : %type <node>  table_ref
     546             : %type <jexpr> joined_table
     547             : %type <range> relation_expr
     548             : %type <range> extended_relation_expr
     549             : %type <range> relation_expr_opt_alias
     550             : %type <node>  tablesample_clause opt_repeatable_clause
     551             : %type <target>    target_el set_target insert_column_item
     552             : 
     553             : %type <str>       generic_option_name
     554             : %type <node>  generic_option_arg
     555             : %type <defelt>    generic_option_elem alter_generic_option_elem
     556             : %type <list>  generic_option_list alter_generic_option_list
     557             : 
     558             : %type <ival>  reindex_target_relation reindex_target_all
     559             : %type <list>  opt_reindex_option_list
     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      739612 :                 pg_yyget_extra(yyscanner)->parsetree = $1;
     918             :                 (void) yynerrs;     /* suppress compiler warning */
     919             :             }
     920             :             | MODE_TYPE_NAME Typename
     921             :             {
     922        9650 :                 pg_yyget_extra(yyscanner)->parsetree = list_make1($2);
     923             :             }
     924             :             | MODE_PLPGSQL_EXPR PLpgSQL_Expr
     925             :             {
     926       33000 :                 pg_yyget_extra(yyscanner)->parsetree =
     927       33000 :                     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      590328 :                     if ($1 != NIL)
     964             :                     {
     965             :                         /* update length of previous stmt */
     966      589764 :                         updateRawStmtEnd(llast_node(RawStmt, $1), @2);
     967             :                     }
     968      590328 :                     if ($3 != NULL)
     969       56056 :                         $$ = lappend($1, makeRawStmt($3, @3));
     970             :                     else
     971      534272 :                         $$ = $1;
     972             :                 }
     973             :             | toplevel_stmt
     974             :                 {
     975      739620 :                     if ($1 != NULL)
     976      738360 :                         $$ = list_make1(makeRawStmt($1, @1));
     977             :                     else
     978        1260 :                         $$ = 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      535550 :                 { $$ = NULL; }
    1118             :         ;
    1119             : 
    1120             : /*
    1121             :  * Generic supporting productions for DDL
    1122             :  */
    1123             : opt_single_name:
    1124        5718 :             ColId                           { $$ = $1; }
    1125        1530 :             | /* EMPTY */                   { $$ = NULL; }
    1126             :         ;
    1127             : 
    1128             : opt_qualified_name:
    1129        1930 :             any_name                        { $$ = $1; }
    1130       15800 :             | /*EMPTY*/                     { $$ = NIL; }
    1131             :         ;
    1132             : 
    1133             : opt_concurrently:
    1134        1102 :             CONCURRENTLY                    { $$ = true; }
    1135        7896 :             | /*EMPTY*/                     { $$ = false; }
    1136             :         ;
    1137             : 
    1138             : opt_drop_behavior:
    1139        1960 :             CASCADE                         { $$ = DROP_CASCADE; }
    1140         170 :             | RESTRICT                      { $$ = DROP_RESTRICT; }
    1141       40226 :             | /* EMPTY */                   { $$ = DROP_RESTRICT; /* default */ }
    1142             :         ;
    1143             : 
    1144             : /*****************************************************************************
    1145             :  *
    1146             :  * CALL statement
    1147             :  *
    1148             :  *****************************************************************************/
    1149             : 
    1150             : CallStmt:   CALL func_application
    1151             :                 {
    1152         620 :                     CallStmt   *n = makeNode(CallStmt);
    1153             : 
    1154         620 :                     n->funccall = castNode(FuncCall, $2);
    1155         620 :                     $$ = (Node *) n;
    1156             :                 }
    1157             :         ;
    1158             : 
    1159             : /*****************************************************************************
    1160             :  *
    1161             :  * Create a new Postgres DBMS role
    1162             :  *
    1163             :  *****************************************************************************/
    1164             : 
    1165             : CreateRoleStmt:
    1166             :             CREATE ROLE RoleId opt_with OptRoleList
    1167             :                 {
    1168        1368 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1169             : 
    1170        1368 :                     n->stmt_type = ROLESTMT_ROLE;
    1171        1368 :                     n->role = $3;
    1172        1368 :                     n->options = $5;
    1173        1368 :                     $$ = (Node *) n;
    1174             :                 }
    1175             :         ;
    1176             : 
    1177             : 
    1178             : opt_with:   WITH
    1179             :             | WITH_LA
    1180             :             | /*EMPTY*/
    1181             :         ;
    1182             : 
    1183             : /*
    1184             :  * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
    1185             :  * for backwards compatibility).  Note: the only option required by SQL99
    1186             :  * is "WITH ADMIN name".
    1187             :  */
    1188             : OptRoleList:
    1189        1168 :             OptRoleList CreateOptRoleElem           { $$ = lappend($1, $2); }
    1190        1848 :             | /* EMPTY */                           { $$ = NIL; }
    1191             :         ;
    1192             : 
    1193             : AlterOptRoleList:
    1194         658 :             AlterOptRoleList AlterOptRoleElem       { $$ = lappend($1, $2); }
    1195         418 :             | /* EMPTY */                           { $$ = NIL; }
    1196             :         ;
    1197             : 
    1198             : AlterOptRoleElem:
    1199             :             PASSWORD Sconst
    1200             :                 {
    1201         188 :                     $$ = makeDefElem("password",
    1202         188 :                                      (Node *) makeString($2), @1);
    1203             :                 }
    1204             :             | PASSWORD NULL_P
    1205             :                 {
    1206          12 :                     $$ = makeDefElem("password", NULL, @1);
    1207             :                 }
    1208             :             | ENCRYPTED PASSWORD Sconst
    1209             :                 {
    1210             :                     /*
    1211             :                      * These days, passwords are always stored in encrypted
    1212             :                      * form, so there is no difference between PASSWORD and
    1213             :                      * ENCRYPTED PASSWORD.
    1214             :                      */
    1215          18 :                     $$ = makeDefElem("password",
    1216          18 :                                      (Node *) makeString($3), @1);
    1217             :                 }
    1218             :             | UNENCRYPTED PASSWORD Sconst
    1219             :                 {
    1220           0 :                     ereport(ERROR,
    1221             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1222             :                              errmsg("UNENCRYPTED PASSWORD is no longer supported"),
    1223             :                              errhint("Remove UNENCRYPTED to store the password in encrypted form instead."),
    1224             :                              parser_errposition(@1)));
    1225             :                 }
    1226             :             | INHERIT
    1227             :                 {
    1228          92 :                     $$ = makeDefElem("inherit", (Node *) makeBoolean(true), @1);
    1229             :                 }
    1230             :             | CONNECTION LIMIT SignedIconst
    1231             :                 {
    1232          26 :                     $$ = makeDefElem("connectionlimit", (Node *) makeInteger($3), @1);
    1233             :                 }
    1234             :             | VALID UNTIL Sconst
    1235             :                 {
    1236           2 :                     $$ = makeDefElem("validUntil", (Node *) makeString($3), @1);
    1237             :                 }
    1238             :         /*  Supported but not documented for roles, for use by ALTER GROUP. */
    1239             :             | USER role_list
    1240             :                 {
    1241           6 :                     $$ = makeDefElem("rolemembers", (Node *) $2, @1);
    1242             :                 }
    1243             :             | IDENT
    1244             :                 {
    1245             :                     /*
    1246             :                      * We handle identifiers that aren't parser keywords with
    1247             :                      * the following special-case codes, to avoid bloating the
    1248             :                      * size of the main parser.
    1249             :                      */
    1250        1334 :                     if (strcmp($1, "superuser") == 0)
    1251         194 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(true), @1);
    1252        1140 :                     else if (strcmp($1, "nosuperuser") == 0)
    1253          96 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(false), @1);
    1254        1044 :                     else if (strcmp($1, "createrole") == 0)
    1255         102 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(true), @1);
    1256         942 :                     else if (strcmp($1, "nocreaterole") == 0)
    1257          34 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(false), @1);
    1258         908 :                     else if (strcmp($1, "replication") == 0)
    1259         132 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(true), @1);
    1260         776 :                     else if (strcmp($1, "noreplication") == 0)
    1261          92 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(false), @1);
    1262         684 :                     else if (strcmp($1, "createdb") == 0)
    1263          92 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(true), @1);
    1264         592 :                     else if (strcmp($1, "nocreatedb") == 0)
    1265          42 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(false), @1);
    1266         550 :                     else if (strcmp($1, "login") == 0)
    1267         282 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(true), @1);
    1268         268 :                     else if (strcmp($1, "nologin") == 0)
    1269          86 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(false), @1);
    1270         182 :                     else if (strcmp($1, "bypassrls") == 0)
    1271          82 :                         $$ = makeDefElem("bypassrls", (Node *) makeBoolean(true), @1);
    1272         100 :                     else if (strcmp($1, "nobypassrls") == 0)
    1273          64 :                         $$ = makeDefElem("bypassrls", (Node *) makeBoolean(false), @1);
    1274          36 :                     else if (strcmp($1, "noinherit") == 0)
    1275             :                     {
    1276             :                         /*
    1277             :                          * Note that INHERIT is a keyword, so it's handled by main parser, but
    1278             :                          * NOINHERIT is handled here.
    1279             :                          */
    1280          36 :                         $$ = makeDefElem("inherit", (Node *) makeBoolean(false), @1);
    1281             :                     }
    1282             :                     else
    1283           0 :                         ereport(ERROR,
    1284             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    1285             :                                  errmsg("unrecognized role option \"%s\"", $1),
    1286             :                                      parser_errposition(@1)));
    1287             :                 }
    1288             :         ;
    1289             : 
    1290             : CreateOptRoleElem:
    1291        1020 :             AlterOptRoleElem            { $$ = $1; }
    1292             :             /* The following are not supported by ALTER ROLE/USER/GROUP */
    1293             :             | SYSID Iconst
    1294             :                 {
    1295           6 :                     $$ = makeDefElem("sysid", (Node *) makeInteger($2), @1);
    1296             :                 }
    1297             :             | ADMIN role_list
    1298             :                 {
    1299          22 :                     $$ = makeDefElem("adminmembers", (Node *) $2, @1);
    1300             :                 }
    1301             :             | ROLE role_list
    1302             :                 {
    1303          22 :                     $$ = makeDefElem("rolemembers", (Node *) $2, @1);
    1304             :                 }
    1305             :             | IN_P ROLE role_list
    1306             :                 {
    1307          98 :                     $$ = makeDefElem("addroleto", (Node *) $3, @1);
    1308             :                 }
    1309             :             | IN_P GROUP_P role_list
    1310             :                 {
    1311           0 :                     $$ = makeDefElem("addroleto", (Node *) $3, @1);
    1312             :                 }
    1313             :         ;
    1314             : 
    1315             : 
    1316             : /*****************************************************************************
    1317             :  *
    1318             :  * Create a new Postgres DBMS user (role with implied login ability)
    1319             :  *
    1320             :  *****************************************************************************/
    1321             : 
    1322             : CreateUserStmt:
    1323             :             CREATE USER RoleId opt_with OptRoleList
    1324             :                 {
    1325         456 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1326             : 
    1327         456 :                     n->stmt_type = ROLESTMT_USER;
    1328         456 :                     n->role = $3;
    1329         456 :                     n->options = $5;
    1330         456 :                     $$ = (Node *) n;
    1331             :                 }
    1332             :         ;
    1333             : 
    1334             : 
    1335             : /*****************************************************************************
    1336             :  *
    1337             :  * Alter a postgresql DBMS role
    1338             :  *
    1339             :  *****************************************************************************/
    1340             : 
    1341             : AlterRoleStmt:
    1342             :             ALTER ROLE RoleSpec opt_with AlterOptRoleList
    1343             :                  {
    1344         326 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1345             : 
    1346         326 :                     n->role = $3;
    1347         326 :                     n->action = +1;  /* add, if there are members */
    1348         326 :                     n->options = $5;
    1349         326 :                     $$ = (Node *) n;
    1350             :                  }
    1351             :             | ALTER USER RoleSpec opt_with AlterOptRoleList
    1352             :                  {
    1353          92 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1354             : 
    1355          92 :                     n->role = $3;
    1356          92 :                     n->action = +1;  /* add, if there are members */
    1357          92 :                     n->options = $5;
    1358          92 :                     $$ = (Node *) n;
    1359             :                  }
    1360             :         ;
    1361             : 
    1362             : opt_in_database:
    1363          86 :                /* EMPTY */                  { $$ = NULL; }
    1364           0 :             | IN_P DATABASE name    { $$ = $3; }
    1365             :         ;
    1366             : 
    1367             : AlterRoleSetStmt:
    1368             :             ALTER ROLE RoleSpec opt_in_database SetResetClause
    1369             :                 {
    1370          48 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1371             : 
    1372          48 :                     n->role = $3;
    1373          48 :                     n->database = $4;
    1374          48 :                     n->setstmt = $5;
    1375          48 :                     $$ = (Node *) n;
    1376             :                 }
    1377             :             | ALTER ROLE ALL opt_in_database SetResetClause
    1378             :                 {
    1379           4 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1380             : 
    1381           4 :                     n->role = NULL;
    1382           4 :                     n->database = $4;
    1383           4 :                     n->setstmt = $5;
    1384           4 :                     $$ = (Node *) n;
    1385             :                 }
    1386             :             | ALTER USER RoleSpec opt_in_database SetResetClause
    1387             :                 {
    1388          26 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1389             : 
    1390          26 :                     n->role = $3;
    1391          26 :                     n->database = $4;
    1392          26 :                     n->setstmt = $5;
    1393          26 :                     $$ = (Node *) n;
    1394             :                 }
    1395             :             | ALTER USER ALL opt_in_database SetResetClause
    1396             :                 {
    1397           4 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1398             : 
    1399           4 :                     n->role = NULL;
    1400           4 :                     n->database = $4;
    1401           4 :                     n->setstmt = $5;
    1402           4 :                     $$ = (Node *) n;
    1403             :                 }
    1404             :         ;
    1405             : 
    1406             : 
    1407             : /*****************************************************************************
    1408             :  *
    1409             :  * Drop a postgresql DBMS role
    1410             :  *
    1411             :  * XXX Ideally this would have CASCADE/RESTRICT options, but a role
    1412             :  * might own objects in multiple databases, and there is presently no way to
    1413             :  * implement cascading to other databases.  So we always behave as RESTRICT.
    1414             :  *****************************************************************************/
    1415             : 
    1416             : DropRoleStmt:
    1417             :             DROP ROLE role_list
    1418             :                 {
    1419        1104 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1420             : 
    1421        1104 :                     n->missing_ok = false;
    1422        1104 :                     n->roles = $3;
    1423        1104 :                     $$ = (Node *) n;
    1424             :                 }
    1425             :             | DROP ROLE IF_P EXISTS role_list
    1426             :                 {
    1427         134 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1428             : 
    1429         134 :                     n->missing_ok = true;
    1430         134 :                     n->roles = $5;
    1431         134 :                     $$ = (Node *) n;
    1432             :                 }
    1433             :             | DROP USER role_list
    1434             :                 {
    1435         406 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1436             : 
    1437         406 :                     n->missing_ok = false;
    1438         406 :                     n->roles = $3;
    1439         406 :                     $$ = (Node *) n;
    1440             :                 }
    1441             :             | DROP USER IF_P EXISTS role_list
    1442             :                 {
    1443          36 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1444             : 
    1445          36 :                     n->roles = $5;
    1446          36 :                     n->missing_ok = true;
    1447          36 :                     $$ = (Node *) n;
    1448             :                 }
    1449             :             | DROP GROUP_P role_list
    1450             :                 {
    1451          36 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1452             : 
    1453          36 :                     n->missing_ok = false;
    1454          36 :                     n->roles = $3;
    1455          36 :                     $$ = (Node *) n;
    1456             :                 }
    1457             :             | DROP GROUP_P IF_P EXISTS role_list
    1458             :                 {
    1459           6 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1460             : 
    1461           6 :                     n->missing_ok = true;
    1462           6 :                     n->roles = $5;
    1463           6 :                     $$ = (Node *) n;
    1464             :                 }
    1465             :             ;
    1466             : 
    1467             : 
    1468             : /*****************************************************************************
    1469             :  *
    1470             :  * Create a postgresql group (role without login ability)
    1471             :  *
    1472             :  *****************************************************************************/
    1473             : 
    1474             : CreateGroupStmt:
    1475             :             CREATE GROUP_P RoleId opt_with OptRoleList
    1476             :                 {
    1477          24 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1478             : 
    1479          24 :                     n->stmt_type = ROLESTMT_GROUP;
    1480          24 :                     n->role = $3;
    1481          24 :                     n->options = $5;
    1482          24 :                     $$ = (Node *) n;
    1483             :                 }
    1484             :         ;
    1485             : 
    1486             : 
    1487             : /*****************************************************************************
    1488             :  *
    1489             :  * Alter a postgresql group
    1490             :  *
    1491             :  *****************************************************************************/
    1492             : 
    1493             : AlterGroupStmt:
    1494             :             ALTER GROUP_P RoleSpec add_drop USER role_list
    1495             :                 {
    1496          42 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1497             : 
    1498          42 :                     n->role = $3;
    1499          42 :                     n->action = $4;
    1500          42 :                     n->options = list_make1(makeDefElem("rolemembers",
    1501             :                                                         (Node *) $6, @6));
    1502          42 :                     $$ = (Node *) n;
    1503             :                 }
    1504             :         ;
    1505             : 
    1506          86 : add_drop:   ADD_P                                   { $$ = +1; }
    1507         198 :             | DROP                                  { $$ = -1; }
    1508             :         ;
    1509             : 
    1510             : 
    1511             : /*****************************************************************************
    1512             :  *
    1513             :  * Manipulate a schema
    1514             :  *
    1515             :  *****************************************************************************/
    1516             : 
    1517             : CreateSchemaStmt:
    1518             :             CREATE SCHEMA opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
    1519             :                 {
    1520         158 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1521             : 
    1522             :                     /* One can omit the schema name or the authorization id. */
    1523         158 :                     n->schemaname = $3;
    1524         158 :                     n->authrole = $5;
    1525         158 :                     n->schemaElts = $6;
    1526         158 :                     n->if_not_exists = false;
    1527         158 :                     $$ = (Node *) n;
    1528             :                 }
    1529             :             | CREATE SCHEMA ColId OptSchemaEltList
    1530             :                 {
    1531         888 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1532             : 
    1533             :                     /* ...but not both */
    1534         888 :                     n->schemaname = $3;
    1535         888 :                     n->authrole = NULL;
    1536         888 :                     n->schemaElts = $4;
    1537         888 :                     n->if_not_exists = false;
    1538         888 :                     $$ = (Node *) n;
    1539             :                 }
    1540             :             | CREATE SCHEMA IF_P NOT EXISTS opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
    1541             :                 {
    1542          18 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1543             : 
    1544             :                     /* schema name can be omitted here, too */
    1545          18 :                     n->schemaname = $6;
    1546          18 :                     n->authrole = $8;
    1547          18 :                     if ($9 != NIL)
    1548           0 :                         ereport(ERROR,
    1549             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1550             :                                  errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
    1551             :                                  parser_errposition(@9)));
    1552          18 :                     n->schemaElts = $9;
    1553          18 :                     n->if_not_exists = true;
    1554          18 :                     $$ = (Node *) n;
    1555             :                 }
    1556             :             | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
    1557             :                 {
    1558          34 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1559             : 
    1560             :                     /* ...but not here */
    1561          34 :                     n->schemaname = $6;
    1562          34 :                     n->authrole = NULL;
    1563          34 :                     if ($7 != NIL)
    1564           6 :                         ereport(ERROR,
    1565             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1566             :                                  errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
    1567             :                                  parser_errposition(@7)));
    1568          28 :                     n->schemaElts = $7;
    1569          28 :                     n->if_not_exists = true;
    1570          28 :                     $$ = (Node *) n;
    1571             :                 }
    1572             :         ;
    1573             : 
    1574             : OptSchemaEltList:
    1575             :             OptSchemaEltList schema_stmt
    1576             :                 {
    1577         546 :                     $$ = lappend($1, $2);
    1578             :                 }
    1579             :             | /* EMPTY */
    1580        1098 :                 { $$ = NIL; }
    1581             :         ;
    1582             : 
    1583             : /*
    1584             :  *  schema_stmt are the ones that can show up inside a CREATE SCHEMA
    1585             :  *  statement (in addition to by themselves).
    1586             :  */
    1587             : schema_stmt:
    1588             :             CreateStmt
    1589             :             | IndexStmt
    1590             :             | CreateSeqStmt
    1591             :             | CreateTrigStmt
    1592             :             | GrantStmt
    1593             :             | ViewStmt
    1594             :         ;
    1595             : 
    1596             : 
    1597             : /*****************************************************************************
    1598             :  *
    1599             :  * Set PG internal variable
    1600             :  *    SET name TO 'var_value'
    1601             :  * Include SQL syntax (thomas 1997-10-22):
    1602             :  *    SET TIME ZONE 'var_value'
    1603             :  *
    1604             :  *****************************************************************************/
    1605             : 
    1606             : VariableSetStmt:
    1607             :             SET set_rest
    1608             :                 {
    1609       22270 :                     VariableSetStmt *n = $2;
    1610             : 
    1611       22270 :                     n->is_local = false;
    1612       22270 :                     $$ = (Node *) n;
    1613             :                 }
    1614             :             | SET LOCAL set_rest
    1615             :                 {
    1616        1236 :                     VariableSetStmt *n = $3;
    1617             : 
    1618        1236 :                     n->is_local = true;
    1619        1236 :                     $$ = (Node *) n;
    1620             :                 }
    1621             :             | SET SESSION set_rest
    1622             :                 {
    1623          84 :                     VariableSetStmt *n = $3;
    1624             : 
    1625          84 :                     n->is_local = false;
    1626          84 :                     $$ = (Node *) n;
    1627             :                 }
    1628             :         ;
    1629             : 
    1630             : set_rest:
    1631             :             TRANSACTION transaction_mode_list
    1632             :                 {
    1633         682 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1634             : 
    1635         682 :                     n->kind = VAR_SET_MULTI;
    1636         682 :                     n->name = "TRANSACTION";
    1637         682 :                     n->args = $2;
    1638         682 :                     n->jumble_args = true;
    1639         682 :                     n->location = -1;
    1640         682 :                     $$ = n;
    1641             :                 }
    1642             :             | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
    1643             :                 {
    1644          18 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1645             : 
    1646          18 :                     n->kind = VAR_SET_MULTI;
    1647          18 :                     n->name = "SESSION CHARACTERISTICS";
    1648          18 :                     n->args = $5;
    1649          18 :                     n->jumble_args = true;
    1650          18 :                     n->location = -1;
    1651          18 :                     $$ = n;
    1652             :                 }
    1653             :             | set_rest_more
    1654             :             ;
    1655             : 
    1656             : generic_set:
    1657             :             var_name TO var_list
    1658             :                 {
    1659        5272 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1660             : 
    1661        5272 :                     n->kind = VAR_SET_VALUE;
    1662        5272 :                     n->name = $1;
    1663        5272 :                     n->args = $3;
    1664        5272 :                     n->location = @3;
    1665        5272 :                     $$ = n;
    1666             :                 }
    1667             :             | var_name '=' var_list
    1668             :                 {
    1669       15304 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1670             : 
    1671       15304 :                     n->kind = VAR_SET_VALUE;
    1672       15304 :                     n->name = $1;
    1673       15304 :                     n->args = $3;
    1674       15304 :                     n->location = @3;
    1675       15304 :                     $$ = n;
    1676             :                 }
    1677             :             | var_name TO DEFAULT
    1678             :                 {
    1679         136 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1680             : 
    1681         136 :                     n->kind = VAR_SET_DEFAULT;
    1682         136 :                     n->name = $1;
    1683         136 :                     n->location = -1;
    1684         136 :                     $$ = n;
    1685             :                 }
    1686             :             | var_name '=' DEFAULT
    1687             :                 {
    1688          10 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1689             : 
    1690          10 :                     n->kind = VAR_SET_DEFAULT;
    1691          10 :                     n->name = $1;
    1692          10 :                     n->location = -1;
    1693          10 :                     $$ = n;
    1694             :                 }
    1695             :         ;
    1696             : 
    1697             : set_rest_more:  /* Generic SET syntaxes: */
    1698       20596 :             generic_set                         {$$ = $1;}
    1699             :             | var_name FROM CURRENT_P
    1700             :                 {
    1701           4 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1702             : 
    1703           4 :                     n->kind = VAR_SET_CURRENT;
    1704           4 :                     n->name = $1;
    1705           4 :                     n->location = -1;
    1706           4 :                     $$ = n;
    1707             :                 }
    1708             :             /* Special syntaxes mandated by SQL standard: */
    1709             :             | TIME ZONE zone_value
    1710             :                 {
    1711         104 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1712             : 
    1713         104 :                     n->kind = VAR_SET_VALUE;
    1714         104 :                     n->name = "timezone";
    1715         104 :                     n->location = -1;
    1716         104 :                     n->jumble_args = true;
    1717         104 :                     if ($3 != NULL)
    1718          88 :                         n->args = list_make1($3);
    1719             :                     else
    1720          16 :                         n->kind = VAR_SET_DEFAULT;
    1721         104 :                     $$ = n;
    1722             :                 }
    1723             :             | CATALOG_P Sconst
    1724             :                 {
    1725           0 :                     ereport(ERROR,
    1726             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1727             :                              errmsg("current database cannot be changed"),
    1728             :                              parser_errposition(@2)));
    1729             :                     $$ = NULL; /*not reached*/
    1730             :                 }
    1731             :             | SCHEMA Sconst
    1732             :                 {
    1733           4 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1734             : 
    1735           4 :                     n->kind = VAR_SET_VALUE;
    1736           4 :                     n->name = "search_path";
    1737           4 :                     n->args = list_make1(makeStringConst($2, @2));
    1738           4 :                     n->location = @2;
    1739           4 :                     $$ = n;
    1740             :                 }
    1741             :             | NAMES opt_encoding
    1742             :                 {
    1743           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1744             : 
    1745           0 :                     n->kind = VAR_SET_VALUE;
    1746           0 :                     n->name = "client_encoding";
    1747           0 :                     n->location = @2;
    1748           0 :                     if ($2 != NULL)
    1749           0 :                         n->args = list_make1(makeStringConst($2, @2));
    1750             :                     else
    1751           0 :                         n->kind = VAR_SET_DEFAULT;
    1752           0 :                     $$ = n;
    1753             :                 }
    1754             :             | ROLE NonReservedWord_or_Sconst
    1755             :                 {
    1756         960 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1757             : 
    1758         960 :                     n->kind = VAR_SET_VALUE;
    1759         960 :                     n->name = "role";
    1760         960 :                     n->args = list_make1(makeStringConst($2, @2));
    1761         960 :                     n->location = @2;
    1762         960 :                     $$ = n;
    1763             :                 }
    1764             :             | SESSION AUTHORIZATION NonReservedWord_or_Sconst
    1765             :                 {
    1766        2550 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1767             : 
    1768        2550 :                     n->kind = VAR_SET_VALUE;
    1769        2550 :                     n->name = "session_authorization";
    1770        2550 :                     n->args = list_make1(makeStringConst($3, @3));
    1771        2550 :                     n->location = @3;
    1772        2550 :                     $$ = n;
    1773             :                 }
    1774             :             | SESSION AUTHORIZATION DEFAULT
    1775             :                 {
    1776           4 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1777             : 
    1778           4 :                     n->kind = VAR_SET_DEFAULT;
    1779           4 :                     n->name = "session_authorization";
    1780           4 :                     n->location = -1;
    1781           4 :                     $$ = n;
    1782             :                 }
    1783             :             | XML_P OPTION document_or_content
    1784             :                 {
    1785          16 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1786             : 
    1787          16 :                     n->kind = VAR_SET_VALUE;
    1788          16 :                     n->name = "xmloption";
    1789          16 :                     n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
    1790          16 :                     n->jumble_args = true;
    1791          16 :                     n->location = -1;
    1792          16 :                     $$ = n;
    1793             :                 }
    1794             :             /* Special syntaxes invented by PostgreSQL: */
    1795             :             | TRANSACTION SNAPSHOT Sconst
    1796             :                 {
    1797          48 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1798             : 
    1799          48 :                     n->kind = VAR_SET_MULTI;
    1800          48 :                     n->name = "TRANSACTION SNAPSHOT";
    1801          48 :                     n->args = list_make1(makeStringConst($3, @3));
    1802          48 :                     n->location = @3;
    1803          48 :                     $$ = n;
    1804             :                 }
    1805             :         ;
    1806             : 
    1807       25356 : var_name:   ColId                               { $$ = $1; }
    1808             :             | var_name '.' ColId
    1809         470 :                 { $$ = psprintf("%s.%s", $1, $3); }
    1810             :         ;
    1811             : 
    1812       20576 : var_list:   var_value                               { $$ = list_make1($1); }
    1813         188 :             | var_list ',' var_value                { $$ = lappend($1, $3); }
    1814             :         ;
    1815             : 
    1816             : var_value:  opt_boolean_or_string
    1817       15092 :                 { $$ = makeStringConst($1, @1); }
    1818             :             | NumericOnly
    1819        5672 :                 { $$ = makeAConst($1, @1); }
    1820             :         ;
    1821             : 
    1822           0 : iso_level:  READ UNCOMMITTED                        { $$ = "read uncommitted"; }
    1823         908 :             | READ COMMITTED                        { $$ = "read committed"; }
    1824        2680 :             | REPEATABLE READ                       { $$ = "repeatable read"; }
    1825        3196 :             | SERIALIZABLE                          { $$ = "serializable"; }
    1826             :         ;
    1827             : 
    1828             : opt_boolean_or_string:
    1829         682 :             TRUE_P                                  { $$ = "true"; }
    1830        1458 :             | FALSE_P                               { $$ = "false"; }
    1831        2212 :             | ON                                    { $$ = "on"; }
    1832             :             /*
    1833             :              * OFF is also accepted as a boolean value, but is handled by
    1834             :              * the NonReservedWord rule.  The action for booleans and strings
    1835             :              * is the same, so we don't need to distinguish them here.
    1836             :              */
    1837       30438 :             | NonReservedWord_or_Sconst             { $$ = $1; }
    1838             :         ;
    1839             : 
    1840             : /* Timezone values can be:
    1841             :  * - a string such as 'pst8pdt'
    1842             :  * - an identifier such as "pst8pdt"
    1843             :  * - an integer or floating point number
    1844             :  * - a time interval per SQL99
    1845             :  * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
    1846             :  * so use IDENT (meaning we reject anything that is a key word).
    1847             :  */
    1848             : zone_value:
    1849             :             Sconst
    1850             :                 {
    1851          60 :                     $$ = makeStringConst($1, @1);
    1852             :                 }
    1853             :             | IDENT
    1854             :                 {
    1855           4 :                     $$ = makeStringConst($1, @1);
    1856             :                 }
    1857             :             | ConstInterval Sconst opt_interval
    1858             :                 {
    1859           0 :                     TypeName   *t = $1;
    1860             : 
    1861           0 :                     if ($3 != NIL)
    1862             :                     {
    1863           0 :                         A_Const    *n = (A_Const *) linitial($3);
    1864             : 
    1865           0 :                         if ((n->val.ival.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
    1866           0 :                             ereport(ERROR,
    1867             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    1868             :                                      errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
    1869             :                                      parser_errposition(@3)));
    1870             :                     }
    1871           0 :                     t->typmods = $3;
    1872           0 :                     $$ = makeStringConstCast($2, @2, t);
    1873             :                 }
    1874             :             | ConstInterval '(' Iconst ')' Sconst
    1875             :                 {
    1876           0 :                     TypeName   *t = $1;
    1877             : 
    1878           0 :                     t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
    1879             :                                             makeIntConst($3, @3));
    1880           0 :                     $$ = makeStringConstCast($5, @5, t);
    1881             :                 }
    1882          24 :             | NumericOnly                           { $$ = makeAConst($1, @1); }
    1883          14 :             | DEFAULT                               { $$ = NULL; }
    1884           2 :             | LOCAL                                 { $$ = NULL; }
    1885             :         ;
    1886             : 
    1887             : opt_encoding:
    1888           0 :             Sconst                                  { $$ = $1; }
    1889           0 :             | DEFAULT                               { $$ = NULL; }
    1890           0 :             | /*EMPTY*/                             { $$ = NULL; }
    1891             :         ;
    1892             : 
    1893             : NonReservedWord_or_Sconst:
    1894       53688 :             NonReservedWord                         { $$ = $1; }
    1895        5520 :             | Sconst                                { $$ = $1; }
    1896             :         ;
    1897             : 
    1898             : VariableResetStmt:
    1899        4510 :             RESET reset_rest                        { $$ = (Node *) $2; }
    1900             :         ;
    1901             : 
    1902             : reset_rest:
    1903        3730 :             generic_reset                           { $$ = $1; }
    1904             :             | TIME ZONE
    1905             :                 {
    1906          14 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1907             : 
    1908          14 :                     n->kind = VAR_RESET;
    1909          14 :                     n->name = "timezone";
    1910          14 :                     n->location = -1;
    1911          14 :                     $$ = n;
    1912             :                 }
    1913             :             | TRANSACTION ISOLATION LEVEL
    1914             :                 {
    1915           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1916             : 
    1917           0 :                     n->kind = VAR_RESET;
    1918           0 :                     n->name = "transaction_isolation";
    1919           0 :                     n->location = -1;
    1920           0 :                     $$ = n;
    1921             :                 }
    1922             :             | SESSION AUTHORIZATION
    1923             :                 {
    1924         766 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1925             : 
    1926         766 :                     n->kind = VAR_RESET;
    1927         766 :                     n->name = "session_authorization";
    1928         766 :                     n->location = -1;
    1929         766 :                     $$ = n;
    1930             :                 }
    1931             :         ;
    1932             : 
    1933             : generic_reset:
    1934             :             var_name
    1935             :                 {
    1936        3766 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1937             : 
    1938        3766 :                     n->kind = VAR_RESET;
    1939        3766 :                     n->name = $1;
    1940        3766 :                     n->location = -1;
    1941        3766 :                     $$ = n;
    1942             :                 }
    1943             :             | ALL
    1944             :                 {
    1945          18 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1946             : 
    1947          18 :                     n->kind = VAR_RESET_ALL;
    1948          18 :                     n->location = -1;
    1949          18 :                     $$ = n;
    1950             :                 }
    1951             :         ;
    1952             : 
    1953             : /* SetResetClause allows SET or RESET without LOCAL */
    1954             : SetResetClause:
    1955        1248 :             SET set_rest                    { $$ = $2; }
    1956          44 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    1957             :         ;
    1958             : 
    1959             : /* SetResetClause allows SET or RESET without LOCAL */
    1960             : FunctionSetResetClause:
    1961         148 :             SET set_rest_more               { $$ = $2; }
    1962          12 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    1963             :         ;
    1964             : 
    1965             : 
    1966             : VariableShowStmt:
    1967             :             SHOW var_name
    1968             :                 {
    1969         864 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1970             : 
    1971         864 :                     n->name = $2;
    1972         864 :                     $$ = (Node *) n;
    1973             :                 }
    1974             :             | SHOW TIME ZONE
    1975             :                 {
    1976          10 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1977             : 
    1978          10 :                     n->name = "timezone";
    1979          10 :                     $$ = (Node *) n;
    1980             :                 }
    1981             :             | SHOW TRANSACTION ISOLATION LEVEL
    1982             :                 {
    1983           4 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1984             : 
    1985           4 :                     n->name = "transaction_isolation";
    1986           4 :                     $$ = (Node *) n;
    1987             :                 }
    1988             :             | SHOW SESSION AUTHORIZATION
    1989             :                 {
    1990           0 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1991             : 
    1992           0 :                     n->name = "session_authorization";
    1993           0 :                     $$ = (Node *) n;
    1994             :                 }
    1995             :             | SHOW ALL
    1996             :                 {
    1997           0 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1998             : 
    1999           0 :                     n->name = "all";
    2000           0 :                     $$ = (Node *) n;
    2001             :                 }
    2002             :         ;
    2003             : 
    2004             : 
    2005             : ConstraintsSetStmt:
    2006             :             SET CONSTRAINTS constraints_set_list constraints_set_mode
    2007             :                 {
    2008         104 :                     ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
    2009             : 
    2010         104 :                     n->constraints = $3;
    2011         104 :                     n->deferred = $4;
    2012         104 :                     $$ = (Node *) n;
    2013             :                 }
    2014             :         ;
    2015             : 
    2016             : constraints_set_list:
    2017          56 :             ALL                                     { $$ = NIL; }
    2018          48 :             | qualified_name_list                   { $$ = $1; }
    2019             :         ;
    2020             : 
    2021             : constraints_set_mode:
    2022          68 :             DEFERRED                                { $$ = true; }
    2023          36 :             | IMMEDIATE                             { $$ = false; }
    2024             :         ;
    2025             : 
    2026             : 
    2027             : /*
    2028             :  * Checkpoint statement
    2029             :  */
    2030             : CheckPointStmt:
    2031             :             CHECKPOINT
    2032             :                 {
    2033         216 :                     CheckPointStmt *n = makeNode(CheckPointStmt);
    2034             : 
    2035         216 :                     $$ = (Node *) n;
    2036             :                 }
    2037             :             | CHECKPOINT '(' utility_option_list ')'
    2038             :                 {
    2039          24 :                     CheckPointStmt *n = makeNode(CheckPointStmt);
    2040             : 
    2041          24 :                     $$ = (Node *) n;
    2042          24 :                     n->options = $3;
    2043             :                 }
    2044             :         ;
    2045             : 
    2046             : 
    2047             : /*****************************************************************************
    2048             :  *
    2049             :  * DISCARD { ALL | TEMP | PLANS | SEQUENCES }
    2050             :  *
    2051             :  *****************************************************************************/
    2052             : 
    2053             : DiscardStmt:
    2054             :             DISCARD ALL
    2055             :                 {
    2056           6 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2057             : 
    2058           6 :                     n->target = DISCARD_ALL;
    2059           6 :                     $$ = (Node *) n;
    2060             :                 }
    2061             :             | DISCARD TEMP
    2062             :                 {
    2063           8 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2064             : 
    2065           8 :                     n->target = DISCARD_TEMP;
    2066           8 :                     $$ = (Node *) n;
    2067             :                 }
    2068             :             | DISCARD TEMPORARY
    2069             :                 {
    2070           0 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2071             : 
    2072           0 :                     n->target = DISCARD_TEMP;
    2073           0 :                     $$ = (Node *) n;
    2074             :                 }
    2075             :             | DISCARD PLANS
    2076             :                 {
    2077           4 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2078             : 
    2079           4 :                     n->target = DISCARD_PLANS;
    2080           4 :                     $$ = (Node *) n;
    2081             :                 }
    2082             :             | DISCARD SEQUENCES
    2083             :                 {
    2084          12 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2085             : 
    2086          12 :                     n->target = DISCARD_SEQUENCES;
    2087          12 :                     $$ = (Node *) n;
    2088             :                 }
    2089             : 
    2090             :         ;
    2091             : 
    2092             : 
    2093             : /*****************************************************************************
    2094             :  *
    2095             :  *  ALTER [ TABLE | INDEX | SEQUENCE | VIEW | MATERIALIZED VIEW | FOREIGN TABLE ] variations
    2096             :  *
    2097             :  * Note: we accept all subcommands for each of the variants, and sort
    2098             :  * out what's really legal at execution time.
    2099             :  *****************************************************************************/
    2100             : 
    2101             : AlterTableStmt:
    2102             :             ALTER TABLE relation_expr alter_table_cmds
    2103             :                 {
    2104       28354 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2105             : 
    2106       28354 :                     n->relation = $3;
    2107       28354 :                     n->cmds = $4;
    2108       28354 :                     n->objtype = OBJECT_TABLE;
    2109       28354 :                     n->missing_ok = false;
    2110       28354 :                     $$ = (Node *) n;
    2111             :                 }
    2112             :         |   ALTER TABLE IF_P EXISTS relation_expr alter_table_cmds
    2113             :                 {
    2114          54 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2115             : 
    2116          54 :                     n->relation = $5;
    2117          54 :                     n->cmds = $6;
    2118          54 :                     n->objtype = OBJECT_TABLE;
    2119          54 :                     n->missing_ok = true;
    2120          54 :                     $$ = (Node *) n;
    2121             :                 }
    2122             :         |   ALTER TABLE relation_expr partition_cmd
    2123             :                 {
    2124        3446 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2125             : 
    2126        3446 :                     n->relation = $3;
    2127        3446 :                     n->cmds = list_make1($4);
    2128        3446 :                     n->objtype = OBJECT_TABLE;
    2129        3446 :                     n->missing_ok = false;
    2130        3446 :                     $$ = (Node *) n;
    2131             :                 }
    2132             :         |   ALTER TABLE IF_P EXISTS relation_expr partition_cmd
    2133             :                 {
    2134           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2135             : 
    2136           0 :                     n->relation = $5;
    2137           0 :                     n->cmds = list_make1($6);
    2138           0 :                     n->objtype = OBJECT_TABLE;
    2139           0 :                     n->missing_ok = true;
    2140           0 :                     $$ = (Node *) n;
    2141             :                 }
    2142             :         |   ALTER TABLE ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2143             :                 {
    2144             :                     AlterTableMoveAllStmt *n =
    2145          12 :                         makeNode(AlterTableMoveAllStmt);
    2146             : 
    2147          12 :                     n->orig_tablespacename = $6;
    2148          12 :                     n->objtype = OBJECT_TABLE;
    2149          12 :                     n->roles = NIL;
    2150          12 :                     n->new_tablespacename = $9;
    2151          12 :                     n->nowait = $10;
    2152          12 :                     $$ = (Node *) n;
    2153             :                 }
    2154             :         |   ALTER TABLE ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2155             :                 {
    2156             :                     AlterTableMoveAllStmt *n =
    2157           0 :                         makeNode(AlterTableMoveAllStmt);
    2158             : 
    2159           0 :                     n->orig_tablespacename = $6;
    2160           0 :                     n->objtype = OBJECT_TABLE;
    2161           0 :                     n->roles = $9;
    2162           0 :                     n->new_tablespacename = $12;
    2163           0 :                     n->nowait = $13;
    2164           0 :                     $$ = (Node *) n;
    2165             :                 }
    2166             :         |   ALTER INDEX qualified_name alter_table_cmds
    2167             :                 {
    2168         228 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2169             : 
    2170         228 :                     n->relation = $3;
    2171         228 :                     n->cmds = $4;
    2172         228 :                     n->objtype = OBJECT_INDEX;
    2173         228 :                     n->missing_ok = false;
    2174         228 :                     $$ = (Node *) n;
    2175             :                 }
    2176             :         |   ALTER INDEX IF_P EXISTS qualified_name alter_table_cmds
    2177             :                 {
    2178           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2179             : 
    2180           0 :                     n->relation = $5;
    2181           0 :                     n->cmds = $6;
    2182           0 :                     n->objtype = OBJECT_INDEX;
    2183           0 :                     n->missing_ok = true;
    2184           0 :                     $$ = (Node *) n;
    2185             :                 }
    2186             :         |   ALTER INDEX qualified_name index_partition_cmd
    2187             :                 {
    2188         482 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2189             : 
    2190         482 :                     n->relation = $3;
    2191         482 :                     n->cmds = list_make1($4);
    2192         482 :                     n->objtype = OBJECT_INDEX;
    2193         482 :                     n->missing_ok = false;
    2194         482 :                     $$ = (Node *) n;
    2195             :                 }
    2196             :         |   ALTER INDEX ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2197             :                 {
    2198             :                     AlterTableMoveAllStmt *n =
    2199           6 :                         makeNode(AlterTableMoveAllStmt);
    2200             : 
    2201           6 :                     n->orig_tablespacename = $6;
    2202           6 :                     n->objtype = OBJECT_INDEX;
    2203           6 :                     n->roles = NIL;
    2204           6 :                     n->new_tablespacename = $9;
    2205           6 :                     n->nowait = $10;
    2206           6 :                     $$ = (Node *) n;
    2207             :                 }
    2208             :         |   ALTER INDEX ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2209             :                 {
    2210             :                     AlterTableMoveAllStmt *n =
    2211           0 :                         makeNode(AlterTableMoveAllStmt);
    2212             : 
    2213           0 :                     n->orig_tablespacename = $6;
    2214           0 :                     n->objtype = OBJECT_INDEX;
    2215           0 :                     n->roles = $9;
    2216           0 :                     n->new_tablespacename = $12;
    2217           0 :                     n->nowait = $13;
    2218           0 :                     $$ = (Node *) n;
    2219             :                 }
    2220             :         |   ALTER SEQUENCE qualified_name alter_table_cmds
    2221             :                 {
    2222         156 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2223             : 
    2224         156 :                     n->relation = $3;
    2225         156 :                     n->cmds = $4;
    2226         156 :                     n->objtype = OBJECT_SEQUENCE;
    2227         156 :                     n->missing_ok = false;
    2228         156 :                     $$ = (Node *) n;
    2229             :                 }
    2230             :         |   ALTER SEQUENCE IF_P EXISTS qualified_name alter_table_cmds
    2231             :                 {
    2232           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2233             : 
    2234           0 :                     n->relation = $5;
    2235           0 :                     n->cmds = $6;
    2236           0 :                     n->objtype = OBJECT_SEQUENCE;
    2237           0 :                     n->missing_ok = true;
    2238           0 :                     $$ = (Node *) n;
    2239             :                 }
    2240             :         |   ALTER VIEW qualified_name alter_table_cmds
    2241             :                 {
    2242         356 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2243             : 
    2244         356 :                     n->relation = $3;
    2245         356 :                     n->cmds = $4;
    2246         356 :                     n->objtype = OBJECT_VIEW;
    2247         356 :                     n->missing_ok = false;
    2248         356 :                     $$ = (Node *) n;
    2249             :                 }
    2250             :         |   ALTER VIEW IF_P EXISTS qualified_name alter_table_cmds
    2251             :                 {
    2252           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2253             : 
    2254           0 :                     n->relation = $5;
    2255           0 :                     n->cmds = $6;
    2256           0 :                     n->objtype = OBJECT_VIEW;
    2257           0 :                     n->missing_ok = true;
    2258           0 :                     $$ = (Node *) n;
    2259             :                 }
    2260             :         |   ALTER MATERIALIZED VIEW qualified_name alter_table_cmds
    2261             :                 {
    2262          64 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2263             : 
    2264          64 :                     n->relation = $4;
    2265          64 :                     n->cmds = $5;
    2266          64 :                     n->objtype = OBJECT_MATVIEW;
    2267          64 :                     n->missing_ok = false;
    2268          64 :                     $$ = (Node *) n;
    2269             :                 }
    2270             :         |   ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name alter_table_cmds
    2271             :                 {
    2272           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2273             : 
    2274           0 :                     n->relation = $6;
    2275           0 :                     n->cmds = $7;
    2276           0 :                     n->objtype = OBJECT_MATVIEW;
    2277           0 :                     n->missing_ok = true;
    2278           0 :                     $$ = (Node *) n;
    2279             :                 }
    2280             :         |   ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2281             :                 {
    2282             :                     AlterTableMoveAllStmt *n =
    2283          12 :                         makeNode(AlterTableMoveAllStmt);
    2284             : 
    2285          12 :                     n->orig_tablespacename = $7;
    2286          12 :                     n->objtype = OBJECT_MATVIEW;
    2287          12 :                     n->roles = NIL;
    2288          12 :                     n->new_tablespacename = $10;
    2289          12 :                     n->nowait = $11;
    2290          12 :                     $$ = (Node *) n;
    2291             :                 }
    2292             :         |   ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2293             :                 {
    2294             :                     AlterTableMoveAllStmt *n =
    2295           0 :                         makeNode(AlterTableMoveAllStmt);
    2296             : 
    2297           0 :                     n->orig_tablespacename = $7;
    2298           0 :                     n->objtype = OBJECT_MATVIEW;
    2299           0 :                     n->roles = $10;
    2300           0 :                     n->new_tablespacename = $13;
    2301           0 :                     n->nowait = $14;
    2302           0 :                     $$ = (Node *) n;
    2303             :                 }
    2304             :         |   ALTER FOREIGN TABLE relation_expr alter_table_cmds
    2305             :                 {
    2306         374 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2307             : 
    2308         374 :                     n->relation = $4;
    2309         374 :                     n->cmds = $5;
    2310         374 :                     n->objtype = OBJECT_FOREIGN_TABLE;
    2311         374 :                     n->missing_ok = false;
    2312         374 :                     $$ = (Node *) n;
    2313             :                 }
    2314             :         |   ALTER FOREIGN TABLE IF_P EXISTS relation_expr alter_table_cmds
    2315             :                 {
    2316         108 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2317             : 
    2318         108 :                     n->relation = $6;
    2319         108 :                     n->cmds = $7;
    2320         108 :                     n->objtype = OBJECT_FOREIGN_TABLE;
    2321         108 :                     n->missing_ok = true;
    2322         108 :                     $$ = (Node *) n;
    2323             :                 }
    2324             :         ;
    2325             : 
    2326             : alter_table_cmds:
    2327       29694 :             alter_table_cmd                         { $$ = list_make1($1); }
    2328        1020 :             | alter_table_cmds ',' alter_table_cmd  { $$ = lappend($1, $3); }
    2329             :         ;
    2330             : 
    2331             : partition_cmd:
    2332             :             /* ALTER TABLE <name> ATTACH PARTITION <table_name> FOR VALUES */
    2333             :             ATTACH PARTITION qualified_name PartitionBoundSpec
    2334             :                 {
    2335        2832 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2336        2832 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2337             : 
    2338        2832 :                     n->subtype = AT_AttachPartition;
    2339        2832 :                     cmd->name = $3;
    2340        2832 :                     cmd->bound = $4;
    2341        2832 :                     cmd->concurrent = false;
    2342        2832 :                     n->def = (Node *) cmd;
    2343             : 
    2344        2832 :                     $$ = (Node *) n;
    2345             :                 }
    2346             :             /* ALTER TABLE <name> DETACH PARTITION <partition_name> [CONCURRENTLY] */
    2347             :             | DETACH PARTITION qualified_name opt_concurrently
    2348             :                 {
    2349         594 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2350         594 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2351             : 
    2352         594 :                     n->subtype = AT_DetachPartition;
    2353         594 :                     cmd->name = $3;
    2354         594 :                     cmd->bound = NULL;
    2355         594 :                     cmd->concurrent = $4;
    2356         594 :                     n->def = (Node *) cmd;
    2357             : 
    2358         594 :                     $$ = (Node *) n;
    2359             :                 }
    2360             :             | DETACH PARTITION qualified_name FINALIZE
    2361             :                 {
    2362          20 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2363          20 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2364             : 
    2365          20 :                     n->subtype = AT_DetachPartitionFinalize;
    2366          20 :                     cmd->name = $3;
    2367          20 :                     cmd->bound = NULL;
    2368          20 :                     cmd->concurrent = false;
    2369          20 :                     n->def = (Node *) cmd;
    2370          20 :                     $$ = (Node *) n;
    2371             :                 }
    2372             :         ;
    2373             : 
    2374             : index_partition_cmd:
    2375             :             /* ALTER INDEX <name> ATTACH PARTITION <index_name> */
    2376             :             ATTACH PARTITION qualified_name
    2377             :                 {
    2378         482 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2379         482 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2380             : 
    2381         482 :                     n->subtype = AT_AttachPartition;
    2382         482 :                     cmd->name = $3;
    2383         482 :                     cmd->bound = NULL;
    2384         482 :                     cmd->concurrent = false;
    2385         482 :                     n->def = (Node *) cmd;
    2386             : 
    2387         482 :                     $$ = (Node *) n;
    2388             :                 }
    2389             :         ;
    2390             : 
    2391             : alter_table_cmd:
    2392             :             /* ALTER TABLE <name> ADD <coldef> */
    2393             :             ADD_P columnDef
    2394             :                 {
    2395         192 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2396             : 
    2397         192 :                     n->subtype = AT_AddColumn;
    2398         192 :                     n->def = $2;
    2399         192 :                     n->missing_ok = false;
    2400         192 :                     $$ = (Node *) n;
    2401             :                 }
    2402             :             /* ALTER TABLE <name> ADD IF NOT EXISTS <coldef> */
    2403             :             | ADD_P IF_P NOT EXISTS columnDef
    2404             :                 {
    2405           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2406             : 
    2407           0 :                     n->subtype = AT_AddColumn;
    2408           0 :                     n->def = $5;
    2409           0 :                     n->missing_ok = true;
    2410           0 :                     $$ = (Node *) n;
    2411             :                 }
    2412             :             /* ALTER TABLE <name> ADD COLUMN <coldef> */
    2413             :             | ADD_P COLUMN columnDef
    2414             :                 {
    2415        1896 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2416             : 
    2417        1896 :                     n->subtype = AT_AddColumn;
    2418        1896 :                     n->def = $3;
    2419        1896 :                     n->missing_ok = false;
    2420        1896 :                     $$ = (Node *) n;
    2421             :                 }
    2422             :             /* ALTER TABLE <name> ADD COLUMN IF NOT EXISTS <coldef> */
    2423             :             | ADD_P COLUMN IF_P NOT EXISTS columnDef
    2424             :                 {
    2425          60 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2426             : 
    2427          60 :                     n->subtype = AT_AddColumn;
    2428          60 :                     n->def = $6;
    2429          60 :                     n->missing_ok = true;
    2430          60 :                     $$ = (Node *) n;
    2431             :                 }
    2432             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
    2433             :             | ALTER opt_column ColId alter_column_default
    2434             :                 {
    2435         578 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2436             : 
    2437         578 :                     n->subtype = AT_ColumnDefault;
    2438         578 :                     n->name = $3;
    2439         578 :                     n->def = $4;
    2440         578 :                     $$ = (Node *) n;
    2441             :                 }
    2442             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
    2443             :             | ALTER opt_column ColId DROP NOT NULL_P
    2444             :                 {
    2445         294 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2446             : 
    2447         294 :                     n->subtype = AT_DropNotNull;
    2448         294 :                     n->name = $3;
    2449         294 :                     $$ = (Node *) n;
    2450             :                 }
    2451             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
    2452             :             | ALTER opt_column ColId SET NOT NULL_P
    2453             :                 {
    2454         434 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2455             : 
    2456         434 :                     n->subtype = AT_SetNotNull;
    2457         434 :                     n->name = $3;
    2458         434 :                     $$ = (Node *) n;
    2459             :                 }
    2460             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET EXPRESSION AS <expr> */
    2461             :             | ALTER opt_column ColId SET EXPRESSION AS '(' a_expr ')'
    2462             :                 {
    2463         168 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2464             : 
    2465         168 :                     n->subtype = AT_SetExpression;
    2466         168 :                     n->name = $3;
    2467         168 :                     n->def = $8;
    2468         168 :                     $$ = (Node *) n;
    2469             :                 }
    2470             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
    2471             :             | ALTER opt_column ColId DROP EXPRESSION
    2472             :                 {
    2473          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2474             : 
    2475          62 :                     n->subtype = AT_DropExpression;
    2476          62 :                     n->name = $3;
    2477          62 :                     $$ = (Node *) n;
    2478             :                 }
    2479             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION IF EXISTS */
    2480             :             | ALTER opt_column ColId DROP EXPRESSION IF_P EXISTS
    2481             :                 {
    2482          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2483             : 
    2484          12 :                     n->subtype = AT_DropExpression;
    2485          12 :                     n->name = $3;
    2486          12 :                     n->missing_ok = true;
    2487          12 :                     $$ = (Node *) n;
    2488             :                 }
    2489             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS */
    2490             :             | ALTER opt_column ColId SET STATISTICS set_statistics_value
    2491             :                 {
    2492          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2493             : 
    2494          62 :                     n->subtype = AT_SetStatistics;
    2495          62 :                     n->name = $3;
    2496          62 :                     n->def = $6;
    2497          62 :                     $$ = (Node *) n;
    2498             :                 }
    2499             :             /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS */
    2500             :             | ALTER opt_column Iconst SET STATISTICS set_statistics_value
    2501             :                 {
    2502          70 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2503             : 
    2504          70 :                     if ($3 <= 0 || $3 > PG_INT16_MAX)
    2505           6 :                         ereport(ERROR,
    2506             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
    2507             :                                  errmsg("column number must be in range from 1 to %d", PG_INT16_MAX),
    2508             :                                  parser_errposition(@3)));
    2509             : 
    2510          64 :                     n->subtype = AT_SetStatistics;
    2511          64 :                     n->num = (int16) $3;
    2512          64 :                     n->def = $6;
    2513          64 :                     $$ = (Node *) n;
    2514             :                 }
    2515             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
    2516             :             | ALTER opt_column ColId SET reloptions
    2517             :                 {
    2518          38 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2519             : 
    2520          38 :                     n->subtype = AT_SetOptions;
    2521          38 :                     n->name = $3;
    2522          38 :                     n->def = (Node *) $5;
    2523          38 :                     $$ = (Node *) n;
    2524             :                 }
    2525             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> RESET ( column_parameter [, ... ] ) */
    2526             :             | ALTER opt_column ColId RESET reloptions
    2527             :                 {
    2528           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2529             : 
    2530           6 :                     n->subtype = AT_ResetOptions;
    2531           6 :                     n->name = $3;
    2532           6 :                     n->def = (Node *) $5;
    2533           6 :                     $$ = (Node *) n;
    2534             :                 }
    2535             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
    2536             :             | ALTER opt_column ColId SET column_storage
    2537             :                 {
    2538         224 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2539             : 
    2540         224 :                     n->subtype = AT_SetStorage;
    2541         224 :                     n->name = $3;
    2542         224 :                     n->def = (Node *) makeString($5);
    2543         224 :                     $$ = (Node *) n;
    2544             :                 }
    2545             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET COMPRESSION <cm> */
    2546             :             | ALTER opt_column ColId SET column_compression
    2547             :                 {
    2548         104 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2549             : 
    2550         104 :                     n->subtype = AT_SetCompression;
    2551         104 :                     n->name = $3;
    2552         104 :                     n->def = (Node *) makeString($5);
    2553         104 :                     $$ = (Node *) n;
    2554             :                 }
    2555             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> ADD GENERATED ... AS IDENTITY ... */
    2556             :             | ALTER opt_column ColId ADD_P GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    2557             :                 {
    2558         210 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2559         210 :                     Constraint *c = makeNode(Constraint);
    2560             : 
    2561         210 :                     c->contype = CONSTR_IDENTITY;
    2562         210 :                     c->generated_when = $6;
    2563         210 :                     c->options = $9;
    2564         210 :                     c->location = @5;
    2565             : 
    2566         210 :                     n->subtype = AT_AddIdentity;
    2567         210 :                     n->name = $3;
    2568         210 :                     n->def = (Node *) c;
    2569             : 
    2570         210 :                     $$ = (Node *) n;
    2571             :                 }
    2572             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET <sequence options>/RESET */
    2573             :             | ALTER opt_column ColId alter_identity_column_option_list
    2574             :                 {
    2575          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2576             : 
    2577          62 :                     n->subtype = AT_SetIdentity;
    2578          62 :                     n->name = $3;
    2579          62 :                     n->def = (Node *) $4;
    2580          62 :                     $$ = (Node *) n;
    2581             :                 }
    2582             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY */
    2583             :             | ALTER opt_column ColId DROP IDENTITY_P
    2584             :                 {
    2585          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2586             : 
    2587          50 :                     n->subtype = AT_DropIdentity;
    2588          50 :                     n->name = $3;
    2589          50 :                     n->missing_ok = false;
    2590          50 :                     $$ = (Node *) n;
    2591             :                 }
    2592             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY IF EXISTS */
    2593             :             | ALTER opt_column ColId DROP IDENTITY_P IF_P EXISTS
    2594             :                 {
    2595           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2596             : 
    2597           6 :                     n->subtype = AT_DropIdentity;
    2598           6 :                     n->name = $3;
    2599           6 :                     n->missing_ok = true;
    2600           6 :                     $$ = (Node *) n;
    2601             :                 }
    2602             :             /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
    2603             :             | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
    2604             :                 {
    2605          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2606             : 
    2607          18 :                     n->subtype = AT_DropColumn;
    2608          18 :                     n->name = $5;
    2609          18 :                     n->behavior = $6;
    2610          18 :                     n->missing_ok = true;
    2611          18 :                     $$ = (Node *) n;
    2612             :                 }
    2613             :             /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
    2614             :             | DROP opt_column ColId opt_drop_behavior
    2615             :                 {
    2616        1574 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2617             : 
    2618        1574 :                     n->subtype = AT_DropColumn;
    2619        1574 :                     n->name = $3;
    2620        1574 :                     n->behavior = $4;
    2621        1574 :                     n->missing_ok = false;
    2622        1574 :                     $$ = (Node *) n;
    2623             :                 }
    2624             :             /*
    2625             :              * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
    2626             :              *      [ USING <expression> ]
    2627             :              */
    2628             :             | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using
    2629             :                 {
    2630        1024 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2631        1024 :                     ColumnDef *def = makeNode(ColumnDef);
    2632             : 
    2633        1024 :                     n->subtype = AT_AlterColumnType;
    2634        1024 :                     n->name = $3;
    2635        1024 :                     n->def = (Node *) def;
    2636             :                     /* We only use these fields of the ColumnDef node */
    2637        1024 :                     def->typeName = $6;
    2638        1024 :                     def->collClause = (CollateClause *) $7;
    2639        1024 :                     def->raw_default = $8;
    2640        1024 :                     def->location = @3;
    2641        1024 :                     $$ = (Node *) n;
    2642             :                 }
    2643             :             /* ALTER FOREIGN TABLE <name> ALTER [COLUMN] <colname> OPTIONS */
    2644             :             | ALTER opt_column ColId alter_generic_options
    2645             :                 {
    2646          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2647             : 
    2648          50 :                     n->subtype = AT_AlterColumnGenericOptions;
    2649          50 :                     n->name = $3;
    2650          50 :                     n->def = (Node *) $4;
    2651          50 :                     $$ = (Node *) n;
    2652             :                 }
    2653             :             /* ALTER TABLE <name> ADD CONSTRAINT ... */
    2654             :             | ADD_P TableConstraint
    2655             :                 {
    2656       15108 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2657             : 
    2658       15108 :                     n->subtype = AT_AddConstraint;
    2659       15108 :                     n->def = $2;
    2660       15108 :                     $$ = (Node *) n;
    2661             :                 }
    2662             :             /* ALTER TABLE <name> ALTER CONSTRAINT ... */
    2663             :             | ALTER CONSTRAINT name ConstraintAttributeSpec
    2664             :                 {
    2665         240 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2666         240 :                     ATAlterConstraint *c = makeNode(ATAlterConstraint);
    2667             : 
    2668         240 :                     n->subtype = AT_AlterConstraint;
    2669         240 :                     n->def = (Node *) c;
    2670         240 :                     c->conname = $3;
    2671         240 :                     if ($4 & (CAS_NOT_ENFORCED | CAS_ENFORCED))
    2672          84 :                         c->alterEnforceability = true;
    2673         240 :                     if ($4 & (CAS_DEFERRABLE | CAS_NOT_DEFERRABLE |
    2674             :                               CAS_INITIALLY_DEFERRED | CAS_INITIALLY_IMMEDIATE))
    2675         120 :                         c->alterDeferrability = true;
    2676         240 :                     if ($4 & CAS_NO_INHERIT)
    2677          30 :                         c->alterInheritability = true;
    2678             :                     /* handle unsupported case with specific error message */
    2679         240 :                     if ($4 & CAS_NOT_VALID)
    2680          12 :                         ereport(ERROR,
    2681             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    2682             :                                 errmsg("constraints cannot be altered to be NOT VALID"),
    2683             :                                 parser_errposition(@4));
    2684         228 :                     processCASbits($4, @4, "FOREIGN KEY",
    2685             :                                     &c->deferrable,
    2686             :                                     &c->initdeferred,
    2687             :                                     &c->is_enforced,
    2688             :                                     NULL,
    2689             :                                     &c->noinherit,
    2690             :                                     yyscanner);
    2691         228 :                     $$ = (Node *) n;
    2692             :                 }
    2693             :             /* ALTER TABLE <name> ALTER CONSTRAINT INHERIT */
    2694             :             | ALTER CONSTRAINT name INHERIT
    2695             :                 {
    2696          66 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2697          66 :                     ATAlterConstraint *c = makeNode(ATAlterConstraint);
    2698             : 
    2699          66 :                     n->subtype = AT_AlterConstraint;
    2700          66 :                     n->def = (Node *) c;
    2701          66 :                     c->conname = $3;
    2702          66 :                     c->alterInheritability = true;
    2703          66 :                     c->noinherit = false;
    2704             : 
    2705          66 :                     $$ = (Node *) n;
    2706             :                 }
    2707             :             /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
    2708             :             | VALIDATE CONSTRAINT name
    2709             :                 {
    2710         476 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2711             : 
    2712         476 :                     n->subtype = AT_ValidateConstraint;
    2713         476 :                     n->name = $3;
    2714         476 :                     $$ = (Node *) n;
    2715             :                 }
    2716             :             /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
    2717             :             | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
    2718             :                 {
    2719          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2720             : 
    2721          18 :                     n->subtype = AT_DropConstraint;
    2722          18 :                     n->name = $5;
    2723          18 :                     n->behavior = $6;
    2724          18 :                     n->missing_ok = true;
    2725          18 :                     $$ = (Node *) n;
    2726             :                 }
    2727             :             /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
    2728             :             | DROP CONSTRAINT name opt_drop_behavior
    2729             :                 {
    2730         816 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2731             : 
    2732         816 :                     n->subtype = AT_DropConstraint;
    2733         816 :                     n->name = $3;
    2734         816 :                     n->behavior = $4;
    2735         816 :                     n->missing_ok = false;
    2736         816 :                     $$ = (Node *) n;
    2737             :                 }
    2738             :             /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat */
    2739             :             | SET WITHOUT OIDS
    2740             :                 {
    2741           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2742             : 
    2743           6 :                     n->subtype = AT_DropOids;
    2744           6 :                     $$ = (Node *) n;
    2745             :                 }
    2746             :             /* ALTER TABLE <name> CLUSTER ON <indexname> */
    2747             :             | CLUSTER ON name
    2748             :                 {
    2749          46 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2750             : 
    2751          46 :                     n->subtype = AT_ClusterOn;
    2752          46 :                     n->name = $3;
    2753          46 :                     $$ = (Node *) n;
    2754             :                 }
    2755             :             /* ALTER TABLE <name> SET WITHOUT CLUSTER */
    2756             :             | SET WITHOUT CLUSTER
    2757             :                 {
    2758          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2759             : 
    2760          18 :                     n->subtype = AT_DropCluster;
    2761          18 :                     n->name = NULL;
    2762          18 :                     $$ = (Node *) n;
    2763             :                 }
    2764             :             /* ALTER TABLE <name> SET LOGGED */
    2765             :             | SET LOGGED
    2766             :                 {
    2767          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2768             : 
    2769          50 :                     n->subtype = AT_SetLogged;
    2770          50 :                     $$ = (Node *) n;
    2771             :                 }
    2772             :             /* ALTER TABLE <name> SET UNLOGGED */
    2773             :             | SET UNLOGGED
    2774             :                 {
    2775          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2776             : 
    2777          62 :                     n->subtype = AT_SetUnLogged;
    2778          62 :                     $$ = (Node *) n;
    2779             :                 }
    2780             :             /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
    2781             :             | ENABLE_P TRIGGER name
    2782             :                 {
    2783         122 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2784             : 
    2785         122 :                     n->subtype = AT_EnableTrig;
    2786         122 :                     n->name = $3;
    2787         122 :                     $$ = (Node *) n;
    2788             :                 }
    2789             :             /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
    2790             :             | ENABLE_P ALWAYS TRIGGER name
    2791             :                 {
    2792          44 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2793             : 
    2794          44 :                     n->subtype = AT_EnableAlwaysTrig;
    2795          44 :                     n->name = $4;
    2796          44 :                     $$ = (Node *) n;
    2797             :                 }
    2798             :             /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
    2799             :             | ENABLE_P REPLICA TRIGGER name
    2800             :                 {
    2801          16 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2802             : 
    2803          16 :                     n->subtype = AT_EnableReplicaTrig;
    2804          16 :                     n->name = $4;
    2805          16 :                     $$ = (Node *) n;
    2806             :                 }
    2807             :             /* ALTER TABLE <name> ENABLE TRIGGER ALL */
    2808             :             | ENABLE_P TRIGGER ALL
    2809             :                 {
    2810           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2811             : 
    2812           0 :                     n->subtype = AT_EnableTrigAll;
    2813           0 :                     $$ = (Node *) n;
    2814             :                 }
    2815             :             /* ALTER TABLE <name> ENABLE TRIGGER USER */
    2816             :             | ENABLE_P TRIGGER USER
    2817             :                 {
    2818           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2819             : 
    2820           0 :                     n->subtype = AT_EnableTrigUser;
    2821           0 :                     $$ = (Node *) n;
    2822             :                 }
    2823             :             /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
    2824             :             | DISABLE_P TRIGGER name
    2825             :                 {
    2826         140 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2827             : 
    2828         140 :                     n->subtype = AT_DisableTrig;
    2829         140 :                     n->name = $3;
    2830         140 :                     $$ = (Node *) n;
    2831             :                 }
    2832             :             /* ALTER TABLE <name> DISABLE TRIGGER ALL */
    2833             :             | DISABLE_P TRIGGER ALL
    2834             :                 {
    2835          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2836             : 
    2837          12 :                     n->subtype = AT_DisableTrigAll;
    2838          12 :                     $$ = (Node *) n;
    2839             :                 }
    2840             :             /* ALTER TABLE <name> DISABLE TRIGGER USER */
    2841             :             | DISABLE_P TRIGGER USER
    2842             :                 {
    2843          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2844             : 
    2845          12 :                     n->subtype = AT_DisableTrigUser;
    2846          12 :                     $$ = (Node *) n;
    2847             :                 }
    2848             :             /* ALTER TABLE <name> ENABLE RULE <rule> */
    2849             :             | ENABLE_P RULE name
    2850             :                 {
    2851           8 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2852             : 
    2853           8 :                     n->subtype = AT_EnableRule;
    2854           8 :                     n->name = $3;
    2855           8 :                     $$ = (Node *) n;
    2856             :                 }
    2857             :             /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
    2858             :             | ENABLE_P ALWAYS RULE name
    2859             :                 {
    2860           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2861             : 
    2862           0 :                     n->subtype = AT_EnableAlwaysRule;
    2863           0 :                     n->name = $4;
    2864           0 :                     $$ = (Node *) n;
    2865             :                 }
    2866             :             /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
    2867             :             | ENABLE_P REPLICA RULE name
    2868             :                 {
    2869           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2870             : 
    2871           6 :                     n->subtype = AT_EnableReplicaRule;
    2872           6 :                     n->name = $4;
    2873           6 :                     $$ = (Node *) n;
    2874             :                 }
    2875             :             /* ALTER TABLE <name> DISABLE RULE <rule> */
    2876             :             | DISABLE_P RULE name
    2877             :                 {
    2878          38 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2879             : 
    2880          38 :                     n->subtype = AT_DisableRule;
    2881          38 :                     n->name = $3;
    2882          38 :                     $$ = (Node *) n;
    2883             :                 }
    2884             :             /* ALTER TABLE <name> INHERIT <parent> */
    2885             :             | INHERIT qualified_name
    2886             :                 {
    2887         448 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2888             : 
    2889         448 :                     n->subtype = AT_AddInherit;
    2890         448 :                     n->def = (Node *) $2;
    2891         448 :                     $$ = (Node *) n;
    2892             :                 }
    2893             :             /* ALTER TABLE <name> NO INHERIT <parent> */
    2894             :             | NO INHERIT qualified_name
    2895             :                 {
    2896          86 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2897             : 
    2898          86 :                     n->subtype = AT_DropInherit;
    2899          86 :                     n->def = (Node *) $3;
    2900          86 :                     $$ = (Node *) n;
    2901             :                 }
    2902             :             /* ALTER TABLE <name> OF <type_name> */
    2903             :             | OF any_name
    2904             :                 {
    2905          66 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2906          66 :                     TypeName   *def = makeTypeNameFromNameList($2);
    2907             : 
    2908          66 :                     def->location = @2;
    2909          66 :                     n->subtype = AT_AddOf;
    2910          66 :                     n->def = (Node *) def;
    2911          66 :                     $$ = (Node *) n;
    2912             :                 }
    2913             :             /* ALTER TABLE <name> NOT OF */
    2914             :             | NOT OF
    2915             :                 {
    2916           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2917             : 
    2918           6 :                     n->subtype = AT_DropOf;
    2919           6 :                     $$ = (Node *) n;
    2920             :                 }
    2921             :             /* ALTER TABLE <name> OWNER TO RoleSpec */
    2922             :             | OWNER TO RoleSpec
    2923             :                 {
    2924        3626 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2925             : 
    2926        3626 :                     n->subtype = AT_ChangeOwner;
    2927        3626 :                     n->newowner = $3;
    2928        3626 :                     $$ = (Node *) n;
    2929             :                 }
    2930             :             /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
    2931             :             | SET ACCESS METHOD set_access_method_name
    2932             :                 {
    2933         128 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2934             : 
    2935         128 :                     n->subtype = AT_SetAccessMethod;
    2936         128 :                     n->name = $4;
    2937         128 :                     $$ = (Node *) n;
    2938             :                 }
    2939             :             /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
    2940             :             | SET TABLESPACE name
    2941             :                 {
    2942         104 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2943             : 
    2944         104 :                     n->subtype = AT_SetTableSpace;
    2945         104 :                     n->name = $3;
    2946         104 :                     $$ = (Node *) n;
    2947             :                 }
    2948             :             /* ALTER TABLE <name> SET (...) */
    2949             :             | SET reloptions
    2950             :                 {
    2951         594 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2952             : 
    2953         594 :                     n->subtype = AT_SetRelOptions;
    2954         594 :                     n->def = (Node *) $2;
    2955         594 :                     $$ = (Node *) n;
    2956             :                 }
    2957             :             /* ALTER TABLE <name> RESET (...) */
    2958             :             | RESET reloptions
    2959             :                 {
    2960         170 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2961             : 
    2962         170 :                     n->subtype = AT_ResetRelOptions;
    2963         170 :                     n->def = (Node *) $2;
    2964         170 :                     $$ = (Node *) n;
    2965             :                 }
    2966             :             /* ALTER TABLE <name> REPLICA IDENTITY */
    2967             :             | REPLICA IDENTITY_P replica_identity
    2968             :                 {
    2969         490 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2970             : 
    2971         490 :                     n->subtype = AT_ReplicaIdentity;
    2972         490 :                     n->def = $3;
    2973         490 :                     $$ = (Node *) n;
    2974             :                 }
    2975             :             /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
    2976             :             | ENABLE_P ROW LEVEL SECURITY
    2977             :                 {
    2978         308 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2979             : 
    2980         308 :                     n->subtype = AT_EnableRowSecurity;
    2981         308 :                     $$ = (Node *) n;
    2982             :                 }
    2983             :             /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
    2984             :             | DISABLE_P ROW LEVEL SECURITY
    2985             :                 {
    2986          10 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2987             : 
    2988          10 :                     n->subtype = AT_DisableRowSecurity;
    2989          10 :                     $$ = (Node *) n;
    2990             :                 }
    2991             :             /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
    2992             :             | FORCE ROW LEVEL SECURITY
    2993             :                 {
    2994         102 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2995             : 
    2996         102 :                     n->subtype = AT_ForceRowSecurity;
    2997         102 :                     $$ = (Node *) n;
    2998             :                 }
    2999             :             /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
    3000             :             | NO FORCE ROW LEVEL SECURITY
    3001             :                 {
    3002          32 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3003             : 
    3004          32 :                     n->subtype = AT_NoForceRowSecurity;
    3005          32 :                     $$ = (Node *) n;
    3006             :                 }
    3007             :             | alter_generic_options
    3008             :                 {
    3009          64 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3010             : 
    3011          64 :                     n->subtype = AT_GenericOptions;
    3012          64 :                     n->def = (Node *) $1;
    3013          64 :                     $$ = (Node *) n;
    3014             :                 }
    3015             :         ;
    3016             : 
    3017             : alter_column_default:
    3018         406 :             SET DEFAULT a_expr          { $$ = $3; }
    3019         186 :             | DROP DEFAULT              { $$ = NULL; }
    3020             :         ;
    3021             : 
    3022             : opt_collate_clause:
    3023             :             COLLATE any_name
    3024             :                 {
    3025          18 :                     CollateClause *n = makeNode(CollateClause);
    3026             : 
    3027          18 :                     n->arg = NULL;
    3028          18 :                     n->collname = $2;
    3029          18 :                     n->location = @1;
    3030          18 :                     $$ = (Node *) n;
    3031             :                 }
    3032        4808 :             | /* EMPTY */               { $$ = NULL; }
    3033             :         ;
    3034             : 
    3035             : alter_using:
    3036         180 :             USING a_expr                { $$ = $2; }
    3037         844 :             | /* EMPTY */               { $$ = NULL; }
    3038             :         ;
    3039             : 
    3040             : replica_identity:
    3041             :             NOTHING
    3042             :                 {
    3043          48 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3044             : 
    3045          48 :                     n->identity_type = REPLICA_IDENTITY_NOTHING;
    3046          48 :                     n->name = NULL;
    3047          48 :                     $$ = (Node *) n;
    3048             :                 }
    3049             :             | FULL
    3050             :                 {
    3051         166 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3052             : 
    3053         166 :                     n->identity_type = REPLICA_IDENTITY_FULL;
    3054         166 :                     n->name = NULL;
    3055         166 :                     $$ = (Node *) n;
    3056             :                 }
    3057             :             | DEFAULT
    3058             :                 {
    3059           6 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3060             : 
    3061           6 :                     n->identity_type = REPLICA_IDENTITY_DEFAULT;
    3062           6 :                     n->name = NULL;
    3063           6 :                     $$ = (Node *) n;
    3064             :                 }
    3065             :             | USING INDEX name
    3066             :                 {
    3067         270 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3068             : 
    3069         270 :                     n->identity_type = REPLICA_IDENTITY_INDEX;
    3070         270 :                     n->name = $3;
    3071         270 :                     $$ = (Node *) n;
    3072             :                 }
    3073             : ;
    3074             : 
    3075             : reloptions:
    3076        2794 :             '(' reloption_list ')'                  { $$ = $2; }
    3077             :         ;
    3078             : 
    3079        1022 : opt_reloptions:     WITH reloptions                 { $$ = $2; }
    3080       24054 :              |      /* EMPTY */                     { $$ = NIL; }
    3081             :         ;
    3082             : 
    3083             : reloption_list:
    3084        2794 :             reloption_elem                          { $$ = list_make1($1); }
    3085         266 :             | reloption_list ',' reloption_elem     { $$ = lappend($1, $3); }
    3086             :         ;
    3087             : 
    3088             : /* This should match def_elem and also allow qualified names */
    3089             : reloption_elem:
    3090             :             ColLabel '=' def_arg
    3091             :                 {
    3092        2390 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    3093             :                 }
    3094             :             | ColLabel
    3095             :                 {
    3096         590 :                     $$ = makeDefElem($1, NULL, @1);
    3097             :                 }
    3098             :             | ColLabel '.' ColLabel '=' def_arg
    3099             :                 {
    3100          74 :                     $$ = makeDefElemExtended($1, $3, (Node *) $5,
    3101          74 :                                              DEFELEM_UNSPEC, @1);
    3102             :                 }
    3103             :             | ColLabel '.' ColLabel
    3104             :                 {
    3105           6 :                     $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC, @1);
    3106             :                 }
    3107             :         ;
    3108             : 
    3109             : alter_identity_column_option_list:
    3110             :             alter_identity_column_option
    3111          62 :                 { $$ = list_make1($1); }
    3112             :             | alter_identity_column_option_list alter_identity_column_option
    3113          60 :                 { $$ = lappend($1, $2); }
    3114             :         ;
    3115             : 
    3116             : alter_identity_column_option:
    3117             :             RESTART
    3118             :                 {
    3119          24 :                     $$ = makeDefElem("restart", NULL, @1);
    3120             :                 }
    3121             :             | RESTART opt_with NumericOnly
    3122             :                 {
    3123           0 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    3124             :                 }
    3125             :             | SET SeqOptElem
    3126             :                 {
    3127          54 :                     if (strcmp($2->defname, "as") == 0 ||
    3128          54 :                         strcmp($2->defname, "restart") == 0 ||
    3129          54 :                         strcmp($2->defname, "owned_by") == 0)
    3130           0 :                         ereport(ERROR,
    3131             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3132             :                                  errmsg("sequence option \"%s\" not supported here", $2->defname),
    3133             :                                  parser_errposition(@2)));
    3134          54 :                     $$ = $2;
    3135             :                 }
    3136             :             | SET GENERATED generated_when
    3137             :                 {
    3138          44 :                     $$ = makeDefElem("generated", (Node *) makeInteger($3), @1);
    3139             :                 }
    3140             :         ;
    3141             : 
    3142             : set_statistics_value:
    3143         158 :             SignedIconst                    { $$ = (Node *) makeInteger($1); }
    3144           0 :             | DEFAULT                       { $$ = NULL; }
    3145             :         ;
    3146             : 
    3147             : set_access_method_name:
    3148          92 :             ColId                           { $$ = $1; }
    3149          36 :             | DEFAULT                       { $$ = NULL; }
    3150             :         ;
    3151             : 
    3152             : PartitionBoundSpec:
    3153             :             /* a HASH partition */
    3154             :             FOR VALUES WITH '(' hash_partbound ')'
    3155             :                 {
    3156             :                     ListCell   *lc;
    3157         738 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3158             : 
    3159         738 :                     n->strategy = PARTITION_STRATEGY_HASH;
    3160         738 :                     n->modulus = n->remainder = -1;
    3161             : 
    3162        2214 :                     foreach (lc, $5)
    3163             :                     {
    3164        1476 :                         DefElem    *opt = lfirst_node(DefElem, lc);
    3165             : 
    3166        1476 :                         if (strcmp(opt->defname, "modulus") == 0)
    3167             :                         {
    3168         738 :                             if (n->modulus != -1)
    3169           0 :                                 ereport(ERROR,
    3170             :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    3171             :                                          errmsg("modulus for hash partition provided more than once"),
    3172             :                                          parser_errposition(opt->location)));
    3173         738 :                             n->modulus = defGetInt32(opt);
    3174             :                         }
    3175         738 :                         else if (strcmp(opt->defname, "remainder") == 0)
    3176             :                         {
    3177         738 :                             if (n->remainder != -1)
    3178           0 :                                 ereport(ERROR,
    3179             :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    3180             :                                          errmsg("remainder for hash partition provided more than once"),
    3181             :                                          parser_errposition(opt->location)));
    3182         738 :                             n->remainder = defGetInt32(opt);
    3183             :                         }
    3184             :                         else
    3185           0 :                             ereport(ERROR,
    3186             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    3187             :                                      errmsg("unrecognized hash partition bound specification \"%s\"",
    3188             :                                             opt->defname),
    3189             :                                      parser_errposition(opt->location)));
    3190             :                     }
    3191             : 
    3192         738 :                     if (n->modulus == -1)
    3193           0 :                         ereport(ERROR,
    3194             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3195             :                                  errmsg("modulus for hash partition must be specified"),
    3196             :                                  parser_errposition(@3)));
    3197         738 :                     if (n->remainder == -1)
    3198           0 :                         ereport(ERROR,
    3199             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3200             :                                  errmsg("remainder for hash partition must be specified"),
    3201             :                                  parser_errposition(@3)));
    3202             : 
    3203         738 :                     n->location = @3;
    3204             : 
    3205         738 :                     $$ = n;
    3206             :                 }
    3207             : 
    3208             :             /* a LIST partition */
    3209             :             | FOR VALUES IN_P '(' expr_list ')'
    3210             :                 {
    3211        5068 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3212             : 
    3213        5068 :                     n->strategy = PARTITION_STRATEGY_LIST;
    3214        5068 :                     n->is_default = false;
    3215        5068 :                     n->listdatums = $5;
    3216        5068 :                     n->location = @3;
    3217             : 
    3218        5068 :                     $$ = n;
    3219             :                 }
    3220             : 
    3221             :             /* a RANGE partition */
    3222             :             | FOR VALUES FROM '(' expr_list ')' TO '(' expr_list ')'
    3223             :                 {
    3224        4392 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3225             : 
    3226        4392 :                     n->strategy = PARTITION_STRATEGY_RANGE;
    3227        4392 :                     n->is_default = false;
    3228        4392 :                     n->lowerdatums = $5;
    3229        4392 :                     n->upperdatums = $9;
    3230        4392 :                     n->location = @3;
    3231             : 
    3232        4392 :                     $$ = n;
    3233             :                 }
    3234             : 
    3235             :             /* a DEFAULT partition */
    3236             :             | DEFAULT
    3237             :                 {
    3238         622 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3239             : 
    3240         622 :                     n->is_default = true;
    3241         622 :                     n->location = @1;
    3242             : 
    3243         622 :                     $$ = n;
    3244             :                 }
    3245             :         ;
    3246             : 
    3247             : hash_partbound_elem:
    3248             :         NonReservedWord Iconst
    3249             :             {
    3250        1476 :                 $$ = makeDefElem($1, (Node *) makeInteger($2), @1);
    3251             :             }
    3252             :         ;
    3253             : 
    3254             : hash_partbound:
    3255             :         hash_partbound_elem
    3256             :             {
    3257         738 :                 $$ = list_make1($1);
    3258             :             }
    3259             :         | hash_partbound ',' hash_partbound_elem
    3260             :             {
    3261         738 :                 $$ = lappend($1, $3);
    3262             :             }
    3263             :         ;
    3264             : 
    3265             : /*****************************************************************************
    3266             :  *
    3267             :  *  ALTER TYPE
    3268             :  *
    3269             :  * really variants of the ALTER TABLE subcommands with different spellings
    3270             :  *****************************************************************************/
    3271             : 
    3272             : AlterCompositeTypeStmt:
    3273             :             ALTER TYPE_P any_name alter_type_cmds
    3274             :                 {
    3275         210 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    3276             : 
    3277             :                     /* can't use qualified_name, sigh */
    3278         210 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
    3279         210 :                     n->cmds = $4;
    3280         210 :                     n->objtype = OBJECT_TYPE;
    3281         210 :                     $$ = (Node *) n;
    3282             :                 }
    3283             :             ;
    3284             : 
    3285             : alter_type_cmds:
    3286         210 :             alter_type_cmd                          { $$ = list_make1($1); }
    3287          12 :             | alter_type_cmds ',' alter_type_cmd    { $$ = lappend($1, $3); }
    3288             :         ;
    3289             : 
    3290             : alter_type_cmd:
    3291             :             /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
    3292             :             ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
    3293             :                 {
    3294          64 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3295             : 
    3296          64 :                     n->subtype = AT_AddColumn;
    3297          64 :                     n->def = $3;
    3298          64 :                     n->behavior = $4;
    3299          64 :                     $$ = (Node *) n;
    3300             :                 }
    3301             :             /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
    3302             :             | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
    3303             :                 {
    3304           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3305             : 
    3306           6 :                     n->subtype = AT_DropColumn;
    3307           6 :                     n->name = $5;
    3308           6 :                     n->behavior = $6;
    3309           6 :                     n->missing_ok = true;
    3310           6 :                     $$ = (Node *) n;
    3311             :                 }
    3312             :             /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
    3313             :             | DROP ATTRIBUTE ColId opt_drop_behavior
    3314             :                 {
    3315          78 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3316             : 
    3317          78 :                     n->subtype = AT_DropColumn;
    3318          78 :                     n->name = $3;
    3319          78 :                     n->behavior = $4;
    3320          78 :                     n->missing_ok = false;
    3321          78 :                     $$ = (Node *) n;
    3322             :                 }
    3323             :             /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
    3324             :             | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
    3325             :                 {
    3326          74 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3327          74 :                     ColumnDef *def = makeNode(ColumnDef);
    3328             : 
    3329          74 :                     n->subtype = AT_AlterColumnType;
    3330          74 :                     n->name = $3;
    3331          74 :                     n->def = (Node *) def;
    3332          74 :                     n->behavior = $8;
    3333             :                     /* We only use these fields of the ColumnDef node */
    3334          74 :                     def->typeName = $6;
    3335          74 :                     def->collClause = (CollateClause *) $7;
    3336          74 :                     def->raw_default = NULL;
    3337          74 :                     def->location = @3;
    3338          74 :                     $$ = (Node *) n;
    3339             :                 }
    3340             :         ;
    3341             : 
    3342             : 
    3343             : /*****************************************************************************
    3344             :  *
    3345             :  *      QUERY :
    3346             :  *              close <portalname>
    3347             :  *
    3348             :  *****************************************************************************/
    3349             : 
    3350             : ClosePortalStmt:
    3351             :             CLOSE cursor_name
    3352             :                 {
    3353        2212 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3354             : 
    3355        2212 :                     n->portalname = $2;
    3356        2212 :                     $$ = (Node *) n;
    3357             :                 }
    3358             :             | CLOSE ALL
    3359             :                 {
    3360          12 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3361             : 
    3362          12 :                     n->portalname = NULL;
    3363          12 :                     $$ = (Node *) n;
    3364             :                 }
    3365             :         ;
    3366             : 
    3367             : 
    3368             : /*****************************************************************************
    3369             :  *
    3370             :  *      QUERY :
    3371             :  *              COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
    3372             :  *              COPY ( query ) TO file  [WITH] [(options)]
    3373             :  *
    3374             :  *              where 'query' can be one of:
    3375             :  *              { SELECT | UPDATE | INSERT | DELETE }
    3376             :  *
    3377             :  *              and 'file' can be one of:
    3378             :  *              { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
    3379             :  *
    3380             :  *              In the preferred syntax the options are comma-separated
    3381             :  *              and use generic identifiers instead of keywords.  The pre-9.0
    3382             :  *              syntax had a hard-wired, space-separated set of options.
    3383             :  *
    3384             :  *              Really old syntax, from versions 7.2 and prior:
    3385             :  *              COPY [ BINARY ] table FROM/TO file
    3386             :  *                  [ [ USING ] DELIMITERS 'delimiter' ] ]
    3387             :  *                  [ WITH NULL AS 'null string' ]
    3388             :  *              This option placement is not supported with COPY (query...).
    3389             :  *
    3390             :  *****************************************************************************/
    3391             : 
    3392             : CopyStmt:   COPY opt_binary qualified_name opt_column_list
    3393             :             copy_from opt_program copy_file_name copy_delimiter opt_with
    3394             :             copy_options where_clause
    3395             :                 {
    3396       16156 :                     CopyStmt *n = makeNode(CopyStmt);
    3397             : 
    3398       16156 :                     n->relation = $3;
    3399       16156 :                     n->query = NULL;
    3400       16156 :                     n->attlist = $4;
    3401       16156 :                     n->is_from = $5;
    3402       16156 :                     n->is_program = $6;
    3403       16156 :                     n->filename = $7;
    3404       16156 :                     n->whereClause = $11;
    3405             : 
    3406       16156 :                     if (n->is_program && n->filename == NULL)
    3407           0 :                         ereport(ERROR,
    3408             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3409             :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3410             :                                  parser_errposition(@8)));
    3411             : 
    3412       16156 :                     if (!n->is_from && n->whereClause != NULL)
    3413           6 :                         ereport(ERROR,
    3414             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3415             :                                  errmsg("WHERE clause not allowed with COPY TO"),
    3416             :                                  parser_errposition(@11)));
    3417             : 
    3418       16150 :                     n->options = NIL;
    3419             :                     /* Concatenate user-supplied flags */
    3420       16150 :                     if ($2)
    3421          12 :                         n->options = lappend(n->options, $2);
    3422       16150 :                     if ($8)
    3423           0 :                         n->options = lappend(n->options, $8);
    3424       16150 :                     if ($10)
    3425         968 :                         n->options = list_concat(n->options, $10);
    3426       16150 :                     $$ = (Node *) n;
    3427             :                 }
    3428             :             | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
    3429             :                 {
    3430         526 :                     CopyStmt *n = makeNode(CopyStmt);
    3431             : 
    3432         526 :                     n->relation = NULL;
    3433         526 :                     n->query = $3;
    3434         526 :                     n->attlist = NIL;
    3435         526 :                     n->is_from = false;
    3436         526 :                     n->is_program = $6;
    3437         526 :                     n->filename = $7;
    3438         526 :                     n->options = $9;
    3439             : 
    3440         526 :                     if (n->is_program && n->filename == NULL)
    3441           0 :                         ereport(ERROR,
    3442             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3443             :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3444             :                                  parser_errposition(@5)));
    3445             : 
    3446         526 :                     $$ = (Node *) n;
    3447             :                 }
    3448             :         ;
    3449             : 
    3450             : copy_from:
    3451        3108 :             FROM                                    { $$ = true; }
    3452       13048 :             | TO                                    { $$ = false; }
    3453             :         ;
    3454             : 
    3455             : opt_program:
    3456           0 :             PROGRAM                                 { $$ = true; }
    3457       16682 :             | /* EMPTY */                           { $$ = false; }
    3458             :         ;
    3459             : 
    3460             : /*
    3461             :  * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
    3462             :  * used depends on the direction. (It really doesn't make sense to copy from
    3463             :  * stdout. We silently correct the "typo".)        - AY 9/94
    3464             :  */
    3465             : copy_file_name:
    3466         454 :             Sconst                                  { $$ = $1; }
    3467        2718 :             | STDIN                                 { $$ = NULL; }
    3468       13510 :             | STDOUT                                { $$ = NULL; }
    3469             :         ;
    3470             : 
    3471       15984 : copy_options: copy_opt_list                         { $$ = $1; }
    3472         698 :             | '(' copy_generic_opt_list ')'         { $$ = $2; }
    3473             :         ;
    3474             : 
    3475             : /* old COPY option syntax */
    3476             : copy_opt_list:
    3477         504 :             copy_opt_list copy_opt_item             { $$ = lappend($1, $2); }
    3478       15984 :             | /* EMPTY */                           { $$ = NIL; }
    3479             :         ;
    3480             : 
    3481             : copy_opt_item:
    3482             :             BINARY
    3483             :                 {
    3484           0 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3485             :                 }
    3486             :             | FREEZE
    3487             :                 {
    3488          50 :                     $$ = makeDefElem("freeze", (Node *) makeBoolean(true), @1);
    3489             :                 }
    3490             :             | DELIMITER opt_as Sconst
    3491             :                 {
    3492         172 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @1);
    3493             :                 }
    3494             :             | NULL_P opt_as Sconst
    3495             :                 {
    3496          48 :                     $$ = makeDefElem("null", (Node *) makeString($3), @1);
    3497             :                 }
    3498             :             | CSV
    3499             :                 {
    3500         150 :                     $$ = makeDefElem("format", (Node *) makeString("csv"), @1);
    3501             :                 }
    3502             :             | HEADER_P
    3503             :                 {
    3504          18 :                     $$ = makeDefElem("header", (Node *) makeBoolean(true), @1);
    3505             :                 }
    3506             :             | QUOTE opt_as Sconst
    3507             :                 {
    3508          18 :                     $$ = makeDefElem("quote", (Node *) makeString($3), @1);
    3509             :                 }
    3510             :             | ESCAPE opt_as Sconst
    3511             :                 {
    3512          18 :                     $$ = makeDefElem("escape", (Node *) makeString($3), @1);
    3513             :                 }
    3514             :             | FORCE QUOTE columnList
    3515             :                 {
    3516          12 :                     $$ = makeDefElem("force_quote", (Node *) $3, @1);
    3517             :                 }
    3518             :             | FORCE QUOTE '*'
    3519             :                 {
    3520           6 :                     $$ = makeDefElem("force_quote", (Node *) makeNode(A_Star), @1);
    3521             :                 }
    3522             :             | FORCE NOT NULL_P columnList
    3523             :                 {
    3524           0 :                     $$ = makeDefElem("force_not_null", (Node *) $4, @1);
    3525             :                 }
    3526             :             | FORCE NOT NULL_P '*'
    3527             :                 {
    3528           0 :                     $$ = makeDefElem("force_not_null", (Node *) makeNode(A_Star), @1);
    3529             :                 }
    3530             :             | FORCE NULL_P columnList
    3531             :                 {
    3532           0 :                     $$ = makeDefElem("force_null", (Node *) $3, @1);
    3533             :                 }
    3534             :             | FORCE NULL_P '*'
    3535             :                 {
    3536           0 :                     $$ = makeDefElem("force_null", (Node *) makeNode(A_Star), @1);
    3537             :                 }
    3538             :             | ENCODING Sconst
    3539             :                 {
    3540          12 :                     $$ = makeDefElem("encoding", (Node *) makeString($2), @1);
    3541             :                 }
    3542             :         ;
    3543             : 
    3544             : /* The following exist for backward compatibility with very old versions */
    3545             : 
    3546             : opt_binary:
    3547             :             BINARY
    3548             :                 {
    3549          12 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3550             :                 }
    3551       16144 :             | /*EMPTY*/                             { $$ = NULL; }
    3552             :         ;
    3553             : 
    3554             : copy_delimiter:
    3555             :             opt_using DELIMITERS Sconst
    3556             :                 {
    3557           0 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @2);
    3558             :                 }
    3559       16156 :             | /*EMPTY*/                             { $$ = NULL; }
    3560             :         ;
    3561             : 
    3562             : opt_using:
    3563             :             USING
    3564             :             | /*EMPTY*/
    3565             :         ;
    3566             : 
    3567             : /* new COPY option syntax */
    3568             : copy_generic_opt_list:
    3569             :             copy_generic_opt_elem
    3570             :                 {
    3571         698 :                     $$ = list_make1($1);
    3572             :                 }
    3573             :             | copy_generic_opt_list ',' copy_generic_opt_elem
    3574             :                 {
    3575         468 :                     $$ = lappend($1, $3);
    3576             :                 }
    3577             :         ;
    3578             : 
    3579             : copy_generic_opt_elem:
    3580             :             ColLabel copy_generic_opt_arg
    3581             :                 {
    3582        1166 :                     $$ = makeDefElem($1, $2, @1);
    3583             :                 }
    3584             :         ;
    3585             : 
    3586             : copy_generic_opt_arg:
    3587         818 :             opt_boolean_or_string           { $$ = (Node *) makeString($1); }
    3588          60 :             | NumericOnly                   { $$ = (Node *) $1; }
    3589          90 :             | '*'                           { $$ = (Node *) makeNode(A_Star); }
    3590           6 :             | DEFAULT                       { $$ = (Node *) makeString("default"); }
    3591         150 :             | '(' copy_generic_opt_arg_list ')'     { $$ = (Node *) $2; }
    3592          42 :             | /* EMPTY */                   { $$ = NULL; }
    3593             :         ;
    3594             : 
    3595             : copy_generic_opt_arg_list:
    3596             :               copy_generic_opt_arg_list_item
    3597             :                 {
    3598         150 :                     $$ = list_make1($1);
    3599             :                 }
    3600             :             | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
    3601             :                 {
    3602          12 :                     $$ = lappend($1, $3);
    3603             :                 }
    3604             :         ;
    3605             : 
    3606             : /* beware of emitting non-string list elements here; see commands/define.c */
    3607             : copy_generic_opt_arg_list_item:
    3608         162 :             opt_boolean_or_string   { $$ = (Node *) makeString($1); }
    3609             :         ;
    3610             : 
    3611             : 
    3612             : /*****************************************************************************
    3613             :  *
    3614             :  *      QUERY :
    3615             :  *              CREATE TABLE relname
    3616             :  *
    3617             :  *****************************************************************************/
    3618             : 
    3619             : CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
    3620             :             OptInherit OptPartitionSpec table_access_method_clause OptWith
    3621             :             OnCommitOption OptTableSpace
    3622             :                 {
    3623       30856 :                     CreateStmt *n = makeNode(CreateStmt);
    3624             : 
    3625       30856 :                     $4->relpersistence = $2;
    3626       30856 :                     n->relation = $4;
    3627       30856 :                     n->tableElts = $6;
    3628       30856 :                     n->inhRelations = $8;
    3629       30856 :                     n->partspec = $9;
    3630       30856 :                     n->ofTypename = NULL;
    3631       30856 :                     n->constraints = NIL;
    3632       30856 :                     n->accessMethod = $10;
    3633       30856 :                     n->options = $11;
    3634       30856 :                     n->oncommit = $12;
    3635       30856 :                     n->tablespacename = $13;
    3636       30856 :                     n->if_not_exists = false;
    3637       30856 :                     $$ = (Node *) n;
    3638             :                 }
    3639             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
    3640             :             OptTableElementList ')' OptInherit OptPartitionSpec table_access_method_clause
    3641             :             OptWith OnCommitOption OptTableSpace
    3642             :                 {
    3643          30 :                     CreateStmt *n = makeNode(CreateStmt);
    3644             : 
    3645          30 :                     $7->relpersistence = $2;
    3646          30 :                     n->relation = $7;
    3647          30 :                     n->tableElts = $9;
    3648          30 :                     n->inhRelations = $11;
    3649          30 :                     n->partspec = $12;
    3650          30 :                     n->ofTypename = NULL;
    3651          30 :                     n->constraints = NIL;
    3652          30 :                     n->accessMethod = $13;
    3653          30 :                     n->options = $14;
    3654          30 :                     n->oncommit = $15;
    3655          30 :                     n->tablespacename = $16;
    3656          30 :                     n->if_not_exists = true;
    3657          30 :                     $$ = (Node *) n;
    3658             :                 }
    3659             :         | CREATE OptTemp TABLE qualified_name OF any_name
    3660             :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3661             :             OptWith OnCommitOption OptTableSpace
    3662             :                 {
    3663         134 :                     CreateStmt *n = makeNode(CreateStmt);
    3664             : 
    3665         134 :                     $4->relpersistence = $2;
    3666         134 :                     n->relation = $4;
    3667         134 :                     n->tableElts = $7;
    3668         134 :                     n->inhRelations = NIL;
    3669         134 :                     n->partspec = $8;
    3670         134 :                     n->ofTypename = makeTypeNameFromNameList($6);
    3671         134 :                     n->ofTypename->location = @6;
    3672         134 :                     n->constraints = NIL;
    3673         134 :                     n->accessMethod = $9;
    3674         134 :                     n->options = $10;
    3675         134 :                     n->oncommit = $11;
    3676         134 :                     n->tablespacename = $12;
    3677         134 :                     n->if_not_exists = false;
    3678         134 :                     $$ = (Node *) n;
    3679             :                 }
    3680             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
    3681             :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3682             :             OptWith OnCommitOption OptTableSpace
    3683             :                 {
    3684           6 :                     CreateStmt *n = makeNode(CreateStmt);
    3685             : 
    3686           6 :                     $7->relpersistence = $2;
    3687           6 :                     n->relation = $7;
    3688           6 :                     n->tableElts = $10;
    3689           6 :                     n->inhRelations = NIL;
    3690           6 :                     n->partspec = $11;
    3691           6 :                     n->ofTypename = makeTypeNameFromNameList($9);
    3692           6 :                     n->ofTypename->location = @9;
    3693           6 :                     n->constraints = NIL;
    3694           6 :                     n->accessMethod = $12;
    3695           6 :                     n->options = $13;
    3696           6 :                     n->oncommit = $14;
    3697           6 :                     n->tablespacename = $15;
    3698           6 :                     n->if_not_exists = true;
    3699           6 :                     $$ = (Node *) n;
    3700             :                 }
    3701             :         | CREATE OptTemp TABLE qualified_name PARTITION OF qualified_name
    3702             :             OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3703             :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3704             :                 {
    3705        7898 :                     CreateStmt *n = makeNode(CreateStmt);
    3706             : 
    3707        7898 :                     $4->relpersistence = $2;
    3708        7898 :                     n->relation = $4;
    3709        7898 :                     n->tableElts = $8;
    3710        7898 :                     n->inhRelations = list_make1($7);
    3711        7898 :                     n->partbound = $9;
    3712        7898 :                     n->partspec = $10;
    3713        7898 :                     n->ofTypename = NULL;
    3714        7898 :                     n->constraints = NIL;
    3715        7898 :                     n->accessMethod = $11;
    3716        7898 :                     n->options = $12;
    3717        7898 :                     n->oncommit = $13;
    3718        7898 :                     n->tablespacename = $14;
    3719        7898 :                     n->if_not_exists = false;
    3720        7898 :                     $$ = (Node *) n;
    3721             :                 }
    3722             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name PARTITION OF
    3723             :             qualified_name OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3724             :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3725             :                 {
    3726           0 :                     CreateStmt *n = makeNode(CreateStmt);
    3727             : 
    3728           0 :                     $7->relpersistence = $2;
    3729           0 :                     n->relation = $7;
    3730           0 :                     n->tableElts = $11;
    3731           0 :                     n->inhRelations = list_make1($10);
    3732           0 :                     n->partbound = $12;
    3733           0 :                     n->partspec = $13;
    3734           0 :                     n->ofTypename = NULL;
    3735           0 :                     n->constraints = NIL;
    3736           0 :                     n->accessMethod = $14;
    3737           0 :                     n->options = $15;
    3738           0 :                     n->oncommit = $16;
    3739           0 :                     n->tablespacename = $17;
    3740           0 :                     n->if_not_exists = true;
    3741           0 :                     $$ = (Node *) n;
    3742             :                 }
    3743             :         ;
    3744             : 
    3745             : /*
    3746             :  * Redundancy here is needed to avoid shift/reduce conflicts,
    3747             :  * since TEMP is not a reserved word.  See also OptTempTableName.
    3748             :  *
    3749             :  * NOTE: we accept both GLOBAL and LOCAL options.  They currently do nothing,
    3750             :  * but future versions might consider GLOBAL to request SQL-spec-compliant
    3751             :  * temp table behavior, so warn about that.  Since we have no modules the
    3752             :  * LOCAL keyword is really meaningless; furthermore, some other products
    3753             :  * implement LOCAL as meaning the same as our default temp table behavior,
    3754             :  * so we'll probably continue to treat LOCAL as a noise word.
    3755             :  */
    3756         336 : OptTemp:    TEMPORARY                   { $$ = RELPERSISTENCE_TEMP; }
    3757        2732 :             | TEMP                      { $$ = RELPERSISTENCE_TEMP; }
    3758           0 :             | LOCAL TEMPORARY           { $$ = RELPERSISTENCE_TEMP; }
    3759           0 :             | LOCAL TEMP                { $$ = RELPERSISTENCE_TEMP; }
    3760             :             | GLOBAL TEMPORARY
    3761             :                 {
    3762           0 :                     ereport(WARNING,
    3763             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3764             :                              parser_errposition(@1)));
    3765           0 :                     $$ = RELPERSISTENCE_TEMP;
    3766             :                 }
    3767             :             | GLOBAL TEMP
    3768             :                 {
    3769           0 :                     ereport(WARNING,
    3770             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3771             :                              parser_errposition(@1)));
    3772           0 :                     $$ = RELPERSISTENCE_TEMP;
    3773             :                 }
    3774         168 :             | UNLOGGED                  { $$ = RELPERSISTENCE_UNLOGGED; }
    3775       55234 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    3776             :         ;
    3777             : 
    3778             : OptTableElementList:
    3779       29668 :             TableElementList                    { $$ = $1; }
    3780        1654 :             | /*EMPTY*/                         { $$ = NIL; }
    3781             :         ;
    3782             : 
    3783             : OptTypedTableElementList:
    3784         354 :             '(' TypedTableElementList ')'       { $$ = $2; }
    3785        7780 :             | /*EMPTY*/                         { $$ = NIL; }
    3786             :         ;
    3787             : 
    3788             : TableElementList:
    3789             :             TableElement
    3790             :                 {
    3791       29722 :                     $$ = list_make1($1);
    3792             :                 }
    3793             :             | TableElementList ',' TableElement
    3794             :                 {
    3795       44426 :                     $$ = lappend($1, $3);
    3796             :                 }
    3797             :         ;
    3798             : 
    3799             : TypedTableElementList:
    3800             :             TypedTableElement
    3801             :                 {
    3802         354 :                     $$ = list_make1($1);
    3803             :                 }
    3804             :             | TypedTableElementList ',' TypedTableElement
    3805             :                 {
    3806          70 :                     $$ = lappend($1, $3);
    3807             :                 }
    3808             :         ;
    3809             : 
    3810             : TableElement:
    3811       70618 :             columnDef                           { $$ = $1; }
    3812         774 :             | TableLikeClause                   { $$ = $1; }
    3813        2756 :             | TableConstraint                   { $$ = $1; }
    3814             :         ;
    3815             : 
    3816             : TypedTableElement:
    3817         354 :             columnOptions                       { $$ = $1; }
    3818          70 :             | TableConstraint                   { $$ = $1; }
    3819             :         ;
    3820             : 
    3821             : columnDef:  ColId Typename opt_column_storage opt_column_compression create_generic_options ColQualList
    3822             :                 {
    3823       72766 :                     ColumnDef *n = makeNode(ColumnDef);
    3824             : 
    3825       72766 :                     n->colname = $1;
    3826       72766 :                     n->typeName = $2;
    3827       72766 :                     n->storage_name = $3;
    3828       72766 :                     n->compression = $4;
    3829       72766 :                     n->inhcount = 0;
    3830       72766 :                     n->is_local = true;
    3831       72766 :                     n->is_not_null = false;
    3832       72766 :                     n->is_from_type = false;
    3833       72766 :                     n->storage = 0;
    3834       72766 :                     n->raw_default = NULL;
    3835       72766 :                     n->cooked_default = NULL;
    3836       72766 :                     n->collOid = InvalidOid;
    3837       72766 :                     n->fdwoptions = $5;
    3838       72766 :                     SplitColQualList($6, &n->constraints, &n->collClause,
    3839             :                                      yyscanner);
    3840       72766 :                     n->location = @1;
    3841       72766 :                     $$ = (Node *) n;
    3842             :                 }
    3843             :         ;
    3844             : 
    3845             : columnOptions:  ColId ColQualList
    3846             :                 {
    3847         146 :                     ColumnDef *n = makeNode(ColumnDef);
    3848             : 
    3849         146 :                     n->colname = $1;
    3850         146 :                     n->typeName = NULL;
    3851         146 :                     n->inhcount = 0;
    3852         146 :                     n->is_local = true;
    3853         146 :                     n->is_not_null = false;
    3854         146 :                     n->is_from_type = false;
    3855         146 :                     n->storage = 0;
    3856         146 :                     n->raw_default = NULL;
    3857         146 :                     n->cooked_default = NULL;
    3858         146 :                     n->collOid = InvalidOid;
    3859         146 :                     SplitColQualList($2, &n->constraints, &n->collClause,
    3860             :                                      yyscanner);
    3861         146 :                     n->location = @1;
    3862         146 :                     $$ = (Node *) n;
    3863             :                 }
    3864             :                 | ColId WITH OPTIONS ColQualList
    3865             :                 {
    3866         208 :                     ColumnDef *n = makeNode(ColumnDef);
    3867             : 
    3868         208 :                     n->colname = $1;
    3869         208 :                     n->typeName = NULL;
    3870         208 :                     n->inhcount = 0;
    3871         208 :                     n->is_local = true;
    3872         208 :                     n->is_not_null = false;
    3873         208 :                     n->is_from_type = false;
    3874         208 :                     n->storage = 0;
    3875         208 :                     n->raw_default = NULL;
    3876         208 :                     n->cooked_default = NULL;
    3877         208 :                     n->collOid = InvalidOid;
    3878         208 :                     SplitColQualList($4, &n->constraints, &n->collClause,
    3879             :                                      yyscanner);
    3880         208 :                     n->location = @1;
    3881         208 :                     $$ = (Node *) n;
    3882             :                 }
    3883             :         ;
    3884             : 
    3885             : column_compression:
    3886         192 :             COMPRESSION ColId                       { $$ = $2; }
    3887           6 :             | COMPRESSION DEFAULT                   { $$ = pstrdup("default"); }
    3888             :         ;
    3889             : 
    3890             : opt_column_compression:
    3891          94 :             column_compression                      { $$ = $1; }
    3892       72738 :             | /*EMPTY*/                             { $$ = NULL; }
    3893             :         ;
    3894             : 
    3895             : column_storage:
    3896         238 :             STORAGE ColId                           { $$ = $2; }
    3897           6 :             | STORAGE DEFAULT                       { $$ = pstrdup("default"); }
    3898             :         ;
    3899             : 
    3900             : opt_column_storage:
    3901          20 :             column_storage                          { $$ = $1; }
    3902       72812 :             | /*EMPTY*/                             { $$ = NULL; }
    3903             :         ;
    3904             : 
    3905             : ColQualList:
    3906       20474 :             ColQualList ColConstraint               { $$ = lappend($1, $2); }
    3907       74696 :             | /*EMPTY*/                             { $$ = NIL; }
    3908             :         ;
    3909             : 
    3910             : ColConstraint:
    3911             :             CONSTRAINT name ColConstraintElem
    3912             :                 {
    3913         958 :                     Constraint *n = castNode(Constraint, $3);
    3914             : 
    3915         958 :                     n->conname = $2;
    3916         958 :                     n->location = @1;
    3917         958 :                     $$ = (Node *) n;
    3918             :                 }
    3919       18454 :             | ColConstraintElem                     { $$ = $1; }
    3920         294 :             | ConstraintAttr                        { $$ = $1; }
    3921             :             | COLLATE any_name
    3922             :                 {
    3923             :                     /*
    3924             :                      * Note: the CollateClause is momentarily included in
    3925             :                      * the list built by ColQualList, but we split it out
    3926             :                      * again in SplitColQualList.
    3927             :                      */
    3928         768 :                     CollateClause *n = makeNode(CollateClause);
    3929             : 
    3930         768 :                     n->arg = NULL;
    3931         768 :                     n->collname = $2;
    3932         768 :                     n->location = @1;
    3933         768 :                     $$ = (Node *) n;
    3934             :                 }
    3935             :         ;
    3936             : 
    3937             : /* DEFAULT NULL is already the default for Postgres.
    3938             :  * But define it here and carry it forward into the system
    3939             :  * to make it explicit.
    3940             :  * - thomas 1998-09-13
    3941             :  *
    3942             :  * WITH NULL and NULL are not SQL-standard syntax elements,
    3943             :  * so leave them out. Use DEFAULT NULL to explicitly indicate
    3944             :  * that a column may have that value. WITH NULL leads to
    3945             :  * shift/reduce conflicts with WITH TIME ZONE anyway.
    3946             :  * - thomas 1999-01-08
    3947             :  *
    3948             :  * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
    3949             :  * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
    3950             :  * or be part of a_expr NOT LIKE or similar constructs).
    3951             :  */
    3952             : ColConstraintElem:
    3953             :             NOT NULL_P opt_no_inherit
    3954             :                 {
    3955        7152 :                     Constraint *n = makeNode(Constraint);
    3956             : 
    3957        7152 :                     n->contype = CONSTR_NOTNULL;
    3958        7152 :                     n->location = @1;
    3959        7152 :                     n->is_no_inherit = $3;
    3960        7152 :                     n->is_enforced = true;
    3961        7152 :                     n->skip_validation = false;
    3962        7152 :                     n->initially_valid = true;
    3963        7152 :                     $$ = (Node *) n;
    3964             :                 }
    3965             :             | NULL_P
    3966             :                 {
    3967          30 :                     Constraint *n = makeNode(Constraint);
    3968             : 
    3969          30 :                     n->contype = CONSTR_NULL;
    3970          30 :                     n->location = @1;
    3971          30 :                     $$ = (Node *) n;
    3972             :                 }
    3973             :             | UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace
    3974             :                 {
    3975         444 :                     Constraint *n = makeNode(Constraint);
    3976             : 
    3977         444 :                     n->contype = CONSTR_UNIQUE;
    3978         444 :                     n->location = @1;
    3979         444 :                     n->nulls_not_distinct = !$2;
    3980         444 :                     n->keys = NULL;
    3981         444 :                     n->options = $3;
    3982         444 :                     n->indexname = NULL;
    3983         444 :                     n->indexspace = $4;
    3984         444 :                     $$ = (Node *) n;
    3985             :                 }
    3986             :             | PRIMARY KEY opt_definition OptConsTableSpace
    3987             :                 {
    3988        5772 :                     Constraint *n = makeNode(Constraint);
    3989             : 
    3990        5772 :                     n->contype = CONSTR_PRIMARY;
    3991        5772 :                     n->location = @1;
    3992        5772 :                     n->keys = NULL;
    3993        5772 :                     n->options = $3;
    3994        5772 :                     n->indexname = NULL;
    3995        5772 :                     n->indexspace = $4;
    3996        5772 :                     $$ = (Node *) n;
    3997             :                 }
    3998             :             | CHECK '(' a_expr ')' opt_no_inherit
    3999             :                 {
    4000        1118 :                     Constraint *n = makeNode(Constraint);
    4001             : 
    4002        1118 :                     n->contype = CONSTR_CHECK;
    4003        1118 :                     n->location = @1;
    4004        1118 :                     n->is_no_inherit = $5;
    4005        1118 :                     n->raw_expr = $3;
    4006        1118 :                     n->cooked_expr = NULL;
    4007        1118 :                     n->is_enforced = true;
    4008        1118 :                     n->skip_validation = false;
    4009        1118 :                     n->initially_valid = true;
    4010        1118 :                     $$ = (Node *) n;
    4011             :                 }
    4012             :             | DEFAULT b_expr
    4013             :                 {
    4014        1898 :                     Constraint *n = makeNode(Constraint);
    4015             : 
    4016        1898 :                     n->contype = CONSTR_DEFAULT;
    4017        1898 :                     n->location = @1;
    4018        1898 :                     n->raw_expr = $2;
    4019        1898 :                     n->cooked_expr = NULL;
    4020        1898 :                     $$ = (Node *) n;
    4021             :                 }
    4022             :             | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    4023             :                 {
    4024         330 :                     Constraint *n = makeNode(Constraint);
    4025             : 
    4026         330 :                     n->contype = CONSTR_IDENTITY;
    4027         330 :                     n->generated_when = $2;
    4028         330 :                     n->options = $5;
    4029         330 :                     n->location = @1;
    4030         330 :                     $$ = (Node *) n;
    4031             :                 }
    4032             :             | GENERATED generated_when AS '(' a_expr ')' opt_virtual_or_stored
    4033             :                 {
    4034        1852 :                     Constraint *n = makeNode(Constraint);
    4035             : 
    4036        1852 :                     n->contype = CONSTR_GENERATED;
    4037        1852 :                     n->generated_when = $2;
    4038        1852 :                     n->raw_expr = $5;
    4039        1852 :                     n->cooked_expr = NULL;
    4040        1852 :                     n->generated_kind = $7;
    4041        1852 :                     n->location = @1;
    4042             : 
    4043             :                     /*
    4044             :                      * Can't do this in the grammar because of shift/reduce
    4045             :                      * conflicts.  (IDENTITY allows both ALWAYS and BY
    4046             :                      * DEFAULT, but generated columns only allow ALWAYS.)  We
    4047             :                      * can also give a more useful error message and location.
    4048             :                      */
    4049        1852 :                     if ($2 != ATTRIBUTE_IDENTITY_ALWAYS)
    4050          12 :                         ereport(ERROR,
    4051             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    4052             :                                  errmsg("for a generated column, GENERATED ALWAYS must be specified"),
    4053             :                                  parser_errposition(@2)));
    4054             : 
    4055        1840 :                     $$ = (Node *) n;
    4056             :                 }
    4057             :             | REFERENCES qualified_name opt_column_list key_match key_actions
    4058             :                 {
    4059         828 :                     Constraint *n = makeNode(Constraint);
    4060             : 
    4061         828 :                     n->contype = CONSTR_FOREIGN;
    4062         828 :                     n->location = @1;
    4063         828 :                     n->pktable = $2;
    4064         828 :                     n->fk_attrs = NIL;
    4065         828 :                     n->pk_attrs = $3;
    4066         828 :                     n->fk_matchtype = $4;
    4067         828 :                     n->fk_upd_action = ($5)->updateAction->action;
    4068         828 :                     n->fk_del_action = ($5)->deleteAction->action;
    4069         828 :                     n->fk_del_set_cols = ($5)->deleteAction->cols;
    4070         828 :                     n->is_enforced = true;
    4071         828 :                     n->skip_validation = false;
    4072         828 :                     n->initially_valid = true;
    4073         828 :                     $$ = (Node *) n;
    4074             :                 }
    4075             :         ;
    4076             : 
    4077             : opt_unique_null_treatment:
    4078          12 :             NULLS_P DISTINCT        { $$ = true; }
    4079          36 :             | NULLS_P NOT DISTINCT  { $$ = false; }
    4080        8026 :             | /*EMPTY*/             { $$ = true; }
    4081             :         ;
    4082             : 
    4083             : generated_when:
    4084        2238 :             ALWAYS          { $$ = ATTRIBUTE_IDENTITY_ALWAYS; }
    4085         198 :             | BY DEFAULT    { $$ = ATTRIBUTE_IDENTITY_BY_DEFAULT; }
    4086             :         ;
    4087             : 
    4088             : opt_virtual_or_stored:
    4089        1038 :             STORED          { $$ = ATTRIBUTE_GENERATED_STORED; }
    4090         634 :             | VIRTUAL       { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
    4091         180 :             | /*EMPTY*/     { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
    4092             :         ;
    4093             : 
    4094             : /*
    4095             :  * ConstraintAttr represents constraint attributes, which we parse as if
    4096             :  * they were independent constraint clauses, in order to avoid shift/reduce
    4097             :  * conflicts (since NOT might start either an independent NOT NULL clause
    4098             :  * or an attribute).  parse_utilcmd.c is responsible for attaching the
    4099             :  * attribute information to the preceding "real" constraint node, and for
    4100             :  * complaining if attribute clauses appear in the wrong place or wrong
    4101             :  * combinations.
    4102             :  *
    4103             :  * See also ConstraintAttributeSpec, which can be used in places where
    4104             :  * there is no parsing conflict.  (Note: currently, NOT VALID and NO INHERIT
    4105             :  * are allowed clauses in ConstraintAttributeSpec, but not here.  Someday we
    4106             :  * might need to allow them here too, but for the moment it doesn't seem
    4107             :  * useful in the statements that use ConstraintAttr.)
    4108             :  */
    4109             : ConstraintAttr:
    4110             :             DEFERRABLE
    4111             :                 {
    4112         102 :                     Constraint *n = makeNode(Constraint);
    4113             : 
    4114         102 :                     n->contype = CONSTR_ATTR_DEFERRABLE;
    4115         102 :                     n->location = @1;
    4116         102 :                     $$ = (Node *) n;
    4117             :                 }
    4118             :             | NOT DEFERRABLE
    4119             :                 {
    4120           0 :                     Constraint *n = makeNode(Constraint);
    4121             : 
    4122           0 :                     n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
    4123           0 :                     n->location = @1;
    4124           0 :                     $$ = (Node *) n;
    4125             :                 }
    4126             :             | INITIALLY DEFERRED
    4127             :                 {
    4128          78 :                     Constraint *n = makeNode(Constraint);
    4129             : 
    4130          78 :                     n->contype = CONSTR_ATTR_DEFERRED;
    4131          78 :                     n->location = @1;
    4132          78 :                     $$ = (Node *) n;
    4133             :                 }
    4134             :             | INITIALLY IMMEDIATE
    4135             :                 {
    4136           6 :                     Constraint *n = makeNode(Constraint);
    4137             : 
    4138           6 :                     n->contype = CONSTR_ATTR_IMMEDIATE;
    4139           6 :                     n->location = @1;
    4140           6 :                     $$ = (Node *) n;
    4141             :                 }
    4142             :             | ENFORCED
    4143             :                 {
    4144          42 :                     Constraint *n = makeNode(Constraint);
    4145             : 
    4146          42 :                     n->contype = CONSTR_ATTR_ENFORCED;
    4147          42 :                     n->location = @1;
    4148          42 :                     $$ = (Node *) n;
    4149             :                 }
    4150             :             | NOT ENFORCED
    4151             :                 {
    4152          66 :                     Constraint *n = makeNode(Constraint);
    4153             : 
    4154          66 :                     n->contype = CONSTR_ATTR_NOT_ENFORCED;
    4155          66 :                     n->location = @1;
    4156          66 :                     $$ = (Node *) n;
    4157             :                 }
    4158             :         ;
    4159             : 
    4160             : 
    4161             : TableLikeClause:
    4162             :             LIKE qualified_name TableLikeOptionList
    4163             :                 {
    4164         774 :                     TableLikeClause *n = makeNode(TableLikeClause);
    4165             : 
    4166         774 :                     n->relation = $2;
    4167         774 :                     n->options = $3;
    4168         774 :                     n->relationOid = InvalidOid;
    4169         774 :                     $$ = (Node *) n;
    4170             :                 }
    4171             :         ;
    4172             : 
    4173             : TableLikeOptionList:
    4174         288 :                 TableLikeOptionList INCLUDING TableLikeOption   { $$ = $1 | $3; }
    4175           8 :                 | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
    4176         774 :                 | /* EMPTY */                       { $$ = 0; }
    4177             :         ;
    4178             : 
    4179             : TableLikeOption:
    4180          30 :                 COMMENTS            { $$ = CREATE_TABLE_LIKE_COMMENTS; }
    4181           6 :                 | COMPRESSION       { $$ = CREATE_TABLE_LIKE_COMPRESSION; }
    4182          54 :                 | CONSTRAINTS       { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
    4183          20 :                 | DEFAULTS          { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
    4184          12 :                 | IDENTITY_P        { $$ = CREATE_TABLE_LIKE_IDENTITY; }
    4185          30 :                 | GENERATED         { $$ = CREATE_TABLE_LIKE_GENERATED; }
    4186          50 :                 | INDEXES           { $$ = CREATE_TABLE_LIKE_INDEXES; }
    4187           0 :                 | STATISTICS        { $$ = CREATE_TABLE_LIKE_STATISTICS; }
    4188          26 :                 | STORAGE           { $$ = CREATE_TABLE_LIKE_STORAGE; }
    4189          68 :                 | ALL               { $$ = CREATE_TABLE_LIKE_ALL; }
    4190             :         ;
    4191             : 
    4192             : 
    4193             : /* ConstraintElem specifies constraint syntax which is not embedded into
    4194             :  *  a column definition. ColConstraintElem specifies the embedded form.
    4195             :  * - thomas 1997-12-03
    4196             :  */
    4197             : TableConstraint:
    4198             :             CONSTRAINT name ConstraintElem
    4199             :                 {
    4200        4506 :                     Constraint *n = castNode(Constraint, $3);
    4201             : 
    4202        4506 :                     n->conname = $2;
    4203        4506 :                     n->location = @1;
    4204        4506 :                     $$ = (Node *) n;
    4205             :                 }
    4206       13428 :             | ConstraintElem                        { $$ = $1; }
    4207             :         ;
    4208             : 
    4209             : ConstraintElem:
    4210             :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    4211             :                 {
    4212        1344 :                     Constraint *n = makeNode(Constraint);
    4213             : 
    4214        1344 :                     n->contype = CONSTR_CHECK;
    4215        1344 :                     n->location = @1;
    4216        1344 :                     n->raw_expr = $3;
    4217        1344 :                     n->cooked_expr = NULL;
    4218        1344 :                     processCASbits($5, @5, "CHECK",
    4219             :                                    NULL, NULL, &n->is_enforced, &n->skip_validation,
    4220             :                                    &n->is_no_inherit, yyscanner);
    4221        1344 :                     n->initially_valid = !n->skip_validation;
    4222        1344 :                     $$ = (Node *) n;
    4223             :                 }
    4224             :             | NOT NULL_P ColId ConstraintAttributeSpec
    4225             :                 {
    4226         622 :                     Constraint *n = makeNode(Constraint);
    4227             : 
    4228         622 :                     n->contype = CONSTR_NOTNULL;
    4229         622 :                     n->location = @1;
    4230         622 :                     n->keys = list_make1(makeString($3));
    4231         622 :                     processCASbits($4, @4, "NOT NULL",
    4232             :                                    NULL, NULL, NULL, &n->skip_validation,
    4233             :                                    &n->is_no_inherit, yyscanner);
    4234         622 :                     n->initially_valid = !n->skip_validation;
    4235         622 :                     $$ = (Node *) n;
    4236             :                 }
    4237             :             | UNIQUE opt_unique_null_treatment '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
    4238             :                 ConstraintAttributeSpec
    4239             :                 {
    4240         612 :                     Constraint *n = makeNode(Constraint);
    4241             : 
    4242         612 :                     n->contype = CONSTR_UNIQUE;
    4243         612 :                     n->location = @1;
    4244         612 :                     n->nulls_not_distinct = !$2;
    4245         612 :                     n->keys = $4;
    4246         612 :                     n->without_overlaps = $5;
    4247         612 :                     n->including = $7;
    4248         612 :                     n->options = $8;
    4249         612 :                     n->indexname = NULL;
    4250         612 :                     n->indexspace = $9;
    4251         612 :                     processCASbits($10, @10, "UNIQUE",
    4252             :                                    &n->deferrable, &n->initdeferred, NULL,
    4253             :                                    NULL, NULL, yyscanner);
    4254         612 :                     $$ = (Node *) n;
    4255             :                 }
    4256             :             | UNIQUE ExistingIndex ConstraintAttributeSpec
    4257             :                 {
    4258        4744 :                     Constraint *n = makeNode(Constraint);
    4259             : 
    4260        4744 :                     n->contype = CONSTR_UNIQUE;
    4261        4744 :                     n->location = @1;
    4262        4744 :                     n->keys = NIL;
    4263        4744 :                     n->including = NIL;
    4264        4744 :                     n->options = NIL;
    4265        4744 :                     n->indexname = $2;
    4266        4744 :                     n->indexspace = NULL;
    4267        4744 :                     processCASbits($3, @3, "UNIQUE",
    4268             :                                    &n->deferrable, &n->initdeferred, NULL,
    4269             :                                    NULL, NULL, yyscanner);
    4270        4744 :                     $$ = (Node *) n;
    4271             :                 }
    4272             :             | PRIMARY KEY '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
    4273             :                 ConstraintAttributeSpec
    4274             :                 {
    4275        2386 :                     Constraint *n = makeNode(Constraint);
    4276             : 
    4277        2386 :                     n->contype = CONSTR_PRIMARY;
    4278        2386 :                     n->location = @1;
    4279        2386 :                     n->keys = $4;
    4280        2386 :                     n->without_overlaps = $5;
    4281        2386 :                     n->including = $7;
    4282        2386 :                     n->options = $8;
    4283        2386 :                     n->indexname = NULL;
    4284        2386 :                     n->indexspace = $9;
    4285        2386 :                     processCASbits($10, @10, "PRIMARY KEY",
    4286             :                                    &n->deferrable, &n->initdeferred, NULL,
    4287             :                                    NULL, NULL, yyscanner);
    4288        2386 :                     $$ = (Node *) n;
    4289             :                 }
    4290             :             | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
    4291             :                 {
    4292        6142 :                     Constraint *n = makeNode(Constraint);
    4293             : 
    4294        6142 :                     n->contype = CONSTR_PRIMARY;
    4295        6142 :                     n->location = @1;
    4296        6142 :                     n->keys = NIL;
    4297        6142 :                     n->including = NIL;
    4298        6142 :                     n->options = NIL;
    4299        6142 :                     n->indexname = $3;
    4300        6142 :                     n->indexspace = NULL;
    4301        6142 :                     processCASbits($4, @4, "PRIMARY KEY",
    4302             :                                    &n->deferrable, &n->initdeferred, NULL,
    4303             :                                    NULL, NULL, yyscanner);
    4304        6142 :                     $$ = (Node *) n;
    4305             :                 }
    4306             :             | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
    4307             :                 opt_c_include opt_definition OptConsTableSpace OptWhereClause
    4308             :                 ConstraintAttributeSpec
    4309             :                 {
    4310         238 :                     Constraint *n = makeNode(Constraint);
    4311             : 
    4312         238 :                     n->contype = CONSTR_EXCLUSION;
    4313         238 :                     n->location = @1;
    4314         238 :                     n->access_method = $2;
    4315         238 :                     n->exclusions = $4;
    4316         238 :                     n->including = $6;
    4317         238 :                     n->options = $7;
    4318         238 :                     n->indexname = NULL;
    4319         238 :                     n->indexspace = $8;
    4320         238 :                     n->where_clause = $9;
    4321         238 :                     processCASbits($10, @10, "EXCLUDE",
    4322             :                                    &n->deferrable, &n->initdeferred, NULL,
    4323             :                                    NULL, NULL, yyscanner);
    4324         238 :                     $$ = (Node *) n;
    4325             :                 }
    4326             :             | FOREIGN KEY '(' columnList optionalPeriodName ')' REFERENCES qualified_name
    4327             :                 opt_column_and_period_list key_match key_actions ConstraintAttributeSpec
    4328             :                 {
    4329        1846 :                     Constraint *n = makeNode(Constraint);
    4330             : 
    4331        1846 :                     n->contype = CONSTR_FOREIGN;
    4332        1846 :                     n->location = @1;
    4333        1846 :                     n->pktable = $8;
    4334        1846 :                     n->fk_attrs = $4;
    4335        1846 :                     if ($5)
    4336             :                     {
    4337         296 :                         n->fk_attrs = lappend(n->fk_attrs, $5);
    4338         296 :                         n->fk_with_period = true;
    4339             :                     }
    4340        1846 :                     n->pk_attrs = linitial($9);
    4341        1846 :                     if (lsecond($9))
    4342             :                     {
    4343         176 :                         n->pk_attrs = lappend(n->pk_attrs, lsecond($9));
    4344         176 :                         n->pk_with_period = true;
    4345             :                     }
    4346        1846 :                     n->fk_matchtype = $10;
    4347        1846 :                     n->fk_upd_action = ($11)->updateAction->action;
    4348        1846 :                     n->fk_del_action = ($11)->deleteAction->action;
    4349        1846 :                     n->fk_del_set_cols = ($11)->deleteAction->cols;
    4350        1846 :                     processCASbits($12, @12, "FOREIGN KEY",
    4351             :                                    &n->deferrable, &n->initdeferred,
    4352             :                                    &n->is_enforced, &n->skip_validation, NULL,
    4353             :                                    yyscanner);
    4354        1846 :                     n->initially_valid = !n->skip_validation;
    4355        1846 :                     $$ = (Node *) n;
    4356             :                 }
    4357             :         ;
    4358             : 
    4359             : /*
    4360             :  * DomainConstraint is separate from TableConstraint because the syntax for
    4361             :  * NOT NULL constraints is different.  For table constraints, we need to
    4362             :  * accept a column name, but for domain constraints, we don't.  (We could
    4363             :  * accept something like NOT NULL VALUE, but that seems weird.)  CREATE DOMAIN
    4364             :  * (which uses ColQualList) has for a long time accepted NOT NULL without a
    4365             :  * column name, so it makes sense that ALTER DOMAIN (which uses
    4366             :  * DomainConstraint) does as well.  None of these syntaxes are per SQL
    4367             :  * standard; we are just living with the bits of inconsistency that have built
    4368             :  * up over time.
    4369             :  */
    4370             : DomainConstraint:
    4371             :             CONSTRAINT name DomainConstraintElem
    4372             :                 {
    4373         166 :                     Constraint *n = castNode(Constraint, $3);
    4374             : 
    4375         166 :                     n->conname = $2;
    4376         166 :                     n->location = @1;
    4377         166 :                     $$ = (Node *) n;
    4378             :                 }
    4379          18 :             | DomainConstraintElem                  { $$ = $1; }
    4380             :         ;
    4381             : 
    4382             : DomainConstraintElem:
    4383             :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    4384             :                 {
    4385         166 :                     Constraint *n = makeNode(Constraint);
    4386             : 
    4387         166 :                     n->contype = CONSTR_CHECK;
    4388         166 :                     n->location = @1;
    4389         166 :                     n->raw_expr = $3;
    4390         166 :                     n->cooked_expr = NULL;
    4391         166 :                     processCASbits($5, @5, "CHECK",
    4392             :                                    NULL, NULL, NULL, &n->skip_validation,
    4393             :                                    &n->is_no_inherit, yyscanner);
    4394         154 :                     n->is_enforced = true;
    4395         154 :                     n->initially_valid = !n->skip_validation;
    4396         154 :                     $$ = (Node *) n;
    4397             :                 }
    4398             :             | NOT NULL_P ConstraintAttributeSpec
    4399             :                 {
    4400          30 :                     Constraint *n = makeNode(Constraint);
    4401             : 
    4402          30 :                     n->contype = CONSTR_NOTNULL;
    4403          30 :                     n->location = @1;
    4404          30 :                     n->keys = list_make1(makeString("value"));
    4405             :                     /* no NOT VALID, NO INHERIT support */
    4406          30 :                     processCASbits($3, @3, "NOT NULL",
    4407             :                                    NULL, NULL, NULL,
    4408             :                                    NULL, NULL, yyscanner);
    4409          30 :                     n->initially_valid = true;
    4410          30 :                     $$ = (Node *) n;
    4411             :                 }
    4412             :         ;
    4413             : 
    4414         138 : opt_no_inherit: NO INHERIT                          {  $$ = true; }
    4415        8132 :             | /* EMPTY */                           {  $$ = false; }
    4416             :         ;
    4417             : 
    4418             : opt_without_overlaps:
    4419         570 :             WITHOUT OVERLAPS                        { $$ = true; }
    4420        2428 :             | /*EMPTY*/                             { $$ = false; }
    4421             :     ;
    4422             : 
    4423             : opt_column_list:
    4424       15662 :             '(' columnList ')'                      { $$ = $2; }
    4425       43428 :             | /*EMPTY*/                             { $$ = NIL; }
    4426             :         ;
    4427             : 
    4428             : columnList:
    4429       22254 :             columnElem                              { $$ = list_make1($1); }
    4430       44732 :             | columnList ',' columnElem             { $$ = lappend($1, $3); }
    4431             :         ;
    4432             : 
    4433             : optionalPeriodName:
    4434         472 :             ',' PERIOD columnElem { $$ = $3; }
    4435        2542 :             | /*EMPTY*/               { $$ = NULL; }
    4436             :     ;
    4437             : 
    4438             : opt_column_and_period_list:
    4439        1162 :             '(' columnList optionalPeriodName ')'           { $$ = list_make2($2, $3); }
    4440         690 :             | /*EMPTY*/                             { $$ = list_make2(NIL, NULL); }
    4441             :         ;
    4442             : 
    4443             : columnElem: ColId
    4444             :                 {
    4445       67458 :                     $$ = (Node *) makeString($1);
    4446             :                 }
    4447             :         ;
    4448             : 
    4449         176 : opt_c_include:  INCLUDE '(' columnList ')'          { $$ = $3; }
    4450        3060 :              |      /* EMPTY */                     { $$ = NIL; }
    4451             :         ;
    4452             : 
    4453             : key_match:  MATCH FULL
    4454             :             {
    4455         100 :                 $$ = FKCONSTR_MATCH_FULL;
    4456             :             }
    4457             :         | MATCH PARTIAL
    4458             :             {
    4459           0 :                 ereport(ERROR,
    4460             :                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4461             :                          errmsg("MATCH PARTIAL not yet implemented"),
    4462             :                          parser_errposition(@1)));
    4463             :                 $$ = FKCONSTR_MATCH_PARTIAL;
    4464             :             }
    4465             :         | MATCH SIMPLE
    4466             :             {
    4467           6 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4468             :             }
    4469             :         | /*EMPTY*/
    4470             :             {
    4471        2574 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4472             :             }
    4473             :         ;
    4474             : 
    4475             : ExclusionConstraintList:
    4476         238 :             ExclusionConstraintElem                 { $$ = list_make1($1); }
    4477             :             | ExclusionConstraintList ',' ExclusionConstraintElem
    4478         110 :                                                     { $$ = lappend($1, $3); }
    4479             :         ;
    4480             : 
    4481             : ExclusionConstraintElem: index_elem WITH any_operator
    4482             :             {
    4483         348 :                 $$ = list_make2($1, $3);
    4484             :             }
    4485             :             /* allow OPERATOR() decoration for the benefit of ruleutils.c */
    4486             :             | index_elem WITH OPERATOR '(' any_operator ')'
    4487             :             {
    4488           0 :                 $$ = list_make2($1, $5);
    4489             :             }
    4490             :         ;
    4491             : 
    4492             : OptWhereClause:
    4493         440 :             WHERE '(' a_expr ')'                    { $$ = $3; }
    4494        1244 :             | /*EMPTY*/                             { $$ = NULL; }
    4495             :         ;
    4496             : 
    4497             : key_actions:
    4498             :             key_update
    4499             :                 {
    4500          76 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4501             : 
    4502          76 :                     n->updateAction = $1;
    4503          76 :                     n->deleteAction = palloc(sizeof(KeyAction));
    4504          76 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4505          76 :                     n->deleteAction->cols = NIL;
    4506          76 :                     $$ = n;
    4507             :                 }
    4508             :             | key_delete
    4509             :                 {
    4510         150 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4511             : 
    4512         150 :                     n->updateAction = palloc(sizeof(KeyAction));
    4513         150 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4514         150 :                     n->updateAction->cols = NIL;
    4515         150 :                     n->deleteAction = $1;
    4516         150 :                     $$ = n;
    4517             :                 }
    4518             :             | key_update key_delete
    4519             :                 {
    4520         162 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4521             : 
    4522         162 :                     n->updateAction = $1;
    4523         162 :                     n->deleteAction = $2;
    4524         162 :                     $$ = n;
    4525             :                 }
    4526             :             | key_delete key_update
    4527             :                 {
    4528         150 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4529             : 
    4530         150 :                     n->updateAction = $2;
    4531         150 :                     n->deleteAction = $1;
    4532         150 :                     $$ = n;
    4533             :                 }
    4534             :             | /*EMPTY*/
    4535             :                 {
    4536        2136 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4537             : 
    4538        2136 :                     n->updateAction = palloc(sizeof(KeyAction));
    4539        2136 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4540        2136 :                     n->updateAction->cols = NIL;
    4541        2136 :                     n->deleteAction = palloc(sizeof(KeyAction));
    4542        2136 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4543        2136 :                     n->deleteAction->cols = NIL;
    4544        2136 :                     $$ = n;
    4545             :                 }
    4546             :         ;
    4547             : 
    4548             : key_update: ON UPDATE key_action
    4549             :                 {
    4550         394 :                     if (($3)->cols)
    4551           6 :                         ereport(ERROR,
    4552             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4553             :                                  errmsg("a column list with %s is only supported for ON DELETE actions",
    4554             :                                         ($3)->action == FKCONSTR_ACTION_SETNULL ? "SET NULL" : "SET DEFAULT"),
    4555             :                                  parser_errposition(@1)));
    4556         388 :                     $$ = $3;
    4557             :                 }
    4558             :         ;
    4559             : 
    4560             : key_delete: ON DELETE_P key_action
    4561             :                 {
    4562         462 :                     $$ = $3;
    4563             :                 }
    4564             :         ;
    4565             : 
    4566             : key_action:
    4567             :             NO ACTION
    4568             :                 {
    4569          80 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4570             : 
    4571          80 :                     n->action = FKCONSTR_ACTION_NOACTION;
    4572          80 :                     n->cols = NIL;
    4573          80 :                     $$ = n;
    4574             :                 }
    4575             :             | RESTRICT
    4576             :                 {
    4577          48 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4578             : 
    4579          48 :                     n->action = FKCONSTR_ACTION_RESTRICT;
    4580          48 :                     n->cols = NIL;
    4581          48 :                     $$ = n;
    4582             :                 }
    4583             :             | CASCADE
    4584             :                 {
    4585         434 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4586             : 
    4587         434 :                     n->action = FKCONSTR_ACTION_CASCADE;
    4588         434 :                     n->cols = NIL;
    4589         434 :                     $$ = n;
    4590             :                 }
    4591             :             | SET NULL_P opt_column_list
    4592             :                 {
    4593         192 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4594             : 
    4595         192 :                     n->action = FKCONSTR_ACTION_SETNULL;
    4596         192 :                     n->cols = $3;
    4597         192 :                     $$ = n;
    4598             :                 }
    4599             :             | SET DEFAULT opt_column_list
    4600             :                 {
    4601         102 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4602             : 
    4603         102 :                     n->action = FKCONSTR_ACTION_SETDEFAULT;
    4604         102 :                     n->cols = $3;
    4605         102 :                     $$ = n;
    4606             :                 }
    4607             :         ;
    4608             : 
    4609        2198 : OptInherit: INHERITS '(' qualified_name_list ')'    { $$ = $3; }
    4610       29106 :             | /*EMPTY*/                             { $$ = NIL; }
    4611             :         ;
    4612             : 
    4613             : /* Optional partition key specification */
    4614        5154 : OptPartitionSpec: PartitionSpec { $$ = $1; }
    4615       33782 :             | /*EMPTY*/         { $$ = NULL; }
    4616             :         ;
    4617             : 
    4618             : PartitionSpec: PARTITION BY ColId '(' part_params ')'
    4619             :                 {
    4620        5160 :                     PartitionSpec *n = makeNode(PartitionSpec);
    4621             : 
    4622        5160 :                     n->strategy = parsePartitionStrategy($3, @3, yyscanner);
    4623        5154 :                     n->partParams = $5;
    4624        5154 :                     n->location = @1;
    4625             : 
    4626        5154 :                     $$ = n;
    4627             :                 }
    4628             :         ;
    4629             : 
    4630        5160 : part_params:    part_elem                       { $$ = list_make1($1); }
    4631         466 :             | part_params ',' part_elem         { $$ = lappend($1, $3); }
    4632             :         ;
    4633             : 
    4634             : part_elem: ColId opt_collate opt_qualified_name
    4635             :                 {
    4636        5306 :                     PartitionElem *n = makeNode(PartitionElem);
    4637             : 
    4638        5306 :                     n->name = $1;
    4639        5306 :                     n->expr = NULL;
    4640        5306 :                     n->collation = $2;
    4641        5306 :                     n->opclass = $3;
    4642        5306 :                     n->location = @1;
    4643        5306 :                     $$ = n;
    4644             :                 }
    4645             :             | func_expr_windowless opt_collate opt_qualified_name
    4646             :                 {
    4647         134 :                     PartitionElem *n = makeNode(PartitionElem);
    4648             : 
    4649         134 :                     n->name = NULL;
    4650         134 :                     n->expr = $1;
    4651         134 :                     n->collation = $2;
    4652         134 :                     n->opclass = $3;
    4653         134 :                     n->location = @1;
    4654         134 :                     $$ = n;
    4655             :                 }
    4656             :             | '(' a_expr ')' opt_collate opt_qualified_name
    4657             :                 {
    4658         186 :                     PartitionElem *n = makeNode(PartitionElem);
    4659             : 
    4660         186 :                     n->name = NULL;
    4661         186 :                     n->expr = $2;
    4662         186 :                     n->collation = $4;
    4663         186 :                     n->opclass = $5;
    4664         186 :                     n->location = @1;
    4665         186 :                     $$ = n;
    4666             :                 }
    4667             :         ;
    4668             : 
    4669             : table_access_method_clause:
    4670         122 :             USING name                          { $$ = $2; }
    4671       40738 :             | /*EMPTY*/                         { $$ = NULL; }
    4672             :         ;
    4673             : 
    4674             : /* WITHOUT OIDS is legacy only */
    4675             : OptWith:
    4676         798 :             WITH reloptions             { $$ = $2; }
    4677          24 :             | WITHOUT OIDS              { $$ = NIL; }
    4678       39434 :             | /*EMPTY*/                 { $$ = NIL; }
    4679             :         ;
    4680             : 
    4681          60 : OnCommitOption:  ON COMMIT DROP             { $$ = ONCOMMIT_DROP; }
    4682         104 :             | ON COMMIT DELETE_P ROWS       { $$ = ONCOMMIT_DELETE_ROWS; }
    4683          24 :             | ON COMMIT PRESERVE ROWS       { $$ = ONCOMMIT_PRESERVE_ROWS; }
    4684       40068 :             | /*EMPTY*/                     { $$ = ONCOMMIT_NOOP; }
    4685             :         ;
    4686             : 
    4687         206 : OptTableSpace:   TABLESPACE name                    { $$ = $2; }
    4688       47666 :             | /*EMPTY*/                             { $$ = NULL; }
    4689             :         ;
    4690             : 
    4691          66 : OptConsTableSpace:   USING INDEX TABLESPACE name    { $$ = $4; }
    4692        9386 :             | /*EMPTY*/                             { $$ = NULL; }
    4693             :         ;
    4694             : 
    4695       10886 : ExistingIndex:   USING INDEX name                   { $$ = $3; }
    4696             :         ;
    4697             : 
    4698             : /*****************************************************************************
    4699             :  *
    4700             :  *      QUERY :
    4701             :  *              CREATE STATISTICS [[IF NOT EXISTS] stats_name] [(stat types)]
    4702             :  *                  ON expression-list FROM from_list
    4703             :  *
    4704             :  * Note: the expectation here is that the clauses after ON are a subset of
    4705             :  * SELECT syntax, allowing for expressions and joined tables, and probably
    4706             :  * someday a WHERE clause.  Much less than that is currently implemented,
    4707             :  * but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
    4708             :  * errors as necessary at execution.
    4709             :  *
    4710             :  * Statistics name is optional unless IF NOT EXISTS is specified.
    4711             :  *
    4712             :  *****************************************************************************/
    4713             : 
    4714             : CreateStatsStmt:
    4715             :             CREATE STATISTICS opt_qualified_name
    4716             :             opt_name_list ON stats_params FROM from_list
    4717             :                 {
    4718         690 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4719             : 
    4720         690 :                     n->defnames = $3;
    4721         690 :                     n->stat_types = $4;
    4722         690 :                     n->exprs = $6;
    4723         690 :                     n->relations = $8;
    4724         690 :                     n->stxcomment = NULL;
    4725         690 :                     n->if_not_exists = false;
    4726         690 :                     $$ = (Node *) n;
    4727             :                 }
    4728             :             | CREATE STATISTICS IF_P NOT EXISTS any_name
    4729             :             opt_name_list ON stats_params FROM from_list
    4730             :                 {
    4731          12 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4732             : 
    4733          12 :                     n->defnames = $6;
    4734          12 :                     n->stat_types = $7;
    4735          12 :                     n->exprs = $9;
    4736          12 :                     n->relations = $11;
    4737          12 :                     n->stxcomment = NULL;
    4738          12 :                     n->if_not_exists = true;
    4739          12 :                     $$ = (Node *) n;
    4740             :                 }
    4741             :             ;
    4742             : 
    4743             : /*
    4744             :  * Statistics attributes can be either simple column references, or arbitrary
    4745             :  * expressions in parens.  For compatibility with index attributes permitted
    4746             :  * in CREATE INDEX, we allow an expression that's just a function call to be
    4747             :  * written without parens.
    4748             :  */
    4749             : 
    4750         714 : stats_params:   stats_param                         { $$ = list_make1($1); }
    4751         988 :             | stats_params ',' stats_param          { $$ = lappend($1, $3); }
    4752             :         ;
    4753             : 
    4754             : stats_param:    ColId
    4755             :                 {
    4756        1192 :                     $$ = makeNode(StatsElem);
    4757        1192 :                     $$->name = $1;
    4758        1192 :                     $$->expr = NULL;
    4759             :                 }
    4760             :             | func_expr_windowless
    4761             :                 {
    4762          34 :                     $$ = makeNode(StatsElem);
    4763          34 :                     $$->name = NULL;
    4764          34 :                     $$->expr = $1;
    4765             :                 }
    4766             :             | '(' a_expr ')'
    4767             :                 {
    4768         476 :                     $$ = makeNode(StatsElem);
    4769         476 :                     $$->name = NULL;
    4770         476 :                     $$->expr = $2;
    4771             :                 }
    4772             :         ;
    4773             : 
    4774             : /*****************************************************************************
    4775             :  *
    4776             :  *      QUERY :
    4777             :  *              ALTER STATISTICS [IF EXISTS] stats_name
    4778             :  *                  SET STATISTICS  <SignedIconst>
    4779             :  *
    4780             :  *****************************************************************************/
    4781             : 
    4782             : AlterStatsStmt:
    4783             :             ALTER STATISTICS any_name SET STATISTICS set_statistics_value
    4784             :                 {
    4785          20 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4786             : 
    4787          20 :                     n->defnames = $3;
    4788          20 :                     n->missing_ok = false;
    4789          20 :                     n->stxstattarget = $6;
    4790          20 :                     $$ = (Node *) n;
    4791             :                 }
    4792             :             | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
    4793             :                 {
    4794           6 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4795             : 
    4796           6 :                     n->defnames = $5;
    4797           6 :                     n->missing_ok = true;
    4798           6 :                     n->stxstattarget = $8;
    4799           6 :                     $$ = (Node *) n;
    4800             :                 }
    4801             :             ;
    4802             : 
    4803             : /*****************************************************************************
    4804             :  *
    4805             :  *      QUERY :
    4806             :  *              CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
    4807             :  *
    4808             :  *
    4809             :  * Note: SELECT ... INTO is a now-deprecated alternative for this.
    4810             :  *
    4811             :  *****************************************************************************/
    4812             : 
    4813             : CreateAsStmt:
    4814             :         CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
    4815             :                 {
    4816        1192 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4817             : 
    4818        1192 :                     ctas->query = $6;
    4819        1192 :                     ctas->into = $4;
    4820        1192 :                     ctas->objtype = OBJECT_TABLE;
    4821        1192 :                     ctas->is_select_into = false;
    4822        1192 :                     ctas->if_not_exists = false;
    4823             :                     /* cram additional flags into the IntoClause */
    4824        1192 :                     $4->rel->relpersistence = $2;
    4825        1192 :                     $4->skipData = !($7);
    4826        1192 :                     $$ = (Node *) ctas;
    4827             :                 }
    4828             :         | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
    4829             :                 {
    4830          52 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4831             : 
    4832          52 :                     ctas->query = $9;
    4833          52 :                     ctas->into = $7;
    4834          52 :                     ctas->objtype = OBJECT_TABLE;
    4835          52 :                     ctas->is_select_into = false;
    4836          52 :                     ctas->if_not_exists = true;
    4837             :                     /* cram additional flags into the IntoClause */
    4838          52 :                     $7->rel->relpersistence = $2;
    4839          52 :                     $7->skipData = !($10);
    4840          52 :                     $$ = (Node *) ctas;
    4841             :                 }
    4842             :         ;
    4843             : 
    4844             : create_as_target:
    4845             :             qualified_name opt_column_list table_access_method_clause
    4846             :             OptWith OnCommitOption OptTableSpace
    4847             :                 {
    4848        1332 :                     $$ = makeNode(IntoClause);
    4849        1332 :                     $$->rel = $1;
    4850        1332 :                     $$->colNames = $2;
    4851        1332 :                     $$->accessMethod = $3;
    4852        1332 :                     $$->options = $4;
    4853        1332 :                     $$->onCommit = $5;
    4854        1332 :                     $$->tableSpaceName = $6;
    4855        1332 :                     $$->viewQuery = NULL;
    4856        1332 :                     $$->skipData = false;        /* might get changed later */
    4857             :                 }
    4858             :         ;
    4859             : 
    4860             : opt_with_data:
    4861          36 :             WITH DATA_P                             { $$ = true; }
    4862         234 :             | WITH NO DATA_P                        { $$ = false; }
    4863        1944 :             | /*EMPTY*/                             { $$ = true; }
    4864             :         ;
    4865             : 
    4866             : 
    4867             : /*****************************************************************************
    4868             :  *
    4869             :  *      QUERY :
    4870             :  *              CREATE MATERIALIZED VIEW relname AS SelectStmt
    4871             :  *
    4872             :  *****************************************************************************/
    4873             : 
    4874             : CreateMatViewStmt:
    4875             :         CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
    4876             :                 {
    4877         550 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4878             : 
    4879         550 :                     ctas->query = $7;
    4880         550 :                     ctas->into = $5;
    4881         550 :                     ctas->objtype = OBJECT_MATVIEW;
    4882         550 :                     ctas->is_select_into = false;
    4883         550 :                     ctas->if_not_exists = false;
    4884             :                     /* cram additional flags into the IntoClause */
    4885         550 :                     $5->rel->relpersistence = $2;
    4886         550 :                     $5->skipData = !($8);
    4887         550 :                     $$ = (Node *) ctas;
    4888             :                 }
    4889             :         | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
    4890             :                 {
    4891          48 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4892             : 
    4893          48 :                     ctas->query = $10;
    4894          48 :                     ctas->into = $8;
    4895          48 :                     ctas->objtype = OBJECT_MATVIEW;
    4896          48 :                     ctas->is_select_into = false;
    4897          48 :                     ctas->if_not_exists = true;
    4898             :                     /* cram additional flags into the IntoClause */
    4899          48 :                     $8->rel->relpersistence = $2;
    4900          48 :                     $8->skipData = !($11);
    4901          48 :                     $$ = (Node *) ctas;
    4902             :                 }
    4903             :         ;
    4904             : 
    4905             : create_mv_target:
    4906             :             qualified_name opt_column_list table_access_method_clause opt_reloptions OptTableSpace
    4907             :                 {
    4908         598 :                     $$ = makeNode(IntoClause);
    4909         598 :                     $$->rel = $1;
    4910         598 :                     $$->colNames = $2;
    4911         598 :                     $$->accessMethod = $3;
    4912         598 :                     $$->options = $4;
    4913         598 :                     $$->onCommit = ONCOMMIT_NOOP;
    4914         598 :                     $$->tableSpaceName = $5;
    4915         598 :                     $$->viewQuery = NULL;        /* filled at analysis time */
    4916         598 :                     $$->skipData = false;        /* might get changed later */
    4917             :                 }
    4918             :         ;
    4919             : 
    4920           0 : OptNoLog:   UNLOGGED                    { $$ = RELPERSISTENCE_UNLOGGED; }
    4921         598 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    4922             :         ;
    4923             : 
    4924             : 
    4925             : /*****************************************************************************
    4926             :  *
    4927             :  *      QUERY :
    4928             :  *              REFRESH MATERIALIZED VIEW qualified_name
    4929             :  *
    4930             :  *****************************************************************************/
    4931             : 
    4932             : RefreshMatViewStmt:
    4933             :             REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
    4934             :                 {
    4935         284 :                     RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
    4936             : 
    4937         284 :                     n->concurrent = $4;
    4938         284 :                     n->relation = $5;
    4939         284 :                     n->skipData = !($6);
    4940         284 :                     $$ = (Node *) n;
    4941             :                 }
    4942             :         ;
    4943             : 
    4944             : 
    4945             : /*****************************************************************************
    4946             :  *
    4947             :  *      QUERY :
    4948             :  *              CREATE SEQUENCE seqname
    4949             :  *              ALTER SEQUENCE seqname
    4950             :  *
    4951             :  *****************************************************************************/
    4952             : 
    4953             : CreateSeqStmt:
    4954             :             CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
    4955             :                 {
    4956         720 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    4957             : 
    4958         720 :                     $4->relpersistence = $2;
    4959         720 :                     n->sequence = $4;
    4960         720 :                     n->options = $5;
    4961         720 :                     n->ownerId = InvalidOid;
    4962         720 :                     n->if_not_exists = false;
    4963         720 :                     $$ = (Node *) n;
    4964             :                 }
    4965             :             | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
    4966             :                 {
    4967          24 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    4968             : 
    4969          24 :                     $7->relpersistence = $2;
    4970          24 :                     n->sequence = $7;
    4971          24 :                     n->options = $8;
    4972          24 :                     n->ownerId = InvalidOid;
    4973          24 :                     n->if_not_exists = true;
    4974          24 :                     $$ = (Node *) n;
    4975             :                 }
    4976             :         ;
    4977             : 
    4978             : AlterSeqStmt:
    4979             :             ALTER SEQUENCE qualified_name SeqOptList
    4980             :                 {
    4981         212 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    4982             : 
    4983         212 :                     n->sequence = $3;
    4984         212 :                     n->options = $4;
    4985         212 :                     n->missing_ok = false;
    4986         212 :                     $$ = (Node *) n;
    4987             :                 }
    4988             :             | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
    4989             :                 {
    4990          12 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    4991             : 
    4992          12 :                     n->sequence = $5;
    4993          12 :                     n->options = $6;
    4994          12 :                     n->missing_ok = true;
    4995          12 :                     $$ = (Node *) n;
    4996             :                 }
    4997             : 
    4998             :         ;
    4999             : 
    5000         326 : OptSeqOptList: SeqOptList                           { $$ = $1; }
    5001         418 :             | /*EMPTY*/                             { $$ = NIL; }
    5002             :         ;
    5003             : 
    5004         118 : OptParenthesizedSeqOptList: '(' SeqOptList ')'      { $$ = $2; }
    5005         422 :             | /*EMPTY*/                             { $$ = NIL; }
    5006             :         ;
    5007             : 
    5008         668 : SeqOptList: SeqOptElem                              { $$ = list_make1($1); }
    5009        1322 :             | SeqOptList SeqOptElem                 { $$ = lappend($1, $2); }
    5010             :         ;
    5011             : 
    5012             : SeqOptElem: AS SimpleTypename
    5013             :                 {
    5014         236 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    5015             :                 }
    5016             :             | CACHE NumericOnly
    5017             :                 {
    5018         236 :                     $$ = makeDefElem("cache", (Node *) $2, @1);
    5019             :                 }
    5020             :             | CYCLE
    5021             :                 {
    5022          36 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(true), @1);
    5023             :                 }
    5024             :             | NO CYCLE
    5025             :                 {
    5026          14 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(false), @1);
    5027             :                 }
    5028             :             | INCREMENT opt_by NumericOnly
    5029             :                 {
    5030         352 :                     $$ = makeDefElem("increment", (Node *) $3, @1);
    5031             :                 }
    5032             :             | LOGGED
    5033             :                 {
    5034           4 :                     $$ = makeDefElem("logged", NULL, @1);
    5035             :                 }
    5036             :             | MAXVALUE NumericOnly
    5037             :                 {
    5038          74 :                     $$ = makeDefElem("maxvalue", (Node *) $2, @1);
    5039             :                 }
    5040             :             | MINVALUE NumericOnly
    5041             :                 {
    5042          74 :                     $$ = makeDefElem("minvalue", (Node *) $2, @1);
    5043             :                 }
    5044             :             | NO MAXVALUE
    5045             :                 {
    5046         208 :                     $$ = makeDefElem("maxvalue", NULL, @1);
    5047             :                 }
    5048             :             | NO MINVALUE
    5049             :                 {
    5050         208 :                     $$ = makeDefElem("minvalue", NULL, @1);
    5051             :                 }
    5052             :             | OWNED BY any_name
    5053             :                 {
    5054         100 :                     $$ = makeDefElem("owned_by", (Node *) $3, @1);
    5055             :                 }
    5056             :             | SEQUENCE NAME_P any_name
    5057             :                 {
    5058          88 :                     $$ = makeDefElem("sequence_name", (Node *) $3, @1);
    5059             :                 }
    5060             :             | START opt_with NumericOnly
    5061             :                 {
    5062         344 :                     $$ = makeDefElem("start", (Node *) $3, @1);
    5063             :                 }
    5064             :             | RESTART
    5065             :                 {
    5066           6 :                     $$ = makeDefElem("restart", NULL, @1);
    5067             :                 }
    5068             :             | RESTART opt_with NumericOnly
    5069             :                 {
    5070          60 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    5071             :                 }
    5072             :             | UNLOGGED
    5073             :                 {
    5074           4 :                     $$ = makeDefElem("unlogged", NULL, @1);
    5075             :                 }
    5076             :         ;
    5077             : 
    5078             : opt_by:     BY
    5079             :             | /* EMPTY */
    5080             :       ;
    5081             : 
    5082             : NumericOnly:
    5083         328 :             FCONST                              { $$ = (Node *) makeFloat($1); }
    5084           0 :             | '+' FCONST                        { $$ = (Node *) makeFloat($2); }
    5085             :             | '-' FCONST
    5086             :                 {
    5087          22 :                     Float      *f = makeFloat($2);
    5088             : 
    5089          22 :                     doNegateFloat(f);
    5090          22 :                     $$ = (Node *) f;
    5091             :                 }
    5092       13684 :             | SignedIconst                      { $$ = (Node *) makeInteger($1); }
    5093             :         ;
    5094             : 
    5095          80 : NumericOnly_list:   NumericOnly                     { $$ = list_make1($1); }
    5096           6 :                 | NumericOnly_list ',' NumericOnly  { $$ = lappend($1, $3); }
    5097             :         ;
    5098             : 
    5099             : /*****************************************************************************
    5100             :  *
    5101             :  *      QUERIES :
    5102             :  *              CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
    5103             :  *              DROP [PROCEDURAL] LANGUAGE ...
    5104             :  *
    5105             :  *****************************************************************************/
    5106             : 
    5107             : CreatePLangStmt:
    5108             :             CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
    5109             :             {
    5110             :                 /*
    5111             :                  * We now interpret parameterless CREATE LANGUAGE as
    5112             :                  * CREATE EXTENSION.  "OR REPLACE" is silently translated
    5113             :                  * to "IF NOT EXISTS", which isn't quite the same, but
    5114             :                  * seems more useful than throwing an error.  We just
    5115             :                  * ignore TRUSTED, as the previous code would have too.
    5116             :                  */
    5117           0 :                 CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5118             : 
    5119           0 :                 n->if_not_exists = $2;
    5120           0 :                 n->extname = $6;
    5121           0 :                 n->options = NIL;
    5122           0 :                 $$ = (Node *) n;
    5123             :             }
    5124             :             | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
    5125             :               HANDLER handler_name opt_inline_handler opt_validator
    5126             :             {
    5127         144 :                 CreatePLangStmt *n = makeNode(CreatePLangStmt);
    5128             : 
    5129         144 :                 n->replace = $2;
    5130         144 :                 n->plname = $6;
    5131         144 :                 n->plhandler = $8;
    5132         144 :                 n->plinline = $9;
    5133         144 :                 n->plvalidator = $10;
    5134         144 :                 n->pltrusted = $3;
    5135         144 :                 $$ = (Node *) n;
    5136             :             }
    5137             :         ;
    5138             : 
    5139             : opt_trusted:
    5140         114 :             TRUSTED                                 { $$ = true; }
    5141          38 :             | /*EMPTY*/                             { $$ = false; }
    5142             :         ;
    5143             : 
    5144             : /* This ought to be just func_name, but that causes reduce/reduce conflicts
    5145             :  * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
    5146             :  * Work around by using simple names, instead.
    5147             :  */
    5148             : handler_name:
    5149         562 :             name                        { $$ = list_make1(makeString($1)); }
    5150           2 :             | name attrs                { $$ = lcons(makeString($1), $2); }
    5151             :         ;
    5152             : 
    5153             : opt_inline_handler:
    5154         126 :             INLINE_P handler_name                   { $$ = $2; }
    5155          18 :             | /*EMPTY*/                             { $$ = NIL; }
    5156             :         ;
    5157             : 
    5158             : validator_clause:
    5159         126 :             VALIDATOR handler_name                  { $$ = $2; }
    5160           0 :             | NO VALIDATOR                          { $$ = NIL; }
    5161             :         ;
    5162             : 
    5163             : opt_validator:
    5164         126 :             validator_clause                        { $$ = $1; }
    5165          18 :             | /*EMPTY*/                             { $$ = NIL; }
    5166             :         ;
    5167             : 
    5168             : opt_procedural:
    5169             :             PROCEDURAL
    5170             :             | /*EMPTY*/
    5171             :         ;
    5172             : 
    5173             : /*****************************************************************************
    5174             :  *
    5175             :  *      QUERY:
    5176             :  *             CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
    5177             :  *
    5178             :  *****************************************************************************/
    5179             : 
    5180             : CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
    5181             :                 {
    5182         116 :                     CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
    5183             : 
    5184         116 :                     n->tablespacename = $3;
    5185         116 :                     n->owner = $4;
    5186         116 :                     n->location = $6;
    5187         116 :                     n->options = $7;
    5188         116 :                     $$ = (Node *) n;
    5189             :                 }
    5190             :         ;
    5191             : 
    5192           6 : OptTableSpaceOwner: OWNER RoleSpec      { $$ = $2; }
    5193         110 :             | /*EMPTY */                { $$ = NULL; }
    5194             :         ;
    5195             : 
    5196             : /*****************************************************************************
    5197             :  *
    5198             :  *      QUERY :
    5199             :  *              DROP TABLESPACE <tablespace>
    5200             :  *
    5201             :  *      No need for drop behaviour as we cannot implement dependencies for
    5202             :  *      objects in other databases; we can only support RESTRICT.
    5203             :  *
    5204             :  ****************************************************************************/
    5205             : 
    5206             : DropTableSpaceStmt: DROP TABLESPACE name
    5207             :                 {
    5208          64 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    5209             : 
    5210          64 :                     n->tablespacename = $3;
    5211          64 :                     n->missing_ok = false;
    5212          64 :                     $$ = (Node *) n;
    5213             :                 }
    5214             :                 |  DROP TABLESPACE IF_P EXISTS name
    5215             :                 {
    5216           0 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    5217             : 
    5218           0 :                     n->tablespacename = $5;
    5219           0 :                     n->missing_ok = true;
    5220           0 :                     $$ = (Node *) n;
    5221             :                 }
    5222             :         ;
    5223             : 
    5224             : /*****************************************************************************
    5225             :  *
    5226             :  *      QUERY:
    5227             :  *             CREATE EXTENSION extension
    5228             :  *             [ WITH ] [ SCHEMA schema ] [ VERSION version ]
    5229             :  *
    5230             :  *****************************************************************************/
    5231             : 
    5232             : CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
    5233             :                 {
    5234         520 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5235             : 
    5236         520 :                     n->extname = $3;
    5237         520 :                     n->if_not_exists = false;
    5238         520 :                     n->options = $5;
    5239         520 :                     $$ = (Node *) n;
    5240             :                 }
    5241             :                 | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
    5242             :                 {
    5243          18 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5244             : 
    5245          18 :                     n->extname = $6;
    5246          18 :                     n->if_not_exists = true;
    5247          18 :                     n->options = $8;
    5248          18 :                     $$ = (Node *) n;
    5249             :                 }
    5250             :         ;
    5251             : 
    5252             : create_extension_opt_list:
    5253             :             create_extension_opt_list create_extension_opt_item
    5254          98 :                 { $$ = lappend($1, $2); }
    5255             :             | /* EMPTY */
    5256         538 :                 { $$ = NIL; }
    5257             :         ;
    5258             : 
    5259             : create_extension_opt_item:
    5260             :             SCHEMA name
    5261             :                 {
    5262          46 :                     $$ = makeDefElem("schema", (Node *) makeString($2), @1);
    5263             :                 }
    5264             :             | VERSION_P NonReservedWord_or_Sconst
    5265             :                 {
    5266          12 :                     $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
    5267             :                 }
    5268             :             | FROM NonReservedWord_or_Sconst
    5269             :                 {
    5270           0 :                     ereport(ERROR,
    5271             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    5272             :                              errmsg("CREATE EXTENSION ... FROM is no longer supported"),
    5273             :                              parser_errposition(@1)));
    5274             :                 }
    5275             :             | CASCADE
    5276             :                 {
    5277          40 :                     $$ = makeDefElem("cascade", (Node *) makeBoolean(true), @1);
    5278             :                 }
    5279             :         ;
    5280             : 
    5281             : /*****************************************************************************
    5282             :  *
    5283             :  * ALTER EXTENSION name UPDATE [ TO version ]
    5284             :  *
    5285             :  *****************************************************************************/
    5286             : 
    5287             : AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
    5288             :                 {
    5289          38 :                     AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
    5290             : 
    5291          38 :                     n->extname = $3;
    5292          38 :                     n->options = $5;
    5293          38 :                     $$ = (Node *) n;
    5294             :                 }
    5295             :         ;
    5296             : 
    5297             : alter_extension_opt_list:
    5298             :             alter_extension_opt_list alter_extension_opt_item
    5299          38 :                 { $$ = lappend($1, $2); }
    5300             :             | /* EMPTY */
    5301          38 :                 { $$ = NIL; }
    5302             :         ;
    5303             : 
    5304             : alter_extension_opt_item:
    5305             :             TO NonReservedWord_or_Sconst
    5306             :                 {
    5307          38 :                     $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
    5308             :                 }
    5309             :         ;
    5310             : 
    5311             : /*****************************************************************************
    5312             :  *
    5313             :  * ALTER EXTENSION name ADD/DROP object-identifier
    5314             :  *
    5315             :  *****************************************************************************/
    5316             : 
    5317             : AlterExtensionContentsStmt:
    5318             :             ALTER EXTENSION name add_drop object_type_name name
    5319             :                 {
    5320          18 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5321             : 
    5322          18 :                     n->extname = $3;
    5323          18 :                     n->action = $4;
    5324          18 :                     n->objtype = $5;
    5325          18 :                     n->object = (Node *) makeString($6);
    5326          18 :                     $$ = (Node *) n;
    5327             :                 }
    5328             :             | ALTER EXTENSION name add_drop object_type_any_name any_name
    5329             :                 {
    5330          76 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5331             : 
    5332          76 :                     n->extname = $3;
    5333          76 :                     n->action = $4;
    5334          76 :                     n->objtype = $5;
    5335          76 :                     n->object = (Node *) $6;
    5336          76 :                     $$ = (Node *) n;
    5337             :                 }
    5338             :             | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
    5339             :                 {
    5340           8 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5341             : 
    5342           8 :                     n->extname = $3;
    5343           8 :                     n->action = $4;
    5344           8 :                     n->objtype = OBJECT_AGGREGATE;
    5345           8 :                     n->object = (Node *) $6;
    5346           8 :                     $$ = (Node *) n;
    5347             :                 }
    5348             :             | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
    5349             :                 {
    5350           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5351             : 
    5352           4 :                     n->extname = $3;
    5353           4 :                     n->action = $4;
    5354           4 :                     n->objtype = OBJECT_CAST;
    5355           4 :                     n->object = (Node *) list_make2($7, $9);
    5356           4 :                     $$ = (Node *) n;
    5357             :                 }
    5358             :             | ALTER EXTENSION name add_drop DOMAIN_P Typename
    5359             :                 {
    5360           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5361             : 
    5362           0 :                     n->extname = $3;
    5363           0 :                     n->action = $4;
    5364           0 :                     n->objtype = OBJECT_DOMAIN;
    5365           0 :                     n->object = (Node *) $6;
    5366           0 :                     $$ = (Node *) n;
    5367             :                 }
    5368             :             | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
    5369             :                 {
    5370          98 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5371             : 
    5372          98 :                     n->extname = $3;
    5373          98 :                     n->action = $4;
    5374          98 :                     n->objtype = OBJECT_FUNCTION;
    5375          98 :                     n->object = (Node *) $6;
    5376          98 :                     $$ = (Node *) n;
    5377             :                 }
    5378             :             | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
    5379             :                 {
    5380          18 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5381             : 
    5382          18 :                     n->extname = $3;
    5383          18 :                     n->action = $4;
    5384          18 :                     n->objtype = OBJECT_OPERATOR;
    5385          18 :                     n->object = (Node *) $6;
    5386          18 :                     $$ = (Node *) n;
    5387             :                 }
    5388             :             | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING name
    5389             :                 {
    5390           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5391             : 
    5392           4 :                     n->extname = $3;
    5393           4 :                     n->action = $4;
    5394           4 :                     n->objtype = OBJECT_OPCLASS;
    5395           4 :                     n->object = (Node *) lcons(makeString($9), $7);
    5396           4 :                     $$ = (Node *) n;
    5397             :                 }
    5398             :             | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING name
    5399             :                 {
    5400           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5401             : 
    5402           4 :                     n->extname = $3;
    5403           4 :                     n->action = $4;
    5404           4 :                     n->objtype = OBJECT_OPFAMILY;
    5405           4 :                     n->object = (Node *) lcons(makeString($9), $7);
    5406           4 :                     $$ = (Node *) n;
    5407             :                 }
    5408             :             | ALTER EXTENSION name add_drop PROCEDURE function_with_argtypes
    5409             :                 {
    5410           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5411             : 
    5412           0 :                     n->extname = $3;
    5413           0 :                     n->action = $4;
    5414           0 :                     n->objtype = OBJECT_PROCEDURE;
    5415           0 :                     n->object = (Node *) $6;
    5416           0 :                     $$ = (Node *) n;
    5417             :                 }
    5418             :             | ALTER EXTENSION name add_drop ROUTINE function_with_argtypes
    5419             :                 {
    5420           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5421             : 
    5422           0 :                     n->extname = $3;
    5423           0 :                     n->action = $4;
    5424           0 :                     n->objtype = OBJECT_ROUTINE;
    5425           0 :                     n->object = (Node *) $6;
    5426           0 :                     $$ = (Node *) n;
    5427             :                 }
    5428             :             | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
    5429             :                 {
    5430           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5431             : 
    5432           4 :                     n->extname = $3;
    5433           4 :                     n->action = $4;
    5434           4 :                     n->objtype = OBJECT_TRANSFORM;
    5435           4 :                     n->object = (Node *) list_make2($7, makeString($9));
    5436           4 :                     $$ = (Node *) n;
    5437             :                 }
    5438             :             | ALTER EXTENSION name add_drop TYPE_P Typename
    5439             :                 {
    5440           8 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5441             : 
    5442           8 :                     n->extname = $3;
    5443           8 :                     n->action = $4;
    5444           8 :                     n->objtype = OBJECT_TYPE;
    5445           8 :                     n->object = (Node *) $6;
    5446           8 :                     $$ = (Node *) n;
    5447             :                 }
    5448             :         ;
    5449             : 
    5450             : /*****************************************************************************
    5451             :  *
    5452             :  *      QUERY:
    5453             :  *             CREATE FOREIGN DATA WRAPPER name options
    5454             :  *
    5455             :  *****************************************************************************/
    5456             : 
    5457             : CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
    5458             :                 {
    5459         208 :                     CreateFdwStmt *n = makeNode(CreateFdwStmt);
    5460             : 
    5461         208 :                     n->fdwname = $5;
    5462         208 :                     n->func_options = $6;
    5463         208 :                     n->options = $7;
    5464         208 :                     $$ = (Node *) n;
    5465             :                 }
    5466             :         ;
    5467             : 
    5468             : fdw_option:
    5469          56 :             HANDLER handler_name                { $$ = makeDefElem("handler", (Node *) $2, @1); }
    5470           0 :             | NO HANDLER                        { $$ = makeDefElem("handler", NULL, @1); }
    5471          48 :             | VALIDATOR handler_name            { $$ = makeDefElem("validator", (Node *) $2, @1); }
    5472           6 :             | NO VALIDATOR                      { $$ = makeDefElem("validator", NULL, @1); }
    5473             :         ;
    5474             : 
    5475             : fdw_options:
    5476          90 :             fdw_option                          { $$ = list_make1($1); }
    5477          20 :             | fdw_options fdw_option            { $$ = lappend($1, $2); }
    5478             :         ;
    5479             : 
    5480             : opt_fdw_options:
    5481          54 :             fdw_options                         { $$ = $1; }
    5482         246 :             | /*EMPTY*/                         { $$ = NIL; }
    5483             :         ;
    5484             : 
    5485             : /*****************************************************************************
    5486             :  *
    5487             :  *      QUERY :
    5488             :  *              ALTER FOREIGN DATA WRAPPER name options
    5489             :  *
    5490             :  ****************************************************************************/
    5491             : 
    5492             : AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
    5493             :                 {
    5494          86 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5495             : 
    5496          86 :                     n->fdwname = $5;
    5497          86 :                     n->func_options = $6;
    5498          86 :                     n->options = $7;
    5499          86 :                     $$ = (Node *) n;
    5500             :                 }
    5501             :             | ALTER FOREIGN DATA_P WRAPPER name fdw_options
    5502             :                 {
    5503          36 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5504             : 
    5505          36 :                     n->fdwname = $5;
    5506          36 :                     n->func_options = $6;
    5507          36 :                     n->options = NIL;
    5508          36 :                     $$ = (Node *) n;
    5509             :                 }
    5510             :         ;
    5511             : 
    5512             : /* Options definition for CREATE FDW, SERVER and USER MAPPING */
    5513             : create_generic_options:
    5514         738 :             OPTIONS '(' generic_option_list ')'         { $$ = $3; }
    5515       73384 :             | /*EMPTY*/                                 { $$ = NIL; }
    5516             :         ;
    5517             : 
    5518             : generic_option_list:
    5519             :             generic_option_elem
    5520             :                 {
    5521         738 :                     $$ = list_make1($1);
    5522             :                 }
    5523             :             | generic_option_list ',' generic_option_elem
    5524             :                 {
    5525         480 :                     $$ = lappend($1, $3);
    5526             :                 }
    5527             :         ;
    5528             : 
    5529             : /* Options definition for ALTER FDW, SERVER and USER MAPPING */
    5530             : alter_generic_options:
    5531         504 :             OPTIONS '(' alter_generic_option_list ')'       { $$ = $3; }
    5532             :         ;
    5533             : 
    5534             : alter_generic_option_list:
    5535             :             alter_generic_option_elem
    5536             :                 {
    5537         504 :                     $$ = list_make1($1);
    5538             :                 }
    5539             :             | alter_generic_option_list ',' alter_generic_option_elem
    5540             :                 {
    5541         168 :                     $$ = lappend($1, $3);
    5542             :                 }
    5543             :         ;
    5544             : 
    5545             : alter_generic_option_elem:
    5546             :             generic_option_elem
    5547             :                 {
    5548         200 :                     $$ = $1;
    5549             :                 }
    5550             :             | SET generic_option_elem
    5551             :                 {
    5552         128 :                     $$ = $2;
    5553         128 :                     $$->defaction = DEFELEM_SET;
    5554             :                 }
    5555             :             | ADD_P generic_option_elem
    5556             :                 {
    5557         218 :                     $$ = $2;
    5558         218 :                     $$->defaction = DEFELEM_ADD;
    5559             :                 }
    5560             :             | DROP generic_option_name
    5561             :                 {
    5562         126 :                     $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP, @2);
    5563             :                 }
    5564             :         ;
    5565             : 
    5566             : generic_option_elem:
    5567             :             generic_option_name generic_option_arg
    5568             :                 {
    5569        1764 :                     $$ = makeDefElem($1, $2, @1);
    5570             :                 }
    5571             :         ;
    5572             : 
    5573             : generic_option_name:
    5574        1890 :                 ColLabel            { $$ = $1; }
    5575             :         ;
    5576             : 
    5577             : /* We could use def_arg here, but the spec only requires string literals */
    5578             : generic_option_arg:
    5579        1764 :                 Sconst              { $$ = (Node *) makeString($1); }
    5580             :         ;
    5581             : 
    5582             : /*****************************************************************************
    5583             :  *
    5584             :  *      QUERY:
    5585             :  *             CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
    5586             :  *
    5587             :  *****************************************************************************/
    5588             : 
    5589             : CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
    5590             :                          FOREIGN DATA_P WRAPPER name create_generic_options
    5591             :                 {
    5592         274 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5593             : 
    5594         274 :                     n->servername = $3;
    5595         274 :                     n->servertype = $4;
    5596         274 :                     n->version = $5;
    5597         274 :                     n->fdwname = $9;
    5598         274 :                     n->options = $10;
    5599         274 :                     n->if_not_exists = false;
    5600         274 :                     $$ = (Node *) n;
    5601             :                 }
    5602             :                 | CREATE SERVER IF_P NOT EXISTS name opt_type opt_foreign_server_version
    5603             :                          FOREIGN DATA_P WRAPPER name create_generic_options
    5604             :                 {
    5605          24 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5606             : 
    5607          24 :                     n->servername = $6;
    5608          24 :                     n->servertype = $7;
    5609          24 :                     n->version = $8;
    5610          24 :                     n->fdwname = $12;
    5611          24 :                     n->options = $13;
    5612          24 :                     n->if_not_exists = true;
    5613          24 :                     $$ = (Node *) n;
    5614             :                 }
    5615             :         ;
    5616             : 
    5617             : opt_type:
    5618          18 :             TYPE_P Sconst           { $$ = $2; }
    5619         280 :             | /*EMPTY*/             { $$ = NULL; }
    5620             :         ;
    5621             : 
    5622             : 
    5623             : foreign_server_version:
    5624          66 :             VERSION_P Sconst        { $$ = $2; }
    5625           0 :         |   VERSION_P NULL_P        { $$ = NULL; }
    5626             :         ;
    5627             : 
    5628             : opt_foreign_server_version:
    5629          18 :             foreign_server_version  { $$ = $1; }
    5630         280 :             | /*EMPTY*/             { $$ = NULL; }
    5631             :         ;
    5632             : 
    5633             : /*****************************************************************************
    5634             :  *
    5635             :  *      QUERY :
    5636             :  *              ALTER SERVER name [VERSION] [OPTIONS]
    5637             :  *
    5638             :  ****************************************************************************/
    5639             : 
    5640             : AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
    5641             :                 {
    5642           6 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5643             : 
    5644           6 :                     n->servername = $3;
    5645           6 :                     n->version = $4;
    5646           6 :                     n->options = $5;
    5647           6 :                     n->has_version = true;
    5648           6 :                     $$ = (Node *) n;
    5649             :                 }
    5650             :             | ALTER SERVER name foreign_server_version
    5651             :                 {
    5652          42 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5653             : 
    5654          42 :                     n->servername = $3;
    5655          42 :                     n->version = $4;
    5656          42 :                     n->has_version = true;
    5657          42 :                     $$ = (Node *) n;
    5658             :                 }
    5659             :             | ALTER SERVER name alter_generic_options
    5660             :                 {
    5661         180 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5662             : 
    5663         180 :                     n->servername = $3;
    5664         180 :                     n->options = $4;
    5665         180 :                     $$ = (Node *) n;
    5666             :                 }
    5667             :         ;
    5668             : 
    5669             : /*****************************************************************************
    5670             :  *
    5671             :  *      QUERY:
    5672             :  *             CREATE FOREIGN TABLE relname (...) SERVER name (...)
    5673             :  *
    5674             :  *****************************************************************************/
    5675             : 
    5676             : CreateForeignTableStmt:
    5677             :         CREATE FOREIGN TABLE qualified_name
    5678             :             '(' OptTableElementList ')'
    5679             :             OptInherit SERVER name create_generic_options
    5680             :                 {
    5681         394 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5682             : 
    5683         394 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5684         394 :                     n->base.relation = $4;
    5685         394 :                     n->base.tableElts = $6;
    5686         394 :                     n->base.inhRelations = $8;
    5687         394 :                     n->base.ofTypename = NULL;
    5688         394 :                     n->base.constraints = NIL;
    5689         394 :                     n->base.options = NIL;
    5690         394 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5691         394 :                     n->base.tablespacename = NULL;
    5692         394 :                     n->base.if_not_exists = false;
    5693             :                     /* FDW-specific data */
    5694         394 :                     n->servername = $10;
    5695         394 :                     n->options = $11;
    5696         394 :                     $$ = (Node *) n;
    5697             :                 }
    5698             :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5699             :             '(' OptTableElementList ')'
    5700             :             OptInherit SERVER name create_generic_options
    5701             :                 {
    5702           0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5703             : 
    5704           0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5705           0 :                     n->base.relation = $7;
    5706           0 :                     n->base.tableElts = $9;
    5707           0 :                     n->base.inhRelations = $11;
    5708           0 :                     n->base.ofTypename = NULL;
    5709           0 :                     n->base.constraints = NIL;
    5710           0 :                     n->base.options = NIL;
    5711           0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5712           0 :                     n->base.tablespacename = NULL;
    5713           0 :                     n->base.if_not_exists = true;
    5714             :                     /* FDW-specific data */
    5715           0 :                     n->servername = $13;
    5716           0 :                     n->options = $14;
    5717           0 :                     $$ = (Node *) n;
    5718             :                 }
    5719             :         | CREATE FOREIGN TABLE qualified_name
    5720             :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5721             :             SERVER name create_generic_options
    5722             :                 {
    5723          90 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5724             : 
    5725          90 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5726          90 :                     n->base.relation = $4;
    5727          90 :                     n->base.inhRelations = list_make1($7);
    5728          90 :                     n->base.tableElts = $8;
    5729          90 :                     n->base.partbound = $9;
    5730          90 :                     n->base.ofTypename = NULL;
    5731          90 :                     n->base.constraints = NIL;
    5732          90 :                     n->base.options = NIL;
    5733          90 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5734          90 :                     n->base.tablespacename = NULL;
    5735          90 :                     n->base.if_not_exists = false;
    5736             :                     /* FDW-specific data */
    5737          90 :                     n->servername = $11;
    5738          90 :                     n->options = $12;
    5739          90 :                     $$ = (Node *) n;
    5740             :                 }
    5741             :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5742             :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5743             :             SERVER name create_generic_options
    5744             :                 {
    5745           0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5746             : 
    5747           0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5748           0 :                     n->base.relation = $7;
    5749           0 :                     n->base.inhRelations = list_make1($10);
    5750           0 :                     n->base.tableElts = $11;
    5751           0 :                     n->base.partbound = $12;
    5752           0 :                     n->base.ofTypename = NULL;
    5753           0 :                     n->base.constraints = NIL;
    5754           0 :                     n->base.options = NIL;
    5755           0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5756           0 :                     n->base.tablespacename = NULL;
    5757           0 :                     n->base.if_not_exists = true;
    5758             :                     /* FDW-specific data */
    5759           0 :                     n->servername = $14;
    5760           0 :                     n->options = $15;
    5761           0 :                     $$ = (Node *) n;
    5762             :                 }
    5763             :         ;
    5764             : 
    5765             : /*****************************************************************************
    5766             :  *
    5767             :  *      QUERY:
    5768             :  *              IMPORT FOREIGN SCHEMA remote_schema
    5769             :  *              [ { LIMIT TO | EXCEPT } ( table_list ) ]
    5770             :  *              FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
    5771             :  *
    5772             :  ****************************************************************************/
    5773             : 
    5774             : ImportForeignSchemaStmt:
    5775             :         IMPORT_P FOREIGN SCHEMA name import_qualification
    5776             :           FROM SERVER name INTO name create_generic_options
    5777             :             {
    5778          48 :                 ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
    5779             : 
    5780          48 :                 n->server_name = $8;
    5781          48 :                 n->remote_schema = $4;
    5782          48 :                 n->local_schema = $10;
    5783          48 :                 n->list_type = $5->type;
    5784          48 :                 n->table_list = $5->table_names;
    5785          48 :                 n->options = $11;
    5786          48 :                 $$ = (Node *) n;
    5787             :             }
    5788             :         ;
    5789             : 
    5790             : import_qualification_type:
    5791          14 :         LIMIT TO                { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
    5792          14 :         | EXCEPT                { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
    5793             :         ;
    5794             : 
    5795             : import_qualification:
    5796             :         import_qualification_type '(' relation_expr_list ')'
    5797             :             {
    5798          28 :                 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
    5799             : 
    5800          28 :                 n->type = $1;
    5801          28 :                 n->table_names = $3;
    5802          28 :                 $$ = n;
    5803             :             }
    5804             :         | /*EMPTY*/
    5805             :             {
    5806          20 :                 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
    5807          20 :                 n->type = FDW_IMPORT_SCHEMA_ALL;
    5808          20 :                 n->table_names = NIL;
    5809          20 :                 $$ = n;
    5810             :             }
    5811             :         ;
    5812             : 
    5813             : /*****************************************************************************
    5814             :  *
    5815             :  *      QUERY:
    5816             :  *             CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
    5817             :  *
    5818             :  *****************************************************************************/
    5819             : 
    5820             : CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
    5821             :                 {
    5822         246 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5823             : 
    5824         246 :                     n->user = $5;
    5825         246 :                     n->servername = $7;
    5826         246 :                     n->options = $8;
    5827         246 :                     n->if_not_exists = false;
    5828         246 :                     $$ = (Node *) n;
    5829             :                 }
    5830             :                 | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
    5831             :                 {
    5832           6 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5833             : 
    5834           6 :                     n->user = $8;
    5835           6 :                     n->servername = $10;
    5836           6 :                     n->options = $11;
    5837           6 :                     n->if_not_exists = true;
    5838           6 :                     $$ = (Node *) n;
    5839             :                 }
    5840             :         ;
    5841             : 
    5842             : /* User mapping authorization identifier */
    5843         450 : auth_ident: RoleSpec            { $$ = $1; }
    5844          46 :             | USER              { $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1); }
    5845             :         ;
    5846             : 
    5847             : /*****************************************************************************
    5848             :  *
    5849             :  *      QUERY :
    5850             :  *              DROP USER MAPPING FOR auth_ident SERVER name
    5851             :  *
    5852             :  * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
    5853             :  * only pro forma; but the SQL standard doesn't show one.
    5854             :  ****************************************************************************/
    5855             : 
    5856             : DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
    5857             :                 {
    5858          88 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5859             : 
    5860          88 :                     n->user = $5;
    5861          88 :                     n->servername = $7;
    5862          88 :                     n->missing_ok = false;
    5863          88 :                     $$ = (Node *) n;
    5864             :                 }
    5865             :                 |  DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
    5866             :                 {
    5867          38 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5868             : 
    5869          38 :                     n->user = $7;
    5870          38 :                     n->servername = $9;
    5871          38 :                     n->missing_ok = true;
    5872          38 :                     $$ = (Node *) n;
    5873             :                 }
    5874             :         ;
    5875             : 
    5876             : /*****************************************************************************
    5877             :  *
    5878             :  *      QUERY :
    5879             :  *              ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
    5880             :  *
    5881             :  ****************************************************************************/
    5882             : 
    5883             : AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
    5884             :                 {
    5885         118 :                     AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
    5886             : 
    5887         118 :                     n->user = $5;
    5888         118 :                     n->servername = $7;
    5889         118 :                     n->options = $8;
    5890         118 :                     $$ = (Node *) n;
    5891             :                 }
    5892             :         ;
    5893             : 
    5894             : /*****************************************************************************
    5895             :  *
    5896             :  *      QUERIES:
    5897             :  *              CREATE POLICY name ON table
    5898             :  *                  [AS { PERMISSIVE | RESTRICTIVE } ]
    5899             :  *                  [FOR { SELECT | INSERT | UPDATE | DELETE } ]
    5900             :  *                  [TO role, ...]
    5901             :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    5902             :  *              ALTER POLICY name ON table [TO role, ...]
    5903             :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    5904             :  *
    5905             :  *****************************************************************************/
    5906             : 
    5907             : CreatePolicyStmt:
    5908             :             CREATE POLICY name ON qualified_name RowSecurityDefaultPermissive
    5909             :                 RowSecurityDefaultForCmd RowSecurityDefaultToRole
    5910             :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    5911             :                 {
    5912         706 :                     CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
    5913             : 
    5914         706 :                     n->policy_name = $3;
    5915         706 :                     n->table = $5;
    5916         706 :                     n->permissive = $6;
    5917         706 :                     n->cmd_name = $7;
    5918         706 :                     n->roles = $8;
    5919         706 :                     n->qual = $9;
    5920         706 :                     n->with_check = $10;
    5921         706 :                     $$ = (Node *) n;
    5922             :                 }
    5923             :         ;
    5924             : 
    5925             : AlterPolicyStmt:
    5926             :             ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
    5927             :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    5928             :                 {
    5929          84 :                     AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
    5930             : 
    5931          84 :                     n->policy_name = $3;
    5932          84 :                     n->table = $5;
    5933          84 :                     n->roles = $6;
    5934          84 :                     n->qual = $7;
    5935          84 :                     n->with_check = $8;
    5936          84 :                     $$ = (Node *) n;
    5937             :                 }
    5938             :         ;
    5939             : 
    5940             : RowSecurityOptionalExpr:
    5941         732 :             USING '(' a_expr ')'    { $$ = $3; }
    5942          58 :             | /* EMPTY */           { $$ = NULL; }
    5943             :         ;
    5944             : 
    5945             : RowSecurityOptionalWithCheck:
    5946         128 :             WITH CHECK '(' a_expr ')'       { $$ = $4; }
    5947         662 :             | /* EMPTY */                   { $$ = NULL; }
    5948             :         ;
    5949             : 
    5950             : RowSecurityDefaultToRole:
    5951         130 :             TO role_list            { $$ = $2; }
    5952         576 :             | /* EMPTY */           { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
    5953             :         ;
    5954             : 
    5955             : RowSecurityOptionalToRole:
    5956          12 :             TO role_list            { $$ = $2; }
    5957          72 :             | /* EMPTY */           { $$ = NULL; }
    5958             :         ;
    5959             : 
    5960             : RowSecurityDefaultPermissive:
    5961             :             AS IDENT
    5962             :                 {
    5963          98 :                     if (strcmp($2, "permissive") == 0)
    5964          24 :                         $$ = true;
    5965          74 :                     else if (strcmp($2, "restrictive") == 0)
    5966          68 :                         $$ = false;
    5967             :                     else
    5968           6 :                         ereport(ERROR,
    5969             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    5970             :                                  errmsg("unrecognized row security option \"%s\"", $2),
    5971             :                                  errhint("Only PERMISSIVE or RESTRICTIVE policies are supported currently."),
    5972             :                                  parser_errposition(@2)));
    5973             : 
    5974             :                 }
    5975         614 :             | /* EMPTY */           { $$ = true; }
    5976             :         ;
    5977             : 
    5978             : RowSecurityDefaultForCmd:
    5979         332 :             FOR row_security_cmd    { $$ = $2; }
    5980         374 :             | /* EMPTY */           { $$ = "all"; }
    5981             :         ;
    5982             : 
    5983             : row_security_cmd:
    5984          44 :             ALL             { $$ = "all"; }
    5985         116 :         |   SELECT          { $$ = "select"; }
    5986          44 :         |   INSERT          { $$ = "insert"; }
    5987          82 :         |   UPDATE          { $$ = "update"; }
    5988          46 :         |   DELETE_P        { $$ = "delete"; }
    5989             :         ;
    5990             : 
    5991             : /*****************************************************************************
    5992             :  *
    5993             :  *      QUERY:
    5994             :  *             CREATE ACCESS METHOD name HANDLER handler_name
    5995             :  *
    5996             :  *****************************************************************************/
    5997             : 
    5998             : CreateAmStmt: CREATE ACCESS METHOD name TYPE_P am_type HANDLER handler_name
    5999             :                 {
    6000          64 :                     CreateAmStmt *n = makeNode(CreateAmStmt);
    6001             : 
    6002          64 :                     n->amname = $4;
    6003          64 :                     n->handler_name = $8;
    6004          64 :                     n->amtype = $6;
    6005          64 :                     $$ = (Node *) n;
    6006             :                 }
    6007             :         ;
    6008             : 
    6009             : am_type:
    6010          34 :             INDEX           { $$ = AMTYPE_INDEX; }
    6011          30 :         |   TABLE           { $$ = AMTYPE_TABLE; }
    6012             :         ;
    6013             : 
    6014             : /*****************************************************************************
    6015             :  *
    6016             :  *      QUERIES :
    6017             :  *              CREATE TRIGGER ...
    6018             :  *
    6019             :  *****************************************************************************/
    6020             : 
    6021             : CreateTrigStmt:
    6022             :             CREATE opt_or_replace TRIGGER name TriggerActionTime TriggerEvents ON
    6023             :             qualified_name TriggerReferencing TriggerForSpec TriggerWhen
    6024             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    6025             :                 {
    6026        3260 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    6027             : 
    6028        3260 :                     n->replace = $2;
    6029        3260 :                     n->isconstraint = false;
    6030        3260 :                     n->trigname = $4;
    6031        3260 :                     n->relation = $8;
    6032        3260 :                     n->funcname = $14;
    6033        3260 :                     n->args = $16;
    6034        3260 :                     n->row = $10;
    6035        3260 :                     n->timing = $5;
    6036        3260 :                     n->events = intVal(linitial($6));
    6037        3260 :                     n->columns = (List *) lsecond($6);
    6038        3260 :                     n->whenClause = $11;
    6039        3260 :                     n->transitionRels = $9;
    6040        3260 :                     n->deferrable = false;
    6041        3260 :                     n->initdeferred = false;
    6042        3260 :                     n->constrrel = NULL;
    6043        3260 :                     $$ = (Node *) n;
    6044             :                 }
    6045             :           | CREATE opt_or_replace CONSTRAINT TRIGGER name AFTER TriggerEvents ON
    6046             :             qualified_name OptConstrFromTable ConstraintAttributeSpec
    6047             :             FOR EACH ROW TriggerWhen
    6048             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    6049             :                 {
    6050          80 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    6051             :                     bool        dummy;
    6052             : 
    6053          80 :                     if (($11 & CAS_NOT_VALID) != 0)
    6054           6 :                         ereport(ERROR,
    6055             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6056             :                                 errmsg("constraint triggers cannot be marked %s",
    6057             :                                        "NOT VALID"),
    6058             :                                 parser_errposition(@11));
    6059          74 :                     if (($11 & CAS_NO_INHERIT) != 0)
    6060           6 :                         ereport(ERROR,
    6061             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6062             :                                 errmsg("constraint triggers cannot be marked %s",
    6063             :                                        "NO INHERIT"),
    6064             :                                 parser_errposition(@11));
    6065          68 :                     if (($11 & CAS_NOT_ENFORCED) != 0)
    6066           6 :                         ereport(ERROR,
    6067             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6068             :                                 errmsg("constraint triggers cannot be marked %s",
    6069             :                                        "NOT ENFORCED"),
    6070             :                                 parser_errposition(@11));
    6071             : 
    6072          62 :                     n->replace = $2;
    6073          62 :                     if (n->replace) /* not supported, see CreateTrigger */
    6074           0 :                         ereport(ERROR,
    6075             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6076             :                                  errmsg("CREATE OR REPLACE CONSTRAINT TRIGGER is not supported"),
    6077             :                                  parser_errposition(@1)));
    6078          62 :                     n->isconstraint = true;
    6079          62 :                     n->trigname = $5;
    6080          62 :                     n->relation = $9;
    6081          62 :                     n->funcname = $18;
    6082          62 :                     n->args = $20;
    6083          62 :                     n->row = true;
    6084          62 :                     n->timing = TRIGGER_TYPE_AFTER;
    6085          62 :                     n->events = intVal(linitial($7));
    6086          62 :                     n->columns = (List *) lsecond($7);
    6087          62 :                     n->whenClause = $15;
    6088          62 :                     n->transitionRels = NIL;
    6089          62 :                     processCASbits($11, @11, "TRIGGER",
    6090             :                                    &n->deferrable, &n->initdeferred, &dummy,
    6091             :                                    NULL, NULL, yyscanner);
    6092          62 :                     n->constrrel = $10;
    6093          62 :                     $$ = (Node *) n;
    6094             :                 }
    6095             :         ;
    6096             : 
    6097             : TriggerActionTime:
    6098        1478 :             BEFORE                              { $$ = TRIGGER_TYPE_BEFORE; }
    6099        1650 :             | AFTER                             { $$ = TRIGGER_TYPE_AFTER; }
    6100         144 :             | INSTEAD OF                        { $$ = TRIGGER_TYPE_INSTEAD; }
    6101             :         ;
    6102             : 
    6103             : TriggerEvents:
    6104             :             TriggerOneEvent
    6105        3352 :                 { $$ = $1; }
    6106             :             | TriggerEvents OR TriggerOneEvent
    6107             :                 {
    6108        1212 :                     int         events1 = intVal(linitial($1));
    6109        1212 :                     int         events2 = intVal(linitial($3));
    6110        1212 :                     List       *columns1 = (List *) lsecond($1);
    6111        1212 :                     List       *columns2 = (List *) lsecond($3);
    6112             : 
    6113        1212 :                     if (events1 & events2)
    6114           6 :                         parser_yyerror("duplicate trigger events specified");
    6115             :                     /*
    6116             :                      * concat'ing the columns lists loses information about
    6117             :                      * which columns went with which event, but so long as
    6118             :                      * only UPDATE carries columns and we disallow multiple
    6119             :                      * UPDATE items, it doesn't matter.  Command execution
    6120             :                      * should just ignore the columns for non-UPDATE events.
    6121             :                      */
    6122        1206 :                     $$ = list_make2(makeInteger(events1 | events2),
    6123             :                                     list_concat(columns1, columns2));
    6124             :                 }
    6125             :         ;
    6126             : 
    6127             : TriggerOneEvent:
    6128             :             INSERT
    6129        1728 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
    6130             :             | DELETE_P
    6131         896 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
    6132             :             | UPDATE
    6133        1794 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
    6134             :             | UPDATE OF columnList
    6135         108 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
    6136             :             | TRUNCATE
    6137          38 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
    6138             :         ;
    6139             : 
    6140             : TriggerReferencing:
    6141         470 :             REFERENCING TriggerTransitions          { $$ = $2; }
    6142        2790 :             | /*EMPTY*/                             { $$ = NIL; }
    6143             :         ;
    6144             : 
    6145             : TriggerTransitions:
    6146         470 :             TriggerTransition                       { $$ = list_make1($1); }
    6147         144 :             | TriggerTransitions TriggerTransition  { $$ = lappend($1, $2); }
    6148             :         ;
    6149             : 
    6150             : TriggerTransition:
    6151             :             TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
    6152             :                 {
    6153         614 :                     TriggerTransition *n = makeNode(TriggerTransition);
    6154             : 
    6155         614 :                     n->name = $4;
    6156         614 :                     n->isNew = $1;
    6157         614 :                     n->isTable = $2;
    6158         614 :                     $$ = (Node *) n;
    6159             :                 }
    6160             :         ;
    6161             : 
    6162             : TransitionOldOrNew:
    6163         336 :             NEW                                     { $$ = true; }
    6164         278 :             | OLD                                   { $$ = false; }
    6165             :         ;
    6166             : 
    6167             : TransitionRowOrTable:
    6168         614 :             TABLE                                   { $$ = true; }
    6169             :             /*
    6170             :              * According to the standard, lack of a keyword here implies ROW.
    6171             :              * Support for that would require prohibiting ROW entirely here,
    6172             :              * reserving the keyword ROW, and/or requiring AS (instead of
    6173             :              * allowing it to be optional, as the standard specifies) as the
    6174             :              * next token.  Requiring ROW seems cleanest and easiest to
    6175             :              * explain.
    6176             :              */
    6177           0 :             | ROW                                   { $$ = false; }
    6178             :         ;
    6179             : 
    6180             : TransitionRelName:
    6181         614 :             ColId                                   { $$ = $1; }
    6182             :         ;
    6183             : 
    6184             : TriggerForSpec:
    6185             :             FOR TriggerForOptEach TriggerForType
    6186             :                 {
    6187        3032 :                     $$ = $3;
    6188             :                 }
    6189             :             | /* EMPTY */
    6190             :                 {
    6191             :                     /*
    6192             :                      * If ROW/STATEMENT not specified, default to
    6193             :                      * STATEMENT, per SQL
    6194             :                      */
    6195         228 :                     $$ = false;
    6196             :                 }
    6197             :         ;
    6198             : 
    6199             : TriggerForOptEach:
    6200             :             EACH
    6201             :             | /*EMPTY*/
    6202             :         ;
    6203             : 
    6204             : TriggerForType:
    6205        2196 :             ROW                                     { $$ = true; }
    6206         836 :             | STATEMENT                             { $$ = false; }
    6207             :         ;
    6208             : 
    6209             : TriggerWhen:
    6210         194 :             WHEN '(' a_expr ')'                     { $$ = $3; }
    6211        3146 :             | /*EMPTY*/                             { $$ = NULL; }
    6212             :         ;
    6213             : 
    6214             : FUNCTION_or_PROCEDURE:
    6215             :             FUNCTION
    6216             :         |   PROCEDURE
    6217             :         ;
    6218             : 
    6219             : TriggerFuncArgs:
    6220         588 :             TriggerFuncArg                          { $$ = list_make1($1); }
    6221         166 :             | TriggerFuncArgs ',' TriggerFuncArg    { $$ = lappend($1, $3); }
    6222        2752 :             | /*EMPTY*/                             { $$ = NIL; }
    6223             :         ;
    6224             : 
    6225             : TriggerFuncArg:
    6226             :             Iconst
    6227             :                 {
    6228          94 :                     $$ = (Node *) makeString(psprintf("%d", $1));
    6229             :                 }
    6230           0 :             | FCONST                                { $$ = (Node *) makeString($1); }
    6231         638 :             | Sconst                                { $$ = (Node *) makeString($1); }
    6232          22 :             | ColLabel                              { $$ = (Node *) makeString($1); }
    6233             :         ;
    6234             : 
    6235             : OptConstrFromTable:
    6236          12 :             FROM qualified_name                     { $$ = $2; }
    6237          68 :             | /*EMPTY*/                             { $$ = NULL; }
    6238             :         ;
    6239             : 
    6240             : ConstraintAttributeSpec:
    6241             :             /*EMPTY*/
    6242       18462 :                 { $$ = 0; }
    6243             :             | ConstraintAttributeSpec ConstraintAttributeElem
    6244             :                 {
    6245             :                     /*
    6246             :                      * We must complain about conflicting options.
    6247             :                      * We could, but choose not to, complain about redundant
    6248             :                      * options (ie, where $2's bit is already set in $1).
    6249             :                      */
    6250        1728 :                     int     newspec = $1 | $2;
    6251             : 
    6252             :                     /* special message for this case */
    6253        1728 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
    6254           6 :                         ereport(ERROR,
    6255             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6256             :                                  errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
    6257             :                                  parser_errposition(@2)));
    6258             :                     /* generic message for other conflicts */
    6259        1722 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
    6260        1722 :                         (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED) ||
    6261        1722 :                         (newspec & (CAS_NOT_ENFORCED | CAS_ENFORCED)) == (CAS_NOT_ENFORCED | CAS_ENFORCED))
    6262           6 :                         ereport(ERROR,
    6263             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6264             :                                  errmsg("conflicting constraint properties"),
    6265             :                                  parser_errposition(@2)));
    6266        1716 :                     $$ = newspec;
    6267             :                 }
    6268             :         ;
    6269             : 
    6270             : ConstraintAttributeElem:
    6271          42 :             NOT DEFERRABLE                  { $$ = CAS_NOT_DEFERRABLE; }
    6272         212 :             | DEFERRABLE                    { $$ = CAS_DEFERRABLE; }
    6273          30 :             | INITIALLY IMMEDIATE           { $$ = CAS_INITIALLY_IMMEDIATE; }
    6274         158 :             | INITIALLY DEFERRED            { $$ = CAS_INITIALLY_DEFERRED; }
    6275         750 :             | NOT VALID                     { $$ = CAS_NOT_VALID; }
    6276         254 :             | NO INHERIT                    { $$ = CAS_NO_INHERIT; }
    6277         174 :             | NOT ENFORCED                  { $$ = CAS_NOT_ENFORCED; }
    6278         108 :             | ENFORCED                      { $$ = CAS_ENFORCED; }
    6279             :         ;
    6280             : 
    6281             : 
    6282             : /*****************************************************************************
    6283             :  *
    6284             :  *      QUERIES :
    6285             :  *              CREATE EVENT TRIGGER ...
    6286             :  *              ALTER EVENT TRIGGER ...
    6287             :  *
    6288             :  *****************************************************************************/
    6289             : 
    6290             : CreateEventTrigStmt:
    6291             :             CREATE EVENT TRIGGER name ON ColLabel
    6292             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    6293             :                 {
    6294          98 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6295             : 
    6296          98 :                     n->trigname = $4;
    6297          98 :                     n->eventname = $6;
    6298          98 :                     n->whenclause = NULL;
    6299          98 :                     n->funcname = $9;
    6300          98 :                     $$ = (Node *) n;
    6301             :                 }
    6302             :           | CREATE EVENT TRIGGER name ON ColLabel
    6303             :             WHEN event_trigger_when_list
    6304             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    6305             :                 {
    6306         100 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6307             : 
    6308         100 :                     n->trigname = $4;
    6309         100 :                     n->eventname = $6;
    6310         100 :                     n->whenclause = $8;
    6311         100 :                     n->funcname = $11;
    6312         100 :                     $$ = (Node *) n;
    6313             :                 }
    6314             :         ;
    6315             : 
    6316             : event_trigger_when_list:
    6317             :           event_trigger_when_item
    6318         100 :             { $$ = list_make1($1); }
    6319             :         | event_trigger_when_list AND event_trigger_when_item
    6320           6 :             { $$ = lappend($1, $3); }
    6321             :         ;
    6322             : 
    6323             : event_trigger_when_item:
    6324             :         ColId IN_P '(' event_trigger_value_list ')'
    6325         106 :             { $$ = makeDefElem($1, (Node *) $4, @1); }
    6326             :         ;
    6327             : 
    6328             : event_trigger_value_list:
    6329             :           SCONST
    6330         106 :             { $$ = list_make1(makeString($1)); }
    6331             :         | event_trigger_value_list ',' SCONST
    6332          66 :             { $$ = lappend($1, makeString($3)); }
    6333             :         ;
    6334             : 
    6335             : AlterEventTrigStmt:
    6336             :             ALTER EVENT TRIGGER name enable_trigger
    6337             :                 {
    6338          48 :                     AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
    6339             : 
    6340          48 :                     n->trigname = $4;
    6341          48 :                     n->tgenabled = $5;
    6342          48 :                     $$ = (Node *) n;
    6343             :                 }
    6344             :         ;
    6345             : 
    6346             : enable_trigger:
    6347           6 :             ENABLE_P                    { $$ = TRIGGER_FIRES_ON_ORIGIN; }
    6348           6 :             | ENABLE_P REPLICA          { $$ = TRIGGER_FIRES_ON_REPLICA; }
    6349          16 :             | ENABLE_P ALWAYS           { $$ = TRIGGER_FIRES_ALWAYS; }
    6350          20 :             | DISABLE_P                 { $$ = TRIGGER_DISABLED; }
    6351             :         ;
    6352             : 
    6353             : /*****************************************************************************
    6354             :  *
    6355             :  *      QUERY :
    6356             :  *              CREATE ASSERTION ...
    6357             :  *
    6358             :  *****************************************************************************/
    6359             : 
    6360             : CreateAssertionStmt:
    6361             :             CREATE ASSERTION any_name CHECK '(' a_expr ')' ConstraintAttributeSpec
    6362             :                 {
    6363           0 :                     ereport(ERROR,
    6364             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6365             :                              errmsg("CREATE ASSERTION is not yet implemented"),
    6366             :                              parser_errposition(@1)));
    6367             : 
    6368             :                     $$ = NULL;
    6369             :                 }
    6370             :         ;
    6371             : 
    6372             : 
    6373             : /*****************************************************************************
    6374             :  *
    6375             :  *      QUERY :
    6376             :  *              define (aggregate,operator,type)
    6377             :  *
    6378             :  *****************************************************************************/
    6379             : 
    6380             : DefineStmt:
    6381             :             CREATE opt_or_replace AGGREGATE func_name aggr_args definition
    6382             :                 {
    6383         638 :                     DefineStmt *n = makeNode(DefineStmt);
    6384             : 
    6385         638 :                     n->kind = OBJECT_AGGREGATE;
    6386         638 :                     n->oldstyle = false;
    6387         638 :                     n->replace = $2;
    6388         638 :                     n->defnames = $4;
    6389         638 :                     n->args = $5;
    6390         638 :                     n->definition = $6;
    6391         638 :                     $$ = (Node *) n;
    6392             :                 }
    6393             :             | CREATE opt_or_replace AGGREGATE func_name old_aggr_definition
    6394             :                 {
    6395             :                     /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
    6396         362 :                     DefineStmt *n = makeNode(DefineStmt);
    6397             : 
    6398         362 :                     n->kind = OBJECT_AGGREGATE;
    6399         362 :                     n->oldstyle = true;
    6400         362 :                     n->replace = $2;
    6401         362 :                     n->defnames = $4;
    6402         362 :                     n->args = NIL;
    6403         362 :                     n->definition = $5;
    6404         362 :                     $$ = (Node *) n;
    6405             :                 }
    6406             :             | CREATE OPERATOR any_operator definition
    6407             :                 {
    6408        1610 :                     DefineStmt *n = makeNode(DefineStmt);
    6409             : 
    6410        1610 :                     n->kind = OBJECT_OPERATOR;
    6411        1610 :                     n->oldstyle = false;
    6412        1610 :                     n->defnames = $3;
    6413        1610 :                     n->args = NIL;
    6414        1610 :                     n->definition = $4;
    6415        1610 :                     $$ = (Node *) n;
    6416             :                 }
    6417             :             | CREATE TYPE_P any_name definition
    6418             :                 {
    6419         230 :                     DefineStmt *n = makeNode(DefineStmt);
    6420             : 
    6421         230 :                     n->kind = OBJECT_TYPE;
    6422         230 :                     n->oldstyle = false;
    6423         230 :                     n->defnames = $3;
    6424         230 :                     n->args = NIL;
    6425         230 :                     n->definition = $4;
    6426         230 :                     $$ = (Node *) n;
    6427             :                 }
    6428             :             | CREATE TYPE_P any_name
    6429             :                 {
    6430             :                     /* Shell type (identified by lack of definition) */
    6431         172 :                     DefineStmt *n = makeNode(DefineStmt);
    6432             : 
    6433         172 :                     n->kind = OBJECT_TYPE;
    6434         172 :                     n->oldstyle = false;
    6435         172 :                     n->defnames = $3;
    6436         172 :                     n->args = NIL;
    6437         172 :                     n->definition = NIL;
    6438         172 :                     $$ = (Node *) n;
    6439             :                 }
    6440             :             | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
    6441             :                 {
    6442        4534 :                     CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
    6443             : 
    6444             :                     /* can't use qualified_name, sigh */
    6445        4534 :                     n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
    6446        4534 :                     n->coldeflist = $6;
    6447        4534 :                     $$ = (Node *) n;
    6448             :                 }
    6449             :             | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
    6450             :                 {
    6451         208 :                     CreateEnumStmt *n = makeNode(CreateEnumStmt);
    6452             : 
    6453         208 :                     n->typeName = $3;
    6454         208 :                     n->vals = $7;
    6455         208 :                     $$ = (Node *) n;
    6456             :                 }
    6457             :             | CREATE TYPE_P any_name AS RANGE definition
    6458             :                 {
    6459         196 :                     CreateRangeStmt *n = makeNode(CreateRangeStmt);
    6460             : 
    6461         196 :                     n->typeName = $3;
    6462         196 :                     n->params = $6;
    6463         196 :                     $$ = (Node *) n;
    6464             :                 }
    6465             :             | CREATE TEXT_P SEARCH PARSER any_name definition
    6466             :                 {
    6467          40 :                     DefineStmt *n = makeNode(DefineStmt);
    6468             : 
    6469          40 :                     n->kind = OBJECT_TSPARSER;
    6470          40 :                     n->args = NIL;
    6471          40 :                     n->defnames = $5;
    6472          40 :                     n->definition = $6;
    6473          40 :                     $$ = (Node *) n;
    6474             :                 }
    6475             :             | CREATE TEXT_P SEARCH DICTIONARY any_name definition
    6476             :                 {
    6477        3006 :                     DefineStmt *n = makeNode(DefineStmt);
    6478             : 
    6479        3006 :                     n->kind = OBJECT_TSDICTIONARY;
    6480        3006 :                     n->args = NIL;
    6481        3006 :                     n->defnames = $5;
    6482        3006 :                     n->definition = $6;
    6483        3006 :                     $$ = (Node *) n;
    6484             :                 }
    6485             :             | CREATE TEXT_P SEARCH TEMPLATE any_name definition
    6486             :                 {
    6487         142 :                     DefineStmt *n = makeNode(DefineStmt);
    6488             : 
    6489         142 :                     n->kind = OBJECT_TSTEMPLATE;
    6490         142 :                     n->args = NIL;
    6491         142 :                     n->defnames = $5;
    6492         142 :                     n->definition = $6;
    6493         142 :                     $$ = (Node *) n;
    6494             :                 }
    6495             :             | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
    6496             :                 {
    6497        2938 :                     DefineStmt *n = makeNode(DefineStmt);
    6498             : 
    6499        2938 :                     n->kind = OBJECT_TSCONFIGURATION;
    6500        2938 :                     n->args = NIL;
    6501        2938 :                     n->defnames = $5;
    6502        2938 :                     n->definition = $6;
    6503        2938 :                     $$ = (Node *) n;
    6504             :                 }
    6505             :             | CREATE COLLATION any_name definition
    6506             :                 {
    6507         298 :                     DefineStmt *n = makeNode(DefineStmt);
    6508             : 
    6509         298 :                     n->kind = OBJECT_COLLATION;
    6510         298 :                     n->args = NIL;
    6511         298 :                     n->defnames = $3;
    6512         298 :                     n->definition = $4;
    6513         298 :                     $$ = (Node *) n;
    6514             :                 }
    6515             :             | CREATE COLLATION IF_P NOT EXISTS any_name definition
    6516             :                 {
    6517          18 :                     DefineStmt *n = makeNode(DefineStmt);
    6518             : 
    6519          18 :                     n->kind = OBJECT_COLLATION;
    6520          18 :                     n->args = NIL;
    6521          18 :                     n->defnames = $6;
    6522          18 :                     n->definition = $7;
    6523          18 :                     n->if_not_exists = true;
    6524          18 :                     $$ = (Node *) n;
    6525             :                 }
    6526             :             | CREATE COLLATION any_name FROM any_name
    6527             :                 {
    6528          54 :                     DefineStmt *n = makeNode(DefineStmt);
    6529             : 
    6530          54 :                     n->kind = OBJECT_COLLATION;
    6531          54 :                     n->args = NIL;
    6532          54 :                     n->defnames = $3;
    6533          54 :                     n->definition = list_make1(makeDefElem("from", (Node *) $5, @5));
    6534          54 :                     $$ = (Node *) n;
    6535             :                 }
    6536             :             | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
    6537             :                 {
    6538           0 :                     DefineStmt *n = makeNode(DefineStmt);
    6539             : 
    6540           0 :                     n->kind = OBJECT_COLLATION;
    6541           0 :                     n->args = NIL;
    6542           0 :                     n->defnames = $6;
    6543           0 :                     n->definition = list_make1(makeDefElem("from", (Node *) $8, @8));
    6544           0 :                     n->if_not_exists = true;
    6545           0 :                     $$ = (Node *) n;
    6546             :                 }
    6547             :         ;
    6548             : 
    6549       10088 : definition: '(' def_list ')'                        { $$ = $2; }
    6550             :         ;
    6551             : 
    6552       10088 : def_list:   def_elem                                { $$ = list_make1($1); }
    6553       15114 :             | def_list ',' def_elem                 { $$ = lappend($1, $3); }
    6554             :         ;
    6555             : 
    6556             : def_elem:   ColLabel '=' def_arg
    6557             :                 {
    6558       24844 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6559             :                 }
    6560             :             | ColLabel
    6561             :                 {
    6562         358 :                     $$ = makeDefElem($1, NULL, @1);
    6563             :                 }
    6564             :         ;
    6565             : 
    6566             : /* Note: any simple identifier will be returned as a type name! */
    6567       20130 : def_arg:    func_type                       { $$ = (Node *) $1; }
    6568        4128 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
    6569        1186 :             | qual_all_Op                   { $$ = (Node *) $1; }
    6570        1306 :             | NumericOnly                   { $$ = (Node *) $1; }
    6571        2048 :             | Sconst                        { $$ = (Node *) makeString($1); }
    6572         164 :             | NONE                          { $$ = (Node *) makeString(pstrdup($1)); }
    6573             :         ;
    6574             : 
    6575         362 : old_aggr_definition: '(' old_aggr_list ')'          { $$ = $2; }
    6576             :         ;
    6577             : 
    6578         362 : old_aggr_list: old_aggr_elem                        { $$ = list_make1($1); }
    6579        1292 :             | old_aggr_list ',' old_aggr_elem       { $$ = lappend($1, $3); }
    6580             :         ;
    6581             : 
    6582             : /*
    6583             :  * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
    6584             :  * the item names needed in old aggregate definitions are likely to become
    6585             :  * SQL keywords.
    6586             :  */
    6587             : old_aggr_elem:  IDENT '=' def_arg
    6588             :                 {
    6589        1654 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6590             :                 }
    6591             :         ;
    6592             : 
    6593             : opt_enum_val_list:
    6594         200 :         enum_val_list                           { $$ = $1; }
    6595           8 :         | /*EMPTY*/                             { $$ = NIL; }
    6596             :         ;
    6597             : 
    6598             : enum_val_list:  Sconst
    6599         200 :                 { $$ = list_make1(makeString($1)); }
    6600             :             | enum_val_list ',' Sconst
    6601       10496 :                 { $$ = lappend($1, makeString($3)); }
    6602             :         ;
    6603             : 
    6604             : /*****************************************************************************
    6605             :  *
    6606             :  *  ALTER TYPE enumtype ADD ...
    6607             :  *
    6608             :  *****************************************************************************/
    6609             : 
    6610             : AlterEnumStmt:
    6611             :         ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
    6612             :             {
    6613         154 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6614             : 
    6615         154 :                 n->typeName = $3;
    6616         154 :                 n->oldVal = NULL;
    6617         154 :                 n->newVal = $7;
    6618         154 :                 n->newValNeighbor = NULL;
    6619         154 :                 n->newValIsAfter = true;
    6620         154 :                 n->skipIfNewValExists = $6;
    6621         154 :                 $$ = (Node *) n;
    6622             :             }
    6623             :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
    6624             :             {
    6625         196 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6626             : 
    6627         196 :                 n->typeName = $3;
    6628         196 :                 n->oldVal = NULL;
    6629         196 :                 n->newVal = $7;
    6630         196 :                 n->newValNeighbor = $9;
    6631         196 :                 n->newValIsAfter = false;
    6632         196 :                 n->skipIfNewValExists = $6;
    6633         196 :                 $$ = (Node *) n;
    6634             :             }
    6635             :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
    6636             :             {
    6637          22 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6638             : 
    6639          22 :                 n->typeName = $3;
    6640          22 :                 n->oldVal = NULL;
    6641          22 :                 n->newVal = $7;
    6642          22 :                 n->newValNeighbor = $9;
    6643          22 :                 n->newValIsAfter = true;
    6644          22 :                 n->skipIfNewValExists = $6;
    6645          22 :                 $$ = (Node *) n;
    6646             :             }
    6647             :          | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
    6648             :             {
    6649          24 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6650             : 
    6651          24 :                 n->typeName = $3;
    6652          24 :                 n->oldVal = $6;
    6653          24 :                 n->newVal = $8;
    6654          24 :                 n->newValNeighbor = NULL;
    6655          24 :                 n->newValIsAfter = false;
    6656          24 :                 n->skipIfNewValExists = false;
    6657          24 :                 $$ = (Node *) n;
    6658             :             }
    6659             :          | ALTER TYPE_P any_name DROP VALUE_P Sconst
    6660             :             {
    6661             :                 /*
    6662             :                  * The following problems must be solved before this can be
    6663             :                  * implemented:
    6664             :                  *
    6665             :                  * - There must be no instance of the target value in
    6666             :                  *   any table.
    6667             :                  *
    6668             :                  * - The value must not appear in any catalog metadata,
    6669             :                  *   such as stored view expressions or column defaults.
    6670             :                  *
    6671             :                  * - The value must not appear in any non-leaf page of a
    6672             :                  *   btree (and similar issues with other index types).
    6673             :                  *   This is problematic because a value could persist
    6674             :                  *   there long after it's gone from user-visible data.
    6675             :                  *
    6676             :                  * - Concurrent sessions must not be able to insert the
    6677             :                  *   value while the preceding conditions are being checked.
    6678             :                  *
    6679             :                  * - Possibly more...
    6680             :                  */
    6681           0 :                 ereport(ERROR,
    6682             :                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6683             :                          errmsg("dropping an enum value is not implemented"),
    6684             :                          parser_errposition(@4)));
    6685             :             }
    6686             :          ;
    6687             : 
    6688          12 : opt_if_not_exists: IF_P NOT EXISTS              { $$ = true; }
    6689         360 :         | /* EMPTY */                          { $$ = false; }
    6690             :         ;
    6691             : 
    6692             : 
    6693             : /*****************************************************************************
    6694             :  *
    6695             :  *      QUERIES :
    6696             :  *              CREATE OPERATOR CLASS ...
    6697             :  *              CREATE OPERATOR FAMILY ...
    6698             :  *              ALTER OPERATOR FAMILY ...
    6699             :  *              DROP OPERATOR CLASS ...
    6700             :  *              DROP OPERATOR FAMILY ...
    6701             :  *
    6702             :  *****************************************************************************/
    6703             : 
    6704             : CreateOpClassStmt:
    6705             :             CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
    6706             :             USING name opt_opfamily AS opclass_item_list
    6707             :                 {
    6708         394 :                     CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
    6709             : 
    6710         394 :                     n->opclassname = $4;
    6711         394 :                     n->isDefault = $5;
    6712         394 :                     n->datatype = $8;
    6713         394 :                     n->amname = $10;
    6714         394 :                     n->opfamilyname = $11;
    6715         394 :                     n->items = $13;
    6716         394 :                     $$ = (Node *) n;
    6717             :                 }
    6718             :         ;
    6719             : 
    6720             : opclass_item_list:
    6721         928 :             opclass_item                            { $$ = list_make1($1); }
    6722        3228 :             | opclass_item_list ',' opclass_item    { $$ = lappend($1, $3); }
    6723             :         ;
    6724             : 
    6725             : opclass_item:
    6726             :             OPERATOR Iconst any_operator opclass_purpose
    6727             :                 {
    6728        1092 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6729        1092 :                     ObjectWithArgs *owa = makeNode(ObjectWithArgs);
    6730             : 
    6731        1092 :                     owa->objname = $3;
    6732        1092 :                     owa->objargs = NIL;
    6733        1092 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6734        1092 :                     n->name = owa;
    6735        1092 :                     n->number = $2;
    6736        1092 :                     n->order_family = $4;
    6737        1092 :                     $$ = (Node *) n;
    6738             :                 }
    6739             :             | OPERATOR Iconst operator_with_argtypes opclass_purpose
    6740             :                 {
    6741        1226 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6742             : 
    6743        1226 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6744        1226 :                     n->name = $3;
    6745        1226 :                     n->number = $2;
    6746        1226 :                     n->order_family = $4;
    6747        1226 :                     $$ = (Node *) n;
    6748             :                 }
    6749             :             | FUNCTION Iconst function_with_argtypes
    6750             :                 {
    6751        1386 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6752             : 
    6753        1386 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6754        1386 :                     n->name = $3;
    6755        1386 :                     n->number = $2;
    6756        1386 :                     $$ = (Node *) n;
    6757             :                 }
    6758             :             | FUNCTION Iconst '(' type_list ')' function_with_argtypes
    6759             :                 {
    6760         252 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6761             : 
    6762         252 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6763         252 :                     n->name = $6;
    6764         252 :                     n->number = $2;
    6765         252 :                     n->class_args = $4;
    6766         252 :                     $$ = (Node *) n;
    6767             :                 }
    6768             :             | STORAGE Typename
    6769             :                 {
    6770         200 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6771             : 
    6772         200 :                     n->itemtype = OPCLASS_ITEM_STORAGETYPE;
    6773         200 :                     n->storedtype = $2;
    6774         200 :                     $$ = (Node *) n;
    6775             :                 }
    6776             :         ;
    6777             : 
    6778         290 : opt_default:    DEFAULT                     { $$ = true; }
    6779         168 :             | /*EMPTY*/                     { $$ = false; }
    6780             :         ;
    6781             : 
    6782          50 : opt_opfamily:   FAMILY any_name             { $$ = $2; }
    6783         344 :             | /*EMPTY*/                     { $$ = NIL; }
    6784             :         ;
    6785             : 
    6786           0 : opclass_purpose: FOR SEARCH                 { $$ = NIL; }
    6787          72 :             | FOR ORDER BY any_name         { $$ = $4; }
    6788        2246 :             | /*EMPTY*/                     { $$ = NIL; }
    6789             :         ;
    6790             : 
    6791             : 
    6792             : CreateOpFamilyStmt:
    6793             :             CREATE OPERATOR FAMILY any_name USING name
    6794             :                 {
    6795         162 :                     CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
    6796             : 
    6797         162 :                     n->opfamilyname = $4;
    6798         162 :                     n->amname = $6;
    6799         162 :                     $$ = (Node *) n;
    6800             :                 }
    6801             :         ;
    6802             : 
    6803             : AlterOpFamilyStmt:
    6804             :             ALTER OPERATOR FAMILY any_name USING name ADD_P opclass_item_list
    6805             :                 {
    6806         534 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6807             : 
    6808         534 :                     n->opfamilyname = $4;
    6809         534 :                     n->amname = $6;
    6810         534 :                     n->isDrop = false;
    6811         534 :                     n->items = $8;
    6812         534 :                     $$ = (Node *) n;
    6813             :                 }
    6814             :             | ALTER OPERATOR FAMILY any_name USING name DROP opclass_drop_list
    6815             :                 {
    6816          64 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6817             : 
    6818          64 :                     n->opfamilyname = $4;
    6819          64 :                     n->amname = $6;
    6820          64 :                     n->isDrop = true;
    6821          64 :                     n->items = $8;
    6822          64 :                     $$ = (Node *) n;
    6823             :                 }
    6824             :         ;
    6825             : 
    6826             : opclass_drop_list:
    6827          64 :             opclass_drop                            { $$ = list_make1($1); }
    6828          30 :             | opclass_drop_list ',' opclass_drop    { $$ = lappend($1, $3); }
    6829             :         ;
    6830             : 
    6831             : opclass_drop:
    6832             :             OPERATOR Iconst '(' type_list ')'
    6833             :                 {
    6834          56 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6835             : 
    6836          56 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6837          56 :                     n->number = $2;
    6838          56 :                     n->class_args = $4;
    6839          56 :                     $$ = (Node *) n;
    6840             :                 }
    6841             :             | FUNCTION Iconst '(' type_list ')'
    6842             :                 {
    6843          38 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6844             : 
    6845          38 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6846          38 :                     n->number = $2;
    6847          38 :                     n->class_args = $4;
    6848          38 :                     $$ = (Node *) n;
    6849             :                 }
    6850             :         ;
    6851             : 
    6852             : 
    6853             : DropOpClassStmt:
    6854             :             DROP OPERATOR CLASS any_name USING name opt_drop_behavior
    6855             :                 {
    6856          38 :                     DropStmt *n = makeNode(DropStmt);
    6857             : 
    6858          38 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6859          38 :                     n->removeType = OBJECT_OPCLASS;
    6860          38 :                     n->behavior = $7;
    6861          38 :                     n->missing_ok = false;
    6862          38 :                     n->concurrent = false;
    6863          38 :                     $$ = (Node *) n;
    6864             :                 }
    6865             :             | DROP OPERATOR CLASS IF_P EXISTS any_name USING name opt_drop_behavior
    6866             :                 {
    6867          18 :                     DropStmt *n = makeNode(DropStmt);
    6868             : 
    6869          18 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6870          18 :                     n->removeType = OBJECT_OPCLASS;
    6871          18 :                     n->behavior = $9;
    6872          18 :                     n->missing_ok = true;
    6873          18 :                     n->concurrent = false;
    6874          18 :                     $$ = (Node *) n;
    6875             :                 }
    6876             :         ;
    6877             : 
    6878             : DropOpFamilyStmt:
    6879             :             DROP OPERATOR FAMILY any_name USING name opt_drop_behavior
    6880             :                 {
    6881         110 :                     DropStmt *n = makeNode(DropStmt);
    6882             : 
    6883         110 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6884         110 :                     n->removeType = OBJECT_OPFAMILY;
    6885         110 :                     n->behavior = $7;
    6886         110 :                     n->missing_ok = false;
    6887         110 :                     n->concurrent = false;
    6888         110 :                     $$ = (Node *) n;
    6889             :                 }
    6890             :             | DROP OPERATOR FAMILY IF_P EXISTS any_name USING name opt_drop_behavior
    6891             :                 {
    6892          18 :                     DropStmt *n = makeNode(DropStmt);
    6893             : 
    6894          18 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6895          18 :                     n->removeType = OBJECT_OPFAMILY;
    6896          18 :                     n->behavior = $9;
    6897          18 :                     n->missing_ok = true;
    6898          18 :                     n->concurrent = false;
    6899          18 :                     $$ = (Node *) n;
    6900             :                 }
    6901             :         ;
    6902             : 
    6903             : 
    6904             : /*****************************************************************************
    6905             :  *
    6906             :  *      QUERY:
    6907             :  *
    6908             :  *      DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
    6909             :  *      REASSIGN OWNED BY username [, username ...] TO username
    6910             :  *
    6911             :  *****************************************************************************/
    6912             : DropOwnedStmt:
    6913             :             DROP OWNED BY role_list opt_drop_behavior
    6914             :                 {
    6915         152 :                     DropOwnedStmt *n = makeNode(DropOwnedStmt);
    6916             : 
    6917         152 :                     n->roles = $4;
    6918         152 :                     n->behavior = $5;
    6919         152 :                     $$ = (Node *) n;
    6920             :                 }
    6921             :         ;
    6922             : 
    6923             : ReassignOwnedStmt:
    6924             :             REASSIGN OWNED BY role_list TO RoleSpec
    6925             :                 {
    6926          52 :                     ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
    6927             : 
    6928          52 :                     n->roles = $4;
    6929          52 :                     n->newrole = $6;
    6930          52 :                     $$ = (Node *) n;
    6931             :                 }
    6932             :         ;
    6933             : 
    6934             : /*****************************************************************************
    6935             :  *
    6936             :  *      QUERY:
    6937             :  *
    6938             :  *      DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
    6939             :  *           [ RESTRICT | CASCADE ]
    6940             :  *
    6941             :  *****************************************************************************/
    6942             : 
    6943             : DropStmt:   DROP object_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
    6944             :                 {
    6945        1334 :                     DropStmt *n = makeNode(DropStmt);
    6946             : 
    6947        1334 :                     n->removeType = $2;
    6948        1334 :                     n->missing_ok = true;
    6949        1334 :                     n->objects = $5;
    6950        1334 :                     n->behavior = $6;
    6951        1334 :                     n->concurrent = false;
    6952        1334 :                     $$ = (Node *) n;
    6953             :                 }
    6954             :             | DROP object_type_any_name any_name_list opt_drop_behavior
    6955             :                 {
    6956       16002 :                     DropStmt *n = makeNode(DropStmt);
    6957             : 
    6958       16002 :                     n->removeType = $2;
    6959       16002 :                     n->missing_ok = false;
    6960       16002 :                     n->objects = $3;
    6961       16002 :                     n->behavior = $4;
    6962       16002 :                     n->concurrent = false;
    6963       16002 :                     $$ = (Node *) n;
    6964             :                 }
    6965             :             | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
    6966             :                 {
    6967          78 :                     DropStmt *n = makeNode(DropStmt);
    6968             : 
    6969          78 :                     n->removeType = $2;
    6970          78 :                     n->missing_ok = true;
    6971          78 :                     n->objects = $5;
    6972          78 :                     n->behavior = $6;
    6973          78 :                     n->concurrent = false;
    6974          78 :                     $$ = (Node *) n;
    6975             :                 }
    6976             :             | DROP drop_type_name name_list opt_drop_behavior
    6977             :                 {
    6978        1412 :                     DropStmt *n = makeNode(DropStmt);
    6979             : 
    6980        1412 :                     n->removeType = $2;
    6981        1412 :                     n->missing_ok = false;
    6982        1412 :                     n->objects = $3;
    6983        1412 :                     n->behavior = $4;
    6984        1412 :                     n->concurrent = false;
    6985        1412 :                     $$ = (Node *) n;
    6986             :                 }
    6987             :             | DROP object_type_name_on_any_name name ON any_name opt_drop_behavior
    6988             :                 {
    6989        1130 :                     DropStmt *n = makeNode(DropStmt);
    6990             : 
    6991        1130 :                     n->removeType = $2;
    6992        1130 :                     n->objects = list_make1(lappend($5, makeString($3)));
    6993        1130 :                     n->behavior = $6;
    6994        1130 :                     n->missing_ok = false;
    6995        1130 :                     n->concurrent = false;
    6996        1130 :                     $$ = (Node *) n;
    6997             :                 }
    6998             :             | DROP object_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
    6999             :                 {
    7000          48 :                     DropStmt *n = makeNode(DropStmt);
    7001             : 
    7002          48 :                     n->removeType = $2;
    7003          48 :                     n->objects = list_make1(lappend($7, makeString($5)));
    7004          48 :                     n->behavior = $8;
    7005          48 :                     n->missing_ok = true;
    7006          48 :                     n->concurrent = false;
    7007          48 :                     $$ = (Node *) n;
    7008             :                 }
    7009             :             | DROP TYPE_P type_name_list opt_drop_behavior
    7010             :                 {
    7011         560 :                     DropStmt *n = makeNode(DropStmt);
    7012             : 
    7013         560 :                     n->removeType = OBJECT_TYPE;
    7014         560 :                     n->missing_ok = false;
    7015         560 :                     n->objects = $3;
    7016         560 :                     n->behavior = $4;
    7017         560 :                     n->concurrent = false;
    7018         560 :                     $$ = (Node *) n;
    7019             :                 }
    7020             :             | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
    7021             :                 {
    7022          26 :                     DropStmt *n = makeNode(DropStmt);
    7023             : 
    7024          26 :                     n->removeType = OBJECT_TYPE;
    7025          26 :                     n->missing_ok = true;
    7026          26 :                     n->objects = $5;
    7027          26 :                     n->behavior = $6;
    7028          26 :                     n->concurrent = false;
    7029          26 :                     $$ = (Node *) n;
    7030             :                 }
    7031             :             | DROP DOMAIN_P type_name_list opt_drop_behavior
    7032             :                 {
    7033         464 :                     DropStmt *n = makeNode(DropStmt);
    7034             : 
    7035         464 :                     n->removeType = OBJECT_DOMAIN;
    7036         464 :                     n->missing_ok = false;
    7037         464 :                     n->objects = $3;
    7038         464 :                     n->behavior = $4;
    7039         464 :                     n->concurrent = false;
    7040         464 :                     $$ = (Node *) n;
    7041             :                 }
    7042             :             | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
    7043             :                 {
    7044          18 :                     DropStmt *n = makeNode(DropStmt);
    7045             : 
    7046          18 :                     n->removeType = OBJECT_DOMAIN;
    7047          18 :                     n->missing_ok = true;
    7048          18 :                     n->objects = $5;
    7049          18 :                     n->behavior = $6;
    7050          18 :                     n->concurrent = false;
    7051          18 :                     $$ = (Node *) n;
    7052             :                 }
    7053             :             | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
    7054             :                 {
    7055         226 :                     DropStmt *n = makeNode(DropStmt);
    7056             : 
    7057         226 :                     n->removeType = OBJECT_INDEX;
    7058         226 :                     n->missing_ok = false;
    7059         226 :                     n->objects = $4;
    7060         226 :                     n->behavior = $5;
    7061         226 :                     n->concurrent = true;
    7062         226 :                     $$ = (Node *) n;
    7063             :                 }
    7064             :             | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
    7065             :                 {
    7066          12 :                     DropStmt *n = makeNode(DropStmt);
    7067             : 
    7068          12 :                     n->removeType = OBJECT_INDEX;
    7069          12 :                     n->missing_ok = true;
    7070          12 :                     n->objects = $6;
    7071          12 :                     n->behavior = $7;
    7072          12 :                     n->concurrent = true;
    7073          12 :                     $$ = (Node *) n;
    7074             :                 }
    7075             :         ;
    7076             : 
    7077             : /* object types taking any_name/any_name_list */
    7078             : object_type_any_name:
    7079       14952 :             TABLE                                   { $$ = OBJECT_TABLE; }
    7080         192 :             | SEQUENCE                              { $$ = OBJECT_SEQUENCE; }
    7081        1010 :             | VIEW                                  { $$ = OBJECT_VIEW; }
    7082         130 :             | MATERIALIZED VIEW                     { $$ = OBJECT_MATVIEW; }
    7083         784 :             | INDEX                                 { $$ = OBJECT_INDEX; }
    7084         184 :             | FOREIGN TABLE                         { $$ = OBJECT_FOREIGN_TABLE; }
    7085          96 :             | COLLATION                             { $$ = OBJECT_COLLATION; }
    7086          56 :             | CONVERSION_P                          { $$ = OBJECT_CONVERSION; }
    7087         210 :             | STATISTICS                            { $$ = OBJECT_STATISTIC_EXT; }
    7088          20 :             | TEXT_P SEARCH PARSER                  { $$ = OBJECT_TSPARSER; }
    7089        2872 :             | TEXT_P SEARCH DICTIONARY              { $$ = OBJECT_TSDICTIONARY; }
    7090         118 :             | TEXT_P SEARCH TEMPLATE                { $$ = OBJECT_TSTEMPLATE; }
    7091        2876 :             | TEXT_P SEARCH CONFIGURATION           { $$ = OBJECT_TSCONFIGURATION; }
    7092             :         ;
    7093             : 
    7094             : /*
    7095             :  * object types taking name/name_list
    7096             :  *
    7097             :  * DROP handles some of them separately
    7098             :  */
    7099             : 
    7100             : object_type_name:
    7101         234 :             drop_type_name                          { $$ = $1; }
    7102         242 :             | DATABASE                              { $$ = OBJECT_DATABASE; }
    7103          52 :             | ROLE                                  { $$ = OBJECT_ROLE; }
    7104          10 :             | SUBSCRIPTION                          { $$ = OBJECT_SUBSCRIPTION; }
    7105           0 :             | TABLESPACE                            { $$ = OBJECT_TABLESPACE; }
    7106             :         ;
    7107             : 
    7108             : drop_type_name:
    7109          46 :             ACCESS METHOD                           { $$ = OBJECT_ACCESS_METHOD; }
    7110         124 :             | EVENT TRIGGER                         { $$ = OBJECT_EVENT_TRIGGER; }
    7111         150 :             | EXTENSION                             { $$ = OBJECT_EXTENSION; }
    7112         154 :             | FOREIGN DATA_P WRAPPER                { $$ = OBJECT_FDW; }
    7113         156 :             | opt_procedural LANGUAGE               { $$ = OBJECT_LANGUAGE; }
    7114         382 :             | PUBLICATION                           { $$ = OBJECT_PUBLICATION; }
    7115         582 :             | SCHEMA                                { $$ = OBJECT_SCHEMA; }
    7116         130 :             | SERVER                                { $$ = OBJECT_FOREIGN_SERVER; }
    7117             :         ;
    7118             : 
    7119             : /* object types attached to a table */
    7120             : object_type_name_on_any_name:
    7121         164 :             POLICY                                  { $$ = OBJECT_POLICY; }
    7122         268 :             | RULE                                  { $$ = OBJECT_RULE; }
    7123         798 :             | TRIGGER                               { $$ = OBJECT_TRIGGER; }
    7124             :         ;
    7125             : 
    7126             : any_name_list:
    7127       26582 :             any_name                                { $$ = list_make1($1); }
    7128        4240 :             | any_name_list ',' any_name            { $$ = lappend($1, $3); }
    7129             :         ;
    7130             : 
    7131       67534 : any_name:   ColId                       { $$ = list_make1(makeString($1)); }
    7132        9612 :             | ColId attrs               { $$ = lcons(makeString($1), $2); }
    7133             :         ;
    7134             : 
    7135             : attrs:      '.' attr_name
    7136      129932 :                     { $$ = list_make1(makeString($2)); }
    7137             :             | attrs '.' attr_name
    7138          96 :                     { $$ = lappend($1, makeString($3)); }
    7139             :         ;
    7140             : 
    7141             : type_name_list:
    7142        1068 :             Typename                                { $$ = list_make1($1); }
    7143          96 :             | type_name_list ',' Typename           { $$ = lappend($1, $3); }
    7144             :         ;
    7145             : 
    7146             : /*****************************************************************************
    7147             :  *
    7148             :  *      QUERY:
    7149             :  *              truncate table relname1, relname2, ...
    7150             :  *
    7151             :  *****************************************************************************/
    7152             : 
    7153             : TruncateStmt:
    7154             :             TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
    7155             :                 {
    7156        2956 :                     TruncateStmt *n = makeNode(TruncateStmt);
    7157             : 
    7158        2956 :                     n->relations = $3;
    7159        2956 :                     n->restart_seqs = $4;
    7160        2956 :                     n->behavior = $5;
    7161        2956 :                     $$ = (Node *) n;
    7162             :                 }
    7163             :         ;
    7164             : 
    7165             : opt_restart_seqs:
    7166          24 :             CONTINUE_P IDENTITY_P       { $$ = false; }
    7167          22 :             | RESTART IDENTITY_P        { $$ = true; }
    7168        2910 :             | /* EMPTY */               { $$ = false; }
    7169             :         ;
    7170             : 
    7171             : /*****************************************************************************
    7172             :  *
    7173             :  * COMMENT ON <object> IS <text>
    7174             :  *
    7175             :  *****************************************************************************/
    7176             : 
    7177             : CommentStmt:
    7178             :             COMMENT ON object_type_any_name any_name IS comment_text
    7179             :                 {
    7180        6022 :                     CommentStmt *n = makeNode(CommentStmt);
    7181             : 
    7182        6022 :                     n->objtype = $3;
    7183        6022 :                     n->object = (Node *) $4;
    7184        6022 :                     n->comment = $6;
    7185        6022 :                     $$ = (Node *) n;
    7186             :                 }
    7187             :             | COMMENT ON COLUMN any_name IS comment_text
    7188             :                 {
    7189         118 :                     CommentStmt *n = makeNode(CommentStmt);
    7190             : 
    7191         118 :                     n->objtype = OBJECT_COLUMN;
    7192         118 :                     n->object = (Node *) $4;
    7193         118 :                     n->comment = $6;
    7194         118 :                     $$ = (Node *) n;
    7195             :                 }
    7196             :             | COMMENT ON object_type_name name IS comment_text
    7197             :                 {
    7198         476 :                     CommentStmt *n = makeNode(CommentStmt);
    7199             : 
    7200         476 :                     n->objtype = $3;
    7201         476 :                     n->object = (Node *) makeString($4);
    7202         476 :                     n->comment = $6;
    7203         476 :                     $$ = (Node *) n;
    7204             :                 }
    7205             :             | COMMENT ON TYPE_P Typename IS comment_text
    7206             :                 {
    7207          56 :                     CommentStmt *n = makeNode(CommentStmt);
    7208             : 
    7209          56 :                     n->objtype = OBJECT_TYPE;
    7210          56 :                     n->object = (Node *) $4;
    7211          56 :                     n->comment = $6;
    7212          56 :                     $$ = (Node *) n;
    7213             :                 }
    7214             :             | COMMENT ON DOMAIN_P Typename IS comment_text
    7215             :                 {
    7216           8 :                     CommentStmt *n = makeNode(CommentStmt);
    7217             : 
    7218           8 :                     n->objtype = OBJECT_DOMAIN;
    7219           8 :                     n->object = (Node *) $4;
    7220           8 :                     n->comment = $6;
    7221           8 :                     $$ = (Node *) n;
    7222             :                 }
    7223             :             | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
    7224             :                 {
    7225          44 :                     CommentStmt *n = makeNode(CommentStmt);
    7226             : 
    7227          44 :                     n->objtype = OBJECT_AGGREGATE;
    7228          44 :                     n->object = (Node *) $4;
    7229          44 :                     n->comment = $6;
    7230          44 :                     $$ = (Node *) n;
    7231             :                 }
    7232             :             | COMMENT ON FUNCTION function_with_argtypes IS comment_text
    7233             :                 {
    7234         170 :                     CommentStmt *n = makeNode(CommentStmt);
    7235             : 
    7236         170 :                     n->objtype = OBJECT_FUNCTION;
    7237         170 :                     n->object = (Node *) $4;
    7238         170 :                     n->comment = $6;
    7239         170 :                     $$ = (Node *) n;
    7240             :                 }
    7241             :             | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
    7242             :                 {
    7243          18 :                     CommentStmt *n = makeNode(CommentStmt);
    7244             : 
    7245          18 :                     n->objtype = OBJECT_OPERATOR;
    7246          18 :                     n->object = (Node *) $4;
    7247          18 :                     n->comment = $6;
    7248          18 :                     $$ = (Node *) n;
    7249             :                 }
    7250             :             | COMMENT ON CONSTRAINT name ON any_name IS comment_text
    7251             :                 {
    7252         162 :                     CommentStmt *n = makeNode(CommentStmt);
    7253             : 
    7254         162 :                     n->objtype = OBJECT_TABCONSTRAINT;
    7255         162 :                     n->object = (Node *) lappend($6, makeString($4));
    7256         162 :                     n->comment = $8;
    7257         162 :                     $$ = (Node *) n;
    7258             :                 }
    7259             :             | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
    7260             :                 {
    7261          48 :                     CommentStmt *n = makeNode(CommentStmt);
    7262             : 
    7263          48 :                     n->objtype = OBJECT_DOMCONSTRAINT;
    7264             :                     /*
    7265             :                      * should use Typename not any_name in the production, but
    7266             :                      * there's a shift/reduce conflict if we do that, so fix it
    7267             :                      * up here.
    7268             :                      */
    7269          48 :                     n->object = (Node *) list_make2(makeTypeNameFromNameList($7), makeString($4));
    7270          48 :                     n->comment = $9;
    7271          48 :                     $$ = (Node *) n;
    7272             :                 }
    7273             :             | COMMENT ON object_type_name_on_any_name name ON any_name IS comment_text
    7274             :                 {
    7275          40 :                     CommentStmt *n = makeNode(CommentStmt);
    7276             : 
    7277          40 :                     n->objtype = $3;
    7278          40 :                     n->object = (Node *) lappend($6, makeString($4));
    7279          40 :                     n->comment = $8;
    7280          40 :                     $$ = (Node *) n;
    7281             :                 }
    7282             :             | COMMENT ON PROCEDURE function_with_argtypes IS comment_text
    7283             :                 {
    7284           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7285             : 
    7286           0 :                     n->objtype = OBJECT_PROCEDURE;
    7287           0 :                     n->object = (Node *) $4;
    7288           0 :                     n->comment = $6;
    7289           0 :                     $$ = (Node *) n;
    7290             :                 }
    7291             :             | COMMENT ON ROUTINE function_with_argtypes IS comment_text
    7292             :                 {
    7293           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7294             : 
    7295           0 :                     n->objtype = OBJECT_ROUTINE;
    7296           0 :                     n->object = (Node *) $4;
    7297           0 :                     n->comment = $6;
    7298           0 :                     $$ = (Node *) n;
    7299             :                 }
    7300             :             | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
    7301             :                 {
    7302          14 :                     CommentStmt *n = makeNode(CommentStmt);
    7303             : 
    7304          14 :                     n->objtype = OBJECT_TRANSFORM;
    7305          14 :                     n->object = (Node *) list_make2($5, makeString($7));
    7306          14 :                     n->comment = $9;
    7307          14 :                     $$ = (Node *) n;
    7308             :                 }
    7309             :             | COMMENT ON OPERATOR CLASS any_name USING name IS comment_text
    7310             :                 {
    7311           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7312             : 
    7313           0 :                     n->objtype = OBJECT_OPCLASS;
    7314           0 :                     n->object = (Node *) lcons(makeString($7), $5);
    7315           0 :                     n->comment = $9;
    7316           0 :                     $$ = (Node *) n;
    7317             :                 }
    7318             :             | COMMENT ON OPERATOR FAMILY any_name USING name IS comment_text
    7319             :                 {
    7320           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7321             : 
    7322           0 :                     n->objtype = OBJECT_OPFAMILY;
    7323           0 :                     n->object = (Node *) lcons(makeString($7), $5);
    7324           0 :                     n->comment = $9;
    7325           0 :                     $$ = (Node *) n;
    7326             :                 }
    7327             :             | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
    7328             :                 {
    7329          28 :                     CommentStmt *n = makeNode(CommentStmt);
    7330             : 
    7331          28 :                     n->objtype = OBJECT_LARGEOBJECT;
    7332          28 :                     n->object = (Node *) $5;
    7333          28 :                     n->comment = $7;
    7334          28 :                     $$ = (Node *) n;
    7335             :                 }
    7336             :             | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
    7337             :                 {
    7338           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7339             : 
    7340           0 :                     n->objtype = OBJECT_CAST;
    7341           0 :                     n->object = (Node *) list_make2($5, $7);
    7342           0 :                     n->comment = $10;
    7343           0 :                     $$ = (Node *) n;
    7344             :                 }
    7345             :         ;
    7346             : 
    7347             : comment_text:
    7348        7100 :             Sconst                              { $$ = $1; }
    7349         104 :             | NULL_P                            { $$ = NULL; }
    7350             :         ;
    7351             : 
    7352             : 
    7353             : /*****************************************************************************
    7354             :  *
    7355             :  *  SECURITY LABEL [FOR <provider>] ON <object> IS <label>
    7356             :  *
    7357             :  *  As with COMMENT ON, <object> can refer to various types of database
    7358             :  *  objects (e.g. TABLE, COLUMN, etc.).
    7359             :  *
    7360             :  *****************************************************************************/
    7361             : 
    7362             : SecLabelStmt:
    7363             :             SECURITY LABEL opt_provider ON object_type_any_name any_name
    7364             :             IS security_label
    7365             :                 {
    7366          48 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7367             : 
    7368          48 :                     n->provider = $3;
    7369          48 :                     n->objtype = $5;
    7370          48 :                     n->object = (Node *) $6;
    7371          48 :                     n->label = $8;
    7372          48 :                     $$ = (Node *) n;
    7373             :                 }
    7374             :             | SECURITY LABEL opt_provider ON COLUMN any_name
    7375             :               IS security_label
    7376             :                 {
    7377           4 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7378             : 
    7379           4 :                     n->provider = $3;
    7380           4 :                     n->objtype = OBJECT_COLUMN;
    7381           4 :                     n->object = (Node *) $6;
    7382           4 :                     n->label = $8;
    7383           4 :                     $$ = (Node *) n;
    7384             :                 }
    7385             :             | SECURITY LABEL opt_provider ON object_type_name name
    7386             :               IS security_label
    7387             :                 {
    7388          44 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7389             : 
    7390          44 :                     n->provider = $3;
    7391          44 :                     n->objtype = $5;
    7392          44 :                     n->object = (Node *) makeString($6);
    7393          44 :                     n->label = $8;
    7394          44 :                     $$ = (Node *) n;
    7395             :                 }
    7396             :             | SECURITY LABEL opt_provider ON TYPE_P Typename
    7397             :               IS security_label
    7398             :                 {
    7399           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7400             : 
    7401           0 :                     n->provider = $3;
    7402           0 :                     n->objtype = OBJECT_TYPE;
    7403           0 :                     n->object = (Node *) $6;
    7404           0 :                     n->label = $8;
    7405           0 :                     $$ = (Node *) n;
    7406             :                 }
    7407             :             | SECURITY LABEL opt_provider ON DOMAIN_P Typename
    7408             :               IS security_label
    7409             :                 {
    7410           2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7411             : 
    7412           2 :                     n->provider = $3;
    7413           2 :                     n->objtype = OBJECT_DOMAIN;
    7414           2 :                     n->object = (Node *) $6;
    7415           2 :                     n->label = $8;
    7416           2 :                     $$ = (Node *) n;
    7417             :                 }
    7418             :             | SECURITY LABEL opt_provider ON AGGREGATE aggregate_with_argtypes
    7419             :               IS security_label
    7420             :                 {
    7421           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7422             : 
    7423           0 :                     n->provider = $3;
    7424           0 :                     n->objtype = OBJECT_AGGREGATE;
    7425           0 :                     n->object = (Node *) $6;
    7426           0 :                     n->label = $8;
    7427           0 :                     $$ = (Node *) n;
    7428             :                 }
    7429             :             | SECURITY LABEL opt_provider ON FUNCTION function_with_argtypes
    7430             :               IS security_label
    7431             :                 {
    7432           2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7433             : 
    7434           2 :                     n->provider = $3;
    7435           2 :                     n->objtype = OBJECT_FUNCTION;
    7436           2 :                     n->object = (Node *) $6;
    7437           2 :                     n->label = $8;
    7438           2 :                     $$ = (Node *) n;
    7439             :                 }
    7440             :             | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
    7441             :               IS security_label
    7442             :                 {
    7443           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7444             : 
    7445           0 :                     n->provider = $3;
    7446           0 :                     n->objtype = OBJECT_LARGEOBJECT;
    7447           0 :                     n->object = (Node *) $7;
    7448           0 :                     n->label = $9;
    7449           0 :                     $$ = (Node *) n;
    7450             :                 }
    7451             :             | SECURITY LABEL opt_provider ON PROCEDURE function_with_argtypes
    7452             :               IS security_label
    7453             :                 {
    7454           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7455             : 
    7456           0 :                     n->provider = $3;
    7457           0 :                     n->objtype = OBJECT_PROCEDURE;
    7458           0 :                     n->object = (Node *) $6;
    7459           0 :                     n->label = $8;
    7460           0 :                     $$ = (Node *) n;
    7461             :                 }
    7462             :             | SECURITY LABEL opt_provider ON ROUTINE function_with_argtypes
    7463             :               IS security_label
    7464             :                 {
    7465           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7466             : 
    7467           0 :                     n->provider = $3;
    7468           0 :                     n->objtype = OBJECT_ROUTINE;
    7469           0 :                     n->object = (Node *) $6;
    7470           0 :                     n->label = $8;
    7471           0 :                     $$ = (Node *) n;
    7472             :                 }
    7473             :         ;
    7474             : 
    7475          20 : opt_provider:   FOR NonReservedWord_or_Sconst   { $$ = $2; }
    7476          80 :                 | /* EMPTY */                   { $$ = NULL; }
    7477             :         ;
    7478             : 
    7479         100 : security_label: Sconst              { $$ = $1; }
    7480           0 :                 | NULL_P            { $$ = NULL; }
    7481             :         ;
    7482             : 
    7483             : /*****************************************************************************
    7484             :  *
    7485             :  *      QUERY:
    7486             :  *          fetch/move
    7487             :  *
    7488             :  *****************************************************************************/
    7489             : 
    7490             : FetchStmt:  FETCH fetch_args
    7491             :                 {
    7492        7518 :                     FetchStmt *n = (FetchStmt *) $2;
    7493             : 
    7494        7518 :                     n->ismove = false;
    7495        7518 :                     $$ = (Node *) n;
    7496             :                 }
    7497             :             | MOVE fetch_args
    7498             :                 {
    7499          68 :                     FetchStmt *n = (FetchStmt *) $2;
    7500             : 
    7501          68 :                     n->ismove = true;
    7502          68 :                     $$ = (Node *) n;
    7503             :                 }
    7504             :         ;
    7505             : 
    7506             : fetch_args: cursor_name
    7507             :                 {
    7508         272 :                     FetchStmt *n = makeNode(FetchStmt);
    7509             : 
    7510         272 :                     n->portalname = $1;
    7511         272 :                     n->direction = FETCH_FORWARD;
    7512         272 :                     n->howMany = 1;
    7513         272 :                     n->location = -1;
    7514         272 :                     n->direction_keyword = FETCH_KEYWORD_NONE;
    7515         272 :                     $$ = (Node *) n;
    7516             :                 }
    7517             :             | from_in cursor_name
    7518             :                 {
    7519         218 :                     FetchStmt *n = makeNode(FetchStmt);
    7520             : 
    7521         218 :                     n->portalname = $2;
    7522         218 :                     n->direction = FETCH_FORWARD;
    7523         218 :                     n->howMany = 1;
    7524         218 :                     n->location = -1;
    7525         218 :                     n->direction_keyword = FETCH_KEYWORD_NONE;
    7526         218 :                     $$ = (Node *) n;
    7527             :                 }
    7528             :             | SignedIconst opt_from_in cursor_name
    7529             :                 {
    7530        4152 :                     FetchStmt *n = makeNode(FetchStmt);
    7531             : 
    7532        4152 :                     n->portalname = $3;
    7533        4152 :                     n->direction = FETCH_FORWARD;
    7534        4152 :                     n->howMany = $1;
    7535        4152 :                     n->location = @1;
    7536        4152 :                     n->direction_keyword = FETCH_KEYWORD_NONE;
    7537        4152 :                     $$ = (Node *) n;
    7538             :                 }
    7539             :             | NEXT opt_from_in cursor_name
    7540             :                 {
    7541        2010 :                     FetchStmt *n = makeNode(FetchStmt);
    7542             : 
    7543        2010 :                     n->portalname = $3;
    7544        2010 :                     n->direction = FETCH_FORWARD;
    7545        2010 :                     n->howMany = 1;
    7546        2010 :                     n->location = -1;
    7547        2010 :                     n->direction_keyword = FETCH_KEYWORD_NEXT;
    7548        2010 :                     $$ = (Node *) n;
    7549             :                 }
    7550             :             | PRIOR opt_from_in cursor_name
    7551             :                 {
    7552          32 :                     FetchStmt *n = makeNode(FetchStmt);
    7553             : 
    7554          32 :                     n->portalname = $3;
    7555          32 :                     n->direction = FETCH_BACKWARD;
    7556          32 :                     n->howMany = 1;
    7557          32 :                     n->location = -1;
    7558          32 :                     n->direction_keyword = FETCH_KEYWORD_PRIOR;
    7559          32 :                     $$ = (Node *) n;
    7560             :                 }
    7561             :             | FIRST_P opt_from_in cursor_name
    7562             :                 {
    7563          26 :                     FetchStmt *n = makeNode(FetchStmt);
    7564             : 
    7565          26 :                     n->portalname = $3;
    7566          26 :                     n->direction = FETCH_ABSOLUTE;
    7567          26 :                     n->howMany = 1;
    7568          26 :                     n->location = -1;
    7569          26 :                     n->direction_keyword = FETCH_KEYWORD_FIRST;
    7570          26 :                     $$ = (Node *) n;
    7571             :                 }
    7572             :             | LAST_P opt_from_in cursor_name
    7573             :                 {
    7574          20 :                     FetchStmt *n = makeNode(FetchStmt);
    7575             : 
    7576          20 :                     n->portalname = $3;
    7577          20 :                     n->direction = FETCH_ABSOLUTE;
    7578          20 :                     n->howMany = -1;
    7579          20 :                     n->location = -1;
    7580          20 :                     n->direction_keyword = FETCH_KEYWORD_LAST;
    7581          20 :                     $$ = (Node *) n;
    7582             :                 }
    7583             :             | ABSOLUTE_P SignedIconst opt_from_in cursor_name
    7584             :                 {
    7585          94 :                     FetchStmt *n = makeNode(FetchStmt);
    7586             : 
    7587          94 :                     n->portalname = $4;
    7588          94 :                     n->direction = FETCH_ABSOLUTE;
    7589          94 :                     n->howMany = $2;
    7590          94 :                     n->location = @2;
    7591          94 :                     n->direction_keyword = FETCH_KEYWORD_ABSOLUTE;
    7592          94 :                     $$ = (Node *) n;
    7593             :                 }
    7594             :             | RELATIVE_P SignedIconst opt_from_in cursor_name
    7595             :                 {
    7596          36 :                     FetchStmt *n = makeNode(FetchStmt);
    7597             : 
    7598          36 :                     n->portalname = $4;
    7599          36 :                     n->direction = FETCH_RELATIVE;
    7600          36 :                     n->howMany = $2;
    7601          36 :                     n->location = @2;
    7602          36 :                     n->direction_keyword = FETCH_KEYWORD_RELATIVE;
    7603          36 :                     $$ = (Node *) n;
    7604             :                 }
    7605             :             | ALL opt_from_in cursor_name
    7606             :                 {
    7607         270 :                     FetchStmt *n = makeNode(FetchStmt);
    7608             : 
    7609         270 :                     n->portalname = $3;
    7610         270 :                     n->direction = FETCH_FORWARD;
    7611         270 :                     n->howMany = FETCH_ALL;
    7612         270 :                     n->location = -1;
    7613         270 :                     n->direction_keyword = FETCH_KEYWORD_ALL;
    7614         270 :                     $$ = (Node *) n;
    7615             :                 }
    7616             :             | FORWARD opt_from_in cursor_name
    7617             :                 {
    7618          30 :                     FetchStmt *n = makeNode(FetchStmt);
    7619             : 
    7620          30 :                     n->portalname = $3;
    7621          30 :                     n->direction = FETCH_FORWARD;
    7622          30 :                     n->howMany = 1;
    7623          30 :                     n->location = -1;
    7624          30 :                     n->direction_keyword = FETCH_KEYWORD_FORWARD;
    7625          30 :                     $$ = (Node *) n;
    7626             :                 }
    7627             :             | FORWARD SignedIconst opt_from_in cursor_name
    7628             :                 {
    7629          12 :                     FetchStmt *n = makeNode(FetchStmt);
    7630             : 
    7631          12 :                     n->portalname = $4;
    7632          12 :                     n->direction = FETCH_FORWARD;
    7633          12 :                     n->howMany = $2;
    7634          12 :                     n->location = @2;
    7635          12 :                     n->direction_keyword = FETCH_KEYWORD_FORWARD;
    7636          12 :                     $$ = (Node *) n;
    7637             :                 }
    7638             :             | FORWARD ALL opt_from_in cursor_name
    7639             :                 {
    7640          16 :                     FetchStmt *n = makeNode(FetchStmt);
    7641             : 
    7642          16 :                     n->portalname = $4;
    7643          16 :                     n->direction = FETCH_FORWARD;
    7644          16 :                     n->howMany = FETCH_ALL;
    7645          16 :                     n->location = -1;
    7646          16 :                     n->direction_keyword = FETCH_KEYWORD_FORWARD_ALL;
    7647          16 :                     $$ = (Node *) n;
    7648             :                 }
    7649             :             | BACKWARD opt_from_in cursor_name
    7650             :                 {
    7651          80 :                     FetchStmt *n = makeNode(FetchStmt);
    7652             : 
    7653          80 :                     n->portalname = $3;
    7654          80 :                     n->direction = FETCH_BACKWARD;
    7655          80 :                     n->howMany = 1;
    7656          80 :                     n->location = -1;
    7657          80 :                     n->direction_keyword = FETCH_KEYWORD_BACKWARD;
    7658          80 :                     $$ = (Node *) n;
    7659             :                 }
    7660             :             | BACKWARD SignedIconst opt_from_in cursor_name
    7661             :                 {
    7662         226 :                     FetchStmt *n = makeNode(FetchStmt);
    7663             : 
    7664         226 :                     n->portalname = $4;
    7665         226 :                     n->direction = FETCH_BACKWARD;
    7666         226 :                     n->howMany = $2;
    7667         226 :                     n->location = @2;
    7668         226 :                     n->direction_keyword = FETCH_KEYWORD_BACKWARD;
    7669         226 :                     $$ = (Node *) n;
    7670             :                 }
    7671             :             | BACKWARD ALL opt_from_in cursor_name
    7672             :                 {
    7673          92 :                     FetchStmt *n = makeNode(FetchStmt);
    7674             : 
    7675          92 :                     n->portalname = $4;
    7676          92 :                     n->direction = FETCH_BACKWARD;
    7677          92 :                     n->howMany = FETCH_ALL;
    7678          92 :                     n->location = -1;
    7679          92 :                     n->direction_keyword = FETCH_KEYWORD_BACKWARD_ALL;
    7680          92 :                     $$ = (Node *) n;
    7681             :                 }
    7682             :         ;
    7683             : 
    7684             : from_in:    FROM
    7685             :             | IN_P
    7686             :         ;
    7687             : 
    7688             : opt_from_in:    from_in
    7689             :             | /* EMPTY */
    7690             :         ;
    7691             : 
    7692             : 
    7693             : /*****************************************************************************
    7694             :  *
    7695             :  * GRANT and REVOKE statements
    7696             :  *
    7697             :  *****************************************************************************/
    7698             : 
    7699             : GrantStmt:  GRANT privileges ON privilege_target TO grantee_list
    7700             :             opt_grant_grant_option opt_granted_by
    7701             :                 {
    7702       11810 :                     GrantStmt *n = makeNode(GrantStmt);
    7703             : 
    7704       11810 :                     n->is_grant = true;
    7705       11810 :                     n->privileges = $2;
    7706       11810 :                     n->targtype = ($4)->targtype;
    7707       11810 :                     n->objtype = ($4)->objtype;
    7708       11810 :                     n->objects = ($4)->objs;
    7709       11810 :                     n->grantees = $6;
    7710       11810 :                     n->grant_option = $7;
    7711       11810 :                     n->grantor = $8;
    7712       11810 :                     $$ = (Node *) n;
    7713             :                 }
    7714             :         ;
    7715             : 
    7716             : RevokeStmt:
    7717             :             REVOKE privileges ON privilege_target
    7718             :             FROM grantee_list opt_granted_by opt_drop_behavior
    7719             :                 {
    7720       10470 :                     GrantStmt *n = makeNode(GrantStmt);
    7721             : 
    7722       10470 :                     n->is_grant = false;
    7723       10470 :                     n->grant_option = false;
    7724       10470 :                     n->privileges = $2;
    7725       10470 :                     n->targtype = ($4)->targtype;
    7726       10470 :                     n->objtype = ($4)->objtype;
    7727       10470 :                     n->objects = ($4)->objs;
    7728       10470 :                     n->grantees = $6;
    7729       10470 :                     n->grantor = $7;
    7730       10470 :                     n->behavior = $8;
    7731       10470 :                     $$ = (Node *) n;
    7732             :                 }
    7733             :             | REVOKE GRANT OPTION FOR privileges ON privilege_target
    7734             :             FROM grantee_list opt_granted_by opt_drop_behavior
    7735             :                 {
    7736          16 :                     GrantStmt *n = makeNode(GrantStmt);
    7737             : 
    7738          16 :                     n->is_grant = false;
    7739          16 :                     n->grant_option = true;
    7740          16 :                     n->privileges = $5;
    7741          16 :                     n->targtype = ($7)->targtype;
    7742          16 :                     n->objtype = ($7)->objtype;
    7743          16 :                     n->objects = ($7)->objs;
    7744          16 :                     n->grantees = $9;
    7745          16 :                     n->grantor = $10;
    7746          16 :                     n->behavior = $11;
    7747          16 :                     $$ = (Node *) n;
    7748             :                 }
    7749             :         ;
    7750             : 
    7751             : 
    7752             : /*
    7753             :  * Privilege names are represented as strings; the validity of the privilege
    7754             :  * names gets checked at execution.  This is a bit annoying but we have little
    7755             :  * choice because of the syntactic conflict with lists of role names in
    7756             :  * GRANT/REVOKE.  What's more, we have to call out in the "privilege"
    7757             :  * production any reserved keywords that need to be usable as privilege names.
    7758             :  */
    7759             : 
    7760             : /* either ALL [PRIVILEGES] or a list of individual privileges */
    7761             : privileges: privilege_list
    7762       19630 :                 { $$ = $1; }
    7763             :             | ALL
    7764        2728 :                 { $$ = NIL; }
    7765             :             | ALL PRIVILEGES
    7766         122 :                 { $$ = NIL; }
    7767             :             | ALL '(' columnList ')'
    7768             :                 {
    7769          18 :                     AccessPriv *n = makeNode(AccessPriv);
    7770             : 
    7771          18 :                     n->priv_name = NULL;
    7772          18 :                     n->cols = $3;
    7773          18 :                     $$ = list_make1(n);
    7774             :                 }
    7775             :             | ALL PRIVILEGES '(' columnList ')'
    7776             :                 {
    7777           0 :                     AccessPriv *n = makeNode(AccessPriv);
    7778             : 
    7779           0 :                     n->priv_name = NULL;
    7780           0 :                     n->cols = $4;
    7781           0 :                     $$ = list_make1(n);
    7782             :                 }
    7783             :         ;
    7784             : 
    7785       20560 : privilege_list: privilege                           { $$ = list_make1($1); }
    7786         570 :             | privilege_list ',' privilege          { $$ = lappend($1, $3); }
    7787             :         ;
    7788             : 
    7789             : privilege:  SELECT opt_column_list
    7790             :             {
    7791        9396 :                 AccessPriv *n = makeNode(AccessPriv);
    7792             : 
    7793        9396 :                 n->priv_name = pstrdup($1);
    7794        9396 :                 n->cols = $2;
    7795        9396 :                 $$ = n;
    7796             :             }
    7797             :         | REFERENCES opt_column_list
    7798             :             {
    7799          16 :                 AccessPriv *n = makeNode(AccessPriv);
    7800             : 
    7801          16 :                 n->priv_name = pstrdup($1);
    7802          16 :                 n->cols = $2;
    7803          16 :                 $$ = n;
    7804             :             }
    7805             :         | CREATE opt_column_list
    7806             :             {
    7807         298 :                 AccessPriv *n = makeNode(AccessPriv);
    7808             : 
    7809         298 :                 n->priv_name = pstrdup($1);
    7810         298 :                 n->cols = $2;
    7811         298 :                 $$ = n;
    7812             :             }
    7813             :         | ALTER SYSTEM_P
    7814             :             {
    7815          24 :                 AccessPriv *n = makeNode(AccessPriv);
    7816          24 :                 n->priv_name = pstrdup("alter system");
    7817          24 :                 n->cols = NIL;
    7818          24 :                 $$ = n;
    7819             :             }
    7820             :         | ColId opt_column_list
    7821             :             {
    7822       11396 :                 AccessPriv *n = makeNode(AccessPriv);
    7823             : 
    7824       11396 :                 n->priv_name = $1;
    7825       11396 :                 n->cols = $2;
    7826       11396 :                 $$ = n;
    7827             :             }
    7828             :         ;
    7829             : 
    7830             : parameter_name_list:
    7831             :         parameter_name
    7832             :             {
    7833          76 :                 $$ = list_make1(makeString($1));
    7834             :             }
    7835             :         | parameter_name_list ',' parameter_name
    7836             :             {
    7837          50 :                 $$ = lappend($1, makeString($3));
    7838             :             }
    7839             :         ;
    7840             : 
    7841             : parameter_name:
    7842             :         ColId
    7843             :             {
    7844         126 :                 $$ = $1;
    7845             :             }
    7846             :         | parameter_name '.' ColId
    7847             :             {
    7848          32 :                 $$ = psprintf("%s.%s", $1, $3);
    7849             :             }
    7850             :         ;
    7851             : 
    7852             : 
    7853             : /* Don't bother trying to fold the first two rules into one using
    7854             :  * opt_table.  You're going to get conflicts.
    7855             :  */
    7856             : privilege_target:
    7857             :             qualified_name_list
    7858             :                 {
    7859       11442 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7860             : 
    7861       11442 :                     n->targtype = ACL_TARGET_OBJECT;
    7862       11442 :                     n->objtype = OBJECT_TABLE;
    7863       11442 :                     n->objs = $1;
    7864       11442 :                     $$ = n;
    7865             :                 }
    7866             :             | TABLE qualified_name_list
    7867             :                 {
    7868         420 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7869             : 
    7870         420 :                     n->targtype = ACL_TARGET_OBJECT;
    7871         420 :                     n->objtype = OBJECT_TABLE;
    7872         420 :                     n->objs = $2;
    7873         420 :                     $$ = n;
    7874             :                 }
    7875             :             | SEQUENCE qualified_name_list
    7876             :                 {
    7877          24 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7878             : 
    7879          24 :                     n->targtype = ACL_TARGET_OBJECT;
    7880          24 :                     n->objtype = OBJECT_SEQUENCE;
    7881          24 :                     n->objs = $2;
    7882          24 :                     $$ = n;
    7883             :                 }
    7884             :             | FOREIGN DATA_P WRAPPER name_list
    7885             :                 {
    7886          92 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7887             : 
    7888          92 :                     n->targtype = ACL_TARGET_OBJECT;
    7889          92 :                     n->objtype = OBJECT_FDW;
    7890          92 :                     n->objs = $4;
    7891          92 :                     $$ = n;
    7892             :                 }
    7893             :             | FOREIGN SERVER name_list
    7894             :                 {
    7895          88 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7896             : 
    7897          88 :                     n->targtype = ACL_TARGET_OBJECT;
    7898          88 :                     n->objtype = OBJECT_FOREIGN_SERVER;
    7899          88 :                     n->objs = $3;
    7900          88 :                     $$ = n;
    7901             :                 }
    7902             :             | FUNCTION function_with_argtypes_list
    7903             :                 {
    7904        9100 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7905             : 
    7906        9100 :                     n->targtype = ACL_TARGET_OBJECT;
    7907        9100 :                     n->objtype = OBJECT_FUNCTION;
    7908        9100 :                     n->objs = $2;
    7909        9100 :                     $$ = n;
    7910             :                 }
    7911             :             | PROCEDURE function_with_argtypes_list
    7912             :                 {
    7913          42 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7914             : 
    7915          42 :                     n->targtype = ACL_TARGET_OBJECT;
    7916          42 :                     n->objtype = OBJECT_PROCEDURE;
    7917          42 :                     n->objs = $2;
    7918          42 :                     $$ = n;
    7919             :                 }
    7920             :             | ROUTINE function_with_argtypes_list
    7921             :                 {
    7922           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7923             : 
    7924           0 :                     n->targtype = ACL_TARGET_OBJECT;
    7925           0 :                     n->objtype = OBJECT_ROUTINE;
    7926           0 :                     n->objs = $2;
    7927           0 :                     $$ = n;
    7928             :                 }
    7929             :             | DATABASE name_list
    7930             :                 {
    7931         352 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7932             : 
    7933         352 :                     n->targtype = ACL_TARGET_OBJECT;
    7934         352 :                     n->objtype = OBJECT_DATABASE;
    7935         352 :                     n->objs = $2;
    7936         352 :                     $$ = n;
    7937             :                 }
    7938             :             | DOMAIN_P any_name_list
    7939             :                 {
    7940          26 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7941             : 
    7942          26 :                     n->targtype = ACL_TARGET_OBJECT;
    7943          26 :                     n->objtype = OBJECT_DOMAIN;
    7944          26 :                     n->objs = $2;
    7945          26 :                     $$ = n;
    7946             :                 }
    7947             :             | LANGUAGE name_list
    7948             :                 {
    7949          42 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7950             : 
    7951          42 :                     n->targtype = ACL_TARGET_OBJECT;
    7952          42 :                     n->objtype = OBJECT_LANGUAGE;
    7953          42 :                     n->objs = $2;
    7954          42 :                     $$ = n;
    7955             :                 }
    7956             :             | LARGE_P OBJECT_P NumericOnly_list
    7957             :                 {
    7958          80 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7959             : 
    7960          80 :                     n->targtype = ACL_TARGET_OBJECT;
    7961          80 :                     n->objtype = OBJECT_LARGEOBJECT;
    7962          80 :                     n->objs = $3;
    7963          80 :                     $$ = n;
    7964             :                 }
    7965             :             | PARAMETER parameter_name_list
    7966             :                 {
    7967          76 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7968          76 :                     n->targtype = ACL_TARGET_OBJECT;
    7969          76 :                     n->objtype = OBJECT_PARAMETER_ACL;
    7970          76 :                     n->objs = $2;
    7971          76 :                     $$ = n;
    7972             :                 }
    7973             :             | SCHEMA name_list
    7974             :                 {
    7975         376 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7976             : 
    7977         376 :                     n->targtype = ACL_TARGET_OBJECT;
    7978         376 :                     n->objtype = OBJECT_SCHEMA;
    7979         376 :                     n->objs = $2;
    7980         376 :                     $$ = n;
    7981             :                 }
    7982             :             | TABLESPACE name_list
    7983             :                 {
    7984           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7985             : 
    7986           6 :                     n->targtype = ACL_TARGET_OBJECT;
    7987           6 :                     n->objtype = OBJECT_TABLESPACE;
    7988           6 :                     n->objs = $2;
    7989           6 :                     $$ = n;
    7990             :                 }
    7991             :             | TYPE_P any_name_list
    7992             :                 {
    7993         112 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7994             : 
    7995         112 :                     n->targtype = ACL_TARGET_OBJECT;
    7996         112 :                     n->objtype = OBJECT_TYPE;
    7997         112 :                     n->objs = $2;
    7998         112 :                     $$ = n;
    7999             :                 }
    8000             :             | ALL TABLES IN_P SCHEMA name_list
    8001             :                 {
    8002          12 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    8003             : 
    8004          12 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8005          12 :                     n->objtype = OBJECT_TABLE;
    8006          12 :                     n->objs = $5;
    8007          12 :                     $$ = n;
    8008             :                 }
    8009             :             | ALL SEQUENCES IN_P SCHEMA name_list
    8010             :                 {
    8011           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    8012             : 
    8013           0 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8014           0 :                     n->objtype = OBJECT_SEQUENCE;
    8015           0 :                     n->objs = $5;
    8016           0 :                     $$ = n;
    8017             :                 }
    8018             :             | ALL FUNCTIONS IN_P SCHEMA name_list
    8019             :                 {
    8020           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    8021             : 
    8022           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8023           6 :                     n->objtype = OBJECT_FUNCTION;
    8024           6 :                     n->objs = $5;
    8025           6 :                     $$ = n;
    8026             :                 }
    8027             :             | ALL PROCEDURES IN_P SCHEMA name_list
    8028             :                 {
    8029           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    8030             : 
    8031           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8032           6 :                     n->objtype = OBJECT_PROCEDURE;
    8033           6 :                     n->objs = $5;
    8034           6 :                     $$ = n;
    8035             :                 }
    8036             :             | ALL ROUTINES IN_P SCHEMA name_list
    8037             :                 {
    8038           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    8039             : 
    8040           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8041           6 :                     n->objtype = OBJECT_ROUTINE;
    8042           6 :                     n->objs = $5;
    8043           6 :                     $$ = n;
    8044             :                 }
    8045             :         ;
    8046             : 
    8047             : 
    8048             : grantee_list:
    8049       22486 :             grantee                                 { $$ = list_make1($1); }
    8050         108 :             | grantee_list ',' grantee              { $$ = lappend($1, $3); }
    8051             :         ;
    8052             : 
    8053             : grantee:
    8054       22570 :             RoleSpec                                { $$ = $1; }
    8055          24 :             | GROUP_P RoleSpec                      { $$ = $2; }
    8056             :         ;
    8057             : 
    8058             : 
    8059             : opt_grant_grant_option:
    8060         102 :             WITH GRANT OPTION { $$ = true; }
    8061       11832 :             | /*EMPTY*/ { $$ = false; }
    8062             :         ;
    8063             : 
    8064             : /*****************************************************************************
    8065             :  *
    8066             :  * GRANT and REVOKE ROLE statements
    8067             :  *
    8068             :  *****************************************************************************/
    8069             : 
    8070             : GrantRoleStmt:
    8071             :             GRANT privilege_list TO role_list opt_granted_by
    8072             :                 {
    8073         596 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8074             : 
    8075         596 :                     n->is_grant = true;
    8076         596 :                     n->granted_roles = $2;
    8077         596 :                     n->grantee_roles = $4;
    8078         596 :                     n->opt = NIL;
    8079         596 :                     n->grantor = $5;
    8080         596 :                     $$ = (Node *) n;
    8081             :                 }
    8082             :           | GRANT privilege_list TO role_list WITH grant_role_opt_list opt_granted_by
    8083             :                 {
    8084         178 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8085             : 
    8086         178 :                     n->is_grant = true;
    8087         178 :                     n->granted_roles = $2;
    8088         178 :                     n->grantee_roles = $4;
    8089         178 :                     n->opt = $6;
    8090         178 :                     n->grantor = $7;
    8091         178 :                     $$ = (Node *) n;
    8092             :                 }
    8093             :         ;
    8094             : 
    8095             : RevokeRoleStmt:
    8096             :             REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
    8097             :                 {
    8098          90 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8099             : 
    8100          90 :                     n->is_grant = false;
    8101          90 :                     n->opt = NIL;
    8102          90 :                     n->granted_roles = $2;
    8103          90 :                     n->grantee_roles = $4;
    8104          90 :                     n->grantor = $5;
    8105          90 :                     n->behavior = $6;
    8106          90 :                     $$ = (Node *) n;
    8107             :                 }
    8108             :             | REVOKE ColId OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
    8109             :                 {
    8110          66 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8111             :                     DefElem *opt;
    8112             : 
    8113          66 :                     opt = makeDefElem(pstrdup($2),
    8114          66 :                                       (Node *) makeBoolean(false), @2);
    8115          66 :                     n->is_grant = false;
    8116          66 :                     n->opt = list_make1(opt);
    8117          66 :                     n->granted_roles = $5;
    8118          66 :                     n->grantee_roles = $7;
    8119          66 :                     n->grantor = $8;
    8120          66 :                     n->behavior = $9;
    8121          66 :                     $$ = (Node *) n;
    8122             :                 }
    8123             :         ;
    8124             : 
    8125             : grant_role_opt_list:
    8126         120 :             grant_role_opt_list ',' grant_role_opt  { $$ = lappend($1, $3); }
    8127         178 :             | grant_role_opt                        { $$ = list_make1($1); }
    8128             :         ;
    8129             : 
    8130             : grant_role_opt:
    8131             :         ColLabel grant_role_opt_value
    8132             :             {
    8133         298 :                 $$ = makeDefElem(pstrdup($1), $2, @1);
    8134             :             }
    8135             :         ;
    8136             : 
    8137             : grant_role_opt_value:
    8138          72 :         OPTION          { $$ = (Node *) makeBoolean(true); }
    8139         112 :         | TRUE_P        { $$ = (Node *) makeBoolean(true); }
    8140         114 :         | FALSE_P       { $$ = (Node *) makeBoolean(false); }
    8141             :         ;
    8142             : 
    8143         138 : opt_granted_by: GRANTED BY RoleSpec                     { $$ = $3; }
    8144       23088 :             | /*EMPTY*/                                 { $$ = NULL; }
    8145             :         ;
    8146             : 
    8147             : /*****************************************************************************
    8148             :  *
    8149             :  * ALTER DEFAULT PRIVILEGES statement
    8150             :  *
    8151             :  *****************************************************************************/
    8152             : 
    8153             : AlterDefaultPrivilegesStmt:
    8154             :             ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
    8155             :                 {
    8156         190 :                     AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
    8157             : 
    8158         190 :                     n->options = $4;
    8159         190 :                     n->action = (GrantStmt *) $5;
    8160         190 :                     $$ = (Node *) n;
    8161             :                 }
    8162             :         ;
    8163             : 
    8164             : DefACLOptionList:
    8165         128 :             DefACLOptionList DefACLOption           { $$ = lappend($1, $2); }
    8166         190 :             | /* EMPTY */                           { $$ = NIL; }
    8167             :         ;
    8168             : 
    8169             : DefACLOption:
    8170             :             IN_P SCHEMA name_list
    8171             :                 {
    8172          60 :                     $$ = makeDefElem("schemas", (Node *) $3, @1);
    8173             :                 }
    8174             :             | FOR ROLE role_list
    8175             :                 {
    8176          68 :                     $$ = makeDefElem("roles", (Node *) $3, @1);
    8177             :                 }
    8178             :             | FOR USER role_list
    8179             :                 {
    8180           0 :                     $$ = makeDefElem("roles", (Node *) $3, @1);
    8181             :                 }
    8182             :         ;
    8183             : 
    8184             : /*
    8185             :  * This should match GRANT/REVOKE, except that individual target objects
    8186             :  * are not mentioned and we only allow a subset of object types.
    8187             :  */
    8188             : DefACLAction:
    8189             :             GRANT privileges ON defacl_privilege_target TO grantee_list
    8190             :             opt_grant_grant_option
    8191             :                 {
    8192         124 :                     GrantStmt *n = makeNode(GrantStmt);
    8193             : 
    8194         124 :                     n->is_grant = true;
    8195         124 :                     n->privileges = $2;
    8196         124 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8197         124 :                     n->objtype = $4;
    8198         124 :                     n->objects = NIL;
    8199         124 :                     n->grantees = $6;
    8200         124 :                     n->grant_option = $7;
    8201         124 :                     $$ = (Node *) n;
    8202             :                 }
    8203             :             | REVOKE privileges ON defacl_privilege_target
    8204             :             FROM grantee_list opt_drop_behavior
    8205             :                 {
    8206          66 :                     GrantStmt *n = makeNode(GrantStmt);
    8207             : 
    8208          66 :                     n->is_grant = false;
    8209          66 :                     n->grant_option = false;
    8210          66 :                     n->privileges = $2;
    8211          66 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8212          66 :                     n->objtype = $4;
    8213          66 :                     n->objects = NIL;
    8214          66 :                     n->grantees = $6;
    8215          66 :                     n->behavior = $7;
    8216          66 :                     $$ = (Node *) n;
    8217             :                 }
    8218             :             | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
    8219             :             FROM grantee_list opt_drop_behavior
    8220             :                 {
    8221           0 :                     GrantStmt *n = makeNode(GrantStmt);
    8222             : 
    8223           0 :                     n->is_grant = false;
    8224           0 :                     n->grant_option = true;
    8225           0 :                     n->privileges = $5;
    8226           0 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8227           0 :                     n->objtype = $7;
    8228           0 :                     n->objects = NIL;
    8229           0 :                     n->grantees = $9;
    8230           0 :                     n->behavior = $10;
    8231           0 :                     $$ = (Node *) n;
    8232             :                 }
    8233             :         ;
    8234             : 
    8235             : defacl_privilege_target:
    8236          78 :             TABLES          { $$ = OBJECT_TABLE; }
    8237          16 :             | FUNCTIONS     { $$ = OBJECT_FUNCTION; }
    8238           6 :             | ROUTINES      { $$ = OBJECT_FUNCTION; }
    8239           6 :             | SEQUENCES     { $$ = OBJECT_SEQUENCE; }
    8240          18 :             | TYPES_P       { $$ = OBJECT_TYPE; }
    8241          36 :             | SCHEMAS       { $$ = OBJECT_SCHEMA; }
    8242          30 :             | LARGE_P OBJECTS_P { $$ = OBJECT_LARGEOBJECT; }
    8243             :         ;
    8244             : 
    8245             : 
    8246             : /*****************************************************************************
    8247             :  *
    8248             :  *      QUERY: CREATE INDEX
    8249             :  *
    8250             :  * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
    8251             :  * willing to make TABLESPACE a fully reserved word.
    8252             :  *****************************************************************************/
    8253             : 
    8254             : IndexStmt:  CREATE opt_unique INDEX opt_concurrently opt_single_name
    8255             :             ON relation_expr access_method_clause '(' index_params ')'
    8256             :             opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
    8257             :                 {
    8258        7000 :                     IndexStmt *n = makeNode(IndexStmt);
    8259             : 
    8260        7000 :                     n->unique = $2;
    8261        7000 :                     n->concurrent = $4;
    8262        7000 :                     n->idxname = $5;
    8263        7000 :                     n->relation = $7;
    8264        7000 :                     n->accessMethod = $8;
    8265        7000 :                     n->indexParams = $10;
    8266        7000 :                     n->indexIncludingParams = $12;
    8267        7000 :                     n->nulls_not_distinct = !$13;
    8268        7000 :                     n->options = $14;
    8269        7000 :                     n->tableSpace = $15;
    8270        7000 :                     n->whereClause = $16;
    8271        7000 :                     n->excludeOpNames = NIL;
    8272        7000 :                     n->idxcomment = NULL;
    8273        7000 :                     n->indexOid = InvalidOid;
    8274        7000 :                     n->oldNumber = InvalidRelFileNumber;
    8275        7000 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8276        7000 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8277        7000 :                     n->primary = false;
    8278        7000 :                     n->isconstraint = false;
    8279        7000 :                     n->deferrable = false;
    8280        7000 :                     n->initdeferred = false;
    8281        7000 :                     n->transformed = false;
    8282        7000 :                     n->if_not_exists = false;
    8283        7000 :                     n->reset_default_tblspc = false;
    8284        7000 :                     $$ = (Node *) n;
    8285             :                 }
    8286             :             | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS name
    8287             :             ON relation_expr access_method_clause '(' index_params ')'
    8288             :             opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
    8289             :                 {
    8290          18 :                     IndexStmt *n = makeNode(IndexStmt);
    8291             : 
    8292          18 :                     n->unique = $2;
    8293          18 :                     n->concurrent = $4;
    8294          18 :                     n->idxname = $8;
    8295          18 :                     n->relation = $10;
    8296          18 :                     n->accessMethod = $11;
    8297          18 :                     n->indexParams = $13;
    8298          18 :                     n->indexIncludingParams = $15;
    8299          18 :                     n->nulls_not_distinct = !$16;
    8300          18 :                     n->options = $17;
    8301          18 :                     n->tableSpace = $18;
    8302          18 :                     n->whereClause = $19;
    8303          18 :                     n->excludeOpNames = NIL;
    8304          18 :                     n->idxcomment = NULL;
    8305          18 :                     n->indexOid = InvalidOid;
    8306          18 :                     n->oldNumber = InvalidRelFileNumber;
    8307          18 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8308          18 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8309          18 :                     n->primary = false;
    8310          18 :                     n->isconstraint = false;
    8311          18 :                     n->deferrable = false;
    8312          18 :                     n->initdeferred = false;
    8313          18 :                     n->transformed = false;
    8314          18 :                     n->if_not_exists = true;
    8315          18 :                     n->reset_default_tblspc = false;
    8316          18 :                     $$ = (Node *) n;
    8317             :                 }
    8318             :         ;
    8319             : 
    8320             : opt_unique:
    8321        1378 :             UNIQUE                                  { $$ = true; }
    8322        5646 :             | /*EMPTY*/                             { $$ = false; }
    8323             :         ;
    8324             : 
    8325             : access_method_clause:
    8326        3348 :             USING name                              { $$ = $2; }
    8327        3908 :             | /*EMPTY*/                             { $$ = DEFAULT_INDEX_TYPE; }
    8328             :         ;
    8329             : 
    8330        8444 : index_params:   index_elem                          { $$ = list_make1($1); }
    8331        2332 :             | index_params ',' index_elem           { $$ = lappend($1, $3); }
    8332             :         ;
    8333             : 
    8334             : 
    8335             : index_elem_options:
    8336             :     opt_collate opt_qualified_name opt_asc_desc opt_nulls_order
    8337             :         {
    8338       11384 :             $$ = makeNode(IndexElem);
    8339       11384 :             $$->name = NULL;
    8340       11384 :             $$->expr = NULL;
    8341       11384 :             $$->indexcolname = NULL;
    8342       11384 :             $$->collation = $1;
    8343       11384 :             $$->opclass = $2;
    8344       11384 :             $$->opclassopts = NIL;
    8345       11384 :             $$->ordering = $3;
    8346       11384 :             $$->nulls_ordering = $4;
    8347             :         }
    8348             :     | opt_collate any_name reloptions opt_asc_desc opt_nulls_order
    8349             :         {
    8350         142 :             $$ = makeNode(IndexElem);
    8351         142 :             $$->name = NULL;
    8352         142 :             $$->expr = NULL;
    8353         142 :             $$->indexcolname = NULL;
    8354         142 :             $$->collation = $1;
    8355         142 :             $$->opclass = $2;
    8356         142 :             $$->opclassopts = $3;
    8357         142 :             $$->ordering = $4;
    8358         142 :             $$->nulls_ordering = $5;
    8359             :         }
    8360             :     ;
    8361             : 
    8362             : /*
    8363             :  * Index attributes can be either simple column references, or arbitrary
    8364             :  * expressions in parens.  For backwards-compatibility reasons, we allow
    8365             :  * an expression that's just a function call to be written without parens.
    8366             :  */
    8367             : index_elem: ColId index_elem_options
    8368             :                 {
    8369       10372 :                     $$ = $2;
    8370       10372 :                     $$->name = $1;
    8371             :                 }
    8372             :             | func_expr_windowless index_elem_options
    8373             :                 {
    8374         612 :                     $$ = $2;
    8375         612 :                     $$->expr = $1;
    8376             :                 }
    8377             :             | '(' a_expr ')' index_elem_options
    8378             :                 {
    8379         542 :                     $$ = $4;
    8380         542 :                     $$->expr = $2;
    8381             :                 }
    8382             :         ;
    8383             : 
    8384         232 : opt_include:        INCLUDE '(' index_including_params ')'          { $$ = $3; }
    8385        6786 :              |      /* EMPTY */                     { $$ = NIL; }
    8386             :         ;
    8387             : 
    8388         232 : index_including_params: index_elem                      { $$ = list_make1($1); }
    8389         170 :             | index_including_params ',' index_elem     { $$ = lappend($1, $3); }
    8390             :         ;
    8391             : 
    8392         192 : opt_collate: COLLATE any_name                       { $$ = $2; }
    8393       16960 :             | /*EMPTY*/                             { $$ = NIL; }
    8394             :         ;
    8395             : 
    8396             : 
    8397        1822 : opt_asc_desc: ASC                           { $$ = SORTBY_ASC; }
    8398        3552 :             | DESC                          { $$ = SORTBY_DESC; }
    8399      117344 :             | /*EMPTY*/                     { $$ = SORTBY_DEFAULT; }
    8400             :         ;
    8401             : 
    8402         344 : opt_nulls_order: NULLS_LA FIRST_P           { $$ = SORTBY_NULLS_FIRST; }
    8403        1732 :             | NULLS_LA LAST_P               { $$ = SORTBY_NULLS_LAST; }
    8404      120862 :             | /*EMPTY*/                     { $$ = SORTBY_NULLS_DEFAULT; }
    8405             :         ;
    8406             : 
    8407             : 
    8408             : /*****************************************************************************
    8409             :  *
    8410             :  *      QUERY:
    8411             :  *              create [or replace] function <fname>
    8412             :  *                      [(<type-1> { , <type-n>})]
    8413             :  *                      returns <type-r>
    8414             :  *                      as <filename or code in language as appropriate>
    8415             :  *                      language <lang> [with parameters]
    8416             :  *
    8417             :  *****************************************************************************/
    8418             : 
    8419             : CreateFunctionStmt:
    8420             :             CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8421             :             RETURNS func_return opt_createfunc_opt_list opt_routine_body
    8422             :                 {
    8423       23984 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8424             : 
    8425       23984 :                     n->is_procedure = false;
    8426       23984 :                     n->replace = $2;
    8427       23984 :                     n->funcname = $4;
    8428       23984 :                     n->parameters = $5;
    8429       23984 :                     n->returnType = $7;
    8430       23984 :                     n->options = $8;
    8431       23984 :                     n->sql_body = $9;
    8432       23984 :                     $$ = (Node *) n;
    8433             :                 }
    8434             :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8435             :               RETURNS TABLE '(' table_func_column_list ')' opt_createfunc_opt_list opt_routine_body
    8436             :                 {
    8437         202 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8438             : 
    8439         202 :                     n->is_procedure = false;
    8440         202 :                     n->replace = $2;
    8441         202 :                     n->funcname = $4;
    8442         202 :                     n->parameters = mergeTableFuncParameters($5, $9, yyscanner);
    8443         202 :                     n->returnType = TableFuncTypeName($9);
    8444         202 :                     n->returnType->location = @7;
    8445         202 :                     n->options = $11;
    8446         202 :                     n->sql_body = $12;
    8447         202 :                     $$ = (Node *) n;
    8448             :                 }
    8449             :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8450             :               opt_createfunc_opt_list opt_routine_body
    8451             :                 {
    8452         488 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8453             : 
    8454         488 :                     n->is_procedure = false;
    8455         488 :                     n->replace = $2;
    8456         488 :                     n->funcname = $4;
    8457         488 :                     n->parameters = $5;
    8458         488 :                     n->returnType = NULL;
    8459         488 :                     n->options = $6;
    8460         488 :                     n->sql_body = $7;
    8461         488 :                     $$ = (Node *) n;
    8462             :                 }
    8463             :             | CREATE opt_or_replace PROCEDURE func_name func_args_with_defaults
    8464             :               opt_createfunc_opt_list opt_routine_body
    8465             :                 {
    8466         392 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8467             : 
    8468         392 :                     n->is_procedure = true;
    8469         392 :                     n->replace = $2;
    8470         392 :                     n->funcname = $4;
    8471         392 :                     n->parameters = $5;
    8472         392 :                     n->returnType = NULL;
    8473         392 :                     n->options = $6;
    8474         392 :                     n->sql_body = $7;
    8475         392 :                     $$ = (Node *) n;
    8476             :                 }
    8477             :         ;
    8478             : 
    8479             : opt_or_replace:
    8480       10150 :             OR REPLACE                              { $$ = true; }
    8481       20646 :             | /*EMPTY*/                             { $$ = false; }
    8482             :         ;
    8483             : 
    8484       10416 : func_args:  '(' func_args_list ')'                  { $$ = $2; }
    8485        6166 :             | '(' ')'                               { $$ = NIL; }
    8486             :         ;
    8487             : 
    8488             : func_args_list:
    8489       10416 :             func_arg                                { $$ = list_make1($1); }
    8490        8386 :             | func_args_list ',' func_arg           { $$ = lappend($1, $3); }
    8491             :         ;
    8492             : 
    8493             : function_with_argtypes_list:
    8494       12826 :             function_with_argtypes                  { $$ = list_make1($1); }
    8495             :             | function_with_argtypes_list ',' function_with_argtypes
    8496          84 :                                                     { $$ = lappend($1, $3); }
    8497             :         ;
    8498             : 
    8499             : function_with_argtypes:
    8500             :             func_name func_args
    8501             :                 {
    8502       16582 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8503             : 
    8504       16582 :                     n->objname = $1;
    8505       16582 :                     n->objargs = extractArgTypes($2);
    8506       16582 :                     n->objfuncargs = $2;
    8507       16582 :                     $$ = n;
    8508             :                 }
    8509             :             /*
    8510             :              * Because of reduce/reduce conflicts, we can't use func_name
    8511             :              * below, but we can write it out the long way, which actually
    8512             :              * allows more cases.
    8513             :              */
    8514             :             | type_func_name_keyword
    8515             :                 {
    8516           0 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8517             : 
    8518           0 :                     n->objname = list_make1(makeString(pstrdup($1)));
    8519           0 :                     n->args_unspecified = true;
    8520           0 :                     $$ = n;
    8521             :                 }
    8522             :             | ColId
    8523             :                 {
    8524         352 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8525             : 
    8526         352 :                     n->objname = list_make1(makeString($1));
    8527         352 :                     n->args_unspecified = true;
    8528         352 :                     $$ = n;
    8529             :                 }
    8530             :             | ColId indirection
    8531             :                 {
    8532          28 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8533             : 
    8534          28 :                     n->objname = check_func_name(lcons(makeString($1), $2),
    8535             :                                                   yyscanner);
    8536          28 :                     n->args_unspecified = true;
    8537          28 :                     $$ = n;
    8538             :                 }
    8539             :         ;
    8540             : 
    8541             : /*
    8542             :  * func_args_with_defaults is separate because we only want to accept
    8543             :  * defaults in CREATE FUNCTION, not in ALTER etc.
    8544             :  */
    8545             : func_args_with_defaults:
    8546       20354 :         '(' func_args_with_defaults_list ')'        { $$ = $2; }
    8547        4712 :         | '(' ')'                                   { $$ = NIL; }
    8548             :         ;
    8549             : 
    8550             : func_args_with_defaults_list:
    8551       20354 :         func_arg_with_default                       { $$ = list_make1($1); }
    8552             :         | func_args_with_defaults_list ',' func_arg_with_default
    8553       34072 :                                                     { $$ = lappend($1, $3); }
    8554             :         ;
    8555             : 
    8556             : /*
    8557             :  * The style with arg_class first is SQL99 standard, but Oracle puts
    8558             :  * param_name first; accept both since it's likely people will try both
    8559             :  * anyway.  Don't bother trying to save productions by letting arg_class
    8560             :  * have an empty alternative ... you'll get shift/reduce conflicts.
    8561             :  *
    8562             :  * We can catch over-specified arguments here if we want to,
    8563             :  * but for now better to silently swallow typmod, etc.
    8564             :  * - thomas 2000-03-22
    8565             :  */
    8566             : func_arg:
    8567             :             arg_class param_name func_type
    8568             :                 {
    8569       16600 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8570             : 
    8571       16600 :                     n->name = $2;
    8572       16600 :                     n->argType = $3;
    8573       16600 :                     n->mode = $1;
    8574       16600 :                     n->defexpr = NULL;
    8575       16600 :                     n->location = @1;
    8576       16600 :                     $$ = n;
    8577             :                 }
    8578             :             | param_name arg_class func_type
    8579             :                 {
    8580         420 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8581             : 
    8582         420 :                     n->name = $1;
    8583         420 :                     n->argType = $3;
    8584         420 :                     n->mode = $2;
    8585         420 :                     n->defexpr = NULL;
    8586         420 :                     n->location = @1;
    8587         420 :                     $$ = n;
    8588             :                 }
    8589             :             | param_name func_type
    8590             :                 {
    8591       16120 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8592             : 
    8593       16120 :                     n->name = $1;
    8594       16120 :                     n->argType = $2;
    8595       16120 :                     n->mode = FUNC_PARAM_DEFAULT;
    8596       16120 :                     n->defexpr = NULL;
    8597       16120 :                     n->location = @1;
    8598       16120 :                     $$ = n;
    8599             :                 }
    8600             :             | arg_class func_type
    8601             :                 {
    8602         358 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8603             : 
    8604         358 :                     n->name = NULL;
    8605         358 :                     n->argType = $2;
    8606         358 :                     n->mode = $1;
    8607         358 :                     n->defexpr = NULL;
    8608         358 :                     n->location = @1;
    8609         358 :                     $$ = n;
    8610             :                 }
    8611             :             | func_type
    8612             :                 {
    8613       40828 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8614             : 
    8615       40828 :                     n->name = NULL;
    8616       40828 :                     n->argType = $1;
    8617       40828 :                     n->mode = FUNC_PARAM_DEFAULT;
    8618       40828 :                     n->defexpr = NULL;
    8619       40828 :                     n->location = @1;
    8620       40828 :                     $$ = n;
    8621             :                 }
    8622             :         ;
    8623             : 
    8624             : /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
    8625        4108 : arg_class:  IN_P                                { $$ = FUNC_PARAM_IN; }
    8626       12446 :             | OUT_P                             { $$ = FUNC_PARAM_OUT; }
    8627         218 :             | INOUT                             { $$ = FUNC_PARAM_INOUT; }
    8628           0 :             | IN_P OUT_P                        { $$ = FUNC_PARAM_INOUT; }
    8629         606 :             | VARIADIC                          { $$ = FUNC_PARAM_VARIADIC; }
    8630             :         ;
    8631             : 
    8632             : /*
    8633             :  * Ideally param_name should be ColId, but that causes too many conflicts.
    8634             :  */
    8635             : param_name: type_function_name
    8636             :         ;
    8637             : 
    8638             : func_return:
    8639             :             func_type
    8640             :                 {
    8641             :                     /* We can catch over-specified results here if we want to,
    8642             :                      * but for now better to silently swallow typmod, etc.
    8643             :                      * - thomas 2000-03-22
    8644             :                      */
    8645       23984 :                     $$ = $1;
    8646             :                 }
    8647             :         ;
    8648             : 
    8649             : /*
    8650             :  * We would like to make the %TYPE productions here be ColId attrs etc,
    8651             :  * but that causes reduce/reduce conflicts.  type_function_name
    8652             :  * is next best choice.
    8653             :  */
    8654      119910 : func_type:  Typename                                { $$ = $1; }
    8655             :             | type_function_name attrs '%' TYPE_P
    8656             :                 {
    8657          18 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
    8658          18 :                     $$->pct_type = true;
    8659          18 :                     $$->location = @1;
    8660             :                 }
    8661             :             | SETOF type_function_name attrs '%' TYPE_P
    8662             :                 {
    8663           6 :                     $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
    8664           6 :                     $$->pct_type = true;
    8665           6 :                     $$->setof = true;
    8666           6 :                     $$->location = @2;
    8667             :                 }
    8668             :         ;
    8669             : 
    8670             : func_arg_with_default:
    8671             :         func_arg
    8672             :                 {
    8673       47872 :                     $$ = $1;
    8674             :                 }
    8675             :         | func_arg DEFAULT a_expr
    8676             :                 {
    8677        6358 :                     $$ = $1;
    8678        6358 :                     $$->defexpr = $3;
    8679             :                 }
    8680             :         | func_arg '=' a_expr
    8681             :                 {
    8682         196 :                     $$ = $1;
    8683         196 :                     $$->defexpr = $3;
    8684             :                 }
    8685             :         ;
    8686             : 
    8687             : /* Aggregate args can be most things that function args can be */
    8688             : aggr_arg:   func_arg
    8689             :                 {
    8690        1098 :                     if (!($1->mode == FUNC_PARAM_DEFAULT ||
    8691          76 :                           $1->mode == FUNC_PARAM_IN ||
    8692          76 :                           $1->mode == FUNC_PARAM_VARIADIC))
    8693           0 :                         ereport(ERROR,
    8694             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    8695             :                                  errmsg("aggregates cannot have output arguments"),
    8696             :                                  parser_errposition(@1)));
    8697        1098 :                     $$ = $1;
    8698             :                 }
    8699             :         ;
    8700             : 
    8701             : /*
    8702             :  * The SQL standard offers no guidance on how to declare aggregate argument
    8703             :  * lists, since it doesn't have CREATE AGGREGATE etc.  We accept these cases:
    8704             :  *
    8705             :  * (*)                                  - normal agg with no args
    8706             :  * (aggr_arg,...)                       - normal agg with args
    8707             :  * (ORDER BY aggr_arg,...)              - ordered-set agg with no direct args
    8708             :  * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
    8709             :  *
    8710             :  * The zero-argument case is spelled with '*' for consistency with COUNT(*).
    8711             :  *
    8712             :  * An additional restriction is that if the direct-args list ends in a
    8713             :  * VARIADIC item, the ordered-args list must contain exactly one item that
    8714             :  * is also VARIADIC with the same type.  This allows us to collapse the two
    8715             :  * VARIADIC items into one, which is necessary to represent the aggregate in
    8716             :  * pg_proc.  We check this at the grammar stage so that we can return a list
    8717             :  * in which the second VARIADIC item is already discarded, avoiding extra work
    8718             :  * in cases such as DROP AGGREGATE.
    8719             :  *
    8720             :  * The return value of this production is a two-element list, in which the
    8721             :  * first item is a sublist of FunctionParameter nodes (with any duplicate
    8722             :  * VARIADIC item already dropped, as per above) and the second is an Integer
    8723             :  * node, containing -1 if there was no ORDER BY and otherwise the number
    8724             :  * of argument declarations before the ORDER BY.  (If this number is equal
    8725             :  * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
    8726             :  * This representation is passed as-is to CREATE AGGREGATE; for operations
    8727             :  * on existing aggregates, we can just apply extractArgTypes to the first
    8728             :  * sublist.
    8729             :  */
    8730             : aggr_args:  '(' '*' ')'
    8731             :                 {
    8732         170 :                     $$ = list_make2(NIL, makeInteger(-1));
    8733             :                 }
    8734             :             | '(' aggr_args_list ')'
    8735             :                 {
    8736         882 :                     $$ = list_make2($2, makeInteger(-1));
    8737             :                 }
    8738             :             | '(' ORDER BY aggr_args_list ')'
    8739             :                 {
    8740           6 :                     $$ = list_make2($4, makeInteger(0));
    8741             :                 }
    8742             :             | '(' aggr_args_list ORDER BY aggr_args_list ')'
    8743             :                 {
    8744             :                     /* this is the only case requiring consistency checking */
    8745          40 :                     $$ = makeOrderedSetArgs($2, $5, yyscanner);
    8746             :                 }
    8747             :         ;
    8748             : 
    8749             : aggr_args_list:
    8750         968 :             aggr_arg                                { $$ = list_make1($1); }
    8751         130 :             | aggr_args_list ',' aggr_arg           { $$ = lappend($1, $3); }
    8752             :         ;
    8753             : 
    8754             : aggregate_with_argtypes:
    8755             :             func_name aggr_args
    8756             :                 {
    8757         460 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8758             : 
    8759         460 :                     n->objname = $1;
    8760         460 :                     n->objargs = extractAggrArgTypes($2);
    8761         460 :                     n->objfuncargs = (List *) linitial($2);
    8762         460 :                     $$ = n;
    8763             :                 }
    8764             :         ;
    8765             : 
    8766             : aggregate_with_argtypes_list:
    8767         104 :             aggregate_with_argtypes                 { $$ = list_make1($1); }
    8768             :             | aggregate_with_argtypes_list ',' aggregate_with_argtypes
    8769           0 :                                                     { $$ = lappend($1, $3); }
    8770             :         ;
    8771             : 
    8772             : opt_createfunc_opt_list:
    8773             :             createfunc_opt_list
    8774          54 :             | /*EMPTY*/ { $$ = NIL; }
    8775             :     ;
    8776             : 
    8777             : createfunc_opt_list:
    8778             :             /* Must be at least one to prevent conflict */
    8779       25012 :             createfunc_opt_item                     { $$ = list_make1($1); }
    8780       65640 :             | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
    8781             :     ;
    8782             : 
    8783             : /*
    8784             :  * Options common to both CREATE FUNCTION and ALTER FUNCTION
    8785             :  */
    8786             : common_func_opt_item:
    8787             :             CALLED ON NULL_P INPUT_P
    8788             :                 {
    8789         386 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(false), @1);
    8790             :                 }
    8791             :             | RETURNS NULL_P ON NULL_P INPUT_P
    8792             :                 {
    8793         900 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8794             :                 }
    8795             :             | STRICT_P
    8796             :                 {
    8797       12966 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8798             :                 }
    8799             :             | IMMUTABLE
    8800             :                 {
    8801        9374 :                     $$ = makeDefElem("volatility", (Node *) makeString("immutable"), @1);
    8802             :                 }
    8803             :             | STABLE
    8804             :                 {
    8805        2578 :                     $$ = makeDefElem("volatility", (Node *) makeString("stable"), @1);
    8806             :                 }
    8807             :             | VOLATILE
    8808             :                 {
    8809        1766 :                     $$ = makeDefElem("volatility", (Node *) makeString("volatile"), @1);
    8810             :                 }
    8811             :             | EXTERNAL SECURITY DEFINER
    8812             :                 {
    8813           0 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8814             :                 }
    8815             :             | EXTERNAL SECURITY INVOKER
    8816             :                 {
    8817           0 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8818             :                 }
    8819             :             | SECURITY DEFINER
    8820             :                 {
    8821          58 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8822             :                 }
    8823             :             | SECURITY INVOKER
    8824             :                 {
    8825          18 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8826             :                 }
    8827             :             | LEAKPROOF
    8828             :                 {
    8829          50 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(true), @1);
    8830             :                 }
    8831             :             | NOT LEAKPROOF
    8832             :                 {
    8833          12 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(false), @1);
    8834             :                 }
    8835             :             | COST NumericOnly
    8836             :                 {
    8837        4450 :                     $$ = makeDefElem("cost", (Node *) $2, @1);
    8838             :                 }
    8839             :             | ROWS NumericOnly
    8840             :                 {
    8841         612 :                     $$ = makeDefElem("rows", (Node *) $2, @1);
    8842             :                 }
    8843             :             | SUPPORT any_name
    8844             :                 {
    8845         120 :                     $$ = makeDefElem("support", (Node *) $2, @1);
    8846             :                 }
    8847             :             | FunctionSetResetClause
    8848             :                 {
    8849             :                     /* we abuse the normal content of a DefElem here */
    8850         160 :                     $$ = makeDefElem("set", (Node *) $1, @1);
    8851             :                 }
    8852             :             | PARALLEL ColId
    8853             :                 {
    8854       13472 :                     $$ = makeDefElem("parallel", (Node *) makeString($2), @1);
    8855             :                 }
    8856             :         ;
    8857             : 
    8858             : createfunc_opt_item:
    8859             :             AS func_as
    8860             :                 {
    8861       19274 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    8862             :                 }
    8863             :             | LANGUAGE NonReservedWord_or_Sconst
    8864             :                 {
    8865       24992 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    8866             :                 }
    8867             :             | TRANSFORM transform_type_list
    8868             :                 {
    8869         118 :                     $$ = makeDefElem("transform", (Node *) $2, @1);
    8870             :                 }
    8871             :             | WINDOW
    8872             :                 {
    8873          22 :                     $$ = makeDefElem("window", (Node *) makeBoolean(true), @1);
    8874             :                 }
    8875             :             | common_func_opt_item
    8876             :                 {
    8877       46246 :                     $$ = $1;
    8878             :                 }
    8879             :         ;
    8880             : 
    8881       16000 : func_as:    Sconst                      { $$ = list_make1(makeString($1)); }
    8882             :             | Sconst ',' Sconst
    8883             :                 {
    8884        3274 :                     $$ = list_make2(makeString($1), makeString($3));
    8885             :                 }
    8886             :         ;
    8887             : 
    8888             : ReturnStmt: RETURN a_expr
    8889             :                 {
    8890        4980 :                     ReturnStmt *r = makeNode(ReturnStmt);
    8891             : 
    8892        4980 :                     r->returnval = (Node *) $2;
    8893        4980 :                     $$ = (Node *) r;
    8894             :                 }
    8895             :         ;
    8896             : 
    8897             : opt_routine_body:
    8898             :             ReturnStmt
    8899             :                 {
    8900        4974 :                     $$ = $1;
    8901             :                 }
    8902             :             | BEGIN_P ATOMIC routine_body_stmt_list END_P
    8903             :                 {
    8904             :                     /*
    8905             :                      * A compound statement is stored as a single-item list
    8906             :                      * containing the list of statements as its member.  That
    8907             :                      * way, the parse analysis code can tell apart an empty
    8908             :                      * body from no body at all.
    8909             :                      */
    8910         824 :                     $$ = (Node *) list_make1($3);
    8911             :                 }
    8912             :             | /*EMPTY*/
    8913             :                 {
    8914       19268 :                     $$ = NULL;
    8915             :                 }
    8916             :         ;
    8917             : 
    8918             : routine_body_stmt_list:
    8919             :             routine_body_stmt_list routine_body_stmt ';'
    8920             :                 {
    8921             :                     /* As in stmtmulti, discard empty statements */
    8922         838 :                     if ($2 != NULL)
    8923         820 :                         $$ = lappend($1, $2);
    8924             :                     else
    8925          18 :                         $$ = $1;
    8926             :                 }
    8927             :             | /*EMPTY*/
    8928             :                 {
    8929         824 :                     $$ = NIL;
    8930             :                 }
    8931             :         ;
    8932             : 
    8933             : routine_body_stmt:
    8934             :             stmt
    8935             :             | ReturnStmt
    8936             :         ;
    8937             : 
    8938             : transform_type_list:
    8939         118 :             FOR TYPE_P Typename { $$ = list_make1($3); }
    8940           4 :             | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
    8941             :         ;
    8942             : 
    8943             : opt_definition:
    8944         606 :             WITH definition                         { $$ = $2; }
    8945       10296 :             | /*EMPTY*/                             { $$ = NIL; }
    8946             :         ;
    8947             : 
    8948             : table_func_column:  param_name func_type
    8949             :                 {
    8950         462 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8951             : 
    8952         462 :                     n->name = $1;
    8953         462 :                     n->argType = $2;
    8954         462 :                     n->mode = FUNC_PARAM_TABLE;
    8955         462 :                     n->defexpr = NULL;
    8956         462 :                     n->location = @1;
    8957         462 :                     $$ = n;
    8958             :                 }
    8959             :         ;
    8960             : 
    8961             : table_func_column_list:
    8962             :             table_func_column
    8963             :                 {
    8964         202 :                     $$ = list_make1($1);
    8965             :                 }
    8966             :             | table_func_column_list ',' table_func_column
    8967             :                 {
    8968         260 :                     $$ = lappend($1, $3);
    8969             :                 }
    8970             :         ;
    8971             : 
    8972             : /*****************************************************************************
    8973             :  * ALTER FUNCTION / ALTER PROCEDURE / ALTER ROUTINE
    8974             :  *
    8975             :  * RENAME and OWNER subcommands are already provided by the generic
    8976             :  * ALTER infrastructure, here we just specify alterations that can
    8977             :  * only be applied to functions.
    8978             :  *
    8979             :  *****************************************************************************/
    8980             : AlterFunctionStmt:
    8981             :             ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
    8982             :                 {
    8983         654 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8984             : 
    8985         654 :                     n->objtype = OBJECT_FUNCTION;
    8986         654 :                     n->func = $3;
    8987         654 :                     n->actions = $4;
    8988         654 :                     $$ = (Node *) n;
    8989             :                 }
    8990             :             | ALTER PROCEDURE function_with_argtypes alterfunc_opt_list opt_restrict
    8991             :                 {
    8992          18 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8993             : 
    8994          18 :                     n->objtype = OBJECT_PROCEDURE;
    8995          18 :                     n->func = $3;
    8996          18 :                     n->actions = $4;
    8997          18 :                     $$ = (Node *) n;
    8998             :                 }
    8999             :             | ALTER ROUTINE function_with_argtypes alterfunc_opt_list opt_restrict
    9000             :                 {
    9001           0 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    9002             : 
    9003           0 :                     n->objtype = OBJECT_ROUTINE;
    9004           0 :                     n->func = $3;
    9005           0 :                     n->actions = $4;
    9006           0 :                     $$ = (Node *) n;
    9007             :                 }
    9008             :         ;
    9009             : 
    9010             : alterfunc_opt_list:
    9011             :             /* At least one option must be specified */
    9012         672 :             common_func_opt_item                    { $$ = list_make1($1); }
    9013           4 :             | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
    9014             :         ;
    9015             : 
    9016             : /* Ignored, merely for SQL compliance */
    9017             : opt_restrict:
    9018             :             RESTRICT
    9019             :             | /* EMPTY */
    9020             :         ;
    9021             : 
    9022             : 
    9023             : /*****************************************************************************
    9024             :  *
    9025             :  *      QUERY:
    9026             :  *
    9027             :  *      DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    9028             :  *      DROP PROCEDURE procname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    9029             :  *      DROP ROUTINE routname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    9030             :  *      DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
    9031             :  *      DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
    9032             :  *
    9033             :  *****************************************************************************/
    9034             : 
    9035             : RemoveFuncStmt:
    9036             :             DROP FUNCTION function_with_argtypes_list opt_drop_behavior
    9037             :                 {
    9038        3262 :                     DropStmt *n = makeNode(DropStmt);
    9039             : 
    9040        3262 :                     n->removeType = OBJECT_FUNCTION;
    9041        3262 :                     n->objects = $3;
    9042        3262 :                     n->behavior = $4;
    9043        3262 :                     n->missing_ok = false;
    9044        3262 :                     n->concurrent = false;
    9045        3262 :                     $$ = (Node *) n;
    9046             :                 }
    9047             :             | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9048             :                 {
    9049         260 :                     DropStmt *n = makeNode(DropStmt);
    9050             : 
    9051         260 :                     n->removeType = OBJECT_FUNCTION;
    9052         260 :                     n->objects = $5;
    9053         260 :                     n->behavior = $6;
    9054         260 :                     n->missing_ok = true;
    9055         260 :                     n->concurrent = false;
    9056         260 :                     $$ = (Node *) n;
    9057             :                 }
    9058             :             | DROP PROCEDURE function_with_argtypes_list opt_drop_behavior
    9059             :                 {
    9060         138 :                     DropStmt *n = makeNode(DropStmt);
    9061             : 
    9062         138 :                     n->removeType = OBJECT_PROCEDURE;
    9063         138 :                     n->objects = $3;
    9064         138 :                     n->behavior = $4;
    9065         138 :                     n->missing_ok = false;
    9066         138 :                     n->concurrent = false;
    9067         138 :                     $$ = (Node *) n;
    9068             :                 }
    9069             :             | DROP PROCEDURE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9070             :                 {
    9071           6 :                     DropStmt *n = makeNode(DropStmt);
    9072             : 
    9073           6 :                     n->removeType = OBJECT_PROCEDURE;
    9074           6 :                     n->objects = $5;
    9075           6 :                     n->behavior = $6;
    9076           6 :                     n->missing_ok = true;
    9077           6 :                     n->concurrent = false;
    9078           6 :                     $$ = (Node *) n;
    9079             :                 }
    9080             :             | DROP ROUTINE function_with_argtypes_list opt_drop_behavior
    9081             :                 {
    9082          12 :                     DropStmt *n = makeNode(DropStmt);
    9083             : 
    9084          12 :                     n->removeType = OBJECT_ROUTINE;
    9085          12 :                     n->objects = $3;
    9086          12 :                     n->behavior = $4;
    9087          12 :                     n->missing_ok = false;
    9088          12 :                     n->concurrent = false;
    9089          12 :                     $$ = (Node *) n;
    9090             :                 }
    9091             :             | DROP ROUTINE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9092             :                 {
    9093           6 :                     DropStmt *n = makeNode(DropStmt);
    9094             : 
    9095           6 :                     n->removeType = OBJECT_ROUTINE;
    9096           6 :                     n->objects = $5;
    9097           6 :                     n->behavior = $6;
    9098           6 :                     n->missing_ok = true;
    9099           6 :                     n->concurrent = false;
    9100           6 :                     $$ = (Node *) n;
    9101             :                 }
    9102             :         ;
    9103             : 
    9104             : RemoveAggrStmt:
    9105             :             DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
    9106             :                 {
    9107          74 :                     DropStmt *n = makeNode(DropStmt);
    9108             : 
    9109          74 :                     n->removeType = OBJECT_AGGREGATE;
    9110          74 :                     n->objects = $3;
    9111          74 :                     n->behavior = $4;
    9112          74 :                     n->missing_ok = false;
    9113          74 :                     n->concurrent = false;
    9114          74 :                     $$ = (Node *) n;
    9115             :                 }
    9116             :             | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
    9117             :                 {
    9118          30 :                     DropStmt *n = makeNode(DropStmt);
    9119             : 
    9120          30 :                     n->removeType = OBJECT_AGGREGATE;
    9121          30 :                     n->objects = $5;
    9122          30 :                     n->behavior = $6;
    9123          30 :                     n->missing_ok = true;
    9124          30 :                     n->concurrent = false;
    9125          30 :                     $$ = (Node *) n;
    9126             :                 }
    9127             :         ;
    9128             : 
    9129             : RemoveOperStmt:
    9130             :             DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
    9131             :                 {
    9132         194 :                     DropStmt *n = makeNode(DropStmt);
    9133             : 
    9134         194 :                     n->removeType = OBJECT_OPERATOR;
    9135         194 :                     n->objects = $3;
    9136         194 :                     n->behavior = $4;
    9137         194 :                     n->missing_ok = false;
    9138         194 :                     n->concurrent = false;
    9139         194 :                     $$ = (Node *) n;
    9140             :                 }
    9141             :             | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
    9142             :                 {
    9143          30 :                     DropStmt *n = makeNode(DropStmt);
    9144             : 
    9145          30 :                     n->removeType = OBJECT_OPERATOR;
    9146          30 :                     n->objects = $5;
    9147          30 :                     n->behavior = $6;
    9148          30 :                     n->missing_ok = true;
    9149          30 :                     n->concurrent = false;
    9150          30 :                     $$ = (Node *) n;
    9151             :                 }
    9152             :         ;
    9153             : 
    9154             : oper_argtypes:
    9155             :             '(' Typename ')'
    9156             :                 {
    9157          12 :                    ereport(ERROR,
    9158             :                            (errcode(ERRCODE_SYNTAX_ERROR),
    9159             :                             errmsg("missing argument"),
    9160             :                             errhint("Use NONE to denote the missing argument of a unary operator."),
    9161             :                             parser_errposition(@3)));
    9162             :                 }
    9163             :             | '(' Typename ',' Typename ')'
    9164        2128 :                     { $$ = list_make2($2, $4); }
    9165             :             | '(' NONE ',' Typename ')'                 /* left unary */
    9166          40 :                     { $$ = list_make2(NULL, $4); }
    9167             :             | '(' Typename ',' NONE ')'                 /* right unary */
    9168          12 :                     { $$ = list_make2($2, NULL); }
    9169             :         ;
    9170             : 
    9171             : any_operator:
    9172             :             all_Op
    9173       21088 :                     { $$ = list_make1(makeString($1)); }
    9174             :             | ColId '.' any_operator
    9175       16008 :                     { $$ = lcons(makeString($1), $3); }
    9176             :         ;
    9177             : 
    9178             : operator_with_argtypes_list:
    9179         224 :             operator_with_argtypes                  { $$ = list_make1($1); }
    9180             :             | operator_with_argtypes_list ',' operator_with_argtypes
    9181           0 :                                                     { $$ = lappend($1, $3); }
    9182             :         ;
    9183             : 
    9184             : operator_with_argtypes:
    9185             :             any_operator oper_argtypes
    9186             :                 {
    9187        2180 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    9188             : 
    9189        2180 :                     n->objname = $1;
    9190        2180 :                     n->objargs = $2;
    9191        2180 :                     $$ = n;
    9192             :                 }
    9193             :         ;
    9194             : 
    9195             : /*****************************************************************************
    9196             :  *
    9197             :  *      DO <anonymous code block> [ LANGUAGE language ]
    9198             :  *
    9199             :  * We use a DefElem list for future extensibility, and to allow flexibility
    9200             :  * in the clause order.
    9201             :  *
    9202             :  *****************************************************************************/
    9203             : 
    9204             : DoStmt: DO dostmt_opt_list
    9205             :                 {
    9206        1142 :                     DoStmt *n = makeNode(DoStmt);
    9207             : 
    9208        1142 :                     n->args = $2;
    9209        1142 :                     $$ = (Node *) n;
    9210             :                 }
    9211             :         ;
    9212             : 
    9213             : dostmt_opt_list:
    9214        1142 :             dostmt_opt_item                     { $$ = list_make1($1); }
    9215         198 :             | dostmt_opt_list dostmt_opt_item   { $$ = lappend($1, $2); }
    9216             :         ;
    9217             : 
    9218             : dostmt_opt_item:
    9219             :             Sconst
    9220             :                 {
    9221        1142 :                     $$ = makeDefElem("as", (Node *) makeString($1), @1);
    9222             :                 }
    9223             :             | LANGUAGE NonReservedWord_or_Sconst
    9224             :                 {
    9225         198 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    9226             :                 }
    9227             :         ;
    9228             : 
    9229             : /*****************************************************************************
    9230             :  *
    9231             :  *      CREATE CAST / DROP CAST
    9232             :  *
    9233             :  *****************************************************************************/
    9234             : 
    9235             : CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
    9236             :                     WITH FUNCTION function_with_argtypes cast_context
    9237             :                 {
    9238         110 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9239             : 
    9240         110 :                     n->sourcetype = $4;
    9241         110 :                     n->targettype = $6;
    9242         110 :                     n->func = $10;
    9243         110 :                     n->context = (CoercionContext) $11;
    9244         110 :                     n->inout = false;
    9245         110 :                     $$ = (Node *) n;
    9246             :                 }
    9247             :             | CREATE CAST '(' Typename AS Typename ')'
    9248             :                     WITHOUT FUNCTION cast_context
    9249             :                 {
    9250         172 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9251             : 
    9252         172 :                     n->sourcetype = $4;
    9253         172 :                     n->targettype = $6;
    9254         172 :                     n->func = NULL;
    9255         172 :                     n->context = (CoercionContext) $10;
    9256         172 :                     n->inout = false;
    9257         172 :                     $$ = (Node *) n;
    9258             :                 }
    9259             :             | CREATE CAST '(' Typename AS Typename ')'
    9260             :                     WITH INOUT cast_context
    9261             :                 {
    9262           8 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9263             : 
    9264           8 :                     n->sourcetype = $4;
    9265           8 :                     n->targettype = $6;
    9266           8 :                     n->func = NULL;
    9267           8 :                     n->context = (CoercionContext) $10;
    9268           8 :                     n->inout = true;
    9269           8 :                     $$ = (Node *) n;
    9270             :                 }
    9271             :         ;
    9272             : 
    9273          40 : cast_context:  AS IMPLICIT_P                    { $$ = COERCION_IMPLICIT; }
    9274          58 :         | AS ASSIGNMENT                         { $$ = COERCION_ASSIGNMENT; }
    9275         192 :         | /*EMPTY*/                             { $$ = COERCION_EXPLICIT; }
    9276             :         ;
    9277             : 
    9278             : 
    9279             : DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
    9280             :                 {
    9281          60 :                     DropStmt *n = makeNode(DropStmt);
    9282             : 
    9283          60 :                     n->removeType = OBJECT_CAST;
    9284          60 :                     n->objects = list_make1(list_make2($5, $7));
    9285          60 :                     n->behavior = $9;
    9286          60 :                     n->missing_ok = $3;
    9287          60 :                     n->concurrent = false;
    9288          60 :                     $$ = (Node *) n;
    9289             :                 }
    9290             :         ;
    9291             : 
    9292          36 : opt_if_exists: IF_P EXISTS                      { $$ = true; }
    9293          38 :         | /*EMPTY*/                             { $$ = false; }
    9294             :         ;
    9295             : 
    9296             : 
    9297             : /*****************************************************************************
    9298             :  *
    9299             :  *      CREATE TRANSFORM / DROP TRANSFORM
    9300             :  *
    9301             :  *****************************************************************************/
    9302             : 
    9303             : CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name '(' transform_element_list ')'
    9304             :                 {
    9305          52 :                     CreateTransformStmt *n = makeNode(CreateTransformStmt);
    9306             : 
    9307          52 :                     n->replace = $2;
    9308          52 :                     n->type_name = $5;
    9309          52 :                     n->lang = $7;
    9310          52 :                     n->fromsql = linitial($9);
    9311          52 :                     n->tosql = lsecond($9);
    9312          52 :                     $$ = (Node *) n;
    9313             :                 }
    9314             :         ;
    9315             : 
    9316             : transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes ',' TO SQL_P WITH FUNCTION function_with_argtypes
    9317             :                 {
    9318          46 :                     $$ = list_make2($5, $11);
    9319             :                 }
    9320             :                 | TO SQL_P WITH FUNCTION function_with_argtypes ',' FROM SQL_P WITH FUNCTION function_with_argtypes
    9321             :                 {
    9322           0 :                     $$ = list_make2($11, $5);
    9323             :                 }
    9324             :                 | FROM SQL_P WITH FUNCTION function_with_argtypes
    9325             :                 {
    9326           4 :                     $$ = list_make2($5, NULL);
    9327             :                 }
    9328             :                 | TO SQL_P WITH FUNCTION function_with_argtypes
    9329             :                 {
    9330           2 :                     $$ = list_make2(NULL, $5);
    9331             :                 }
    9332             :         ;
    9333             : 
    9334             : 
    9335             : DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
    9336             :                 {
    9337          14 :                     DropStmt *n = makeNode(DropStmt);
    9338             : 
    9339          14 :                     n->removeType = OBJECT_TRANSFORM;
    9340          14 :                     n->objects = list_make1(list_make2($5, makeString($7)));
    9341          14 :                     n->behavior = $8;
    9342          14 :                     n->missing_ok = $3;
    9343          14 :                     $$ = (Node *) n;
    9344             :                 }
    9345             :         ;
    9346             : 
    9347             : 
    9348             : /*****************************************************************************
    9349             :  *
    9350             :  *      QUERY:
    9351             :  *
    9352             :  *      REINDEX [ (options) ] {INDEX | TABLE | SCHEMA} [CONCURRENTLY] <name>
    9353             :  *      REINDEX [ (options) ] {DATABASE | SYSTEM} [CONCURRENTLY] [<name>]
    9354             :  *****************************************************************************/
    9355             : 
    9356             : ReindexStmt:
    9357             :             REINDEX opt_reindex_option_list reindex_target_relation opt_concurrently qualified_name
    9358             :                 {
    9359         918 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9360             : 
    9361         918 :                     n->kind = $3;
    9362         918 :                     n->relation = $5;
    9363         918 :                     n->name = NULL;
    9364         918 :                     n->params = $2;
    9365         918 :                     if ($4)
    9366         514 :                         n->params = lappend(n->params,
    9367         514 :                                             makeDefElem("concurrently", NULL, @4));
    9368         918 :                     $$ = (Node *) n;
    9369             :                 }
    9370             :             | REINDEX opt_reindex_option_list SCHEMA opt_concurrently name
    9371             :                 {
    9372         114 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9373             : 
    9374         114 :                     n->kind = REINDEX_OBJECT_SCHEMA;
    9375         114 :                     n->relation = NULL;
    9376         114 :                     n->name = $5;
    9377         114 :                     n->params = $2;
    9378         114 :                     if ($4)
    9379          40 :                         n->params = lappend(n->params,
    9380          40 :                                             makeDefElem("concurrently", NULL, @4));
    9381         114 :                     $$ = (Node *) n;
    9382             :                 }
    9383             :             | REINDEX opt_reindex_option_list reindex_target_all opt_concurrently opt_single_name
    9384             :                 {
    9385          64 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9386             : 
    9387          64 :                     n->kind = $3;
    9388          64 :                     n->relation = NULL;
    9389          64 :                     n->name = $5;
    9390          64 :                     n->params = $2;
    9391          64 :                     if ($4)
    9392          10 :                         n->params = lappend(n->params,
    9393          10 :                                             makeDefElem("concurrently", NULL, @4));
    9394          64 :                     $$ = (Node *) n;
    9395             :                 }
    9396             :         ;
    9397             : reindex_target_relation:
    9398         390 :             INDEX                   { $$ = REINDEX_OBJECT_INDEX; }
    9399         528 :             | TABLE                 { $$ = REINDEX_OBJECT_TABLE; }
    9400             :         ;
    9401             : reindex_target_all:
    9402          34 :             SYSTEM_P                { $$ = REINDEX_OBJECT_SYSTEM; }
    9403          30 :             | DATABASE              { $$ = REINDEX_OBJECT_DATABASE; }
    9404             :         ;
    9405             : opt_reindex_option_list:
    9406         156 :             '(' utility_option_list ')'             { $$ = $2; }
    9407         940 :             | /* EMPTY */                           { $$ = NULL; }
    9408             :         ;
    9409             : 
    9410             : /*****************************************************************************
    9411             :  *
    9412             :  * ALTER TABLESPACE
    9413             :  *
    9414             :  *****************************************************************************/
    9415             : 
    9416             : AlterTblSpcStmt:
    9417             :             ALTER TABLESPACE name SET reloptions
    9418             :                 {
    9419             :                     AlterTableSpaceOptionsStmt *n =
    9420          12 :                         makeNode(AlterTableSpaceOptionsStmt);
    9421             : 
    9422          12 :                     n->tablespacename = $3;
    9423          12 :                     n->options = $5;
    9424          12 :                     n->isReset = false;
    9425          12 :                     $$ = (Node *) n;
    9426             :                 }
    9427             :             | ALTER TABLESPACE name RESET reloptions
    9428             :                 {
    9429             :                     AlterTableSpaceOptionsStmt *n =
    9430          12 :                         makeNode(AlterTableSpaceOptionsStmt);
    9431             : 
    9432          12 :                     n->tablespacename = $3;
    9433          12 :                     n->options = $5;
    9434          12 :                     n->isReset = true;
    9435          12 :                     $$ = (Node *) n;
    9436             :                 }
    9437             :         ;
    9438             : 
    9439             : /*****************************************************************************
    9440             :  *
    9441             :  * ALTER THING name RENAME TO newname
    9442             :  *
    9443             :  *****************************************************************************/
    9444             : 
    9445             : RenameStmt: ALTER AGGREGATE aggregate_with_argtypes RENAME TO name
    9446             :                 {
    9447          42 :                     RenameStmt *n = makeNode(RenameStmt);
    9448             : 
    9449          42 :                     n->renameType = OBJECT_AGGREGATE;
    9450          42 :                     n->object = (Node *) $3;
    9451          42 :                     n->newname = $6;
    9452          42 :                     n->missing_ok = false;
    9453          42 :                     $$ = (Node *) n;
    9454             :                 }
    9455             :             | ALTER COLLATION any_name RENAME TO name
    9456             :                 {
    9457          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9458             : 
    9459          18 :                     n->renameType = OBJECT_COLLATION;
    9460          18 :                     n->object = (Node *) $3;
    9461          18 :                     n->newname = $6;
    9462          18 :                     n->missing_ok = false;
    9463          18 :                     $$ = (Node *) n;
    9464             :                 }
    9465             :             | ALTER CONVERSION_P any_name RENAME TO name
    9466             :                 {
    9467          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9468             : 
    9469          24 :                     n->renameType = OBJECT_CONVERSION;
    9470          24 :                     n->object = (Node *) $3;
    9471          24 :                     n->newname = $6;
    9472          24 :                     n->missing_ok = false;
    9473          24 :                     $$ = (Node *) n;
    9474             :                 }
    9475             :             | ALTER DATABASE name RENAME TO name
    9476             :                 {
    9477           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9478             : 
    9479           6 :                     n->renameType = OBJECT_DATABASE;
    9480           6 :                     n->subname = $3;
    9481           6 :                     n->newname = $6;
    9482           6 :                     n->missing_ok = false;
    9483           6 :                     $$ = (Node *) n;
    9484             :                 }
    9485             :             | ALTER DOMAIN_P any_name RENAME TO name
    9486             :                 {
    9487           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9488             : 
    9489           6 :                     n->renameType = OBJECT_DOMAIN;
    9490           6 :                     n->object = (Node *) $3;
    9491           6 :                     n->newname = $6;
    9492           6 :                     n->missing_ok = false;
    9493           6 :                     $$ = (Node *) n;
    9494             :                 }
    9495             :             | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
    9496             :                 {
    9497           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9498             : 
    9499           6 :                     n->renameType = OBJECT_DOMCONSTRAINT;
    9500           6 :                     n->object = (Node *) $3;
    9501           6 :                     n->subname = $6;
    9502           6 :                     n->newname = $8;
    9503           6 :                     $$ = (Node *) n;
    9504             :                 }
    9505             :             | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
    9506             :                 {
    9507          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9508             : 
    9509          24 :                     n->renameType = OBJECT_FDW;
    9510          24 :                     n->object = (Node *) makeString($5);
    9511          24 :                     n->newname = $8;
    9512          24 :                     n->missing_ok = false;
    9513          24 :                     $$ = (Node *) n;
    9514             :                 }
    9515             :             | ALTER FUNCTION function_with_argtypes RENAME TO name
    9516             :                 {
    9517          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9518             : 
    9519          24 :                     n->renameType = OBJECT_FUNCTION;
    9520          24 :                     n->object = (Node *) $3;
    9521          24 :                     n->newname = $6;
    9522          24 :                     n->missing_ok = false;
    9523          24 :                     $$ = (Node *) n;
    9524             :                 }
    9525             :             | ALTER GROUP_P RoleId RENAME TO RoleId
    9526             :                 {
    9527           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9528             : 
    9529           0 :                     n->renameType = OBJECT_ROLE;
    9530           0 :                     n->subname = $3;
    9531           0 :                     n->newname = $6;
    9532           0 :                     n->missing_ok = false;
    9533           0 :                     $$ = (Node *) n;
    9534             :                 }
    9535             :             | ALTER opt_procedural LANGUAGE name RENAME TO name
    9536             :                 {
    9537          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9538             : 
    9539          18 :                     n->renameType = OBJECT_LANGUAGE;
    9540          18 :                     n->object = (Node *) makeString($4);
    9541          18 :                     n->newname = $7;
    9542          18 :                     n->missing_ok = false;
    9543          18 :                     $$ = (Node *) n;
    9544             :                 }
    9545             :             | ALTER OPERATOR CLASS any_name USING name RENAME TO name
    9546             :                 {
    9547          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9548             : 
    9549          24 :                     n->renameType = OBJECT_OPCLASS;
    9550          24 :                     n->object = (Node *) lcons(makeString($6), $4);
    9551          24 :                     n->newname = $9;
    9552          24 :                     n->missing_ok = false;
    9553          24 :                     $$ = (Node *) n;
    9554             :                 }
    9555             :             | ALTER OPERATOR FAMILY any_name USING name RENAME TO name
    9556             :                 {
    9557          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9558             : 
    9559          24 :                     n->renameType = OBJECT_OPFAMILY;
    9560          24 :                     n->object = (Node *) lcons(makeString($6), $4);
    9561          24 :                     n->newname = $9;
    9562          24 :                     n->missing_ok = false;
    9563          24 :                     $$ = (Node *) n;
    9564             :                 }
    9565             :             | ALTER POLICY name ON qualified_name RENAME TO name
    9566             :                 {
    9567          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9568             : 
    9569          18 :                     n->renameType = OBJECT_POLICY;
    9570          18 :                     n->relation = $5;
    9571          18 :                     n->subname = $3;
    9572          18 :                     n->newname = $8;
    9573          18 :                     n->missing_ok = false;
    9574          18 :                     $$ = (Node *) n;
    9575             :                 }
    9576             :             | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
    9577             :                 {
    9578           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9579             : 
    9580           0 :                     n->renameType = OBJECT_POLICY;
    9581           0 :                     n->relation = $7;
    9582           0 :                     n->subname = $5;
    9583           0 :                     n->newname = $10;
    9584           0 :                     n->missing_ok = true;
    9585           0 :                     $$ = (Node *) n;
    9586             :                 }
    9587             :             | ALTER PROCEDURE function_with_argtypes RENAME TO name
    9588             :                 {
    9589           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9590             : 
    9591           0 :                     n->renameType = OBJECT_PROCEDURE;
    9592           0 :                     n->object = (Node *) $3;
    9593           0 :                     n->newname = $6;
    9594           0 :                     n->missing_ok = false;
    9595           0 :                     $$ = (Node *) n;
    9596             :                 }
    9597             :             | ALTER PUBLICATION name RENAME TO name
    9598             :                 {
    9599          42 :                     RenameStmt *n = makeNode(RenameStmt);
    9600             : 
    9601          42 :                     n->renameType = OBJECT_PUBLICATION;
    9602          42 :                     n->object = (Node *) makeString($3);
    9603          42 :                     n->newname = $6;
    9604          42 :                     n->missing_ok = false;
    9605          42 :                     $$ = (Node *) n;
    9606             :                 }
    9607             :             | ALTER ROUTINE function_with_argtypes RENAME TO name
    9608             :                 {
    9609          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9610             : 
    9611          24 :                     n->renameType = OBJECT_ROUTINE;
    9612          24 :                     n->object = (Node *) $3;
    9613          24 :                     n->newname = $6;
    9614          24 :                     n->missing_ok = false;
    9615          24 :                     $$ = (Node *) n;
    9616             :                 }
    9617             :             | ALTER SCHEMA name RENAME TO name
    9618             :                 {
    9619          20 :                     RenameStmt *n = makeNode(RenameStmt);
    9620             : 
    9621          20 :                     n->renameType = OBJECT_SCHEMA;
    9622          20 :                     n->subname = $3;
    9623          20 :                     n->newname = $6;
    9624          20 :                     n->missing_ok = false;
    9625          20 :                     $$ = (Node *) n;
    9626             :                 }
    9627             :             | ALTER SERVER name RENAME TO name
    9628             :                 {
    9629          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9630             : 
    9631          24 :                     n->renameType = OBJECT_FOREIGN_SERVER;
    9632          24 :                     n->object = (Node *) makeString($3);
    9633          24 :                     n->newname = $6;
    9634          24 :                     n->missing_ok = false;
    9635          24 :                     $$ = (Node *) n;
    9636             :                 }
    9637             :             | ALTER SUBSCRIPTION name RENAME TO name
    9638             :                 {
    9639          38 :                     RenameStmt *n = makeNode(RenameStmt);
    9640             : 
    9641          38 :                     n->renameType = OBJECT_SUBSCRIPTION;
    9642          38 :                     n->object = (Node *) makeString($3);
    9643          38 :                     n->newname = $6;
    9644          38 :                     n->missing_ok = false;
    9645          38 :                     $$ = (Node *) n;
    9646             :                 }
    9647             :             | ALTER TABLE relation_expr RENAME TO name
    9648             :                 {
    9649         286 :                     RenameStmt *n = makeNode(RenameStmt);
    9650             : 
    9651         286 :                     n->renameType = OBJECT_TABLE;
    9652         286 :                     n->relation = $3;
    9653         286 :                     n->subname = NULL;
    9654         286 :                     n->newname = $6;
    9655         286 :                     n->missing_ok = false;
    9656         286 :                     $$ = (Node *) n;
    9657             :                 }
    9658             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
    9659             :                 {
    9660           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9661             : 
    9662           0 :                     n->renameType = OBJECT_TABLE;
    9663           0 :                     n->relation = $5;
    9664           0 :                     n->subname = NULL;
    9665           0 :                     n->newname = $8;
    9666           0 :                     n->missing_ok = true;
    9667           0 :                     $$ = (Node *) n;
    9668             :                 }
    9669             :             | ALTER SEQUENCE qualified_name RENAME TO name
    9670             :                 {
    9671           2 :                     RenameStmt *n = makeNode(RenameStmt);
    9672             : 
    9673           2 :                     n->renameType = OBJECT_SEQUENCE;
    9674           2 :                     n->relation = $3;
    9675           2 :                     n->subname = NULL;
    9676           2 :                     n->newname = $6;
    9677           2 :                     n->missing_ok = false;
    9678           2 :                     $$ = (Node *) n;
    9679             :                 }
    9680             :             | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
    9681             :                 {
    9682           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9683             : 
    9684           0 :                     n->renameType = OBJECT_SEQUENCE;
    9685           0 :                     n->relation = $5;
    9686           0 :                     n->subname = NULL;
    9687           0 :                     n->newname = $8;
    9688           0 :                     n->missing_ok = true;
    9689           0 :                     $$ = (Node *) n;
    9690             :                 }
    9691             :             | ALTER VIEW qualified_name RENAME TO name
    9692             :                 {
    9693           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9694             : 
    9695           6 :                     n->renameType = OBJECT_VIEW;
    9696           6 :                     n->relation = $3;
    9697           6 :                     n->subname = NULL;
    9698           6 :                     n->newname = $6;
    9699           6 :                     n->missing_ok = false;
    9700           6 :                     $$ = (Node *) n;
    9701             :                 }
    9702             :             | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
    9703             :                 {
    9704           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9705             : 
    9706           0 :                     n->renameType = OBJECT_VIEW;
    9707           0 :                     n->relation = $5;
    9708           0 :                     n->subname = NULL;
    9709           0 :                     n->newname = $8;
    9710           0 :                     n->missing_ok = true;
    9711           0 :                     $$ = (Node *) n;
    9712             :                 }
    9713             :             | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
    9714             :                 {
    9715           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9716             : 
    9717           0 :                     n->renameType = OBJECT_MATVIEW;
    9718           0 :                     n->relation = $4;
    9719           0 :                     n->subname = NULL;
    9720           0 :                     n->newname = $7;
    9721           0 :                     n->missing_ok = false;
    9722           0 :                     $$ = (Node *) n;
    9723             :                 }
    9724             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
    9725             :                 {
    9726           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9727             : 
    9728           0 :                     n->renameType = OBJECT_MATVIEW;
    9729           0 :                     n->relation = $6;
    9730           0 :                     n->subname = NULL;
    9731           0 :                     n->newname = $9;
    9732           0 :                     n->missing_ok = true;
    9733           0 :                     $$ = (Node *) n;
    9734             :                 }
    9735             :             | ALTER INDEX qualified_name RENAME TO name
    9736             :                 {
    9737         192 :                     RenameStmt *n = makeNode(RenameStmt);
    9738             : 
    9739         192 :                     n->renameType = OBJECT_INDEX;
    9740         192 :                     n->relation = $3;
    9741         192 :                     n->subname = NULL;
    9742         192 :                     n->newname = $6;
    9743         192 :                     n->missing_ok = false;
    9744         192 :                     $$ = (Node *) n;
    9745             :                 }
    9746             :             | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
    9747             :                 {
    9748          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9749             : 
    9750          12 :                     n->renameType = OBJECT_INDEX;
    9751          12 :                     n->relation = $5;
    9752          12 :                     n->subname = NULL;
    9753          12 :                     n->newname = $8;
    9754          12 :                     n->missing_ok = true;
    9755          12 :                     $$ = (Node *) n;
    9756             :                 }
    9757             :             | ALTER FOREIGN TABLE relation_expr RENAME TO name
    9758             :                 {
    9759           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9760             : 
    9761           6 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9762           6 :                     n->relation = $4;
    9763           6 :                     n->subname = NULL;
    9764           6 :                     n->newname = $7;
    9765           6 :                     n->missing_ok = false;
    9766           6 :                     $$ = (Node *) n;
    9767             :                 }
    9768             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
    9769             :                 {
    9770           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9771             : 
    9772           6 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9773           6 :                     n->relation = $6;
    9774           6 :                     n->subname = NULL;
    9775           6 :                     n->newname = $9;
    9776           6 :                     n->missing_ok = true;
    9777           6 :                     $$ = (Node *) n;
    9778             :                 }
    9779             :             | ALTER TABLE relation_expr RENAME opt_column name TO name
    9780             :                 {
    9781         238 :                     RenameStmt *n = makeNode(RenameStmt);
    9782             : 
    9783         238 :                     n->renameType = OBJECT_COLUMN;
    9784         238 :                     n->relationType = OBJECT_TABLE;
    9785         238 :                     n->relation = $3;
    9786         238 :                     n->subname = $6;
    9787         238 :                     n->newname = $8;
    9788         238 :                     n->missing_ok = false;
    9789         238 :                     $$ = (Node *) n;
    9790             :                 }
    9791             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9792             :                 {
    9793          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9794             : 
    9795          24 :                     n->renameType = OBJECT_COLUMN;
    9796          24 :                     n->relationType = OBJECT_TABLE;
    9797          24 :                     n->relation = $5;
    9798          24 :                     n->subname = $8;
    9799          24 :                     n->newname = $10;
    9800          24 :                     n->missing_ok = true;
    9801          24 :                     $$ = (Node *) n;
    9802             :                 }
    9803             :             | ALTER VIEW qualified_name RENAME opt_column name TO name
    9804             :                 {
    9805          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9806             : 
    9807          18 :                     n->renameType = OBJECT_COLUMN;
    9808          18 :                     n->relationType = OBJECT_VIEW;
    9809          18 :                     n->relation = $3;
    9810          18 :                     n->subname = $6;
    9811          18 :                     n->newname = $8;
    9812          18 :                     n->missing_ok = false;
    9813          18 :                     $$ = (Node *) n;
    9814             :                 }
    9815             :             | ALTER VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    9816             :                 {
    9817           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9818             : 
    9819           0 :                     n->renameType = OBJECT_COLUMN;
    9820           0 :                     n->relationType = OBJECT_VIEW;
    9821           0 :                     n->relation = $5;
    9822           0 :                     n->subname = $8;
    9823           0 :                     n->newname = $10;
    9824           0 :                     n->missing_ok = true;
    9825           0 :                     $$ = (Node *) n;
    9826             :                 }
    9827             :             | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
    9828             :                 {
    9829           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9830             : 
    9831           0 :                     n->renameType = OBJECT_COLUMN;
    9832           0 :                     n->relationType = OBJECT_MATVIEW;
    9833           0 :                     n->relation = $4;
    9834           0 :                     n->subname = $7;
    9835           0 :                     n->newname = $9;
    9836           0 :                     n->missing_ok = false;
    9837           0 :                     $$ = (Node *) n;
    9838             :                 }
    9839             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    9840             :                 {
    9841           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9842             : 
    9843           0 :                     n->renameType = OBJECT_COLUMN;
    9844           0 :                     n->relationType = OBJECT_MATVIEW;
    9845           0 :                     n->relation = $6;
    9846           0 :                     n->subname = $9;
    9847           0 :                     n->newname = $11;
    9848           0 :                     n->missing_ok = true;
    9849           0 :                     $$ = (Node *) n;
    9850             :                 }
    9851             :             | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
    9852             :                 {
    9853          72 :                     RenameStmt *n = makeNode(RenameStmt);
    9854             : 
    9855          72 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9856          72 :                     n->relation = $3;
    9857          72 :                     n->subname = $6;
    9858          72 :                     n->newname = $8;
    9859          72 :                     n->missing_ok = false;
    9860          72 :                     $$ = (Node *) n;
    9861             :                 }
    9862             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
    9863             :                 {
    9864           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9865             : 
    9866           6 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9867           6 :                     n->relation = $5;
    9868           6 :                     n->subname = $8;
    9869           6 :                     n->newname = $10;
    9870           6 :                     n->missing_ok = true;
    9871           6 :                     $$ = (Node *) n;
    9872             :                 }
    9873             :             | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
    9874             :                 {
    9875           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9876             : 
    9877           6 :                     n->renameType = OBJECT_COLUMN;
    9878           6 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    9879           6 :                     n->relation = $4;
    9880           6 :                     n->subname = $7;
    9881           6 :                     n->newname = $9;
    9882           6 :                     n->missing_ok = false;
    9883           6 :                     $$ = (Node *) n;
    9884             :                 }
    9885             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9886             :                 {
    9887           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9888             : 
    9889           6 :                     n->renameType = OBJECT_COLUMN;
    9890           6 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    9891           6 :                     n->relation = $6;
    9892           6 :                     n->subname = $9;
    9893           6 :                     n->newname = $11;
    9894           6 :                     n->missing_ok = true;
    9895           6 :                     $$ = (Node *) n;
    9896             :                 }
    9897             :             | ALTER RULE name ON qualified_name RENAME TO name
    9898             :                 {
    9899          34 :                     RenameStmt *n = makeNode(RenameStmt);
    9900             : 
    9901          34 :                     n->renameType = OBJECT_RULE;
    9902          34 :                     n->relation = $5;
    9903          34 :                     n->subname = $3;
    9904          34 :                     n->newname = $8;
    9905          34 :                     n->missing_ok = false;
    9906          34 :                     $$ = (Node *) n;
    9907             :                 }
    9908             :             | ALTER TRIGGER name ON qualified_name RENAME TO name
    9909             :                 {
    9910          40 :                     RenameStmt *n = makeNode(RenameStmt);
    9911             : 
    9912          40 :                     n->renameType = OBJECT_TRIGGER;
    9913          40 :                     n->relation = $5;
    9914          40 :                     n->subname = $3;
    9915          40 :                     n->newname = $8;
    9916          40 :                     n->missing_ok = false;
    9917          40 :                     $$ = (Node *) n;
    9918             :                 }
    9919             :             | ALTER EVENT TRIGGER name RENAME TO name
    9920             :                 {
    9921          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9922             : 
    9923          12 :                     n->renameType = OBJECT_EVENT_TRIGGER;
    9924          12 :                     n->object = (Node *) makeString($4);
    9925          12 :                     n->newname = $7;
    9926          12 :                     $$ = (Node *) n;
    9927             :                 }
    9928             :             | ALTER ROLE RoleId RENAME TO RoleId
    9929             :                 {
    9930          30 :                     RenameStmt *n = makeNode(RenameStmt);
    9931             : 
    9932          30 :                     n->renameType = OBJECT_ROLE;
    9933          30 :                     n->subname = $3;
    9934          30 :                     n->newname = $6;
    9935          30 :                     n->missing_ok = false;
    9936          30 :                     $$ = (Node *) n;
    9937             :                 }
    9938             :             | ALTER USER RoleId RENAME TO RoleId
    9939             :                 {
    9940           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9941             : 
    9942           0 :                     n->renameType = OBJECT_ROLE;
    9943           0 :                     n->subname = $3;
    9944           0 :                     n->newname = $6;
    9945           0 :                     n->missing_ok = false;
    9946           0 :                     $$ = (Node *) n;
    9947             :                 }
    9948             :             | ALTER TABLESPACE name RENAME TO name
    9949             :                 {
    9950           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9951             : 
    9952           6 :                     n->renameType = OBJECT_TABLESPACE;
    9953           6 :                     n->subname = $3;
    9954           6 :                     n->newname = $6;
    9955           6 :                     n->missing_ok = false;
    9956           6 :                     $$ = (Node *) n;
    9957             :                 }
    9958             :             | ALTER STATISTICS any_name RENAME TO name
    9959             :                 {
    9960          30 :                     RenameStmt *n = makeNode(RenameStmt);
    9961             : 
    9962          30 :                     n->renameType = OBJECT_STATISTIC_EXT;
    9963          30 :                     n->object = (Node *) $3;
    9964          30 :                     n->newname = $6;
    9965          30 :                     n->missing_ok = false;
    9966          30 :                     $$ = (Node *) n;
    9967             :                 }
    9968             :             | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
    9969             :                 {
    9970          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9971             : 
    9972          12 :                     n->renameType = OBJECT_TSPARSER;
    9973          12 :                     n->object = (Node *) $5;
    9974          12 :                     n->newname = $8;
    9975          12 :                     n->missing_ok = false;
    9976          12 :                     $$ = (Node *) n;
    9977             :                 }
    9978             :             | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
    9979             :                 {
    9980          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9981             : 
    9982          24 :                     n->renameType = OBJECT_TSDICTIONARY;
    9983          24 :                     n->object = (Node *) $5;
    9984          24 :                     n->newname = $8;
    9985          24 :                     n->missing_ok = false;
    9986          24 :                     $$ = (Node *) n;
    9987             :                 }
    9988             :             | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
    9989             :                 {
    9990          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9991             : 
    9992          12 :                     n->renameType = OBJECT_TSTEMPLATE;
    9993          12 :                     n->object = (Node *) $5;
    9994          12 :                     n->newname = $8;
    9995          12 :                     n->missing_ok = false;
    9996          12 :                     $$ = (Node *) n;
    9997             :                 }
    9998             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
    9999             :                 {
   10000          24 :                     RenameStmt *n = makeNode(RenameStmt);
   10001             : 
   10002          24 :                     n->renameType = OBJECT_TSCONFIGURATION;
   10003          24 :                     n->object = (Node *) $5;
   10004          24 :                     n->newname = $8;
   10005          24 :                     n->missing_ok = false;
   10006          24 :                     $$ = (Node *) n;
   10007             :                 }
   10008             :             | ALTER TYPE_P any_name RENAME TO name
   10009             :                 {
   10010          26 :                     RenameStmt *n = makeNode(RenameStmt);
   10011             : 
   10012          26 :                     n->renameType = OBJECT_TYPE;
   10013          26 :                     n->object = (Node *) $3;
   10014          26 :                     n->newname = $6;
   10015          26 :                     n->missing_ok = false;
   10016          26 :                     $$ = (Node *) n;
   10017             :                 }
   10018             :             | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
   10019             :                 {
   10020          24 :                     RenameStmt *n = makeNode(RenameStmt);
   10021             : 
   10022          24 :                     n->renameType = OBJECT_ATTRIBUTE;
   10023          24 :                     n->relationType = OBJECT_TYPE;
   10024          24 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
   10025          24 :                     n->subname = $6;
   10026          24 :                     n->newname = $8;
   10027          24 :                     n->behavior = $9;
   10028          24 :                     n->missing_ok = false;
   10029          24 :                     $$ = (Node *) n;
   10030             :                 }
   10031             :         ;
   10032             : 
   10033             : opt_column: COLUMN
   10034             :             | /*EMPTY*/
   10035             :         ;
   10036             : 
   10037         184 : opt_set_data: SET DATA_P                            { $$ = 1; }
   10038         914 :             | /*EMPTY*/                             { $$ = 0; }
   10039             :         ;
   10040             : 
   10041             : /*****************************************************************************
   10042             :  *
   10043             :  * ALTER THING name DEPENDS ON EXTENSION name
   10044             :  *
   10045             :  *****************************************************************************/
   10046             : 
   10047             : AlterObjectDependsStmt:
   10048             :             ALTER FUNCTION function_with_argtypes opt_no DEPENDS ON EXTENSION name
   10049             :                 {
   10050          12 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10051             : 
   10052          12 :                     n->objectType = OBJECT_FUNCTION;
   10053          12 :                     n->object = (Node *) $3;
   10054          12 :                     n->extname = makeString($8);
   10055          12 :                     n->remove = $4;
   10056          12 :                     $$ = (Node *) n;
   10057             :                 }
   10058             :             | ALTER PROCEDURE function_with_argtypes opt_no DEPENDS ON EXTENSION name
   10059             :                 {
   10060           0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10061             : 
   10062           0 :                     n->objectType = OBJECT_PROCEDURE;
   10063           0 :                     n->object = (Node *) $3;
   10064           0 :                     n->extname = makeString($8);
   10065           0 :                     n->remove = $4;
   10066           0 :                     $$ = (Node *) n;
   10067             :                 }
   10068             :             | ALTER ROUTINE function_with_argtypes opt_no DEPENDS ON EXTENSION name
   10069             :                 {
   10070           0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10071             : 
   10072           0 :                     n->objectType = OBJECT_ROUTINE;
   10073           0 :                     n->object = (Node *) $3;
   10074           0 :                     n->extname = makeString($8);
   10075           0 :                     n->remove = $4;
   10076           0 :                     $$ = (Node *) n;
   10077             :                 }
   10078             :             | ALTER TRIGGER name ON qualified_name opt_no DEPENDS ON EXTENSION name
   10079             :                 {
   10080          10 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10081             : 
   10082          10 :                     n->objectType = OBJECT_TRIGGER;
   10083          10 :                     n->relation = $5;
   10084          10 :                     n->object = (Node *) list_make1(makeString($3));
   10085          10 :                     n->extname = makeString($10);
   10086          10 :                     n->remove = $6;
   10087          10 :                     $$ = (Node *) n;
   10088             :                 }
   10089             :             | ALTER MATERIALIZED VIEW qualified_name opt_no DEPENDS ON EXTENSION name
   10090             :                 {
   10091          10 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10092             : 
   10093          10 :                     n->objectType = OBJECT_MATVIEW;
   10094          10 :                     n->relation = $4;
   10095          10 :                     n->extname = makeString($9);
   10096          10 :                     n->remove = $5;
   10097          10 :                     $$ = (Node *) n;
   10098             :                 }
   10099             :             | ALTER INDEX qualified_name opt_no DEPENDS ON EXTENSION name
   10100             :                 {
   10101          14 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10102             : 
   10103          14 :                     n->objectType = OBJECT_INDEX;
   10104          14 :                     n->relation = $3;
   10105          14 :                     n->extname = makeString($8);
   10106          14 :                     n->remove = $4;
   10107          14 :                     $$ = (Node *) n;
   10108             :                 }
   10109             :         ;
   10110             : 
   10111           8 : opt_no:     NO              { $$ = true; }
   10112          38 :             | /* EMPTY */   { $$ = false;   }
   10113             :         ;
   10114             : 
   10115             : /*****************************************************************************
   10116             :  *
   10117             :  * ALTER THING name SET SCHEMA name
   10118             :  *
   10119             :  *****************************************************************************/
   10120             : 
   10121             : AlterObjectSchemaStmt:
   10122             :             ALTER AGGREGATE aggregate_with_argtypes SET SCHEMA name
   10123             :                 {
   10124          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10125             : 
   10126          24 :                     n->objectType = OBJECT_AGGREGATE;
   10127          24 :                     n->object = (Node *) $3;
   10128          24 :                     n->newschema = $6;
   10129          24 :                     n->missing_ok = false;
   10130          24 :                     $$ = (Node *) n;
   10131             :                 }
   10132             :             | ALTER COLLATION any_name SET SCHEMA name
   10133             :                 {
   10134           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10135             : 
   10136           6 :                     n->objectType = OBJECT_COLLATION;
   10137           6 :                     n->object = (Node *) $3;
   10138           6 :                     n->newschema = $6;
   10139           6 :                     n->missing_ok = false;
   10140           6 :                     $$ = (Node *) n;
   10141             :                 }
   10142             :             | ALTER CONVERSION_P any_name SET SCHEMA name
   10143             :                 {
   10144          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10145             : 
   10146          24 :                     n->objectType = OBJECT_CONVERSION;
   10147          24 :                     n->object = (Node *) $3;
   10148          24 :                     n->newschema = $6;
   10149          24 :                     n->missing_ok = false;
   10150          24 :                     $$ = (Node *) n;
   10151             :                 }
   10152             :             | ALTER DOMAIN_P any_name SET SCHEMA name
   10153             :                 {
   10154           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10155             : 
   10156           6 :                     n->objectType = OBJECT_DOMAIN;
   10157           6 :                     n->object = (Node *) $3;
   10158           6 :                     n->newschema = $6;
   10159           6 :                     n->missing_ok = false;
   10160           6 :                     $$ = (Node *) n;
   10161             :                 }
   10162             :             | ALTER EXTENSION name SET SCHEMA name
   10163             :                 {
   10164          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10165             : 
   10166          12 :                     n->objectType = OBJECT_EXTENSION;
   10167          12 :                     n->object = (Node *) makeString($3);
   10168          12 :                     n->newschema = $6;
   10169          12 :                     n->missing_ok = false;
   10170          12 :                     $$ = (Node *) n;
   10171             :                 }
   10172             :             | ALTER FUNCTION function_with_argtypes SET SCHEMA name
   10173             :                 {
   10174          42 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10175             : 
   10176          42 :                     n->objectType = OBJECT_FUNCTION;
   10177          42 :                     n->object = (Node *) $3;
   10178          42 :                     n->newschema = $6;
   10179          42 :                     n->missing_ok = false;
   10180          42 :                     $$ = (Node *) n;
   10181             :                 }
   10182             :             | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
   10183             :                 {
   10184          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10185             : 
   10186          18 :                     n->objectType = OBJECT_OPERATOR;
   10187          18 :                     n->object = (Node *) $3;
   10188          18 :                     n->newschema = $6;
   10189          18 :                     n->missing_ok = false;
   10190          18 :                     $$ = (Node *) n;
   10191             :                 }
   10192             :             | ALTER OPERATOR CLASS any_name USING name SET SCHEMA name
   10193             :                 {
   10194          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10195             : 
   10196          24 :                     n->objectType = OBJECT_OPCLASS;
   10197          24 :                     n->object = (Node *) lcons(makeString($6), $4);
   10198          24 :                     n->newschema = $9;
   10199          24 :                     n->missing_ok = false;
   10200          24 :                     $$ = (Node *) n;
   10201             :                 }
   10202             :             | ALTER OPERATOR FAMILY any_name USING name SET SCHEMA name
   10203             :                 {
   10204          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10205             : 
   10206          24 :                     n->objectType = OBJECT_OPFAMILY;
   10207          24 :                     n->object = (Node *) lcons(makeString($6), $4);
   10208          24 :                     n->newschema = $9;
   10209          24 :                     n->missing_ok = false;
   10210          24 :                     $$ = (Node *) n;
   10211             :                 }
   10212             :             | ALTER PROCEDURE function_with_argtypes SET SCHEMA name
   10213             :                 {
   10214           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10215             : 
   10216           0 :                     n->objectType = OBJECT_PROCEDURE;
   10217           0 :                     n->object = (Node *) $3;
   10218           0 :                     n->newschema = $6;
   10219           0 :                     n->missing_ok = false;
   10220           0 :                     $$ = (Node *) n;
   10221             :                 }
   10222             :             | ALTER ROUTINE function_with_argtypes SET SCHEMA name
   10223             :                 {
   10224           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10225             : 
   10226           0 :                     n->objectType = OBJECT_ROUTINE;
   10227           0 :                     n->object = (Node *) $3;
   10228           0 :                     n->newschema = $6;
   10229           0 :                     n->missing_ok = false;
   10230           0 :                     $$ = (Node *) n;
   10231             :                 }
   10232             :             | ALTER TABLE relation_expr SET SCHEMA name
   10233             :                 {
   10234          66 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10235             : 
   10236          66 :                     n->objectType = OBJECT_TABLE;
   10237          66 :                     n->relation = $3;
   10238          66 :                     n->newschema = $6;
   10239          66 :                     n->missing_ok = false;
   10240          66 :                     $$ = (Node *) n;
   10241             :                 }
   10242             :             | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10243             :                 {
   10244          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10245             : 
   10246          12 :                     n->objectType = OBJECT_TABLE;
   10247          12 :                     n->relation = $5;
   10248          12 :                     n->newschema = $8;
   10249          12 :                     n->missing_ok = true;
   10250          12 :                     $$ = (Node *) n;
   10251             :                 }
   10252             :             | ALTER STATISTICS any_name SET SCHEMA name
   10253             :                 {
   10254          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10255             : 
   10256          18 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10257          18 :                     n->object = (Node *) $3;
   10258          18 :                     n->newschema = $6;
   10259          18 :                     n->missing_ok = false;
   10260          18 :                     $$ = (Node *) n;
   10261             :                 }
   10262             :             | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
   10263             :                 {
   10264          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10265             : 
   10266          18 :                     n->objectType = OBJECT_TSPARSER;
   10267          18 :                     n->object = (Node *) $5;
   10268          18 :                     n->newschema = $8;
   10269          18 :                     n->missing_ok = false;
   10270          18 :                     $$ = (Node *) n;
   10271             :                 }
   10272             :             | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
   10273             :                 {
   10274          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10275             : 
   10276          24 :                     n->objectType = OBJECT_TSDICTIONARY;
   10277          24 :                     n->object = (Node *) $5;
   10278          24 :                     n->newschema = $8;
   10279          24 :                     n->missing_ok = false;
   10280          24 :                     $$ = (Node *) n;
   10281             :                 }
   10282             :             | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
   10283             :                 {
   10284          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10285             : 
   10286          18 :                     n->objectType = OBJECT_TSTEMPLATE;
   10287          18 :                     n->object = (Node *) $5;
   10288          18 :                     n->newschema = $8;
   10289          18 :                     n->missing_ok = false;
   10290          18 :                     $$ = (Node *) n;
   10291             :                 }
   10292             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
   10293             :                 {
   10294          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10295             : 
   10296          24 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10297          24 :                     n->object = (Node *) $5;
   10298          24 :                     n->newschema = $8;
   10299          24 :                     n->missing_ok = false;
   10300          24 :                     $$ = (Node *) n;
   10301             :                 }
   10302             :             | ALTER SEQUENCE qualified_name SET SCHEMA name
   10303             :                 {
   10304           8 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10305             : 
   10306           8 :                     n->objectType = OBJECT_SEQUENCE;
   10307           8 :                     n->relation = $3;
   10308           8 :                     n->newschema = $6;
   10309           8 :                     n->missing_ok = false;
   10310           8 :                     $$ = (Node *) n;
   10311             :                 }
   10312             :             | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
   10313             :                 {
   10314           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10315             : 
   10316           0 :                     n->objectType = OBJECT_SEQUENCE;
   10317           0 :                     n->relation = $5;
   10318           0 :                     n->newschema = $8;
   10319           0 :                     n->missing_ok = true;
   10320           0 :                     $$ = (Node *) n;
   10321             :                 }
   10322             :             | ALTER VIEW qualified_name SET SCHEMA name
   10323             :                 {
   10324           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10325             : 
   10326           0 :                     n->objectType = OBJECT_VIEW;
   10327           0 :                     n->relation = $3;
   10328           0 :                     n->newschema = $6;
   10329           0 :                     n->missing_ok = false;
   10330           0 :                     $$ = (Node *) n;
   10331             :                 }
   10332             :             | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
   10333             :                 {
   10334           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10335             : 
   10336           0 :                     n->objectType = OBJECT_VIEW;
   10337           0 :                     n->relation = $5;
   10338           0 :                     n->newschema = $8;
   10339           0 :                     n->missing_ok = true;
   10340           0 :                     $$ = (Node *) n;
   10341             :                 }
   10342             :             | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
   10343             :                 {
   10344           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10345             : 
   10346           6 :                     n->objectType = OBJECT_MATVIEW;
   10347           6 :                     n->relation = $4;
   10348           6 :                     n->newschema = $7;
   10349           6 :                     n->missing_ok = false;
   10350           6 :                     $$ = (Node *) n;
   10351             :                 }
   10352             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
   10353             :                 {
   10354           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10355             : 
   10356           0 :                     n->objectType = OBJECT_MATVIEW;
   10357           0 :                     n->relation = $6;
   10358           0 :                     n->newschema = $9;
   10359           0 :                     n->missing_ok = true;
   10360           0 :                     $$ = (Node *) n;
   10361             :                 }
   10362             :             | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
   10363             :                 {
   10364           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10365             : 
   10366           6 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10367           6 :                     n->relation = $4;
   10368           6 :                     n->newschema = $7;
   10369           6 :                     n->missing_ok = false;
   10370           6 :                     $$ = (Node *) n;
   10371             :                 }
   10372             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10373             :                 {
   10374           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10375             : 
   10376           6 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10377           6 :                     n->relation = $6;
   10378           6 :                     n->newschema = $9;
   10379           6 :                     n->missing_ok = true;
   10380           6 :                     $$ = (Node *) n;
   10381             :                 }
   10382             :             | ALTER TYPE_P any_name SET SCHEMA name
   10383             :                 {
   10384          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10385             : 
   10386          12 :                     n->objectType = OBJECT_TYPE;
   10387          12 :                     n->object = (Node *) $3;
   10388          12 :                     n->newschema = $6;
   10389          12 :                     n->missing_ok = false;
   10390          12 :                     $$ = (Node *) n;
   10391             :                 }
   10392             :         ;
   10393             : 
   10394             : /*****************************************************************************
   10395             :  *
   10396             :  * ALTER OPERATOR name SET define
   10397             :  *
   10398             :  *****************************************************************************/
   10399             : 
   10400             : AlterOperatorStmt:
   10401             :             ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
   10402             :                 {
   10403         608 :                     AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
   10404             : 
   10405         608 :                     n->opername = $3;
   10406         608 :                     n->options = $6;
   10407         608 :                     $$ = (Node *) n;
   10408             :                 }
   10409             :         ;
   10410             : 
   10411         668 : operator_def_list:  operator_def_elem                               { $$ = list_make1($1); }
   10412         506 :             | operator_def_list ',' operator_def_elem               { $$ = lappend($1, $3); }
   10413             :         ;
   10414             : 
   10415             : operator_def_elem: ColLabel '=' NONE
   10416          30 :                         { $$ = makeDefElem($1, NULL, @1); }
   10417             :                    | ColLabel '=' operator_def_arg
   10418        1110 :                         { $$ = makeDefElem($1, (Node *) $3, @1); }
   10419             :                    | ColLabel
   10420          34 :                         { $$ = makeDefElem($1, NULL, @1); }
   10421             :         ;
   10422             : 
   10423             : /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
   10424             : operator_def_arg:
   10425        1032 :             func_type                       { $$ = (Node *) $1; }
   10426          24 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
   10427          54 :             | qual_all_Op                   { $$ = (Node *) $1; }
   10428           0 :             | NumericOnly                   { $$ = (Node *) $1; }
   10429           0 :             | Sconst                        { $$ = (Node *) makeString($1); }
   10430             :         ;
   10431             : 
   10432             : /*****************************************************************************
   10433             :  *
   10434             :  * ALTER TYPE name SET define
   10435             :  *
   10436             :  * We repurpose ALTER OPERATOR's version of "definition" here
   10437             :  *
   10438             :  *****************************************************************************/
   10439             : 
   10440             : AlterTypeStmt:
   10441             :             ALTER TYPE_P any_name SET '(' operator_def_list ')'
   10442             :                 {
   10443          60 :                     AlterTypeStmt *n = makeNode(AlterTypeStmt);
   10444             : 
   10445          60 :                     n->typeName = $3;
   10446          60 :                     n->options = $6;
   10447          60 :                     $$ = (Node *) n;
   10448             :                 }
   10449             :         ;
   10450             : 
   10451             : /*****************************************************************************
   10452             :  *
   10453             :  * ALTER THING name OWNER TO newname
   10454             :  *
   10455             :  *****************************************************************************/
   10456             : 
   10457             : AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec
   10458             :                 {
   10459         236 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10460             : 
   10461         236 :                     n->objectType = OBJECT_AGGREGATE;
   10462         236 :                     n->object = (Node *) $3;
   10463         236 :                     n->newowner = $6;
   10464         236 :                     $$ = (Node *) n;
   10465             :                 }
   10466             :             | ALTER COLLATION any_name OWNER TO RoleSpec
   10467             :                 {
   10468          24 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10469             : 
   10470          24 :                     n->objectType = OBJECT_COLLATION;
   10471          24 :                     n->object = (Node *) $3;
   10472          24 :                     n->newowner = $6;
   10473          24 :                     $$ = (Node *) n;
   10474             :                 }
   10475             :             | ALTER CONVERSION_P any_name OWNER TO RoleSpec
   10476             :                 {
   10477          24 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10478             : 
   10479          24 :                     n->objectType = OBJECT_CONVERSION;
   10480          24 :                     n->object = (Node *) $3;
   10481          24 :                     n->newowner = $6;
   10482          24 :                     $$ = (Node *) n;
   10483             :                 }
   10484             :             | ALTER DATABASE name OWNER TO RoleSpec
   10485             :                 {
   10486          80 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10487             : 
   10488          80 :                     n->objectType = OBJECT_DATABASE;
   10489          80 :                     n->object = (Node *) makeString($3);
   10490          80 :                     n->newowner = $6;
   10491          80 :                     $$ = (Node *) n;
   10492             :                 }
   10493             :             | ALTER DOMAIN_P any_name OWNER TO RoleSpec
   10494             :                 {
   10495          96 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10496             : 
   10497          96 :                     n->objectType = OBJECT_DOMAIN;
   10498          96 :                     n->object = (Node *) $3;
   10499          96 :                     n->newowner = $6;
   10500          96 :                     $$ = (Node *) n;
   10501             :                 }
   10502             :             | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
   10503             :                 {
   10504        1114 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10505             : 
   10506        1114 :                     n->objectType = OBJECT_FUNCTION;
   10507        1114 :                     n->object = (Node *) $3;
   10508        1114 :                     n->newowner = $6;
   10509        1114 :                     $$ = (Node *) n;
   10510             :                 }
   10511             :             | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
   10512             :                 {
   10513         144 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10514             : 
   10515         144 :                     n->objectType = OBJECT_LANGUAGE;
   10516         144 :                     n->object = (Node *) makeString($4);
   10517         144 :                     n->newowner = $7;
   10518         144 :                     $$ = (Node *) n;
   10519             :                 }
   10520             :             | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
   10521             :                 {
   10522          12 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10523             : 
   10524          12 :                     n->objectType = OBJECT_LARGEOBJECT;
   10525          12 :                     n->object = (Node *) $4;
   10526          12 :                     n->newowner = $7;
   10527          12 :                     $$ = (Node *) n;
   10528             :                 }
   10529             :             | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
   10530             :                 {
   10531          68 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10532             : 
   10533          68 :                     n->objectType = OBJECT_OPERATOR;
   10534          68 :                     n->object = (Node *) $3;
   10535          68 :                     n->newowner = $6;
   10536          68 :                     $$ = (Node *) n;
   10537             :                 }
   10538             :             | ALTER OPERATOR CLASS any_name USING name OWNER TO RoleSpec
   10539             :                 {
   10540          60 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10541             : 
   10542          60 :                     n->objectType = OBJECT_OPCLASS;
   10543          60 :                     n->object = (Node *) lcons(makeString($6), $4);
   10544          60 :                     n->newowner = $9;
   10545          60 :                     $$ = (Node *) n;
   10546             :                 }
   10547             :             | ALTER OPERATOR FAMILY any_name USING name OWNER TO RoleSpec
   10548             :                 {
   10549          76 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10550             : 
   10551          76 :                     n->objectType = OBJECT_OPFAMILY;
   10552          76 :                     n->object = (Node *) lcons(makeString($6), $4);
   10553          76 :                     n->newowner = $9;
   10554          76 :                     $$ = (Node *) n;
   10555             :                 }
   10556             :             | ALTER PROCEDURE function_with_argtypes OWNER TO RoleSpec
   10557             :                 {
   10558          48 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10559             : 
   10560          48 :                     n->objectType = OBJECT_PROCEDURE;
   10561          48 :                     n->object = (Node *) $3;
   10562          48 :                     n->newowner = $6;
   10563          48 :                     $$ = (Node *) n;
   10564             :                 }
   10565             :             | ALTER ROUTINE function_with_argtypes OWNER TO RoleSpec
   10566             :                 {
   10567           0 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10568             : 
   10569           0 :                     n->objectType = OBJECT_ROUTINE;
   10570           0 :                     n->object = (Node *) $3;
   10571           0 :                     n->newowner = $6;
   10572           0 :                     $$ = (Node *) n;
   10573             :                 }
   10574             :             | ALTER SCHEMA name OWNER TO RoleSpec
   10575             :                 {
   10576          86 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10577             : 
   10578          86 :                     n->objectType = OBJECT_SCHEMA;
   10579          86 :                     n->object = (Node *) makeString($3);
   10580          86 :                     n->newowner = $6;
   10581          86 :                     $$ = (Node *) n;
   10582             :                 }
   10583             :             | ALTER TYPE_P any_name OWNER TO RoleSpec
   10584             :                 {
   10585         152 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10586             : 
   10587         152 :                     n->objectType = OBJECT_TYPE;
   10588         152 :                     n->object = (Node *) $3;
   10589         152 :                     n->newowner = $6;
   10590         152 :                     $$ = (Node *) n;
   10591             :                 }
   10592             :             | ALTER TABLESPACE name OWNER TO RoleSpec
   10593             :                 {
   10594           6 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10595             : 
   10596           6 :                     n->objectType = OBJECT_TABLESPACE;
   10597           6 :                     n->object = (Node *) makeString($3);
   10598           6 :                     n->newowner = $6;
   10599           6 :                     $$ = (Node *) n;
   10600             :                 }
   10601             :             | ALTER STATISTICS any_name OWNER TO RoleSpec
   10602             :                 {
   10603          40 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10604             : 
   10605          40 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10606          40 :                     n->object = (Node *) $3;
   10607          40 :                     n->newowner = $6;
   10608          40 :                     $$ = (Node *) n;
   10609             :                 }
   10610             :             | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
   10611             :                 {
   10612          60 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10613             : 
   10614          60 :                     n->objectType = OBJECT_TSDICTIONARY;
   10615          60 :                     n->object = (Node *) $5;
   10616          60 :                     n->newowner = $8;
   10617          60 :                     $$ = (Node *) n;
   10618             :                 }
   10619             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
   10620             :                 {
   10621          40 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10622             : 
   10623          40 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10624          40 :                     n->object = (Node *) $5;
   10625          40 :                     n->newowner = $8;
   10626          40 :                     $$ = (Node *) n;
   10627             :                 }
   10628             :             | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
   10629             :                 {
   10630          22 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10631             : 
   10632          22 :                     n->objectType = OBJECT_FDW;
   10633          22 :                     n->object = (Node *) makeString($5);
   10634          22 :                     n->newowner = $8;
   10635          22 :                     $$ = (Node *) n;
   10636             :                 }
   10637             :             | ALTER SERVER name OWNER TO RoleSpec
   10638             :                 {
   10639          70 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10640             : 
   10641          70 :                     n->objectType = OBJECT_FOREIGN_SERVER;
   10642          70 :                     n->object = (Node *) makeString($3);
   10643          70 :                     n->newowner = $6;
   10644          70 :                     $$ = (Node *) n;
   10645             :                 }
   10646             :             | ALTER EVENT TRIGGER name OWNER TO RoleSpec
   10647             :                 {
   10648          16 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10649             : 
   10650          16 :                     n->objectType = OBJECT_EVENT_TRIGGER;
   10651          16 :                     n->object = (Node *) makeString($4);
   10652          16 :                     n->newowner = $7;
   10653          16 :                     $$ = (Node *) n;
   10654             :                 }
   10655             :             | ALTER PUBLICATION name OWNER TO RoleSpec
   10656             :                 {
   10657          26 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10658             : 
   10659          26 :                     n->objectType = OBJECT_PUBLICATION;
   10660          26 :                     n->object = (Node *) makeString($3);
   10661          26 :                     n->newowner = $6;
   10662          26 :                     $$ = (Node *) n;
   10663             :                 }
   10664             :             | ALTER SUBSCRIPTION name OWNER TO RoleSpec
   10665             :                 {
   10666          18 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10667             : 
   10668          18 :                     n->objectType = OBJECT_SUBSCRIPTION;
   10669          18 :                     n->object = (Node *) makeString($3);
   10670          18 :                     n->newowner = $6;
   10671          18 :                     $$ = (Node *) n;
   10672             :                 }
   10673             :         ;
   10674             : 
   10675             : 
   10676             : /*****************************************************************************
   10677             :  *
   10678             :  * CREATE PUBLICATION name [WITH options]
   10679             :  *
   10680             :  * CREATE PUBLICATION FOR ALL TABLES [WITH options]
   10681             :  *
   10682             :  * CREATE PUBLICATION FOR pub_obj [, ...] [WITH options]
   10683             :  *
   10684             :  * pub_obj is one of:
   10685             :  *
   10686             :  *      TABLE table [, ...]
   10687             :  *      TABLES IN SCHEMA schema [, ...]
   10688             :  *
   10689             :  *****************************************************************************/
   10690             : 
   10691             : CreatePublicationStmt:
   10692             :             CREATE PUBLICATION name opt_definition
   10693             :                 {
   10694         128 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10695             : 
   10696         128 :                     n->pubname = $3;
   10697         128 :                     n->options = $4;
   10698         128 :                     $$ = (Node *) n;
   10699             :                 }
   10700             :             | CREATE PUBLICATION name FOR ALL TABLES opt_definition
   10701             :                 {
   10702          94 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10703             : 
   10704          94 :                     n->pubname = $3;
   10705          94 :                     n->options = $7;
   10706          94 :                     n->for_all_tables = true;
   10707          94 :                     $$ = (Node *) n;
   10708             :                 }
   10709             :             | CREATE PUBLICATION name FOR pub_obj_list opt_definition
   10710             :                 {
   10711         624 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10712             : 
   10713         624 :                     n->pubname = $3;
   10714         624 :                     n->options = $6;
   10715         624 :                     n->pubobjects = (List *) $5;
   10716         624 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10717         594 :                     $$ = (Node *) n;
   10718             :                 }
   10719             :         ;
   10720             : 
   10721             : /*
   10722             :  * FOR TABLE and FOR TABLES IN SCHEMA specifications
   10723             :  *
   10724             :  * This rule parses publication objects with and without keyword prefixes.
   10725             :  *
   10726             :  * The actual type of the object without keyword prefix depends on the previous
   10727             :  * one with keyword prefix. It will be preprocessed in preprocess_pubobj_list().
   10728             :  *
   10729             :  * For the object without keyword prefix, we cannot just use relation_expr here,
   10730             :  * because some extended expressions in relation_expr cannot be used as a
   10731             :  * schemaname and we cannot differentiate it. So, we extract the rules from
   10732             :  * relation_expr here.
   10733             :  */
   10734             : PublicationObjSpec:
   10735             :             TABLE relation_expr opt_column_list OptWhereClause
   10736             :                 {
   10737        1278 :                     $$ = makeNode(PublicationObjSpec);
   10738        1278 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLE;
   10739        1278 :                     $$->pubtable = makeNode(PublicationTable);
   10740        1278 :                     $$->pubtable->relation = $2;
   10741        1278 :                     $$->pubtable->columns = $3;
   10742        1278 :                     $$->pubtable->whereClause = $4;
   10743             :                 }
   10744             :             | TABLES IN_P SCHEMA ColId
   10745             :                 {
   10746         332 :                     $$ = makeNode(PublicationObjSpec);
   10747         332 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   10748         332 :                     $$->name = $4;
   10749         332 :                     $$->location = @4;
   10750             :                 }
   10751             :             | TABLES IN_P SCHEMA CURRENT_SCHEMA
   10752             :                 {
   10753          18 :                     $$ = makeNode(PublicationObjSpec);
   10754          18 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   10755          18 :                     $$->location = @4;
   10756             :                 }
   10757             :             | ColId opt_column_list OptWhereClause
   10758             :                 {
   10759         130 :                     $$ = makeNode(PublicationObjSpec);
   10760         130 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10761             :                     /*
   10762             :                      * If either a row filter or column list is specified, create
   10763             :                      * a PublicationTable object.
   10764             :                      */
   10765         130 :                     if ($2 || $3)
   10766             :                     {
   10767             :                         /*
   10768             :                          * The OptWhereClause must be stored here but it is
   10769             :                          * valid only for tables. For non-table objects, an
   10770             :                          * error will be thrown later via
   10771             :                          * preprocess_pubobj_list().
   10772             :                          */
   10773          42 :                         $$->pubtable = makeNode(PublicationTable);
   10774          42 :                         $$->pubtable->relation = makeRangeVar(NULL, $1, @1);
   10775          42 :                         $$->pubtable->columns = $2;
   10776          42 :                         $$->pubtable->whereClause = $3;
   10777             :                     }
   10778             :                     else
   10779             :                     {
   10780          88 :                         $$->name = $1;
   10781             :                     }
   10782         130 :                     $$->location = @1;
   10783             :                 }
   10784             :             | ColId indirection opt_column_list OptWhereClause
   10785             :                 {
   10786          32 :                     $$ = makeNode(PublicationObjSpec);
   10787          32 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10788          32 :                     $$->pubtable = makeNode(PublicationTable);
   10789          32 :                     $$->pubtable->relation = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   10790          32 :                     $$->pubtable->columns = $3;
   10791          32 :                     $$->pubtable->whereClause = $4;
   10792          32 :                     $$->location = @1;
   10793             :                 }
   10794             :             /* grammar like tablename * , ONLY tablename, ONLY ( tablename ) */
   10795             :             | extended_relation_expr opt_column_list OptWhereClause
   10796             :                 {
   10797           6 :                     $$ = makeNode(PublicationObjSpec);
   10798           6 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10799           6 :                     $$->pubtable = makeNode(PublicationTable);
   10800           6 :                     $$->pubtable->relation = $1;
   10801           6 :                     $$->pubtable->columns = $2;
   10802           6 :                     $$->pubtable->whereClause = $3;
   10803             :                 }
   10804             :             | CURRENT_SCHEMA
   10805             :                 {
   10806          18 :                     $$ = makeNode(PublicationObjSpec);
   10807          18 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10808          18 :                     $$->location = @1;
   10809             :                 }
   10810             :                 ;
   10811             : 
   10812             : pub_obj_list:   PublicationObjSpec
   10813        1590 :                     { $$ = list_make1($1); }
   10814             :             | pub_obj_list ',' PublicationObjSpec
   10815         224 :                     { $$ = lappend($1, $3); }
   10816             :     ;
   10817             : 
   10818             : /*****************************************************************************
   10819             :  *
   10820             :  * ALTER PUBLICATION name SET ( options )
   10821             :  *
   10822             :  * ALTER PUBLICATION name ADD pub_obj [, ...]
   10823             :  *
   10824             :  * ALTER PUBLICATION name DROP pub_obj [, ...]
   10825             :  *
   10826             :  * ALTER PUBLICATION name SET pub_obj [, ...]
   10827             :  *
   10828             :  * pub_obj is one of:
   10829             :  *
   10830             :  *      TABLE table_name [, ...]
   10831             :  *      TABLES IN SCHEMA schema_name [, ...]
   10832             :  *
   10833             :  *****************************************************************************/
   10834             : 
   10835             : AlterPublicationStmt:
   10836             :             ALTER PUBLICATION name SET definition
   10837             :                 {
   10838         116 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10839             : 
   10840         116 :                     n->pubname = $3;
   10841         116 :                     n->options = $5;
   10842         116 :                     $$ = (Node *) n;
   10843             :                 }
   10844             :             | ALTER PUBLICATION name ADD_P pub_obj_list
   10845             :                 {
   10846         348 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10847             : 
   10848         348 :                     n->pubname = $3;
   10849         348 :                     n->pubobjects = $5;
   10850         348 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10851         342 :                     n->action = AP_AddObjects;
   10852         342 :                     $$ = (Node *) n;
   10853             :                 }
   10854             :             | ALTER PUBLICATION name SET pub_obj_list
   10855             :                 {
   10856         464 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10857             : 
   10858         464 :                     n->pubname = $3;
   10859         464 :                     n->pubobjects = $5;
   10860         464 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10861         464 :                     n->action = AP_SetObjects;
   10862         464 :                     $$ = (Node *) n;
   10863             :                 }
   10864             :             | ALTER PUBLICATION name DROP pub_obj_list
   10865             :                 {
   10866         154 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10867             : 
   10868         154 :                     n->pubname = $3;
   10869         154 :                     n->pubobjects = $5;
   10870         154 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10871         154 :                     n->action = AP_DropObjects;
   10872         154 :                     $$ = (Node *) n;
   10873             :                 }
   10874             :         ;
   10875             : 
   10876             : /*****************************************************************************
   10877             :  *
   10878             :  * CREATE SUBSCRIPTION name ...
   10879             :  *
   10880             :  *****************************************************************************/
   10881             : 
   10882             : CreateSubscriptionStmt:
   10883             :             CREATE SUBSCRIPTION name CONNECTION Sconst PUBLICATION name_list opt_definition
   10884             :                 {
   10885             :                     CreateSubscriptionStmt *n =
   10886         448 :                         makeNode(CreateSubscriptionStmt);
   10887         448 :                     n->subname = $3;
   10888         448 :                     n->conninfo = $5;
   10889         448 :                     n->publication = $7;
   10890         448 :                     n->options = $8;
   10891         448 :                     $$ = (Node *) n;
   10892             :                 }
   10893             :         ;
   10894             : 
   10895             : /*****************************************************************************
   10896             :  *
   10897             :  * ALTER SUBSCRIPTION name ...
   10898             :  *
   10899             :  *****************************************************************************/
   10900             : 
   10901             : AlterSubscriptionStmt:
   10902             :             ALTER SUBSCRIPTION name SET definition
   10903             :                 {
   10904             :                     AlterSubscriptionStmt *n =
   10905         186 :                         makeNode(AlterSubscriptionStmt);
   10906             : 
   10907         186 :                     n->kind = ALTER_SUBSCRIPTION_OPTIONS;
   10908         186 :                     n->subname = $3;
   10909         186 :                     n->options = $5;
   10910         186 :                     $$ = (Node *) n;
   10911             :                 }
   10912             :             | ALTER SUBSCRIPTION name CONNECTION Sconst
   10913             :                 {
   10914             :                     AlterSubscriptionStmt *n =
   10915          26 :                         makeNode(AlterSubscriptionStmt);
   10916             : 
   10917          26 :                     n->kind = ALTER_SUBSCRIPTION_CONNECTION;
   10918          26 :                     n->subname = $3;
   10919          26 :                     n->conninfo = $5;
   10920          26 :                     $$ = (Node *) n;
   10921             :                 }
   10922             :             | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
   10923             :                 {
   10924             :                     AlterSubscriptionStmt *n =
   10925          58 :                         makeNode(AlterSubscriptionStmt);
   10926             : 
   10927          58 :                     n->kind = ALTER_SUBSCRIPTION_REFRESH;
   10928          58 :                     n->subname = $3;
   10929          58 :                     n->options = $6;
   10930          58 :                     $$ = (Node *) n;
   10931             :                 }
   10932             :             | ALTER SUBSCRIPTION name ADD_P PUBLICATION name_list opt_definition
   10933             :                 {
   10934             :                     AlterSubscriptionStmt *n =
   10935          28 :                         makeNode(AlterSubscriptionStmt);
   10936             : 
   10937          28 :                     n->kind = ALTER_SUBSCRIPTION_ADD_PUBLICATION;
   10938          28 :                     n->subname = $3;
   10939          28 :                     n->publication = $6;
   10940          28 :                     n->options = $7;
   10941          28 :                     $$ = (Node *) n;
   10942             :                 }
   10943             :             | ALTER SUBSCRIPTION name DROP PUBLICATION name_list opt_definition
   10944             :                 {
   10945             :                     AlterSubscriptionStmt *n =
   10946          26 :                         makeNode(AlterSubscriptionStmt);
   10947             : 
   10948          26 :                     n->kind = ALTER_SUBSCRIPTION_DROP_PUBLICATION;
   10949          26 :                     n->subname = $3;
   10950          26 :                     n->publication = $6;
   10951          26 :                     n->options = $7;
   10952          26 :                     $$ = (Node *) n;
   10953             :                 }
   10954             :             | ALTER SUBSCRIPTION name SET PUBLICATION name_list opt_definition
   10955             :                 {
   10956             :                     AlterSubscriptionStmt *n =
   10957          44 :                         makeNode(AlterSubscriptionStmt);
   10958             : 
   10959          44 :                     n->kind = ALTER_SUBSCRIPTION_SET_PUBLICATION;
   10960          44 :                     n->subname = $3;
   10961          44 :                     n->publication = $6;
   10962          44 :                     n->options = $7;
   10963          44 :                     $$ = (Node *) n;
   10964             :                 }
   10965             :             | ALTER SUBSCRIPTION name ENABLE_P
   10966             :                 {
   10967             :                     AlterSubscriptionStmt *n =
   10968          50 :                         makeNode(AlterSubscriptionStmt);
   10969             : 
   10970          50 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   10971          50 :                     n->subname = $3;
   10972          50 :                     n->options = list_make1(makeDefElem("enabled",
   10973             :                                             (Node *) makeBoolean(true), @1));
   10974          50 :                     $$ = (Node *) n;
   10975             :                 }
   10976             :             | ALTER SUBSCRIPTION name DISABLE_P
   10977             :                 {
   10978             :                     AlterSubscriptionStmt *n =
   10979          34 :                         makeNode(AlterSubscriptionStmt);
   10980             : 
   10981          34 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   10982          34 :                     n->subname = $3;
   10983          34 :                     n->options = list_make1(makeDefElem("enabled",
   10984             :                                             (Node *) makeBoolean(false), @1));
   10985          34 :                     $$ = (Node *) n;
   10986             :                 }
   10987             :             | ALTER SUBSCRIPTION name SKIP definition
   10988             :                 {
   10989             :                     AlterSubscriptionStmt *n =
   10990          24 :                         makeNode(AlterSubscriptionStmt);
   10991             : 
   10992          24 :                     n->kind = ALTER_SUBSCRIPTION_SKIP;
   10993          24 :                     n->subname = $3;
   10994          24 :                     n->options = $5;
   10995          24 :                     $$ = (Node *) n;
   10996             :                 }
   10997             :         ;
   10998             : 
   10999             : /*****************************************************************************
   11000             :  *
   11001             :  * DROP SUBSCRIPTION [ IF EXISTS ] name
   11002             :  *
   11003             :  *****************************************************************************/
   11004             : 
   11005             : DropSubscriptionStmt: DROP SUBSCRIPTION name opt_drop_behavior
   11006             :                 {
   11007         222 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   11008             : 
   11009         222 :                     n->subname = $3;
   11010         222 :                     n->missing_ok = false;
   11011         222 :                     n->behavior = $4;
   11012         222 :                     $$ = (Node *) n;
   11013             :                 }
   11014             :                 |  DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
   11015             :                 {
   11016           6 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   11017             : 
   11018           6 :                     n->subname = $5;
   11019           6 :                     n->missing_ok = true;
   11020           6 :                     n->behavior = $6;
   11021           6 :                     $$ = (Node *) n;
   11022             :                 }
   11023             :         ;
   11024             : 
   11025             : /*****************************************************************************
   11026             :  *
   11027             :  *      QUERY:  Define Rewrite Rule
   11028             :  *
   11029             :  *****************************************************************************/
   11030             : 
   11031             : RuleStmt:   CREATE opt_or_replace RULE name AS
   11032             :             ON event TO qualified_name where_clause
   11033             :             DO opt_instead RuleActionList
   11034             :                 {
   11035        1174 :                     RuleStmt   *n = makeNode(RuleStmt);
   11036             : 
   11037        1174 :                     n->replace = $2;
   11038        1174 :                     n->relation = $9;
   11039        1174 :                     n->rulename = $4;
   11040        1174 :                     n->whereClause = $10;
   11041        1174 :                     n->event = $7;
   11042        1174 :                     n->instead = $12;
   11043        1174 :                     n->actions = $13;
   11044        1174 :                     $$ = (Node *) n;
   11045             :                 }
   11046             :         ;
   11047             : 
   11048             : RuleActionList:
   11049         170 :             NOTHING                                 { $$ = NIL; }
   11050         954 :             | RuleActionStmt                        { $$ = list_make1($1); }
   11051          50 :             | '(' RuleActionMulti ')'               { $$ = $2; }
   11052             :         ;
   11053             : 
   11054             : /* the thrashing around here is to discard "empty" statements... */
   11055             : RuleActionMulti:
   11056             :             RuleActionMulti ';' RuleActionStmtOrEmpty
   11057          70 :                 { if ($3 != NULL)
   11058          50 :                     $$ = lappend($1, $3);
   11059             :                   else
   11060          20 :                     $$ = $1;
   11061             :                 }
   11062             :             | RuleActionStmtOrEmpty
   11063          50 :                 { if ($1 != NULL)
   11064          50 :                     $$ = list_make1($1);
   11065             :                   else
   11066           0 :                     $$ = NIL;
   11067             :                 }
   11068             :         ;
   11069             : 
   11070             : RuleActionStmt:
   11071             :             SelectStmt
   11072             :             | InsertStmt
   11073             :             | UpdateStmt
   11074             :             | DeleteStmt
   11075             :             | NotifyStmt
   11076             :         ;
   11077             : 
   11078             : RuleActionStmtOrEmpty:
   11079         100 :             RuleActionStmt                          { $$ = $1; }
   11080          20 :             |   /*EMPTY*/                           { $$ = NULL; }
   11081             :         ;
   11082             : 
   11083          18 : event:      SELECT                                  { $$ = CMD_SELECT; }
   11084         456 :             | UPDATE                                { $$ = CMD_UPDATE; }
   11085         180 :             | DELETE_P                              { $$ = CMD_DELETE; }
   11086         520 :             | INSERT                                { $$ = CMD_INSERT; }
   11087             :          ;
   11088             : 
   11089             : opt_instead:
   11090         802 :             INSTEAD                                 { $$ = true; }
   11091         156 :             | ALSO                                  { $$ = false; }
   11092         216 :             | /*EMPTY*/                             { $$ = false; }
   11093             :         ;
   11094             : 
   11095             : 
   11096             : /*****************************************************************************
   11097             :  *
   11098             :  *      QUERY:
   11099             :  *              NOTIFY <identifier> can appear both in rule bodies and
   11100             :  *              as a query-level command
   11101             :  *
   11102             :  *****************************************************************************/
   11103             : 
   11104             : NotifyStmt: NOTIFY ColId notify_payload
   11105             :                 {
   11106         130 :                     NotifyStmt *n = makeNode(NotifyStmt);
   11107             : 
   11108         130 :                     n->conditionname = $2;
   11109         130 :                     n->payload = $3;
   11110         130 :                     $$ = (Node *) n;
   11111             :                 }
   11112             :         ;
   11113             : 
   11114             : notify_payload:
   11115          62 :             ',' Sconst                          { $$ = $2; }
   11116          68 :             | /*EMPTY*/                         { $$ = NULL; }
   11117             :         ;
   11118             : 
   11119             : ListenStmt: LISTEN ColId
   11120             :                 {
   11121          74 :                     ListenStmt *n = makeNode(ListenStmt);
   11122             : 
   11123          74 :                     n->conditionname = $2;
   11124          74 :                     $$ = (Node *) n;
   11125             :                 }
   11126             :         ;
   11127             : 
   11128             : UnlistenStmt:
   11129             :             UNLISTEN ColId
   11130             :                 {
   11131           6 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   11132             : 
   11133           6 :                     n->conditionname = $2;
   11134           6 :                     $$ = (Node *) n;
   11135             :                 }
   11136             :             | UNLISTEN '*'
   11137             :                 {
   11138          32 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   11139             : 
   11140          32 :                     n->conditionname = NULL;
   11141          32 :                     $$ = (Node *) n;
   11142             :                 }
   11143             :         ;
   11144             : 
   11145             : 
   11146             : /*****************************************************************************
   11147             :  *
   11148             :  *      Transactions:
   11149             :  *
   11150             :  *      BEGIN / COMMIT / ROLLBACK
   11151             :  *      (also older versions END / ABORT)
   11152             :  *
   11153             :  *****************************************************************************/
   11154             : 
   11155             : TransactionStmt:
   11156             :             ABORT_P opt_transaction opt_transaction_chain
   11157             :                 {
   11158         216 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11159             : 
   11160         216 :                     n->kind = TRANS_STMT_ROLLBACK;
   11161         216 :                     n->options = NIL;
   11162         216 :                     n->chain = $3;
   11163         216 :                     n->location = -1;
   11164         216 :                     $$ = (Node *) n;
   11165             :                 }
   11166             :             | START TRANSACTION transaction_mode_list_or_empty
   11167             :                 {
   11168        1610 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11169             : 
   11170        1610 :                     n->kind = TRANS_STMT_START;
   11171        1610 :                     n->options = $3;
   11172        1610 :                     n->location = -1;
   11173        1610 :                     $$ = (Node *) n;
   11174             :                 }
   11175             :             | COMMIT opt_transaction opt_transaction_chain
   11176             :                 {
   11177       13094 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11178             : 
   11179       13094 :                     n->kind = TRANS_STMT_COMMIT;
   11180       13094 :                     n->options = NIL;
   11181       13094 :                     n->chain = $3;
   11182       13094 :                     n->location = -1;
   11183       13094 :                     $$ = (Node *) n;
   11184             :                 }
   11185             :             | ROLLBACK opt_transaction opt_transaction_chain
   11186             :                 {
   11187        2650 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11188             : 
   11189        2650 :                     n->kind = TRANS_STMT_ROLLBACK;
   11190        2650 :                     n->options = NIL;
   11191        2650 :                     n->chain = $3;
   11192        2650 :                     n->location = -1;
   11193        2650 :                     $$ = (Node *) n;
   11194             :                 }
   11195             :             | SAVEPOINT ColId
   11196             :                 {
   11197        1952 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11198             : 
   11199        1952 :                     n->kind = TRANS_STMT_SAVEPOINT;
   11200        1952 :                     n->savepoint_name = $2;
   11201        1952 :                     n->location = @2;
   11202        1952 :                     $$ = (Node *) n;
   11203             :                 }
   11204             :             | RELEASE SAVEPOINT ColId
   11205             :                 {
   11206         208 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11207             : 
   11208         208 :                     n->kind = TRANS_STMT_RELEASE;
   11209         208 :                     n->savepoint_name = $3;
   11210         208 :                     n->location = @3;
   11211         208 :                     $$ = (Node *) n;
   11212             :                 }
   11213             :             | RELEASE ColId
   11214             :                 {
   11215          86 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11216             : 
   11217          86 :                     n->kind = TRANS_STMT_RELEASE;
   11218          86 :                     n->savepoint_name = $2;
   11219          86 :                     n->location = @2;
   11220          86 :                     $$ = (Node *) n;
   11221             :                 }
   11222             :             | ROLLBACK opt_transaction TO SAVEPOINT ColId
   11223             :                 {
   11224         228 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11225             : 
   11226         228 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   11227         228 :                     n->savepoint_name = $5;
   11228         228 :                     n->location = @5;
   11229         228 :                     $$ = (Node *) n;
   11230             :                 }
   11231             :             | ROLLBACK opt_transaction TO ColId
   11232             :                 {
   11233         496 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11234             : 
   11235         496 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   11236         496 :                     n->savepoint_name = $4;
   11237         496 :                     n->location = @4;
   11238         496 :                     $$ = (Node *) n;
   11239             :                 }
   11240             :             | PREPARE TRANSACTION Sconst
   11241             :                 {
   11242         660 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11243             : 
   11244         660 :                     n->kind = TRANS_STMT_PREPARE;
   11245         660 :                     n->gid = $3;
   11246         660 :                     n->location = @3;
   11247         660 :                     $$ = (Node *) n;
   11248             :                 }
   11249             :             | COMMIT PREPARED Sconst
   11250             :                 {
   11251         504 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11252             : 
   11253         504 :                     n->kind = TRANS_STMT_COMMIT_PREPARED;
   11254         504 :                     n->gid = $3;
   11255         504 :                     n->location = @3;
   11256         504 :                     $$ = (Node *) n;
   11257             :                 }
   11258             :             | ROLLBACK PREPARED Sconst
   11259             :                 {
   11260          74 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11261             : 
   11262          74 :                     n->kind = TRANS_STMT_ROLLBACK_PREPARED;
   11263          74 :                     n->gid = $3;
   11264          74 :                     n->location = @3;
   11265          74 :                     $$ = (Node *) n;
   11266             :                 }
   11267             :         ;
   11268             : 
   11269             : TransactionStmtLegacy:
   11270             :             BEGIN_P opt_transaction transaction_mode_list_or_empty
   11271             :                 {
   11272       15828 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11273             : 
   11274       15828 :                     n->kind = TRANS_STMT_BEGIN;
   11275       15828 :                     n->options = $3;
   11276       15828 :                     n->location = -1;
   11277       15828 :                     $$ = (Node *) n;
   11278             :                 }
   11279             :             | END_P opt_transaction opt_transaction_chain
   11280             :                 {
   11281         360 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11282             : 
   11283         360 :                     n->kind = TRANS_STMT_COMMIT;
   11284         360 :                     n->options = NIL;
   11285         360 :                     n->chain = $3;
   11286         360 :                     n->location = -1;
   11287         360 :                     $$ = (Node *) n;
   11288             :                 }
   11289             :         ;
   11290             : 
   11291             : opt_transaction:    WORK
   11292             :             | TRANSACTION
   11293             :             | /*EMPTY*/
   11294             :         ;
   11295             : 
   11296             : transaction_mode_item:
   11297             :             ISOLATION LEVEL iso_level
   11298        6784 :                     { $$ = makeDefElem("transaction_isolation",
   11299        6784 :                                        makeStringConst($3, @3), @1); }
   11300             :             | READ ONLY
   11301        1510 :                     { $$ = makeDefElem("transaction_read_only",
   11302        1510 :                                        makeIntConst(true, @1), @1); }
   11303             :             | READ WRITE
   11304          90 :                     { $$ = makeDefElem("transaction_read_only",
   11305          90 :                                        makeIntConst(false, @1), @1); }
   11306             :             | DEFERRABLE
   11307          44 :                     { $$ = makeDefElem("transaction_deferrable",
   11308             :                                        makeIntConst(true, @1), @1); }
   11309             :             | NOT DEFERRABLE
   11310          10 :                     { $$ = makeDefElem("transaction_deferrable",
   11311          10 :                                        makeIntConst(false, @1), @1); }
   11312             :         ;
   11313             : 
   11314             : /* Syntax with commas is SQL-spec, without commas is Postgres historical */
   11315             : transaction_mode_list:
   11316             :             transaction_mode_item
   11317        7000 :                     { $$ = list_make1($1); }
   11318             :             | transaction_mode_list ',' transaction_mode_item
   11319        1040 :                     { $$ = lappend($1, $3); }
   11320             :             | transaction_mode_list transaction_mode_item
   11321         398 :                     { $$ = lappend($1, $2); }
   11322             :         ;
   11323             : 
   11324             : transaction_mode_list_or_empty:
   11325             :             transaction_mode_list
   11326             :             | /* EMPTY */
   11327       11138 :                     { $$ = NIL; }
   11328             :         ;
   11329             : 
   11330             : opt_transaction_chain:
   11331         120 :             AND CHAIN       { $$ = true; }
   11332           2 :             | AND NO CHAIN  { $$ = false; }
   11333       16198 :             | /* EMPTY */   { $$ = false; }
   11334             :         ;
   11335             : 
   11336             : 
   11337             : /*****************************************************************************
   11338             :  *
   11339             :  *  QUERY:
   11340             :  *      CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
   11341             :  *          AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
   11342             :  *
   11343             :  *****************************************************************************/
   11344             : 
   11345             : ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11346             :                 AS SelectStmt opt_check_option
   11347             :                 {
   11348       17076 :                     ViewStmt   *n = makeNode(ViewStmt);
   11349             : 
   11350       17076 :                     n->view = $4;
   11351       17076 :                     n->view->relpersistence = $2;
   11352       17076 :                     n->aliases = $5;
   11353       17076 :                     n->query = $8;
   11354       17076 :                     n->replace = false;
   11355       17076 :                     n->options = $6;
   11356       17076 :                     n->withCheckOption = $9;
   11357       17076 :                     $$ = (Node *) n;
   11358             :                 }
   11359             :         | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11360             :                 AS SelectStmt opt_check_option
   11361             :                 {
   11362         248 :                     ViewStmt   *n = makeNode(ViewStmt);
   11363             : 
   11364         248 :                     n->view = $6;
   11365         248 :                     n->view->relpersistence = $4;
   11366         248 :                     n->aliases = $7;
   11367         248 :                     n->query = $10;
   11368         248 :                     n->replace = true;
   11369         248 :                     n->options = $8;
   11370         248 :                     n->withCheckOption = $11;
   11371         248 :                     $$ = (Node *) n;
   11372             :                 }
   11373             :         | CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11374             :                 AS SelectStmt opt_check_option
   11375             :                 {
   11376           8 :                     ViewStmt   *n = makeNode(ViewStmt);
   11377             : 
   11378           8 :                     n->view = $5;
   11379           8 :                     n->view->relpersistence = $2;
   11380           8 :                     n->aliases = $7;
   11381           8 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
   11382           8 :                     n->replace = false;
   11383           8 :                     n->options = $9;
   11384           8 :                     n->withCheckOption = $12;
   11385           8 :                     if (n->withCheckOption != NO_CHECK_OPTION)
   11386           0 :                         ereport(ERROR,
   11387             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   11388             :                                  errmsg("WITH CHECK OPTION not supported on recursive views"),
   11389             :                                  parser_errposition(@12)));
   11390           8 :                     $$ = (Node *) n;
   11391             :                 }
   11392             :         | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11393             :                 AS SelectStmt opt_check_option
   11394             :                 {
   11395           6 :                     ViewStmt   *n = makeNode(ViewStmt);
   11396             : 
   11397           6 :                     n->view = $7;
   11398           6 :                     n->view->relpersistence = $4;
   11399           6 :                     n->aliases = $9;
   11400           6 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
   11401           6 :                     n->replace = true;
   11402           6 :                     n->options = $11;
   11403           6 :                     n->withCheckOption = $14;
   11404           6 :                     if (n->withCheckOption != NO_CHECK_OPTION)
   11405           0 :                         ereport(ERROR,
   11406             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   11407             :                                  errmsg("WITH CHECK OPTION not supported on recursive views"),
   11408             :                                  parser_errposition(@14)));
   11409           6 :                     $$ = (Node *) n;
   11410             :                 }
   11411             :         ;
   11412             : 
   11413             : opt_check_option:
   11414          96 :         WITH CHECK OPTION               { $$ = CASCADED_CHECK_OPTION; }
   11415           6 :         | WITH CASCADED CHECK OPTION    { $$ = CASCADED_CHECK_OPTION; }
   11416          24 :         | WITH LOCAL CHECK OPTION       { $$ = LOCAL_CHECK_OPTION; }
   11417       17212 :         | /* EMPTY */                   { $$ = NO_CHECK_OPTION; }
   11418             :         ;
   11419             : 
   11420             : /*****************************************************************************
   11421             :  *
   11422             :  *      QUERY:
   11423             :  *              LOAD "filename"
   11424             :  *
   11425             :  *****************************************************************************/
   11426             : 
   11427             : LoadStmt:   LOAD file_name
   11428             :                 {
   11429          52 :                     LoadStmt   *n = makeNode(LoadStmt);
   11430             : 
   11431          52 :                     n->filename = $2;
   11432          52 :                     $$ = (Node *) n;
   11433             :                 }
   11434             :         ;
   11435             : 
   11436             : 
   11437             : /*****************************************************************************
   11438             :  *
   11439             :  *      CREATE DATABASE
   11440             :  *
   11441             :  *****************************************************************************/
   11442             : 
   11443             : CreatedbStmt:
   11444             :             CREATE DATABASE name opt_with createdb_opt_list
   11445             :                 {
   11446         790 :                     CreatedbStmt *n = makeNode(CreatedbStmt);
   11447             : 
   11448         790 :                     n->dbname = $3;
   11449         790 :                     n->options = $5;
   11450         790 :                     $$ = (Node *) n;
   11451             :                 }
   11452             :         ;
   11453             : 
   11454             : createdb_opt_list:
   11455         634 :             createdb_opt_items                      { $$ = $1; }
   11456         216 :             | /* EMPTY */                           { $$ = NIL; }
   11457             :         ;
   11458             : 
   11459             : createdb_opt_items:
   11460         634 :             createdb_opt_item                       { $$ = list_make1($1); }
   11461         940 :             | createdb_opt_items createdb_opt_item  { $$ = lappend($1, $2); }
   11462             :         ;
   11463             : 
   11464             : createdb_opt_item:
   11465             :             createdb_opt_name opt_equal NumericOnly
   11466             :                 {
   11467         262 :                     $$ = makeDefElem($1, $3, @1);
   11468             :                 }
   11469             :             | createdb_opt_name opt_equal opt_boolean_or_string
   11470             :                 {
   11471        1312 :                     $$ = makeDefElem($1, (Node *) makeString($3), @1);
   11472             :                 }
   11473             :             | createdb_opt_name opt_equal DEFAULT
   11474             :                 {
   11475           0 :                     $$ = makeDefElem($1, NULL, @1);
   11476             :                 }
   11477             :         ;
   11478             : 
   11479             : /*
   11480             :  * Ideally we'd use ColId here, but that causes shift/reduce conflicts against
   11481             :  * the ALTER DATABASE SET/RESET syntaxes.  Instead call out specific keywords
   11482             :  * we need, and allow IDENT so that database option names don't have to be
   11483             :  * parser keywords unless they are already keywords for other reasons.
   11484             :  *
   11485             :  * XXX this coding technique is fragile since if someone makes a formerly
   11486             :  * non-keyword option name into a keyword and forgets to add it here, the
   11487             :  * option will silently break.  Best defense is to provide a regression test
   11488             :  * exercising every such option, at least at the syntax level.
   11489             :  */
   11490             : createdb_opt_name:
   11491        1114 :             IDENT                           { $$ = $1; }
   11492           2 :             | CONNECTION LIMIT              { $$ = pstrdup("connection_limit"); }
   11493          96 :             | ENCODING                      { $$ = pstrdup($1); }
   11494           0 :             | LOCATION                      { $$ = pstrdup($1); }
   11495           2 :             | OWNER                         { $$ = pstrdup($1); }
   11496          16 :             | TABLESPACE                    { $$ = pstrdup($1); }
   11497         344 :             | TEMPLATE                      { $$ = pstrdup($1); }
   11498             :         ;
   11499             : 
   11500             : /*
   11501             :  *  Though the equals sign doesn't match other WITH options, pg_dump uses
   11502             :  *  equals for backward compatibility, and it doesn't seem worth removing it.
   11503             :  */
   11504             : opt_equal:  '='
   11505             :             | /*EMPTY*/
   11506             :         ;
   11507             : 
   11508             : 
   11509             : /*****************************************************************************
   11510             :  *
   11511             :  *      ALTER DATABASE
   11512             :  *
   11513             :  *****************************************************************************/
   11514             : 
   11515             : AlterDatabaseStmt:
   11516             :             ALTER DATABASE name WITH createdb_opt_list
   11517             :                  {
   11518           0 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11519             : 
   11520           0 :                     n->dbname = $3;
   11521           0 :                     n->options = $5;
   11522           0 :                     $$ = (Node *) n;
   11523             :                  }
   11524             :             | ALTER DATABASE name createdb_opt_list
   11525             :                  {
   11526          60 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11527             : 
   11528          60 :                     n->dbname = $3;
   11529          60 :                     n->options = $4;
   11530          60 :                     $$ = (Node *) n;
   11531             :                  }
   11532             :             | ALTER DATABASE name SET TABLESPACE name
   11533             :                  {
   11534          16 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11535             : 
   11536          16 :                     n->dbname = $3;
   11537          16 :                     n->options = list_make1(makeDefElem("tablespace",
   11538             :                                                         (Node *) makeString($6), @6));
   11539          16 :                     $$ = (Node *) n;
   11540             :                  }
   11541             :             | ALTER DATABASE name REFRESH COLLATION VERSION_P
   11542             :                  {
   11543           6 :                     AlterDatabaseRefreshCollStmt *n = makeNode(AlterDatabaseRefreshCollStmt);
   11544             : 
   11545           6 :                     n->dbname = $3;
   11546           6 :                     $$ = (Node *) n;
   11547             :                  }
   11548             :         ;
   11549             : 
   11550             : AlterDatabaseSetStmt:
   11551             :             ALTER DATABASE name SetResetClause
   11552             :                 {
   11553        1210 :                     AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
   11554             : 
   11555        1210 :                     n->dbname = $3;
   11556        1210 :                     n->setstmt = $4;
   11557        1210 :                     $$ = (Node *) n;
   11558             :                 }
   11559             :         ;
   11560             : 
   11561             : 
   11562             : /*****************************************************************************
   11563             :  *
   11564             :  *      DROP DATABASE [ IF EXISTS ] dbname [ [ WITH ] ( options ) ]
   11565             :  *
   11566             :  * This is implicitly CASCADE, no need for drop behavior
   11567             :  *****************************************************************************/
   11568             : 
   11569             : DropdbStmt: DROP DATABASE name
   11570             :                 {
   11571          92 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11572             : 
   11573          92 :                     n->dbname = $3;
   11574          92 :                     n->missing_ok = false;
   11575          92 :                     n->options = NULL;
   11576          92 :                     $$ = (Node *) n;
   11577             :                 }
   11578             :             | DROP DATABASE IF_P EXISTS name
   11579             :                 {
   11580           4 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11581             : 
   11582           4 :                     n->dbname = $5;
   11583           4 :                     n->missing_ok = true;
   11584           4 :                     n->options = NULL;
   11585           4 :                     $$ = (Node *) n;
   11586             :                 }
   11587             :             | DROP DATABASE name opt_with '(' drop_option_list ')'
   11588             :                 {
   11589          14 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11590             : 
   11591          14 :                     n->dbname = $3;
   11592          14 :                     n->missing_ok = false;
   11593          14 :                     n->options = $6;
   11594          14 :                     $$ = (Node *) n;
   11595             :                 }
   11596             :             | DROP DATABASE IF_P EXISTS name opt_with '(' drop_option_list ')'
   11597             :                 {
   11598          12 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11599             : 
   11600          12 :                     n->dbname = $5;
   11601          12 :                     n->missing_ok = true;
   11602          12 :                     n->options = $8;
   11603          12 :                     $$ = (Node *) n;
   11604             :                 }
   11605             :         ;
   11606             : 
   11607             : drop_option_list:
   11608             :             drop_option
   11609             :                 {
   11610          26 :                     $$ = list_make1((Node *) $1);
   11611             :                 }
   11612             :             | drop_option_list ',' drop_option
   11613             :                 {
   11614           0 :                     $$ = lappend($1, (Node *) $3);
   11615             :                 }
   11616             :         ;
   11617             : 
   11618             : /*
   11619             :  * Currently only the FORCE option is supported, but the syntax is designed
   11620             :  * to be extensible so that we can add more options in the future if required.
   11621             :  */
   11622             : drop_option:
   11623             :             FORCE
   11624             :                 {
   11625          26 :                     $$ = makeDefElem("force", NULL, @1);
   11626             :                 }
   11627             :         ;
   11628             : 
   11629             : /*****************************************************************************
   11630             :  *
   11631             :  *      ALTER COLLATION
   11632             :  *
   11633             :  *****************************************************************************/
   11634             : 
   11635             : AlterCollationStmt: ALTER COLLATION any_name REFRESH VERSION_P
   11636             :                 {
   11637           6 :                     AlterCollationStmt *n = makeNode(AlterCollationStmt);
   11638             : 
   11639           6 :                     n->collname = $3;
   11640           6 :                     $$ = (Node *) n;
   11641             :                 }
   11642             :         ;
   11643             : 
   11644             : 
   11645             : /*****************************************************************************
   11646             :  *
   11647             :  *      ALTER SYSTEM
   11648             :  *
   11649             :  * This is used to change configuration parameters persistently.
   11650             :  *****************************************************************************/
   11651             : 
   11652             : AlterSystemStmt:
   11653             :             ALTER SYSTEM_P SET generic_set
   11654             :                 {
   11655         126 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11656             : 
   11657         126 :                     n->setstmt = $4;
   11658         126 :                     $$ = (Node *) n;
   11659             :                 }
   11660             :             | ALTER SYSTEM_P RESET generic_reset
   11661             :                 {
   11662          54 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11663             : 
   11664          54 :                     n->setstmt = $4;
   11665          54 :                     $$ = (Node *) n;
   11666             :                 }
   11667             :         ;
   11668             : 
   11669             : 
   11670             : /*****************************************************************************
   11671             :  *
   11672             :  * Manipulate a domain
   11673             :  *
   11674             :  *****************************************************************************/
   11675             : 
   11676             : CreateDomainStmt:
   11677             :             CREATE DOMAIN_P any_name opt_as Typename ColQualList
   11678             :                 {
   11679        1510 :                     CreateDomainStmt *n = makeNode(CreateDomainStmt);
   11680             : 
   11681        1510 :                     n->domainname = $3;
   11682        1510 :                     n->typeName = $5;
   11683        1510 :                     SplitColQualList($6, &n->constraints, &n->collClause,
   11684             :                                      yyscanner);
   11685        1510 :                     $$ = (Node *) n;
   11686             :                 }
   11687             :         ;
   11688             : 
   11689             : AlterDomainStmt:
   11690             :             /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
   11691             :             ALTER DOMAIN_P any_name alter_column_default
   11692             :                 {
   11693          14 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11694             : 
   11695          14 :                     n->subtype = AD_AlterDefault;
   11696          14 :                     n->typeName = $3;
   11697          14 :                     n->def = $4;
   11698          14 :                     $$ = (Node *) n;
   11699             :                 }
   11700             :             /* ALTER DOMAIN <domain> DROP NOT NULL */
   11701             :             | ALTER DOMAIN_P any_name DROP NOT NULL_P
   11702             :                 {
   11703          12 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11704             : 
   11705          12 :                     n->subtype = AD_DropNotNull;
   11706          12 :                     n->typeName = $3;
   11707          12 :                     $$ = (Node *) n;
   11708             :                 }
   11709             :             /* ALTER DOMAIN <domain> SET NOT NULL */
   11710             :             | ALTER DOMAIN_P any_name SET NOT NULL_P
   11711             :                 {
   11712          24 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11713             : 
   11714          24 :                     n->subtype = AD_SetNotNull;
   11715          24 :                     n->typeName = $3;
   11716          24 :                     $$ = (Node *) n;
   11717             :                 }
   11718             :             /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
   11719             :             | ALTER DOMAIN_P any_name ADD_P DomainConstraint
   11720             :                 {
   11721         184 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11722             : 
   11723         184 :                     n->subtype = AD_AddConstraint;
   11724         184 :                     n->typeName = $3;
   11725         184 :                     n->def = $5;
   11726         184 :                     $$ = (Node *) n;
   11727             :                 }
   11728             :             /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
   11729             :             | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
   11730             :                 {
   11731          54 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11732             : 
   11733          54 :                     n->subtype = AD_DropConstraint;
   11734          54 :                     n->typeName = $3;
   11735          54 :                     n->name = $6;
   11736          54 :                     n->behavior = $7;
   11737          54 :                     n->missing_ok = false;
   11738          54 :                     $$ = (Node *) n;
   11739             :                 }
   11740             :             /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
   11741             :             | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
   11742             :                 {
   11743           6 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11744             : 
   11745           6 :                     n->subtype = AD_DropConstraint;
   11746           6 :                     n->typeName = $3;
   11747           6 :                     n->name = $8;
   11748           6 :                     n->behavior = $9;
   11749           6 :                     n->missing_ok = true;
   11750           6 :                     $$ = (Node *) n;
   11751             :                 }
   11752             :             /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
   11753             :             | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
   11754             :                 {
   11755          12 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11756             : 
   11757          12 :                     n->subtype = AD_ValidateConstraint;
   11758          12 :                     n->typeName = $3;
   11759          12 :                     n->name = $6;
   11760          12 :                     $$ = (Node *) n;
   11761             :                 }
   11762             :             ;
   11763             : 
   11764             : opt_as:     AS
   11765             :             | /* EMPTY */
   11766             :         ;
   11767             : 
   11768             : 
   11769             : /*****************************************************************************
   11770             :  *
   11771             :  * Manipulate a text search dictionary or configuration
   11772             :  *
   11773             :  *****************************************************************************/
   11774             : 
   11775             : AlterTSDictionaryStmt:
   11776             :             ALTER TEXT_P SEARCH DICTIONARY any_name definition
   11777             :                 {
   11778          40 :                     AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
   11779             : 
   11780          40 :                     n->dictname = $5;
   11781          40 :                     n->options = $6;
   11782          40 :                     $$ = (Node *) n;
   11783             :                 }
   11784             :         ;
   11785             : 
   11786             : AlterTSConfigurationStmt:
   11787             :             ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
   11788             :                 {
   11789        8844 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11790             : 
   11791        8844 :                     n->kind = ALTER_TSCONFIG_ADD_MAPPING;
   11792        8844 :                     n->cfgname = $5;
   11793        8844 :                     n->tokentype = $9;
   11794        8844 :                     n->dicts = $11;
   11795        8844 :                     n->override = false;
   11796        8844 :                     n->replace = false;
   11797        8844 :                     $$ = (Node *) n;
   11798             :                 }
   11799             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
   11800             :                 {
   11801          26 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11802             : 
   11803          26 :                     n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
   11804          26 :                     n->cfgname = $5;
   11805          26 :                     n->tokentype = $9;
   11806          26 :                     n->dicts = $11;
   11807          26 :                     n->override = true;
   11808          26 :                     n->replace = false;
   11809          26 :                     $$ = (Node *) n;
   11810             :                 }
   11811             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
   11812             :                 {
   11813          18 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11814             : 
   11815          18 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT;
   11816          18 :                     n->cfgname = $5;
   11817          18 :                     n->tokentype = NIL;
   11818          18 :                     n->dicts = list_make2($9,$11);
   11819          18 :                     n->override = false;
   11820          18 :                     n->replace = true;
   11821          18 :                     $$ = (Node *) n;
   11822             :                 }
   11823             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
   11824             :                 {
   11825           0 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11826             : 
   11827           0 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN;
   11828           0 :                     n->cfgname = $5;
   11829           0 :                     n->tokentype = $9;
   11830           0 :                     n->dicts = list_make2($11,$13);
   11831           0 :                     n->override = false;
   11832           0 :                     n->replace = true;
   11833           0 :                     $$ = (Node *) n;
   11834             :                 }
   11835             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
   11836             :                 {
   11837          18 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11838             : 
   11839          18 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   11840          18 :                     n->cfgname = $5;
   11841          18 :                     n->tokentype = $9;
   11842          18 :                     n->missing_ok = false;
   11843          18 :                     $$ = (Node *) n;
   11844             :                 }
   11845             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
   11846             :                 {
   11847          12 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11848             : 
   11849          12 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   11850          12 :                     n->cfgname = $5;
   11851          12 :                     n->tokentype = $11;
   11852          12 :                     n->missing_ok = true;
   11853          12 :                     $$ = (Node *) n;
   11854             :                 }
   11855             :         ;
   11856             : 
   11857             : /* Use this if TIME or ORDINALITY after WITH should be taken as an identifier */
   11858             : any_with:   WITH
   11859             :             | WITH_LA
   11860             :         ;
   11861             : 
   11862             : 
   11863             : /*****************************************************************************
   11864             :  *
   11865             :  * Manipulate a conversion
   11866             :  *
   11867             :  *      CREATE [DEFAULT] CONVERSION <conversion_name>
   11868             :  *      FOR <encoding_name> TO <encoding_name> FROM <func_name>
   11869             :  *
   11870             :  *****************************************************************************/
   11871             : 
   11872             : CreateConversionStmt:
   11873             :             CREATE opt_default CONVERSION_P any_name FOR Sconst
   11874             :             TO Sconst FROM any_name
   11875             :             {
   11876          64 :                 CreateConversionStmt *n = makeNode(CreateConversionStmt);
   11877             : 
   11878          64 :                 n->conversion_name = $4;
   11879          64 :                 n->for_encoding_name = $6;
   11880          64 :                 n->to_encoding_name = $8;
   11881          64 :                 n->func_name = $10;
   11882          64 :                 n->def = $2;
   11883          64 :                 $$ = (Node *) n;
   11884             :             }
   11885             :         ;
   11886             : 
   11887             : /*****************************************************************************
   11888             :  *
   11889             :  *      QUERY:
   11890             :  *              CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
   11891             :  *              CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
   11892             :  *              CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
   11893             :  *
   11894             :  *****************************************************************************/
   11895             : 
   11896             : ClusterStmt:
   11897             :             CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
   11898             :                 {
   11899           0 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11900             : 
   11901           0 :                     n->relation = $5;
   11902           0 :                     n->indexname = $6;
   11903           0 :                     n->params = $3;
   11904           0 :                     $$ = (Node *) n;
   11905             :                 }
   11906             :             | CLUSTER '(' utility_option_list ')'
   11907             :                 {
   11908           0 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11909             : 
   11910           0 :                     n->relation = NULL;
   11911           0 :                     n->indexname = NULL;
   11912           0 :                     n->params = $3;
   11913           0 :                     $$ = (Node *) n;
   11914             :                 }
   11915             :             /* unparenthesized VERBOSE kept for pre-14 compatibility */
   11916             :             | CLUSTER opt_verbose qualified_name cluster_index_specification
   11917             :                 {
   11918         184 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11919             : 
   11920         184 :                     n->relation = $3;
   11921         184 :                     n->indexname = $4;
   11922         184 :                     n->params = NIL;
   11923         184 :                     if ($2)
   11924           0 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11925         184 :                     $$ = (Node *) n;
   11926             :                 }
   11927             :             /* unparenthesized VERBOSE kept for pre-17 compatibility */
   11928             :             | CLUSTER opt_verbose
   11929             :                 {
   11930          18 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11931             : 
   11932          18 :                     n->relation = NULL;
   11933          18 :                     n->indexname = NULL;
   11934          18 :                     n->params = NIL;
   11935          18 :                     if ($2)
   11936           2 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11937          18 :                     $$ = (Node *) n;
   11938             :                 }
   11939             :             /* kept for pre-8.3 compatibility */
   11940             :             | CLUSTER opt_verbose name ON qualified_name
   11941             :                 {
   11942          18 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11943             : 
   11944          18 :                     n->relation = $5;
   11945          18 :                     n->indexname = $3;
   11946          18 :                     n->params = NIL;
   11947          18 :                     if ($2)
   11948           0 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11949          18 :                     $$ = (Node *) n;
   11950             :                 }
   11951             :         ;
   11952             : 
   11953             : cluster_index_specification:
   11954         154 :             USING name              { $$ = $2; }
   11955          30 :             | /*EMPTY*/             { $$ = NULL; }
   11956             :         ;
   11957             : 
   11958             : 
   11959             : /*****************************************************************************
   11960             :  *
   11961             :  *      QUERY:
   11962             :  *              VACUUM
   11963             :  *              ANALYZE
   11964             :  *
   11965             :  *****************************************************************************/
   11966             : 
   11967             : VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relation_list
   11968             :                 {
   11969        1230 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11970             : 
   11971        1230 :                     n->options = NIL;
   11972        1230 :                     if ($2)
   11973         146 :                         n->options = lappend(n->options,
   11974         146 :                                              makeDefElem("full", NULL, @2));
   11975        1230 :                     if ($3)
   11976         164 :                         n->options = lappend(n->options,
   11977         164 :                                              makeDefElem("freeze", NULL, @3));
   11978        1230 :                     if ($4)
   11979          16 :                         n->options = lappend(n->options,
   11980          16 :                                              makeDefElem("verbose", NULL, @4));
   11981        1230 :                     if ($5)
   11982         292 :                         n->options = lappend(n->options,
   11983         292 :                                              makeDefElem("analyze", NULL, @5));
   11984        1230 :                     n->rels = $6;
   11985        1230 :                     n->is_vacuumcmd = true;
   11986        1230 :                     $$ = (Node *) n;
   11987             :                 }
   11988             :             | VACUUM '(' utility_option_list ')' opt_vacuum_relation_list
   11989             :                 {
   11990        7646 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11991             : 
   11992        7646 :                     n->options = $3;
   11993        7646 :                     n->rels = $5;
   11994        7646 :                     n->is_vacuumcmd = true;
   11995        7646 :                     $$ = (Node *) n;
   11996             :                 }
   11997             :         ;
   11998             : 
   11999             : AnalyzeStmt: analyze_keyword opt_verbose opt_vacuum_relation_list
   12000             :                 {
   12001        4504 :                     VacuumStmt *n = makeNode(VacuumStmt);
   12002             : 
   12003        4504 :                     n->options = NIL;
   12004        4504 :                     if ($2)
   12005           0 :                         n->options = lappend(n->options,
   12006           0 :                                              makeDefElem("verbose", NULL, @2));
   12007        4504 :                     n->rels = $3;
   12008        4504 :                     n->is_vacuumcmd = false;
   12009        4504 :                     $$ = (Node *) n;
   12010             :                 }
   12011             :             | analyze_keyword '(' utility_option_list ')' opt_vacuum_relation_list
   12012             :                 {
   12013         186 :                     VacuumStmt *n = makeNode(VacuumStmt);
   12014             : 
   12015         186 :                     n->options = $3;
   12016         186 :                     n->rels = $5;
   12017         186 :                     n->is_vacuumcmd = false;
   12018         186 :                     $$ = (Node *) n;
   12019             :                 }
   12020             :         ;
   12021             : 
   12022             : utility_option_list:
   12023             :             utility_option_elem
   12024             :                 {
   12025       21912 :                     $$ = list_make1($1);
   12026             :                 }
   12027             :             | utility_option_list ',' utility_option_elem
   12028             :                 {
   12029       12374 :                     $$ = lappend($1, $3);
   12030             :                 }
   12031             :         ;
   12032             : 
   12033             : analyze_keyword:
   12034             :             ANALYZE
   12035             :             | ANALYSE /* British */
   12036             :         ;
   12037             : 
   12038             : utility_option_elem:
   12039             :             utility_option_name utility_option_arg
   12040             :                 {
   12041       34286 :                     $$ = makeDefElem($1, $2, @1);
   12042             :                 }
   12043             :         ;
   12044             : 
   12045             : utility_option_name:
   12046       30536 :             NonReservedWord                         { $$ = $1; }
   12047        3608 :             | analyze_keyword                       { $$ = "analyze"; }
   12048         148 :             | FORMAT_LA                             { $$ = "format"; }
   12049             :         ;
   12050             : 
   12051             : utility_option_arg:
   12052       17406 :             opt_boolean_or_string                   { $$ = (Node *) makeString($1); }
   12053         382 :             | NumericOnly                           { $$ = (Node *) $1; }
   12054       16498 :             | /* EMPTY */                           { $$ = NULL; }
   12055             :         ;
   12056             : 
   12057             : opt_analyze:
   12058         292 :             analyze_keyword                         { $$ = true; }
   12059         938 :             | /*EMPTY*/                             { $$ = false; }
   12060             :         ;
   12061             : 
   12062             : opt_verbose:
   12063          18 :             VERBOSE                                 { $$ = true; }
   12064        8240 :             | /*EMPTY*/                             { $$ = false; }
   12065             :         ;
   12066             : 
   12067         146 : opt_full:   FULL                                    { $$ = true; }
   12068        1084 :             | /*EMPTY*/                             { $$ = false; }
   12069             :         ;
   12070             : 
   12071         164 : opt_freeze: FREEZE                                  { $$ = true; }
   12072        1066 :             | /*EMPTY*/                             { $$ = false; }
   12073             :         ;
   12074             : 
   12075             : opt_name_list:
   12076        2786 :             '(' name_list ')'                       { $$ = $2; }
   12077       15830 :             | /*EMPTY*/                             { $$ = NIL; }
   12078             :         ;
   12079             : 
   12080             : vacuum_relation:
   12081             :             relation_expr opt_name_list
   12082             :                 {
   12083       13334 :                     $$ = (Node *) makeVacuumRelation($1, InvalidOid, $2);
   12084             :                 }
   12085             :         ;
   12086             : 
   12087             : vacuum_relation_list:
   12088             :             vacuum_relation
   12089       13176 :                     { $$ = list_make1($1); }
   12090             :             | vacuum_relation_list ',' vacuum_relation
   12091         158 :                     { $$ = lappend($1, $3); }
   12092             :         ;
   12093             : 
   12094             : opt_vacuum_relation_list:
   12095       13176 :             vacuum_relation_list                    { $$ = $1; }
   12096         390 :             | /*EMPTY*/                             { $$ = NIL; }
   12097             :         ;
   12098             : 
   12099             : 
   12100             : /*****************************************************************************
   12101             :  *
   12102             :  *      QUERY:
   12103             :  *              EXPLAIN [ANALYZE] [VERBOSE] query
   12104             :  *              EXPLAIN ( options ) query
   12105             :  *
   12106             :  *****************************************************************************/
   12107             : 
   12108             : ExplainStmt:
   12109             :         EXPLAIN ExplainableStmt
   12110             :                 {
   12111        7718 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12112             : 
   12113        7718 :                     n->query = $2;
   12114        7718 :                     n->options = NIL;
   12115        7718 :                     $$ = (Node *) n;
   12116             :                 }
   12117             :         | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
   12118             :                 {
   12119        2304 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12120             : 
   12121        2304 :                     n->query = $4;
   12122        2304 :                     n->options = list_make1(makeDefElem("analyze", NULL, @2));
   12123        2304 :                     if ($3)
   12124           0 :                         n->options = lappend(n->options,
   12125           0 :                                              makeDefElem("verbose", NULL, @3));
   12126        2304 :                     $$ = (Node *) n;
   12127             :                 }
   12128             :         | EXPLAIN VERBOSE ExplainableStmt
   12129             :                 {
   12130          12 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12131             : 
   12132          12 :                     n->query = $3;
   12133          12 :                     n->options = list_make1(makeDefElem("verbose", NULL, @2));
   12134          12 :                     $$ = (Node *) n;
   12135             :                 }
   12136             :         | EXPLAIN '(' utility_option_list ')' ExplainableStmt
   12137             :                 {
   12138       13900 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12139             : 
   12140       13900 :                     n->query = $5;
   12141       13900 :                     n->options = $3;
   12142       13900 :                     $$ = (Node *) n;
   12143             :                 }
   12144             :         ;
   12145             : 
   12146             : ExplainableStmt:
   12147             :             SelectStmt
   12148             :             | InsertStmt
   12149             :             | UpdateStmt
   12150             :             | DeleteStmt
   12151             :             | MergeStmt
   12152             :             | DeclareCursorStmt
   12153             :             | CreateAsStmt
   12154             :             | CreateMatViewStmt
   12155             :             | RefreshMatViewStmt
   12156             :             | ExecuteStmt                   /* by default all are $$=$1 */
   12157             :         ;
   12158             : 
   12159             : /*****************************************************************************
   12160             :  *
   12161             :  *      QUERY:
   12162             :  *              PREPARE <plan_name> [(args, ...)] AS <query>
   12163             :  *
   12164             :  *****************************************************************************/
   12165             : 
   12166             : PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
   12167             :                 {
   12168        2142 :                     PrepareStmt *n = makeNode(PrepareStmt);
   12169             : 
   12170        2142 :                     n->name = $2;
   12171        2142 :                     n->argtypes = $3;
   12172        2142 :                     n->query = $5;
   12173        2142 :                     $$ = (Node *) n;
   12174             :                 }
   12175             :         ;
   12176             : 
   12177        1834 : prep_type_clause: '(' type_list ')'         { $$ = $2; }
   12178         326 :                 | /* EMPTY */               { $$ = NIL; }
   12179             :         ;
   12180             : 
   12181             : PreparableStmt:
   12182             :             SelectStmt
   12183             :             | InsertStmt
   12184             :             | UpdateStmt
   12185             :             | DeleteStmt
   12186             :             | MergeStmt                     /* by default all are $$=$1 */
   12187             :         ;
   12188             : 
   12189             : /*****************************************************************************
   12190             :  *
   12191             :  * EXECUTE <plan_name> [(params, ...)]
   12192             :  * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
   12193             :  *
   12194             :  *****************************************************************************/
   12195             : 
   12196             : ExecuteStmt: EXECUTE name execute_param_clause
   12197             :                 {
   12198       19988 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12199             : 
   12200       19988 :                     n->name = $2;
   12201       19988 :                     n->params = $3;
   12202       19988 :                     $$ = (Node *) n;
   12203             :                 }
   12204             :             | CREATE OptTemp TABLE create_as_target AS
   12205             :                 EXECUTE name execute_param_clause opt_with_data
   12206             :                 {
   12207          76 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   12208          76 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12209             : 
   12210          76 :                     n->name = $7;
   12211          76 :                     n->params = $8;
   12212          76 :                     ctas->query = (Node *) n;
   12213          76 :                     ctas->into = $4;
   12214          76 :                     ctas->objtype = OBJECT_TABLE;
   12215          76 :                     ctas->is_select_into = false;
   12216          76 :                     ctas->if_not_exists = false;
   12217             :                     /* cram additional flags into the IntoClause */
   12218          76 :                     $4->rel->relpersistence = $2;
   12219          76 :                     $4->skipData = !($9);
   12220          76 :                     $$ = (Node *) ctas;
   12221             :                 }
   12222             :             | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS
   12223             :                 EXECUTE name execute_param_clause opt_with_data
   12224             :                 {
   12225          12 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   12226          12 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12227             : 
   12228          12 :                     n->name = $10;
   12229          12 :                     n->params = $11;
   12230          12 :                     ctas->query = (Node *) n;
   12231          12 :                     ctas->into = $7;
   12232          12 :                     ctas->objtype = OBJECT_TABLE;
   12233          12 :                     ctas->is_select_into = false;
   12234          12 :                     ctas->if_not_exists = true;
   12235             :                     /* cram additional flags into the IntoClause */
   12236          12 :                     $7->rel->relpersistence = $2;
   12237          12 :                     $7->skipData = !($12);
   12238          12 :                     $$ = (Node *) ctas;
   12239             :                 }
   12240             :         ;
   12241             : 
   12242       18934 : execute_param_clause: '(' expr_list ')'             { $$ = $2; }
   12243        1142 :                     | /* EMPTY */                   { $$ = NIL; }
   12244             :                     ;
   12245             : 
   12246             : /*****************************************************************************
   12247             :  *
   12248             :  *      QUERY:
   12249             :  *              DEALLOCATE [PREPARE] <plan_name>
   12250             :  *
   12251             :  *****************************************************************************/
   12252             : 
   12253             : DeallocateStmt: DEALLOCATE name
   12254             :                     {
   12255        3990 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12256             : 
   12257        3990 :                         n->name = $2;
   12258        3990 :                         n->isall = false;
   12259        3990 :                         n->location = @2;
   12260        3990 :                         $$ = (Node *) n;
   12261             :                     }
   12262             :                 | DEALLOCATE PREPARE name
   12263             :                     {
   12264          20 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12265             : 
   12266          20 :                         n->name = $3;
   12267          20 :                         n->isall = false;
   12268          20 :                         n->location = @3;
   12269          20 :                         $$ = (Node *) n;
   12270             :                     }
   12271             :                 | DEALLOCATE ALL
   12272             :                     {
   12273          54 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12274             : 
   12275          54 :                         n->name = NULL;
   12276          54 :                         n->isall = true;
   12277          54 :                         n->location = -1;
   12278          54 :                         $$ = (Node *) n;
   12279             :                     }
   12280             :                 | DEALLOCATE PREPARE ALL
   12281             :                     {
   12282           2 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12283             : 
   12284           2 :                         n->name = NULL;
   12285           2 :                         n->isall = true;
   12286           2 :                         n->location = -1;
   12287           2 :                         $$ = (Node *) n;
   12288             :                     }
   12289             :         ;
   12290             : 
   12291             : /*****************************************************************************
   12292             :  *
   12293             :  *      QUERY:
   12294             :  *              INSERT STATEMENTS
   12295             :  *
   12296             :  *****************************************************************************/
   12297             : 
   12298             : InsertStmt:
   12299             :             opt_with_clause INSERT INTO insert_target insert_rest
   12300             :             opt_on_conflict returning_clause
   12301             :                 {
   12302       68532 :                     $5->relation = $4;
   12303       68532 :                     $5->onConflictClause = $6;
   12304       68532 :                     $5->returningClause = $7;
   12305       68532 :                     $5->withClause = $1;
   12306       68532 :                     $$ = (Node *) $5;
   12307             :                 }
   12308             :         ;
   12309             : 
   12310             : /*
   12311             :  * Can't easily make AS optional here, because VALUES in insert_rest would
   12312             :  * have a shift/reduce conflict with VALUES as an optional alias.  We could
   12313             :  * easily allow unreserved_keywords as optional aliases, but that'd be an odd
   12314             :  * divergence from other places.  So just require AS for now.
   12315             :  */
   12316             : insert_target:
   12317             :             qualified_name
   12318             :                 {
   12319       68400 :                     $$ = $1;
   12320             :                 }
   12321             :             | qualified_name AS ColId
   12322             :                 {
   12323         138 :                     $1->alias = makeAlias($3, NIL);
   12324         138 :                     $$ = $1;
   12325             :                 }
   12326             :         ;
   12327             : 
   12328             : insert_rest:
   12329             :             SelectStmt
   12330             :                 {
   12331       43320 :                     $$ = makeNode(InsertStmt);
   12332       43320 :                     $$->cols = NIL;
   12333       43320 :                     $$->selectStmt = $1;
   12334             :                 }
   12335             :             | OVERRIDING override_kind VALUE_P SelectStmt
   12336             :                 {
   12337          96 :                     $$ = makeNode(InsertStmt);
   12338          96 :                     $$->cols = NIL;
   12339          96 :                     $$->override = $2;
   12340          96 :                     $$->selectStmt = $4;
   12341             :                 }
   12342             :             | '(' insert_column_list ')' SelectStmt
   12343             :                 {
   12344       14314 :                     $$ = makeNode(InsertStmt);
   12345       14314 :                     $$->cols = $2;
   12346       14314 :                     $$->selectStmt = $4;
   12347             :                 }
   12348             :             | '(' insert_column_list ')' OVERRIDING override_kind VALUE_P SelectStmt
   12349             :                 {
   12350           0 :                     $$ = makeNode(InsertStmt);
   12351           0 :                     $$->cols = $2;
   12352           0 :                     $$->override = $5;
   12353           0 :                     $$->selectStmt = $7;
   12354             :                 }
   12355             :             | DEFAULT VALUES
   12356             :                 {
   12357       10808 :                     $$ = makeNode(InsertStmt);
   12358       10808 :                     $$->cols = NIL;
   12359       10808 :                     $$->selectStmt = NULL;
   12360             :                 }
   12361             :         ;
   12362             : 
   12363             : override_kind:
   12364          66 :             USER        { $$ = OVERRIDING_USER_VALUE; }
   12365          60 :             | SYSTEM_P  { $$ = OVERRIDING_SYSTEM_VALUE; }
   12366             :         ;
   12367             : 
   12368             : insert_column_list:
   12369             :             insert_column_item
   12370       14642 :                     { $$ = list_make1($1); }
   12371             :             | insert_column_list ',' insert_column_item
   12372       16278 :                     { $$ = lappend($1, $3); }
   12373             :         ;
   12374             : 
   12375             : insert_column_item:
   12376             :             ColId opt_indirection
   12377             :                 {
   12378       30920 :                     $$ = makeNode(ResTarget);
   12379       30920 :                     $$->name = $1;
   12380       30920 :                     $$->indirection = check_indirection($2, yyscanner);
   12381       30920 :                     $$->val = NULL;
   12382       30920 :                     $$->location = @1;
   12383             :                 }
   12384             :         ;
   12385             : 
   12386             : opt_on_conflict:
   12387             :             ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
   12388             :                 {
   12389        1302 :                     $$ = makeNode(OnConflictClause);
   12390        1302 :                     $$->action = ONCONFLICT_UPDATE;
   12391        1302 :                     $$->infer = $3;
   12392        1302 :                     $$->targetList = $7;
   12393        1302 :                     $$->whereClause = $8;
   12394        1302 :                     $$->location = @1;
   12395             :                 }
   12396             :             |
   12397             :             ON CONFLICT opt_conf_expr DO NOTHING
   12398             :                 {
   12399         550 :                     $$ = makeNode(OnConflictClause);
   12400         550 :                     $$->action = ONCONFLICT_NOTHING;
   12401         550 :                     $$->infer = $3;
   12402         550 :                     $$->targetList = NIL;
   12403         550 :                     $$->whereClause = NULL;
   12404         550 :                     $$->location = @1;
   12405             :                 }
   12406             :             | /*EMPTY*/
   12407             :                 {
   12408       66686 :                     $$ = NULL;
   12409             :                 }
   12410             :         ;
   12411             : 
   12412             : opt_conf_expr:
   12413             :             '(' index_params ')' where_clause
   12414             :                 {
   12415        1426 :                     $$ = makeNode(InferClause);
   12416        1426 :                     $$->indexElems = $2;
   12417        1426 :                     $$->whereClause = $4;
   12418        1426 :                     $$->conname = NULL;
   12419        1426 :                     $$->location = @1;
   12420             :                 }
   12421             :             |
   12422             :             ON CONSTRAINT name
   12423             :                 {
   12424         192 :                     $$ = makeNode(InferClause);
   12425         192 :                     $$->indexElems = NIL;
   12426         192 :                     $$->whereClause = NULL;
   12427         192 :                     $$->conname = $3;
   12428         192 :                     $$->location = @1;
   12429             :                 }
   12430             :             | /*EMPTY*/
   12431             :                 {
   12432         234 :                     $$ = NULL;
   12433             :                 }
   12434             :         ;
   12435             : 
   12436             : returning_clause:
   12437             :             RETURNING returning_with_clause target_list
   12438             :                 {
   12439        3158 :                     ReturningClause *n = makeNode(ReturningClause);
   12440             : 
   12441        3158 :                     n->options = $2;
   12442        3158 :                     n->exprs = $3;
   12443        3158 :                     $$ = n;
   12444             :                 }
   12445             :             | /* EMPTY */
   12446             :                 {
   12447       86118 :                     $$ = NULL;
   12448             :                 }
   12449             :         ;
   12450             : 
   12451             : returning_with_clause:
   12452          72 :             WITH '(' returning_options ')'      { $$ = $3; }
   12453        3086 :             | /* EMPTY */                       { $$ = NIL; }
   12454             :         ;
   12455             : 
   12456             : returning_options:
   12457          72 :             returning_option                            { $$ = list_make1($1); }
   12458          54 :             | returning_options ',' returning_option    { $$ = lappend($1, $3); }
   12459             :         ;
   12460             : 
   12461             : returning_option:
   12462             :             returning_option_kind AS ColId
   12463             :                 {
   12464         126 :                     ReturningOption *n = makeNode(ReturningOption);
   12465             : 
   12466         126 :                     n->option = $1;
   12467         126 :                     n->value = $3;
   12468         126 :                     n->location = @1;
   12469         126 :                     $$ = (Node *) n;
   12470             :                 }
   12471             :         ;
   12472             : 
   12473             : returning_option_kind:
   12474          54 :             OLD         { $$ = RETURNING_OPTION_OLD; }
   12475          72 :             | NEW       { $$ = RETURNING_OPTION_NEW; }
   12476             :         ;
   12477             : 
   12478             : 
   12479             : /*****************************************************************************
   12480             :  *
   12481             :  *      QUERY:
   12482             :  *              DELETE STATEMENTS
   12483             :  *
   12484             :  *****************************************************************************/
   12485             : 
   12486             : DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
   12487             :             using_clause where_or_current_clause returning_clause
   12488             :                 {
   12489        4624 :                     DeleteStmt *n = makeNode(DeleteStmt);
   12490             : 
   12491        4624 :                     n->relation = $4;
   12492        4624 :                     n->usingClause = $5;
   12493        4624 :                     n->whereClause = $6;
   12494        4624 :                     n->returningClause = $7;
   12495        4624 :                     n->withClause = $1;
   12496        4624 :                     $$ = (Node *) n;
   12497             :                 }
   12498             :         ;
   12499             : 
   12500             : using_clause:
   12501         108 :                 USING from_list                     { $$ = $2; }
   12502        4516 :             | /*EMPTY*/                             { $$ = NIL; }
   12503             :         ;
   12504             : 
   12505             : 
   12506             : /*****************************************************************************
   12507             :  *
   12508             :  *      QUERY:
   12509             :  *              LOCK TABLE
   12510             :  *
   12511             :  *****************************************************************************/
   12512             : 
   12513             : LockStmt:   LOCK_P opt_table relation_expr_list opt_lock opt_nowait
   12514             :                 {
   12515        2524 :                     LockStmt   *n = makeNode(LockStmt);
   12516             : 
   12517        2524 :                     n->relations = $3;
   12518        2524 :                     n->mode = $4;
   12519        2524 :                     n->nowait = $5;
   12520        2524 :                     $$ = (Node *) n;
   12521             :                 }
   12522             :         ;
   12523             : 
   12524        2416 : opt_lock:   IN_P lock_type MODE             { $$ = $2; }
   12525         108 :             | /*EMPTY*/                     { $$ = AccessExclusiveLock; }
   12526             :         ;
   12527             : 
   12528        1926 : lock_type:  ACCESS SHARE                    { $$ = AccessShareLock; }
   12529          14 :             | ROW SHARE                     { $$ = RowShareLock; }
   12530          88 :             | ROW EXCLUSIVE                 { $$ = RowExclusiveLock; }
   12531          66 :             | SHARE UPDATE EXCLUSIVE        { $$ = ShareUpdateExclusiveLock; }
   12532          80 :             | SHARE                         { $$ = ShareLock; }
   12533          14 :             | SHARE ROW EXCLUSIVE           { $$ = ShareRowExclusiveLock; }
   12534         102 :             | EXCLUSIVE                     { $$ = ExclusiveLock; }
   12535         126 :             | ACCESS EXCLUSIVE              { $$ = AccessExclusiveLock; }
   12536             :         ;
   12537             : 
   12538        1594 : opt_nowait: NOWAIT                          { $$ = true; }
   12539         960 :             | /*EMPTY*/                     { $$ = false; }
   12540             :         ;
   12541             : 
   12542             : opt_nowait_or_skip:
   12543          50 :             NOWAIT                          { $$ = LockWaitError; }
   12544         190 :             | SKIP LOCKED                   { $$ = LockWaitSkip; }
   12545        5024 :             | /*EMPTY*/                     { $$ = LockWaitBlock; }
   12546             :         ;
   12547             : 
   12548             : 
   12549             : /*****************************************************************************
   12550             :  *
   12551             :  *      QUERY:
   12552             :  *              UpdateStmt (UPDATE)
   12553             :  *
   12554             :  *****************************************************************************/
   12555             : 
   12556             : UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
   12557             :             SET set_clause_list
   12558             :             from_clause
   12559             :             where_or_current_clause
   12560             :             returning_clause
   12561             :                 {
   12562       14038 :                     UpdateStmt *n = makeNode(UpdateStmt);
   12563             : 
   12564       14038 :                     n->relation = $3;
   12565       14038 :                     n->targetList = $5;
   12566       14038 :                     n->fromClause = $6;
   12567       14038 :                     n->whereClause = $7;
   12568       14038 :                     n->returningClause = $8;
   12569       14038 :                     n->withClause = $1;
   12570       14038 :                     $$ = (Node *) n;
   12571             :                 }
   12572             :         ;
   12573             : 
   12574             : set_clause_list:
   12575       16890 :             set_clause                          { $$ = $1; }
   12576        4118 :             | set_clause_list ',' set_clause    { $$ = list_concat($1,$3); }
   12577             :         ;
   12578             : 
   12579             : set_clause:
   12580             :             set_target '=' a_expr
   12581             :                 {
   12582       20824 :                     $1->val = (Node *) $3;
   12583       20824 :                     $$ = list_make1($1);
   12584             :                 }
   12585             :             | '(' set_target_list ')' '=' a_expr
   12586             :                 {
   12587         184 :                     int         ncolumns = list_length($2);
   12588         184 :                     int         i = 1;
   12589             :                     ListCell   *col_cell;
   12590             : 
   12591             :                     /* Create a MultiAssignRef source for each target */
   12592         568 :                     foreach(col_cell, $2)
   12593             :                     {
   12594         384 :                         ResTarget  *res_col = (ResTarget *) lfirst(col_cell);
   12595         384 :                         MultiAssignRef *r = makeNode(MultiAssignRef);
   12596             : 
   12597         384 :                         r->source = (Node *) $5;
   12598         384 :                         r->colno = i;
   12599         384 :                         r->ncolumns = ncolumns;
   12600         384 :                         res_col->val = (Node *) r;
   12601         384 :                         i++;
   12602             :                     }
   12603             : 
   12604         184 :                     $$ = $2;
   12605             :                 }
   12606             :         ;
   12607             : 
   12608             : set_target:
   12609             :             ColId opt_indirection
   12610             :                 {
   12611       21214 :                     $$ = makeNode(ResTarget);
   12612       21214 :                     $$->name = $1;
   12613       21214 :                     $$->indirection = check_indirection($2, yyscanner);
   12614       21214 :                     $$->val = NULL;  /* upper production sets this */
   12615       21214 :                     $$->location = @1;
   12616             :                 }
   12617             :         ;
   12618             : 
   12619             : set_target_list:
   12620         190 :             set_target                              { $$ = list_make1($1); }
   12621         200 :             | set_target_list ',' set_target        { $$ = lappend($1,$3); }
   12622             :         ;
   12623             : 
   12624             : 
   12625             : /*****************************************************************************
   12626             :  *
   12627             :  *      QUERY:
   12628             :  *              MERGE
   12629             :  *
   12630             :  *****************************************************************************/
   12631             : 
   12632             : MergeStmt:
   12633             :             opt_with_clause MERGE INTO relation_expr_opt_alias
   12634             :             USING table_ref
   12635             :             ON a_expr
   12636             :             merge_when_list
   12637             :             returning_clause
   12638             :                 {
   12639        2082 :                     MergeStmt  *m = makeNode(MergeStmt);
   12640             : 
   12641        2082 :                     m->withClause = $1;
   12642        2082 :                     m->relation = $4;
   12643        2082 :                     m->sourceRelation = $6;
   12644        2082 :                     m->joinCondition = $8;
   12645        2082 :                     m->mergeWhenClauses = $9;
   12646        2082 :                     m->returningClause = $10;
   12647             : 
   12648        2082 :                     $$ = (Node *) m;
   12649             :                 }
   12650             :         ;
   12651             : 
   12652             : merge_when_list:
   12653        2082 :             merge_when_clause                       { $$ = list_make1($1); }
   12654        1164 :             | merge_when_list merge_when_clause     { $$ = lappend($1,$2); }
   12655             :         ;
   12656             : 
   12657             : /*
   12658             :  * A WHEN clause may be WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, or WHEN NOT
   12659             :  * MATCHED [BY TARGET]. The first two cases match target tuples, and support
   12660             :  * UPDATE/DELETE/DO NOTHING actions. The third case does not match target
   12661             :  * tuples, and only supports INSERT/DO NOTHING actions.
   12662             :  */
   12663             : merge_when_clause:
   12664             :             merge_when_tgt_matched opt_merge_when_condition THEN merge_update
   12665             :                 {
   12666        1550 :                     $4->matchKind = $1;
   12667        1550 :                     $4->condition = $2;
   12668             : 
   12669        1550 :                     $$ = (Node *) $4;
   12670             :                 }
   12671             :             | merge_when_tgt_matched opt_merge_when_condition THEN merge_delete
   12672             :                 {
   12673         518 :                     $4->matchKind = $1;
   12674         518 :                     $4->condition = $2;
   12675             : 
   12676         518 :                     $$ = (Node *) $4;
   12677             :                 }
   12678             :             | merge_when_tgt_not_matched opt_merge_when_condition THEN merge_insert
   12679             :                 {
   12680        1094 :                     $4->matchKind = $1;
   12681        1094 :                     $4->condition = $2;
   12682             : 
   12683        1094 :                     $$ = (Node *) $4;
   12684             :                 }
   12685             :             | merge_when_tgt_matched opt_merge_when_condition THEN DO NOTHING
   12686             :                 {
   12687          64 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12688             : 
   12689          64 :                     m->matchKind = $1;
   12690          64 :                     m->commandType = CMD_NOTHING;
   12691          64 :                     m->condition = $2;
   12692             : 
   12693          64 :                     $$ = (Node *) m;
   12694             :                 }
   12695             :             | merge_when_tgt_not_matched opt_merge_when_condition THEN DO NOTHING
   12696             :                 {
   12697          20 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12698             : 
   12699          20 :                     m->matchKind = $1;
   12700          20 :                     m->commandType = CMD_NOTHING;
   12701          20 :                     m->condition = $2;
   12702             : 
   12703          20 :                     $$ = (Node *) m;
   12704             :                 }
   12705             :         ;
   12706             : 
   12707             : merge_when_tgt_matched:
   12708        1970 :             WHEN MATCHED                    { $$ = MERGE_WHEN_MATCHED; }
   12709         180 :             | WHEN NOT MATCHED BY SOURCE    { $$ = MERGE_WHEN_NOT_MATCHED_BY_SOURCE; }
   12710             :         ;
   12711             : 
   12712             : merge_when_tgt_not_matched:
   12713        1120 :             WHEN NOT MATCHED                { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
   12714          18 :             | WHEN NOT MATCHED BY TARGET    { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
   12715             :         ;
   12716             : 
   12717             : opt_merge_when_condition:
   12718         808 :             AND a_expr              { $$ = $2; }
   12719        2480 :             |                       { $$ = NULL; }
   12720             :         ;
   12721             : 
   12722             : merge_update:
   12723             :             UPDATE SET set_clause_list
   12724             :                 {
   12725        1550 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12726        1550 :                     n->commandType = CMD_UPDATE;
   12727        1550 :                     n->override = OVERRIDING_NOT_SET;
   12728        1550 :                     n->targetList = $3;
   12729        1550 :                     n->values = NIL;
   12730             : 
   12731        1550 :                     $$ = n;
   12732             :                 }
   12733             :         ;
   12734             : 
   12735             : merge_delete:
   12736             :             DELETE_P
   12737             :                 {
   12738         518 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12739         518 :                     n->commandType = CMD_DELETE;
   12740         518 :                     n->override = OVERRIDING_NOT_SET;
   12741         518 :                     n->targetList = NIL;
   12742         518 :                     n->values = NIL;
   12743             : 
   12744         518 :                     $$ = n;
   12745             :                 }
   12746             :         ;
   12747             : 
   12748             : merge_insert:
   12749             :             INSERT merge_values_clause
   12750             :                 {
   12751         730 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12752         730 :                     n->commandType = CMD_INSERT;
   12753         730 :                     n->override = OVERRIDING_NOT_SET;
   12754         730 :                     n->targetList = NIL;
   12755         730 :                     n->values = $2;
   12756         730 :                     $$ = n;
   12757             :                 }
   12758             :             | INSERT OVERRIDING override_kind VALUE_P merge_values_clause
   12759             :                 {
   12760           0 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12761           0 :                     n->commandType = CMD_INSERT;
   12762           0 :                     n->override = $3;
   12763           0 :                     n->targetList = NIL;
   12764           0 :                     n->values = $5;
   12765           0 :                     $$ = n;
   12766             :                 }
   12767             :             | INSERT '(' insert_column_list ')' merge_values_clause
   12768             :                 {
   12769         298 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12770         298 :                     n->commandType = CMD_INSERT;
   12771         298 :                     n->override = OVERRIDING_NOT_SET;
   12772         298 :                     n->targetList = $3;
   12773         298 :                     n->values = $5;
   12774         298 :                     $$ = n;
   12775             :                 }
   12776             :             | INSERT '(' insert_column_list ')' OVERRIDING override_kind VALUE_P merge_values_clause
   12777             :                 {
   12778          30 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12779          30 :                     n->commandType = CMD_INSERT;
   12780          30 :                     n->override = $6;
   12781          30 :                     n->targetList = $3;
   12782          30 :                     n->values = $8;
   12783          30 :                     $$ = n;
   12784             :                 }
   12785             :             | INSERT DEFAULT VALUES
   12786             :                 {
   12787          36 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12788          36 :                     n->commandType = CMD_INSERT;
   12789          36 :                     n->override = OVERRIDING_NOT_SET;
   12790          36 :                     n->targetList = NIL;
   12791          36 :                     n->values = NIL;
   12792          36 :                     $$ = n;
   12793             :                 }
   12794             :         ;
   12795             : 
   12796             : merge_values_clause:
   12797             :             VALUES '(' expr_list ')'
   12798             :                 {
   12799        1058 :                     $$ = $3;
   12800             :                 }
   12801             :         ;
   12802             : 
   12803             : /*****************************************************************************
   12804             :  *
   12805             :  *      QUERY:
   12806             :  *              CURSOR STATEMENTS
   12807             :  *
   12808             :  *****************************************************************************/
   12809             : DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
   12810             :                 {
   12811        4582 :                     DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
   12812             : 
   12813        4582 :                     n->portalname = $2;
   12814             :                     /* currently we always set FAST_PLAN option */
   12815        4582 :                     n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
   12816        4582 :                     n->query = $7;
   12817        4582 :                     $$ = (Node *) n;
   12818             :                 }
   12819             :         ;
   12820             : 
   12821       14646 : cursor_name:    name                        { $$ = $1; }
   12822             :         ;
   12823             : 
   12824        4582 : cursor_options: /*EMPTY*/                   { $$ = 0; }
   12825          28 :             | cursor_options NO SCROLL      { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
   12826         240 :             | cursor_options SCROLL         { $$ = $1 | CURSOR_OPT_SCROLL; }
   12827          14 :             | cursor_options BINARY         { $$ = $1 | CURSOR_OPT_BINARY; }
   12828           0 :             | cursor_options ASENSITIVE     { $$ = $1 | CURSOR_OPT_ASENSITIVE; }
   12829           6 :             | cursor_options INSENSITIVE    { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
   12830             :         ;
   12831             : 
   12832        4484 : opt_hold: /* EMPTY */                       { $$ = 0; }
   12833          92 :             | WITH HOLD                     { $$ = CURSOR_OPT_HOLD; }
   12834           6 :             | WITHOUT HOLD                  { $$ = 0; }
   12835             :         ;
   12836             : 
   12837             : /*****************************************************************************
   12838             :  *
   12839             :  *      QUERY:
   12840             :  *              SELECT STATEMENTS
   12841             :  *
   12842             :  *****************************************************************************/
   12843             : 
   12844             : /* A complete SELECT statement looks like this.
   12845             :  *
   12846             :  * The rule returns either a single SelectStmt node or a tree of them,
   12847             :  * representing a set-operation tree.
   12848             :  *
   12849             :  * There is an ambiguity when a sub-SELECT is within an a_expr and there
   12850             :  * are excess parentheses: do the parentheses belong to the sub-SELECT or
   12851             :  * to the surrounding a_expr?  We don't really care, but bison wants to know.
   12852             :  * To resolve the ambiguity, we are careful to define the grammar so that
   12853             :  * the decision is staved off as long as possible: as long as we can keep
   12854             :  * absorbing parentheses into the sub-SELECT, we will do so, and only when
   12855             :  * it's no longer possible to do that will we decide that parens belong to
   12856             :  * the expression.  For example, in "SELECT (((SELECT 2)) + 3)" the extra
   12857             :  * parentheses are treated as part of the sub-select.  The necessity of doing
   12858             :  * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)".    Had we
   12859             :  * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
   12860             :  * SELECT viewpoint when we see the UNION.
   12861             :  *
   12862             :  * This approach is implemented by defining a nonterminal select_with_parens,
   12863             :  * which represents a SELECT with at least one outer layer of parentheses,
   12864             :  * and being careful to use select_with_parens, never '(' SelectStmt ')',
   12865             :  * in the expression grammar.  We will then have shift-reduce conflicts
   12866             :  * which we can resolve in favor of always treating '(' <select> ')' as
   12867             :  * a select_with_parens.  To resolve the conflicts, the productions that
   12868             :  * conflict with the select_with_parens productions are manually given
   12869             :  * precedences lower than the precedence of ')', thereby ensuring that we
   12870             :  * shift ')' (and then reduce to select_with_parens) rather than trying to
   12871             :  * reduce the inner <select> nonterminal to something else.  We use UMINUS
   12872             :  * precedence for this, which is a fairly arbitrary choice.
   12873             :  *
   12874             :  * To be able to define select_with_parens itself without ambiguity, we need
   12875             :  * a nonterminal select_no_parens that represents a SELECT structure with no
   12876             :  * outermost parentheses.  This is a little bit tedious, but it works.
   12877             :  *
   12878             :  * In non-expression contexts, we use SelectStmt which can represent a SELECT
   12879             :  * with or without outer parentheses.
   12880             :  */
   12881             : 
   12882             : SelectStmt: select_no_parens            %prec UMINUS
   12883             :             | select_with_parens        %prec UMINUS
   12884             :         ;
   12885             : 
   12886             : select_with_parens:
   12887       67066 :             '(' select_no_parens ')'                { $$ = $2; }
   12888         156 :             | '(' select_with_parens ')'            { $$ = $2; }
   12889             :         ;
   12890             : 
   12891             : /*
   12892             :  * This rule parses the equivalent of the standard's <query expression>.
   12893             :  * The duplicative productions are annoying, but hard to get rid of without
   12894             :  * creating shift/reduce conflicts.
   12895             :  *
   12896             :  *  The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
   12897             :  *  In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
   12898             :  *  We now support both orderings, but prefer LIMIT/OFFSET before the locking
   12899             :  * clause.
   12900             :  *  2002-08-28 bjm
   12901             :  */
   12902             : select_no_parens:
   12903      395830 :             simple_select                       { $$ = $1; }
   12904             :             | select_clause sort_clause
   12905             :                 {
   12906       72718 :                     insertSelectOptions((SelectStmt *) $1, $2, NIL,
   12907             :                                         NULL, NULL,
   12908             :                                         yyscanner);
   12909       72718 :                     $$ = $1;
   12910             :                 }
   12911             :             | select_clause opt_sort_clause for_locking_clause opt_select_limit
   12912             :                 {
   12913        4816 :                     insertSelectOptions((SelectStmt *) $1, $2, $3,
   12914        4816 :                                         $4,
   12915             :                                         NULL,
   12916             :                                         yyscanner);
   12917        4816 :                     $$ = $1;
   12918             :                 }
   12919             :             | select_clause opt_sort_clause select_limit opt_for_locking_clause
   12920             :                 {
   12921        4912 :                     insertSelectOptions((SelectStmt *) $1, $2, $4,
   12922        4912 :                                         $3,
   12923             :                                         NULL,
   12924             :                                         yyscanner);
   12925        4900 :                     $$ = $1;
   12926             :                 }
   12927             :             | with_clause select_clause
   12928             :                 {
   12929        2242 :                     insertSelectOptions((SelectStmt *) $2, NULL, NIL,
   12930             :                                         NULL,
   12931        2242 :                                         $1,
   12932             :                                         yyscanner);
   12933        2242 :                     $$ = $2;
   12934             :                 }
   12935             :             | with_clause select_clause sort_clause
   12936             :                 {
   12937         580 :                     insertSelectOptions((SelectStmt *) $2, $3, NIL,
   12938             :                                         NULL,
   12939         580 :                                         $1,
   12940             :                                         yyscanner);
   12941         580 :                     $$ = $2;
   12942             :                 }
   12943             :             | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
   12944             :                 {
   12945           6 :                     insertSelectOptions((SelectStmt *) $2, $3, $4,
   12946           6 :                                         $5,
   12947           6 :                                         $1,
   12948             :                                         yyscanner);
   12949           6 :                     $$ = $2;
   12950             :                 }
   12951             :             | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
   12952             :                 {
   12953          64 :                     insertSelectOptions((SelectStmt *) $2, $3, $5,
   12954          64 :                                         $4,
   12955          64 :                                         $1,
   12956             :                                         yyscanner);
   12957          64 :                     $$ = $2;
   12958             :                 }
   12959             :         ;
   12960             : 
   12961             : select_clause:
   12962      123704 :             simple_select                           { $$ = $1; }
   12963         590 :             | select_with_parens                    { $$ = $1; }
   12964             :         ;
   12965             : 
   12966             : /*
   12967             :  * This rule parses SELECT statements that can appear within set operations,
   12968             :  * including UNION, INTERSECT and EXCEPT.  '(' and ')' can be used to specify
   12969             :  * the ordering of the set operations.  Without '(' and ')' we want the
   12970             :  * operations to be ordered per the precedence specs at the head of this file.
   12971             :  *
   12972             :  * As with select_no_parens, simple_select cannot have outer parentheses,
   12973             :  * but can have parenthesized subclauses.
   12974             :  *
   12975             :  * It might appear that we could fold the first two alternatives into one
   12976             :  * by using opt_distinct_clause.  However, that causes a shift/reduce conflict
   12977             :  * against INSERT ... SELECT ... ON CONFLICT.  We avoid the ambiguity by
   12978             :  * requiring SELECT DISTINCT [ON] to be followed by a non-empty target_list.
   12979             :  *
   12980             :  * Note that sort clauses cannot be included at this level --- SQL requires
   12981             :  *      SELECT foo UNION SELECT bar ORDER BY baz
   12982             :  * to be parsed as
   12983             :  *      (SELECT foo UNION SELECT bar) ORDER BY baz
   12984             :  * not
   12985             :  *      SELECT foo UNION (SELECT bar ORDER BY baz)
   12986             :  * Likewise for WITH, FOR UPDATE and LIMIT.  Therefore, those clauses are
   12987             :  * described as part of the select_no_parens production, not simple_select.
   12988             :  * This does not limit functionality, because you can reintroduce these
   12989             :  * clauses inside parentheses.
   12990             :  *
   12991             :  * NOTE: only the leftmost component SelectStmt should have INTO.
   12992             :  * However, this is not checked by the grammar; parse analysis must check it.
   12993             :  */
   12994             : simple_select:
   12995             :             SELECT opt_all_clause opt_target_list
   12996             :             into_clause from_clause where_clause
   12997             :             group_clause having_clause window_clause
   12998             :                 {
   12999      437018 :                     SelectStmt *n = makeNode(SelectStmt);
   13000             : 
   13001      437018 :                     n->targetList = $3;
   13002      437018 :                     n->intoClause = $4;
   13003      437018 :                     n->fromClause = $5;
   13004      437018 :                     n->whereClause = $6;
   13005      437018 :                     n->groupClause = ($7)->list;
   13006      437018 :                     n->groupDistinct = ($7)->distinct;
   13007      437018 :                     n->havingClause = $8;
   13008      437018 :                     n->windowClause = $9;
   13009      437018 :                     $$ = (Node *) n;
   13010             :                 }
   13011             :             | SELECT distinct_clause target_list
   13012             :             into_clause from_clause where_clause
   13013             :             group_clause having_clause window_clause
   13014             :                 {
   13015        3754 :                     SelectStmt *n = makeNode(SelectStmt);
   13016             : 
   13017        3754 :                     n->distinctClause = $2;
   13018        3754 :                     n->targetList = $3;
   13019        3754 :                     n->intoClause = $4;
   13020        3754 :                     n->fromClause = $5;
   13021        3754 :                     n->whereClause = $6;
   13022        3754 :                     n->groupClause = ($7)->list;
   13023        3754 :                     n->groupDistinct = ($7)->distinct;
   13024        3754 :                     n->havingClause = $8;
   13025        3754 :                     n->windowClause = $9;
   13026        3754 :                     $$ = (Node *) n;
   13027             :                 }
   13028       58982 :             | values_clause                         { $$ = $1; }
   13029             :             | TABLE relation_expr
   13030             :                 {
   13031             :                     /* same as SELECT * FROM relation_expr */
   13032         308 :                     ColumnRef  *cr = makeNode(ColumnRef);
   13033         308 :                     ResTarget  *rt = makeNode(ResTarget);
   13034         308 :                     SelectStmt *n = makeNode(SelectStmt);
   13035             : 
   13036         308 :                     cr->fields = list_make1(makeNode(A_Star));
   13037         308 :                     cr->location = -1;
   13038             : 
   13039         308 :                     rt->name = NULL;
   13040         308 :                     rt->indirection = NIL;
   13041         308 :                     rt->val = (Node *) cr;
   13042         308 :                     rt->location = -1;
   13043             : 
   13044         308 :                     n->targetList = list_make1(rt);
   13045         308 :                     n->fromClause = list_make1($2);
   13046         308 :                     $$ = (Node *) n;
   13047             :                 }
   13048             :             | select_clause UNION set_quantifier select_clause
   13049             :                 {
   13050       18738 :                     $$ = makeSetOp(SETOP_UNION, $3 == SET_QUANTIFIER_ALL, $1, $4);
   13051             :                 }
   13052             :             | select_clause INTERSECT set_quantifier select_clause
   13053             :                 {
   13054         258 :                     $$ = makeSetOp(SETOP_INTERSECT, $3 == SET_QUANTIFIER_ALL, $1, $4);
   13055             :                 }
   13056             :             | select_clause EXCEPT set_quantifier select_clause
   13057             :                 {
   13058         476 :                     $$ = makeSetOp(SETOP_EXCEPT, $3 == SET_QUANTIFIER_ALL, $1, $4);
   13059             :                 }
   13060             :         ;
   13061             : 
   13062             : /*
   13063             :  * SQL standard WITH clause looks like:
   13064             :  *
   13065             :  * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
   13066             :  *      AS (query) [ SEARCH or CYCLE clause ]
   13067             :  *
   13068             :  * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
   13069             :  */
   13070             : with_clause:
   13071             :         WITH cte_list
   13072             :             {
   13073        2014 :                 $$ = makeNode(WithClause);
   13074        2014 :                 $$->ctes = $2;
   13075        2014 :                 $$->recursive = false;
   13076        2014 :                 $$->location = @1;
   13077             :             }
   13078             :         | WITH_LA cte_list
   13079             :             {
   13080           6 :                 $$ = makeNode(WithClause);
   13081           6 :                 $$->ctes = $2;
   13082           6 :                 $$->recursive = false;
   13083           6 :                 $$->location = @1;
   13084             :             }
   13085             :         | WITH RECURSIVE cte_list
   13086             :             {
   13087        1326 :                 $$ = makeNode(WithClause);
   13088        1326 :                 $$->ctes = $3;
   13089        1326 :                 $$->recursive = true;
   13090        1326 :                 $$->location = @1;
   13091             :             }
   13092             :         ;
   13093             : 
   13094             : cte_list:
   13095        3346 :         common_table_expr                       { $$ = list_make1($1); }
   13096        1204 :         | cte_list ',' common_table_expr        { $$ = lappend($1, $3); }
   13097             :         ;
   13098             : 
   13099             : common_table_expr:  name opt_name_list AS opt_materialized '(' PreparableStmt ')' opt_search_clause opt_cycle_clause
   13100             :             {
   13101        4550 :                 CommonTableExpr *n = makeNode(CommonTableExpr);
   13102             : 
   13103        4550 :                 n->ctename = $1;
   13104        4550 :                 n->aliascolnames = $2;
   13105        4550 :                 n->ctematerialized = $4;
   13106        4550 :                 n->ctequery = $6;
   13107        4550 :                 n->search_clause = castNode(CTESearchClause, $8);
   13108        4550 :                 n->cycle_clause = castNode(CTECycleClause, $9);
   13109        4550 :                 n->location = @1;
   13110        4550 :                 $$ = (Node *) n;
   13111             :             }
   13112             :         ;
   13113             : 
   13114             : opt_materialized:
   13115         178 :         MATERIALIZED                            { $$ = CTEMaterializeAlways; }
   13116          48 :         | NOT MATERIALIZED                      { $$ = CTEMaterializeNever; }
   13117        4324 :         | /*EMPTY*/                             { $$ = CTEMaterializeDefault; }
   13118             :         ;
   13119             : 
   13120             : opt_search_clause:
   13121             :         SEARCH DEPTH FIRST_P BY columnList SET ColId
   13122             :             {
   13123          90 :                 CTESearchClause *n = makeNode(CTESearchClause);
   13124             : 
   13125          90 :                 n->search_col_list = $5;
   13126          90 :                 n->search_breadth_first = false;
   13127          90 :                 n->search_seq_column = $7;
   13128          90 :                 n->location = @1;
   13129          90 :                 $$ = (Node *) n;
   13130             :             }
   13131             :         | SEARCH BREADTH FIRST_P BY columnList SET ColId
   13132             :             {
   13133          36 :                 CTESearchClause *n = makeNode(CTESearchClause);
   13134             : 
   13135          36 :                 n->search_col_list = $5;
   13136          36 :                 n->search_breadth_first = true;
   13137          36 :                 n->search_seq_column = $7;
   13138          36 :                 n->location = @1;
   13139          36 :                 $$ = (Node *) n;
   13140             :             }
   13141             :         | /*EMPTY*/
   13142             :             {
   13143        4424 :                 $$ = NULL;
   13144             :             }
   13145             :         ;
   13146             : 
   13147             : opt_cycle_clause:
   13148             :         CYCLE columnList SET ColId TO AexprConst DEFAULT AexprConst USING ColId
   13149             :             {
   13150          66 :                 CTECycleClause *n = makeNode(CTECycleClause);
   13151             : 
   13152          66 :                 n->cycle_col_list = $2;
   13153          66 :                 n->cycle_mark_column = $4;
   13154          66 :                 n->cycle_mark_value = $6;
   13155          66 :                 n->cycle_mark_default = $8;
   13156          66 :                 n->cycle_path_column = $10;
   13157          66 :                 n->location = @1;
   13158          66 :                 $$ = (Node *) n;
   13159             :             }
   13160             :         | CYCLE columnList SET ColId USING ColId
   13161             :             {
   13162          60 :                 CTECycleClause *n = makeNode(CTECycleClause);
   13163             : 
   13164          60 :                 n->cycle_col_list = $2;
   13165          60 :                 n->cycle_mark_column = $4;
   13166          60 :                 n->cycle_mark_value = makeBoolAConst(true, -1);
   13167          60 :                 n->cycle_mark_default = makeBoolAConst(false, -1);
   13168          60 :                 n->cycle_path_column = $6;
   13169          60 :                 n->location = @1;
   13170          60 :                 $$ = (Node *) n;
   13171             :             }
   13172             :         | /*EMPTY*/
   13173             :             {
   13174        4424 :                 $$ = NULL;
   13175             :             }
   13176             :         ;
   13177             : 
   13178             : opt_with_clause:
   13179         454 :         with_clause                             { $$ = $1; }
   13180       88938 :         | /*EMPTY*/                             { $$ = NULL; }
   13181             :         ;
   13182             : 
   13183             : into_clause:
   13184             :             INTO OptTempTableName
   13185             :                 {
   13186         138 :                     $$ = makeNode(IntoClause);
   13187         138 :                     $$->rel = $2;
   13188         138 :                     $$->colNames = NIL;
   13189         138 :                     $$->options = NIL;
   13190         138 :                     $$->onCommit = ONCOMMIT_NOOP;
   13191         138 :                     $$->tableSpaceName = NULL;
   13192         138 :                     $$->viewQuery = NULL;
   13193         138 :                     $$->skipData = false;
   13194             :                 }
   13195             :             | /*EMPTY*/
   13196      440664 :                 { $$ = NULL; }
   13197             :         ;
   13198             : 
   13199             : /*
   13200             :  * Redundancy here is needed to avoid shift/reduce conflicts,
   13201             :  * since TEMP is not a reserved word.  See also OptTemp.
   13202             :  */
   13203             : OptTempTableName:
   13204             :             TEMPORARY opt_table qualified_name
   13205             :                 {
   13206           0 :                     $$ = $3;
   13207           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13208             :                 }
   13209             :             | TEMP opt_table qualified_name
   13210             :                 {
   13211           6 :                     $$ = $3;
   13212           6 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13213             :                 }
   13214             :             | LOCAL TEMPORARY opt_table qualified_name
   13215             :                 {
   13216           0 :                     $$ = $4;
   13217           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13218             :                 }
   13219             :             | LOCAL TEMP opt_table qualified_name
   13220             :                 {
   13221           0 :                     $$ = $4;
   13222           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13223             :                 }
   13224             :             | GLOBAL TEMPORARY opt_table qualified_name
   13225             :                 {
   13226           0 :                     ereport(WARNING,
   13227             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   13228             :                              parser_errposition(@1)));
   13229           0 :                     $$ = $4;
   13230           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13231             :                 }
   13232             :             | GLOBAL TEMP opt_table qualified_name
   13233             :                 {
   13234           0 :                     ereport(WARNING,
   13235             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   13236             :                              parser_errposition(@1)));
   13237           0 :                     $$ = $4;
   13238           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13239             :                 }
   13240             :             | UNLOGGED opt_table qualified_name
   13241             :                 {
   13242           0 :                     $$ = $3;
   13243           0 :                     $$->relpersistence = RELPERSISTENCE_UNLOGGED;
   13244             :                 }
   13245             :             | TABLE qualified_name
   13246             :                 {
   13247          30 :                     $$ = $2;
   13248          30 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   13249             :                 }
   13250             :             | qualified_name
   13251             :                 {
   13252         102 :                     $$ = $1;
   13253         102 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   13254             :                 }
   13255             :         ;
   13256             : 
   13257             : opt_table:  TABLE
   13258             :             | /*EMPTY*/
   13259             :         ;
   13260             : 
   13261             : set_quantifier:
   13262       10822 :             ALL                                     { $$ = SET_QUANTIFIER_ALL; }
   13263          32 :             | DISTINCT                              { $$ = SET_QUANTIFIER_DISTINCT; }
   13264       13268 :             | /*EMPTY*/                             { $$ = SET_QUANTIFIER_DEFAULT; }
   13265             :         ;
   13266             : 
   13267             : /* We use (NIL) as a placeholder to indicate that all target expressions
   13268             :  * should be placed in the DISTINCT list during parsetree analysis.
   13269             :  */
   13270             : distinct_clause:
   13271        3500 :             DISTINCT                                { $$ = list_make1(NIL); }
   13272         260 :             | DISTINCT ON '(' expr_list ')'         { $$ = $4; }
   13273             :         ;
   13274             : 
   13275             : opt_all_clause:
   13276             :             ALL
   13277             :             | /*EMPTY*/
   13278             :         ;
   13279             : 
   13280             : opt_distinct_clause:
   13281           0 :             distinct_clause                         { $$ = $1; }
   13282       40044 :             | opt_all_clause                        { $$ = NIL; }
   13283             :         ;
   13284             : 
   13285             : opt_sort_clause:
   13286        7706 :             sort_clause                             { $$ = $1; }
   13287      369666 :             | /*EMPTY*/                             { $$ = NIL; }
   13288             :         ;
   13289             : 
   13290             : sort_clause:
   13291       81352 :             ORDER BY sortby_list                    { $$ = $3; }
   13292             :         ;
   13293             : 
   13294             : sortby_list:
   13295       81370 :             sortby                                  { $$ = list_make1($1); }
   13296       30042 :             | sortby_list ',' sortby                { $$ = lappend($1, $3); }
   13297             :         ;
   13298             : 
   13299             : sortby:     a_expr USING qual_all_Op opt_nulls_order
   13300             :                 {
   13301         220 :                     $$ = makeNode(SortBy);
   13302         220 :                     $$->node = $1;
   13303         220 :                     $$->sortby_dir = SORTBY_USING;
   13304         220 :                     $$->sortby_nulls = $4;
   13305         220 :                     $$->useOp = $3;
   13306         220 :                     $$->location = @3;
   13307             :                 }
   13308             :             | a_expr opt_asc_desc opt_nulls_order
   13309             :                 {
   13310      111192 :                     $$ = makeNode(SortBy);
   13311      111192 :                     $$->node = $1;
   13312      111192 :                     $$->sortby_dir = $2;
   13313      111192 :                     $$->sortby_nulls = $3;
   13314      111192 :                     $$->useOp = NIL;
   13315      111192 :                     $$->location = -1;       /* no operator */
   13316             :                 }
   13317             :         ;
   13318             : 
   13319             : 
   13320             : select_limit:
   13321             :             limit_clause offset_clause
   13322             :                 {
   13323         172 :                     $$ = $1;
   13324         172 :                     ($$)->limitOffset = $2;
   13325         172 :                     ($$)->offsetLoc = @2;
   13326             :                 }
   13327             :             | offset_clause limit_clause
   13328             :                 {
   13329         226 :                     $$ = $2;
   13330         226 :                     ($$)->limitOffset = $1;
   13331         226 :                     ($$)->offsetLoc = @1;
   13332             :                 }
   13333             :             | limit_clause
   13334             :                 {
   13335        4318 :                     $$ = $1;
   13336             :                 }
   13337             :             | offset_clause
   13338             :                 {
   13339         450 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13340             : 
   13341         450 :                     n->limitOffset = $1;
   13342         450 :                     n->limitCount = NULL;
   13343         450 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13344         450 :                     n->offsetLoc = @1;
   13345         450 :                     n->countLoc = -1;
   13346         450 :                     n->optionLoc = -1;
   13347         450 :                     $$ = n;
   13348             :                 }
   13349             :         ;
   13350             : 
   13351             : opt_select_limit:
   13352         190 :             select_limit                        { $$ = $1; }
   13353       44676 :             | /* EMPTY */                       { $$ = NULL; }
   13354             :         ;
   13355             : 
   13356             : limit_clause:
   13357             :             LIMIT select_limit_value
   13358             :                 {
   13359        4614 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13360             : 
   13361        4614 :                     n->limitOffset = NULL;
   13362        4614 :                     n->limitCount = $2;
   13363        4614 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13364        4614 :                     n->offsetLoc = -1;
   13365        4614 :                     n->countLoc = @1;
   13366        4614 :                     n->optionLoc = -1;
   13367        4614 :                     $$ = n;
   13368             :                 }
   13369             :             | LIMIT select_limit_value ',' select_offset_value
   13370             :                 {
   13371             :                     /* Disabled because it was too confusing, bjm 2002-02-18 */
   13372           0 :                     ereport(ERROR,
   13373             :                             (errcode(ERRCODE_SYNTAX_ERROR),
   13374             :                              errmsg("LIMIT #,# syntax is not supported"),
   13375             :                              errhint("Use separate LIMIT and OFFSET clauses."),
   13376             :                              parser_errposition(@1)));
   13377             :                 }
   13378             :             /* SQL:2008 syntax */
   13379             :             /* to avoid shift/reduce conflicts, handle the optional value with
   13380             :              * a separate production rather than an opt_ expression.  The fact
   13381             :              * that ONLY is fully reserved means that this way, we defer any
   13382             :              * decision about what rule reduces ROW or ROWS to the point where
   13383             :              * we can see the ONLY token in the lookahead slot.
   13384             :              */
   13385             :             | FETCH first_or_next select_fetch_first_value row_or_rows ONLY
   13386             :                 {
   13387          24 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13388             : 
   13389          24 :                     n->limitOffset = NULL;
   13390          24 :                     n->limitCount = $3;
   13391          24 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13392          24 :                     n->offsetLoc = -1;
   13393          24 :                     n->countLoc = @1;
   13394          24 :                     n->optionLoc = -1;
   13395          24 :                     $$ = n;
   13396             :                 }
   13397             :             | FETCH first_or_next select_fetch_first_value row_or_rows WITH TIES
   13398             :                 {
   13399          72 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13400             : 
   13401          72 :                     n->limitOffset = NULL;
   13402          72 :                     n->limitCount = $3;
   13403          72 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13404          72 :                     n->offsetLoc = -1;
   13405          72 :                     n->countLoc = @1;
   13406          72 :                     n->optionLoc = @5;
   13407          72 :                     $$ = n;
   13408             :                 }
   13409             :             | FETCH first_or_next row_or_rows ONLY
   13410             :                 {
   13411           0 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13412             : 
   13413           0 :                     n->limitOffset = NULL;
   13414           0 :                     n->limitCount = makeIntConst(1, -1);
   13415           0 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13416           0 :                     n->offsetLoc = -1;
   13417           0 :                     n->countLoc = @1;
   13418           0 :                     n->optionLoc = -1;
   13419           0 :                     $$ = n;
   13420             :                 }
   13421             :             | FETCH first_or_next row_or_rows WITH TIES
   13422             :                 {
   13423           6 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13424             : 
   13425           6 :                     n->limitOffset = NULL;
   13426           6 :                     n->limitCount = makeIntConst(1, -1);
   13427           6 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13428           6 :                     n->offsetLoc = -1;
   13429           6 :                     n->countLoc = @1;
   13430           6 :                     n->optionLoc = @4;
   13431           6 :                     $$ = n;
   13432             :                 }
   13433             :         ;
   13434             : 
   13435             : offset_clause:
   13436             :             OFFSET select_offset_value
   13437         848 :                 { $$ = $2; }
   13438             :             /* SQL:2008 syntax */
   13439             :             | OFFSET select_fetch_first_value row_or_rows
   13440           0 :                 { $$ = $2; }
   13441             :         ;
   13442             : 
   13443             : select_limit_value:
   13444        4610 :             a_expr                                  { $$ = $1; }
   13445             :             | ALL
   13446             :                 {
   13447             :                     /* LIMIT ALL is represented as a NULL constant */
   13448           4 :                     $$ = makeNullAConst(@1);
   13449             :                 }
   13450             :         ;
   13451             : 
   13452             : select_offset_value:
   13453         848 :             a_expr                                  { $$ = $1; }
   13454             :         ;
   13455             : 
   13456             : /*
   13457             :  * Allowing full expressions without parentheses causes various parsing
   13458             :  * problems with the trailing ROW/ROWS key words.  SQL spec only calls for
   13459             :  * <simple value specification>, which is either a literal or a parameter (but
   13460             :  * an <SQL parameter reference> could be an identifier, bringing up conflicts
   13461             :  * with ROW/ROWS). We solve this by leveraging the presence of ONLY (see above)
   13462             :  * to determine whether the expression is missing rather than trying to make it
   13463             :  * optional in this rule.
   13464             :  *
   13465             :  * c_expr covers almost all the spec-required cases (and more), but it doesn't
   13466             :  * cover signed numeric literals, which are allowed by the spec. So we include
   13467             :  * those here explicitly. We need FCONST as well as ICONST because values that
   13468             :  * don't fit in the platform's "long", but do fit in bigint, should still be
   13469             :  * accepted here. (This is possible in 64-bit Windows as well as all 32-bit
   13470             :  * builds.)
   13471             :  */
   13472             : select_fetch_first_value:
   13473          96 :             c_expr                                  { $$ = $1; }
   13474             :             | '+' I_or_F_const
   13475           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   13476             :             | '-' I_or_F_const
   13477           0 :                 { $$ = doNegate($2, @1); }
   13478             :         ;
   13479             : 
   13480             : I_or_F_const:
   13481           0 :             Iconst                                  { $$ = makeIntConst($1,@1); }
   13482           0 :             | FCONST                                { $$ = makeFloatConst($1,@1); }
   13483             :         ;
   13484             : 
   13485             : /* noise words */
   13486          36 : row_or_rows: ROW                                    { $$ = 0; }
   13487          66 :             | ROWS                                  { $$ = 0; }
   13488             :         ;
   13489             : 
   13490         102 : first_or_next: FIRST_P                              { $$ = 0; }
   13491           0 :             | NEXT                                  { $$ = 0; }
   13492             :         ;
   13493             : 
   13494             : 
   13495             : /*
   13496             :  * This syntax for group_clause tries to follow the spec quite closely.
   13497             :  * However, the spec allows only column references, not expressions,
   13498             :  * which introduces an ambiguity between implicit row constructors
   13499             :  * (a,b) and lists of column references.
   13500             :  *
   13501             :  * We handle this by using the a_expr production for what the spec calls
   13502             :  * <ordinary grouping set>, which in the spec represents either one column
   13503             :  * reference or a parenthesized list of column references. Then, we check the
   13504             :  * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
   13505             :  * grab and use the list, discarding the node. (this is done in parse analysis,
   13506             :  * not here)
   13507             :  *
   13508             :  * (we abuse the row_format field of RowExpr to distinguish implicit and
   13509             :  * explicit row constructors; it's debatable if anyone sanely wants to use them
   13510             :  * in a group clause, but if they have a reason to, we make it possible.)
   13511             :  *
   13512             :  * Each item in the group_clause list is either an expression tree or a
   13513             :  * GroupingSet node of some type.
   13514             :  */
   13515             : group_clause:
   13516             :             GROUP_P BY set_quantifier group_by_list
   13517             :                 {
   13518        4638 :                     GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
   13519             : 
   13520        4638 :                     n->distinct = $3 == SET_QUANTIFIER_DISTINCT;
   13521        4638 :                     n->list = $4;
   13522        4638 :                     $$ = n;
   13523             :                 }
   13524             :             | /*EMPTY*/
   13525             :                 {
   13526      476178 :                     GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
   13527             : 
   13528      476178 :                     n->distinct = false;
   13529      476178 :                     n->list = NIL;
   13530      476178 :                     $$ = n;
   13531             :                 }
   13532             :         ;
   13533             : 
   13534             : group_by_list:
   13535        5236 :             group_by_item                           { $$ = list_make1($1); }
   13536        3036 :             | group_by_list ',' group_by_item       { $$ = lappend($1,$3); }
   13537             :         ;
   13538             : 
   13539             : group_by_item:
   13540        6982 :             a_expr                                  { $$ = $1; }
   13541         222 :             | empty_grouping_set                    { $$ = $1; }
   13542         184 :             | cube_clause                           { $$ = $1; }
   13543         286 :             | rollup_clause                         { $$ = $1; }
   13544         598 :             | grouping_sets_clause                  { $$ = $1; }
   13545             :         ;
   13546             : 
   13547             : empty_grouping_set:
   13548             :             '(' ')'
   13549             :                 {
   13550         222 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, @1);
   13551             :                 }
   13552             :         ;
   13553             : 
   13554             : /*
   13555             :  * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
   13556             :  * so that they shift in these rules rather than reducing the conflicting
   13557             :  * unreserved_keyword rule.
   13558             :  */
   13559             : 
   13560             : rollup_clause:
   13561             :             ROLLUP '(' expr_list ')'
   13562             :                 {
   13563         286 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_ROLLUP, $3, @1);
   13564             :                 }
   13565             :         ;
   13566             : 
   13567             : cube_clause:
   13568             :             CUBE '(' expr_list ')'
   13569             :                 {
   13570         184 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_CUBE, $3, @1);
   13571             :                 }
   13572             :         ;
   13573             : 
   13574             : grouping_sets_clause:
   13575             :             GROUPING SETS '(' group_by_list ')'
   13576             :                 {
   13577         598 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_SETS, $4, @1);
   13578             :                 }
   13579             :         ;
   13580             : 
   13581             : having_clause:
   13582         684 :             HAVING a_expr                           { $$ = $2; }
   13583      480132 :             | /*EMPTY*/                             { $$ = NULL; }
   13584             :         ;
   13585             : 
   13586             : for_locking_clause:
   13587        5162 :             for_locking_items                       { $$ = $1; }
   13588           0 :             | FOR READ ONLY                         { $$ = NIL; }
   13589             :         ;
   13590             : 
   13591             : opt_for_locking_clause:
   13592         340 :             for_locking_clause                      { $$ = $1; }
   13593       44680 :             | /* EMPTY */                           { $$ = NIL; }
   13594             :         ;
   13595             : 
   13596             : for_locking_items:
   13597        5162 :             for_locking_item                        { $$ = list_make1($1); }
   13598         102 :             | for_locking_items for_locking_item    { $$ = lappend($1, $2); }
   13599             :         ;
   13600             : 
   13601             : for_locking_item:
   13602             :             for_locking_strength locked_rels_list opt_nowait_or_skip
   13603             :                 {
   13604        5264 :                     LockingClause *n = makeNode(LockingClause);
   13605             : 
   13606        5264 :                     n->lockedRels = $2;
   13607        5264 :                     n->strength = $1;
   13608        5264 :                     n->waitPolicy = $3;
   13609        5264 :                     $$ = (Node *) n;
   13610             :                 }
   13611             :         ;
   13612             : 
   13613             : for_locking_strength:
   13614        1526 :             FOR UPDATE                          { $$ = LCS_FORUPDATE; }
   13615          76 :             | FOR NO KEY UPDATE                 { $$ = LCS_FORNOKEYUPDATE; }
   13616         214 :             | FOR SHARE                         { $$ = LCS_FORSHARE; }
   13617        3448 :             | FOR KEY SHARE                     { $$ = LCS_FORKEYSHARE; }
   13618             :         ;
   13619             : 
   13620             : locked_rels_list:
   13621        3474 :             OF qualified_name_list                  { $$ = $2; }
   13622        1790 :             | /* EMPTY */                           { $$ = NIL; }
   13623             :         ;
   13624             : 
   13625             : 
   13626             : /*
   13627             :  * We should allow ROW '(' expr_list ')' too, but that seems to require
   13628             :  * making VALUES a fully reserved word, which will probably break more apps
   13629             :  * than allowing the noise-word is worth.
   13630             :  */
   13631             : values_clause:
   13632             :             VALUES '(' expr_list ')'
   13633             :                 {
   13634       58982 :                     SelectStmt *n = makeNode(SelectStmt);
   13635             : 
   13636       58982 :                     n->valuesLists = list_make1($3);
   13637       58982 :                     $$ = (Node *) n;
   13638             :                 }
   13639             :             | values_clause ',' '(' expr_list ')'
   13640             :                 {
   13641       25198 :                     SelectStmt *n = (SelectStmt *) $1;
   13642             : 
   13643       25198 :                     n->valuesLists = lappend(n->valuesLists, $4);
   13644       25198 :                     $$ = (Node *) n;
   13645             :                 }
   13646             :         ;
   13647             : 
   13648             : 
   13649             : /*****************************************************************************
   13650             :  *
   13651             :  *  clauses common to all Optimizable Stmts:
   13652             :  *      from_clause     - allow list of both JOIN expressions and table names
   13653             :  *      where_clause    - qualifications for joins or restrictions
   13654             :  *
   13655             :  *****************************************************************************/
   13656             : 
   13657             : from_clause:
   13658      321598 :             FROM from_list                          { $$ = $2; }
   13659      173256 :             | /*EMPTY*/                             { $$ = NIL; }
   13660             :         ;
   13661             : 
   13662             : from_list:
   13663      322408 :             table_ref                               { $$ = list_make1($1); }
   13664       61784 :             | from_list ',' table_ref               { $$ = lappend($1, $3); }
   13665             :         ;
   13666             : 
   13667             : /*
   13668             :  * table_ref is where an alias clause can be attached.
   13669             :  */
   13670             : table_ref:  relation_expr opt_alias_clause
   13671             :                 {
   13672      407162 :                     $1->alias = $2;
   13673      407162 :                     $$ = (Node *) $1;
   13674             :                 }
   13675             :             | relation_expr opt_alias_clause tablesample_clause
   13676             :                 {
   13677         264 :                     RangeTableSample *n = (RangeTableSample *) $3;
   13678             : 
   13679         264 :                     $1->alias = $2;
   13680             :                     /* relation_expr goes inside the RangeTableSample node */
   13681         264 :                     n->relation = (Node *) $1;
   13682         264 :                     $$ = (Node *) n;
   13683             :                 }
   13684             :             | func_table func_alias_clause
   13685             :                 {
   13686       47638 :                     RangeFunction *n = (RangeFunction *) $1;
   13687             : 
   13688       47638 :                     n->alias = linitial($2);
   13689       47638 :                     n->coldeflist = lsecond($2);
   13690       47638 :                     $$ = (Node *) n;
   13691             :                 }
   13692             :             | LATERAL_P func_table func_alias_clause
   13693             :                 {
   13694        1156 :                     RangeFunction *n = (RangeFunction *) $2;
   13695             : 
   13696        1156 :                     n->lateral = true;
   13697        1156 :                     n->alias = linitial($3);
   13698        1156 :                     n->coldeflist = lsecond($3);
   13699        1156 :                     $$ = (Node *) n;
   13700             :                 }
   13701             :             | xmltable opt_alias_clause
   13702             :                 {
   13703          82 :                     RangeTableFunc *n = (RangeTableFunc *) $1;
   13704             : 
   13705          82 :                     n->alias = $2;
   13706          82 :                     $$ = (Node *) n;
   13707             :                 }
   13708             :             | LATERAL_P xmltable opt_alias_clause
   13709             :                 {
   13710         142 :                     RangeTableFunc *n = (RangeTableFunc *) $2;
   13711             : 
   13712         142 :                     n->lateral = true;
   13713         142 :                     n->alias = $3;
   13714         142 :                     $$ = (Node *) n;
   13715             :                 }
   13716             :             | select_with_parens opt_alias_clause
   13717             :                 {
   13718       14042 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13719             : 
   13720       14042 :                     n->lateral = false;
   13721       14042 :                     n->subquery = $1;
   13722       14042 :                     n->alias = $2;
   13723       14042 :                     $$ = (Node *) n;
   13724             :                 }
   13725             :             | LATERAL_P select_with_parens opt_alias_clause
   13726             :                 {
   13727        1904 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13728             : 
   13729        1904 :                     n->lateral = true;
   13730        1904 :                     n->subquery = $2;
   13731        1904 :                     n->alias = $3;
   13732        1904 :                     $$ = (Node *) n;
   13733             :                 }
   13734             :             | joined_table
   13735             :                 {
   13736       86424 :                     $$ = (Node *) $1;
   13737             :                 }
   13738             :             | '(' joined_table ')' alias_clause
   13739             :                 {
   13740         174 :                     $2->alias = $4;
   13741         174 :                     $$ = (Node *) $2;
   13742             :                 }
   13743             :             | json_table opt_alias_clause
   13744             :                 {
   13745         524 :                     JsonTable  *jt = castNode(JsonTable, $1);
   13746             : 
   13747         524 :                     jt->alias = $2;
   13748         524 :                     $$ = (Node *) jt;
   13749             :                 }
   13750             :             | LATERAL_P json_table opt_alias_clause
   13751             :                 {
   13752           0 :                     JsonTable  *jt = castNode(JsonTable, $2);
   13753             : 
   13754           0 :                     jt->alias = $3;
   13755           0 :                     jt->lateral = true;
   13756           0 :                     $$ = (Node *) jt;
   13757             :                 }
   13758             :         ;
   13759             : 
   13760             : 
   13761             : /*
   13762             :  * It may seem silly to separate joined_table from table_ref, but there is
   13763             :  * method in SQL's madness: if you don't do it this way you get reduce-
   13764             :  * reduce conflicts, because it's not clear to the parser generator whether
   13765             :  * to expect alias_clause after ')' or not.  For the same reason we must
   13766             :  * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
   13767             :  * join_type to expand to empty; if we try it, the parser generator can't
   13768             :  * figure out when to reduce an empty join_type right after table_ref.
   13769             :  *
   13770             :  * Note that a CROSS JOIN is the same as an unqualified
   13771             :  * INNER JOIN, and an INNER JOIN/ON has the same shape
   13772             :  * but a qualification expression to limit membership.
   13773             :  * A NATURAL JOIN implicitly matches column names between
   13774             :  * tables and the shape is determined by which columns are
   13775             :  * in common. We'll collect columns during the later transformations.
   13776             :  */
   13777             : 
   13778             : joined_table:
   13779             :             '(' joined_table ')'
   13780             :                 {
   13781        4014 :                     $$ = $2;
   13782             :                 }
   13783             :             | table_ref CROSS JOIN table_ref
   13784             :                 {
   13785             :                     /* CROSS JOIN is same as unqualified inner join */
   13786         504 :                     JoinExpr   *n = makeNode(JoinExpr);
   13787             : 
   13788         504 :                     n->jointype = JOIN_INNER;
   13789         504 :                     n->isNatural = false;
   13790         504 :                     n->larg = $1;
   13791         504 :                     n->rarg = $4;
   13792         504 :                     n->usingClause = NIL;
   13793         504 :                     n->join_using_alias = NULL;
   13794         504 :                     n->quals = NULL;
   13795         504 :                     $$ = n;
   13796             :                 }
   13797             :             | table_ref join_type JOIN table_ref join_qual
   13798             :                 {
   13799       48688 :                     JoinExpr   *n = makeNode(JoinExpr);
   13800             : 
   13801       48688 :                     n->jointype = $2;
   13802       48688 :                     n->isNatural = false;
   13803       48688 :                     n->larg = $1;
   13804       48688 :                     n->rarg = $4;
   13805       48688 :                     if ($5 != NULL && IsA($5, List))
   13806             :                     {
   13807             :                          /* USING clause */
   13808         498 :                         n->usingClause = linitial_node(List, castNode(List, $5));
   13809         498 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $5));
   13810             :                     }
   13811             :                     else
   13812             :                     {
   13813             :                         /* ON clause */
   13814       48190 :                         n->quals = $5;
   13815             :                     }
   13816       48688 :                     $$ = n;
   13817             :                 }
   13818             :             | table_ref JOIN table_ref join_qual
   13819             :                 {
   13820             :                     /* letting join_type reduce to empty doesn't work */
   13821       37148 :                     JoinExpr   *n = makeNode(JoinExpr);
   13822             : 
   13823       37148 :                     n->jointype = JOIN_INNER;
   13824       37148 :                     n->isNatural = false;
   13825       37148 :                     n->larg = $1;
   13826       37148 :                     n->rarg = $3;
   13827       37148 :                     if ($4 != NULL && IsA($4, List))
   13828             :                     {
   13829             :                         /* USING clause */
   13830         752 :                         n->usingClause = linitial_node(List, castNode(List, $4));
   13831         752 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $4));
   13832             :                     }
   13833             :                     else
   13834             :                     {
   13835             :                         /* ON clause */
   13836       36396 :                         n->quals = $4;
   13837             :                     }
   13838       37148 :                     $$ = n;
   13839             :                 }
   13840             :             | table_ref NATURAL join_type JOIN table_ref
   13841             :                 {
   13842          78 :                     JoinExpr   *n = makeNode(JoinExpr);
   13843             : 
   13844          78 :                     n->jointype = $3;
   13845          78 :                     n->isNatural = true;
   13846          78 :                     n->larg = $1;
   13847          78 :                     n->rarg = $5;
   13848          78 :                     n->usingClause = NIL; /* figure out which columns later... */
   13849          78 :                     n->join_using_alias = NULL;
   13850          78 :                     n->quals = NULL; /* fill later */
   13851          78 :                     $$ = n;
   13852             :                 }
   13853             :             | table_ref NATURAL JOIN table_ref
   13854             :                 {
   13855             :                     /* letting join_type reduce to empty doesn't work */
   13856         180 :                     JoinExpr   *n = makeNode(JoinExpr);
   13857             : 
   13858         180 :                     n->jointype = JOIN_INNER;
   13859         180 :                     n->isNatural = true;
   13860         180 :                     n->larg = $1;
   13861         180 :                     n->rarg = $4;
   13862         180 :                     n->usingClause = NIL; /* figure out which columns later... */
   13863         180 :                     n->join_using_alias = NULL;
   13864         180 :                     n->quals = NULL; /* fill later */
   13865         180 :                     $$ = n;
   13866             :                 }
   13867             :         ;
   13868             : 
   13869             : alias_clause:
   13870             :             AS ColId '(' name_list ')'
   13871             :                 {
   13872        7292 :                     $$ = makeNode(Alias);
   13873        7292 :                     $$->aliasname = $2;
   13874        7292 :                     $$->colnames = $4;
   13875             :                 }
   13876             :             | AS ColId
   13877             :                 {
   13878       11004 :                     $$ = makeNode(Alias);
   13879       11004 :                     $$->aliasname = $2;
   13880             :                 }
   13881             :             | ColId '(' name_list ')'
   13882             :                 {
   13883        5822 :                     $$ = makeNode(Alias);
   13884        5822 :                     $$->aliasname = $1;
   13885        5822 :                     $$->colnames = $3;
   13886             :                 }
   13887             :             | ColId
   13888             :                 {
   13889      268124 :                     $$ = makeNode(Alias);
   13890      268124 :                     $$->aliasname = $1;
   13891             :                 }
   13892             :         ;
   13893             : 
   13894      262712 : opt_alias_clause: alias_clause                      { $$ = $1; }
   13895      161408 :             | /*EMPTY*/                             { $$ = NULL; }
   13896             :         ;
   13897             : 
   13898             : /*
   13899             :  * The alias clause after JOIN ... USING only accepts the AS ColId spelling,
   13900             :  * per SQL standard.  (The grammar could parse the other variants, but they
   13901             :  * don't seem to be useful, and it might lead to parser problems in the
   13902             :  * future.)
   13903             :  */
   13904             : opt_alias_clause_for_join_using:
   13905             :             AS ColId
   13906             :                 {
   13907          84 :                     $$ = makeNode(Alias);
   13908          84 :                     $$->aliasname = $2;
   13909             :                     /* the column name list will be inserted later */
   13910             :                 }
   13911        1166 :             | /*EMPTY*/                             { $$ = NULL; }
   13912             :         ;
   13913             : 
   13914             : /*
   13915             :  * func_alias_clause can include both an Alias and a coldeflist, so we make it
   13916             :  * return a 2-element list that gets disassembled by calling production.
   13917             :  */
   13918             : func_alias_clause:
   13919             :             alias_clause
   13920             :                 {
   13921       29356 :                     $$ = list_make2($1, NIL);
   13922             :                 }
   13923             :             | AS '(' TableFuncElementList ')'
   13924             :                 {
   13925         114 :                     $$ = list_make2(NULL, $3);
   13926             :                 }
   13927             :             | AS ColId '(' TableFuncElementList ')'
   13928             :                 {
   13929         596 :                     Alias      *a = makeNode(Alias);
   13930             : 
   13931         596 :                     a->aliasname = $2;
   13932         596 :                     $$ = list_make2(a, $4);
   13933             :                 }
   13934             :             | ColId '(' TableFuncElementList ')'
   13935             :                 {
   13936          50 :                     Alias      *a = makeNode(Alias);
   13937             : 
   13938          50 :                     a->aliasname = $1;
   13939          50 :                     $$ = list_make2(a, $3);
   13940             :                 }
   13941             :             | /*EMPTY*/
   13942             :                 {
   13943       18678 :                     $$ = list_make2(NULL, NIL);
   13944             :                 }
   13945             :         ;
   13946             : 
   13947        1042 : join_type:  FULL opt_outer                          { $$ = JOIN_FULL; }
   13948       43382 :             | LEFT opt_outer                        { $$ = JOIN_LEFT; }
   13949         378 :             | RIGHT opt_outer                       { $$ = JOIN_RIGHT; }
   13950        3964 :             | INNER_P                               { $$ = JOIN_INNER; }
   13951             :         ;
   13952             : 
   13953             : /* OUTER is just noise... */
   13954             : opt_outer: OUTER_P
   13955             :             | /*EMPTY*/
   13956             :         ;
   13957             : 
   13958             : /* JOIN qualification clauses
   13959             :  * Possibilities are:
   13960             :  *  USING ( column list ) [ AS alias ]
   13961             :  *                        allows only unqualified column names,
   13962             :  *                        which must match between tables.
   13963             :  *  ON expr allows more general qualifications.
   13964             :  *
   13965             :  * We return USING as a two-element List (the first item being a sub-List
   13966             :  * of the common column names, and the second either an Alias item or NULL).
   13967             :  * An ON-expr will not be a List, so it can be told apart that way.
   13968             :  */
   13969             : 
   13970             : join_qual: USING '(' name_list ')' opt_alias_clause_for_join_using
   13971             :                 {
   13972        1250 :                     $$ = (Node *) list_make2($3, $5);
   13973             :                 }
   13974             :             | ON a_expr
   13975             :                 {
   13976       84586 :                     $$ = $2;
   13977             :                 }
   13978             :         ;
   13979             : 
   13980             : 
   13981             : relation_expr:
   13982             :             qualified_name
   13983             :                 {
   13984             :                     /* inheritance query, implicitly */
   13985      495306 :                     $$ = $1;
   13986      495306 :                     $$->inh = true;
   13987      495306 :                     $$->alias = NULL;
   13988             :                 }
   13989             :             | extended_relation_expr
   13990             :                 {
   13991        9298 :                     $$ = $1;
   13992             :                 }
   13993             :         ;
   13994             : 
   13995             : extended_relation_expr:
   13996             :             qualified_name '*'
   13997             :                 {
   13998             :                     /* inheritance query, explicitly */
   13999         204 :                     $$ = $1;
   14000         204 :                     $$->inh = true;
   14001         204 :                     $$->alias = NULL;
   14002             :                 }
   14003             :             | ONLY qualified_name
   14004             :                 {
   14005             :                     /* no inheritance */
   14006        9100 :                     $$ = $2;
   14007        9100 :                     $$->inh = false;
   14008        9100 :                     $$->alias = NULL;
   14009             :                 }
   14010             :             | ONLY '(' qualified_name ')'
   14011             :                 {
   14012             :                     /* no inheritance, SQL99-style syntax */
   14013           0 :                     $$ = $3;
   14014           0 :                     $$->inh = false;
   14015           0 :                     $$->alias = NULL;
   14016             :                 }
   14017             :         ;
   14018             : 
   14019             : 
   14020             : relation_expr_list:
   14021        5508 :             relation_expr                           { $$ = list_make1($1); }
   14022       15820 :             | relation_expr_list ',' relation_expr  { $$ = lappend($1, $3); }
   14023             :         ;
   14024             : 
   14025             : 
   14026             : /*
   14027             :  * Given "UPDATE foo set set ...", we have to decide without looking any
   14028             :  * further ahead whether the first "set" is an alias or the UPDATE's SET
   14029             :  * keyword.  Since "set" is allowed as a column name both interpretations
   14030             :  * are feasible.  We resolve the shift/reduce conflict by giving the first
   14031             :  * relation_expr_opt_alias production a higher precedence than the SET token
   14032             :  * has, causing the parser to prefer to reduce, in effect assuming that the
   14033             :  * SET is not an alias.
   14034             :  */
   14035             : relation_expr_opt_alias: relation_expr                  %prec UMINUS
   14036             :                 {
   14037       18486 :                     $$ = $1;
   14038             :                 }
   14039             :             | relation_expr ColId
   14040             :                 {
   14041        2222 :                     Alias      *alias = makeNode(Alias);
   14042             : 
   14043        2222 :                     alias->aliasname = $2;
   14044        2222 :                     $1->alias = alias;
   14045        2222 :                     $$ = $1;
   14046             :                 }
   14047             :             | relation_expr AS ColId
   14048             :                 {
   14049          90 :                     Alias      *alias = makeNode(Alias);
   14050             : 
   14051          90 :                     alias->aliasname = $3;
   14052          90 :                     $1->alias = alias;
   14053          90 :                     $$ = $1;
   14054             :                 }
   14055             :         ;
   14056             : 
   14057             : /*
   14058             :  * TABLESAMPLE decoration in a FROM item
   14059             :  */
   14060             : tablesample_clause:
   14061             :             TABLESAMPLE func_name '(' expr_list ')' opt_repeatable_clause
   14062             :                 {
   14063         264 :                     RangeTableSample *n = makeNode(RangeTableSample);
   14064             : 
   14065             :                     /* n->relation will be filled in later */
   14066         264 :                     n->method = $2;
   14067         264 :                     n->args = $4;
   14068         264 :                     n->repeatable = $6;
   14069         264 :                     n->location = @2;
   14070         264 :                     $$ = (Node *) n;
   14071             :                 }
   14072             :         ;
   14073             : 
   14074             : opt_repeatable_clause:
   14075         110 :             REPEATABLE '(' a_expr ')'   { $$ = (Node *) $3; }
   14076         154 :             | /*EMPTY*/                 { $$ = NULL; }
   14077             :         ;
   14078             : 
   14079             : /*
   14080             :  * func_table represents a function invocation in a FROM list. It can be
   14081             :  * a plain function call, like "foo(...)", or a ROWS FROM expression with
   14082             :  * one or more function calls, "ROWS FROM (foo(...), bar(...))",
   14083             :  * optionally with WITH ORDINALITY attached.
   14084             :  * In the ROWS FROM syntax, a column definition list can be given for each
   14085             :  * function, for example:
   14086             :  *     ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
   14087             :  *                bar() AS (bar_res_a text, bar_res_b text))
   14088             :  * It's also possible to attach a column definition list to the RangeFunction
   14089             :  * as a whole, but that's handled by the table_ref production.
   14090             :  */
   14091             : func_table: func_expr_windowless opt_ordinality
   14092             :                 {
   14093       48668 :                     RangeFunction *n = makeNode(RangeFunction);
   14094             : 
   14095       48668 :                     n->lateral = false;
   14096       48668 :                     n->ordinality = $2;
   14097       48668 :                     n->is_rowsfrom = false;
   14098       48668 :                     n->functions = list_make1(list_make2($1, NIL));
   14099             :                     /* alias and coldeflist are set by table_ref production */
   14100       48668 :                     $$ = (Node *) n;
   14101             :                 }
   14102             :             | ROWS FROM '(' rowsfrom_list ')' opt_ordinality
   14103             :                 {
   14104         132 :                     RangeFunction *n = makeNode(RangeFunction);
   14105             : 
   14106         132 :                     n->lateral = false;
   14107         132 :                     n->ordinality = $6;
   14108         132 :                     n->is_rowsfrom = true;
   14109         132 :                     n->functions = $4;
   14110             :                     /* alias and coldeflist are set by table_ref production */
   14111         132 :                     $$ = (Node *) n;
   14112             :                 }
   14113             :         ;
   14114             : 
   14115             : rowsfrom_item: func_expr_windowless opt_col_def_list
   14116         318 :                 { $$ = list_make2($1, $2); }
   14117             :         ;
   14118             : 
   14119             : rowsfrom_list:
   14120         132 :             rowsfrom_item                       { $$ = list_make1($1); }
   14121         186 :             | rowsfrom_list ',' rowsfrom_item   { $$ = lappend($1, $3); }
   14122             :         ;
   14123             : 
   14124          54 : opt_col_def_list: AS '(' TableFuncElementList ')'   { $$ = $3; }
   14125         264 :             | /*EMPTY*/                             { $$ = NIL; }
   14126             :         ;
   14127             : 
   14128         908 : opt_ordinality: WITH_LA ORDINALITY                  { $$ = true; }
   14129       47892 :             | /*EMPTY*/                             { $$ = false; }
   14130             :         ;
   14131             : 
   14132             : 
   14133             : where_clause:
   14134      216172 :             WHERE a_expr                            { $$ = $2; }
   14135      291720 :             | /*EMPTY*/                             { $$ = NULL; }
   14136             :         ;
   14137             : 
   14138             : /* variant for UPDATE and DELETE */
   14139             : where_or_current_clause:
   14140       13388 :             WHERE a_expr                            { $$ = $2; }
   14141             :             | WHERE CURRENT_P OF cursor_name
   14142             :                 {
   14143         266 :                     CurrentOfExpr *n = makeNode(CurrentOfExpr);
   14144             : 
   14145             :                     /* cvarno is filled in by parse analysis */
   14146         266 :                     n->cursor_name = $4;
   14147         266 :                     n->cursor_param = 0;
   14148         266 :                     $$ = (Node *) n;
   14149             :                 }
   14150        5008 :             | /*EMPTY*/                             { $$ = NULL; }
   14151             :         ;
   14152             : 
   14153             : 
   14154             : OptTableFuncElementList:
   14155         748 :             TableFuncElementList                { $$ = $1; }
   14156        3786 :             | /*EMPTY*/                         { $$ = NIL; }
   14157             :         ;
   14158             : 
   14159             : TableFuncElementList:
   14160             :             TableFuncElement
   14161             :                 {
   14162        1562 :                     $$ = list_make1($1);
   14163             :                 }
   14164             :             | TableFuncElementList ',' TableFuncElement
   14165             :                 {
   14166        2102 :                     $$ = lappend($1, $3);
   14167             :                 }
   14168             :         ;
   14169             : 
   14170             : TableFuncElement:   ColId Typename opt_collate_clause
   14171             :                 {
   14172        3728 :                     ColumnDef *n = makeNode(ColumnDef);
   14173             : 
   14174        3728 :                     n->colname = $1;
   14175        3728 :                     n->typeName = $2;
   14176        3728 :                     n->inhcount = 0;
   14177        3728 :                     n->is_local = true;
   14178        3728 :                     n->is_not_null = false;
   14179        3728 :                     n->is_from_type = false;
   14180        3728 :                     n->storage = 0;
   14181        3728 :                     n->raw_default = NULL;
   14182        3728 :                     n->cooked_default = NULL;
   14183        3728 :                     n->collClause = (CollateClause *) $3;
   14184        3728 :                     n->collOid = InvalidOid;
   14185        3728 :                     n->constraints = NIL;
   14186        3728 :                     n->location = @1;
   14187        3728 :                     $$ = (Node *) n;
   14188             :                 }
   14189             :         ;
   14190             : 
   14191             : /*
   14192             :  * XMLTABLE
   14193             :  */
   14194             : xmltable:
   14195             :             XMLTABLE '(' c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   14196             :                 {
   14197         202 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   14198             : 
   14199         202 :                     n->rowexpr = $3;
   14200         202 :                     n->docexpr = $4;
   14201         202 :                     n->columns = $6;
   14202         202 :                     n->namespaces = NIL;
   14203         202 :                     n->location = @1;
   14204         202 :                     $$ = (Node *) n;
   14205             :                 }
   14206             :             | XMLTABLE '(' XMLNAMESPACES '(' xml_namespace_list ')' ','
   14207             :                 c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   14208             :                 {
   14209          22 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   14210             : 
   14211          22 :                     n->rowexpr = $8;
   14212          22 :                     n->docexpr = $9;
   14213          22 :                     n->columns = $11;
   14214          22 :                     n->namespaces = $5;
   14215          22 :                     n->location = @1;
   14216          22 :                     $$ = (Node *) n;
   14217             :                 }
   14218             :         ;
   14219             : 
   14220         224 : xmltable_column_list: xmltable_column_el                    { $$ = list_make1($1); }
   14221         544 :             | xmltable_column_list ',' xmltable_column_el   { $$ = lappend($1, $3); }
   14222             :         ;
   14223             : 
   14224             : xmltable_column_el:
   14225             :             ColId Typename
   14226             :                 {
   14227         198 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14228             : 
   14229         198 :                     fc->colname = $1;
   14230         198 :                     fc->for_ordinality = false;
   14231         198 :                     fc->typeName = $2;
   14232         198 :                     fc->is_not_null = false;
   14233         198 :                     fc->colexpr = NULL;
   14234         198 :                     fc->coldefexpr = NULL;
   14235         198 :                     fc->location = @1;
   14236             : 
   14237         198 :                     $$ = (Node *) fc;
   14238             :                 }
   14239             :             | ColId Typename xmltable_column_option_list
   14240             :                 {
   14241         506 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14242             :                     ListCell   *option;
   14243         506 :                     bool        nullability_seen = false;
   14244             : 
   14245         506 :                     fc->colname = $1;
   14246         506 :                     fc->typeName = $2;
   14247         506 :                     fc->for_ordinality = false;
   14248         506 :                     fc->is_not_null = false;
   14249         506 :                     fc->colexpr = NULL;
   14250         506 :                     fc->coldefexpr = NULL;
   14251         506 :                     fc->location = @1;
   14252             : 
   14253        1128 :                     foreach(option, $3)
   14254             :                     {
   14255         622 :                         DefElem   *defel = (DefElem *) lfirst(option);
   14256             : 
   14257         622 :                         if (strcmp(defel->defname, "default") == 0)
   14258             :                         {
   14259          58 :                             if (fc->coldefexpr != NULL)
   14260           0 :                                 ereport(ERROR,
   14261             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14262             :                                          errmsg("only one DEFAULT value is allowed"),
   14263             :                                          parser_errposition(defel->location)));
   14264          58 :                             fc->coldefexpr = defel->arg;
   14265             :                         }
   14266         564 :                         else if (strcmp(defel->defname, "path") == 0)
   14267             :                         {
   14268         506 :                             if (fc->colexpr != NULL)
   14269           0 :                                 ereport(ERROR,
   14270             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14271             :                                          errmsg("only one PATH value per column is allowed"),
   14272             :                                          parser_errposition(defel->location)));
   14273         506 :                             fc->colexpr = defel->arg;
   14274             :                         }
   14275          58 :                         else if (strcmp(defel->defname, "__pg__is_not_null") == 0)
   14276             :                         {
   14277          58 :                             if (nullability_seen)
   14278           0 :                                 ereport(ERROR,
   14279             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14280             :                                          errmsg("conflicting or redundant NULL / NOT NULL declarations for column \"%s\"", fc->colname),
   14281             :                                          parser_errposition(defel->location)));
   14282          58 :                             fc->is_not_null = boolVal(defel->arg);
   14283          58 :                             nullability_seen = true;
   14284             :                         }
   14285             :                         else
   14286             :                         {
   14287           0 :                             ereport(ERROR,
   14288             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   14289             :                                      errmsg("unrecognized column option \"%s\"",
   14290             :                                             defel->defname),
   14291             :                                      parser_errposition(defel->location)));
   14292             :                         }
   14293             :                     }
   14294         506 :                     $$ = (Node *) fc;
   14295             :                 }
   14296             :             | ColId FOR ORDINALITY
   14297             :                 {
   14298          64 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14299             : 
   14300          64 :                     fc->colname = $1;
   14301          64 :                     fc->for_ordinality = true;
   14302             :                     /* other fields are ignored, initialized by makeNode */
   14303          64 :                     fc->location = @1;
   14304             : 
   14305          64 :                     $$ = (Node *) fc;
   14306             :                 }
   14307             :         ;
   14308             : 
   14309             : xmltable_column_option_list:
   14310             :             xmltable_column_option_el
   14311         506 :                 { $$ = list_make1($1); }
   14312             :             | xmltable_column_option_list xmltable_column_option_el
   14313         116 :                 { $$ = lappend($1, $2); }
   14314             :         ;
   14315             : 
   14316             : xmltable_column_option_el:
   14317             :             IDENT b_expr
   14318             :                 {
   14319           6 :                     if (strcmp($1, "__pg__is_not_null") == 0)
   14320           6 :                         ereport(ERROR,
   14321             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   14322             :                                  errmsg("option name \"%s\" cannot be used in XMLTABLE", $1),
   14323             :                                  parser_errposition(@1)));
   14324           0 :                     $$ = makeDefElem($1, $2, @1);
   14325             :                 }
   14326             :             | DEFAULT b_expr
   14327          58 :                 { $$ = makeDefElem("default", $2, @1); }
   14328             :             | NOT NULL_P
   14329          58 :                 { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(true), @1); }
   14330             :             | NULL_P
   14331           0 :                 { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(false), @1); }
   14332             :             | PATH b_expr
   14333         506 :                 { $$ = makeDefElem("path", $2, @1); }
   14334             :         ;
   14335             : 
   14336             : xml_namespace_list:
   14337             :             xml_namespace_el
   14338          22 :                 { $$ = list_make1($1); }
   14339             :             | xml_namespace_list ',' xml_namespace_el
   14340           0 :                 { $$ = lappend($1, $3); }
   14341             :         ;
   14342             : 
   14343             : xml_namespace_el:
   14344             :             b_expr AS ColLabel
   14345             :                 {
   14346          16 :                     $$ = makeNode(ResTarget);
   14347          16 :                     $$->name = $3;
   14348          16 :                     $$->indirection = NIL;
   14349          16 :                     $$->val = $1;
   14350          16 :                     $$->location = @1;
   14351             :                 }
   14352             :             | DEFAULT b_expr
   14353             :                 {
   14354           6 :                     $$ = makeNode(ResTarget);
   14355           6 :                     $$->name = NULL;
   14356           6 :                     $$->indirection = NIL;
   14357           6 :                     $$->val = $2;
   14358           6 :                     $$->location = @1;
   14359             :                 }
   14360             :         ;
   14361             : 
   14362             : json_table:
   14363             :             JSON_TABLE '('
   14364             :                 json_value_expr ',' a_expr json_table_path_name_opt
   14365             :                 json_passing_clause_opt
   14366             :                 COLUMNS '(' json_table_column_definition_list ')'
   14367             :                 json_on_error_clause_opt
   14368             :             ')'
   14369             :                 {
   14370         530 :                     JsonTable *n = makeNode(JsonTable);
   14371             :                     char      *pathstring;
   14372             : 
   14373         530 :                     n->context_item = (JsonValueExpr *) $3;
   14374         530 :                     if (!IsA($5, A_Const) ||
   14375         524 :                         castNode(A_Const, $5)->val.node.type != T_String)
   14376           6 :                         ereport(ERROR,
   14377             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   14378             :                                 errmsg("only string constants are supported in JSON_TABLE path specification"),
   14379             :                                 parser_errposition(@5));
   14380         524 :                     pathstring = castNode(A_Const, $5)->val.sval.sval;
   14381         524 :                     n->pathspec = makeJsonTablePathSpec(pathstring, $6, @5, @6);
   14382         524 :                     n->passing = $7;
   14383         524 :                     n->columns = $10;
   14384         524 :                     n->on_error = (JsonBehavior *) $12;
   14385         524 :                     n->location = @1;
   14386         524 :                     $$ = (Node *) n;
   14387             :                 }
   14388             :         ;
   14389             : 
   14390             : json_table_path_name_opt:
   14391          62 :             AS name         { $$ = $2; }
   14392         480 :             | /* empty */   { $$ = NULL; }
   14393             :         ;
   14394             : 
   14395             : json_table_column_definition_list:
   14396             :             json_table_column_definition
   14397         820 :                 { $$ = list_make1($1); }
   14398             :             | json_table_column_definition_list ',' json_table_column_definition
   14399         528 :                 { $$ = lappend($1, $3); }
   14400             :         ;
   14401             : 
   14402             : json_table_column_definition:
   14403             :             ColId FOR ORDINALITY
   14404             :                 {
   14405          84 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14406             : 
   14407          84 :                     n->coltype = JTC_FOR_ORDINALITY;
   14408          84 :                     n->name = $1;
   14409          84 :                     n->location = @1;
   14410          84 :                     $$ = (Node *) n;
   14411             :                 }
   14412             :             | ColId Typename
   14413             :                 json_table_column_path_clause_opt
   14414             :                 json_wrapper_behavior
   14415             :                 json_quotes_clause_opt
   14416             :                 json_behavior_clause_opt
   14417             :                 {
   14418         728 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14419             : 
   14420         728 :                     n->coltype = JTC_REGULAR;
   14421         728 :                     n->name = $1;
   14422         728 :                     n->typeName = $2;
   14423         728 :                     n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   14424         728 :                     n->pathspec = (JsonTablePathSpec *) $3;
   14425         728 :                     n->wrapper = $4;
   14426         728 :                     n->quotes = $5;
   14427         728 :                     n->on_empty = (JsonBehavior *) linitial($6);
   14428         728 :                     n->on_error = (JsonBehavior *) lsecond($6);
   14429         728 :                     n->location = @1;
   14430         728 :                     $$ = (Node *) n;
   14431             :                 }
   14432             :             | ColId Typename json_format_clause
   14433             :                 json_table_column_path_clause_opt
   14434             :                 json_wrapper_behavior
   14435             :                 json_quotes_clause_opt
   14436             :                 json_behavior_clause_opt
   14437             :                 {
   14438         108 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14439             : 
   14440         108 :                     n->coltype = JTC_FORMATTED;
   14441         108 :                     n->name = $1;
   14442         108 :                     n->typeName = $2;
   14443         108 :                     n->format = (JsonFormat *) $3;
   14444         108 :                     n->pathspec = (JsonTablePathSpec *) $4;
   14445         108 :                     n->wrapper = $5;
   14446         108 :                     n->quotes = $6;
   14447         108 :                     n->on_empty = (JsonBehavior *) linitial($7);
   14448         108 :                     n->on_error = (JsonBehavior *) lsecond($7);
   14449         108 :                     n->location = @1;
   14450         108 :                     $$ = (Node *) n;
   14451             :                 }
   14452             :             | ColId Typename
   14453             :                 EXISTS json_table_column_path_clause_opt
   14454             :                 json_on_error_clause_opt
   14455             :                 {
   14456         138 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14457             : 
   14458         138 :                     n->coltype = JTC_EXISTS;
   14459         138 :                     n->name = $1;
   14460         138 :                     n->typeName = $2;
   14461         138 :                     n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   14462         138 :                     n->wrapper = JSW_NONE;
   14463         138 :                     n->quotes = JS_QUOTES_UNSPEC;
   14464         138 :                     n->pathspec = (JsonTablePathSpec *) $4;
   14465         138 :                     n->on_empty = NULL;
   14466         138 :                     n->on_error = (JsonBehavior *) $5;
   14467         138 :                     n->location = @1;
   14468         138 :                     $$ = (Node *) n;
   14469             :                 }
   14470             :             | NESTED path_opt Sconst
   14471             :                 COLUMNS '(' json_table_column_definition_list ')'
   14472             :                 {
   14473         144 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14474             : 
   14475         144 :                     n->coltype = JTC_NESTED;
   14476         288 :                     n->pathspec = (JsonTablePathSpec *)
   14477         144 :                         makeJsonTablePathSpec($3, NULL, @3, -1);
   14478         144 :                     n->columns = $6;
   14479         144 :                     n->location = @1;
   14480         144 :                     $$ = (Node *) n;
   14481             :                 }
   14482             :             | NESTED path_opt Sconst AS name
   14483             :                 COLUMNS '(' json_table_column_definition_list ')'
   14484             :                 {
   14485         146 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14486             : 
   14487         146 :                     n->coltype = JTC_NESTED;
   14488         292 :                     n->pathspec = (JsonTablePathSpec *)
   14489         146 :                         makeJsonTablePathSpec($3, $5, @3, @5);
   14490         146 :                     n->columns = $8;
   14491         146 :                     n->location = @1;
   14492         146 :                     $$ = (Node *) n;
   14493             :                 }
   14494             :         ;
   14495             : 
   14496             : path_opt:
   14497             :             PATH
   14498             :             | /* EMPTY */
   14499             :         ;
   14500             : 
   14501             : json_table_column_path_clause_opt:
   14502             :             PATH Sconst
   14503         828 :                 { $$ = (Node *) makeJsonTablePathSpec($2, NULL, @2, -1); }
   14504             :             | /* EMPTY */
   14505         152 :                 { $$ = NULL; }
   14506             :         ;
   14507             : 
   14508             : /*****************************************************************************
   14509             :  *
   14510             :  *  Type syntax
   14511             :  *      SQL introduces a large amount of type-specific syntax.
   14512             :  *      Define individual clauses to handle these cases, and use
   14513             :  *       the generic case to handle regular type-extensible Postgres syntax.
   14514             :  *      - thomas 1997-10-10
   14515             :  *
   14516             :  *****************************************************************************/
   14517             : 
   14518             : Typename:   SimpleTypename opt_array_bounds
   14519             :                 {
   14520      526054 :                     $$ = $1;
   14521      526054 :                     $$->arrayBounds = $2;
   14522             :                 }
   14523             :             | SETOF SimpleTypename opt_array_bounds
   14524             :                 {
   14525        2412 :                     $$ = $2;
   14526        2412 :                     $$->arrayBounds = $3;
   14527        2412 :                     $$->setof = true;
   14528             :                 }
   14529             :             /* SQL standard syntax, currently only one-dimensional */
   14530             :             | SimpleTypename ARRAY '[' Iconst ']'
   14531             :                 {
   14532           6 :                     $$ = $1;
   14533           6 :                     $$->arrayBounds = list_make1(makeInteger($4));
   14534             :                 }
   14535             :             | SETOF SimpleTypename ARRAY '[' Iconst ']'
   14536             :                 {
   14537           0 :                     $$ = $2;
   14538           0 :                     $$->arrayBounds = list_make1(makeInteger($5));
   14539           0 :                     $$->setof = true;
   14540             :                 }
   14541             :             | SimpleTypename ARRAY
   14542             :                 {
   14543           0 :                     $$ = $1;
   14544           0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   14545             :                 }
   14546             :             | SETOF SimpleTypename ARRAY
   14547             :                 {
   14548           0 :                     $$ = $2;
   14549           0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   14550           0 :                     $$->setof = true;
   14551             :                 }
   14552             :         ;
   14553             : 
   14554             : opt_array_bounds:
   14555             :             opt_array_bounds '[' ']'
   14556       15416 :                     {  $$ = lappend($1, makeInteger(-1)); }
   14557             :             | opt_array_bounds '[' Iconst ']'
   14558          62 :                     {  $$ = lappend($1, makeInteger($3)); }
   14559             :             | /*EMPTY*/
   14560      528466 :                     {  $$ = NIL; }
   14561             :         ;
   14562             : 
   14563             : SimpleTypename:
   14564      410050 :             GenericType                             { $$ = $1; }
   14565      102902 :             | Numeric                               { $$ = $1; }
   14566        1926 :             | Bit                                   { $$ = $1; }
   14567        3242 :             | Character                             { $$ = $1; }
   14568        5118 :             | ConstDatetime                         { $$ = $1; }
   14569             :             | ConstInterval opt_interval
   14570             :                 {
   14571        3788 :                     $$ = $1;
   14572        3788 :                     $$->typmods = $2;
   14573             :                 }
   14574             :             | ConstInterval '(' Iconst ')'
   14575             :                 {
   14576           0 :                     $$ = $1;
   14577           0 :                     $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   14578             :                                              makeIntConst($3, @3));
   14579             :                 }
   14580        1908 :             | JsonType                              { $$ = $1; }
   14581             :         ;
   14582             : 
   14583             : /* We have a separate ConstTypename to allow defaulting fixed-length
   14584             :  * types such as CHAR() and BIT() to an unspecified length.
   14585             :  * SQL9x requires that these default to a length of one, but this
   14586             :  * makes no sense for constructs like CHAR 'hi' and BIT '0101',
   14587             :  * where there is an obvious better choice to make.
   14588             :  * Note that ConstInterval is not included here since it must
   14589             :  * be pushed up higher in the rules to accommodate the postfix
   14590             :  * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
   14591             :  * the generic-type-name case in AexprConst to avoid premature
   14592             :  * reduce/reduce conflicts against function names.
   14593             :  */
   14594             : ConstTypename:
   14595          78 :             Numeric                                 { $$ = $1; }
   14596           0 :             | ConstBit                              { $$ = $1; }
   14597          34 :             | ConstCharacter                        { $$ = $1; }
   14598        2750 :             | ConstDatetime                         { $$ = $1; }
   14599         264 :             | JsonType                              { $$ = $1; }
   14600             :         ;
   14601             : 
   14602             : /*
   14603             :  * GenericType covers all type names that don't have special syntax mandated
   14604             :  * by the standard, including qualified names.  We also allow type modifiers.
   14605             :  * To avoid parsing conflicts against function invocations, the modifiers
   14606             :  * have to be shown as expr_list here, but parse analysis will only accept
   14607             :  * constants for them.
   14608             :  */
   14609             : GenericType:
   14610             :             type_function_name opt_type_modifiers
   14611             :                 {
   14612      289756 :                     $$ = makeTypeName($1);
   14613      289756 :                     $$->typmods = $2;
   14614      289756 :                     $$->location = @1;
   14615             :                 }
   14616             :             | type_function_name attrs opt_type_modifiers
   14617             :                 {
   14618      120294 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
   14619      120294 :                     $$->typmods = $3;
   14620      120294 :                     $$->location = @1;
   14621             :                 }
   14622             :         ;
   14623             : 
   14624        1396 : opt_type_modifiers: '(' expr_list ')'               { $$ = $2; }
   14625      414876 :                     | /* EMPTY */                   { $$ = NIL; }
   14626             :         ;
   14627             : 
   14628             : /*
   14629             :  * SQL numeric data types
   14630             :  */
   14631             : Numeric:    INT_P
   14632             :                 {
   14633       38268 :                     $$ = SystemTypeName("int4");
   14634       38268 :                     $$->location = @1;
   14635             :                 }
   14636             :             | INTEGER
   14637             :                 {
   14638       27638 :                     $$ = SystemTypeName("int4");
   14639       27638 :                     $$->location = @1;
   14640             :                 }
   14641             :             | SMALLINT
   14642             :                 {
   14643        1310 :                     $$ = SystemTypeName("int2");
   14644        1310 :                     $$->location = @1;
   14645             :                 }
   14646             :             | BIGINT
   14647             :                 {
   14648        5362 :                     $$ = SystemTypeName("int8");
   14649        5362 :                     $$->location = @1;
   14650             :                 }
   14651             :             | REAL
   14652             :                 {
   14653        7504 :                     $$ = SystemTypeName("float4");
   14654        7504 :                     $$->location = @1;
   14655             :                 }
   14656             :             | FLOAT_P opt_float
   14657             :                 {
   14658         538 :                     $$ = $2;
   14659         538 :                     $$->location = @1;
   14660             :                 }
   14661             :             | DOUBLE_P PRECISION
   14662             :                 {
   14663         930 :                     $$ = SystemTypeName("float8");
   14664         930 :                     $$->location = @1;
   14665             :                 }
   14666             :             | DECIMAL_P opt_type_modifiers
   14667             :                 {
   14668          36 :                     $$ = SystemTypeName("numeric");
   14669          36 :                     $$->typmods = $2;
   14670          36 :                     $$->location = @1;
   14671             :                 }
   14672             :             | DEC opt_type_modifiers
   14673             :                 {
   14674           0 :                     $$ = SystemTypeName("numeric");
   14675           0 :                     $$->typmods = $2;
   14676           0 :                     $$->location = @1;
   14677             :                 }
   14678             :             | NUMERIC opt_type_modifiers
   14679             :                 {
   14680        6186 :                     $$ = SystemTypeName("numeric");
   14681        6186 :                     $$->typmods = $2;
   14682        6186 :                     $$->location = @1;
   14683             :                 }
   14684             :             | BOOLEAN_P
   14685             :                 {
   14686       15208 :                     $$ = SystemTypeName("bool");
   14687       15208 :                     $$->location = @1;
   14688             :                 }
   14689             :         ;
   14690             : 
   14691             : opt_float:  '(' Iconst ')'
   14692             :                 {
   14693             :                     /*
   14694             :                      * Check FLOAT() precision limits assuming IEEE floating
   14695             :                      * types - thomas 1997-09-18
   14696             :                      */
   14697           2 :                     if ($2 < 1)
   14698           0 :                         ereport(ERROR,
   14699             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   14700             :                                  errmsg("precision for type float must be at least 1 bit"),
   14701             :                                  parser_errposition(@2)));
   14702           2 :                     else if ($2 <= 24)
   14703           2 :                         $$ = SystemTypeName("float4");
   14704           0 :                     else if ($2 <= 53)
   14705           0 :                         $$ = SystemTypeName("float8");
   14706             :                     else
   14707           0 :                         ereport(ERROR,
   14708             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   14709             :                                  errmsg("precision for type float must be less than 54 bits"),
   14710             :                                  parser_errposition(@2)));
   14711             :                 }
   14712             :             | /*EMPTY*/
   14713             :                 {
   14714         536 :                     $$ = SystemTypeName("float8");
   14715             :                 }
   14716             :         ;
   14717             : 
   14718             : /*
   14719             :  * SQL bit-field data types
   14720             :  * The following implements BIT() and BIT VARYING().
   14721             :  */
   14722             : Bit:        BitWithLength
   14723             :                 {
   14724        1710 :                     $$ = $1;
   14725             :                 }
   14726             :             | BitWithoutLength
   14727             :                 {
   14728         216 :                     $$ = $1;
   14729             :                 }
   14730             :         ;
   14731             : 
   14732             : /* ConstBit is like Bit except "BIT" defaults to unspecified length */
   14733             : /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
   14734             : ConstBit:   BitWithLength
   14735             :                 {
   14736           0 :                     $$ = $1;
   14737             :                 }
   14738             :             | BitWithoutLength
   14739             :                 {
   14740           0 :                     $$ = $1;
   14741           0 :                     $$->typmods = NIL;
   14742             :                 }
   14743             :         ;
   14744             : 
   14745             : BitWithLength:
   14746             :             BIT opt_varying '(' expr_list ')'
   14747             :                 {
   14748             :                     char *typname;
   14749             : 
   14750        1710 :                     typname = $2 ? "varbit" : "bit";
   14751        1710 :                     $$ = SystemTypeName(typname);
   14752        1710 :                     $$->typmods = $4;
   14753        1710 :                     $$->location = @1;
   14754             :                 }
   14755             :         ;
   14756             : 
   14757             : BitWithoutLength:
   14758             :             BIT opt_varying
   14759             :                 {
   14760             :                     /* bit defaults to bit(1), varbit to no limit */
   14761         216 :                     if ($2)
   14762             :                     {
   14763          26 :                         $$ = SystemTypeName("varbit");
   14764             :                     }
   14765             :                     else
   14766             :                     {
   14767         190 :                         $$ = SystemTypeName("bit");
   14768         190 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   14769             :                     }
   14770         216 :                     $$->location = @1;
   14771             :                 }
   14772             :         ;
   14773             : 
   14774             : 
   14775             : /*
   14776             :  * SQL character data types
   14777             :  * The following implements CHAR() and VARCHAR().
   14778             :  */
   14779             : Character:  CharacterWithLength
   14780             :                 {
   14781        1838 :                     $$ = $1;
   14782             :                 }
   14783             :             | CharacterWithoutLength
   14784             :                 {
   14785        1404 :                     $$ = $1;
   14786             :                 }
   14787             :         ;
   14788             : 
   14789             : ConstCharacter:  CharacterWithLength
   14790             :                 {
   14791          12 :                     $$ = $1;
   14792             :                 }
   14793             :             | CharacterWithoutLength
   14794             :                 {
   14795             :                     /* Length was not specified so allow to be unrestricted.
   14796             :                      * This handles problems with fixed-length (bpchar) strings
   14797             :                      * which in column definitions must default to a length
   14798             :                      * of one, but should not be constrained if the length
   14799             :                      * was not specified.
   14800             :                      */
   14801          22 :                     $$ = $1;
   14802          22 :                     $$->typmods = NIL;
   14803             :                 }
   14804             :         ;
   14805             : 
   14806             : CharacterWithLength:  character '(' Iconst ')'
   14807             :                 {
   14808        1850 :                     $$ = SystemTypeName($1);
   14809        1850 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14810        1850 :                     $$->location = @1;
   14811             :                 }
   14812             :         ;
   14813             : 
   14814             : CharacterWithoutLength:  character
   14815             :                 {
   14816        1426 :                     $$ = SystemTypeName($1);
   14817             :                     /* char defaults to char(1), varchar to no limit */
   14818        1426 :                     if (strcmp($1, "bpchar") == 0)
   14819         300 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   14820        1426 :                     $$->location = @1;
   14821             :                 }
   14822             :         ;
   14823             : 
   14824             : character:  CHARACTER opt_varying
   14825         798 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14826             :             | CHAR_P opt_varying
   14827        1172 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14828             :             | VARCHAR
   14829        1302 :                                         { $$ = "varchar"; }
   14830             :             | NATIONAL CHARACTER opt_varying
   14831           0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   14832             :             | NATIONAL CHAR_P opt_varying
   14833           0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   14834             :             | NCHAR opt_varying
   14835           4 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14836             :         ;
   14837             : 
   14838             : opt_varying:
   14839         564 :             VARYING                                 { $$ = true; }
   14840        3336 :             | /*EMPTY*/                             { $$ = false; }
   14841             :         ;
   14842             : 
   14843             : /*
   14844             :  * SQL date/time types
   14845             :  */
   14846             : ConstDatetime:
   14847             :             TIMESTAMP '(' Iconst ')' opt_timezone
   14848             :                 {
   14849         140 :                     if ($5)
   14850         114 :                         $$ = SystemTypeName("timestamptz");
   14851             :                     else
   14852          26 :                         $$ = SystemTypeName("timestamp");
   14853         140 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14854         140 :                     $$->location = @1;
   14855             :                 }
   14856             :             | TIMESTAMP opt_timezone
   14857             :                 {
   14858        5186 :                     if ($2)
   14859        1396 :                         $$ = SystemTypeName("timestamptz");
   14860             :                     else
   14861        3790 :                         $$ = SystemTypeName("timestamp");
   14862        5186 :                     $$->location = @1;
   14863             :                 }
   14864             :             | TIME '(' Iconst ')' opt_timezone
   14865             :                 {
   14866          26 :                     if ($5)
   14867          10 :                         $$ = SystemTypeName("timetz");
   14868             :                     else
   14869          16 :                         $$ = SystemTypeName("time");
   14870          26 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14871          26 :                     $$->location = @1;
   14872             :                 }
   14873             :             | TIME opt_timezone
   14874             :                 {
   14875        2516 :                     if ($2)
   14876         354 :                         $$ = SystemTypeName("timetz");
   14877             :                     else
   14878        2162 :                         $$ = SystemTypeName("time");
   14879        2516 :                     $$->location = @1;
   14880             :                 }
   14881             :         ;
   14882             : 
   14883             : ConstInterval:
   14884             :             INTERVAL
   14885             :                 {
   14886        7098 :                     $$ = SystemTypeName("interval");
   14887        7098 :                     $$->location = @1;
   14888             :                 }
   14889             :         ;
   14890             : 
   14891             : opt_timezone:
   14892        1874 :             WITH_LA TIME ZONE                       { $$ = true; }
   14893         628 :             | WITHOUT_LA TIME ZONE                  { $$ = false; }
   14894        5366 :             | /*EMPTY*/                             { $$ = false; }
   14895             :         ;
   14896             : 
   14897             : opt_interval:
   14898             :             YEAR_P
   14899          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
   14900             :             | MONTH_P
   14901          18 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
   14902             :             | DAY_P
   14903          18 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
   14904             :             | HOUR_P
   14905          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
   14906             :             | MINUTE_P
   14907          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
   14908             :             | interval_second
   14909          36 :                 { $$ = $1; }
   14910             :             | YEAR_P TO MONTH_P
   14911             :                 {
   14912          18 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
   14913             :                                                  INTERVAL_MASK(MONTH), @1));
   14914             :                 }
   14915             :             | DAY_P TO HOUR_P
   14916             :                 {
   14917          24 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   14918             :                                                  INTERVAL_MASK(HOUR), @1));
   14919             :                 }
   14920             :             | DAY_P TO MINUTE_P
   14921             :                 {
   14922          24 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   14923             :                                                  INTERVAL_MASK(HOUR) |
   14924             :                                                  INTERVAL_MASK(MINUTE), @1));
   14925             :                 }
   14926             :             | DAY_P TO interval_second
   14927             :                 {
   14928          48 :                     $$ = $3;
   14929          48 :                     linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
   14930             :                                                 INTERVAL_MASK(HOUR) |
   14931             :                                                 INTERVAL_MASK(MINUTE) |
   14932          48 :                                                 INTERVAL_MASK(SECOND), @1);
   14933             :                 }
   14934             :             | HOUR_P TO MINUTE_P
   14935             :                 {
   14936          18 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
   14937             :                                                  INTERVAL_MASK(MINUTE), @1));
   14938             :                 }
   14939             :             | HOUR_P TO interval_second
   14940             :                 {
   14941          36 :                     $$ = $3;
   14942          36 :                     linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
   14943             :                                                 INTERVAL_MASK(MINUTE) |
   14944          36 :                                                 INTERVAL_MASK(SECOND), @1);
   14945             :                 }
   14946             :             | MINUTE_P TO interval_second
   14947             :                 {
   14948          66 :                     $$ = $3;
   14949          66 :                     linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
   14950          66 :                                                 INTERVAL_MASK(SECOND), @1);
   14951             :                 }
   14952             :             | /*EMPTY*/
   14953        6744 :                 { $$ = NIL; }
   14954             :         ;
   14955             : 
   14956             : interval_second:
   14957             :             SECOND_P
   14958             :                 {
   14959         102 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
   14960             :                 }
   14961             :             | SECOND_P '(' Iconst ')'
   14962             :                 {
   14963          84 :                     $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
   14964             :                                     makeIntConst($3, @3));
   14965             :                 }
   14966             :         ;
   14967             : 
   14968             : JsonType:
   14969             :             JSON
   14970             :                 {
   14971        2172 :                     $$ = SystemTypeName("json");
   14972        2172 :                     $$->location = @1;
   14973             :                 }
   14974             :         ;
   14975             : 
   14976             : /*****************************************************************************
   14977             :  *
   14978             :  *  expression grammar
   14979             :  *
   14980             :  *****************************************************************************/
   14981             : 
   14982             : /*
   14983             :  * General expressions
   14984             :  * This is the heart of the expression syntax.
   14985             :  *
   14986             :  * We have two expression types: a_expr is the unrestricted kind, and
   14987             :  * b_expr is a subset that must be used in some places to avoid shift/reduce
   14988             :  * conflicts.  For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
   14989             :  * because that use of AND conflicts with AND as a boolean operator.  So,
   14990             :  * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
   14991             :  *
   14992             :  * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
   14993             :  * always be used by surrounding it with parens.
   14994             :  *
   14995             :  * c_expr is all the productions that are common to a_expr and b_expr;
   14996             :  * it's factored out just to eliminate redundant coding.
   14997             :  *
   14998             :  * Be careful of productions involving more than one terminal token.
   14999             :  * By default, bison will assign such productions the precedence of their
   15000             :  * last terminal, but in nearly all cases you want it to be the precedence
   15001             :  * of the first terminal instead; otherwise you will not get the behavior
   15002             :  * you expect!  So we use %prec annotations freely to set precedences.
   15003             :  */
   15004     3766646 : a_expr:     c_expr                                  { $$ = $1; }
   15005             :             | a_expr TYPECAST Typename
   15006      242746 :                     { $$ = makeTypeCast($1, $3, @2); }
   15007             :             | a_expr COLLATE any_name
   15008             :                 {
   15009        9022 :                     CollateClause *n = makeNode(CollateClause);
   15010             : 
   15011        9022 :                     n->arg = $1;
   15012        9022 :                     n->collname = $3;
   15013        9022 :                     n->location = @2;
   15014        9022 :                     $$ = (Node *) n;
   15015             :                 }
   15016             :             | a_expr AT TIME ZONE a_expr            %prec AT
   15017             :                 {
   15018         408 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   15019         408 :                                                list_make2($5, $1),
   15020             :                                                COERCE_SQL_SYNTAX,
   15021         408 :                                                @2);
   15022             :                 }
   15023             :             | a_expr AT LOCAL                       %prec AT
   15024             :                 {
   15025          42 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   15026          42 :                                                list_make1($1),
   15027             :                                                COERCE_SQL_SYNTAX,
   15028             :                                                -1);
   15029             :                 }
   15030             :         /*
   15031             :          * These operators must be called out explicitly in order to make use
   15032             :          * of bison's automatic operator-precedence handling.  All other
   15033             :          * operator names are handled by the generic productions using "Op",
   15034             :          * below; and all those operators will have the same precedence.
   15035             :          *
   15036             :          * If you add more explicitly-known operators, be sure to add them
   15037             :          * also to b_expr and to the MathOp list below.
   15038             :          */
   15039             :             | '+' a_expr                    %prec UMINUS
   15040          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   15041             :             | '-' a_expr                    %prec UMINUS
   15042        9198 :                 { $$ = doNegate($2, @1); }
   15043             :             | a_expr '+' a_expr
   15044       14166 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   15045             :             | a_expr '-' a_expr
   15046        4496 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   15047             :             | a_expr '*' a_expr
   15048        6386 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   15049             :             | a_expr '/' a_expr
   15050        3432 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   15051             :             | a_expr '%' a_expr
   15052        2844 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   15053             :             | a_expr '^' a_expr
   15054         478 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   15055             :             | a_expr '<' a_expr
   15056       10570 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   15057             :             | a_expr '>' a_expr
   15058       16888 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   15059             :             | a_expr '=' a_expr
   15060      402192 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   15061             :             | a_expr LESS_EQUALS a_expr
   15062        5442 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   15063             :             | a_expr GREATER_EQUALS a_expr
   15064        7314 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   15065             :             | a_expr NOT_EQUALS a_expr
   15066       40976 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   15067             : 
   15068             :             | a_expr qual_Op a_expr             %prec Op
   15069       59214 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   15070             :             | qual_Op a_expr                    %prec Op
   15071         228 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   15072             : 
   15073             :             | a_expr AND a_expr
   15074      239288 :                 { $$ = makeAndExpr($1, $3, @2); }
   15075             :             | a_expr OR a_expr
   15076       16842 :                 { $$ = makeOrExpr($1, $3, @2); }
   15077             :             | NOT a_expr
   15078       16844 :                 { $$ = makeNotExpr($2, @1); }
   15079             :             | NOT_LA a_expr                     %prec NOT
   15080           0 :                 { $$ = makeNotExpr($2, @1); }
   15081             : 
   15082             :             | a_expr LIKE a_expr
   15083             :                 {
   15084        1968 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   15085        1968 :                                                    $1, $3, @2);
   15086             :                 }
   15087             :             | a_expr LIKE a_expr ESCAPE a_expr                  %prec LIKE
   15088             :                 {
   15089          96 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15090          96 :                                                  list_make2($3, $5),
   15091             :                                                  COERCE_EXPLICIT_CALL,
   15092          96 :                                                  @2);
   15093          96 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   15094          96 :                                                    $1, (Node *) n, @2);
   15095             :                 }
   15096             :             | a_expr NOT_LA LIKE a_expr                         %prec NOT_LA
   15097             :                 {
   15098         198 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   15099         198 :                                                    $1, $4, @2);
   15100             :                 }
   15101             :             | a_expr NOT_LA LIKE a_expr ESCAPE a_expr           %prec NOT_LA
   15102             :                 {
   15103          96 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15104          96 :                                                  list_make2($4, $6),
   15105             :                                                  COERCE_EXPLICIT_CALL,
   15106          96 :                                                  @2);
   15107          96 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   15108          96 :                                                    $1, (Node *) n, @2);
   15109             :                 }
   15110             :             | a_expr ILIKE a_expr
   15111             :                 {
   15112         172 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   15113         172 :                                                    $1, $3, @2);
   15114             :                 }
   15115             :             | a_expr ILIKE a_expr ESCAPE a_expr                 %prec ILIKE
   15116             :                 {
   15117           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15118           0 :                                                  list_make2($3, $5),
   15119             :                                                  COERCE_EXPLICIT_CALL,
   15120           0 :                                                  @2);
   15121           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   15122           0 :                                                    $1, (Node *) n, @2);
   15123             :                 }
   15124             :             | a_expr NOT_LA ILIKE a_expr                        %prec NOT_LA
   15125             :                 {
   15126          30 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   15127          30 :                                                    $1, $4, @2);
   15128             :                 }
   15129             :             | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr          %prec NOT_LA
   15130             :                 {
   15131           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15132           0 :                                                  list_make2($4, $6),
   15133             :                                                  COERCE_EXPLICIT_CALL,
   15134           0 :                                                  @2);
   15135           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   15136           0 :                                                    $1, (Node *) n, @2);
   15137             :                 }
   15138             : 
   15139             :             | a_expr SIMILAR TO a_expr                          %prec SIMILAR
   15140             :                 {
   15141          88 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15142          88 :                                                  list_make1($4),
   15143             :                                                  COERCE_EXPLICIT_CALL,
   15144          88 :                                                  @2);
   15145          88 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   15146          88 :                                                    $1, (Node *) n, @2);
   15147             :                 }
   15148             :             | a_expr SIMILAR TO a_expr ESCAPE a_expr            %prec SIMILAR
   15149             :                 {
   15150          30 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15151          30 :                                                  list_make2($4, $6),
   15152             :                                                  COERCE_EXPLICIT_CALL,
   15153          30 :                                                  @2);
   15154          30 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   15155          30 :                                                    $1, (Node *) n, @2);
   15156             :                 }
   15157             :             | a_expr NOT_LA SIMILAR TO a_expr                   %prec NOT_LA
   15158             :                 {
   15159           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15160           0 :                                                  list_make1($5),
   15161             :                                                  COERCE_EXPLICIT_CALL,
   15162           0 :                                                  @2);
   15163           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   15164           0 :                                                    $1, (Node *) n, @2);
   15165             :                 }
   15166             :             | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr     %prec NOT_LA
   15167             :                 {
   15168           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15169           0 :                                                  list_make2($5, $7),
   15170             :                                                  COERCE_EXPLICIT_CALL,
   15171           0 :                                                  @2);
   15172           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   15173           0 :                                                    $1, (Node *) n, @2);
   15174             :                 }
   15175             : 
   15176             :             /* NullTest clause
   15177             :              * Define SQL-style Null test clause.
   15178             :              * Allow two forms described in the standard:
   15179             :              *  a IS NULL
   15180             :              *  a IS NOT NULL
   15181             :              * Allow two SQL extensions
   15182             :              *  a ISNULL
   15183             :              *  a NOTNULL
   15184             :              */
   15185             :             | a_expr IS NULL_P                          %prec IS
   15186             :                 {
   15187        5290 :                     NullTest   *n = makeNode(NullTest);
   15188             : 
   15189        5290 :                     n->arg = (Expr *) $1;
   15190        5290 :                     n->nulltesttype = IS_NULL;
   15191        5290 :                     n->location = @2;
   15192        5290 :                     $$ = (Node *) n;
   15193             :                 }
   15194             :             | a_expr ISNULL
   15195             :                 {
   15196          96 :                     NullTest   *n = makeNode(NullTest);
   15197             : 
   15198          96 :                     n->arg = (Expr *) $1;
   15199          96 :                     n->nulltesttype = IS_NULL;
   15200          96 :                     n->location = @2;
   15201          96 :                     $$ = (Node *) n;
   15202             :                 }
   15203             :             | a_expr IS NOT NULL_P                      %prec IS
   15204             :                 {
   15205       13454 :                     NullTest   *n = makeNode(NullTest);
   15206             : 
   15207       13454 :                     n->arg = (Expr *) $1;
   15208       13454 :                     n->nulltesttype = IS_NOT_NULL;
   15209       13454 :                     n->location = @2;
   15210       13454 :                     $$ = (Node *) n;
   15211             :                 }
   15212             :             | a_expr NOTNULL
   15213             :                 {
   15214           6 :                     NullTest   *n = makeNode(NullTest);
   15215             : 
   15216           6 :                     n->arg = (Expr *) $1;
   15217           6 :                     n->nulltesttype = IS_NOT_NULL;
   15218           6 :                     n->location = @2;
   15219           6 :                     $$ = (Node *) n;
   15220             :                 }
   15221             :             | row OVERLAPS row
   15222             :                 {
   15223         984 :                     if (list_length($1) != 2)
   15224           0 :                         ereport(ERROR,
   15225             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   15226             :                                  errmsg("wrong number of parameters on left side of OVERLAPS expression"),
   15227             :                                  parser_errposition(@1)));
   15228         984 :                     if (list_length($3) != 2)
   15229           0 :                         ereport(ERROR,
   15230             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   15231             :                                  errmsg("wrong number of parameters on right side of OVERLAPS expression"),
   15232             :                                  parser_errposition(@3)));
   15233         984 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
   15234         984 :                                                list_concat($1, $3),
   15235             :                                                COERCE_SQL_SYNTAX,
   15236         984 :                                                @2);
   15237             :                 }
   15238             :             | a_expr IS TRUE_P                          %prec IS
   15239             :                 {
   15240         530 :                     BooleanTest *b = makeNode(BooleanTest);
   15241             : 
   15242         530 :                     b->arg = (Expr *) $1;
   15243         530 :                     b->booltesttype = IS_TRUE;
   15244         530 :                     b->location = @2;
   15245         530 :                     $$ = (Node *) b;
   15246             :                 }
   15247             :             | a_expr IS NOT TRUE_P                      %prec IS
   15248             :                 {
   15249         140 :                     BooleanTest *b = makeNode(BooleanTest);
   15250             : 
   15251         140 :                     b->arg = (Expr *) $1;
   15252         140 :                     b->booltesttype = IS_NOT_TRUE;
   15253         140 :                     b->location = @2;
   15254         140 :                     $$ = (Node *) b;
   15255             :                 }
   15256             :             | a_expr IS FALSE_P                         %prec IS
   15257             :                 {
   15258         140 :                     BooleanTest *b = makeNode(BooleanTest);
   15259             : 
   15260         140 :                     b->arg = (Expr *) $1;
   15261         140 :                     b->booltesttype = IS_FALSE;
   15262         140 :                     b->location = @2;
   15263         140 :                     $$ = (Node *) b;
   15264             :                 }
   15265             :             | a_expr IS NOT FALSE_P                     %prec IS
   15266             :                 {
   15267          92 :                     BooleanTest *b = makeNode(BooleanTest);
   15268             : 
   15269          92 :                     b->arg = (Expr *) $1;
   15270          92 :                     b->booltesttype = IS_NOT_FALSE;
   15271          92 :                     b->location = @2;
   15272          92 :                     $$ = (Node *) b;
   15273             :                 }
   15274             :             | a_expr IS UNKNOWN                         %prec IS
   15275             :                 {
   15276          52 :                     BooleanTest *b = makeNode(BooleanTest);
   15277             : 
   15278          52 :                     b->arg = (Expr *) $1;
   15279          52 :                     b->booltesttype = IS_UNKNOWN;
   15280          52 :                     b->location = @2;
   15281          52 :                     $$ = (Node *) b;
   15282             :                 }
   15283             :             | a_expr IS NOT UNKNOWN                     %prec IS
   15284             :                 {
   15285          48 :                     BooleanTest *b = makeNode(BooleanTest);
   15286             : 
   15287          48 :                     b->arg = (Expr *) $1;
   15288          48 :                     b->booltesttype = IS_NOT_UNKNOWN;
   15289          48 :                     b->location = @2;
   15290          48 :                     $$ = (Node *) b;
   15291             :                 }
   15292             :             | a_expr IS DISTINCT FROM a_expr            %prec IS
   15293             :                 {
   15294        1260 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   15295             :                 }
   15296             :             | a_expr IS NOT DISTINCT FROM a_expr        %prec IS
   15297             :                 {
   15298          68 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   15299             :                 }
   15300             :             | a_expr BETWEEN opt_asymmetric b_expr AND a_expr       %prec BETWEEN
   15301             :                 {
   15302         466 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN,
   15303             :                                                    "BETWEEN",
   15304         466 :                                                    $1,
   15305         466 :                                                    (Node *) list_make2($4, $6),
   15306         466 :                                                    @2);
   15307             :                 }
   15308             :             | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
   15309             :                 {
   15310          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN,
   15311             :                                                    "NOT BETWEEN",
   15312          12 :                                                    $1,
   15313          12 :                                                    (Node *) list_make2($5, $7),
   15314          12 :                                                    @2);
   15315             :                 }
   15316             :             | a_expr BETWEEN SYMMETRIC b_expr AND a_expr            %prec BETWEEN
   15317             :                 {
   15318          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN_SYM,
   15319             :                                                    "BETWEEN SYMMETRIC",
   15320          12 :                                                    $1,
   15321          12 :                                                    (Node *) list_make2($4, $6),
   15322          12 :                                                    @2);
   15323             :                 }
   15324             :             | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr     %prec NOT_LA
   15325             :                 {
   15326          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN_SYM,
   15327             :                                                    "NOT BETWEEN SYMMETRIC",
   15328          12 :                                                    $1,
   15329          12 :                                                    (Node *) list_make2($5, $7),
   15330          12 :                                                    @2);
   15331             :                 }
   15332             :             | a_expr IN_P select_with_parens
   15333             :                 {
   15334             :                     /* generate foo = ANY (subquery) */
   15335        5444 :                     SubLink    *n = makeNode(SubLink);
   15336             : 
   15337        5444 :                     n->subselect = $3;
   15338        5444 :                     n->subLinkType = ANY_SUBLINK;
   15339        5444 :                     n->subLinkId = 0;
   15340        5444 :                     n->testexpr = $1;
   15341        5444 :                     n->operName = NIL;       /* show it's IN not = ANY */
   15342        5444 :                     n->location = @2;
   15343        5444 :                     $$ = (Node *) n;
   15344             :                 }
   15345             :             | a_expr IN_P '(' expr_list ')'
   15346             :                 {
   15347             :                     /* generate scalar IN expression */
   15348       19246 :                     A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "=", $1, (Node *) $4, @2);
   15349             : 
   15350       19246 :                     n->rexpr_list_start = @3;
   15351       19246 :                     n->rexpr_list_end = @5;
   15352       19246 :                     $$ = (Node *) n;
   15353             :                 }
   15354             :             | a_expr NOT_LA IN_P select_with_parens         %prec NOT_LA
   15355             :                 {
   15356             :                     /* generate NOT (foo = ANY (subquery)) */
   15357         120 :                     SubLink    *n = makeNode(SubLink);
   15358             : 
   15359         120 :                     n->subselect = $4;
   15360         120 :                     n->subLinkType = ANY_SUBLINK;
   15361         120 :                     n->subLinkId = 0;
   15362         120 :                     n->testexpr = $1;
   15363         120 :                     n->operName = NIL;       /* show it's IN not = ANY */
   15364         120 :                     n->location = @2;
   15365             :                     /* Stick a NOT on top; must have same parse location */
   15366         120 :                     $$ = makeNotExpr((Node *) n, @2);
   15367             :                 }
   15368             :             | a_expr NOT_LA IN_P '(' expr_list ')'
   15369             :                 {
   15370             :                     /* generate scalar NOT IN expression */
   15371        2846 :                     A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "<>", $1, (Node *) $5, @2);
   15372             : 
   15373        2846 :                     n->rexpr_list_start = @4;
   15374        2846 :                     n->rexpr_list_end = @6;
   15375        2846 :                     $$ = (Node *) n;
   15376             :                 }
   15377             :             | a_expr subquery_Op sub_type select_with_parens    %prec Op
   15378             :                 {
   15379         168 :                     SubLink    *n = makeNode(SubLink);
   15380             : 
   15381         168 :                     n->subLinkType = $3;
   15382         168 :                     n->subLinkId = 0;
   15383         168 :                     n->testexpr = $1;
   15384         168 :                     n->operName = $2;
   15385         168 :                     n->subselect = $4;
   15386         168 :                     n->location = @2;
   15387         168 :                     $$ = (Node *) n;
   15388             :                 }
   15389             :             | a_expr subquery_Op sub_type '(' a_expr ')'        %prec Op
   15390             :                 {
   15391       17248 :                     if ($3 == ANY_SUBLINK)
   15392       16948 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
   15393             :                     else
   15394         300 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
   15395             :                 }
   15396             :             | UNIQUE opt_unique_null_treatment select_with_parens
   15397             :                 {
   15398             :                     /* Not sure how to get rid of the parentheses
   15399             :                      * but there are lots of shift/reduce errors without them.
   15400             :                      *
   15401             :                      * Should be able to implement this by plopping the entire
   15402             :                      * select into a node, then transforming the target expressions
   15403             :                      * from whatever they are into count(*), and testing the
   15404             :                      * entire result equal to one.
   15405             :                      * But, will probably implement a separate node in the executor.
   15406             :                      */
   15407           0 :                     ereport(ERROR,
   15408             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   15409             :                              errmsg("UNIQUE predicate is not yet implemented"),
   15410             :                              parser_errposition(@1)));
   15411             :                 }
   15412             :             | a_expr IS DOCUMENT_P                  %prec IS
   15413             :                 {
   15414          18 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15415          18 :                                      list_make1($1), @2);
   15416             :                 }
   15417             :             | a_expr IS NOT DOCUMENT_P              %prec IS
   15418             :                 {
   15419          18 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15420          18 :                                                  list_make1($1), @2),
   15421          18 :                                      @2);
   15422             :                 }
   15423             :             | a_expr IS NORMALIZED                              %prec IS
   15424             :                 {
   15425          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15426          12 :                                                list_make1($1),
   15427             :                                                COERCE_SQL_SYNTAX,
   15428          12 :                                                @2);
   15429             :                 }
   15430             :             | a_expr IS unicode_normal_form NORMALIZED          %prec IS
   15431             :                 {
   15432          36 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15433          36 :                                                list_make2($1, makeStringConst($3, @3)),
   15434             :                                                COERCE_SQL_SYNTAX,
   15435          36 :                                                @2);
   15436             :                 }
   15437             :             | a_expr IS NOT NORMALIZED                          %prec IS
   15438             :                 {
   15439           0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15440           0 :                                                            list_make1($1),
   15441             :                                                            COERCE_SQL_SYNTAX,
   15442           0 :                                                            @2),
   15443           0 :                                      @2);
   15444             :                 }
   15445             :             | a_expr IS NOT unicode_normal_form NORMALIZED      %prec IS
   15446             :                 {
   15447           0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15448           0 :                                                            list_make2($1, makeStringConst($4, @4)),
   15449             :                                                            COERCE_SQL_SYNTAX,
   15450           0 :                                                            @2),
   15451           0 :                                      @2);
   15452             :                 }
   15453             :             | a_expr IS json_predicate_type_constraint
   15454             :                     json_key_uniqueness_constraint_opt      %prec IS
   15455             :                 {
   15456         304 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   15457             : 
   15458         304 :                     $$ = makeJsonIsPredicate($1, format, $3, $4, @1);
   15459             :                 }
   15460             :             /*
   15461             :              * Required by SQL/JSON, but there are conflicts
   15462             :             | a_expr
   15463             :                 json_format_clause
   15464             :                 IS  json_predicate_type_constraint
   15465             :                     json_key_uniqueness_constraint_opt      %prec IS
   15466             :                 {
   15467             :                     $$ = makeJsonIsPredicate($1, $2, $4, $5, @1);
   15468             :                 }
   15469             :             */
   15470             :             | a_expr IS NOT
   15471             :                     json_predicate_type_constraint
   15472             :                     json_key_uniqueness_constraint_opt      %prec IS
   15473             :                 {
   15474          46 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   15475             : 
   15476          46 :                     $$ = makeNotExpr(makeJsonIsPredicate($1, format, $4, $5, @1), @1);
   15477             :                 }
   15478             :             /*
   15479             :              * Required by SQL/JSON, but there are conflicts
   15480             :             | a_expr
   15481             :                 json_format_clause
   15482             :                 IS NOT
   15483             :                     json_predicate_type_constraint
   15484             :                     json_key_uniqueness_constraint_opt      %prec IS
   15485             :                 {
   15486             :                     $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, @1), @1);
   15487             :                 }
   15488             :             */
   15489             :             | DEFAULT
   15490             :                 {
   15491             :                     /*
   15492             :                      * The SQL spec only allows DEFAULT in "contextually typed
   15493             :                      * expressions", but for us, it's easier to allow it in
   15494             :                      * any a_expr and then throw error during parse analysis
   15495             :                      * if it's in an inappropriate context.  This way also
   15496             :                      * lets us say something smarter than "syntax error".
   15497             :                      */
   15498        1536 :                     SetToDefault *n = makeNode(SetToDefault);
   15499             : 
   15500             :                     /* parse analysis will fill in the rest */
   15501        1536 :                     n->location = @1;
   15502        1536 :                     $$ = (Node *) n;
   15503             :                 }
   15504             :         ;
   15505             : 
   15506             : /*
   15507             :  * Restricted expressions
   15508             :  *
   15509             :  * b_expr is a subset of the complete expression syntax defined by a_expr.
   15510             :  *
   15511             :  * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
   15512             :  * cause trouble in the places where b_expr is used.  For simplicity, we
   15513             :  * just eliminate all the boolean-keyword-operator productions from b_expr.
   15514             :  */
   15515             : b_expr:     c_expr
   15516        3874 :                 { $$ = $1; }
   15517             :             | b_expr TYPECAST Typename
   15518         240 :                 { $$ = makeTypeCast($1, $3, @2); }
   15519             :             | '+' b_expr                    %prec UMINUS
   15520           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   15521             :             | '-' b_expr                    %prec UMINUS
   15522          66 :                 { $$ = doNegate($2, @1); }
   15523             :             | b_expr '+' b_expr
   15524          36 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   15525             :             | b_expr '-' b_expr
   15526          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   15527             :             | b_expr '*' b_expr
   15528          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   15529             :             | b_expr '/' b_expr
   15530           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   15531             :             | b_expr '%' b_expr
   15532           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   15533             :             | b_expr '^' b_expr
   15534           6 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   15535             :             | b_expr '<' b_expr
   15536           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   15537             :             | b_expr '>' b_expr
   15538           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   15539             :             | b_expr '=' b_expr
   15540           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   15541             :             | b_expr LESS_EQUALS b_expr
   15542           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   15543             :             | b_expr GREATER_EQUALS b_expr
   15544           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   15545             :             | b_expr NOT_EQUALS b_expr
   15546           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   15547             :             | b_expr qual_Op b_expr             %prec Op
   15548          12 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   15549             :             | qual_Op b_expr                    %prec Op
   15550           0 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   15551             :             | b_expr IS DISTINCT FROM b_expr        %prec IS
   15552             :                 {
   15553           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   15554             :                 }
   15555             :             | b_expr IS NOT DISTINCT FROM b_expr    %prec IS
   15556             :                 {
   15557           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   15558             :                 }
   15559             :             | b_expr IS DOCUMENT_P                  %prec IS
   15560             :                 {
   15561           0 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15562           0 :                                      list_make1($1), @2);
   15563             :                 }
   15564             :             | b_expr IS NOT DOCUMENT_P              %prec IS
   15565             :                 {
   15566           0 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15567           0 :                                                  list_make1($1), @2),
   15568           0 :                                      @2);
   15569             :                 }
   15570             :         ;
   15571             : 
   15572             : /*
   15573             :  * Productions that can be used in both a_expr and b_expr.
   15574             :  *
   15575             :  * Note: productions that refer recursively to a_expr or b_expr mostly
   15576             :  * cannot appear here.  However, it's OK to refer to a_exprs that occur
   15577             :  * inside parentheses, such as function arguments; that cannot introduce
   15578             :  * ambiguity to the b_expr syntax.
   15579             :  */
   15580     1873496 : c_expr:     columnref                               { $$ = $1; }
   15581     1259894 :             | AexprConst                            { $$ = $1; }
   15582             :             | PARAM opt_indirection
   15583             :                 {
   15584       46390 :                     ParamRef   *p = makeNode(ParamRef);
   15585             : 
   15586       46390 :                     p->number = $1;
   15587       46390 :                     p->location = @1;
   15588       46390 :                     if ($2)
   15589             :                     {
   15590        1098 :                         A_Indirection *n = makeNode(A_Indirection);
   15591             : 
   15592        1098 :                         n->arg = (Node *) p;
   15593        1098 :                         n->indirection = check_indirection($2, yyscanner);
   15594        1098 :                         $$ = (Node *) n;
   15595             :                     }
   15596             :                     else
   15597       45292 :                         $$ = (Node *) p;
   15598             :                 }
   15599             :             | '(' a_expr ')' opt_indirection
   15600             :                 {
   15601       93988 :                     if ($4)
   15602             :                     {
   15603       12566 :                         A_Indirection *n = makeNode(A_Indirection);
   15604             : 
   15605       12566 :                         n->arg = $2;
   15606       12566 :                         n->indirection = check_indirection($4, yyscanner);
   15607       12566 :                         $$ = (Node *) n;
   15608             :                     }
   15609             :                     else
   15610       81422 :                         $$ = $2;
   15611             :                 }
   15612             :             | case_expr
   15613       40518 :                 { $$ = $1; }
   15614             :             | func_expr
   15615      398174 :                 { $$ = $1; }
   15616             :             | select_with_parens            %prec UMINUS
   15617             :                 {
   15618       28996 :                     SubLink    *n = makeNode(SubLink);
   15619             : 
   15620       28996 :                     n->subLinkType = EXPR_SUBLINK;
   15621       28996 :                     n->subLinkId = 0;
   15622       28996 :                     n->testexpr = NULL;
   15623       28996 :                     n->operName = NIL;
   15624       28996 :                     n->subselect = $1;
   15625       28996 :                     n->location = @1;
   15626       28996 :                     $$ = (Node *) n;
   15627             :                 }
   15628             :             | select_with_parens indirection
   15629             :                 {
   15630             :                     /*
   15631             :                      * Because the select_with_parens nonterminal is designed
   15632             :                      * to "eat" as many levels of parens as possible, the
   15633             :                      * '(' a_expr ')' opt_indirection production above will
   15634             :                      * fail to match a sub-SELECT with indirection decoration;
   15635             :                      * the sub-SELECT won't be regarded as an a_expr as long
   15636             :                      * as there are parens around it.  To support applying
   15637             :                      * subscripting or field selection to a sub-SELECT result,
   15638             :                      * we need this redundant-looking production.
   15639             :                      */
   15640          18 :                     SubLink    *n = makeNode(SubLink);
   15641          18 :                     A_Indirection *a = makeNode(A_Indirection);
   15642             : 
   15643          18 :                     n->subLinkType = EXPR_SUBLINK;
   15644          18 :                     n->subLinkId = 0;
   15645          18 :                     n->testexpr = NULL;
   15646          18 :                     n->operName = NIL;
   15647          18 :                     n->subselect = $1;
   15648          18 :                     n->location = @1;
   15649          18 :                     a->arg = (Node *) n;
   15650          18 :                     a->indirection = check_indirection($2, yyscanner);
   15651          18 :                     $$ = (Node *) a;
   15652             :                 }
   15653             :             | EXISTS select_with_parens
   15654             :                 {
   15655        6470 :                     SubLink    *n = makeNode(SubLink);
   15656             : 
   15657        6470 :                     n->subLinkType = EXISTS_SUBLINK;
   15658        6470 :                     n->subLinkId = 0;
   15659        6470 :                     n->testexpr = NULL;
   15660        6470 :                     n->operName = NIL;
   15661        6470 :                     n->subselect = $2;
   15662        6470 :                     n->location = @1;
   15663        6470 :                     $$ = (Node *) n;
   15664             :                 }
   15665             :             | ARRAY select_with_parens
   15666             :                 {
   15667        8932 :                     SubLink    *n = makeNode(SubLink);
   15668             : 
   15669        8932 :                     n->subLinkType = ARRAY_SUBLINK;
   15670        8932 :                     n->subLinkId = 0;
   15671        8932 :                     n->testexpr = NULL;
   15672        8932 :                     n->operName = NIL;
   15673        8932 :                     n->subselect = $2;
   15674        8932 :                     n->location = @1;
   15675        8932 :                     $$ = (Node *) n;
   15676             :                 }
   15677             :             | ARRAY array_expr
   15678             :                 {
   15679        7480 :                     A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
   15680             : 
   15681             :                     /* point outermost A_ArrayExpr to the ARRAY keyword */
   15682        7480 :                     n->location = @1;
   15683        7480 :                     $$ = (Node *) n;
   15684             :                 }
   15685             :             | explicit_row
   15686             :                 {
   15687        3816 :                     RowExpr    *r = makeNode(RowExpr);
   15688             : 
   15689        3816 :                     r->args = $1;
   15690        3816 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15691        3816 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15692        3816 :                     r->row_format = COERCE_EXPLICIT_CALL; /* abuse */
   15693        3816 :                     r->location = @1;
   15694        3816 :                     $$ = (Node *) r;
   15695             :                 }
   15696             :             | implicit_row
   15697             :                 {
   15698        2674 :                     RowExpr    *r = makeNode(RowExpr);
   15699             : 
   15700        2674 :                     r->args = $1;
   15701        2674 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15702        2674 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15703        2674 :                     r->row_format = COERCE_IMPLICIT_CAST; /* abuse */
   15704        2674 :                     r->location = @1;
   15705        2674 :                     $$ = (Node *) r;
   15706             :                 }
   15707             :             | GROUPING '(' expr_list ')'
   15708             :               {
   15709         362 :                   GroupingFunc *g = makeNode(GroupingFunc);
   15710             : 
   15711         362 :                   g->args = $3;
   15712         362 :                   g->location = @1;
   15713         362 :                   $$ = (Node *) g;
   15714             :               }
   15715             :         ;
   15716             : 
   15717             : func_application: func_name '(' ')'
   15718             :                 {
   15719       33136 :                     $$ = (Node *) makeFuncCall($1, NIL,
   15720             :                                                COERCE_EXPLICIT_CALL,
   15721       33136 :                                                @1);
   15722             :                 }
   15723             :             | func_name '(' func_arg_list opt_sort_clause ')'
   15724             :                 {
   15725      323076 :                     FuncCall   *n = makeFuncCall($1, $3,
   15726             :                                                  COERCE_EXPLICIT_CALL,
   15727      323076 :                                                  @1);
   15728             : 
   15729      323076 :                     n->agg_order = $4;
   15730      323076 :                     $$ = (Node *) n;
   15731             :                 }
   15732             :             | func_name '(' VARIADIC func_arg_expr opt_sort_clause ')'
   15733             :                 {
   15734         614 :                     FuncCall   *n = makeFuncCall($1, list_make1($4),
   15735             :                                                  COERCE_EXPLICIT_CALL,
   15736         614 :                                                  @1);
   15737             : 
   15738         614 :                     n->func_variadic = true;
   15739         614 :                     n->agg_order = $5;
   15740         614 :                     $$ = (Node *) n;
   15741             :                 }
   15742             :             | func_name '(' func_arg_list ',' VARIADIC func_arg_expr opt_sort_clause ')'
   15743             :                 {
   15744         120 :                     FuncCall   *n = makeFuncCall($1, lappend($3, $6),
   15745             :                                                  COERCE_EXPLICIT_CALL,
   15746         120 :                                                  @1);
   15747             : 
   15748         120 :                     n->func_variadic = true;
   15749         120 :                     n->agg_order = $7;
   15750         120 :                     $$ = (Node *) n;
   15751             :                 }
   15752             :             | func_name '(' ALL func_arg_list opt_sort_clause ')'
   15753             :                 {
   15754           0 :                     FuncCall   *n = makeFuncCall($1, $4,
   15755             :                                                  COERCE_EXPLICIT_CALL,
   15756           0 :                                                  @1);
   15757             : 
   15758           0 :                     n->agg_order = $5;
   15759             :                     /* Ideally we'd mark the FuncCall node to indicate
   15760             :                      * "must be an aggregate", but there's no provision
   15761             :                      * for that in FuncCall at the moment.
   15762             :                      */
   15763           0 :                     $$ = (Node *) n;
   15764             :                 }
   15765             :             | func_name '(' DISTINCT func_arg_list opt_sort_clause ')'
   15766             :                 {
   15767         550 :                     FuncCall   *n = makeFuncCall($1, $4,
   15768             :                                                  COERCE_EXPLICIT_CALL,
   15769         550 :                                                  @1);
   15770             : 
   15771         550 :                     n->agg_order = $5;
   15772         550 :                     n->agg_distinct = true;
   15773         550 :                     $$ = (Node *) n;
   15774             :                 }
   15775             :             | func_name '(' '*' ')'
   15776             :                 {
   15777             :                     /*
   15778             :                      * We consider AGGREGATE(*) to invoke a parameterless
   15779             :                      * aggregate.  This does the right thing for COUNT(*),
   15780             :                      * and there are no other aggregates in SQL that accept
   15781             :                      * '*' as parameter.
   15782             :                      *
   15783             :                      * The FuncCall node is also marked agg_star = true,
   15784             :                      * so that later processing can detect what the argument
   15785             :                      * really was.
   15786             :                      */
   15787       12624 :                     FuncCall   *n = makeFuncCall($1, NIL,
   15788             :                                                  COERCE_EXPLICIT_CALL,
   15789       12624 :                                                  @1);
   15790             : 
   15791       12624 :                     n->agg_star = true;
   15792       12624 :                     $$ = (Node *) n;
   15793             :                 }
   15794             :         ;
   15795             : 
   15796             : 
   15797             : /*
   15798             :  * func_expr and its cousin func_expr_windowless are split out from c_expr just
   15799             :  * so that we have classifications for "everything that is a function call or
   15800             :  * looks like one".  This isn't very important, but it saves us having to
   15801             :  * document which variants are legal in places like "FROM function()" or the
   15802             :  * backwards-compatible functional-index syntax for CREATE INDEX.
   15803             :  * (Note that many of the special SQL functions wouldn't actually make any
   15804             :  * sense as functional index entries, but we ignore that consideration here.)
   15805             :  */
   15806             : func_expr: func_application within_group_clause filter_clause over_clause
   15807             :                 {
   15808      320130 :                     FuncCall   *n = (FuncCall *) $1;
   15809             : 
   15810             :                     /*
   15811             :                      * The order clause for WITHIN GROUP and the one for
   15812             :                      * plain-aggregate ORDER BY share a field, so we have to
   15813             :                      * check here that at most one is present.  We also check
   15814             :                      * for DISTINCT and VARIADIC here to give a better error
   15815             :                      * location.  Other consistency checks are deferred to
   15816             :                      * parse analysis.
   15817             :                      */
   15818      320130 :                     if ($2 != NIL)
   15819             :                     {
   15820         348 :                         if (n->agg_order != NIL)
   15821           6 :                             ereport(ERROR,
   15822             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15823             :                                      errmsg("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
   15824             :                                      parser_errposition(@2)));
   15825         342 :                         if (n->agg_distinct)
   15826           0 :                             ereport(ERROR,
   15827             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15828             :                                      errmsg("cannot use DISTINCT with WITHIN GROUP"),
   15829             :                                      parser_errposition(@2)));
   15830         342 :                         if (n->func_variadic)
   15831           0 :                             ereport(ERROR,
   15832             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15833             :                                      errmsg("cannot use VARIADIC with WITHIN GROUP"),
   15834             :                                      parser_errposition(@2)));
   15835         342 :                         n->agg_order = $2;
   15836         342 :                         n->agg_within_group = true;
   15837             :                     }
   15838      320124 :                     n->agg_filter = $3;
   15839      320124 :                     n->over = $4;
   15840      320124 :                     $$ = (Node *) n;
   15841             :                 }
   15842             :             | json_aggregate_func filter_clause over_clause
   15843             :                 {
   15844         720 :                     JsonAggConstructor *n = IsA($1, JsonObjectAgg) ?
   15845         360 :                         ((JsonObjectAgg *) $1)->constructor :
   15846         156 :                         ((JsonArrayAgg *) $1)->constructor;
   15847             : 
   15848         360 :                     n->agg_filter = $2;
   15849         360 :                     n->over = $3;
   15850         360 :                     $$ = (Node *) $1;
   15851             :                 }
   15852             :             | func_expr_common_subexpr
   15853       77690 :                 { $$ = $1; }
   15854             :         ;
   15855             : 
   15856             : /*
   15857             :  * Like func_expr but does not accept WINDOW functions directly
   15858             :  * (but they can still be contained in arguments for functions etc).
   15859             :  * Use this when window expressions are not allowed, where needed to
   15860             :  * disambiguate the grammar (e.g. in CREATE INDEX).
   15861             :  */
   15862             : func_expr_windowless:
   15863       49364 :             func_application                        { $$ = $1; }
   15864         402 :             | func_expr_common_subexpr              { $$ = $1; }
   15865           0 :             | json_aggregate_func                   { $$ = $1; }
   15866             :         ;
   15867             : 
   15868             : /*
   15869             :  * Special expressions that are considered to be functions.
   15870             :  */
   15871             : func_expr_common_subexpr:
   15872             :             COLLATION FOR '(' a_expr ')'
   15873             :                 {
   15874          30 :                     $$ = (Node *) makeFuncCall(SystemFuncName("pg_collation_for"),
   15875          30 :                                                list_make1($4),
   15876             :                                                COERCE_SQL_SYNTAX,
   15877          30 :                                                @1);
   15878             :                 }
   15879             :             | CURRENT_DATE
   15880             :                 {
   15881         312 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_DATE, -1, @1);
   15882             :                 }
   15883             :             | CURRENT_TIME
   15884             :                 {
   15885          24 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME, -1, @1);
   15886             :                 }
   15887             :             | CURRENT_TIME '(' Iconst ')'
   15888             :                 {
   15889          24 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME_N, $3, @1);
   15890             :                 }
   15891             :             | CURRENT_TIMESTAMP
   15892             :                 {
   15893         284 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP, -1, @1);
   15894             :                 }
   15895             :             | CURRENT_TIMESTAMP '(' Iconst ')'
   15896             :                 {
   15897         176 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP_N, $3, @1);
   15898             :                 }
   15899             :             | LOCALTIME
   15900             :                 {
   15901          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIME, -1, @1);
   15902             :                 }
   15903             :             | LOCALTIME '(' Iconst ')'
   15904             :                 {
   15905          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIME_N, $3, @1);
   15906             :                 }
   15907             :             | LOCALTIMESTAMP
   15908             :                 {
   15909          36 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP, -1, @1);
   15910             :                 }
   15911             :             | LOCALTIMESTAMP '(' Iconst ')'
   15912             :                 {
   15913          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP_N, $3, @1);
   15914             :                 }
   15915             :             | CURRENT_ROLE
   15916             :                 {
   15917          68 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_ROLE, -1, @1);
   15918             :                 }
   15919             :             | CURRENT_USER
   15920             :                 {
   15921        1092 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_USER, -1, @1);
   15922             :                 }
   15923             :             | SESSION_USER
   15924             :                 {
   15925         570 :                     $$ = makeSQLValueFunction(SVFOP_SESSION_USER, -1, @1);
   15926             :                 }
   15927             :             | SYSTEM_USER
   15928             :                 {
   15929          20 :                     $$ = (Node *) makeFuncCall(SystemFuncName("system_user"),
   15930             :                                                NIL,
   15931             :                                                COERCE_SQL_SYNTAX,
   15932             :                                                @1);
   15933             :                 }
   15934             :             | USER
   15935             :                 {
   15936          24 :                     $$ = makeSQLValueFunction(SVFOP_USER, -1, @1);
   15937             :                 }
   15938             :             | CURRENT_CATALOG
   15939             :                 {
   15940          52 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_CATALOG, -1, @1);
   15941             :                 }
   15942             :             | CURRENT_SCHEMA
   15943             :                 {
   15944          30 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_SCHEMA, -1, @1);
   15945             :                 }
   15946             :             | CAST '(' a_expr AS Typename ')'
   15947       63758 :                 { $$ = makeTypeCast($3, $5, @1); }
   15948             :             | EXTRACT '(' extract_list ')'
   15949             :                 {
   15950        1390 :                     $$ = (Node *) makeFuncCall(SystemFuncName("extract"),
   15951        1390 :                                                $3,
   15952             :                                                COERCE_SQL_SYNTAX,
   15953        1390 :                                                @1);
   15954             :                 }
   15955             :             | NORMALIZE '(' a_expr ')'
   15956             :                 {
   15957          18 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   15958          18 :                                                list_make1($3),
   15959             :                                                COERCE_SQL_SYNTAX,
   15960          18 :                                                @1);
   15961             :                 }
   15962             :             | NORMALIZE '(' a_expr ',' unicode_normal_form ')'
   15963             :                 {
   15964          42 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   15965          42 :                                                list_make2($3, makeStringConst($5, @5)),
   15966             :                                                COERCE_SQL_SYNTAX,
   15967          42 :                                                @1);
   15968             :                 }
   15969             :             | OVERLAY '(' overlay_list ')'
   15970             :                 {
   15971          82 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlay"),
   15972          82 :                                                $3,
   15973             :                                                COERCE_SQL_SYNTAX,
   15974          82 :                                                @1);
   15975             :                 }
   15976             :             | OVERLAY '(' func_arg_list_opt ')'
   15977             :                 {
   15978             :                     /*
   15979             :                      * allow functions named overlay() to be called without
   15980             :                      * special syntax
   15981             :                      */
   15982           0 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("overlay")),
   15983           0 :                                                $3,
   15984             :                                                COERCE_EXPLICIT_CALL,
   15985           0 :                                                @1);
   15986             :                 }
   15987             :             | POSITION '(' position_list ')'
   15988             :                 {
   15989             :                     /*
   15990             :                      * position(A in B) is converted to position(B, A)
   15991             :                      *
   15992             :                      * We deliberately don't offer a "plain syntax" option
   15993             :                      * for position(), because the reversal of the arguments
   15994             :                      * creates too much risk of confusion.
   15995             :                      */
   15996         402 :                     $$ = (Node *) makeFuncCall(SystemFuncName("position"),
   15997         402 :                                                $3,
   15998             :                                                COERCE_SQL_SYNTAX,
   15999         402 :                                                @1);
   16000             :                 }
   16001             :             | SUBSTRING '(' substr_list ')'
   16002             :                 {
   16003             :                     /* substring(A from B for C) is converted to
   16004             :                      * substring(A, B, C) - thomas 2000-11-28
   16005             :                      */
   16006         718 :                     $$ = (Node *) makeFuncCall(SystemFuncName("substring"),
   16007         718 :                                                $3,
   16008             :                                                COERCE_SQL_SYNTAX,
   16009         718 :                                                @1);
   16010             :                 }
   16011             :             | SUBSTRING '(' func_arg_list_opt ')'
   16012             :                 {
   16013             :                     /*
   16014             :                      * allow functions named substring() to be called without
   16015             :                      * special syntax
   16016             :                      */
   16017         254 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("substring")),
   16018         254 :                                                $3,
   16019             :                                                COERCE_EXPLICIT_CALL,
   16020         254 :                                                @1);
   16021             :                 }
   16022             :             | TREAT '(' a_expr AS Typename ')'
   16023             :                 {
   16024             :                     /* TREAT(expr AS target) converts expr of a particular type to target,
   16025             :                      * which is defined to be a subtype of the original expression.
   16026             :                      * In SQL99, this is intended for use with structured UDTs,
   16027             :                      * but let's make this a generally useful form allowing stronger
   16028             :                      * coercions than are handled by implicit casting.
   16029             :                      *
   16030             :                      * Convert SystemTypeName() to SystemFuncName() even though
   16031             :                      * at the moment they result in the same thing.
   16032             :                      */
   16033           0 :                     $$ = (Node *) makeFuncCall(SystemFuncName(strVal(llast($5->names))),
   16034           0 :                                                list_make1($3),
   16035             :                                                COERCE_EXPLICIT_CALL,
   16036           0 :                                                @1);
   16037             :                 }
   16038             :             | TRIM '(' BOTH trim_list ')'
   16039             :                 {
   16040             :                     /* various trim expressions are defined in SQL
   16041             :                      * - thomas 1997-07-19
   16042             :                      */
   16043          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   16044          12 :                                                $4,
   16045             :                                                COERCE_SQL_SYNTAX,
   16046          12 :                                                @1);
   16047             :                 }
   16048             :             | TRIM '(' LEADING trim_list ')'
   16049             :                 {
   16050          24 :                     $$ = (Node *) makeFuncCall(SystemFuncName("ltrim"),
   16051          24 :                                                $4,
   16052             :                                                COERCE_SQL_SYNTAX,
   16053          24 :                                                @1);
   16054             :                 }
   16055             :             | TRIM '(' TRAILING trim_list ')'
   16056             :                 {
   16057         582 :                     $$ = (Node *) makeFuncCall(SystemFuncName("rtrim"),
   16058         582 :                                                $4,
   16059             :                                                COERCE_SQL_SYNTAX,
   16060         582 :                                                @1);
   16061             :                 }
   16062             :             | TRIM '(' trim_list ')'
   16063             :                 {
   16064          98 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   16065          98 :                                                $3,
   16066             :                                                COERCE_SQL_SYNTAX,
   16067          98 :                                                @1);
   16068             :                 }
   16069             :             | NULLIF '(' a_expr ',' a_expr ')'
   16070             :                 {
   16071         420 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
   16072             :                 }
   16073             :             | COALESCE '(' expr_list ')'
   16074             :                 {
   16075        3248 :                     CoalesceExpr *c = makeNode(CoalesceExpr);
   16076             : 
   16077        3248 :                     c->args = $3;
   16078        3248 :                     c->location = @1;
   16079        3248 :                     $$ = (Node *) c;
   16080             :                 }
   16081             :             | GREATEST '(' expr_list ')'
   16082             :                 {
   16083         146 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   16084             : 
   16085         146 :                     v->args = $3;
   16086         146 :                     v->op = IS_GREATEST;
   16087         146 :                     v->location = @1;
   16088         146 :                     $$ = (Node *) v;
   16089             :                 }
   16090             :             | LEAST '(' expr_list ')'
   16091             :                 {
   16092         124 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   16093             : 
   16094         124 :                     v->args = $3;
   16095         124 :                     v->op = IS_LEAST;
   16096         124 :                     v->location = @1;
   16097         124 :                     $$ = (Node *) v;
   16098             :                 }
   16099             :             | XMLCONCAT '(' expr_list ')'
   16100             :                 {
   16101          64 :                     $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
   16102             :                 }
   16103             :             | XMLELEMENT '(' NAME_P ColLabel ')'
   16104             :                 {
   16105           6 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
   16106             :                 }
   16107             :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
   16108             :                 {
   16109          36 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
   16110             :                 }
   16111             :             | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
   16112             :                 {
   16113         118 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
   16114             :                 }
   16115             :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
   16116             :                 {
   16117          22 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
   16118             :                 }
   16119             :             | XMLEXISTS '(' c_expr xmlexists_argument ')'
   16120             :                 {
   16121             :                     /* xmlexists(A PASSING [BY REF] B [BY REF]) is
   16122             :                      * converted to xmlexists(A, B)*/
   16123          54 :                     $$ = (Node *) makeFuncCall(SystemFuncName("xmlexists"),
   16124          54 :                                                list_make2($3, $4),
   16125             :                                                COERCE_SQL_SYNTAX,
   16126          54 :                                                @1);
   16127             :                 }
   16128             :             | XMLFOREST '(' xml_attribute_list ')'
   16129             :                 {
   16130          34 :                     $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
   16131             :                 }
   16132             :             | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
   16133             :                 {
   16134             :                     XmlExpr *x = (XmlExpr *)
   16135         142 :                         makeXmlExpr(IS_XMLPARSE, NULL, NIL,
   16136         142 :                                     list_make2($4, makeBoolAConst($5, -1)),
   16137         142 :                                     @1);
   16138             : 
   16139         142 :                     x->xmloption = $3;
   16140         142 :                     $$ = (Node *) x;
   16141             :                 }
   16142             :             | XMLPI '(' NAME_P ColLabel ')'
   16143             :                 {
   16144          30 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
   16145             :                 }
   16146             :             | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
   16147             :                 {
   16148          52 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
   16149             :                 }
   16150             :             | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
   16151             :                 {
   16152          70 :                     $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
   16153          70 :                                      list_make3($3, $5, $6), @1);
   16154             :                 }
   16155             :             | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename xml_indent_option ')'
   16156             :                 {
   16157         226 :                     XmlSerialize *n = makeNode(XmlSerialize);
   16158             : 
   16159         226 :                     n->xmloption = $3;
   16160         226 :                     n->expr = $4;
   16161         226 :                     n->typeName = $6;
   16162         226 :                     n->indent = $7;
   16163         226 :                     n->location = @1;
   16164         226 :                     $$ = (Node *) n;
   16165             :                 }
   16166             :             | JSON_OBJECT '(' func_arg_list ')'
   16167             :                 {
   16168             :                     /* Support for legacy (non-standard) json_object() */
   16169          90 :                     $$ = (Node *) makeFuncCall(SystemFuncName("json_object"),
   16170          90 :                                                $3, COERCE_EXPLICIT_CALL, @1);
   16171             :                 }
   16172             :             | JSON_OBJECT '(' json_name_and_value_list
   16173             :                 json_object_constructor_null_clause_opt
   16174             :                 json_key_uniqueness_constraint_opt
   16175             :                 json_returning_clause_opt ')'
   16176             :                 {
   16177         348 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   16178             : 
   16179         348 :                     n->exprs = $3;
   16180         348 :                     n->absent_on_null = $4;
   16181         348 :                     n->unique = $5;
   16182         348 :                     n->output = (JsonOutput *) $6;
   16183         348 :                     n->location = @1;
   16184         348 :                     $$ = (Node *) n;
   16185             :                 }
   16186             :             | JSON_OBJECT '(' json_returning_clause_opt ')'
   16187             :                 {
   16188          92 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   16189             : 
   16190          92 :                     n->exprs = NULL;
   16191          92 :                     n->absent_on_null = false;
   16192          92 :                     n->unique = false;
   16193          92 :                     n->output = (JsonOutput *) $3;
   16194          92 :                     n->location = @1;
   16195          92 :                     $$ = (Node *) n;
   16196             :                 }
   16197             :             | JSON_ARRAY '('
   16198             :                 json_value_expr_list
   16199             :                 json_array_constructor_null_clause_opt
   16200             :                 json_returning_clause_opt
   16201             :             ')'
   16202             :                 {
   16203         108 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   16204             : 
   16205         108 :                     n->exprs = $3;
   16206         108 :                     n->absent_on_null = $4;
   16207         108 :                     n->output = (JsonOutput *) $5;
   16208         108 :                     n->location = @1;
   16209         108 :                     $$ = (Node *) n;
   16210             :                 }
   16211             :             | JSON_ARRAY '('
   16212             :                 select_no_parens
   16213             :                 json_format_clause_opt
   16214             :                 /* json_array_constructor_null_clause_opt */
   16215             :                 json_returning_clause_opt
   16216             :             ')'
   16217             :                 {
   16218          60 :                     JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
   16219             : 
   16220          60 :                     n->query = $3;
   16221          60 :                     n->format = (JsonFormat *) $4;
   16222          60 :                     n->absent_on_null = true;    /* XXX */
   16223          60 :                     n->output = (JsonOutput *) $5;
   16224          60 :                     n->location = @1;
   16225          60 :                     $$ = (Node *) n;
   16226             :                 }
   16227             :             | JSON_ARRAY '('
   16228             :                 json_returning_clause_opt
   16229             :             ')'
   16230             :                 {
   16231          86 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   16232             : 
   16233          86 :                     n->exprs = NIL;
   16234          86 :                     n->absent_on_null = true;
   16235          86 :                     n->output = (JsonOutput *) $3;
   16236          86 :                     n->location = @1;
   16237          86 :                     $$ = (Node *) n;
   16238             :                 }
   16239             :             | JSON '(' json_value_expr json_key_uniqueness_constraint_opt ')'
   16240             :                 {
   16241         164 :                     JsonParseExpr *n = makeNode(JsonParseExpr);
   16242             : 
   16243         164 :                     n->expr = (JsonValueExpr *) $3;
   16244         164 :                     n->unique_keys = $4;
   16245         164 :                     n->output = NULL;
   16246         164 :                     n->location = @1;
   16247         164 :                     $$ = (Node *) n;
   16248             :                 }
   16249             :             | JSON_SCALAR '(' a_expr ')'
   16250             :                 {
   16251         112 :                     JsonScalarExpr *n = makeNode(JsonScalarExpr);
   16252             : 
   16253         112 :                     n->expr = (Expr *) $3;
   16254         112 :                     n->output = NULL;
   16255         112 :                     n->location = @1;
   16256         112 :                     $$ = (Node *) n;
   16257             :                 }
   16258             :             | JSON_SERIALIZE '(' json_value_expr json_returning_clause_opt ')'
   16259             :                 {
   16260         108 :                     JsonSerializeExpr *n = makeNode(JsonSerializeExpr);
   16261             : 
   16262         108 :                     n->expr = (JsonValueExpr *) $3;
   16263         108 :                     n->output = (JsonOutput *) $4;
   16264         108 :                     n->location = @1;
   16265         108 :                     $$ = (Node *) n;
   16266             :                 }
   16267             :             | MERGE_ACTION '(' ')'
   16268             :                 {
   16269         210 :                     MergeSupportFunc *m = makeNode(MergeSupportFunc);
   16270             : 
   16271         210 :                     m->msftype = TEXTOID;
   16272         210 :                     m->location = @1;
   16273         210 :                     $$ = (Node *) m;
   16274             :                 }
   16275             :             | JSON_QUERY '('
   16276             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16277             :                 json_returning_clause_opt
   16278             :                 json_wrapper_behavior
   16279             :                 json_quotes_clause_opt
   16280             :                 json_behavior_clause_opt
   16281             :             ')'
   16282             :                 {
   16283         984 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16284             : 
   16285         984 :                     n->op = JSON_QUERY_OP;
   16286         984 :                     n->context_item = (JsonValueExpr *) $3;
   16287         984 :                     n->pathspec = $5;
   16288         984 :                     n->passing = $6;
   16289         984 :                     n->output = (JsonOutput *) $7;
   16290         984 :                     n->wrapper = $8;
   16291         984 :                     n->quotes = $9;
   16292         984 :                     n->on_empty = (JsonBehavior *) linitial($10);
   16293         984 :                     n->on_error = (JsonBehavior *) lsecond($10);
   16294         984 :                     n->location = @1;
   16295         984 :                     $$ = (Node *) n;
   16296             :                 }
   16297             :             | JSON_EXISTS '('
   16298             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16299             :                 json_on_error_clause_opt
   16300             :             ')'
   16301             :                 {
   16302         168 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16303             : 
   16304         168 :                     n->op = JSON_EXISTS_OP;
   16305         168 :                     n->context_item = (JsonValueExpr *) $3;
   16306         168 :                     n->pathspec = $5;
   16307         168 :                     n->passing = $6;
   16308         168 :                     n->output = NULL;
   16309         168 :                     n->on_error = (JsonBehavior *) $7;
   16310         168 :                     n->location = @1;
   16311         168 :                     $$ = (Node *) n;
   16312             :                 }
   16313             :             | JSON_VALUE '('
   16314             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16315             :                 json_returning_clause_opt
   16316             :                 json_behavior_clause_opt
   16317             :             ')'
   16318             :                 {
   16319         576 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16320             : 
   16321         576 :                     n->op = JSON_VALUE_OP;
   16322         576 :                     n->context_item = (JsonValueExpr *) $3;
   16323         576 :                     n->pathspec = $5;
   16324         576 :                     n->passing = $6;
   16325         576 :                     n->output = (JsonOutput *) $7;
   16326         576 :                     n->on_empty = (JsonBehavior *) linitial($8);
   16327         576 :                     n->on_error = (JsonBehavior *) lsecond($8);
   16328         576 :                     n->location = @1;
   16329         576 :                     $$ = (Node *) n;
   16330             :                 }
   16331             :             ;
   16332             : 
   16333             : 
   16334             : /*
   16335             :  * SQL/XML support
   16336             :  */
   16337             : xml_root_version: VERSION_P a_expr
   16338          24 :                 { $$ = $2; }
   16339             :             | VERSION_P NO VALUE_P
   16340          46 :                 { $$ = makeNullAConst(-1); }
   16341             :         ;
   16342             : 
   16343             : opt_xml_root_standalone: ',' STANDALONE_P YES_P
   16344          28 :                 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
   16345             :             | ',' STANDALONE_P NO
   16346          12 :                 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
   16347             :             | ',' STANDALONE_P NO VALUE_P
   16348          12 :                 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
   16349             :             | /*EMPTY*/
   16350          18 :                 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
   16351             :         ;
   16352             : 
   16353          58 : xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')'    { $$ = $3; }
   16354             :         ;
   16355             : 
   16356          92 : xml_attribute_list: xml_attribute_el                    { $$ = list_make1($1); }
   16357         150 :             | xml_attribute_list ',' xml_attribute_el   { $$ = lappend($1, $3); }
   16358             :         ;
   16359             : 
   16360             : xml_attribute_el: a_expr AS ColLabel
   16361             :                 {
   16362         116 :                     $$ = makeNode(ResTarget);
   16363         116 :                     $$->name = $3;
   16364         116 :                     $$->indirection = NIL;
   16365         116 :                     $$->val = (Node *) $1;
   16366         116 :                     $$->location = @1;
   16367             :                 }
   16368             :             | a_expr
   16369             :                 {
   16370         126 :                     $$ = makeNode(ResTarget);
   16371         126 :                     $$->name = NULL;
   16372         126 :                     $$->indirection = NIL;
   16373         126 :                     $$->val = (Node *) $1;
   16374         126 :                     $$->location = @1;
   16375             :                 }
   16376             :         ;
   16377             : 
   16378         190 : document_or_content: DOCUMENT_P                     { $$ = XMLOPTION_DOCUMENT; }
   16379         194 :             | CONTENT_P                             { $$ = XMLOPTION_CONTENT; }
   16380             :         ;
   16381             : 
   16382         142 : xml_indent_option: INDENT                           { $$ = true; }
   16383          42 :             | NO INDENT                             { $$ = false; }
   16384          42 :             | /*EMPTY*/                             { $$ = false; }
   16385             :         ;
   16386             : 
   16387           0 : xml_whitespace_option: PRESERVE WHITESPACE_P        { $$ = true; }
   16388           4 :             | STRIP_P WHITESPACE_P                  { $$ = false; }
   16389         138 :             | /*EMPTY*/                             { $$ = false; }
   16390             :         ;
   16391             : 
   16392             : /* We allow several variants for SQL and other compatibility. */
   16393             : xmlexists_argument:
   16394             :             PASSING c_expr
   16395             :                 {
   16396         236 :                     $$ = $2;
   16397             :                 }
   16398             :             | PASSING c_expr xml_passing_mech
   16399             :                 {
   16400           0 :                     $$ = $2;
   16401             :                 }
   16402             :             | PASSING xml_passing_mech c_expr
   16403             :                 {
   16404          42 :                     $$ = $3;
   16405             :                 }
   16406             :             | PASSING xml_passing_mech c_expr xml_passing_mech
   16407             :                 {
   16408           6 :                     $$ = $3;
   16409             :                 }
   16410             :         ;
   16411             : 
   16412             : xml_passing_mech:
   16413             :             BY REF_P
   16414             :             | BY VALUE_P
   16415             :         ;
   16416             : 
   16417             : 
   16418             : /*
   16419             :  * Aggregate decoration clauses
   16420             :  */
   16421             : within_group_clause:
   16422         348 :             WITHIN GROUP_P '(' sort_clause ')'      { $$ = $4; }
   16423      319788 :             | /*EMPTY*/                             { $$ = NIL; }
   16424             :         ;
   16425             : 
   16426             : filter_clause:
   16427         854 :             FILTER '(' WHERE a_expr ')'             { $$ = $4; }
   16428      319642 :             | /*EMPTY*/                             { $$ = NULL; }
   16429             :         ;
   16430             : 
   16431             : 
   16432             : /*
   16433             :  * Window Definitions
   16434             :  */
   16435             : window_clause:
   16436         540 :             WINDOW window_definition_list           { $$ = $2; }
   16437      480276 :             | /*EMPTY*/                             { $$ = NIL; }
   16438             :         ;
   16439             : 
   16440             : window_definition_list:
   16441         540 :             window_definition                       { $$ = list_make1($1); }
   16442             :             | window_definition_list ',' window_definition
   16443          12 :                                                     { $$ = lappend($1, $3); }
   16444             :         ;
   16445             : 
   16446             : window_definition:
   16447             :             ColId AS window_specification
   16448             :                 {
   16449         552 :                     WindowDef  *n = $3;
   16450             : 
   16451         552 :                     n->name = $1;
   16452         552 :                     $$ = n;
   16453             :                 }
   16454             :         ;
   16455             : 
   16456             : over_clause: OVER window_specification
   16457        2618 :                 { $$ = $2; }
   16458             :             | OVER ColId
   16459             :                 {
   16460         954 :                     WindowDef  *n = makeNode(WindowDef);
   16461             : 
   16462         954 :                     n->name = $2;
   16463         954 :                     n->refname = NULL;
   16464         954 :                     n->partitionClause = NIL;
   16465         954 :                     n->orderClause = NIL;
   16466         954 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   16467         954 :                     n->startOffset = NULL;
   16468         954 :                     n->endOffset = NULL;
   16469         954 :                     n->location = @2;
   16470         954 :                     $$ = n;
   16471             :                 }
   16472             :             | /*EMPTY*/
   16473      316918 :                 { $$ = NULL; }
   16474             :         ;
   16475             : 
   16476             : window_specification: '(' opt_existing_window_name opt_partition_clause
   16477             :                         opt_sort_clause opt_frame_clause ')'
   16478             :                 {
   16479        3170 :                     WindowDef  *n = makeNode(WindowDef);
   16480             : 
   16481        3170 :                     n->name = NULL;
   16482        3170 :                     n->refname = $2;
   16483        3170 :                     n->partitionClause = $3;
   16484        3170 :                     n->orderClause = $4;
   16485             :                     /* copy relevant fields of opt_frame_clause */
   16486        3170 :                     n->frameOptions = $5->frameOptions;
   16487        3170 :                     n->startOffset = $5->startOffset;
   16488        3170 :                     n->endOffset = $5->endOffset;
   16489        3170 :                     n->location = @1;
   16490        3170 :                     $$ = n;
   16491             :                 }
   16492             :         ;
   16493             : 
   16494             : /*
   16495             :  * If we see PARTITION, RANGE, ROWS or GROUPS as the first token after the '('
   16496             :  * of a window_specification, we want the assumption to be that there is
   16497             :  * no existing_window_name; but those keywords are unreserved and so could
   16498             :  * be ColIds.  We fix this by making them have the same precedence as IDENT
   16499             :  * and giving the empty production here a slightly higher precedence, so
   16500             :  * that the shift/reduce conflict is resolved in favor of reducing the rule.
   16501             :  * These keywords are thus precluded from being an existing_window_name but
   16502             :  * are not reserved for any other purpose.
   16503             :  */
   16504          54 : opt_existing_window_name: ColId                     { $$ = $1; }
   16505        3122 :             | /*EMPTY*/             %prec Op        { $$ = NULL; }
   16506             :         ;
   16507             : 
   16508         922 : opt_partition_clause: PARTITION BY expr_list        { $$ = $3; }
   16509        2248 :             | /*EMPTY*/                             { $$ = NIL; }
   16510             :         ;
   16511             : 
   16512             : /*
   16513             :  * For frame clauses, we return a WindowDef, but only some fields are used:
   16514             :  * frameOptions, startOffset, and endOffset.
   16515             :  */
   16516             : opt_frame_clause:
   16517             :             RANGE frame_extent opt_window_exclusion_clause
   16518             :                 {
   16519         796 :                     WindowDef  *n = $2;
   16520             : 
   16521         796 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
   16522         796 :                     n->frameOptions |= $3;
   16523         796 :                     $$ = n;
   16524             :                 }
   16525             :             | ROWS frame_extent opt_window_exclusion_clause
   16526             :                 {
   16527         624 :                     WindowDef  *n = $2;
   16528             : 
   16529         624 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
   16530         624 :                     n->frameOptions |= $3;
   16531         624 :                     $$ = n;
   16532             :                 }
   16533             :             | GROUPS frame_extent opt_window_exclusion_clause
   16534             :                 {
   16535         204 :                     WindowDef  *n = $2;
   16536             : 
   16537         204 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_GROUPS;
   16538         204 :                     n->frameOptions |= $3;
   16539         204 :                     $$ = n;
   16540             :                 }
   16541             :             | /*EMPTY*/
   16542             :                 {
   16543        1546 :                     WindowDef  *n = makeNode(WindowDef);
   16544             : 
   16545        1546 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   16546        1546 :                     n->startOffset = NULL;
   16547        1546 :                     n->endOffset = NULL;
   16548        1546 :                     $$ = n;
   16549             :                 }
   16550             :         ;
   16551             : 
   16552             : frame_extent: frame_bound
   16553             :                 {
   16554          12 :                     WindowDef  *n = $1;
   16555             : 
   16556             :                     /* reject invalid cases */
   16557          12 :                     if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   16558           0 :                         ereport(ERROR,
   16559             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16560             :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   16561             :                                  parser_errposition(@1)));
   16562          12 :                     if (n->frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING)
   16563           0 :                         ereport(ERROR,
   16564             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16565             :                                  errmsg("frame starting from following row cannot end with current row"),
   16566             :                                  parser_errposition(@1)));
   16567          12 :                     n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
   16568          12 :                     $$ = n;
   16569             :                 }
   16570             :             | BETWEEN frame_bound AND frame_bound
   16571             :                 {
   16572        1612 :                     WindowDef  *n1 = $2;
   16573        1612 :                     WindowDef  *n2 = $4;
   16574             : 
   16575             :                     /* form merged options */
   16576        1612 :                     int     frameOptions = n1->frameOptions;
   16577             :                     /* shift converts START_ options to END_ options */
   16578        1612 :                     frameOptions |= n2->frameOptions << 1;
   16579        1612 :                     frameOptions |= FRAMEOPTION_BETWEEN;
   16580             :                     /* reject invalid cases */
   16581        1612 :                     if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   16582           0 :                         ereport(ERROR,
   16583             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16584             :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   16585             :                                  parser_errposition(@2)));
   16586        1612 :                     if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
   16587           0 :                         ereport(ERROR,
   16588             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16589             :                                  errmsg("frame end cannot be UNBOUNDED PRECEDING"),
   16590             :                                  parser_errposition(@4)));
   16591        1612 :                     if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
   16592         460 :                         (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING))
   16593           0 :                         ereport(ERROR,
   16594             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16595             :                                  errmsg("frame starting from current row cannot have preceding rows"),
   16596             :                                  parser_errposition(@4)));
   16597        1612 :                     if ((frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING) &&
   16598         168 :                         (frameOptions & (FRAMEOPTION_END_OFFSET_PRECEDING |
   16599             :                                          FRAMEOPTION_END_CURRENT_ROW)))
   16600           0 :                         ereport(ERROR,
   16601             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16602             :                                  errmsg("frame starting from following row cannot have preceding rows"),
   16603             :                                  parser_errposition(@4)));
   16604        1612 :                     n1->frameOptions = frameOptions;
   16605        1612 :                     n1->endOffset = n2->startOffset;
   16606        1612 :                     $$ = n1;
   16607             :                 }
   16608             :         ;
   16609             : 
   16610             : /*
   16611             :  * This is used for both frame start and frame end, with output set up on
   16612             :  * the assumption it's frame start; the frame_extent productions must reject
   16613             :  * invalid cases.
   16614             :  */
   16615             : frame_bound:
   16616             :             UNBOUNDED PRECEDING
   16617             :                 {
   16618         198 :                     WindowDef  *n = makeNode(WindowDef);
   16619             : 
   16620         198 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
   16621         198 :                     n->startOffset = NULL;
   16622         198 :                     n->endOffset = NULL;
   16623         198 :                     $$ = n;
   16624             :                 }
   16625             :             | UNBOUNDED FOLLOWING
   16626             :                 {
   16627         376 :                     WindowDef  *n = makeNode(WindowDef);
   16628             : 
   16629         376 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
   16630         376 :                     n->startOffset = NULL;
   16631         376 :                     n->endOffset = NULL;
   16632         376 :                     $$ = n;
   16633             :                 }
   16634             :             | CURRENT_P ROW
   16635             :                 {
   16636         604 :                     WindowDef  *n = makeNode(WindowDef);
   16637             : 
   16638         604 :                     n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
   16639         604 :                     n->startOffset = NULL;
   16640         604 :                     n->endOffset = NULL;
   16641         604 :                     $$ = n;
   16642             :                 }
   16643             :             | a_expr PRECEDING
   16644             :                 {
   16645         906 :                     WindowDef  *n = makeNode(WindowDef);
   16646             : 
   16647         906 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_PRECEDING;
   16648         906 :                     n->startOffset = $1;
   16649         906 :                     n->endOffset = NULL;
   16650         906 :                     $$ = n;
   16651             :                 }
   16652             :             | a_expr FOLLOWING
   16653             :                 {
   16654        1152 :                     WindowDef  *n = makeNode(WindowDef);
   16655             : 
   16656        1152 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_FOLLOWING;
   16657        1152 :                     n->startOffset = $1;
   16658        1152 :                     n->endOffset = NULL;
   16659        1152 :                     $$ = n;
   16660             :                 }
   16661             :         ;
   16662             : 
   16663             : opt_window_exclusion_clause:
   16664          84 :             EXCLUDE CURRENT_P ROW   { $$ = FRAMEOPTION_EXCLUDE_CURRENT_ROW; }
   16665          96 :             | EXCLUDE GROUP_P       { $$ = FRAMEOPTION_EXCLUDE_GROUP; }
   16666         150 :             | EXCLUDE TIES          { $$ = FRAMEOPTION_EXCLUDE_TIES; }
   16667          18 :             | EXCLUDE NO OTHERS     { $$ = 0; }
   16668        1276 :             | /*EMPTY*/             { $$ = 0; }
   16669             :         ;
   16670             : 
   16671             : 
   16672             : /*
   16673             :  * Supporting nonterminals for expressions.
   16674             :  */
   16675             : 
   16676             : /* Explicit row production.
   16677             :  *
   16678             :  * SQL99 allows an optional ROW keyword, so we can now do single-element rows
   16679             :  * without conflicting with the parenthesized a_expr production.  Without the
   16680             :  * ROW keyword, there must be more than one a_expr inside the parens.
   16681             :  */
   16682           0 : row:        ROW '(' expr_list ')'                   { $$ = $3; }
   16683           0 :             | ROW '(' ')'                           { $$ = NIL; }
   16684        1968 :             | '(' expr_list ',' a_expr ')'          { $$ = lappend($2, $4); }
   16685             :         ;
   16686             : 
   16687        3780 : explicit_row:   ROW '(' expr_list ')'               { $$ = $3; }
   16688          36 :             | ROW '(' ')'                           { $$ = NIL; }
   16689             :         ;
   16690             : 
   16691        2674 : implicit_row:   '(' expr_list ',' a_expr ')'        { $$ = lappend($2, $4); }
   16692             :         ;
   16693             : 
   16694       17092 : sub_type:   ANY                                     { $$ = ANY_SUBLINK; }
   16695           0 :             | SOME                                  { $$ = ANY_SUBLINK; }
   16696         324 :             | ALL                                   { $$ = ALL_SUBLINK; }
   16697             :         ;
   16698             : 
   16699       11156 : all_Op:     Op                                      { $$ = $1; }
   16700       28462 :             | MathOp                                { $$ = $1; }
   16701             :         ;
   16702             : 
   16703          40 : MathOp:      '+'                                    { $$ = "+"; }
   16704          64 :             | '-'                                   { $$ = "-"; }
   16705         114 :             | '*'                                   { $$ = "*"; }
   16706           0 :             | '/'                                   { $$ = "/"; }
   16707           8 :             | '%'                                   { $$ = "%"; }
   16708           0 :             | '^'                                   { $$ = "^"; }
   16709         790 :             | '<'                                    { $$ = "<"; }
   16710         680 :             | '>'                                    { $$ = ">"; }
   16711       24838 :             | '='                                   { $$ = "="; }
   16712         650 :             | LESS_EQUALS                           { $$ = "<="; }
   16713         642 :             | GREATER_EQUALS                        { $$ = ">="; }
   16714         636 :             | NOT_EQUALS                            { $$ = "<>"; }
   16715             :         ;
   16716             : 
   16717             : qual_Op:    Op
   16718       43952 :                     { $$ = list_make1(makeString($1)); }
   16719             :             | OPERATOR '(' any_operator ')'
   16720       15508 :                     { $$ = $3; }
   16721             :         ;
   16722             : 
   16723             : qual_all_Op:
   16724             :             all_Op
   16725        1416 :                     { $$ = list_make1(makeString($1)); }
   16726             :             | OPERATOR '(' any_operator ')'
   16727          44 :                     { $$ = $3; }
   16728             :         ;
   16729             : 
   16730             : subquery_Op:
   16731             :             all_Op
   16732       17114 :                     { $$ = list_make1(makeString($1)); }
   16733             :             | OPERATOR '(' any_operator ')'
   16734         270 :                     { $$ = $3; }
   16735             :             | LIKE
   16736          24 :                     { $$ = list_make1(makeString("~~")); }
   16737             :             | NOT_LA LIKE
   16738          12 :                     { $$ = list_make1(makeString("!~~")); }
   16739             :             | ILIKE
   16740          12 :                     { $$ = list_make1(makeString("~~*")); }
   16741             :             | NOT_LA ILIKE
   16742           0 :                     { $$ = list_make1(makeString("!~~*")); }
   16743             : /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
   16744             :  * the regular expression is preprocessed by a function (similar_to_escape),
   16745             :  * and the ~ operator for posix regular expressions is used.
   16746             :  *        x SIMILAR TO y     ->    x ~ similar_to_escape(y)
   16747             :  * this transformation is made on the fly by the parser upwards.
   16748             :  * however the SubLink structure which handles any/some/all stuff
   16749             :  * is not ready for such a thing.
   16750             :  */
   16751             :             ;
   16752             : 
   16753             : expr_list:  a_expr
   16754             :                 {
   16755      166106 :                     $$ = list_make1($1);
   16756             :                 }
   16757             :             | expr_list ',' a_expr
   16758             :                 {
   16759      147454 :                     $$ = lappend($1, $3);
   16760             :                 }
   16761             :         ;
   16762             : 
   16763             : /* function arguments can have names */
   16764             : func_arg_list:  func_arg_expr
   16765             :                 {
   16766      324090 :                     $$ = list_make1($1);
   16767             :                 }
   16768             :             | func_arg_list ',' func_arg_expr
   16769             :                 {
   16770      286930 :                     $$ = lappend($1, $3);
   16771             :                 }
   16772             :         ;
   16773             : 
   16774             : func_arg_expr:  a_expr
   16775             :                 {
   16776      564638 :                     $$ = $1;
   16777             :                 }
   16778             :             | param_name COLON_EQUALS a_expr
   16779             :                 {
   16780       45504 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   16781             : 
   16782       45504 :                     na->name = $1;
   16783       45504 :                     na->arg = (Expr *) $3;
   16784       45504 :                     na->argnumber = -1;      /* until determined */
   16785       45504 :                     na->location = @1;
   16786       45504 :                     $$ = (Node *) na;
   16787             :                 }
   16788             :             | param_name EQUALS_GREATER a_expr
   16789             :                 {
   16790        1612 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   16791             : 
   16792        1612 :                     na->name = $1;
   16793        1612 :                     na->arg = (Expr *) $3;
   16794        1612 :                     na->argnumber = -1;      /* until determined */
   16795        1612 :                     na->location = @1;
   16796        1612 :                     $$ = (Node *) na;
   16797             :                 }
   16798             :         ;
   16799             : 
   16800         254 : func_arg_list_opt:  func_arg_list                   { $$ = $1; }
   16801           0 :             | /*EMPTY*/                             { $$ = NIL; }
   16802             :         ;
   16803             : 
   16804        2180 : type_list:  Typename                                { $$ = list_make1($1); }
   16805         590 :             | type_list ',' Typename                { $$ = lappend($1, $3); }
   16806             :         ;
   16807             : 
   16808             : array_expr: '[' expr_list ']'
   16809             :                 {
   16810        7734 :                     $$ = makeAArrayExpr($2, @1, @3);
   16811             :                 }
   16812             :             | '[' array_expr_list ']'
   16813             :                 {
   16814         412 :                     $$ = makeAArrayExpr($2, @1, @3);
   16815             :                 }
   16816             :             | '[' ']'
   16817             :                 {
   16818          88 :                     $$ = makeAArrayExpr(NIL, @1, @2);
   16819             :                 }
   16820             :         ;
   16821             : 
   16822         412 : array_expr_list: array_expr                         { $$ = list_make1($1); }
   16823         342 :             | array_expr_list ',' array_expr        { $$ = lappend($1, $3); }
   16824             :         ;
   16825             : 
   16826             : 
   16827             : extract_list:
   16828             :             extract_arg FROM a_expr
   16829             :                 {
   16830        1390 :                     $$ = list_make2(makeStringConst($1, @1), $3);
   16831             :                 }
   16832             :         ;
   16833             : 
   16834             : /* Allow delimited string Sconst in extract_arg as an SQL extension.
   16835             :  * - thomas 2001-04-12
   16836             :  */
   16837             : extract_arg:
   16838        1132 :             IDENT                                   { $$ = $1; }
   16839          72 :             | YEAR_P                                { $$ = "year"; }
   16840          42 :             | MONTH_P                               { $$ = "month"; }
   16841          54 :             | DAY_P                                 { $$ = "day"; }
   16842          30 :             | HOUR_P                                { $$ = "hour"; }
   16843          30 :             | MINUTE_P                              { $$ = "minute"; }
   16844          30 :             | SECOND_P                              { $$ = "second"; }
   16845           0 :             | Sconst                                { $$ = $1; }
   16846             :         ;
   16847             : 
   16848             : unicode_normal_form:
   16849          24 :             NFC                                     { $$ = "NFC"; }
   16850          18 :             | NFD                                   { $$ = "NFD"; }
   16851          18 :             | NFKC                                  { $$ = "NFKC"; }
   16852          18 :             | NFKD                                  { $$ = "NFKD"; }
   16853             :         ;
   16854             : 
   16855             : /* OVERLAY() arguments */
   16856             : overlay_list:
   16857             :             a_expr PLACING a_expr FROM a_expr FOR a_expr
   16858             :                 {
   16859             :                     /* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D) */
   16860          34 :                     $$ = list_make4($1, $3, $5, $7);
   16861             :                 }
   16862             :             | a_expr PLACING a_expr FROM a_expr
   16863             :                 {
   16864             :                     /* overlay(A PLACING B FROM C) is converted to overlay(A, B, C) */
   16865          48 :                     $$ = list_make3($1, $3, $5);
   16866             :                 }
   16867             :         ;
   16868             : 
   16869             : /* position_list uses b_expr not a_expr to avoid conflict with general IN */
   16870             : position_list:
   16871         402 :             b_expr IN_P b_expr                      { $$ = list_make2($3, $1); }
   16872             :         ;
   16873             : 
   16874             : /*
   16875             :  * SUBSTRING() arguments
   16876             :  *
   16877             :  * Note that SQL:1999 has both
   16878             :  *     text FROM int FOR int
   16879             :  * and
   16880             :  *     text FROM pattern FOR escape
   16881             :  *
   16882             :  * In the parser we map them both to a call to the substring() function and
   16883             :  * rely on type resolution to pick the right one.
   16884             :  *
   16885             :  * In SQL:2003, the second variant was changed to
   16886             :  *     text SIMILAR pattern ESCAPE escape
   16887             :  * We could in theory map that to a different function internally, but
   16888             :  * since we still support the SQL:1999 version, we don't.  However,
   16889             :  * ruleutils.c will reverse-list the call in the newer style.
   16890             :  */
   16891             : substr_list:
   16892             :             a_expr FROM a_expr FOR a_expr
   16893             :                 {
   16894         122 :                     $$ = list_make3($1, $3, $5);
   16895             :                 }
   16896             :             | a_expr FOR a_expr FROM a_expr
   16897             :                 {
   16898             :                     /* not legal per SQL, but might as well allow it */
   16899           0 :                     $$ = list_make3($1, $5, $3);
   16900             :                 }
   16901             :             | a_expr FROM a_expr
   16902             :                 {
   16903             :                     /*
   16904             :                      * Because we aren't restricting data types here, this
   16905             :                      * syntax can end up resolving to textregexsubstr().
   16906             :                      * We've historically allowed that to happen, so continue
   16907             :                      * to accept it.  However, ruleutils.c will reverse-list
   16908             :                      * such a call in regular function call syntax.
   16909             :                      */
   16910         376 :                     $$ = list_make2($1, $3);
   16911             :                 }
   16912             :             | a_expr FOR a_expr
   16913             :                 {
   16914             :                     /* not legal per SQL */
   16915             : 
   16916             :                     /*
   16917             :                      * Since there are no cases where this syntax allows
   16918             :                      * a textual FOR value, we forcibly cast the argument
   16919             :                      * to int4.  The possible matches in pg_proc are
   16920             :                      * substring(text,int4) and substring(text,text),
   16921             :                      * and we don't want the parser to choose the latter,
   16922             :                      * which it is likely to do if the second argument
   16923             :                      * is unknown or doesn't have an implicit cast to int4.
   16924             :                      */
   16925          36 :                     $$ = list_make3($1, makeIntConst(1, -1),
   16926             :                                     makeTypeCast($3,
   16927             :                                                  SystemTypeName("int4"), -1));
   16928             :                 }
   16929             :             | a_expr SIMILAR a_expr ESCAPE a_expr
   16930             :                 {
   16931         184 :                     $$ = list_make3($1, $3, $5);
   16932             :                 }
   16933             :         ;
   16934             : 
   16935         606 : trim_list:  a_expr FROM expr_list                   { $$ = lappend($3, $1); }
   16936          24 :             | FROM expr_list                        { $$ = $2; }
   16937          86 :             | expr_list                             { $$ = $1; }
   16938             :         ;
   16939             : 
   16940             : /*
   16941             :  * Define SQL-style CASE clause.
   16942             :  * - Full specification
   16943             :  *  CASE WHEN a = b THEN c ... ELSE d END
   16944             :  * - Implicit argument
   16945             :  *  CASE a WHEN b THEN c ... ELSE d END
   16946             :  */
   16947             : case_expr:  CASE case_arg when_clause_list case_default END_P
   16948             :                 {
   16949       40518 :                     CaseExpr   *c = makeNode(CaseExpr);
   16950             : 
   16951       40518 :                     c->casetype = InvalidOid; /* not analyzed yet */
   16952       40518 :                     c->arg = (Expr *) $2;
   16953       40518 :                     c->args = $3;
   16954       40518 :                     c->defresult = (Expr *) $4;
   16955       40518 :                     c->location = @1;
   16956       40518 :                     $$ = (Node *) c;
   16957             :                 }
   16958             :         ;
   16959             : 
   16960             : when_clause_list:
   16961             :             /* There must be at least one */
   16962       40518 :             when_clause                             { $$ = list_make1($1); }
   16963       29354 :             | when_clause_list when_clause          { $$ = lappend($1, $2); }
   16964             :         ;
   16965             : 
   16966             : when_clause:
   16967             :             WHEN a_expr THEN a_expr
   16968             :                 {
   16969       69872 :                     CaseWhen   *w = makeNode(CaseWhen);
   16970             : 
   16971       69872 :                     w->expr = (Expr *) $2;
   16972       69872 :                     w->result = (Expr *) $4;
   16973       69872 :                     w->location = @1;
   16974       69872 :                     $$ = (Node *) w;
   16975             :                 }
   16976             :         ;
   16977             : 
   16978             : case_default:
   16979       30834 :             ELSE a_expr                             { $$ = $2; }
   16980        9684 :             | /*EMPTY*/                             { $$ = NULL; }
   16981             :         ;
   16982             : 
   16983        6696 : case_arg:   a_expr                                  { $$ = $1; }
   16984       33822 :             | /*EMPTY*/                             { $$ = NULL; }
   16985             :         ;
   16986             : 
   16987             : columnref:  ColId
   16988             :                 {
   16989      781610 :                     $$ = makeColumnRef($1, NIL, @1, yyscanner);
   16990             :                 }
   16991             :             | ColId indirection
   16992             :                 {
   16993     1091886 :                     $$ = makeColumnRef($1, $2, @1, yyscanner);
   16994             :                 }
   16995             :         ;
   16996             : 
   16997             : indirection_el:
   16998             :             '.' attr_name
   16999             :                 {
   17000     1487652 :                     $$ = (Node *) makeString($2);
   17001             :                 }
   17002             :             | '.' '*'
   17003             :                 {
   17004        6932 :                     $$ = (Node *) makeNode(A_Star);
   17005             :                 }
   17006             :             | '[' a_expr ']'
   17007             :                 {
   17008       13134 :                     A_Indices *ai = makeNode(A_Indices);
   17009             : 
   17010       13134 :                     ai->is_slice = false;
   17011       13134 :                     ai->lidx = NULL;
   17012       13134 :                     ai->uidx = $2;
   17013       13134 :                     $$ = (Node *) ai;
   17014             :                 }
   17015             :             | '[' opt_slice_bound ':' opt_slice_bound ']'
   17016             :                 {
   17017         588 :                     A_Indices *ai = makeNode(A_Indices);
   17018             : 
   17019         588 :                     ai->is_slice = true;
   17020         588 :                     ai->lidx = $2;
   17021         588 :                     ai->uidx = $4;
   17022         588 :                     $$ = (Node *) ai;
   17023             :                 }
   17024             :         ;
   17025             : 
   17026             : opt_slice_bound:
   17027         996 :             a_expr                                  { $$ = $1; }
   17028         180 :             | /*EMPTY*/                             { $$ = NULL; }
   17029             :         ;
   17030             : 
   17031             : indirection:
   17032     1487572 :             indirection_el                          { $$ = list_make1($1); }
   17033        3088 :             | indirection indirection_el            { $$ = lappend($1, $2); }
   17034             :         ;
   17035             : 
   17036             : opt_indirection:
   17037      199556 :             /*EMPTY*/                               { $$ = NIL; }
   17038       17646 :             | opt_indirection indirection_el        { $$ = lappend($1, $2); }
   17039             :         ;
   17040             : 
   17041             : opt_asymmetric: ASYMMETRIC
   17042             :             | /*EMPTY*/
   17043             :         ;
   17044             : 
   17045             : /* SQL/JSON support */
   17046             : json_passing_clause_opt:
   17047         336 :             PASSING json_arguments                  { $$ = $2; }
   17048        1934 :             | /*EMPTY*/                             { $$ = NIL; }
   17049             :         ;
   17050             : 
   17051             : json_arguments:
   17052         336 :             json_argument                           { $$ = list_make1($1); }
   17053         126 :             | json_arguments ',' json_argument      { $$ = lappend($1, $3); }
   17054             :         ;
   17055             : 
   17056             : json_argument:
   17057             :             json_value_expr AS ColLabel
   17058             :             {
   17059         462 :                 JsonArgument *n = makeNode(JsonArgument);
   17060             : 
   17061         462 :                 n->val = (JsonValueExpr *) $1;
   17062         462 :                 n->name = $3;
   17063         462 :                 $$ = (Node *) n;
   17064             :             }
   17065             :         ;
   17066             : 
   17067             : /* ARRAY is a noise word */
   17068             : json_wrapper_behavior:
   17069          42 :               WITHOUT WRAPPER                   { $$ = JSW_NONE; }
   17070           0 :             | WITHOUT ARRAY WRAPPER             { $$ = JSW_NONE; }
   17071          78 :             | WITH WRAPPER                      { $$ = JSW_UNCONDITIONAL; }
   17072          12 :             | WITH ARRAY WRAPPER                { $$ = JSW_UNCONDITIONAL; }
   17073           0 :             | WITH CONDITIONAL ARRAY WRAPPER    { $$ = JSW_CONDITIONAL; }
   17074          12 :             | WITH UNCONDITIONAL ARRAY WRAPPER  { $$ = JSW_UNCONDITIONAL; }
   17075          36 :             | WITH CONDITIONAL WRAPPER          { $$ = JSW_CONDITIONAL; }
   17076           6 :             | WITH UNCONDITIONAL WRAPPER        { $$ = JSW_UNCONDITIONAL; }
   17077        1634 :             | /* empty */                       { $$ = JSW_UNSPEC; }
   17078             :         ;
   17079             : 
   17080             : json_behavior:
   17081             :             DEFAULT a_expr
   17082         384 :                 { $$ = (Node *) makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); }
   17083             :             | json_behavior_type
   17084         702 :                 { $$ = (Node *) makeJsonBehavior($1, NULL, @1); }
   17085             :         ;
   17086             : 
   17087             : json_behavior_type:
   17088         492 :             ERROR_P     { $$ = JSON_BEHAVIOR_ERROR; }
   17089          30 :             | NULL_P    { $$ = JSON_BEHAVIOR_NULL; }
   17090          30 :             | TRUE_P    { $$ = JSON_BEHAVIOR_TRUE; }
   17091          12 :             | FALSE_P   { $$ = JSON_BEHAVIOR_FALSE; }
   17092          12 :             | UNKNOWN   { $$ = JSON_BEHAVIOR_UNKNOWN; }
   17093          30 :             | EMPTY_P ARRAY { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
   17094          72 :             | EMPTY_P OBJECT_P  { $$ = JSON_BEHAVIOR_EMPTY_OBJECT; }
   17095             :             /* non-standard, for Oracle compatibility only */
   17096          24 :             | EMPTY_P   { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
   17097             :         ;
   17098             : 
   17099             : json_behavior_clause_opt:
   17100             :             json_behavior ON EMPTY_P
   17101         174 :                 { $$ = list_make2($1, NULL); }
   17102             :             | json_behavior ON ERROR_P
   17103         552 :                 { $$ = list_make2(NULL, $1); }
   17104             :             | json_behavior ON EMPTY_P json_behavior ON ERROR_P
   17105         102 :                 { $$ = list_make2($1, $4); }
   17106             :             | /* EMPTY */
   17107        1568 :                 { $$ = list_make2(NULL, NULL); }
   17108             :         ;
   17109             : 
   17110             : json_on_error_clause_opt:
   17111             :             json_behavior ON ERROR_P
   17112         150 :                 { $$ = $1; }
   17113             :             | /* EMPTY */
   17114         686 :                 { $$ = NULL; }
   17115             :         ;
   17116             : 
   17117             : json_value_expr:
   17118             :             a_expr json_format_clause_opt
   17119             :             {
   17120             :                 /* formatted_expr will be set during parse-analysis. */
   17121        4202 :                 $$ = (Node *) makeJsonValueExpr((Expr *) $1, NULL,
   17122        4202 :                                                 castNode(JsonFormat, $2));
   17123             :             }
   17124             :         ;
   17125             : 
   17126             : json_format_clause:
   17127             :             FORMAT_LA JSON ENCODING name
   17128             :                 {
   17129             :                     int     encoding;
   17130             : 
   17131         100 :                     if (!pg_strcasecmp($4, "utf8"))
   17132          64 :                         encoding = JS_ENC_UTF8;
   17133          36 :                     else if (!pg_strcasecmp($4, "utf16"))
   17134          12 :                         encoding = JS_ENC_UTF16;
   17135          24 :                     else if (!pg_strcasecmp($4, "utf32"))
   17136          12 :                         encoding = JS_ENC_UTF32;
   17137             :                     else
   17138          12 :                         ereport(ERROR,
   17139             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   17140             :                                  errmsg("unrecognized JSON encoding: %s", $4),
   17141             :                                  parser_errposition(@4)));
   17142             : 
   17143          88 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
   17144             :                 }
   17145             :             | FORMAT_LA JSON
   17146             :                 {
   17147         412 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
   17148             :                 }
   17149             :         ;
   17150             : 
   17151             : json_format_clause_opt:
   17152             :             json_format_clause
   17153             :                 {
   17154         392 :                     $$ = $1;
   17155             :                 }
   17156             :             | /* EMPTY */
   17157             :                 {
   17158        5314 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   17159             :                 }
   17160             :         ;
   17161             : 
   17162             : json_quotes_clause_opt:
   17163          12 :             KEEP QUOTES ON SCALAR STRING_P      { $$ = JS_QUOTES_KEEP; }
   17164          90 :             | KEEP QUOTES                       { $$ = JS_QUOTES_KEEP; }
   17165          12 :             | OMIT QUOTES ON SCALAR STRING_P    { $$ = JS_QUOTES_OMIT; }
   17166         168 :             | OMIT QUOTES                       { $$ = JS_QUOTES_OMIT; }
   17167        1538 :             | /* EMPTY */                       { $$ = JS_QUOTES_UNSPEC; }
   17168             :         ;
   17169             : 
   17170             : json_returning_clause_opt:
   17171             :             RETURNING Typename json_format_clause_opt
   17172             :                 {
   17173        1444 :                     JsonOutput *n = makeNode(JsonOutput);
   17174             : 
   17175        1444 :                     n->typeName = $2;
   17176        1444 :                     n->returning = makeNode(JsonReturning);
   17177        1444 :                     n->returning->format = (JsonFormat *) $3;
   17178        1444 :                     $$ = (Node *) n;
   17179             :                 }
   17180        1278 :             | /* EMPTY */                           { $$ = NULL; }
   17181             :         ;
   17182             : 
   17183             : /*
   17184             :  * We must assign the only-JSON production a precedence less than IDENT in
   17185             :  * order to favor shifting over reduction when JSON is followed by VALUE_P,
   17186             :  * OBJECT_P, or SCALAR.  (ARRAY doesn't need that treatment, because it's a
   17187             :  * fully reserved word.)  Because json_predicate_type_constraint is always
   17188             :  * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
   17189             :  * production to have precedence less than WITH and WITHOUT.  UNBOUNDED isn't
   17190             :  * really related to this syntax, but it's a convenient choice because it
   17191             :  * already has a precedence less than IDENT for other reasons.
   17192             :  */
   17193             : json_predicate_type_constraint:
   17194         202 :             JSON                    %prec UNBOUNDED { $$ = JS_TYPE_ANY; }
   17195          28 :             | JSON VALUE_P                          { $$ = JS_TYPE_ANY; }
   17196          40 :             | JSON ARRAY                            { $$ = JS_TYPE_ARRAY; }
   17197          40 :             | JSON OBJECT_P                         { $$ = JS_TYPE_OBJECT; }
   17198          40 :             | JSON SCALAR                           { $$ = JS_TYPE_SCALAR; }
   17199             :         ;
   17200             : 
   17201             : /*
   17202             :  * KEYS is a noise word here.  To avoid shift/reduce conflicts, assign the
   17203             :  * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
   17204             :  * This prevents reducing them when the next token is KEYS.
   17205             :  */
   17206             : json_key_uniqueness_constraint_opt:
   17207         108 :             WITH UNIQUE KEYS                            { $$ = true; }
   17208         100 :             | WITH UNIQUE               %prec UNBOUNDED { $$ = true; }
   17209          44 :             | WITHOUT UNIQUE KEYS                       { $$ = false; }
   17210          16 :             | WITHOUT UNIQUE            %prec UNBOUNDED { $$ = false; }
   17211         798 :             | /* EMPTY */               %prec UNBOUNDED { $$ = false; }
   17212             :         ;
   17213             : 
   17214             : json_name_and_value_list:
   17215             :             json_name_and_value
   17216         348 :                 { $$ = list_make1($1); }
   17217             :             | json_name_and_value_list ',' json_name_and_value
   17218         256 :                 { $$ = lappend($1, $3); }
   17219             :         ;
   17220             : 
   17221             : json_name_and_value:
   17222             : /* Supporting this syntax seems to require major surgery
   17223             :             KEY c_expr VALUE_P json_value_expr
   17224             :                 { $$ = makeJsonKeyValue($2, $4); }
   17225             :             |
   17226             : */
   17227             :             c_expr VALUE_P json_value_expr
   17228          24 :                 { $$ = makeJsonKeyValue($1, $3); }
   17229             :             |
   17230             :             a_expr ':' json_value_expr
   17231         784 :                 { $$ = makeJsonKeyValue($1, $3); }
   17232             :         ;
   17233             : 
   17234             : /* empty means false for objects, true for arrays */
   17235             : json_object_constructor_null_clause_opt:
   17236          30 :             NULL_P ON NULL_P                    { $$ = false; }
   17237         110 :             | ABSENT ON NULL_P                  { $$ = true; }
   17238         412 :             | /* EMPTY */                       { $$ = false; }
   17239             :         ;
   17240             : 
   17241             : json_array_constructor_null_clause_opt:
   17242          60 :             NULL_P ON NULL_P                        { $$ = false; }
   17243          36 :             | ABSENT ON NULL_P                      { $$ = true; }
   17244         168 :             | /* EMPTY */                           { $$ = true; }
   17245             :         ;
   17246             : 
   17247             : json_value_expr_list:
   17248         108 :             json_value_expr                             { $$ = list_make1($1); }
   17249         126 :             | json_value_expr_list ',' json_value_expr  { $$ = lappend($1, $3);}
   17250             :         ;
   17251             : 
   17252             : json_aggregate_func:
   17253             :             JSON_OBJECTAGG '('
   17254             :                 json_name_and_value
   17255             :                 json_object_constructor_null_clause_opt
   17256             :                 json_key_uniqueness_constraint_opt
   17257             :                 json_returning_clause_opt
   17258             :             ')'
   17259             :                 {
   17260         204 :                     JsonObjectAgg *n = makeNode(JsonObjectAgg);
   17261             : 
   17262         204 :                     n->arg = (JsonKeyValue *) $3;
   17263         204 :                     n->absent_on_null = $4;
   17264         204 :                     n->unique = $5;
   17265         204 :                     n->constructor = makeNode(JsonAggConstructor);
   17266         204 :                     n->constructor->output = (JsonOutput *) $6;
   17267         204 :                     n->constructor->agg_order = NULL;
   17268         204 :                     n->constructor->location = @1;
   17269         204 :                     $$ = (Node *) n;
   17270             :                 }
   17271             :             | JSON_ARRAYAGG '('
   17272             :                 json_value_expr
   17273             :                 json_array_aggregate_order_by_clause_opt
   17274             :                 json_array_constructor_null_clause_opt
   17275             :                 json_returning_clause_opt
   17276             :             ')'
   17277             :                 {
   17278         156 :                     JsonArrayAgg *n = makeNode(JsonArrayAgg);
   17279             : 
   17280         156 :                     n->arg = (JsonValueExpr *) $3;
   17281         156 :                     n->absent_on_null = $5;
   17282         156 :                     n->constructor = makeNode(JsonAggConstructor);
   17283         156 :                     n->constructor->agg_order = $4;
   17284         156 :                     n->constructor->output = (JsonOutput *) $6;
   17285         156 :                     n->constructor->location = @1;
   17286         156 :                     $$ = (Node *) n;
   17287             :                 }
   17288             :         ;
   17289             : 
   17290             : json_array_aggregate_order_by_clause_opt:
   17291          18 :             ORDER BY sortby_list                    { $$ = $3; }
   17292         138 :             | /* EMPTY */                           { $$ = NIL; }
   17293             :         ;
   17294             : 
   17295             : /*****************************************************************************
   17296             :  *
   17297             :  *  target list for SELECT
   17298             :  *
   17299             :  *****************************************************************************/
   17300             : 
   17301      476598 : opt_target_list: target_list                        { $$ = $1; }
   17302         494 :             | /* EMPTY */                           { $$ = NIL; }
   17303             :         ;
   17304             : 
   17305             : target_list:
   17306      483516 :             target_el                               { $$ = list_make1($1); }
   17307      711096 :             | target_list ',' target_el             { $$ = lappend($1, $3); }
   17308             :         ;
   17309             : 
   17310             : target_el:  a_expr AS ColLabel
   17311             :                 {
   17312      245090 :                     $$ = makeNode(ResTarget);
   17313      245090 :                     $$->name = $3;
   17314      245090 :                     $$->indirection = NIL;
   17315      245090 :                     $$->val = (Node *) $1;
   17316      245090 :                     $$->location = @1;
   17317             :                 }
   17318             :             | a_expr BareColLabel
   17319             :                 {
   17320        3624 :                     $$ = makeNode(ResTarget);
   17321        3624 :                     $$->name = $2;
   17322        3624 :                     $$->indirection = NIL;
   17323        3624 :                     $$->val = (Node *) $1;
   17324        3624 :                     $$->location = @1;
   17325             :                 }
   17326             :             | a_expr
   17327             :                 {
   17328      889820 :                     $$ = makeNode(ResTarget);
   17329      889820 :                     $$->name = NULL;
   17330      889820 :                     $$->indirection = NIL;
   17331      889820 :                     $$->val = (Node *) $1;
   17332      889820 :                     $$->location = @1;
   17333             :                 }
   17334             :             | '*'
   17335             :                 {
   17336       56078 :                     ColumnRef  *n = makeNode(ColumnRef);
   17337             : 
   17338       56078 :                     n->fields = list_make1(makeNode(A_Star));
   17339       56078 :                     n->location = @1;
   17340             : 
   17341       56078 :                     $$ = makeNode(ResTarget);
   17342       56078 :                     $$->name = NULL;
   17343       56078 :                     $$->indirection = NIL;
   17344       56078 :                     $$->val = (Node *) n;
   17345       56078 :                     $$->location = @1;
   17346             :                 }
   17347             :         ;
   17348             : 
   17349             : 
   17350             : /*****************************************************************************
   17351             :  *
   17352             :  *  Names and constants
   17353             :  *
   17354             :  *****************************************************************************/
   17355             : 
   17356             : qualified_name_list:
   17357       17606 :             qualified_name                          { $$ = list_make1($1); }
   17358         474 :             | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
   17359             :         ;
   17360             : 
   17361             : /*
   17362             :  * The production for a qualified relation name has to exactly match the
   17363             :  * production for a qualified func_name, because in a FROM clause we cannot
   17364             :  * tell which we are parsing until we see what comes after it ('(' for a
   17365             :  * func_name, something else for a relation). Therefore we allow 'indirection'
   17366             :  * which may contain subscripts, and reject that case in the C code.
   17367             :  */
   17368             : qualified_name:
   17369             :             ColId
   17370             :                 {
   17371      426998 :                     $$ = makeRangeVar(NULL, $1, @1);
   17372             :                 }
   17373             :             | ColId indirection
   17374             :                 {
   17375      264592 :                     $$ = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   17376             :                 }
   17377             :         ;
   17378             : 
   17379             : name_list:  name
   17380       29132 :                     { $$ = list_make1(makeString($1)); }
   17381             :             | name_list ',' name
   17382       62464 :                     { $$ = lappend($1, makeString($3)); }
   17383             :         ;
   17384             : 
   17385             : 
   17386      182444 : name:       ColId                                   { $$ = $1; };
   17387             : 
   17388     1617680 : attr_name:  ColLabel                                { $$ = $1; };
   17389             : 
   17390          52 : file_name:  Sconst                                  { $$ = $1; };
   17391             : 
   17392             : /*
   17393             :  * The production for a qualified func_name has to exactly match the
   17394             :  * production for a qualified columnref, because we cannot tell which we
   17395             :  * are parsing until we see what comes after it ('(' or Sconst for a func_name,
   17396             :  * anything else for a columnref).  Therefore we allow 'indirection' which
   17397             :  * may contain subscripts, and reject that case in the C code.  (If we
   17398             :  * ever implement SQL99-like methods, such syntax may actually become legal!)
   17399             :  */
   17400             : func_name:  type_function_name
   17401      295856 :                     { $$ = list_make1(makeString($1)); }
   17402             :             | ColId indirection
   17403             :                     {
   17404      131016 :                         $$ = check_func_name(lcons(makeString($1), $2),
   17405             :                                              yyscanner);
   17406             :                     }
   17407             :         ;
   17408             : 
   17409             : 
   17410             : /*
   17411             :  * Constants
   17412             :  */
   17413             : AexprConst: Iconst
   17414             :                 {
   17415      378988 :                     $$ = makeIntConst($1, @1);
   17416             :                 }
   17417             :             | FCONST
   17418             :                 {
   17419       11410 :                     $$ = makeFloatConst($1, @1);
   17420             :                 }
   17421             :             | Sconst
   17422             :                 {
   17423      712898 :                     $$ = makeStringConst($1, @1);
   17424             :                 }
   17425             :             | BCONST
   17426             :                 {
   17427         754 :                     $$ = makeBitStringConst($1, @1);
   17428             :                 }
   17429             :             | XCONST
   17430             :                 {
   17431             :                     /* This is a bit constant per SQL99:
   17432             :                      * Without Feature F511, "BIT data type",
   17433             :                      * a <general literal> shall not be a
   17434             :                      * <bit string literal> or a <hex string literal>.
   17435             :                      */
   17436        3302 :                     $$ = makeBitStringConst($1, @1);
   17437             :                 }
   17438             :             | func_name Sconst
   17439             :                 {
   17440             :                     /* generic type 'literal' syntax */
   17441        9836 :                     TypeName   *t = makeTypeNameFromNameList($1);
   17442             : 
   17443        9836 :                     t->location = @1;
   17444        9836 :                     $$ = makeStringConstCast($2, @2, t);
   17445             :                 }
   17446             :             | func_name '(' func_arg_list opt_sort_clause ')' Sconst
   17447             :                 {
   17448             :                     /* generic syntax with a type modifier */
   17449           0 :                     TypeName   *t = makeTypeNameFromNameList($1);
   17450             :                     ListCell   *lc;
   17451             : 
   17452             :                     /*
   17453             :                      * We must use func_arg_list and opt_sort_clause in the
   17454             :                      * production to avoid reduce/reduce conflicts, but we
   17455             :                      * don't actually wish to allow NamedArgExpr in this
   17456             :                      * context, nor ORDER BY.
   17457             :                      */
   17458           0 :                     foreach(lc, $3)
   17459             :                     {
   17460           0 :                         NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
   17461             : 
   17462           0 :                         if (IsA(arg, NamedArgExpr))
   17463           0 :                             ereport(ERROR,
   17464             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17465             :                                      errmsg("type modifier cannot have parameter name"),
   17466             :                                      parser_errposition(arg->location)));
   17467             :                     }
   17468           0 :                     if ($4 != NIL)
   17469           0 :                             ereport(ERROR,
   17470             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17471             :                                      errmsg("type modifier cannot have ORDER BY"),
   17472             :                                      parser_errposition(@4)));
   17473             : 
   17474           0 :                     t->typmods = $3;
   17475           0 :                     t->location = @1;
   17476           0 :                     $$ = makeStringConstCast($6, @6, t);
   17477             :                 }
   17478             :             | ConstTypename Sconst
   17479             :                 {
   17480        3126 :                     $$ = makeStringConstCast($2, @2, $1);
   17481             :                 }
   17482             :             | ConstInterval Sconst opt_interval
   17483             :                 {
   17484        3298 :                     TypeName   *t = $1;
   17485             : 
   17486        3298 :                     t->typmods = $3;
   17487        3298 :                     $$ = makeStringConstCast($2, @2, t);
   17488             :                 }
   17489             :             | ConstInterval '(' Iconst ')' Sconst
   17490             :                 {
   17491          12 :                     TypeName   *t = $1;
   17492             : 
   17493          12 :                     t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   17494             :                                             makeIntConst($3, @3));
   17495          12 :                     $$ = makeStringConstCast($5, @5, t);
   17496             :                 }
   17497             :             | TRUE_P
   17498             :                 {
   17499       31202 :                     $$ = makeBoolAConst(true, @1);
   17500             :                 }
   17501             :             | FALSE_P
   17502             :                 {
   17503       36536 :                     $$ = makeBoolAConst(false, @1);
   17504             :                 }
   17505             :             | NULL_P
   17506             :                 {
   17507       68664 :                     $$ = makeNullAConst(@1);
   17508             :                 }
   17509             :         ;
   17510             : 
   17511      405502 : Iconst:     ICONST                                  { $$ = $1; };
   17512      785684 : Sconst:     SCONST                                  { $$ = $1; };
   17513             : 
   17514       18082 : SignedIconst: Iconst                                { $$ = $1; }
   17515           0 :             | '+' Iconst                            { $$ = + $2; }
   17516         306 :             | '-' Iconst                            { $$ = - $2; }
   17517             :         ;
   17518             : 
   17519             : /* Role specifications */
   17520             : RoleId:     RoleSpec
   17521             :                 {
   17522        1918 :                     RoleSpec   *spc = (RoleSpec *) $1;
   17523             : 
   17524        1918 :                     switch (spc->roletype)
   17525             :                     {
   17526        1908 :                         case ROLESPEC_CSTRING:
   17527        1908 :                             $$ = spc->rolename;
   17528        1908 :                             break;
   17529           4 :                         case ROLESPEC_PUBLIC:
   17530           4 :                             ereport(ERROR,
   17531             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17532             :                                      errmsg("role name \"%s\" is reserved",
   17533             :                                             "public"),
   17534             :                                      parser_errposition(@1)));
   17535             :                             break;
   17536           2 :                         case ROLESPEC_SESSION_USER:
   17537           2 :                             ereport(ERROR,
   17538             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17539             :                                      errmsg("%s cannot be used as a role name here",
   17540             :                                             "SESSION_USER"),
   17541             :                                      parser_errposition(@1)));
   17542             :                             break;
   17543           2 :                         case ROLESPEC_CURRENT_USER:
   17544           2 :                             ereport(ERROR,
   17545             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17546             :                                      errmsg("%s cannot be used as a role name here",
   17547             :                                             "CURRENT_USER"),
   17548             :                                      parser_errposition(@1)));
   17549             :                             break;
   17550           2 :                         case ROLESPEC_CURRENT_ROLE:
   17551           2 :                             ereport(ERROR,
   17552             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17553             :                                      errmsg("%s cannot be used as a role name here",
   17554             :                                             "CURRENT_ROLE"),
   17555             :                                      parser_errposition(@1)));
   17556             :                             break;
   17557             :                     }
   17558             :                 }
   17559             :             ;
   17560             : 
   17561             : RoleSpec:   NonReservedWord
   17562             :                 {
   17563             :                     /*
   17564             :                      * "public" and "none" are not keywords, but they must
   17565             :                      * be treated specially here.
   17566             :                      */
   17567             :                     RoleSpec   *n;
   17568             : 
   17569       35170 :                     if (strcmp($1, "public") == 0)
   17570             :                     {
   17571       17866 :                         n = (RoleSpec *) makeRoleSpec(ROLESPEC_PUBLIC, @1);
   17572       17866 :                         n->roletype = ROLESPEC_PUBLIC;
   17573             :                     }
   17574       17304 :                     else if (strcmp($1, "none") == 0)
   17575             :                     {
   17576          26 :                         ereport(ERROR,
   17577             :                                 (errcode(ERRCODE_RESERVED_NAME),
   17578             :                                  errmsg("role name \"%s\" is reserved",
   17579             :                                         "none"),
   17580             :                                  parser_errposition(@1)));
   17581             :                     }
   17582             :                     else
   17583             :                     {
   17584       17278 :                         n = makeRoleSpec(ROLESPEC_CSTRING, @1);
   17585       17278 :                         n->rolename = pstrdup($1);
   17586             :                     }
   17587       35144 :                     $$ = n;
   17588             :                 }
   17589             :             | CURRENT_ROLE
   17590             :                 {
   17591         130 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_ROLE, @1);
   17592             :                 }
   17593             :             | CURRENT_USER
   17594             :                 {
   17595         228 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
   17596             :                 }
   17597             :             | SESSION_USER
   17598             :                 {
   17599          36 :                     $$ = makeRoleSpec(ROLESPEC_SESSION_USER, @1);
   17600             :                 }
   17601             :         ;
   17602             : 
   17603             : role_list:  RoleSpec
   17604        3256 :                 { $$ = list_make1($1); }
   17605             :             | role_list ',' RoleSpec
   17606         270 :                 { $$ = lappend($1, $3); }
   17607             :         ;
   17608             : 
   17609             : 
   17610             : /*****************************************************************************
   17611             :  *
   17612             :  * PL/pgSQL extensions
   17613             :  *
   17614             :  * You'd think a PL/pgSQL "expression" should be just an a_expr, but
   17615             :  * historically it can include just about anything that can follow SELECT.
   17616             :  * Therefore the returned struct is a SelectStmt.
   17617             :  *****************************************************************************/
   17618             : 
   17619             : PLpgSQL_Expr: opt_distinct_clause opt_target_list
   17620             :             from_clause where_clause
   17621             :             group_clause having_clause window_clause
   17622             :             opt_sort_clause opt_select_limit opt_for_locking_clause
   17623             :                 {
   17624       40044 :                     SelectStmt *n = makeNode(SelectStmt);
   17625             : 
   17626       40044 :                     n->distinctClause = $1;
   17627       40044 :                     n->targetList = $2;
   17628       40044 :                     n->fromClause = $3;
   17629       40044 :                     n->whereClause = $4;
   17630       40044 :                     n->groupClause = ($5)->list;
   17631       40044 :                     n->groupDistinct = ($5)->distinct;
   17632       40044 :                     n->havingClause = $6;
   17633       40044 :                     n->windowClause = $7;
   17634       40044 :                     n->sortClause = $8;
   17635       40044 :                     if ($9)
   17636             :                     {
   17637           4 :                         n->limitOffset = $9->limitOffset;
   17638           4 :                         n->limitCount = $9->limitCount;
   17639           4 :                         if (!n->sortClause &&
   17640           4 :                             $9->limitOption == LIMIT_OPTION_WITH_TIES)
   17641           0 :                             ereport(ERROR,
   17642             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17643             :                                      errmsg("WITH TIES cannot be specified without ORDER BY clause"),
   17644             :                                      parser_errposition($9->optionLoc)));
   17645           4 :                         n->limitOption = $9->limitOption;
   17646             :                     }
   17647       40044 :                     n->lockingClause = $10;
   17648       40044 :                     $$ = (Node *) n;
   17649             :                 }
   17650             :         ;
   17651             : 
   17652             : /*
   17653             :  * PL/pgSQL Assignment statement: name opt_indirection := PLpgSQL_Expr
   17654             :  */
   17655             : 
   17656             : PLAssignStmt: plassign_target opt_indirection plassign_equals PLpgSQL_Expr
   17657             :                 {
   17658        7044 :                     PLAssignStmt *n = makeNode(PLAssignStmt);
   17659             : 
   17660        7044 :                     n->name = $1;
   17661        7044 :                     n->indirection = check_indirection($2, yyscanner);
   17662             :                     /* nnames will be filled by calling production */
   17663        7044 :                     n->val = (SelectStmt *) $4;
   17664        7044 :                     n->location = @1;
   17665        7044 :                     $$ = (Node *) n;
   17666             :                 }
   17667             :         ;
   17668             : 
   17669        7020 : plassign_target: ColId                          { $$ = $1; }
   17670          24 :             | PARAM                             { $$ = psprintf("$%d", $1); }
   17671             :         ;
   17672             : 
   17673             : plassign_equals: COLON_EQUALS
   17674             :             | '='
   17675             :         ;
   17676             : 
   17677             : 
   17678             : /*
   17679             :  * Name classification hierarchy.
   17680             :  *
   17681             :  * IDENT is the lexeme returned by the lexer for identifiers that match
   17682             :  * no known keyword.  In most cases, we can accept certain keywords as
   17683             :  * names, not only IDENTs.  We prefer to accept as many such keywords
   17684             :  * as possible to minimize the impact of "reserved words" on programmers.
   17685             :  * So, we divide names into several possible classes.  The classification
   17686             :  * is chosen in part to make keywords acceptable as names wherever possible.
   17687             :  */
   17688             : 
   17689             : /* Column identifier --- names that can be column, table, etc names.
   17690             :  */
   17691     3498564 : ColId:      IDENT                                   { $$ = $1; }
   17692       60360 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17693        6290 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17694             :         ;
   17695             : 
   17696             : /* Type/function identifier --- names that can be type or function names.
   17697             :  */
   17698      710570 : type_function_name: IDENT                           { $$ = $1; }
   17699       76012 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17700          66 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17701             :         ;
   17702             : 
   17703             : /* Any not-fully-reserved word --- these names can be, eg, role names.
   17704             :  */
   17705       85048 : NonReservedWord:    IDENT                           { $$ = $1; }
   17706       30420 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17707         178 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17708        5224 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17709             :         ;
   17710             : 
   17711             : /* Column label --- allowed labels in "AS" clauses.
   17712             :  * This presently includes *all* Postgres keywords.
   17713             :  */
   17714     1846680 : ColLabel:   IDENT                                   { $$ = $1; }
   17715       40438 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17716         284 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17717        1796 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17718        7526 :             | reserved_keyword                      { $$ = pstrdup($1); }
   17719             :         ;
   17720             : 
   17721             : /* Bare column label --- names that can be column labels without writing "AS".
   17722             :  * This classification is orthogonal to the other keyword categories.
   17723             :  */
   17724        3610 : BareColLabel:   IDENT                               { $$ = $1; }
   17725          14 :             | bare_label_keyword                    { $$ = pstrdup($1); }
   17726             :         ;
   17727             : 
   17728             : 
   17729             : /*
   17730             :  * Keyword category lists.  Generally, every keyword present in
   17731             :  * the Postgres grammar should appear in exactly one of these lists.
   17732             :  *
   17733             :  * Put a new keyword into the first list that it can go into without causing
   17734             :  * shift or reduce conflicts.  The earlier lists define "less reserved"
   17735             :  * categories of keywords.
   17736             :  *
   17737             :  * Make sure that each keyword's category in kwlist.h matches where
   17738             :  * it is listed here.  (Someday we may be able to generate these lists and
   17739             :  * kwlist.h's table from one source of truth.)
   17740             :  */
   17741             : 
   17742             : /* "Unreserved" keywords --- available for use as any kind of name.
   17743             :  */
   17744             : unreserved_keyword:
   17745             :               ABORT_P
   17746             :             | ABSENT
   17747             :             | ABSOLUTE_P
   17748             :             | ACCESS
   17749             :             | ACTION
   17750             :             | ADD_P
   17751             :             | ADMIN
   17752             :             | AFTER
   17753             :             | AGGREGATE
   17754             :             | ALSO
   17755             :             | ALTER
   17756             :             | ALWAYS
   17757             :             | ASENSITIVE
   17758             :             | ASSERTION
   17759             :             | ASSIGNMENT
   17760             :             | AT
   17761             :             | ATOMIC
   17762             :             | ATTACH
   17763             :             | ATTRIBUTE
   17764             :             | BACKWARD
   17765             :             | BEFORE
   17766             :             | BEGIN_P
   17767             :             | BREADTH
   17768             :             | BY
   17769             :             | CACHE
   17770             :             | CALL
   17771             :             | CALLED
   17772             :             | CASCADE
   17773             :             | CASCADED
   17774             :             | CATALOG_P
   17775             :             | CHAIN
   17776             :             | CHARACTERISTICS
   17777             :             | CHECKPOINT
   17778             :             | CLASS
   17779             :             | CLOSE
   17780             :             | CLUSTER
   17781             :             | COLUMNS
   17782             :             | COMMENT
   17783             :             | COMMENTS
   17784             :             | COMMIT
   17785             :             | COMMITTED
   17786             :             | COMPRESSION
   17787             :             | CONDITIONAL
   17788             :             | CONFIGURATION
   17789             :             | CONFLICT
   17790             :             | CONNECTION
   17791             :             | CONSTRAINTS
   17792             :             | CONTENT_P
   17793             :             | CONTINUE_P
   17794             :             | CONVERSION_P
   17795             :             | COPY
   17796             :             | COST
   17797             :             | CSV
   17798             :             | CUBE
   17799             :             | CURRENT_P
   17800             :             | CURSOR
   17801             :             | CYCLE
   17802             :             | DATA_P
   17803             :             | DATABASE
   17804             :             | DAY_P
   17805             :             | DEALLOCATE
   17806             :             | DECLARE
   17807             :             | DEFAULTS
   17808             :             | DEFERRED
   17809             :             | DEFINER
   17810             :             | DELETE_P
   17811             :             | DELIMITER
   17812             :             | DELIMITERS
   17813             :             | DEPENDS
   17814             :             | DEPTH
   17815             :             | DETACH
   17816             :             | DICTIONARY
   17817             :             | DISABLE_P
   17818             :             | DISCARD
   17819             :             | DOCUMENT_P
   17820             :             | DOMAIN_P
   17821             :             | DOUBLE_P
   17822             :             | DROP
   17823             :             | EACH
   17824             :             | EMPTY_P
   17825             :             | ENABLE_P
   17826             :             | ENCODING
   17827             :             | ENCRYPTED
   17828             :             | ENFORCED
   17829             :             | ENUM_P
   17830             :             | ERROR_P
   17831             :             | ESCAPE
   17832             :             | EVENT
   17833             :             | EXCLUDE
   17834             :             | EXCLUDING
   17835             :             | EXCLUSIVE
   17836             :             | EXECUTE
   17837             :             | EXPLAIN
   17838             :             | EXPRESSION
   17839             :             | EXTENSION
   17840             :             | EXTERNAL
   17841             :             | FAMILY
   17842             :             | FILTER
   17843             :             | FINALIZE
   17844             :             | FIRST_P
   17845             :             | FOLLOWING
   17846             :             | FORCE
   17847             :             | FORMAT
   17848             :             | FORWARD
   17849             :             | FUNCTION
   17850             :             | FUNCTIONS
   17851             :             | GENERATED
   17852             :             | GLOBAL
   17853             :             | GRANTED
   17854             :             | GROUPS
   17855             :             | HANDLER
   17856             :             | HEADER_P
   17857             :             | HOLD
   17858             :             | HOUR_P
   17859             :             | IDENTITY_P
   17860             :             | IF_P
   17861             :             | IMMEDIATE
   17862             :             | IMMUTABLE
   17863             :             | IMPLICIT_P
   17864             :             | IMPORT_P
   17865             :             | INCLUDE
   17866             :             | INCLUDING
   17867             :             | INCREMENT
   17868             :             | INDENT
   17869             :             | INDEX
   17870             :             | INDEXES
   17871             :             | INHERIT
   17872             :             | INHERITS
   17873             :             | INLINE_P
   17874             :             | INPUT_P
   17875             :             | INSENSITIVE
   17876             :             | INSERT
   17877             :             | INSTEAD
   17878             :             | INVOKER
   17879             :             | ISOLATION
   17880             :             | KEEP
   17881             :             | KEY
   17882             :             | KEYS
   17883             :             | LABEL
   17884             :             | LANGUAGE
   17885             :             | LARGE_P
   17886             :             | LAST_P
   17887             :             | LEAKPROOF
   17888             :             | LEVEL
   17889             :             | LISTEN
   17890             :             | LOAD
   17891             :             | LOCAL
   17892             :             | LOCATION
   17893             :             | LOCK_P
   17894             :             | LOCKED
   17895             :             | LOGGED
   17896             :             | MAPPING
   17897             :             | MATCH
   17898             :             | MATCHED
   17899             :             | MATERIALIZED
   17900             :             | MAXVALUE
   17901             :             | MERGE
   17902             :             | METHOD
   17903             :             | MINUTE_P
   17904             :             | MINVALUE
   17905             :             | MODE
   17906             :             | MONTH_P
   17907             :             | MOVE
   17908             :             | NAME_P
   17909             :             | NAMES
   17910             :             | NESTED
   17911             :             | NEW
   17912             :             | NEXT
   17913             :             | NFC
   17914             :             | NFD
   17915             :             | NFKC
   17916             :             | NFKD
   17917             :             | NO
   17918             :             | NORMALIZED
   17919             :             | NOTHING
   17920             :             | NOTIFY
   17921             :             | NOWAIT
   17922             :             | NULLS_P
   17923             :             | OBJECT_P
   17924             :             | OBJECTS_P
   17925             :             | OF
   17926             :             | OFF
   17927             :             | OIDS
   17928             :             | OLD
   17929             :             | OMIT
   17930             :             | OPERATOR
   17931             :             | OPTION
   17932             :             | OPTIONS
   17933             :             | ORDINALITY
   17934             :             | OTHERS
   17935             :             | OVER
   17936             :             | OVERRIDING
   17937             :             | OWNED
   17938             :             | OWNER
   17939             :             | PARALLEL
   17940             :             | PARAMETER
   17941             :             | PARSER
   17942             :             | PARTIAL
   17943             :             | PARTITION
   17944             :             | PASSING
   17945             :             | PASSWORD
   17946             :             | PATH
   17947             :             | PERIOD
   17948             :             | PLAN
   17949             :             | PLANS
   17950             :             | POLICY
   17951             :             | PRECEDING
   17952             :             | PREPARE
   17953             :             | PREPARED
   17954             :             | PRESERVE
   17955             :             | PRIOR
   17956             :             | PRIVILEGES
   17957             :             | PROCEDURAL
   17958             :             | PROCEDURE
   17959             :             | PROCEDURES
   17960             :             | PROGRAM
   17961             :             | PUBLICATION
   17962             :             | QUOTE
   17963             :             | QUOTES
   17964             :             | RANGE
   17965             :             | READ
   17966             :             | REASSIGN
   17967             :             | RECURSIVE
   17968             :             | REF_P
   17969             :             | REFERENCING
   17970             :             | REFRESH
   17971             :             | REINDEX
   17972             :             | RELATIVE_P
   17973             :             | RELEASE
   17974             :             | RENAME
   17975             :             | REPEATABLE
   17976             :             | REPLACE
   17977             :             | REPLICA
   17978             :             | RESET
   17979             :             | RESTART
   17980             :             | RESTRICT
   17981             :             | RETURN
   17982             :             | RETURNS
   17983             :             | REVOKE
   17984             :             | ROLE
   17985             :             | ROLLBACK
   17986             :             | ROLLUP
   17987             :             | ROUTINE
   17988             :             | ROUTINES
   17989             :             | ROWS
   17990             :             | RULE
   17991             :             | SAVEPOINT
   17992             :             | SCALAR
   17993             :             | SCHEMA
   17994             :             | SCHEMAS
   17995             :             | SCROLL
   17996             :             | SEARCH
   17997             :             | SECOND_P
   17998             :             | SECURITY
   17999             :             | SEQUENCE
   18000             :             | SEQUENCES
   18001             :             | SERIALIZABLE
   18002             :             | SERVER
   18003             :             | SESSION
   18004             :             | SET
   18005             :             | SETS
   18006             :             | SHARE
   18007             :             | SHOW
   18008             :             | SIMPLE
   18009             :             | SKIP
   18010             :             | SNAPSHOT
   18011             :             | SOURCE
   18012             :             | SQL_P
   18013             :             | STABLE
   18014             :             | STANDALONE_P
   18015             :             | START
   18016             :             | STATEMENT
   18017             :             | STATISTICS
   18018             :             | STDIN
   18019             :             | STDOUT
   18020             :             | STORAGE
   18021             :             | STORED
   18022             :             | STRICT_P
   18023             :             | STRING_P
   18024             :             | STRIP_P
   18025             :             | SUBSCRIPTION
   18026             :             | SUPPORT
   18027             :             | SYSID
   18028             :             | SYSTEM_P
   18029             :             | TABLES
   18030             :             | TABLESPACE
   18031             :             | TARGET
   18032             :             | TEMP
   18033             :             | TEMPLATE
   18034             :             | TEMPORARY
   18035             :             | TEXT_P
   18036             :             | TIES
   18037             :             | TRANSACTION
   18038             :             | TRANSFORM
   18039             :             | TRIGGER
   18040             :             | TRUNCATE
   18041             :             | TRUSTED
   18042             :             | TYPE_P
   18043             :             | TYPES_P
   18044             :             | UESCAPE
   18045             :             | UNBOUNDED
   18046             :             | UNCOMMITTED
   18047             :             | UNCONDITIONAL
   18048             :             | UNENCRYPTED
   18049             :             | UNKNOWN
   18050             :             | UNLISTEN
   18051             :             | UNLOGGED
   18052             :             | UNTIL
   18053             :             | UPDATE
   18054             :             | VACUUM
   18055             :             | VALID
   18056             :             | VALIDATE
   18057             :             | VALIDATOR
   18058             :             | VALUE_P
   18059             :             | VARYING
   18060             :             | VERSION_P
   18061             :             | VIEW
   18062             :             | VIEWS
   18063             :             | VIRTUAL
   18064             :             | VOLATILE
   18065             :             | WHITESPACE_P
   18066             :             | WITHIN
   18067             :             | WITHOUT
   18068             :             | WORK
   18069             :             | WRAPPER
   18070             :             | WRITE
   18071             :             | XML_P
   18072             :             | YEAR_P
   18073             :             | YES_P
   18074             :             | ZONE
   18075             :         ;
   18076             : 
   18077             : /* Column identifier --- keywords that can be column, table, etc names.
   18078             :  *
   18079             :  * Many of these keywords will in fact be recognized as type or function
   18080             :  * names too; but they have special productions for the purpose, and so
   18081             :  * can't be treated as "generic" type or function names.
   18082             :  *
   18083             :  * The type names appearing here are not usable as function names
   18084             :  * because they can be followed by '(' in typename productions, which
   18085             :  * looks too much like a function call for an LR(1) parser.
   18086             :  */
   18087             : col_name_keyword:
   18088             :               BETWEEN
   18089             :             | BIGINT
   18090             :             | BIT
   18091             :             | BOOLEAN_P
   18092             :             | CHAR_P
   18093             :             | CHARACTER
   18094             :             | COALESCE
   18095             :             | DEC
   18096             :             | DECIMAL_P
   18097             :             | EXISTS
   18098             :             | EXTRACT
   18099             :             | FLOAT_P
   18100             :             | GREATEST
   18101             :             | GROUPING
   18102             :             | INOUT
   18103             :             | INT_P
   18104             :             | INTEGER
   18105             :             | INTERVAL
   18106             :             | JSON
   18107             :             | JSON_ARRAY
   18108             :             | JSON_ARRAYAGG
   18109             :             | JSON_EXISTS
   18110             :             | JSON_OBJECT
   18111             :             | JSON_OBJECTAGG
   18112             :             | JSON_QUERY
   18113             :             | JSON_SCALAR
   18114             :             | JSON_SERIALIZE
   18115             :             | JSON_TABLE
   18116             :             | JSON_VALUE
   18117             :             | LEAST
   18118             :             | MERGE_ACTION
   18119             :             | NATIONAL
   18120             :             | NCHAR
   18121             :             | NONE
   18122             :             | NORMALIZE
   18123             :             | NULLIF
   18124             :             | NUMERIC
   18125             :             | OUT_P
   18126             :             | OVERLAY
   18127             :             | POSITION
   18128             :             | PRECISION
   18129             :             | REAL
   18130             :             | ROW
   18131             :             | SETOF
   18132             :             | SMALLINT
   18133             :             | SUBSTRING
   18134             :             | TIME
   18135             :             | TIMESTAMP
   18136             :             | TREAT
   18137             :             | TRIM
   18138             :             | VALUES
   18139             :             | VARCHAR
   18140             :             | XMLATTRIBUTES
   18141             :             | XMLCONCAT
   18142             :             | XMLELEMENT
   18143             :             | XMLEXISTS
   18144             :             | XMLFOREST
   18145             :             | XMLNAMESPACES
   18146             :             | XMLPARSE
   18147             :             | XMLPI
   18148             :             | XMLROOT
   18149             :             | XMLSERIALIZE
   18150             :             | XMLTABLE
   18151             :         ;
   18152             : 
   18153             : /* Type/function identifier --- keywords that can be type or function names.
   18154             :  *
   18155             :  * Most of these are keywords that are used as operators in expressions;
   18156             :  * in general such keywords can't be column names because they would be
   18157             :  * ambiguous with variables, but they are unambiguous as function identifiers.
   18158             :  *
   18159             :  * Do not include POSITION, SUBSTRING, etc here since they have explicit
   18160             :  * productions in a_expr to support the goofy SQL9x argument syntax.
   18161             :  * - thomas 2000-11-28
   18162             :  */
   18163             : type_func_name_keyword:
   18164             :               AUTHORIZATION
   18165             :             | BINARY
   18166             :             | COLLATION
   18167             :             | CONCURRENTLY
   18168             :             | CROSS
   18169             :             | CURRENT_SCHEMA
   18170             :             | FREEZE
   18171             :             | FULL
   18172             :             | ILIKE
   18173             :             | INNER_P
   18174             :             | IS
   18175             :             | ISNULL
   18176             :             | JOIN
   18177             :             | LEFT
   18178             :             | LIKE
   18179             :             | NATURAL
   18180             :             | NOTNULL
   18181             :             | OUTER_P
   18182             :             | OVERLAPS
   18183             :             | RIGHT
   18184             :             | SIMILAR
   18185             :             | TABLESAMPLE
   18186             :             | VERBOSE
   18187             :         ;
   18188             : 
   18189             : /* Reserved keyword --- these keywords are usable only as a ColLabel.
   18190             :  *
   18191             :  * Keywords appear here if they could not be distinguished from variable,
   18192             :  * type, or function names in some contexts.  Don't put things here unless
   18193             :  * forced to.
   18194             :  */
   18195             : reserved_keyword:
   18196             :               ALL
   18197             :             | ANALYSE
   18198             :             | ANALYZE
   18199             :             | AND
   18200             :             | ANY
   18201             :             | ARRAY
   18202             :             | AS
   18203             :             | ASC
   18204             :             | ASYMMETRIC
   18205             :             | BOTH
   18206             :             | CASE
   18207             :             | CAST
   18208             :             | CHECK
   18209             :             | COLLATE
   18210             :             | COLUMN
   18211             :             | CONSTRAINT
   18212             :             | CREATE
   18213             :             | CURRENT_CATALOG
   18214             :             | CURRENT_DATE
   18215             :             | CURRENT_ROLE
   18216             :             | CURRENT_TIME
   18217             :             | CURRENT_TIMESTAMP
   18218             :             | CURRENT_USER
   18219             :             | DEFAULT
   18220             :             | DEFERRABLE
   18221             :             | DESC
   18222             :             | DISTINCT
   18223             :             | DO
   18224             :             | ELSE
   18225             :             | END_P
   18226             :             | EXCEPT
   18227             :             | FALSE_P
   18228             :             | FETCH
   18229             :             | FOR
   18230             :             | FOREIGN
   18231             :             | FROM
   18232             :             | GRANT
   18233             :             | GROUP_P
   18234             :             | HAVING
   18235             :             | IN_P
   18236             :             | INITIALLY
   18237             :             | INTERSECT
   18238             :             | INTO
   18239             :             | LATERAL_P
   18240             :             | LEADING
   18241             :             | LIMIT
   18242             :             | LOCALTIME
   18243             :             | LOCALTIMESTAMP
   18244             :             | NOT
   18245             :             | NULL_P
   18246             :             | OFFSET
   18247             :             | ON
   18248             :             | ONLY
   18249             :             | OR
   18250             :             | ORDER
   18251             :             | PLACING
   18252             :             | PRIMARY
   18253             :             | REFERENCES
   18254             :             | RETURNING
   18255             :             | SELECT
   18256             :             | SESSION_USER
   18257             :             | SOME
   18258             :             | SYMMETRIC
   18259             :             | SYSTEM_USER
   18260             :             | TABLE
   18261             :             | THEN
   18262             :             | TO
   18263             :             | TRAILING
   18264             :             | TRUE_P
   18265             :             | UNION
   18266             :             | UNIQUE
   18267             :             | USER
   18268             :             | USING
   18269             :             | VARIADIC
   18270             :             | WHEN
   18271             :             | WHERE
   18272             :             | WINDOW
   18273             :             | WITH
   18274             :         ;
   18275             : 
   18276             : /*
   18277             :  * While all keywords can be used as column labels when preceded by AS,
   18278             :  * not all of them can be used as a "bare" column label without AS.
   18279             :  * Those that can be used as a bare label must be listed here,
   18280             :  * in addition to appearing in one of the category lists above.
   18281             :  *
   18282             :  * Always add a new keyword to this list if possible.  Mark it BARE_LABEL
   18283             :  * in kwlist.h if it is included here, or AS_LABEL if it is not.
   18284             :  */
   18285             : bare_label_keyword:
   18286             :               ABORT_P
   18287             :             | ABSENT
   18288             :             | ABSOLUTE_P
   18289             :             | ACCESS
   18290             :             | ACTION
   18291             :             | ADD_P
   18292             :             | ADMIN
   18293             :             | AFTER
   18294             :             | AGGREGATE
   18295             :             | ALL
   18296             :             | ALSO
   18297             :             | ALTER
   18298             :             | ALWAYS
   18299             :             | ANALYSE
   18300             :             | ANALYZE
   18301             :             | AND
   18302             :             | ANY
   18303             :             | ASC
   18304             :             | ASENSITIVE
   18305             :             | ASSERTION
   18306             :             | ASSIGNMENT
   18307             :             | ASYMMETRIC
   18308             :             | AT
   18309             :             | ATOMIC
   18310             :             | ATTACH
   18311             :             | ATTRIBUTE
   18312             :             | AUTHORIZATION
   18313             :             | BACKWARD
   18314             :             | BEFORE
   18315             :             | BEGIN_P
   18316             :             | BETWEEN
   18317             :             | BIGINT
   18318             :             | BINARY
   18319             :             | BIT
   18320             :             | BOOLEAN_P
   18321             :             | BOTH
   18322             :             | BREADTH
   18323             :             | BY
   18324             :             | CACHE
   18325             :             | CALL
   18326             :             | CALLED
   18327             :             | CASCADE
   18328             :             | CASCADED
   18329             :             | CASE
   18330             :             | CAST
   18331             :             | CATALOG_P
   18332             :             | CHAIN
   18333             :             | CHARACTERISTICS
   18334             :             | CHECK
   18335             :             | CHECKPOINT
   18336             :             | CLASS
   18337             :             | CLOSE
   18338             :             | CLUSTER
   18339             :             | COALESCE
   18340             :             | COLLATE
   18341             :             | COLLATION
   18342             :             | COLUMN
   18343             :             | COLUMNS
   18344             :             | COMMENT
   18345             :             | COMMENTS
   18346             :             | COMMIT
   18347             :             | COMMITTED
   18348             :             | COMPRESSION
   18349             :             | CONCURRENTLY
   18350             :             | CONDITIONAL
   18351             :             | CONFIGURATION
   18352             :             | CONFLICT
   18353             :             | CONNECTION
   18354             :             | CONSTRAINT
   18355             :             | CONSTRAINTS
   18356             :             | CONTENT_P
   18357             :             | CONTINUE_P
   18358             :             | CONVERSION_P
   18359             :             | COPY
   18360             :             | COST
   18361             :             | CROSS
   18362             :             | CSV
   18363             :             | CUBE
   18364             :             | CURRENT_P
   18365             :             | CURRENT_CATALOG
   18366             :             | CURRENT_DATE
   18367             :             | CURRENT_ROLE
   18368             :             | CURRENT_SCHEMA
   18369             :             | CURRENT_TIME
   18370             :             | CURRENT_TIMESTAMP
   18371             :             | CURRENT_USER
   18372             :             | CURSOR
   18373             :             | CYCLE
   18374             :             | DATA_P
   18375             :             | DATABASE
   18376             :             | DEALLOCATE
   18377             :             | DEC
   18378             :             | DECIMAL_P
   18379             :             | DECLARE
   18380             :             | DEFAULT
   18381             :             | DEFAULTS
   18382             :             | DEFERRABLE
   18383             :             | DEFERRED
   18384             :             | DEFINER
   18385             :             | DELETE_P
   18386             :             | DELIMITER
   18387             :             | DELIMITERS
   18388             :             | DEPENDS
   18389             :             | DEPTH
   18390             :             | DESC
   18391             :             | DETACH
   18392             :             | DICTIONARY
   18393             :             | DISABLE_P
   18394             :             | DISCARD
   18395             :             | DISTINCT
   18396             :             | DO
   18397             :             | DOCUMENT_P
   18398             :             | DOMAIN_P
   18399             :             | DOUBLE_P
   18400             :             | DROP
   18401             :             | EACH
   18402             :             | ELSE
   18403             :             | EMPTY_P
   18404             :             | ENABLE_P
   18405             :             | ENCODING
   18406             :             | ENCRYPTED
   18407             :             | END_P
   18408             :             | ENFORCED
   18409             :             | ENUM_P
   18410             :             | ERROR_P
   18411             :             | ESCAPE
   18412             :             | EVENT
   18413             :             | EXCLUDE
   18414             :             | EXCLUDING
   18415             :             | EXCLUSIVE
   18416             :             | EXECUTE
   18417             :             | EXISTS
   18418             :             | EXPLAIN
   18419             :             | EXPRESSION
   18420             :             | EXTENSION
   18421             :             | EXTERNAL
   18422             :             | EXTRACT
   18423             :             | FALSE_P
   18424             :             | FAMILY
   18425             :             | FINALIZE
   18426             :             | FIRST_P
   18427             :             | FLOAT_P
   18428             :             | FOLLOWING
   18429             :             | FORCE
   18430             :             | FOREIGN
   18431             :             | FORMAT
   18432             :             | FORWARD
   18433             :             | FREEZE
   18434             :             | FULL
   18435             :             | FUNCTION
   18436             :             | FUNCTIONS
   18437             :             | GENERATED
   18438             :             | GLOBAL
   18439             :             | GRANTED
   18440             :             | GREATEST
   18441             :             | GROUPING
   18442             :             | GROUPS
   18443             :             | HANDLER
   18444             :             | HEADER_P
   18445             :             | HOLD
   18446             :             | IDENTITY_P
   18447             :             | IF_P
   18448             :             | ILIKE
   18449             :             | IMMEDIATE
   18450             :             | IMMUTABLE
   18451             :             | IMPLICIT_P
   18452             :             | IMPORT_P
   18453             :             | IN_P
   18454             :             | INCLUDE
   18455             :             | INCLUDING
   18456             :             | INCREMENT
   18457             :             | INDENT
   18458             :             | INDEX
   18459             :             | INDEXES
   18460             :             | INHERIT
   18461             :             | INHERITS
   18462             :             | INITIALLY
   18463             :             | INLINE_P
   18464             :             | INNER_P
   18465             :             | INOUT
   18466             :             | INPUT_P
   18467             :             | INSENSITIVE
   18468             :             | INSERT
   18469             :             | INSTEAD
   18470             :             | INT_P
   18471             :             | INTEGER
   18472             :             | INTERVAL
   18473             :             | INVOKER
   18474             :             | IS
   18475             :             | ISOLATION
   18476             :             | JOIN
   18477             :             | JSON
   18478             :             | JSON_ARRAY
   18479             :             | JSON_ARRAYAGG
   18480             :             | JSON_EXISTS
   18481             :             | JSON_OBJECT
   18482             :             | JSON_OBJECTAGG
   18483             :             | JSON_QUERY
   18484             :             | JSON_SCALAR
   18485             :             | JSON_SERIALIZE
   18486             :             | JSON_TABLE
   18487             :             | JSON_VALUE
   18488             :             | KEEP
   18489             :             | KEY
   18490             :             | KEYS
   18491             :             | LABEL
   18492             :             | LANGUAGE
   18493             :             | LARGE_P
   18494             :             | LAST_P
   18495             :             | LATERAL_P
   18496             :             | LEADING
   18497             :             | LEAKPROOF
   18498             :             | LEAST
   18499             :             | LEFT
   18500             :             | LEVEL
   18501             :             | LIKE
   18502             :             | LISTEN
   18503             :             | LOAD
   18504             :             | LOCAL
   18505             :             | LOCALTIME
   18506             :             | LOCALTIMESTAMP
   18507             :             | LOCATION
   18508             :             | LOCK_P
   18509             :             | LOCKED
   18510             :             | LOGGED
   18511             :             | MAPPING
   18512             :             | MATCH
   18513             :             | MATCHED
   18514             :             | MATERIALIZED
   18515             :             | MAXVALUE
   18516             :             | MERGE
   18517             :             | MERGE_ACTION
   18518             :             | METHOD
   18519             :             | MINVALUE
   18520             :             | MODE
   18521             :             | MOVE
   18522             :             | NAME_P
   18523             :             | NAMES
   18524             :             | NATIONAL
   18525             :             | NATURAL
   18526             :             | NCHAR
   18527             :             | NESTED
   18528             :             | NEW
   18529             :             | NEXT
   18530             :             | NFC
   18531             :             | NFD
   18532             :             | NFKC
   18533             :             | NFKD
   18534             :             | NO
   18535             :             | NONE
   18536             :             | NORMALIZE
   18537             :             | NORMALIZED
   18538             :             | NOT
   18539             :             | NOTHING
   18540             :             | NOTIFY
   18541             :             | NOWAIT
   18542             :             | NULL_P
   18543             :             | NULLIF
   18544             :             | NULLS_P
   18545             :             | NUMERIC
   18546             :             | OBJECT_P
   18547             :             | OBJECTS_P
   18548             :             | OF
   18549             :             | OFF
   18550             :             | OIDS
   18551             :             | OLD
   18552             :             | OMIT
   18553             :             | ONLY
   18554             :             | OPERATOR
   18555             :             | OPTION
   18556             :             | OPTIONS
   18557             :             | OR
   18558             :             | ORDINALITY
   18559             :             | OTHERS
   18560             :             | OUT_P
   18561             :             | OUTER_P
   18562             :             | OVERLAY
   18563             :             | OVERRIDING
   18564             :             | OWNED
   18565             :             | OWNER
   18566             :             | PARALLEL
   18567             :             | PARAMETER
   18568             :             | PARSER
   18569             :             | PARTIAL
   18570             :             | PARTITION
   18571             :             | PASSING
   18572             :             | PASSWORD
   18573             :             | PATH
   18574             :             | PERIOD
   18575             :             | PLACING
   18576             :             | PLAN
   18577             :             | PLANS
   18578             :             | POLICY
   18579             :             | POSITION
   18580             :             | PRECEDING
   18581             :             | PREPARE
   18582             :             | PREPARED
   18583             :             | PRESERVE
   18584             :             | PRIMARY
   18585             :             | PRIOR
   18586             :             | PRIVILEGES
   18587             :             | PROCEDURAL
   18588             :             | PROCEDURE
   18589             :             | PROCEDURES
   18590             :             | PROGRAM
   18591             :             | PUBLICATION
   18592             :             | QUOTE
   18593             :             | QUOTES
   18594             :             | RANGE
   18595             :             | READ
   18596             :             | REAL
   18597             :             | REASSIGN
   18598             :             | RECURSIVE
   18599             :             | REF_P
   18600             :             | REFERENCES
   18601             :             | REFERENCING
   18602             :             | REFRESH
   18603             :             | REINDEX
   18604             :             | RELATIVE_P
   18605             :             | RELEASE
   18606             :             | RENAME
   18607             :             | REPEATABLE
   18608             :             | REPLACE
   18609             :             | REPLICA
   18610             :             | RESET
   18611             :             | RESTART
   18612             :             | RESTRICT
   18613             :             | RETURN
   18614             :             | RETURNS
   18615             :             | REVOKE
   18616             :             | RIGHT
   18617             :             | ROLE
   18618             :             | ROLLBACK
   18619             :             | ROLLUP
   18620             :             | ROUTINE
   18621             :             | ROUTINES
   18622             :             | ROW
   18623             :             | ROWS
   18624             :             | RULE
   18625             :             | SAVEPOINT
   18626             :             | SCALAR
   18627             :             | SCHEMA
   18628             :             | SCHEMAS
   18629             :             | SCROLL
   18630             :             | SEARCH
   18631             :             | SECURITY
   18632             :             | SELECT
   18633             :             | SEQUENCE
   18634             :             | SEQUENCES
   18635             :             | SERIALIZABLE
   18636             :             | SERVER
   18637             :             | SESSION
   18638             :             | SESSION_USER
   18639             :             | SET
   18640             :             | SETOF
   18641             :             | SETS
   18642             :             | SHARE
   18643             :             | SHOW
   18644             :             | SIMILAR
   18645             :             | SIMPLE
   18646             :             | SKIP
   18647             :             | SMALLINT
   18648             :             | SNAPSHOT
   18649             :             | SOME
   18650             :             | SOURCE
   18651             :             | SQL_P
   18652             :             | STABLE
   18653             :             | STANDALONE_P
   18654             :             | START
   18655             :             | STATEMENT
   18656             :             | STATISTICS
   18657             :             | STDIN
   18658             :             | STDOUT
   18659             :             | STORAGE
   18660             :             | STORED
   18661             :             | STRICT_P
   18662             :             | STRING_P
   18663             :             | STRIP_P
   18664             :             | SUBSCRIPTION
   18665             :             | SUBSTRING
   18666             :             | SUPPORT
   18667             :             | SYMMETRIC
   18668             :             | SYSID
   18669             :             | SYSTEM_P
   18670             :             | SYSTEM_USER
   18671             :             | TABLE
   18672             :             | TABLES
   18673             :             | TABLESAMPLE
   18674             :             | TABLESPACE
   18675             :             | TARGET
   18676             :             | TEMP
   18677             :             | TEMPLATE
   18678             :             | TEMPORARY
   18679             :             | TEXT_P
   18680             :             | THEN
   18681             :             | TIES
   18682             :             | TIME
   18683             :             | TIMESTAMP
   18684             :             | TRAILING
   18685             :             | TRANSACTION
   18686             :             | TRANSFORM
   18687             :             | TREAT
   18688             :             | TRIGGER
   18689             :             | TRIM
   18690             :             | TRUE_P
   18691             :             | TRUNCATE
   18692             :             | TRUSTED
   18693             :             | TYPE_P
   18694             :             | TYPES_P
   18695             :             | UESCAPE
   18696             :             | UNBOUNDED
   18697             :             | UNCOMMITTED
   18698             :             | UNCONDITIONAL
   18699             :             | UNENCRYPTED
   18700             :             | UNIQUE
   18701             :             | UNKNOWN
   18702             :             | UNLISTEN
   18703             :             | UNLOGGED
   18704             :             | UNTIL
   18705             :             | UPDATE
   18706             :             | USER
   18707             :             | USING
   18708             :             | VACUUM
   18709             :             | VALID
   18710             :             | VALIDATE
   18711             :             | VALIDATOR
   18712             :             | VALUE_P
   18713             :             | VALUES
   18714             :             | VARCHAR
   18715             :             | VARIADIC
   18716             :             | VERBOSE
   18717             :             | VERSION_P
   18718             :             | VIEW
   18719             :             | VIEWS
   18720             :             | VIRTUAL
   18721             :             | VOLATILE
   18722             :             | WHEN
   18723             :             | WHITESPACE_P
   18724             :             | WORK
   18725             :             | WRAPPER
   18726             :             | WRITE
   18727             :             | XML_P
   18728             :             | XMLATTRIBUTES
   18729             :             | XMLCONCAT
   18730             :             | XMLELEMENT
   18731             :             | XMLEXISTS
   18732             :             | XMLFOREST
   18733             :             | XMLNAMESPACES
   18734             :             | XMLPARSE
   18735             :             | XMLPI
   18736             :             | XMLROOT
   18737             :             | XMLSERIALIZE
   18738             :             | XMLTABLE
   18739             :             | YES_P
   18740             :             | ZONE
   18741             :         ;
   18742             : 
   18743             : %%
   18744             : 
   18745             : /*
   18746             :  * The signature of this function is required by bison.  However, we
   18747             :  * ignore the passed yylloc and instead use the last token position
   18748             :  * available from the scanner.
   18749             :  */
   18750             : static void
   18751         696 : base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
   18752             : {
   18753         696 :     parser_yyerror(msg);
   18754             : }
   18755             : 
   18756             : static RawStmt *
   18757      834460 : makeRawStmt(Node *stmt, int stmt_location)
   18758             : {
   18759      834460 :     RawStmt    *rs = makeNode(RawStmt);
   18760             : 
   18761      834460 :     rs->stmt = stmt;
   18762      834460 :     rs->stmt_location = stmt_location;
   18763      834460 :     rs->stmt_len = 0;            /* might get changed later */
   18764      834460 :     return rs;
   18765             : }
   18766             : 
   18767             : /* Adjust a RawStmt to reflect that it doesn't run to the end of the string */
   18768             : static void
   18769      589764 : updateRawStmtEnd(RawStmt *rs, int end_location)
   18770             : {
   18771             :     /*
   18772             :      * If we already set the length, don't change it.  This is for situations
   18773             :      * like "select foo ;; select bar" where the same statement will be last
   18774             :      * in the string for more than one semicolon.
   18775             :      */
   18776      589764 :     if (rs->stmt_len > 0)
   18777         552 :         return;
   18778             : 
   18779             :     /* OK, update length of RawStmt */
   18780      589212 :     rs->stmt_len = end_location - rs->stmt_location;
   18781             : }
   18782             : 
   18783             : static Node *
   18784     1873510 : makeColumnRef(char *colname, List *indirection,
   18785             :               int location, core_yyscan_t yyscanner)
   18786             : {
   18787             :     /*
   18788             :      * Generate a ColumnRef node, with an A_Indirection node added if there is
   18789             :      * any subscripting in the specified indirection list.  However, any field
   18790             :      * selection at the start of the indirection list must be transposed into
   18791             :      * the "fields" part of the ColumnRef node.
   18792             :      */
   18793     1873510 :     ColumnRef  *c = makeNode(ColumnRef);
   18794     1873510 :     int         nfields = 0;
   18795             :     ListCell   *l;
   18796             : 
   18797     1873510 :     c->location = location;
   18798     2958066 :     foreach(l, indirection)
   18799             :     {
   18800     1094694 :         if (IsA(lfirst(l), A_Indices))
   18801             :         {
   18802       10138 :             A_Indirection *i = makeNode(A_Indirection);
   18803             : 
   18804       10138 :             if (nfields == 0)
   18805             :             {
   18806             :                 /* easy case - all indirection goes to A_Indirection */
   18807        7416 :                 c->fields = list_make1(makeString(colname));
   18808        7416 :                 i->indirection = check_indirection(indirection, yyscanner);
   18809             :             }
   18810             :             else
   18811             :             {
   18812             :                 /* got to split the list in two */
   18813        2722 :                 i->indirection = check_indirection(list_copy_tail(indirection,
   18814             :                                                                   nfields),
   18815             :                                                    yyscanner);
   18816        2722 :                 indirection = list_truncate(indirection, nfields);
   18817        2722 :                 c->fields = lcons(makeString(colname), indirection);
   18818             :             }
   18819       10138 :             i->arg = (Node *) c;
   18820       10138 :             return (Node *) i;
   18821             :         }
   18822     1084556 :         else if (IsA(lfirst(l), A_Star))
   18823             :         {
   18824             :             /* We only allow '*' at the end of a ColumnRef */
   18825        5462 :             if (lnext(indirection, l) != NULL)
   18826           0 :                 parser_yyerror("improper use of \"*\"");
   18827             :         }
   18828     1084556 :         nfields++;
   18829             :     }
   18830             :     /* No subscripting, so all indirection gets added to field list */
   18831     1863372 :     c->fields = lcons(makeString(colname), indirection);
   18832     1863372 :     return (Node *) c;
   18833             : }
   18834             : 
   18835             : static Node *
   18836      323052 : makeTypeCast(Node *arg, TypeName *typename, int location)
   18837             : {
   18838      323052 :     TypeCast   *n = makeNode(TypeCast);
   18839             : 
   18840      323052 :     n->arg = arg;
   18841      323052 :     n->typeName = typename;
   18842      323052 :     n->location = location;
   18843      323052 :     return (Node *) n;
   18844             : }
   18845             : 
   18846             : static Node *
   18847       16272 : makeStringConstCast(char *str, int location, TypeName *typename)
   18848             : {
   18849       16272 :     Node       *s = makeStringConst(str, location);
   18850             : 
   18851       16272 :     return makeTypeCast(s, typename, -1);
   18852             : }
   18853             : 
   18854             : static Node *
   18855      389338 : makeIntConst(int val, int location)
   18856             : {
   18857      389338 :     A_Const    *n = makeNode(A_Const);
   18858             : 
   18859      389338 :     n->val.ival.type = T_Integer;
   18860      389338 :     n->val.ival.ival = val;
   18861      389338 :     n->location = location;
   18862             : 
   18863      389338 :     return (Node *) n;
   18864             : }
   18865             : 
   18866             : static Node *
   18867       11628 : makeFloatConst(char *str, int location)
   18868             : {
   18869       11628 :     A_Const    *n = makeNode(A_Const);
   18870             : 
   18871       11628 :     n->val.fval.type = T_Float;
   18872       11628 :     n->val.fval.fval = str;
   18873       11628 :     n->location = location;
   18874             : 
   18875       11628 :     return (Node *) n;
   18876             : }
   18877             : 
   18878             : static Node *
   18879       68000 : makeBoolAConst(bool state, int location)
   18880             : {
   18881       68000 :     A_Const    *n = makeNode(A_Const);
   18882             : 
   18883       68000 :     n->val.boolval.type = T_Boolean;
   18884       68000 :     n->val.boolval.boolval = state;
   18885       68000 :     n->location = location;
   18886             : 
   18887       68000 :     return (Node *) n;
   18888             : }
   18889             : 
   18890             : static Node *
   18891        4056 : makeBitStringConst(char *str, int location)
   18892             : {
   18893        4056 :     A_Const    *n = makeNode(A_Const);
   18894             : 
   18895        4056 :     n->val.bsval.type = T_BitString;
   18896        4056 :     n->val.bsval.bsval = str;
   18897        4056 :     n->location = location;
   18898             : 
   18899        4056 :     return (Node *) n;
   18900             : }
   18901             : 
   18902             : static Node *
   18903       68714 : makeNullAConst(int location)
   18904             : {
   18905       68714 :     A_Const    *n = makeNode(A_Const);
   18906             : 
   18907       68714 :     n->isnull = true;
   18908       68714 :     n->location = location;
   18909             : 
   18910       68714 :     return (Node *) n;
   18911             : }
   18912             : 
   18913             : static Node *
   18914        5696 : makeAConst(Node *v, int location)
   18915             : {
   18916             :     Node       *n;
   18917             : 
   18918        5696 :     switch (v->type)
   18919             :     {
   18920         218 :         case T_Float:
   18921         218 :             n = makeFloatConst(castNode(Float, v)->fval, location);
   18922         218 :             break;
   18923             : 
   18924        5478 :         case T_Integer:
   18925        5478 :             n = makeIntConst(castNode(Integer, v)->ival, location);
   18926        5478 :             break;
   18927             : 
   18928           0 :         default:
   18929             :             /* currently not used */
   18930             :             Assert(false);
   18931           0 :             n = NULL;
   18932             :     }
   18933             : 
   18934        5696 :     return n;
   18935             : }
   18936             : 
   18937             : /* makeRoleSpec
   18938             :  * Create a RoleSpec with the given type
   18939             :  */
   18940             : static RoleSpec *
   18941       36160 : makeRoleSpec(RoleSpecType type, int location)
   18942             : {
   18943       36160 :     RoleSpec   *spec = makeNode(RoleSpec);
   18944             : 
   18945       36160 :     spec->roletype = type;
   18946       36160 :     spec->location = location;
   18947             : 
   18948       36160 :     return spec;
   18949             : }
   18950             : 
   18951             : /* check_qualified_name --- check the result of qualified_name production
   18952             :  *
   18953             :  * It's easiest to let the grammar production for qualified_name allow
   18954             :  * subscripts and '*', which we then must reject here.
   18955             :  */
   18956             : static void
   18957      264624 : check_qualified_name(List *names, core_yyscan_t yyscanner)
   18958             : {
   18959             :     ListCell   *i;
   18960             : 
   18961      529248 :     foreach(i, names)
   18962             :     {
   18963      264624 :         if (!IsA(lfirst(i), String))
   18964           0 :             parser_yyerror("syntax error");
   18965             :     }
   18966      264624 : }
   18967             : 
   18968             : /* check_func_name --- check the result of func_name production
   18969             :  *
   18970             :  * It's easiest to let the grammar production for func_name allow subscripts
   18971             :  * and '*', which we then must reject here.
   18972             :  */
   18973             : static List *
   18974      131044 : check_func_name(List *names, core_yyscan_t yyscanner)
   18975             : {
   18976             :     ListCell   *i;
   18977             : 
   18978      393132 :     foreach(i, names)
   18979             :     {
   18980      262088 :         if (!IsA(lfirst(i), String))
   18981           0 :             parser_yyerror("syntax error");
   18982             :     }
   18983      131044 :     return names;
   18984             : }
   18985             : 
   18986             : /* check_indirection --- check the result of indirection production
   18987             :  *
   18988             :  * We only allow '*' at the end of the list, but it's hard to enforce that
   18989             :  * in the grammar, so do it here.
   18990             :  */
   18991             : static List *
   18992       82998 : check_indirection(List *indirection, core_yyscan_t yyscanner)
   18993             : {
   18994             :     ListCell   *l;
   18995             : 
   18996      111080 :     foreach(l, indirection)
   18997             :     {
   18998       28082 :         if (IsA(lfirst(l), A_Star))
   18999             :         {
   19000        1470 :             if (lnext(indirection, l) != NULL)
   19001           0 :                 parser_yyerror("improper use of \"*\"");
   19002             :         }
   19003             :     }
   19004       82998 :     return indirection;
   19005             : }
   19006             : 
   19007             : /* extractArgTypes()
   19008             :  * Given a list of FunctionParameter nodes, extract a list of just the
   19009             :  * argument types (TypeNames) for input parameters only.  This is what
   19010             :  * is needed to look up an existing function, which is what is wanted by
   19011             :  * the productions that use this call.
   19012             :  */
   19013             : static List *
   19014       17042 : extractArgTypes(List *parameters)
   19015             : {
   19016       17042 :     List       *result = NIL;
   19017             :     ListCell   *i;
   19018             : 
   19019       36286 :     foreach(i, parameters)
   19020             :     {
   19021       19244 :         FunctionParameter *p = (FunctionParameter *) lfirst(i);
   19022             : 
   19023       19244 :         if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
   19024       19022 :             result = lappend(result, p->argType);
   19025             :     }
   19026       17042 :     return result;
   19027             : }
   19028             : 
   19029             : /* extractAggrArgTypes()
   19030             :  * As above, but work from the output of the aggr_args production.
   19031             :  */
   19032             : static List *
   19033         460 : extractAggrArgTypes(List *aggrargs)
   19034             : {
   19035             :     Assert(list_length(aggrargs) == 2);
   19036         460 :     return extractArgTypes((List *) linitial(aggrargs));
   19037             : }
   19038             : 
   19039             : /* makeOrderedSetArgs()
   19040             :  * Build the result of the aggr_args production (which see the comments for).
   19041             :  * This handles only the case where both given lists are nonempty, so that
   19042             :  * we have to deal with multiple VARIADIC arguments.
   19043             :  */
   19044             : static List *
   19045          40 : makeOrderedSetArgs(List *directargs, List *orderedargs,
   19046             :                    core_yyscan_t yyscanner)
   19047             : {
   19048          40 :     FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
   19049             :     Integer    *ndirectargs;
   19050             : 
   19051             :     /* No restriction unless last direct arg is VARIADIC */
   19052          40 :     if (lastd->mode == FUNC_PARAM_VARIADIC)
   19053             :     {
   19054          20 :         FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
   19055             : 
   19056             :         /*
   19057             :          * We ignore the names, though the aggr_arg production allows them; it
   19058             :          * doesn't allow default values, so those need not be checked.
   19059             :          */
   19060          20 :         if (list_length(orderedargs) != 1 ||
   19061          20 :             firsto->mode != FUNC_PARAM_VARIADIC ||
   19062          20 :             !equal(lastd->argType, firsto->argType))
   19063           0 :             ereport(ERROR,
   19064             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19065             :                      errmsg("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
   19066             :                      parser_errposition(firsto->location)));
   19067             : 
   19068             :         /* OK, drop the duplicate VARIADIC argument from the internal form */
   19069          20 :         orderedargs = NIL;
   19070             :     }
   19071             : 
   19072             :     /* don't merge into the next line, as list_concat changes directargs */
   19073          40 :     ndirectargs = makeInteger(list_length(directargs));
   19074             : 
   19075          40 :     return list_make2(list_concat(directargs, orderedargs),
   19076             :                       ndirectargs);
   19077             : }
   19078             : 
   19079             : /* insertSelectOptions()
   19080             :  * Insert ORDER BY, etc into an already-constructed SelectStmt.
   19081             :  *
   19082             :  * This routine is just to avoid duplicating code in SelectStmt productions.
   19083             :  */
   19084             : static void
   19085       85338 : insertSelectOptions(SelectStmt *stmt,
   19086             :                     List *sortClause, List *lockingClause,
   19087             :                     SelectLimit *limitClause,
   19088             :                     WithClause *withClause,
   19089             :                     core_yyscan_t yyscanner)
   19090             : {
   19091             :     Assert(IsA(stmt, SelectStmt));
   19092             : 
   19093             :     /*
   19094             :      * Tests here are to reject constructs like
   19095             :      *  (SELECT foo ORDER BY bar) ORDER BY baz
   19096             :      */
   19097       85338 :     if (sortClause)
   19098             :     {
   19099       75898 :         if (stmt->sortClause)
   19100           0 :             ereport(ERROR,
   19101             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19102             :                      errmsg("multiple ORDER BY clauses not allowed"),
   19103             :                      parser_errposition(exprLocation((Node *) sortClause))));
   19104       75898 :         stmt->sortClause = sortClause;
   19105             :     }
   19106             :     /* We can handle multiple locking clauses, though */
   19107       85338 :     stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
   19108       85338 :     if (limitClause && limitClause->limitOffset)
   19109             :     {
   19110         848 :         if (stmt->limitOffset)
   19111           0 :             ereport(ERROR,
   19112             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19113             :                      errmsg("multiple OFFSET clauses not allowed"),
   19114             :                      parser_errposition(limitClause->offsetLoc)));
   19115         848 :         stmt->limitOffset = limitClause->limitOffset;
   19116             :     }
   19117       85338 :     if (limitClause && limitClause->limitCount)
   19118             :     {
   19119        4712 :         if (stmt->limitCount)
   19120           0 :             ereport(ERROR,
   19121             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19122             :                      errmsg("multiple LIMIT clauses not allowed"),
   19123             :                      parser_errposition(limitClause->countLoc)));
   19124        4712 :         stmt->limitCount = limitClause->limitCount;
   19125             :     }
   19126       85338 :     if (limitClause)
   19127             :     {
   19128             :         /* If there was a conflict, we must have detected it above */
   19129             :         Assert(!stmt->limitOption);
   19130        5162 :         if (!stmt->sortClause && limitClause->limitOption == LIMIT_OPTION_WITH_TIES)
   19131           6 :             ereport(ERROR,
   19132             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19133             :                      errmsg("WITH TIES cannot be specified without ORDER BY clause"),
   19134             :                      parser_errposition(limitClause->optionLoc)));
   19135        5156 :         if (limitClause->limitOption == LIMIT_OPTION_WITH_TIES && stmt->lockingClause)
   19136             :         {
   19137             :             ListCell   *lc;
   19138             : 
   19139           6 :             foreach(lc, stmt->lockingClause)
   19140             :             {
   19141           6 :                 LockingClause *lock = lfirst_node(LockingClause, lc);
   19142             : 
   19143           6 :                 if (lock->waitPolicy == LockWaitSkip)
   19144           6 :                     ereport(ERROR,
   19145             :                             (errcode(ERRCODE_SYNTAX_ERROR),
   19146             :                              errmsg("%s and %s options cannot be used together",
   19147             :                                     "SKIP LOCKED", "WITH TIES"),
   19148             :                              parser_errposition(limitClause->optionLoc)));
   19149             :             }
   19150             :         }
   19151        5150 :         stmt->limitOption = limitClause->limitOption;
   19152             :     }
   19153       85326 :     if (withClause)
   19154             :     {
   19155        2892 :         if (stmt->withClause)
   19156           0 :             ereport(ERROR,
   19157             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19158             :                      errmsg("multiple WITH clauses not allowed"),
   19159             :                      parser_errposition(exprLocation((Node *) withClause))));
   19160        2892 :         stmt->withClause = withClause;
   19161             :     }
   19162       85326 : }
   19163             : 
   19164             : static Node *
   19165       19472 : makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
   19166             : {
   19167       19472 :     SelectStmt *n = makeNode(SelectStmt);
   19168             : 
   19169       19472 :     n->op = op;
   19170       19472 :     n->all = all;
   19171       19472 :     n->larg = (SelectStmt *) larg;
   19172       19472 :     n->rarg = (SelectStmt *) rarg;
   19173       19472 :     return (Node *) n;
   19174             : }
   19175             : 
   19176             : /* SystemFuncName()
   19177             :  * Build a properly-qualified reference to a built-in function.
   19178             :  */
   19179             : List *
   19180       19512 : SystemFuncName(char *name)
   19181             : {
   19182       19512 :     return list_make2(makeString("pg_catalog"), makeString(name));
   19183             : }
   19184             : 
   19185             : /* SystemTypeName()
   19186             :  * Build a properly-qualified reference to a built-in type.
   19187             :  *
   19188             :  * typmod is defaulted, but may be changed afterwards by caller.
   19189             :  * Likewise for the location.
   19190             :  */
   19191             : TypeName *
   19192      126322 : SystemTypeName(char *name)
   19193             : {
   19194      126322 :     return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
   19195             :                                                makeString(name)));
   19196             : }
   19197             : 
   19198             : /* doNegate()
   19199             :  * Handle negation of a numeric constant.
   19200             :  *
   19201             :  * Formerly, we did this here because the optimizer couldn't cope with
   19202             :  * indexquals that looked like "var = -4" --- it wants "var = const"
   19203             :  * and a unary minus operator applied to a constant didn't qualify.
   19204             :  * As of Postgres 7.0, that problem doesn't exist anymore because there
   19205             :  * is a constant-subexpression simplifier in the optimizer.  However,
   19206             :  * there's still a good reason for doing this here, which is that we can
   19207             :  * postpone committing to a particular internal representation for simple
   19208             :  * negative constants.  It's better to leave "-123.456" in string form
   19209             :  * until we know what the desired type is.
   19210             :  */
   19211             : static Node *
   19212        9264 : doNegate(Node *n, int location)
   19213             : {
   19214        9264 :     if (IsA(n, A_Const))
   19215             :     {
   19216        8260 :         A_Const    *con = (A_Const *) n;
   19217             : 
   19218             :         /* report the constant's location as that of the '-' sign */
   19219        8260 :         con->location = location;
   19220             : 
   19221        8260 :         if (IsA(&con->val, Integer))
   19222             :         {
   19223        7302 :             con->val.ival.ival = -con->val.ival.ival;
   19224        7302 :             return n;
   19225             :         }
   19226         958 :         if (IsA(&con->val, Float))
   19227             :         {
   19228         958 :             doNegateFloat(&con->val.fval);
   19229         958 :             return n;
   19230             :         }
   19231             :     }
   19232             : 
   19233        1004 :     return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
   19234             : }
   19235             : 
   19236             : static void
   19237         980 : doNegateFloat(Float *v)
   19238             : {
   19239         980 :     char       *oldval = v->fval;
   19240             : 
   19241         980 :     if (*oldval == '+')
   19242           0 :         oldval++;
   19243         980 :     if (*oldval == '-')
   19244           0 :         v->fval = oldval + 1;    /* just strip the '-' */
   19245             :     else
   19246         980 :         v->fval = psprintf("-%s", oldval);
   19247         980 : }
   19248             : 
   19249             : static Node *
   19250      239288 : makeAndExpr(Node *lexpr, Node *rexpr, int location)
   19251             : {
   19252             :     /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
   19253      239288 :     if (IsA(lexpr, BoolExpr))
   19254             :     {
   19255      112990 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   19256             : 
   19257      112990 :         if (blexpr->boolop == AND_EXPR)
   19258             :         {
   19259      110262 :             blexpr->args = lappend(blexpr->args, rexpr);
   19260      110262 :             return (Node *) blexpr;
   19261             :         }
   19262             :     }
   19263      129026 :     return (Node *) makeBoolExpr(AND_EXPR, list_make2(lexpr, rexpr), location);
   19264             : }
   19265             : 
   19266             : static Node *
   19267       16842 : makeOrExpr(Node *lexpr, Node *rexpr, int location)
   19268             : {
   19269             :     /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
   19270       16842 :     if (IsA(lexpr, BoolExpr))
   19271             :     {
   19272        5930 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   19273             : 
   19274        5930 :         if (blexpr->boolop == OR_EXPR)
   19275             :         {
   19276        4342 :             blexpr->args = lappend(blexpr->args, rexpr);
   19277        4342 :             return (Node *) blexpr;
   19278             :         }
   19279             :     }
   19280       12500 :     return (Node *) makeBoolExpr(OR_EXPR, list_make2(lexpr, rexpr), location);
   19281             : }
   19282             : 
   19283             : static Node *
   19284       17028 : makeNotExpr(Node *expr, int location)
   19285             : {
   19286       17028 :     return (Node *) makeBoolExpr(NOT_EXPR, list_make1(expr), location);
   19287             : }
   19288             : 
   19289             : static Node *
   19290        8234 : makeAArrayExpr(List *elements, int location, int location_end)
   19291             : {
   19292        8234 :     A_ArrayExpr *n = makeNode(A_ArrayExpr);
   19293             : 
   19294        8234 :     n->elements = elements;
   19295        8234 :     n->location = location;
   19296        8234 :     n->list_start = location;
   19297        8234 :     n->list_end = location_end;
   19298        8234 :     return (Node *) n;
   19299             : }
   19300             : 
   19301             : static Node *
   19302        2764 : makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod, int location)
   19303             : {
   19304        2764 :     SQLValueFunction *svf = makeNode(SQLValueFunction);
   19305             : 
   19306        2764 :     svf->op = op;
   19307             :     /* svf->type will be filled during parse analysis */
   19308        2764 :     svf->typmod = typmod;
   19309        2764 :     svf->location = location;
   19310        2764 :     return (Node *) svf;
   19311             : }
   19312             : 
   19313             : static Node *
   19314         610 : makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
   19315             :             int location)
   19316             : {
   19317         610 :     XmlExpr    *x = makeNode(XmlExpr);
   19318             : 
   19319         610 :     x->op = op;
   19320         610 :     x->name = name;
   19321             : 
   19322             :     /*
   19323             :      * named_args is a list of ResTarget; it'll be split apart into separate
   19324             :      * expression and name lists in transformXmlExpr().
   19325             :      */
   19326         610 :     x->named_args = named_args;
   19327         610 :     x->arg_names = NIL;
   19328         610 :     x->args = args;
   19329             :     /* xmloption, if relevant, must be filled in by caller */
   19330             :     /* type and typmod will be filled in during parse analysis */
   19331         610 :     x->type = InvalidOid;        /* marks the node as not analyzed */
   19332         610 :     x->location = location;
   19333         610 :     return (Node *) x;
   19334             : }
   19335             : 
   19336             : /*
   19337             :  * Merge the input and output parameters of a table function.
   19338             :  */
   19339             : static List *
   19340         202 : mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner)
   19341             : {
   19342             :     ListCell   *lc;
   19343             : 
   19344             :     /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
   19345         412 :     foreach(lc, func_args)
   19346             :     {
   19347         210 :         FunctionParameter *p = (FunctionParameter *) lfirst(lc);
   19348             : 
   19349         210 :         if (p->mode != FUNC_PARAM_DEFAULT &&
   19350           0 :             p->mode != FUNC_PARAM_IN &&
   19351           0 :             p->mode != FUNC_PARAM_VARIADIC)
   19352           0 :             ereport(ERROR,
   19353             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19354             :                      errmsg("OUT and INOUT arguments aren't allowed in TABLE functions"),
   19355             :                      parser_errposition(p->location)));
   19356             :     }
   19357             : 
   19358         202 :     return list_concat(func_args, columns);
   19359             : }
   19360             : 
   19361             : /*
   19362             :  * Determine return type of a TABLE function.  A single result column
   19363             :  * returns setof that column's type; otherwise return setof record.
   19364             :  */
   19365             : static TypeName *
   19366         202 : TableFuncTypeName(List *columns)
   19367             : {
   19368             :     TypeName   *result;
   19369             : 
   19370         202 :     if (list_length(columns) == 1)
   19371             :     {
   19372          70 :         FunctionParameter *p = (FunctionParameter *) linitial(columns);
   19373             : 
   19374          70 :         result = copyObject(p->argType);
   19375             :     }
   19376             :     else
   19377         132 :         result = SystemTypeName("record");
   19378             : 
   19379         202 :     result->setof = true;
   19380             : 
   19381         202 :     return result;
   19382             : }
   19383             : 
   19384             : /*
   19385             :  * Convert a list of (dotted) names to a RangeVar (like
   19386             :  * makeRangeVarFromNameList, but with position support).  The
   19387             :  * "AnyName" refers to the any_name production in the grammar.
   19388             :  */
   19389             : static RangeVar *
   19390        4768 : makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
   19391             : {
   19392        4768 :     RangeVar   *r = makeNode(RangeVar);
   19393             : 
   19394        4768 :     switch (list_length(names))
   19395             :     {
   19396        4646 :         case 1:
   19397        4646 :             r->catalogname = NULL;
   19398        4646 :             r->schemaname = NULL;
   19399        4646 :             r->relname = strVal(linitial(names));
   19400        4646 :             break;
   19401         122 :         case 2:
   19402         122 :             r->catalogname = NULL;
   19403         122 :             r->schemaname = strVal(linitial(names));
   19404         122 :             r->relname = strVal(lsecond(names));
   19405         122 :             break;
   19406           0 :         case 3:
   19407           0 :             r->catalogname = strVal(linitial(names));
   19408           0 :             r->schemaname = strVal(lsecond(names));
   19409           0 :             r->relname = strVal(lthird(names));
   19410           0 :             break;
   19411           0 :         default:
   19412           0 :             ereport(ERROR,
   19413             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19414             :                      errmsg("improper qualified name (too many dotted names): %s",
   19415             :                             NameListToString(names)),
   19416             :                      parser_errposition(position)));
   19417             :             break;
   19418             :     }
   19419             : 
   19420        4768 :     r->relpersistence = RELPERSISTENCE_PERMANENT;
   19421        4768 :     r->location = position;
   19422             : 
   19423        4768 :     return r;
   19424             : }
   19425             : 
   19426             : /*
   19427             :  * Convert a relation_name with name and namelist to a RangeVar using
   19428             :  * makeRangeVar.
   19429             :  */
   19430             : static RangeVar *
   19431      264624 : makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
   19432             :                               core_yyscan_t yyscanner)
   19433             : {
   19434             :     RangeVar   *r;
   19435             : 
   19436      264624 :     check_qualified_name(namelist, yyscanner);
   19437      264624 :     r = makeRangeVar(NULL, NULL, location);
   19438             : 
   19439      264624 :     switch (list_length(namelist))
   19440             :     {
   19441      264624 :         case 1:
   19442      264624 :             r->catalogname = NULL;
   19443      264624 :             r->schemaname = name;
   19444      264624 :             r->relname = strVal(linitial(namelist));
   19445      264624 :             break;
   19446           0 :         case 2:
   19447           0 :             r->catalogname = name;
   19448           0 :             r->schemaname = strVal(linitial(namelist));
   19449           0 :             r->relname = strVal(lsecond(namelist));
   19450           0 :             break;
   19451           0 :         default:
   19452           0 :             ereport(ERROR,
   19453             :                     errcode(ERRCODE_SYNTAX_ERROR),
   19454             :                     errmsg("improper qualified name (too many dotted names): %s",
   19455             :                            NameListToString(lcons(makeString(name), namelist))),
   19456             :                     parser_errposition(location));
   19457             :             break;
   19458             :     }
   19459             : 
   19460      264624 :     return r;
   19461             : }
   19462             : 
   19463             : /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
   19464             : static void
   19465       74630 : SplitColQualList(List *qualList,
   19466             :                  List **constraintList, CollateClause **collClause,
   19467             :                  core_yyscan_t yyscanner)
   19468             : {
   19469             :     ListCell   *cell;
   19470             : 
   19471       74630 :     *collClause = NULL;
   19472       95104 :     foreach(cell, qualList)
   19473             :     {
   19474       20474 :         Node       *n = (Node *) lfirst(cell);
   19475             : 
   19476       20474 :         if (IsA(n, Constraint))
   19477             :         {
   19478             :             /* keep it in list */
   19479       19706 :             continue;
   19480             :         }
   19481         768 :         if (IsA(n, CollateClause))
   19482             :         {
   19483         768 :             CollateClause *c = (CollateClause *) n;
   19484             : 
   19485         768 :             if (*collClause)
   19486           0 :                 ereport(ERROR,
   19487             :                         (errcode(ERRCODE_SYNTAX_ERROR),
   19488             :                          errmsg("multiple COLLATE clauses not allowed"),
   19489             :                          parser_errposition(c->location)));
   19490         768 :             *collClause = c;
   19491             :         }
   19492             :         else
   19493           0 :             elog(ERROR, "unexpected node type %d", (int) n->type);
   19494             :         /* remove non-Constraint nodes from qualList */
   19495         768 :         qualList = foreach_delete_current(qualList, cell);
   19496             :     }
   19497       74630 :     *constraintList = qualList;
   19498       74630 : }
   19499             : 
   19500             : /*
   19501             :  * Process result of ConstraintAttributeSpec, and set appropriate bool flags
   19502             :  * in the output command node.  Pass NULL for any flags the particular
   19503             :  * command doesn't support.
   19504             :  */
   19505             : static void
   19506       18420 : processCASbits(int cas_bits, int location, const char *constrType,
   19507             :                bool *deferrable, bool *initdeferred, bool *is_enforced,
   19508             :                bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner)
   19509             : {
   19510             :     /* defaults */
   19511       18420 :     if (deferrable)
   19512       16258 :         *deferrable = false;
   19513       18420 :     if (initdeferred)
   19514       16258 :         *initdeferred = false;
   19515       18420 :     if (not_valid)
   19516        3978 :         *not_valid = false;
   19517       18420 :     if (is_enforced)
   19518        3480 :         *is_enforced = true;
   19519             : 
   19520       18420 :     if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
   19521             :     {
   19522         242 :         if (deferrable)
   19523         242 :             *deferrable = true;
   19524             :         else
   19525           0 :             ereport(ERROR,
   19526             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19527             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19528             :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   19529             :                             constrType),
   19530             :                      parser_errposition(location)));
   19531             :     }
   19532             : 
   19533       18420 :     if (cas_bits & CAS_INITIALLY_DEFERRED)
   19534             :     {
   19535         152 :         if (initdeferred)
   19536         152 :             *initdeferred = true;
   19537             :         else
   19538           0 :             ereport(ERROR,
   19539             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19540             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19541             :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   19542             :                             constrType),
   19543             :                      parser_errposition(location)));
   19544             :     }
   19545             : 
   19546       18420 :     if (cas_bits & CAS_NOT_VALID)
   19547             :     {
   19548         732 :         if (not_valid)
   19549         732 :             *not_valid = true;
   19550             :         else
   19551           0 :             ereport(ERROR,
   19552             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19553             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19554             :                      errmsg("%s constraints cannot be marked NOT VALID",
   19555             :                             constrType),
   19556             :                      parser_errposition(location)));
   19557             :     }
   19558             : 
   19559       18420 :     if (cas_bits & CAS_NO_INHERIT)
   19560             :     {
   19561         248 :         if (no_inherit)
   19562         248 :             *no_inherit = true;
   19563             :         else
   19564           0 :             ereport(ERROR,
   19565             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19566             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19567             :                      errmsg("%s constraints cannot be marked NO INHERIT",
   19568             :                             constrType),
   19569             :                      parser_errposition(location)));
   19570             :     }
   19571             : 
   19572       18420 :     if (cas_bits & CAS_NOT_ENFORCED)
   19573             :     {
   19574         162 :         if (is_enforced)
   19575         156 :             *is_enforced = false;
   19576             :         else
   19577           6 :             ereport(ERROR,
   19578             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19579             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19580             :                      errmsg("%s constraints cannot be marked NOT ENFORCED",
   19581             :                             constrType),
   19582             :                      parser_errposition(location)));
   19583             : 
   19584             :         /*
   19585             :          * NB: The validated status is irrelevant when the constraint is set to
   19586             :          * NOT ENFORCED, but for consistency, it should be set accordingly.
   19587             :          * This ensures that if the constraint is later changed to ENFORCED, it
   19588             :          * will automatically be in the correct NOT VALIDATED state.
   19589             :          */
   19590         156 :         if (not_valid)
   19591         120 :             *not_valid = true;
   19592             :     }
   19593             : 
   19594       18414 :     if (cas_bits & CAS_ENFORCED)
   19595             :     {
   19596         102 :         if (is_enforced)
   19597          96 :             *is_enforced = true;
   19598             :         else
   19599           6 :             ereport(ERROR,
   19600             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19601             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19602             :                      errmsg("%s constraints cannot be marked ENFORCED",
   19603             :                             constrType),
   19604             :                      parser_errposition(location)));
   19605             :     }
   19606       18408 : }
   19607             : 
   19608             : /*
   19609             :  * Parse a user-supplied partition strategy string into parse node
   19610             :  * PartitionStrategy representation, or die trying.
   19611             :  */
   19612             : static PartitionStrategy
   19613        5160 : parsePartitionStrategy(char *strategy, int location, core_yyscan_t yyscanner)
   19614             : {
   19615        5160 :     if (pg_strcasecmp(strategy, "list") == 0)
   19616        2602 :         return PARTITION_STRATEGY_LIST;
   19617        2558 :     else if (pg_strcasecmp(strategy, "range") == 0)
   19618        2292 :         return PARTITION_STRATEGY_RANGE;
   19619         266 :     else if (pg_strcasecmp(strategy, "hash") == 0)
   19620         260 :         return PARTITION_STRATEGY_HASH;
   19621             : 
   19622           6 :     ereport(ERROR,
   19623             :             (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   19624             :              errmsg("unrecognized partitioning strategy \"%s\"", strategy),
   19625             :              parser_errposition(location)));
   19626             :     return PARTITION_STRATEGY_LIST; /* keep compiler quiet */
   19627             : 
   19628             : }
   19629             : 
   19630             : /*
   19631             :  * Process pubobjspec_list to check for errors in any of the objects and
   19632             :  * convert PUBLICATIONOBJ_CONTINUATION into appropriate PublicationObjSpecType.
   19633             :  */
   19634             : static void
   19635        1590 : preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
   19636             : {
   19637             :     ListCell   *cell;
   19638             :     PublicationObjSpec *pubobj;
   19639        1590 :     PublicationObjSpecType prevobjtype = PUBLICATIONOBJ_CONTINUATION;
   19640             : 
   19641        1590 :     if (!pubobjspec_list)
   19642           0 :         return;
   19643             : 
   19644        1590 :     pubobj = (PublicationObjSpec *) linitial(pubobjspec_list);
   19645        1590 :     if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   19646          12 :         ereport(ERROR,
   19647             :                 errcode(ERRCODE_SYNTAX_ERROR),
   19648             :                 errmsg("invalid publication object list"),
   19649             :                 errdetail("One of TABLE or TABLES IN SCHEMA must be specified before a standalone table or schema name."),
   19650             :                 parser_errposition(pubobj->location));
   19651             : 
   19652        3356 :     foreach(cell, pubobjspec_list)
   19653             :     {
   19654        1802 :         pubobj = (PublicationObjSpec *) lfirst(cell);
   19655             : 
   19656        1802 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   19657         174 :             pubobj->pubobjtype = prevobjtype;
   19658             : 
   19659        1802 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE)
   19660             :         {
   19661             :             /* relation name or pubtable must be set for this type of object */
   19662        1398 :             if (!pubobj->name && !pubobj->pubtable)
   19663           6 :                 ereport(ERROR,
   19664             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19665             :                         errmsg("invalid table name"),
   19666             :                         parser_errposition(pubobj->location));
   19667             : 
   19668        1392 :             if (pubobj->name)
   19669             :             {
   19670             :                 /* convert it to PublicationTable */
   19671          58 :                 PublicationTable *pubtable = makeNode(PublicationTable);
   19672             : 
   19673          58 :                 pubtable->relation =
   19674          58 :                     makeRangeVar(NULL, pubobj->name, pubobj->location);
   19675          58 :                 pubobj->pubtable = pubtable;
   19676          58 :                 pubobj->name = NULL;
   19677             :             }
   19678             :         }
   19679         404 :         else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
   19680          24 :                  pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA)
   19681             :         {
   19682             :             /* WHERE clause is not allowed on a schema object */
   19683         404 :             if (pubobj->pubtable && pubobj->pubtable->whereClause)
   19684           6 :                 ereport(ERROR,
   19685             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19686             :                         errmsg("WHERE clause not allowed for schema"),
   19687             :                         parser_errposition(pubobj->location));
   19688             : 
   19689             :             /* Column list is not allowed on a schema object */
   19690         398 :             if (pubobj->pubtable && pubobj->pubtable->columns)
   19691           6 :                 ereport(ERROR,
   19692             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19693             :                         errmsg("column specification not allowed for schema"),
   19694             :                         parser_errposition(pubobj->location));
   19695             : 
   19696             :             /*
   19697             :              * We can distinguish between the different type of schema objects
   19698             :              * based on whether name and pubtable is set.
   19699             :              */
   19700         392 :             if (pubobj->name)
   19701         362 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   19702          30 :             else if (!pubobj->name && !pubobj->pubtable)
   19703          24 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   19704             :             else
   19705           6 :                 ereport(ERROR,
   19706             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19707             :                         errmsg("invalid schema name"),
   19708             :                         parser_errposition(pubobj->location));
   19709             :         }
   19710             : 
   19711        1778 :         prevobjtype = pubobj->pubobjtype;
   19712             :     }
   19713             : }
   19714             : 
   19715             : /*----------
   19716             :  * Recursive view transformation
   19717             :  *
   19718             :  * Convert
   19719             :  *
   19720             :  *     CREATE RECURSIVE VIEW relname (aliases) AS query
   19721             :  *
   19722             :  * to
   19723             :  *
   19724             :  *     CREATE VIEW relname (aliases) AS
   19725             :  *         WITH RECURSIVE relname (aliases) AS (query)
   19726             :  *         SELECT aliases FROM relname
   19727             :  *
   19728             :  * Actually, just the WITH ... part, which is then inserted into the original
   19729             :  * view definition as the query.
   19730             :  * ----------
   19731             :  */
   19732             : static Node *
   19733          14 : makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
   19734             : {
   19735          14 :     SelectStmt *s = makeNode(SelectStmt);
   19736          14 :     WithClause *w = makeNode(WithClause);
   19737          14 :     CommonTableExpr *cte = makeNode(CommonTableExpr);
   19738          14 :     List       *tl = NIL;
   19739             :     ListCell   *lc;
   19740             : 
   19741             :     /* create common table expression */
   19742          14 :     cte->ctename = relname;
   19743          14 :     cte->aliascolnames = aliases;
   19744          14 :     cte->ctematerialized = CTEMaterializeDefault;
   19745          14 :     cte->ctequery = query;
   19746          14 :     cte->location = -1;
   19747             : 
   19748             :     /* create WITH clause and attach CTE */
   19749          14 :     w->recursive = true;
   19750          14 :     w->ctes = list_make1(cte);
   19751          14 :     w->location = -1;
   19752             : 
   19753             :     /*
   19754             :      * create target list for the new SELECT from the alias list of the
   19755             :      * recursive view specification
   19756             :      */
   19757          28 :     foreach(lc, aliases)
   19758             :     {
   19759          14 :         ResTarget  *rt = makeNode(ResTarget);
   19760             : 
   19761          14 :         rt->name = NULL;
   19762          14 :         rt->indirection = NIL;
   19763          14 :         rt->val = makeColumnRef(strVal(lfirst(lc)), NIL, -1, 0);
   19764          14 :         rt->location = -1;
   19765             : 
   19766          14 :         tl = lappend(tl, rt);
   19767             :     }
   19768             : 
   19769             :     /*
   19770             :      * create new SELECT combining WITH clause, target list, and fake FROM
   19771             :      * clause
   19772             :      */
   19773          14 :     s->withClause = w;
   19774          14 :     s->targetList = tl;
   19775          14 :     s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));
   19776             : 
   19777          14 :     return (Node *) s;
   19778             : }
   19779             : 
   19780             : /* parser_init()
   19781             :  * Initialize to parse one query string
   19782             :  */
   19783             : void
   19784      790464 : parser_init(base_yy_extra_type *yyext)
   19785             : {
   19786      790464 :     yyext->parsetree = NIL;      /* in case grammar forgets to set it */
   19787      790464 : }

Generated by: LCOV version 1.16