LCOV - code coverage report
Current view: top level - src/backend/parser - gram.y (source / functions) Hit Total Coverage
Test: PostgreSQL 13beta1 Lines: 5807 6701 86.7 %
Date: 2020-05-25 05:06:35 Functions: 39 40 97.5 %
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-2020, 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 "access/tableam.h"
      52             : #include "catalog/index.h"
      53             : #include "catalog/namespace.h"
      54             : #include "catalog/pg_am.h"
      55             : #include "catalog/pg_trigger.h"
      56             : #include "commands/defrem.h"
      57             : #include "commands/trigger.h"
      58             : #include "nodes/makefuncs.h"
      59             : #include "nodes/nodeFuncs.h"
      60             : #include "parser/gramparse.h"
      61             : #include "parser/parser.h"
      62             : #include "parser/parse_expr.h"
      63             : #include "storage/lmgr.h"
      64             : #include "utils/date.h"
      65             : #include "utils/datetime.h"
      66             : #include "utils/numeric.h"
      67             : #include "utils/xml.h"
      68             : 
      69             : 
      70             : /*
      71             :  * Location tracking support --- simpler than bison's default, since we only
      72             :  * want to track the start position not the end position of each nonterminal.
      73             :  */
      74             : #define YYLLOC_DEFAULT(Current, Rhs, N) \
      75             :     do { \
      76             :         if ((N) > 0) \
      77             :             (Current) = (Rhs)[1]; \
      78             :         else \
      79             :             (Current) = (-1); \
      80             :     } while (0)
      81             : 
      82             : /*
      83             :  * The above macro assigns -1 (unknown) as the parse location of any
      84             :  * nonterminal that was reduced from an empty rule, or whose leftmost
      85             :  * component was reduced from an empty rule.  This is problematic
      86             :  * for nonterminals defined like
      87             :  *      OptFooList: / * EMPTY * / { ... } | OptFooList Foo { ... } ;
      88             :  * because we'll set -1 as the location during the first reduction and then
      89             :  * copy it during each subsequent reduction, leaving us with -1 for the
      90             :  * location even when the list is not empty.  To fix that, do this in the
      91             :  * action for the nonempty rule(s):
      92             :  *      if (@$ < 0) @$ = @2;
      93             :  * (Although we have many nonterminals that follow this pattern, we only
      94             :  * bother with fixing @$ like this when the nonterminal's parse location
      95             :  * is actually referenced in some rule.)
      96             :  *
      97             :  * A cleaner answer would be to make YYLLOC_DEFAULT scan all the Rhs
      98             :  * locations until it's found one that's not -1.  Then we'd get a correct
      99             :  * location for any nonterminal that isn't entirely empty.  But this way
     100             :  * would add overhead to every rule reduction, and so far there's not been
     101             :  * a compelling reason to pay that overhead.
     102             :  */
     103             : 
     104             : /*
     105             :  * Bison doesn't allocate anything that needs to live across parser calls,
     106             :  * so we can easily have it use palloc instead of malloc.  This prevents
     107             :  * memory leaks if we error out during parsing.  Note this only works with
     108             :  * bison >= 2.0.  However, in bison 1.875 the default is to use alloca()
     109             :  * if possible, so there's not really much problem anyhow, at least if
     110             :  * you're building with gcc.
     111             :  */
     112             : #define YYMALLOC palloc
     113             : #define YYFREE   pfree
     114             : 
     115             : /* Private struct for the result of privilege_target production */
     116             : typedef struct PrivTarget
     117             : {
     118             :     GrantTargetType targtype;
     119             :     ObjectType  objtype;
     120             :     List       *objs;
     121             : } PrivTarget;
     122             : 
     123             : /* Private struct for the result of import_qualification production */
     124             : typedef struct ImportQual
     125             : {
     126             :     ImportForeignSchemaType type;
     127             :     List       *table_names;
     128             : } ImportQual;
     129             : 
     130             : /* Private struct for the result of opt_select_limit production */
     131             : typedef struct SelectLimit
     132             : {
     133             :     Node *limitOffset;
     134             :     Node *limitCount;
     135             :     LimitOption limitOption;
     136             : } SelectLimit;
     137             : 
     138             : /* ConstraintAttributeSpec yields an integer bitmask of these flags: */
     139             : #define CAS_NOT_DEFERRABLE          0x01
     140             : #define CAS_DEFERRABLE              0x02
     141             : #define CAS_INITIALLY_IMMEDIATE     0x04
     142             : #define CAS_INITIALLY_DEFERRED      0x08
     143             : #define CAS_NOT_VALID               0x10
     144             : #define CAS_NO_INHERIT              0x20
     145             : 
     146             : 
     147             : #define parser_yyerror(msg)  scanner_yyerror(msg, yyscanner)
     148             : #define parser_errposition(pos)  scanner_errposition(pos, yyscanner)
     149             : 
     150             : static void base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner,
     151             :                          const char *msg);
     152             : static RawStmt *makeRawStmt(Node *stmt, int stmt_location);
     153             : static void updateRawStmtEnd(RawStmt *rs, int end_location);
     154             : static Node *makeColumnRef(char *colname, List *indirection,
     155             :                            int location, core_yyscan_t yyscanner);
     156             : static Node *makeTypeCast(Node *arg, TypeName *typename, int location);
     157             : static Node *makeStringConst(char *str, int location);
     158             : static Node *makeStringConstCast(char *str, int location, TypeName *typename);
     159             : static Node *makeIntConst(int val, int location);
     160             : static Node *makeFloatConst(char *str, int location);
     161             : static Node *makeBitStringConst(char *str, int location);
     162             : static Node *makeNullAConst(int location);
     163             : static Node *makeAConst(Value *v, int location);
     164             : static Node *makeBoolAConst(bool state, int location);
     165             : static RoleSpec *makeRoleSpec(RoleSpecType type, int location);
     166             : static void check_qualified_name(List *names, core_yyscan_t yyscanner);
     167             : static List *check_func_name(List *names, core_yyscan_t yyscanner);
     168             : static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
     169             : static List *extractArgTypes(List *parameters);
     170             : static List *extractAggrArgTypes(List *aggrargs);
     171             : static List *makeOrderedSetArgs(List *directargs, List *orderedargs,
     172             :                                 core_yyscan_t yyscanner);
     173             : static void insertSelectOptions(SelectStmt *stmt,
     174             :                                 List *sortClause, List *lockingClause,
     175             :                                 SelectLimit *limitClause,
     176             :                                 WithClause *withClause,
     177             :                                 core_yyscan_t yyscanner);
     178             : static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
     179             : static Node *doNegate(Node *n, int location);
     180             : static void doNegateFloat(Value *v);
     181             : static Node *makeAndExpr(Node *lexpr, Node *rexpr, int location);
     182             : static Node *makeOrExpr(Node *lexpr, Node *rexpr, int location);
     183             : static Node *makeNotExpr(Node *expr, int location);
     184             : static Node *makeAArrayExpr(List *elements, int location);
     185             : static Node *makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod,
     186             :                                   int location);
     187             : static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
     188             :                          List *args, int location);
     189             : static List *mergeTableFuncParameters(List *func_args, List *columns);
     190             : static TypeName *TableFuncTypeName(List *columns);
     191             : static RangeVar *makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner);
     192             : static void SplitColQualList(List *qualList,
     193             :                              List **constraintList, CollateClause **collClause,
     194             :                              core_yyscan_t yyscanner);
     195             : static void processCASbits(int cas_bits, int location, const char *constrType,
     196             :                bool *deferrable, bool *initdeferred, bool *not_valid,
     197             :                bool *no_inherit, core_yyscan_t yyscanner);
     198             : static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
     199             : 
     200             : %}
     201             : 
     202             : %pure-parser
     203             : %expect 0
     204             : %name-prefix="base_yy"
     205             : %locations
     206             : 
     207             : %parse-param {core_yyscan_t yyscanner}
     208             : %lex-param   {core_yyscan_t yyscanner}
     209             : 
     210             : %union
     211             : {
     212             :     core_YYSTYPE        core_yystype;
     213             :     /* these fields must match core_YYSTYPE: */
     214             :     int                 ival;
     215             :     char                *str;
     216             :     const char          *keyword;
     217             : 
     218             :     char                chr;
     219             :     bool                boolean;
     220             :     JoinType            jtype;
     221             :     DropBehavior        dbehavior;
     222             :     OnCommitAction      oncommit;
     223             :     List                *list;
     224             :     Node                *node;
     225             :     Value               *value;
     226             :     ObjectType          objtype;
     227             :     TypeName            *typnam;
     228             :     FunctionParameter   *fun_param;
     229             :     FunctionParameterMode fun_param_mode;
     230             :     ObjectWithArgs      *objwithargs;
     231             :     DefElem             *defelt;
     232             :     SortBy              *sortby;
     233             :     WindowDef           *windef;
     234             :     JoinExpr            *jexpr;
     235             :     IndexElem           *ielem;
     236             :     Alias               *alias;
     237             :     RangeVar            *range;
     238             :     IntoClause          *into;
     239             :     WithClause          *with;
     240             :     InferClause         *infer;
     241             :     OnConflictClause    *onconflict;
     242             :     A_Indices           *aind;
     243             :     ResTarget           *target;
     244             :     struct PrivTarget   *privtarget;
     245             :     AccessPriv          *accesspriv;
     246             :     struct ImportQual   *importqual;
     247             :     InsertStmt          *istmt;
     248             :     VariableSetStmt     *vsetstmt;
     249             :     PartitionElem       *partelem;
     250             :     PartitionSpec       *partspec;
     251             :     PartitionBoundSpec  *partboundspec;
     252             :     RoleSpec            *rolespec;
     253             :     struct SelectLimit  *selectlimit;
     254             : }
     255             : 
     256             : %type <node>  stmt schema_stmt
     257             :         AlterEventTrigStmt AlterCollationStmt
     258             :         AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt
     259             :         AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
     260             :         AlterObjectDependsStmt AlterObjectSchemaStmt AlterOwnerStmt
     261             :         AlterOperatorStmt AlterTypeStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
     262             :         AlterTblSpcStmt AlterExtensionStmt AlterExtensionContentsStmt AlterForeignTableStmt
     263             :         AlterCompositeTypeStmt AlterUserMappingStmt
     264             :         AlterRoleStmt AlterRoleSetStmt AlterPolicyStmt AlterStatsStmt
     265             :         AlterDefaultPrivilegesStmt DefACLAction
     266             :         AnalyzeStmt CallStmt ClosePortalStmt ClusterStmt CommentStmt
     267             :         ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
     268             :         CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt
     269             :         CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
     270             :         CreateSchemaStmt CreateSeqStmt CreateStmt CreateStatsStmt CreateTableSpaceStmt
     271             :         CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt
     272             :         CreateAssertionStmt CreateTransformStmt CreateTrigStmt CreateEventTrigStmt
     273             :         CreateUserStmt CreateUserMappingStmt CreateRoleStmt CreatePolicyStmt
     274             :         CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
     275             :         DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt
     276             :         DropCastStmt DropRoleStmt
     277             :         DropdbStmt DropTableSpaceStmt
     278             :         DropTransformStmt
     279             :         DropUserMappingStmt ExplainStmt FetchStmt
     280             :         GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
     281             :         ListenStmt LoadStmt LockStmt NotifyStmt ExplainableStmt PreparableStmt
     282             :         CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
     283             :         RemoveFuncStmt RemoveOperStmt RenameStmt RevokeStmt RevokeRoleStmt
     284             :         RuleActionStmt RuleActionStmtOrEmpty RuleStmt
     285             :         SecLabelStmt SelectStmt TransactionStmt TruncateStmt
     286             :         UnlistenStmt UpdateStmt VacuumStmt
     287             :         VariableResetStmt VariableSetStmt VariableShowStmt
     288             :         ViewStmt CheckPointStmt CreateConversionStmt
     289             :         DeallocateStmt PrepareStmt ExecuteStmt
     290             :         DropOwnedStmt ReassignOwnedStmt
     291             :         AlterTSConfigurationStmt AlterTSDictionaryStmt
     292             :         CreateMatViewStmt RefreshMatViewStmt CreateAmStmt
     293             :         CreatePublicationStmt AlterPublicationStmt
     294             :         CreateSubscriptionStmt AlterSubscriptionStmt DropSubscriptionStmt
     295             : 
     296             : %type <node>  select_no_parens select_with_parens select_clause
     297             :                 simple_select values_clause
     298             : 
     299             : %type <node>  alter_column_default opclass_item opclass_drop alter_using
     300             : %type <ival>  add_drop opt_asc_desc opt_nulls_order
     301             : 
     302             : %type <node>  alter_table_cmd alter_type_cmd opt_collate_clause
     303             :        replica_identity partition_cmd index_partition_cmd
     304             : %type <list>  alter_table_cmds alter_type_cmds
     305             : %type <list>    alter_identity_column_option_list
     306             : %type <defelt>  alter_identity_column_option
     307             : 
     308             : %type <dbehavior> opt_drop_behavior
     309             : 
     310             : %type <list>  createdb_opt_list createdb_opt_items copy_opt_list
     311             :                 transaction_mode_list
     312             :                 create_extension_opt_list alter_extension_opt_list
     313             : %type <defelt>    createdb_opt_item copy_opt_item
     314             :                 transaction_mode_item
     315             :                 create_extension_opt_item alter_extension_opt_item
     316             : 
     317             : %type <ival>  opt_lock lock_type cast_context
     318             : %type <str>       vac_analyze_option_name
     319             : %type <defelt>    vac_analyze_option_elem
     320             : %type <list>  vac_analyze_option_list
     321             : %type <node>  vac_analyze_option_arg
     322             : %type <defelt>    drop_option
     323             : %type <boolean>   opt_or_replace opt_no
     324             :                 opt_grant_grant_option opt_grant_admin_option
     325             :                 opt_nowait opt_if_exists opt_with_data
     326             :                 opt_transaction_chain
     327             : %type <ival>  opt_nowait_or_skip
     328             : 
     329             : %type <list>  OptRoleList AlterOptRoleList
     330             : %type <defelt>    CreateOptRoleElem AlterOptRoleElem
     331             : 
     332             : %type <str>       opt_type
     333             : %type <str>       foreign_server_version opt_foreign_server_version
     334             : %type <str>       opt_in_database
     335             : 
     336             : %type <str>       OptSchemaName
     337             : %type <list>  OptSchemaEltList
     338             : 
     339             : %type <chr>       am_type
     340             : 
     341             : %type <boolean> TriggerForSpec TriggerForType
     342             : %type <ival>  TriggerActionTime
     343             : %type <list>  TriggerEvents TriggerOneEvent
     344             : %type <value> TriggerFuncArg
     345             : %type <node>  TriggerWhen
     346             : %type <str>       TransitionRelName
     347             : %type <boolean>   TransitionRowOrTable TransitionOldOrNew
     348             : %type <node>  TriggerTransition
     349             : 
     350             : %type <list>  event_trigger_when_list event_trigger_value_list
     351             : %type <defelt>    event_trigger_when_item
     352             : %type <chr>       enable_trigger
     353             : 
     354             : %type <str>       copy_file_name
     355             :                 database_name access_method_clause access_method attr_name
     356             :                 table_access_method_clause name cursor_name file_name
     357             :                 index_name opt_index_name cluster_index_specification
     358             : 
     359             : %type <list>  func_name handler_name qual_Op qual_all_Op subquery_Op
     360             :                 opt_class opt_inline_handler opt_validator validator_clause
     361             :                 opt_collate
     362             : 
     363             : %type <range> qualified_name insert_target OptConstrFromTable
     364             : 
     365             : %type <str>       all_Op MathOp
     366             : 
     367             : %type <str>       row_security_cmd RowSecurityDefaultForCmd
     368             : %type <boolean> RowSecurityDefaultPermissive
     369             : %type <node>  RowSecurityOptionalWithCheck RowSecurityOptionalExpr
     370             : %type <list>  RowSecurityDefaultToRole RowSecurityOptionalToRole
     371             : 
     372             : %type <str>       iso_level opt_encoding
     373             : %type <rolespec> grantee
     374             : %type <list>  grantee_list
     375             : %type <accesspriv> privilege
     376             : %type <list>  privileges privilege_list
     377             : %type <privtarget> privilege_target
     378             : %type <objwithargs> function_with_argtypes aggregate_with_argtypes operator_with_argtypes
     379             : %type <list>  function_with_argtypes_list aggregate_with_argtypes_list operator_with_argtypes_list
     380             : %type <ival>  defacl_privilege_target
     381             : %type <defelt>    DefACLOption
     382             : %type <list>  DefACLOptionList
     383             : %type <ival>  import_qualification_type
     384             : %type <importqual> import_qualification
     385             : %type <node>  vacuum_relation
     386             : %type <selectlimit> opt_select_limit select_limit limit_clause
     387             : 
     388             : %type <list>  stmtblock stmtmulti
     389             :                 OptTableElementList TableElementList OptInherit definition
     390             :                 OptTypedTableElementList TypedTableElementList
     391             :                 reloptions opt_reloptions
     392             :                 OptWith distinct_clause opt_all_clause opt_definition func_args func_args_list
     393             :                 func_args_with_defaults func_args_with_defaults_list
     394             :                 aggr_args aggr_args_list
     395             :                 func_as createfunc_opt_list alterfunc_opt_list
     396             :                 old_aggr_definition old_aggr_list
     397             :                 oper_argtypes RuleActionList RuleActionMulti
     398             :                 opt_column_list columnList opt_name_list
     399             :                 sort_clause opt_sort_clause sortby_list index_params
     400             :                 opt_include opt_c_include index_including_params
     401             :                 name_list role_list from_clause from_list opt_array_bounds
     402             :                 qualified_name_list any_name any_name_list type_name_list
     403             :                 any_operator expr_list attrs
     404             :                 target_list opt_target_list insert_column_list set_target_list
     405             :                 set_clause_list set_clause
     406             :                 def_list operator_def_list indirection opt_indirection
     407             :                 reloption_list group_clause TriggerFuncArgs opclass_item_list opclass_drop_list
     408             :                 opclass_purpose opt_opfamily transaction_mode_list_or_empty
     409             :                 OptTableFuncElementList TableFuncElementList opt_type_modifiers
     410             :                 prep_type_clause
     411             :                 execute_param_clause using_clause returning_clause
     412             :                 opt_enum_val_list enum_val_list table_func_column_list
     413             :                 create_generic_options alter_generic_options
     414             :                 relation_expr_list dostmt_opt_list
     415             :                 transform_element_list transform_type_list
     416             :                 TriggerTransitions TriggerReferencing
     417             :                 publication_name_list
     418             :                 vacuum_relation_list opt_vacuum_relation_list
     419             :                 drop_option_list
     420             : 
     421             : %type <list>  group_by_list
     422             : %type <node>  group_by_item empty_grouping_set rollup_clause cube_clause
     423             : %type <node>  grouping_sets_clause
     424             : %type <node>  opt_publication_for_tables publication_for_tables
     425             : %type <value> publication_name_item
     426             : 
     427             : %type <list>  opt_fdw_options fdw_options
     428             : %type <defelt>    fdw_option
     429             : 
     430             : %type <range> OptTempTableName
     431             : %type <into>  into_clause create_as_target create_mv_target
     432             : 
     433             : %type <defelt>    createfunc_opt_item common_func_opt_item dostmt_opt_item
     434             : %type <fun_param> func_arg func_arg_with_default table_func_column aggr_arg
     435             : %type <fun_param_mode> arg_class
     436             : %type <typnam>    func_return func_type
     437             : 
     438             : %type <boolean>  opt_trusted opt_restart_seqs
     439             : %type <ival>   OptTemp
     440             : %type <ival>   OptNoLog
     441             : %type <oncommit> OnCommitOption
     442             : 
     443             : %type <ival>  for_locking_strength
     444             : %type <node>  for_locking_item
     445             : %type <list>  for_locking_clause opt_for_locking_clause for_locking_items
     446             : %type <list>  locked_rels_list
     447             : %type <boolean>   all_or_distinct
     448             : 
     449             : %type <node>  join_outer join_qual
     450             : %type <jtype> join_type
     451             : 
     452             : %type <list>  extract_list overlay_list position_list
     453             : %type <list>  substr_list trim_list
     454             : %type <list>  opt_interval interval_second
     455             : %type <node>  overlay_placing substr_from substr_for
     456             : %type <str>       unicode_normal_form
     457             : 
     458             : %type <boolean> opt_instead
     459             : %type <boolean> opt_unique opt_concurrently opt_verbose opt_full
     460             : %type <boolean> opt_freeze opt_analyze opt_default opt_recheck
     461             : %type <defelt>    opt_binary copy_delimiter
     462             : 
     463             : %type <boolean> copy_from opt_program
     464             : 
     465             : %type <ival>  opt_column event cursor_options opt_hold opt_set_data
     466             : %type <objtype>   drop_type_any_name drop_type_name drop_type_name_on_any_name
     467             :                 comment_type_any_name comment_type_name
     468             :                 security_label_type_any_name security_label_type_name
     469             : 
     470             : %type <node>  fetch_args select_limit_value
     471             :                 offset_clause select_offset_value
     472             :                 select_fetch_first_value I_or_F_const
     473             : %type <ival>  row_or_rows first_or_next
     474             : 
     475             : %type <list>  OptSeqOptList SeqOptList OptParenthesizedSeqOptList
     476             : %type <defelt>    SeqOptElem
     477             : 
     478             : %type <istmt> insert_rest
     479             : %type <infer> opt_conf_expr
     480             : %type <onconflict> opt_on_conflict
     481             : 
     482             : %type <vsetstmt> generic_set set_rest set_rest_more generic_reset reset_rest
     483             :                  SetResetClause FunctionSetResetClause
     484             : 
     485             : %type <node>  TableElement TypedTableElement ConstraintElem TableFuncElement
     486             : %type <node>  columnDef columnOptions
     487             : %type <defelt>    def_elem reloption_elem old_aggr_elem operator_def_elem
     488             : %type <node>  def_arg columnElem where_clause where_or_current_clause
     489             :                 a_expr b_expr c_expr AexprConst indirection_el opt_slice_bound
     490             :                 columnref in_expr having_clause func_table xmltable array_expr
     491             :                 ExclusionWhereClause operator_def_arg
     492             : %type <list>  rowsfrom_item rowsfrom_list opt_col_def_list
     493             : %type <boolean> opt_ordinality
     494             : %type <list>  ExclusionConstraintList ExclusionConstraintElem
     495             : %type <list>  func_arg_list
     496             : %type <node>  func_arg_expr
     497             : %type <list>  row explicit_row implicit_row type_list array_expr_list
     498             : %type <node>  case_expr case_arg when_clause case_default
     499             : %type <list>  when_clause_list
     500             : %type <ival>  sub_type opt_materialized
     501             : %type <value> NumericOnly
     502             : %type <list>  NumericOnly_list
     503             : %type <alias> alias_clause opt_alias_clause
     504             : %type <list>  func_alias_clause
     505             : %type <sortby>    sortby
     506             : %type <ielem> index_elem index_elem_options
     507             : %type <node>  table_ref
     508             : %type <jexpr> joined_table
     509             : %type <range> relation_expr
     510             : %type <range> relation_expr_opt_alias
     511             : %type <node>  tablesample_clause opt_repeatable_clause
     512             : %type <target>    target_el set_target insert_column_item
     513             : 
     514             : %type <str>       generic_option_name
     515             : %type <node>  generic_option_arg
     516             : %type <defelt>    generic_option_elem alter_generic_option_elem
     517             : %type <list>  generic_option_list alter_generic_option_list
     518             : %type <str>       explain_option_name
     519             : %type <node>  explain_option_arg
     520             : %type <defelt>    explain_option_elem
     521             : %type <list>  explain_option_list
     522             : 
     523             : %type <ival>  reindex_target_type reindex_target_multitable
     524             : %type <ival>  reindex_option_list reindex_option_elem
     525             : 
     526             : %type <node>  copy_generic_opt_arg copy_generic_opt_arg_list_item
     527             : %type <defelt>    copy_generic_opt_elem
     528             : %type <list>  copy_generic_opt_list copy_generic_opt_arg_list
     529             : %type <list>  copy_options
     530             : 
     531             : %type <typnam>    Typename SimpleTypename ConstTypename
     532             :                 GenericType Numeric opt_float
     533             :                 Character ConstCharacter
     534             :                 CharacterWithLength CharacterWithoutLength
     535             :                 ConstDatetime ConstInterval
     536             :                 Bit ConstBit BitWithLength BitWithoutLength
     537             : %type <str>       character
     538             : %type <str>       extract_arg
     539             : %type <boolean> opt_varying opt_timezone opt_no_inherit
     540             : 
     541             : %type <ival>  Iconst SignedIconst
     542             : %type <str>       Sconst comment_text notify_payload
     543             : %type <str>       RoleId opt_boolean_or_string
     544             : %type <list>  var_list
     545             : %type <str>       ColId ColLabel var_name type_function_name param_name
     546             : %type <str>       NonReservedWord NonReservedWord_or_Sconst
     547             : %type <str>       createdb_opt_name
     548             : %type <node>  var_value zone_value
     549             : %type <rolespec> auth_ident RoleSpec opt_granted_by
     550             : 
     551             : %type <keyword> unreserved_keyword type_func_name_keyword
     552             : %type <keyword> col_name_keyword reserved_keyword
     553             : 
     554             : %type <node>  TableConstraint TableLikeClause
     555             : %type <ival>  TableLikeOptionList TableLikeOption
     556             : %type <list>  ColQualList
     557             : %type <node>  ColConstraint ColConstraintElem ConstraintAttr
     558             : %type <ival>  key_actions key_delete key_match key_update key_action
     559             : %type <ival>  ConstraintAttributeSpec ConstraintAttributeElem
     560             : %type <str>       ExistingIndex
     561             : 
     562             : %type <list>  constraints_set_list
     563             : %type <boolean> constraints_set_mode
     564             : %type <str>       OptTableSpace OptConsTableSpace
     565             : %type <rolespec> OptTableSpaceOwner
     566             : %type <ival>  opt_check_option
     567             : 
     568             : %type <str>       opt_provider security_label
     569             : 
     570             : %type <target>    xml_attribute_el
     571             : %type <list>  xml_attribute_list xml_attributes
     572             : %type <node>  xml_root_version opt_xml_root_standalone
     573             : %type <node>  xmlexists_argument
     574             : %type <ival>  document_or_content
     575             : %type <boolean> xml_whitespace_option
     576             : %type <list>  xmltable_column_list xmltable_column_option_list
     577             : %type <node>  xmltable_column_el
     578             : %type <defelt>    xmltable_column_option_el
     579             : %type <list>  xml_namespace_list
     580             : %type <target>    xml_namespace_el
     581             : 
     582             : %type <node>  func_application func_expr_common_subexpr
     583             : %type <node>  func_expr func_expr_windowless
     584             : %type <node>  common_table_expr
     585             : %type <with>  with_clause opt_with_clause
     586             : %type <list>  cte_list
     587             : 
     588             : %type <list>  within_group_clause
     589             : %type <node>  filter_clause
     590             : %type <list>  window_clause window_definition_list opt_partition_clause
     591             : %type <windef>    window_definition over_clause window_specification
     592             :                 opt_frame_clause frame_extent frame_bound
     593             : %type <ival>  opt_window_exclusion_clause
     594             : %type <str>       opt_existing_window_name
     595             : %type <boolean> opt_if_not_exists
     596             : %type <ival>  generated_when override_kind
     597             : %type <partspec>  PartitionSpec OptPartitionSpec
     598             : %type <partelem>  part_elem
     599             : %type <list>      part_params
     600             : %type <partboundspec> PartitionBoundSpec
     601             : %type <list>      hash_partbound
     602             : %type <defelt>        hash_partbound_elem
     603             : 
     604             : /*
     605             :  * Non-keyword token types.  These are hard-wired into the "flex" lexer.
     606             :  * They must be listed first so that their numeric codes do not depend on
     607             :  * the set of keywords.  PL/pgSQL depends on this so that it can share the
     608             :  * same lexer.  If you add/change tokens here, fix PL/pgSQL to match!
     609             :  *
     610             :  * UIDENT and USCONST are reduced to IDENT and SCONST in parser.c, so that
     611             :  * they need no productions here; but we must assign token codes to them.
     612             :  *
     613             :  * DOT_DOT is unused in the core SQL grammar, and so will always provoke
     614             :  * parse errors.  It is needed by PL/pgSQL.
     615             :  */
     616             : %token <str>  IDENT UIDENT FCONST SCONST USCONST BCONST XCONST Op
     617             : %token <ival> ICONST PARAM
     618             : %token          TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
     619             : %token          LESS_EQUALS GREATER_EQUALS NOT_EQUALS
     620             : 
     621             : /*
     622             :  * If you want to make any keyword changes, update the keyword table in
     623             :  * src/include/parser/kwlist.h and add new keywords to the appropriate one
     624             :  * of the reserved-or-not-so-reserved keyword lists, below; search
     625             :  * this file for "Keyword category lists".
     626             :  */
     627             : 
     628             : /* ordinary key words in alphabetical order */
     629             : %token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
     630             :     AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
     631             :     ASSERTION ASSIGNMENT ASYMMETRIC AT ATTACH ATTRIBUTE AUTHORIZATION
     632             : 
     633             :     BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
     634             :     BOOLEAN_P BOTH BY
     635             : 
     636             :     CACHE CALL CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
     637             :     CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
     638             :     CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
     639             :     COMMITTED CONCURRENTLY CONFIGURATION CONFLICT CONNECTION CONSTRAINT
     640             :     CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE
     641             :     CROSS CSV CUBE CURRENT_P
     642             :     CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
     643             :     CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
     644             : 
     645             :     DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
     646             :     DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DEPENDS DESC
     647             :     DETACH DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P
     648             :     DOUBLE_P DROP
     649             : 
     650             :     EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EVENT EXCEPT
     651             :     EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN EXPRESSION
     652             :     EXTENSION EXTERNAL EXTRACT
     653             : 
     654             :     FALSE_P FAMILY FETCH FILTER FIRST_P FLOAT_P FOLLOWING FOR
     655             :     FORCE FOREIGN FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
     656             : 
     657             :     GENERATED GLOBAL GRANT GRANTED GREATEST GROUP_P GROUPING GROUPS
     658             : 
     659             :     HANDLER HAVING HEADER_P HOLD HOUR_P
     660             : 
     661             :     IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P INCLUDE
     662             :     INCLUDING INCREMENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
     663             :     INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
     664             :     INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
     665             : 
     666             :     JOIN
     667             : 
     668             :     KEY
     669             : 
     670             :     LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
     671             :     LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
     672             :     LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED
     673             : 
     674             :     MAPPING MATCH MATERIALIZED MAXVALUE METHOD MINUTE_P MINVALUE MODE MONTH_P MOVE
     675             : 
     676             :     NAME_P NAMES NATIONAL NATURAL NCHAR NEW NEXT NFC NFD NFKC NFKD NO NONE
     677             :     NORMALIZE NORMALIZED
     678             :     NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
     679             :     NULLS_P NUMERIC
     680             : 
     681             :     OBJECT_P OF OFF OFFSET OIDS OLD ON ONLY OPERATOR OPTION OPTIONS OR
     682             :     ORDER ORDINALITY OTHERS OUT_P OUTER_P
     683             :     OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
     684             : 
     685             :     PARALLEL PARSER PARTIAL PARTITION PASSING PASSWORD PLACING PLANS POLICY
     686             :     POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
     687             :     PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PUBLICATION
     688             : 
     689             :     QUOTE
     690             : 
     691             :     RANGE READ REAL REASSIGN RECHECK RECURSIVE REF REFERENCES REFERENCING
     692             :     REFRESH REINDEX RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
     693             :     RESET RESTART RESTRICT RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
     694             :     ROUTINE ROUTINES ROW ROWS RULE
     695             : 
     696             :     SAVEPOINT SCHEMA SCHEMAS SCROLL SEARCH SECOND_P SECURITY SELECT SEQUENCE SEQUENCES
     697             :     SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
     698             :     SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SQL_P STABLE STANDALONE_P
     699             :     START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRIP_P
     700             :     SUBSCRIPTION SUBSTRING SUPPORT SYMMETRIC SYSID SYSTEM_P
     701             : 
     702             :     TABLE TABLES TABLESAMPLE TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN
     703             :     TIES TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM
     704             :     TREAT TRIGGER TRIM TRUE_P
     705             :     TRUNCATE TRUSTED TYPE_P TYPES_P
     706             : 
     707             :     UESCAPE UNBOUNDED UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
     708             :     UNLISTEN UNLOGGED UNTIL UPDATE USER USING
     709             : 
     710             :     VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
     711             :     VERBOSE VERSION_P VIEW VIEWS VOLATILE
     712             : 
     713             :     WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
     714             : 
     715             :     XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLNAMESPACES
     716             :     XMLPARSE XMLPI XMLROOT XMLSERIALIZE XMLTABLE
     717             : 
     718             :     YEAR_P YES_P
     719             : 
     720             :     ZONE
     721             : 
     722             : /*
     723             :  * The grammar thinks these are keywords, but they are not in the kwlist.h
     724             :  * list and so can never be entered directly.  The filter in parser.c
     725             :  * creates these tokens when required (based on looking one token ahead).
     726             :  *
     727             :  * NOT_LA exists so that productions such as NOT LIKE can be given the same
     728             :  * precedence as LIKE; otherwise they'd effectively have the same precedence
     729             :  * as NOT, at least with respect to their left-hand subexpression.
     730             :  * NULLS_LA and WITH_LA are needed to make the grammar LALR(1).
     731             :  */
     732             : %token      NOT_LA NULLS_LA WITH_LA
     733             : 
     734             : 
     735             : /* Precedence: lowest to highest */
     736             : %nonassoc   SET             /* see relation_expr_opt_alias */
     737             : %left       UNION EXCEPT
     738             : %left       INTERSECT
     739             : %left       OR
     740             : %left       AND
     741             : %right      NOT
     742             : %nonassoc   IS ISNULL NOTNULL   /* IS sets precedence for IS NULL, etc */
     743             : %nonassoc   '<' '>' '=' LESS_EQUALS GREATER_EQUALS NOT_EQUALS
     744             : %nonassoc   BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
     745             : %nonassoc   ESCAPE          /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
     746             : %left       POSTFIXOP       /* dummy for postfix Op rules */
     747             : /*
     748             :  * To support target_el without AS, we must give IDENT an explicit priority
     749             :  * between POSTFIXOP and Op.  We can safely assign the same priority to
     750             :  * various unreserved keywords as needed to resolve ambiguities (this can't
     751             :  * have any bad effects since obviously the keywords will still behave the
     752             :  * same as if they weren't keywords).  We need to do this:
     753             :  * for PARTITION, RANGE, ROWS, GROUPS to support opt_existing_window_name;
     754             :  * for RANGE, ROWS, GROUPS so that they can follow a_expr without creating
     755             :  * postfix-operator problems;
     756             :  * for GENERATED so that it can follow b_expr;
     757             :  * and for NULL so that it can follow b_expr in ColQualList without creating
     758             :  * postfix-operator problems.
     759             :  *
     760             :  * To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
     761             :  * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
     762             :  * rather than reducing a conflicting rule that takes CUBE as a function name.
     763             :  * Using the same precedence as IDENT seems right for the reasons given above.
     764             :  *
     765             :  * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
     766             :  * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
     767             :  * there is no principled way to distinguish these from the productions
     768             :  * a_expr PRECEDING/FOLLOWING.  We hack this up by giving UNBOUNDED slightly
     769             :  * lower precedence than PRECEDING and FOLLOWING.  At present this doesn't
     770             :  * appear to cause UNBOUNDED to be treated differently from other unreserved
     771             :  * keywords anywhere else in the grammar, but it's definitely risky.  We can
     772             :  * blame any funny behavior of UNBOUNDED on the SQL standard, though.
     773             :  */
     774             : %nonassoc   UNBOUNDED       /* ideally should have same precedence as IDENT */
     775             : %nonassoc   IDENT GENERATED NULL_P PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
     776             : %left       Op OPERATOR     /* multi-character ops and user-defined operators */
     777             : %left       '+' '-'
     778             : %left       '*' '/' '%'
     779             : %left       '^'
     780             : /* Unary Operators */
     781             : %left       AT              /* sets precedence for AT TIME ZONE */
     782             : %left       COLLATE
     783             : %right      UMINUS
     784             : %left       '[' ']'
     785             : %left       '(' ')'
     786             : %left       TYPECAST
     787             : %left       '.'
     788             : /*
     789             :  * These might seem to be low-precedence, but actually they are not part
     790             :  * of the arithmetic hierarchy at all in their use as JOIN operators.
     791             :  * We make them high-precedence to support their use as function names.
     792             :  * They wouldn't be given a precedence at all, were it not that we need
     793             :  * left-associativity among the JOIN rules themselves.
     794             :  */
     795             : %left       JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
     796             : /* kluge to keep xml_whitespace_option from causing shift/reduce conflicts */
     797             : %right      PRESERVE STRIP_P
     798             : 
     799             : %%
     800             : 
     801             : /*
     802             :  *  The target production for the whole parse.
     803             :  */
     804             : stmtblock:  stmtmulti
     805             :             {
     806      534974 :                 pg_yyget_extra(yyscanner)->parsetree = $1;
     807             :             }
     808             :         ;
     809             : 
     810             : /*
     811             :  * At top level, we wrap each stmt with a RawStmt node carrying start location
     812             :  * and length of the stmt's text.  Notice that the start loc/len are driven
     813             :  * entirely from semicolon locations (@2).  It would seem natural to use
     814             :  * @1 or @3 to get the true start location of a stmt, but that doesn't work
     815             :  * for statements that can start with empty nonterminals (opt_with_clause is
     816             :  * the main offender here); as noted in the comments for YYLLOC_DEFAULT,
     817             :  * we'd get -1 for the location in such cases.
     818             :  * We also take care to discard empty statements entirely.
     819             :  */
     820             : stmtmulti:  stmtmulti ';' stmt
     821             :                 {
     822      462536 :                     if ($1 != NIL)
     823             :                     {
     824             :                         /* update length of previous stmt */
     825      462240 :                         updateRawStmtEnd(llast_node(RawStmt, $1), @2);
     826             :                     }
     827      462536 :                     if ($3 != NULL)
     828       68704 :                         $$ = lappend($1, makeRawStmt($3, @2 + 1));
     829             :                     else
     830      393832 :                         $$ = $1;
     831             :                 }
     832             :             | stmt
     833             :                 {
     834      534974 :                     if ($1 != NULL)
     835      534456 :                         $$ = list_make1(makeRawStmt($1, 0));
     836             :                     else
     837         518 :                         $$ = NIL;
     838             :                 }
     839             :         ;
     840             : 
     841             : stmt :
     842             :             AlterEventTrigStmt
     843             :             | AlterCollationStmt
     844             :             | AlterDatabaseStmt
     845             :             | AlterDatabaseSetStmt
     846             :             | AlterDefaultPrivilegesStmt
     847             :             | AlterDomainStmt
     848             :             | AlterEnumStmt
     849             :             | AlterExtensionStmt
     850             :             | AlterExtensionContentsStmt
     851             :             | AlterFdwStmt
     852             :             | AlterForeignServerStmt
     853             :             | AlterForeignTableStmt
     854             :             | AlterFunctionStmt
     855             :             | AlterGroupStmt
     856             :             | AlterObjectDependsStmt
     857             :             | AlterObjectSchemaStmt
     858             :             | AlterOwnerStmt
     859             :             | AlterOperatorStmt
     860             :             | AlterTypeStmt
     861             :             | AlterPolicyStmt
     862             :             | AlterSeqStmt
     863             :             | AlterSystemStmt
     864             :             | AlterTableStmt
     865             :             | AlterTblSpcStmt
     866             :             | AlterCompositeTypeStmt
     867             :             | AlterPublicationStmt
     868             :             | AlterRoleSetStmt
     869             :             | AlterRoleStmt
     870             :             | AlterSubscriptionStmt
     871             :             | AlterStatsStmt
     872             :             | AlterTSConfigurationStmt
     873             :             | AlterTSDictionaryStmt
     874             :             | AlterUserMappingStmt
     875             :             | AnalyzeStmt
     876             :             | CallStmt
     877             :             | CheckPointStmt
     878             :             | ClosePortalStmt
     879             :             | ClusterStmt
     880             :             | CommentStmt
     881             :             | ConstraintsSetStmt
     882             :             | CopyStmt
     883             :             | CreateAmStmt
     884             :             | CreateAsStmt
     885             :             | CreateAssertionStmt
     886             :             | CreateCastStmt
     887             :             | CreateConversionStmt
     888             :             | CreateDomainStmt
     889             :             | CreateExtensionStmt
     890             :             | CreateFdwStmt
     891             :             | CreateForeignServerStmt
     892             :             | CreateForeignTableStmt
     893             :             | CreateFunctionStmt
     894             :             | CreateGroupStmt
     895             :             | CreateMatViewStmt
     896             :             | CreateOpClassStmt
     897             :             | CreateOpFamilyStmt
     898             :             | CreatePublicationStmt
     899             :             | AlterOpFamilyStmt
     900             :             | CreatePolicyStmt
     901             :             | CreatePLangStmt
     902             :             | CreateSchemaStmt
     903             :             | CreateSeqStmt
     904             :             | CreateStmt
     905             :             | CreateSubscriptionStmt
     906             :             | CreateStatsStmt
     907             :             | CreateTableSpaceStmt
     908             :             | CreateTransformStmt
     909             :             | CreateTrigStmt
     910             :             | CreateEventTrigStmt
     911             :             | CreateRoleStmt
     912             :             | CreateUserStmt
     913             :             | CreateUserMappingStmt
     914             :             | CreatedbStmt
     915             :             | DeallocateStmt
     916             :             | DeclareCursorStmt
     917             :             | DefineStmt
     918             :             | DeleteStmt
     919             :             | DiscardStmt
     920             :             | DoStmt
     921             :             | DropCastStmt
     922             :             | DropOpClassStmt
     923             :             | DropOpFamilyStmt
     924             :             | DropOwnedStmt
     925             :             | DropPLangStmt
     926             :             | DropStmt
     927             :             | DropSubscriptionStmt
     928             :             | DropTableSpaceStmt
     929             :             | DropTransformStmt
     930             :             | DropRoleStmt
     931             :             | DropUserMappingStmt
     932             :             | DropdbStmt
     933             :             | ExecuteStmt
     934             :             | ExplainStmt
     935             :             | FetchStmt
     936             :             | GrantStmt
     937             :             | GrantRoleStmt
     938             :             | ImportForeignSchemaStmt
     939             :             | IndexStmt
     940             :             | InsertStmt
     941             :             | ListenStmt
     942             :             | RefreshMatViewStmt
     943             :             | LoadStmt
     944             :             | LockStmt
     945             :             | NotifyStmt
     946             :             | PrepareStmt
     947             :             | ReassignOwnedStmt
     948             :             | ReindexStmt
     949             :             | RemoveAggrStmt
     950             :             | RemoveFuncStmt
     951             :             | RemoveOperStmt
     952             :             | RenameStmt
     953             :             | RevokeStmt
     954             :             | RevokeRoleStmt
     955             :             | RuleStmt
     956             :             | SecLabelStmt
     957             :             | SelectStmt
     958             :             | TransactionStmt
     959             :             | TruncateStmt
     960             :             | UnlistenStmt
     961             :             | UpdateStmt
     962             :             | VacuumStmt
     963             :             | VariableResetStmt
     964             :             | VariableSetStmt
     965             :             | VariableShowStmt
     966             :             | ViewStmt
     967             :             | /*EMPTY*/
     968      394350 :                 { $$ = NULL; }
     969             :         ;
     970             : 
     971             : /*****************************************************************************
     972             :  *
     973             :  * CALL statement
     974             :  *
     975             :  *****************************************************************************/
     976             : 
     977             : CallStmt:   CALL func_application
     978             :                 {
     979         308 :                     CallStmt *n = makeNode(CallStmt);
     980         308 :                     n->funccall = castNode(FuncCall, $2);
     981         308 :                     $$ = (Node *)n;
     982             :                 }
     983             :         ;
     984             : 
     985             : /*****************************************************************************
     986             :  *
     987             :  * Create a new Postgres DBMS role
     988             :  *
     989             :  *****************************************************************************/
     990             : 
     991             : CreateRoleStmt:
     992             :             CREATE ROLE RoleId opt_with OptRoleList
     993             :                 {
     994         510 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
     995         510 :                     n->stmt_type = ROLESTMT_ROLE;
     996         510 :                     n->role = $3;
     997         510 :                     n->options = $5;
     998         510 :                     $$ = (Node *)n;
     999             :                 }
    1000             :         ;
    1001             : 
    1002             : 
    1003             : opt_with:   WITH                                    {}
    1004             :             | WITH_LA                               {}
    1005             :             | /*EMPTY*/                             {}
    1006             :         ;
    1007             : 
    1008             : /*
    1009             :  * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
    1010             :  * for backwards compatibility).  Note: the only option required by SQL99
    1011             :  * is "WITH ADMIN name".
    1012             :  */
    1013             : OptRoleList:
    1014         414 :             OptRoleList CreateOptRoleElem           { $$ = lappend($1, $2); }
    1015         742 :             | /* EMPTY */                           { $$ = NIL; }
    1016             :         ;
    1017             : 
    1018             : AlterOptRoleList:
    1019         338 :             AlterOptRoleList AlterOptRoleElem       { $$ = lappend($1, $2); }
    1020         206 :             | /* EMPTY */                           { $$ = NIL; }
    1021             :         ;
    1022             : 
    1023             : AlterOptRoleElem:
    1024             :             PASSWORD Sconst
    1025             :                 {
    1026         100 :                     $$ = makeDefElem("password",
    1027         100 :                                      (Node *)makeString($2), @1);
    1028             :                 }
    1029             :             | PASSWORD NULL_P
    1030             :                 {
    1031           4 :                     $$ = makeDefElem("password", NULL, @1);
    1032             :                 }
    1033             :             | ENCRYPTED PASSWORD Sconst
    1034             :                 {
    1035             :                     /*
    1036             :                      * These days, passwords are always stored in encrypted
    1037             :                      * form, so there is no difference between PASSWORD and
    1038             :                      * ENCRYPTED PASSWORD.
    1039             :                      */
    1040          10 :                     $$ = makeDefElem("password",
    1041          10 :                                      (Node *)makeString($3), @1);
    1042             :                 }
    1043             :             | UNENCRYPTED PASSWORD Sconst
    1044             :                 {
    1045           0 :                     ereport(ERROR,
    1046             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1047             :                              errmsg("UNENCRYPTED PASSWORD is no longer supported"),
    1048             :                              errhint("Remove UNENCRYPTED to store the password in encrypted form instead."),
    1049             :                              parser_errposition(@1)));
    1050             :                 }
    1051             :             | INHERIT
    1052             :                 {
    1053          48 :                     $$ = makeDefElem("inherit", (Node *)makeInteger(true), @1);
    1054             :                 }
    1055             :             | CONNECTION LIMIT SignedIconst
    1056             :                 {
    1057           0 :                     $$ = makeDefElem("connectionlimit", (Node *)makeInteger($3), @1);
    1058             :                 }
    1059             :             | VALID UNTIL Sconst
    1060             :                 {
    1061           0 :                     $$ = makeDefElem("validUntil", (Node *)makeString($3), @1);
    1062             :                 }
    1063             :         /*  Supported but not documented for roles, for use by ALTER GROUP. */
    1064             :             | USER role_list
    1065             :                 {
    1066           4 :                     $$ = makeDefElem("rolemembers", (Node *)$2, @1);
    1067             :                 }
    1068             :             | IDENT
    1069             :                 {
    1070             :                     /*
    1071             :                      * We handle identifiers that aren't parser keywords with
    1072             :                      * the following special-case codes, to avoid bloating the
    1073             :                      * size of the main parser.
    1074             :                      */
    1075         580 :                     if (strcmp($1, "superuser") == 0)
    1076          90 :                         $$ = makeDefElem("superuser", (Node *)makeInteger(true), @1);
    1077         490 :                     else if (strcmp($1, "nosuperuser") == 0)
    1078          30 :                         $$ = makeDefElem("superuser", (Node *)makeInteger(false), @1);
    1079         460 :                     else if (strcmp($1, "createrole") == 0)
    1080          52 :                         $$ = makeDefElem("createrole", (Node *)makeInteger(true), @1);
    1081         408 :                     else if (strcmp($1, "nocreaterole") == 0)
    1082          14 :                         $$ = makeDefElem("createrole", (Node *)makeInteger(false), @1);
    1083         394 :                     else if (strcmp($1, "replication") == 0)
    1084          50 :                         $$ = makeDefElem("isreplication", (Node *)makeInteger(true), @1);
    1085         344 :                     else if (strcmp($1, "noreplication") == 0)
    1086          44 :                         $$ = makeDefElem("isreplication", (Node *)makeInteger(false), @1);
    1087         300 :                     else if (strcmp($1, "createdb") == 0)
    1088          44 :                         $$ = makeDefElem("createdb", (Node *)makeInteger(true), @1);
    1089         256 :                     else if (strcmp($1, "nocreatedb") == 0)
    1090          16 :                         $$ = makeDefElem("createdb", (Node *)makeInteger(false), @1);
    1091         240 :                     else if (strcmp($1, "login") == 0)
    1092         146 :                         $$ = makeDefElem("canlogin", (Node *)makeInteger(true), @1);
    1093          94 :                     else if (strcmp($1, "nologin") == 0)
    1094          48 :                         $$ = makeDefElem("canlogin", (Node *)makeInteger(false), @1);
    1095          46 :                     else if (strcmp($1, "bypassrls") == 0)
    1096          18 :                         $$ = makeDefElem("bypassrls", (Node *)makeInteger(true), @1);
    1097          28 :                     else if (strcmp($1, "nobypassrls") == 0)
    1098          20 :                         $$ = makeDefElem("bypassrls", (Node *)makeInteger(false), @1);
    1099           8 :                     else if (strcmp($1, "noinherit") == 0)
    1100             :                     {
    1101             :                         /*
    1102             :                          * Note that INHERIT is a keyword, so it's handled by main parser, but
    1103             :                          * NOINHERIT is handled here.
    1104             :                          */
    1105           8 :                         $$ = makeDefElem("inherit", (Node *)makeInteger(false), @1);
    1106             :                     }
    1107             :                     else
    1108           0 :                         ereport(ERROR,
    1109             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    1110             :                                  errmsg("unrecognized role option \"%s\"", $1),
    1111             :                                      parser_errposition(@1)));
    1112             :                 }
    1113             :         ;
    1114             : 
    1115             : CreateOptRoleElem:
    1116         408 :             AlterOptRoleElem            { $$ = $1; }
    1117             :             /* The following are not supported by ALTER ROLE/USER/GROUP */
    1118             :             | SYSID Iconst
    1119             :                 {
    1120           0 :                     $$ = makeDefElem("sysid", (Node *)makeInteger($2), @1);
    1121             :                 }
    1122             :             | ADMIN role_list
    1123             :                 {
    1124           0 :                     $$ = makeDefElem("adminmembers", (Node *)$2, @1);
    1125             :                 }
    1126             :             | ROLE role_list
    1127             :                 {
    1128           0 :                     $$ = makeDefElem("rolemembers", (Node *)$2, @1);
    1129             :                 }
    1130             :             | IN_P ROLE role_list
    1131             :                 {
    1132           6 :                     $$ = makeDefElem("addroleto", (Node *)$3, @1);
    1133             :                 }
    1134             :             | IN_P GROUP_P role_list
    1135             :                 {
    1136           0 :                     $$ = makeDefElem("addroleto", (Node *)$3, @1);
    1137             :                 }
    1138             :         ;
    1139             : 
    1140             : 
    1141             : /*****************************************************************************
    1142             :  *
    1143             :  * Create a new Postgres DBMS user (role with implied login ability)
    1144             :  *
    1145             :  *****************************************************************************/
    1146             : 
    1147             : CreateUserStmt:
    1148             :             CREATE USER RoleId opt_with OptRoleList
    1149             :                 {
    1150         216 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1151         216 :                     n->stmt_type = ROLESTMT_USER;
    1152         216 :                     n->role = $3;
    1153         216 :                     n->options = $5;
    1154         216 :                     $$ = (Node *)n;
    1155             :                 }
    1156             :         ;
    1157             : 
    1158             : 
    1159             : /*****************************************************************************
    1160             :  *
    1161             :  * Alter a postgresql DBMS role
    1162             :  *
    1163             :  *****************************************************************************/
    1164             : 
    1165             : AlterRoleStmt:
    1166             :             ALTER ROLE RoleSpec opt_with AlterOptRoleList
    1167             :                  {
    1168         138 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1169         138 :                     n->role = $3;
    1170         138 :                     n->action = +1;  /* add, if there are members */
    1171         138 :                     n->options = $5;
    1172         138 :                     $$ = (Node *)n;
    1173             :                  }
    1174             :             | ALTER USER RoleSpec opt_with AlterOptRoleList
    1175             :                  {
    1176          68 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1177          68 :                     n->role = $3;
    1178          68 :                     n->action = +1;  /* add, if there are members */
    1179          68 :                     n->options = $5;
    1180          68 :                     $$ = (Node *)n;
    1181             :                  }
    1182             :         ;
    1183             : 
    1184             : opt_in_database:
    1185          62 :                /* EMPTY */                  { $$ = NULL; }
    1186           0 :             | IN_P DATABASE database_name   { $$ = $3; }
    1187             :         ;
    1188             : 
    1189             : AlterRoleSetStmt:
    1190             :             ALTER ROLE RoleSpec opt_in_database SetResetClause
    1191             :                 {
    1192          26 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1193          26 :                     n->role = $3;
    1194          26 :                     n->database = $4;
    1195          26 :                     n->setstmt = $5;
    1196          26 :                     $$ = (Node *)n;
    1197             :                 }
    1198             :             | ALTER ROLE ALL opt_in_database SetResetClause
    1199             :                 {
    1200           4 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1201           4 :                     n->role = NULL;
    1202           4 :                     n->database = $4;
    1203           4 :                     n->setstmt = $5;
    1204           4 :                     $$ = (Node *)n;
    1205             :                 }
    1206             :             | ALTER USER RoleSpec opt_in_database SetResetClause
    1207             :                 {
    1208          24 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1209          24 :                     n->role = $3;
    1210          24 :                     n->database = $4;
    1211          24 :                     n->setstmt = $5;
    1212          24 :                     $$ = (Node *)n;
    1213             :                 }
    1214             :             | ALTER USER ALL opt_in_database SetResetClause
    1215             :                 {
    1216           4 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1217           4 :                     n->role = NULL;
    1218           4 :                     n->database = $4;
    1219           4 :                     n->setstmt = $5;
    1220           4 :                     $$ = (Node *)n;
    1221             :                 }
    1222             :         ;
    1223             : 
    1224             : 
    1225             : /*****************************************************************************
    1226             :  *
    1227             :  * Drop a postgresql DBMS role
    1228             :  *
    1229             :  * XXX Ideally this would have CASCADE/RESTRICT options, but a role
    1230             :  * might own objects in multiple databases, and there is presently no way to
    1231             :  * implement cascading to other databases.  So we always behave as RESTRICT.
    1232             :  *****************************************************************************/
    1233             : 
    1234             : DropRoleStmt:
    1235             :             DROP ROLE role_list
    1236             :                 {
    1237         394 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1238         394 :                     n->missing_ok = false;
    1239         394 :                     n->roles = $3;
    1240         394 :                     $$ = (Node *)n;
    1241             :                 }
    1242             :             | DROP ROLE IF_P EXISTS role_list
    1243             :                 {
    1244          86 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1245          86 :                     n->missing_ok = true;
    1246          86 :                     n->roles = $5;
    1247          86 :                     $$ = (Node *)n;
    1248             :                 }
    1249             :             | DROP USER role_list
    1250             :                 {
    1251         220 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1252         220 :                     n->missing_ok = false;
    1253         220 :                     n->roles = $3;
    1254         220 :                     $$ = (Node *)n;
    1255             :                 }
    1256             :             | DROP USER IF_P EXISTS role_list
    1257             :                 {
    1258          24 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1259          24 :                     n->roles = $5;
    1260          24 :                     n->missing_ok = true;
    1261          24 :                     $$ = (Node *)n;
    1262             :                 }
    1263             :             | DROP GROUP_P role_list
    1264             :                 {
    1265          24 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1266          24 :                     n->missing_ok = false;
    1267          24 :                     n->roles = $3;
    1268          24 :                     $$ = (Node *)n;
    1269             :                 }
    1270             :             | DROP GROUP_P IF_P EXISTS role_list
    1271             :                 {
    1272           4 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1273           4 :                     n->missing_ok = true;
    1274           4 :                     n->roles = $5;
    1275           4 :                     $$ = (Node *)n;
    1276             :                 }
    1277             :             ;
    1278             : 
    1279             : 
    1280             : /*****************************************************************************
    1281             :  *
    1282             :  * Create a postgresql group (role without login ability)
    1283             :  *
    1284             :  *****************************************************************************/
    1285             : 
    1286             : CreateGroupStmt:
    1287             :             CREATE GROUP_P RoleId opt_with OptRoleList
    1288             :                 {
    1289          16 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1290          16 :                     n->stmt_type = ROLESTMT_GROUP;
    1291          16 :                     n->role = $3;
    1292          16 :                     n->options = $5;
    1293          16 :                     $$ = (Node *)n;
    1294             :                 }
    1295             :         ;
    1296             : 
    1297             : 
    1298             : /*****************************************************************************
    1299             :  *
    1300             :  * Alter a postgresql group
    1301             :  *
    1302             :  *****************************************************************************/
    1303             : 
    1304             : AlterGroupStmt:
    1305             :             ALTER GROUP_P RoleSpec add_drop USER role_list
    1306             :                 {
    1307          12 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1308          12 :                     n->role = $3;
    1309          12 :                     n->action = $4;
    1310          12 :                     n->options = list_make1(makeDefElem("rolemembers",
    1311             :                                                         (Node *)$6, @6));
    1312          12 :                     $$ = (Node *)n;
    1313             :                 }
    1314             :         ;
    1315             : 
    1316          64 : add_drop:   ADD_P                                   { $$ = +1; }
    1317          76 :             | DROP                                  { $$ = -1; }
    1318             :         ;
    1319             : 
    1320             : 
    1321             : /*****************************************************************************
    1322             :  *
    1323             :  * Manipulate a schema
    1324             :  *
    1325             :  *****************************************************************************/
    1326             : 
    1327             : CreateSchemaStmt:
    1328             :             CREATE SCHEMA OptSchemaName AUTHORIZATION RoleSpec OptSchemaEltList
    1329             :                 {
    1330          30 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1331             :                     /* One can omit the schema name or the authorization id. */
    1332          30 :                     n->schemaname = $3;
    1333          30 :                     n->authrole = $5;
    1334          30 :                     n->schemaElts = $6;
    1335          30 :                     n->if_not_exists = false;
    1336          30 :                     $$ = (Node *)n;
    1337             :                 }
    1338             :             | CREATE SCHEMA ColId OptSchemaEltList
    1339             :                 {
    1340         660 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1341             :                     /* ...but not both */
    1342         660 :                     n->schemaname = $3;
    1343         660 :                     n->authrole = NULL;
    1344         660 :                     n->schemaElts = $4;
    1345         660 :                     n->if_not_exists = false;
    1346         660 :                     $$ = (Node *)n;
    1347             :                 }
    1348             :             | CREATE SCHEMA IF_P NOT EXISTS OptSchemaName AUTHORIZATION RoleSpec OptSchemaEltList
    1349             :                 {
    1350          16 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1351             :                     /* schema name can be omitted here, too */
    1352          16 :                     n->schemaname = $6;
    1353          16 :                     n->authrole = $8;
    1354          16 :                     if ($9 != NIL)
    1355           0 :                         ereport(ERROR,
    1356             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1357             :                                  errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
    1358             :                                  parser_errposition(@9)));
    1359          16 :                     n->schemaElts = $9;
    1360          16 :                     n->if_not_exists = true;
    1361          16 :                     $$ = (Node *)n;
    1362             :                 }
    1363             :             | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
    1364             :                 {
    1365          12 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1366             :                     /* ...but not here */
    1367          12 :                     n->schemaname = $6;
    1368          12 :                     n->authrole = NULL;
    1369          12 :                     if ($7 != NIL)
    1370           4 :                         ereport(ERROR,
    1371             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1372             :                                  errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
    1373             :                                  parser_errposition(@7)));
    1374           8 :                     n->schemaElts = $7;
    1375           8 :                     n->if_not_exists = true;
    1376           8 :                     $$ = (Node *)n;
    1377             :                 }
    1378             :         ;
    1379             : 
    1380             : OptSchemaName:
    1381          58 :             ColId                                   { $$ = $1; }
    1382           0 :             | /* EMPTY */                           { $$ = NULL; }
    1383             :         ;
    1384             : 
    1385             : OptSchemaEltList:
    1386             :             OptSchemaEltList schema_stmt
    1387             :                 {
    1388         164 :                     if (@$ < 0)          /* see comments for YYLLOC_DEFAULT */
    1389          60 :                         @$ = @2;
    1390         164 :                     $$ = lappend($1, $2);
    1391             :                 }
    1392             :             | /* EMPTY */
    1393         718 :                 { $$ = NIL; }
    1394             :         ;
    1395             : 
    1396             : /*
    1397             :  *  schema_stmt are the ones that can show up inside a CREATE SCHEMA
    1398             :  *  statement (in addition to by themselves).
    1399             :  */
    1400             : schema_stmt:
    1401             :             CreateStmt
    1402             :             | IndexStmt
    1403             :             | CreateSeqStmt
    1404             :             | CreateTrigStmt
    1405             :             | GrantStmt
    1406             :             | ViewStmt
    1407             :         ;
    1408             : 
    1409             : 
    1410             : /*****************************************************************************
    1411             :  *
    1412             :  * Set PG internal variable
    1413             :  *    SET name TO 'var_value'
    1414             :  * Include SQL syntax (thomas 1997-10-22):
    1415             :  *    SET TIME ZONE 'var_value'
    1416             :  *
    1417             :  *****************************************************************************/
    1418             : 
    1419             : VariableSetStmt:
    1420             :             SET set_rest
    1421             :                 {
    1422       10032 :                     VariableSetStmt *n = $2;
    1423       10032 :                     n->is_local = false;
    1424       10032 :                     $$ = (Node *) n;
    1425             :                 }
    1426             :             | SET LOCAL set_rest
    1427             :                 {
    1428         510 :                     VariableSetStmt *n = $3;
    1429         510 :                     n->is_local = true;
    1430         510 :                     $$ = (Node *) n;
    1431             :                 }
    1432             :             | SET SESSION set_rest
    1433             :                 {
    1434          50 :                     VariableSetStmt *n = $3;
    1435          50 :                     n->is_local = false;
    1436          50 :                     $$ = (Node *) n;
    1437             :                 }
    1438             :         ;
    1439             : 
    1440             : set_rest:
    1441             :             TRANSACTION transaction_mode_list
    1442             :                 {
    1443         286 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1444         286 :                     n->kind = VAR_SET_MULTI;
    1445         286 :                     n->name = "TRANSACTION";
    1446         286 :                     n->args = $2;
    1447         286 :                     $$ = n;
    1448             :                 }
    1449             :             | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
    1450             :                 {
    1451           8 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1452           8 :                     n->kind = VAR_SET_MULTI;
    1453           8 :                     n->name = "SESSION CHARACTERISTICS";
    1454           8 :                     n->args = $5;
    1455           8 :                     $$ = n;
    1456             :                 }
    1457             :             | set_rest_more
    1458             :             ;
    1459             : 
    1460             : generic_set:
    1461             :             var_name TO var_list
    1462             :                 {
    1463        2802 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1464        2802 :                     n->kind = VAR_SET_VALUE;
    1465        2802 :                     n->name = $1;
    1466        2802 :                     n->args = $3;
    1467        2802 :                     $$ = n;
    1468             :                 }
    1469             :             | var_name '=' var_list
    1470             :                 {
    1471        6720 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1472        6720 :                     n->kind = VAR_SET_VALUE;
    1473        6720 :                     n->name = $1;
    1474        6720 :                     n->args = $3;
    1475        6720 :                     $$ = n;
    1476             :                 }
    1477             :             | var_name TO DEFAULT
    1478             :                 {
    1479          72 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1480          72 :                     n->kind = VAR_SET_DEFAULT;
    1481          72 :                     n->name = $1;
    1482          72 :                     $$ = n;
    1483             :                 }
    1484             :             | var_name '=' DEFAULT
    1485             :                 {
    1486           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1487           0 :                     n->kind = VAR_SET_DEFAULT;
    1488           0 :                     n->name = $1;
    1489           0 :                     $$ = n;
    1490             :                 }
    1491             :         ;
    1492             : 
    1493             : set_rest_more:  /* Generic SET syntaxes: */
    1494        9558 :             generic_set                         {$$ = $1;}
    1495             :             | var_name FROM CURRENT_P
    1496             :                 {
    1497           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1498           0 :                     n->kind = VAR_SET_CURRENT;
    1499           0 :                     n->name = $1;
    1500           0 :                     $$ = n;
    1501             :                 }
    1502             :             /* Special syntaxes mandated by SQL standard: */
    1503             :             | TIME ZONE zone_value
    1504             :                 {
    1505          52 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1506          52 :                     n->kind = VAR_SET_VALUE;
    1507          52 :                     n->name = "timezone";
    1508          52 :                     if ($3 != NULL)
    1509          44 :                         n->args = list_make1($3);
    1510             :                     else
    1511           8 :                         n->kind = VAR_SET_DEFAULT;
    1512          52 :                     $$ = n;
    1513             :                 }
    1514             :             | CATALOG_P Sconst
    1515             :                 {
    1516           0 :                     ereport(ERROR,
    1517             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1518             :                              errmsg("current database cannot be changed"),
    1519             :                              parser_errposition(@2)));
    1520             :                     $$ = NULL; /*not reached*/
    1521             :                 }
    1522             :             | SCHEMA Sconst
    1523             :                 {
    1524           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1525           0 :                     n->kind = VAR_SET_VALUE;
    1526           0 :                     n->name = "search_path";
    1527           0 :                     n->args = list_make1(makeStringConst($2, @2));
    1528           0 :                     $$ = n;
    1529             :                 }
    1530             :             | NAMES opt_encoding
    1531             :                 {
    1532           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1533           0 :                     n->kind = VAR_SET_VALUE;
    1534           0 :                     n->name = "client_encoding";
    1535           0 :                     if ($2 != NULL)
    1536           0 :                         n->args = list_make1(makeStringConst($2, @2));
    1537             :                     else
    1538           0 :                         n->kind = VAR_SET_DEFAULT;
    1539           0 :                     $$ = n;
    1540             :                 }
    1541             :             | ROLE NonReservedWord_or_Sconst
    1542             :                 {
    1543         494 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1544         494 :                     n->kind = VAR_SET_VALUE;
    1545         494 :                     n->name = "role";
    1546         494 :                     n->args = list_make1(makeStringConst($2, @2));
    1547         494 :                     $$ = n;
    1548             :                 }
    1549             :             | SESSION AUTHORIZATION NonReservedWord_or_Sconst
    1550             :                 {
    1551        1112 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1552        1112 :                     n->kind = VAR_SET_VALUE;
    1553        1112 :                     n->name = "session_authorization";
    1554        1112 :                     n->args = list_make1(makeStringConst($3, @3));
    1555        1112 :                     $$ = n;
    1556             :                 }
    1557             :             | SESSION AUTHORIZATION DEFAULT
    1558             :                 {
    1559           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1560           0 :                     n->kind = VAR_SET_DEFAULT;
    1561           0 :                     n->name = "session_authorization";
    1562           0 :                     $$ = n;
    1563             :                 }
    1564             :             | XML_P OPTION document_or_content
    1565             :                 {
    1566           8 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1567           8 :                     n->kind = VAR_SET_VALUE;
    1568           8 :                     n->name = "xmloption";
    1569           8 :                     n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
    1570           8 :                     $$ = n;
    1571             :                 }
    1572             :             /* Special syntaxes invented by PostgreSQL: */
    1573             :             | TRANSACTION SNAPSHOT Sconst
    1574             :                 {
    1575          16 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1576          16 :                     n->kind = VAR_SET_MULTI;
    1577          16 :                     n->name = "TRANSACTION SNAPSHOT";
    1578          16 :                     n->args = list_make1(makeStringConst($3, @3));
    1579          16 :                     $$ = n;
    1580             :                 }
    1581             :         ;
    1582             : 
    1583       11518 : var_name:   ColId                               { $$ = $1; }
    1584             :             | var_name '.' ColId
    1585         142 :                 { $$ = psprintf("%s.%s", $1, $3); }
    1586             :         ;
    1587             : 
    1588        9522 : var_list:   var_value                               { $$ = list_make1($1); }
    1589          78 :             | var_list ',' var_value                { $$ = lappend($1, $3); }
    1590             :         ;
    1591             : 
    1592             : var_value:  opt_boolean_or_string
    1593        7736 :                 { $$ = makeStringConst($1, @1); }
    1594             :             | NumericOnly
    1595        1864 :                 { $$ = makeAConst($1, @1); }
    1596             :         ;
    1597             : 
    1598           0 : iso_level:  READ UNCOMMITTED                        { $$ = "read uncommitted"; }
    1599         600 :             | READ COMMITTED                        { $$ = "read committed"; }
    1600        1452 :             | REPEATABLE READ                       { $$ = "repeatable read"; }
    1601        3088 :             | SERIALIZABLE                          { $$ = "serializable"; }
    1602             :         ;
    1603             : 
    1604             : opt_boolean_or_string:
    1605         528 :             TRUE_P                                  { $$ = "true"; }
    1606         726 :             | FALSE_P                               { $$ = "false"; }
    1607        1098 :             | ON                                    { $$ = "on"; }
    1608             :             /*
    1609             :              * OFF is also accepted as a boolean value, but is handled by
    1610             :              * the NonReservedWord rule.  The action for booleans and strings
    1611             :              * is the same, so we don't need to distinguish them here.
    1612             :              */
    1613       13170 :             | NonReservedWord_or_Sconst             { $$ = $1; }
    1614             :         ;
    1615             : 
    1616             : /* Timezone values can be:
    1617             :  * - a string such as 'pst8pdt'
    1618             :  * - an identifier such as "pst8pdt"
    1619             :  * - an integer or floating point number
    1620             :  * - a time interval per SQL99
    1621             :  * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
    1622             :  * so use IDENT (meaning we reject anything that is a key word).
    1623             :  */
    1624             : zone_value:
    1625             :             Sconst
    1626             :                 {
    1627          24 :                     $$ = makeStringConst($1, @1);
    1628             :                 }
    1629             :             | IDENT
    1630             :                 {
    1631           4 :                     $$ = makeStringConst($1, @1);
    1632             :                 }
    1633             :             | ConstInterval Sconst opt_interval
    1634             :                 {
    1635           0 :                     TypeName *t = $1;
    1636           0 :                     if ($3 != NIL)
    1637             :                     {
    1638           0 :                         A_Const *n = (A_Const *) linitial($3);
    1639           0 :                         if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
    1640           0 :                             ereport(ERROR,
    1641             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    1642             :                                      errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
    1643             :                                      parser_errposition(@3)));
    1644             :                     }
    1645           0 :                     t->typmods = $3;
    1646           0 :                     $$ = makeStringConstCast($2, @2, t);
    1647             :                 }
    1648             :             | ConstInterval '(' Iconst ')' Sconst
    1649             :                 {
    1650           0 :                     TypeName *t = $1;
    1651           0 :                     t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
    1652             :                                             makeIntConst($3, @3));
    1653           0 :                     $$ = makeStringConstCast($5, @5, t);
    1654             :                 }
    1655          16 :             | NumericOnly                           { $$ = makeAConst($1, @1); }
    1656           8 :             | DEFAULT                               { $$ = NULL; }
    1657           0 :             | LOCAL                                 { $$ = NULL; }
    1658             :         ;
    1659             : 
    1660             : opt_encoding:
    1661           0 :             Sconst                                  { $$ = $1; }
    1662           0 :             | DEFAULT                               { $$ = NULL; }
    1663           0 :             | /*EMPTY*/                             { $$ = NULL; }
    1664             :         ;
    1665             : 
    1666             : NonReservedWord_or_Sconst:
    1667       37892 :             NonReservedWord                         { $$ = $1; }
    1668        2758 :             | Sconst                                { $$ = $1; }
    1669             :         ;
    1670             : 
    1671             : VariableResetStmt:
    1672        1820 :             RESET reset_rest                        { $$ = (Node *) $2; }
    1673             :         ;
    1674             : 
    1675             : reset_rest:
    1676        1484 :             generic_reset                           { $$ = $1; }
    1677             :             | TIME ZONE
    1678             :                 {
    1679           8 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1680           8 :                     n->kind = VAR_RESET;
    1681           8 :                     n->name = "timezone";
    1682           8 :                     $$ = n;
    1683             :                 }
    1684             :             | TRANSACTION ISOLATION LEVEL
    1685             :                 {
    1686           4 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1687           4 :                     n->kind = VAR_RESET;
    1688           4 :                     n->name = "transaction_isolation";
    1689           4 :                     $$ = n;
    1690             :                 }
    1691             :             | SESSION AUTHORIZATION
    1692             :                 {
    1693         324 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1694         324 :                     n->kind = VAR_RESET;
    1695         324 :                     n->name = "session_authorization";
    1696         324 :                     $$ = n;
    1697             :                 }
    1698             :         ;
    1699             : 
    1700             : generic_reset:
    1701             :             var_name
    1702             :                 {
    1703        1480 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1704        1480 :                     n->kind = VAR_RESET;
    1705        1480 :                     n->name = $1;
    1706        1480 :                     $$ = n;
    1707             :                 }
    1708             :             | ALL
    1709             :                 {
    1710           8 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1711           8 :                     n->kind = VAR_RESET_ALL;
    1712           8 :                     $$ = n;
    1713             :                 }
    1714             :         ;
    1715             : 
    1716             : /* SetResetClause allows SET or RESET without LOCAL */
    1717             : SetResetClause:
    1718         878 :             SET set_rest                    { $$ = $2; }
    1719          20 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    1720             :         ;
    1721             : 
    1722             : /* SetResetClause allows SET or RESET without LOCAL */
    1723             : FunctionSetResetClause:
    1724          64 :             SET set_rest_more               { $$ = $2; }
    1725           8 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    1726             :         ;
    1727             : 
    1728             : 
    1729             : VariableShowStmt:
    1730             :             SHOW var_name
    1731             :                 {
    1732         444 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1733         444 :                     n->name = $2;
    1734         444 :                     $$ = (Node *) n;
    1735             :                 }
    1736             :             | SHOW TIME ZONE
    1737             :                 {
    1738           8 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1739           8 :                     n->name = "timezone";
    1740           8 :                     $$ = (Node *) n;
    1741             :                 }
    1742             :             | SHOW TRANSACTION ISOLATION LEVEL
    1743             :                 {
    1744           4 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1745           4 :                     n->name = "transaction_isolation";
    1746           4 :                     $$ = (Node *) n;
    1747             :                 }
    1748             :             | SHOW SESSION AUTHORIZATION
    1749             :                 {
    1750           0 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1751           0 :                     n->name = "session_authorization";
    1752           0 :                     $$ = (Node *) n;
    1753             :                 }
    1754             :             | SHOW ALL
    1755             :                 {
    1756           0 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1757           0 :                     n->name = "all";
    1758           0 :                     $$ = (Node *) n;
    1759             :                 }
    1760             :         ;
    1761             : 
    1762             : 
    1763             : ConstraintsSetStmt:
    1764             :             SET CONSTRAINTS constraints_set_list constraints_set_mode
    1765             :                 {
    1766          68 :                     ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
    1767          68 :                     n->constraints = $3;
    1768          68 :                     n->deferred = $4;
    1769          68 :                     $$ = (Node *) n;
    1770             :                 }
    1771             :         ;
    1772             : 
    1773             : constraints_set_list:
    1774          36 :             ALL                                     { $$ = NIL; }
    1775          32 :             | qualified_name_list                   { $$ = $1; }
    1776             :         ;
    1777             : 
    1778             : constraints_set_mode:
    1779          46 :             DEFERRED                                { $$ = true; }
    1780          22 :             | IMMEDIATE                             { $$ = false; }
    1781             :         ;
    1782             : 
    1783             : 
    1784             : /*
    1785             :  * Checkpoint statement
    1786             :  */
    1787             : CheckPointStmt:
    1788             :             CHECKPOINT
    1789             :                 {
    1790         108 :                     CheckPointStmt *n = makeNode(CheckPointStmt);
    1791         108 :                     $$ = (Node *)n;
    1792             :                 }
    1793             :         ;
    1794             : 
    1795             : 
    1796             : /*****************************************************************************
    1797             :  *
    1798             :  * DISCARD { ALL | TEMP | PLANS | SEQUENCES }
    1799             :  *
    1800             :  *****************************************************************************/
    1801             : 
    1802             : DiscardStmt:
    1803             :             DISCARD ALL
    1804             :                 {
    1805           4 :                     DiscardStmt *n = makeNode(DiscardStmt);
    1806           4 :                     n->target = DISCARD_ALL;
    1807           4 :                     $$ = (Node *) n;
    1808             :                 }
    1809             :             | DISCARD TEMP
    1810             :                 {
    1811           4 :                     DiscardStmt *n = makeNode(DiscardStmt);
    1812           4 :                     n->target = DISCARD_TEMP;
    1813           4 :                     $$ = (Node *) n;
    1814             :                 }
    1815             :             | DISCARD TEMPORARY
    1816             :                 {
    1817           0 :                     DiscardStmt *n = makeNode(DiscardStmt);
    1818           0 :                     n->target = DISCARD_TEMP;
    1819           0 :                     $$ = (Node *) n;
    1820             :                 }
    1821             :             | DISCARD PLANS
    1822             :                 {
    1823           4 :                     DiscardStmt *n = makeNode(DiscardStmt);
    1824           4 :                     n->target = DISCARD_PLANS;
    1825           4 :                     $$ = (Node *) n;
    1826             :                 }
    1827             :             | DISCARD SEQUENCES
    1828             :                 {
    1829           8 :                     DiscardStmt *n = makeNode(DiscardStmt);
    1830           8 :                     n->target = DISCARD_SEQUENCES;
    1831           8 :                     $$ = (Node *) n;
    1832             :                 }
    1833             : 
    1834             :         ;
    1835             : 
    1836             : 
    1837             : /*****************************************************************************
    1838             :  *
    1839             :  *  ALTER [ TABLE | INDEX | SEQUENCE | VIEW | MATERIALIZED VIEW ] variations
    1840             :  *
    1841             :  * Note: we accept all subcommands for each of the five variants, and sort
    1842             :  * out what's really legal at execution time.
    1843             :  *****************************************************************************/
    1844             : 
    1845             : AlterTableStmt:
    1846             :             ALTER TABLE relation_expr alter_table_cmds
    1847             :                 {
    1848        8050 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    1849        8050 :                     n->relation = $3;
    1850        8050 :                     n->cmds = $4;
    1851        8050 :                     n->relkind = OBJECT_TABLE;
    1852        8050 :                     n->missing_ok = false;
    1853        8050 :                     $$ = (Node *)n;
    1854             :                 }
    1855             :         |   ALTER TABLE IF_P EXISTS relation_expr alter_table_cmds
    1856             :                 {
    1857          36 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    1858          36 :                     n->relation = $5;
    1859          36 :                     n->cmds = $6;
    1860          36 :                     n->relkind = OBJECT_TABLE;
    1861          36 :                     n->missing_ok = true;
    1862          36 :                     $$ = (Node *)n;
    1863             :                 }
    1864             :         |   ALTER TABLE relation_expr partition_cmd
    1865             :                 {
    1866        1514 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    1867        1514 :                     n->relation = $3;
    1868        1514 :                     n->cmds = list_make1($4);
    1869        1514 :                     n->relkind = OBJECT_TABLE;
    1870        1514 :                     n->missing_ok = false;
    1871        1514 :                     $$ = (Node *)n;
    1872             :                 }
    1873             :         |   ALTER TABLE IF_P EXISTS relation_expr partition_cmd
    1874             :                 {
    1875           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    1876           0 :                     n->relation = $5;
    1877           0 :                     n->cmds = list_make1($6);
    1878           0 :                     n->relkind = OBJECT_TABLE;
    1879           0 :                     n->missing_ok = true;
    1880           0 :                     $$ = (Node *)n;
    1881             :                 }
    1882             :         |   ALTER TABLE ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    1883             :                 {
    1884           8 :                     AlterTableMoveAllStmt *n =
    1885           8 :                         makeNode(AlterTableMoveAllStmt);
    1886           8 :                     n->orig_tablespacename = $6;
    1887           8 :                     n->objtype = OBJECT_TABLE;
    1888           8 :                     n->roles = NIL;
    1889           8 :                     n->new_tablespacename = $9;
    1890           8 :                     n->nowait = $10;
    1891           8 :                     $$ = (Node *)n;
    1892             :                 }
    1893             :         |   ALTER TABLE ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    1894             :                 {
    1895           0 :                     AlterTableMoveAllStmt *n =
    1896           0 :                         makeNode(AlterTableMoveAllStmt);
    1897           0 :                     n->orig_tablespacename = $6;
    1898           0 :                     n->objtype = OBJECT_TABLE;
    1899           0 :                     n->roles = $9;
    1900           0 :                     n->new_tablespacename = $12;
    1901           0 :                     n->nowait = $13;
    1902           0 :                     $$ = (Node *)n;
    1903             :                 }
    1904             :         |   ALTER INDEX qualified_name alter_table_cmds
    1905             :                 {
    1906         162 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    1907         162 :                     n->relation = $3;
    1908         162 :                     n->cmds = $4;
    1909         162 :                     n->relkind = OBJECT_INDEX;
    1910         162 :                     n->missing_ok = false;
    1911         162 :                     $$ = (Node *)n;
    1912             :                 }
    1913             :         |   ALTER INDEX IF_P EXISTS qualified_name alter_table_cmds
    1914             :                 {
    1915           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    1916           0 :                     n->relation = $5;
    1917           0 :                     n->cmds = $6;
    1918           0 :                     n->relkind = OBJECT_INDEX;
    1919           0 :                     n->missing_ok = true;
    1920           0 :                     $$ = (Node *)n;
    1921             :                 }
    1922             :         |   ALTER INDEX qualified_name index_partition_cmd
    1923             :                 {
    1924         224 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    1925         224 :                     n->relation = $3;
    1926         224 :                     n->cmds = list_make1($4);
    1927         224 :                     n->relkind = OBJECT_INDEX;
    1928         224 :                     n->missing_ok = false;
    1929         224 :                     $$ = (Node *)n;
    1930             :                 }
    1931             :         |   ALTER INDEX ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    1932             :                 {
    1933           4 :                     AlterTableMoveAllStmt *n =
    1934           4 :                         makeNode(AlterTableMoveAllStmt);
    1935           4 :                     n->orig_tablespacename = $6;
    1936           4 :                     n->objtype = OBJECT_INDEX;
    1937           4 :                     n->roles = NIL;
    1938           4 :                     n->new_tablespacename = $9;
    1939           4 :                     n->nowait = $10;
    1940           4 :                     $$ = (Node *)n;
    1941             :                 }
    1942             :         |   ALTER INDEX ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    1943             :                 {
    1944           0 :                     AlterTableMoveAllStmt *n =
    1945           0 :                         makeNode(AlterTableMoveAllStmt);
    1946           0 :                     n->orig_tablespacename = $6;
    1947           0 :                     n->objtype = OBJECT_INDEX;
    1948           0 :                     n->roles = $9;
    1949           0 :                     n->new_tablespacename = $12;
    1950           0 :                     n->nowait = $13;
    1951           0 :                     $$ = (Node *)n;
    1952             :                 }
    1953             :         |   ALTER SEQUENCE qualified_name alter_table_cmds
    1954             :                 {
    1955           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    1956           0 :                     n->relation = $3;
    1957           0 :                     n->cmds = $4;
    1958           0 :                     n->relkind = OBJECT_SEQUENCE;
    1959           0 :                     n->missing_ok = false;
    1960           0 :                     $$ = (Node *)n;
    1961             :                 }
    1962             :         |   ALTER SEQUENCE IF_P EXISTS qualified_name alter_table_cmds
    1963             :                 {
    1964           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    1965           0 :                     n->relation = $5;
    1966           0 :                     n->cmds = $6;
    1967           0 :                     n->relkind = OBJECT_SEQUENCE;
    1968           0 :                     n->missing_ok = true;
    1969           0 :                     $$ = (Node *)n;
    1970             :                 }
    1971             :         |   ALTER VIEW qualified_name alter_table_cmds
    1972             :                 {
    1973          82 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    1974          82 :                     n->relation = $3;
    1975          82 :                     n->cmds = $4;
    1976          82 :                     n->relkind = OBJECT_VIEW;
    1977          82 :                     n->missing_ok = false;
    1978          82 :                     $$ = (Node *)n;
    1979             :                 }
    1980             :         |   ALTER VIEW IF_P EXISTS qualified_name alter_table_cmds
    1981             :                 {
    1982           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    1983           0 :                     n->relation = $5;
    1984           0 :                     n->cmds = $6;
    1985           0 :                     n->relkind = OBJECT_VIEW;
    1986           0 :                     n->missing_ok = true;
    1987           0 :                     $$ = (Node *)n;
    1988             :                 }
    1989             :         |   ALTER MATERIALIZED VIEW qualified_name alter_table_cmds
    1990             :                 {
    1991           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    1992           0 :                     n->relation = $4;
    1993           0 :                     n->cmds = $5;
    1994           0 :                     n->relkind = OBJECT_MATVIEW;
    1995           0 :                     n->missing_ok = false;
    1996           0 :                     $$ = (Node *)n;
    1997             :                 }
    1998             :         |   ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name alter_table_cmds
    1999             :                 {
    2000           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2001           0 :                     n->relation = $6;
    2002           0 :                     n->cmds = $7;
    2003           0 :                     n->relkind = OBJECT_MATVIEW;
    2004           0 :                     n->missing_ok = true;
    2005           0 :                     $$ = (Node *)n;
    2006             :                 }
    2007             :         |   ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2008             :                 {
    2009           0 :                     AlterTableMoveAllStmt *n =
    2010           0 :                         makeNode(AlterTableMoveAllStmt);
    2011           0 :                     n->orig_tablespacename = $7;
    2012           0 :                     n->objtype = OBJECT_MATVIEW;
    2013           0 :                     n->roles = NIL;
    2014           0 :                     n->new_tablespacename = $10;
    2015           0 :                     n->nowait = $11;
    2016           0 :                     $$ = (Node *)n;
    2017             :                 }
    2018             :         |   ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2019             :                 {
    2020           0 :                     AlterTableMoveAllStmt *n =
    2021           0 :                         makeNode(AlterTableMoveAllStmt);
    2022           0 :                     n->orig_tablespacename = $7;
    2023           0 :                     n->objtype = OBJECT_MATVIEW;
    2024           0 :                     n->roles = $10;
    2025           0 :                     n->new_tablespacename = $13;
    2026           0 :                     n->nowait = $14;
    2027           0 :                     $$ = (Node *)n;
    2028             :                 }
    2029             :         ;
    2030             : 
    2031             : alter_table_cmds:
    2032        8630 :             alter_table_cmd                         { $$ = list_make1($1); }
    2033         494 :             | alter_table_cmds ',' alter_table_cmd  { $$ = lappend($1, $3); }
    2034             :         ;
    2035             : 
    2036             : partition_cmd:
    2037             :             /* ALTER TABLE <name> ATTACH PARTITION <table_name> FOR VALUES */
    2038             :             ATTACH PARTITION qualified_name PartitionBoundSpec
    2039             :                 {
    2040        1288 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2041        1288 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2042             : 
    2043        1288 :                     n->subtype = AT_AttachPartition;
    2044        1288 :                     cmd->name = $3;
    2045        1288 :                     cmd->bound = $4;
    2046        1288 :                     n->def = (Node *) cmd;
    2047             : 
    2048        1288 :                     $$ = (Node *) n;
    2049             :                 }
    2050             :             /* ALTER TABLE <name> DETACH PARTITION <partition_name> */
    2051             :             | DETACH PARTITION qualified_name
    2052             :                 {
    2053         226 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2054         226 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2055             : 
    2056         226 :                     n->subtype = AT_DetachPartition;
    2057         226 :                     cmd->name = $3;
    2058         226 :                     cmd->bound = NULL;
    2059         226 :                     n->def = (Node *) cmd;
    2060             : 
    2061         226 :                     $$ = (Node *) n;
    2062             :                 }
    2063             :         ;
    2064             : 
    2065             : index_partition_cmd:
    2066             :             /* ALTER INDEX <name> ATTACH PARTITION <index_name> */
    2067             :             ATTACH PARTITION qualified_name
    2068             :                 {
    2069         224 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2070         224 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2071             : 
    2072         224 :                     n->subtype = AT_AttachPartition;
    2073         224 :                     cmd->name = $3;
    2074         224 :                     cmd->bound = NULL;
    2075         224 :                     n->def = (Node *) cmd;
    2076             : 
    2077         224 :                     $$ = (Node *) n;
    2078             :                 }
    2079             :         ;
    2080             : 
    2081             : alter_table_cmd:
    2082             :             /* ALTER TABLE <name> ADD <coldef> */
    2083             :             ADD_P columnDef
    2084             :                 {
    2085         106 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2086         106 :                     n->subtype = AT_AddColumn;
    2087         106 :                     n->def = $2;
    2088         106 :                     n->missing_ok = false;
    2089         106 :                     $$ = (Node *)n;
    2090             :                 }
    2091             :             /* ALTER TABLE <name> ADD IF NOT EXISTS <coldef> */
    2092             :             | ADD_P IF_P NOT EXISTS columnDef
    2093             :                 {
    2094           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2095           0 :                     n->subtype = AT_AddColumn;
    2096           0 :                     n->def = $5;
    2097           0 :                     n->missing_ok = true;
    2098           0 :                     $$ = (Node *)n;
    2099             :                 }
    2100             :             /* ALTER TABLE <name> ADD COLUMN <coldef> */
    2101             :             | ADD_P COLUMN columnDef
    2102             :                 {
    2103        1076 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2104        1076 :                     n->subtype = AT_AddColumn;
    2105        1076 :                     n->def = $3;
    2106        1076 :                     n->missing_ok = false;
    2107        1076 :                     $$ = (Node *)n;
    2108             :                 }
    2109             :             /* ALTER TABLE <name> ADD COLUMN IF NOT EXISTS <coldef> */
    2110             :             | ADD_P COLUMN IF_P NOT EXISTS columnDef
    2111             :                 {
    2112          40 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2113          40 :                     n->subtype = AT_AddColumn;
    2114          40 :                     n->def = $6;
    2115          40 :                     n->missing_ok = true;
    2116          40 :                     $$ = (Node *)n;
    2117             :                 }
    2118             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
    2119             :             | ALTER opt_column ColId alter_column_default
    2120             :                 {
    2121         326 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2122         326 :                     n->subtype = AT_ColumnDefault;
    2123         326 :                     n->name = $3;
    2124         326 :                     n->def = $4;
    2125         326 :                     $$ = (Node *)n;
    2126             :                 }
    2127             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
    2128             :             | ALTER opt_column ColId DROP NOT NULL_P
    2129             :                 {
    2130         104 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2131         104 :                     n->subtype = AT_DropNotNull;
    2132         104 :                     n->name = $3;
    2133         104 :                     $$ = (Node *)n;
    2134             :                 }
    2135             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
    2136             :             | ALTER opt_column ColId SET NOT NULL_P
    2137             :                 {
    2138         194 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2139         194 :                     n->subtype = AT_SetNotNull;
    2140         194 :                     n->name = $3;
    2141         194 :                     $$ = (Node *)n;
    2142             :                 }
    2143             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
    2144             :             | ALTER opt_column ColId DROP EXPRESSION
    2145             :                 {
    2146          20 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2147          20 :                     n->subtype = AT_DropExpression;
    2148          20 :                     n->name = $3;
    2149          20 :                     $$ = (Node *)n;
    2150             :                 }
    2151             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION IF EXISTS */
    2152             :             | ALTER opt_column ColId DROP EXPRESSION IF_P EXISTS
    2153             :                 {
    2154           4 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2155           4 :                     n->subtype = AT_DropExpression;
    2156           4 :                     n->name = $3;
    2157           4 :                     n->missing_ok = true;
    2158           4 :                     $$ = (Node *)n;
    2159             :                 }
    2160             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS <SignedIconst> */
    2161             :             | ALTER opt_column ColId SET STATISTICS SignedIconst
    2162             :                 {
    2163          42 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2164          42 :                     n->subtype = AT_SetStatistics;
    2165          42 :                     n->name = $3;
    2166          42 :                     n->def = (Node *) makeInteger($6);
    2167          42 :                     $$ = (Node *)n;
    2168             :                 }
    2169             :             /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS <SignedIconst> */
    2170             :             | ALTER opt_column Iconst SET STATISTICS SignedIconst
    2171             :                 {
    2172          44 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2173             : 
    2174          44 :                     if ($3 <= 0 || $3 > PG_INT16_MAX)
    2175           4 :                         ereport(ERROR,
    2176             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
    2177             :                                  errmsg("column number must be in range from 1 to %d", PG_INT16_MAX),
    2178             :                                  parser_errposition(@3)));
    2179             : 
    2180          40 :                     n->subtype = AT_SetStatistics;
    2181          40 :                     n->num = (int16) $3;
    2182          40 :                     n->def = (Node *) makeInteger($6);
    2183          40 :                     $$ = (Node *)n;
    2184             :                 }
    2185             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
    2186             :             | ALTER opt_column ColId SET reloptions
    2187             :                 {
    2188          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2189          18 :                     n->subtype = AT_SetOptions;
    2190          18 :                     n->name = $3;
    2191          18 :                     n->def = (Node *) $5;
    2192          18 :                     $$ = (Node *)n;
    2193             :                 }
    2194             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> RESET ( column_parameter = value [, ... ] ) */
    2195             :             | ALTER opt_column ColId RESET reloptions
    2196             :                 {
    2197           4 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2198           4 :                     n->subtype = AT_ResetOptions;
    2199           4 :                     n->name = $3;
    2200           4 :                     n->def = (Node *) $5;
    2201           4 :                     $$ = (Node *)n;
    2202             :                 }
    2203             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
    2204             :             | ALTER opt_column ColId SET STORAGE ColId
    2205             :                 {
    2206         102 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2207         102 :                     n->subtype = AT_SetStorage;
    2208         102 :                     n->name = $3;
    2209         102 :                     n->def = (Node *) makeString($6);
    2210         102 :                     $$ = (Node *)n;
    2211             :                 }
    2212             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> ADD GENERATED ... AS IDENTITY ... */
    2213             :             | ALTER opt_column ColId ADD_P GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    2214             :                 {
    2215          76 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2216          76 :                     Constraint *c = makeNode(Constraint);
    2217             : 
    2218          76 :                     c->contype = CONSTR_IDENTITY;
    2219          76 :                     c->generated_when = $6;
    2220          76 :                     c->options = $9;
    2221          76 :                     c->location = @5;
    2222             : 
    2223          76 :                     n->subtype = AT_AddIdentity;
    2224          76 :                     n->name = $3;
    2225          76 :                     n->def = (Node *) c;
    2226             : 
    2227          76 :                     $$ = (Node *)n;
    2228             :                 }
    2229             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET <sequence options>/RESET */
    2230             :             | ALTER opt_column ColId alter_identity_column_option_list
    2231             :                 {
    2232          24 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2233          24 :                     n->subtype = AT_SetIdentity;
    2234          24 :                     n->name = $3;
    2235          24 :                     n->def = (Node *) $4;
    2236          24 :                     $$ = (Node *)n;
    2237             :                 }
    2238             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY */
    2239             :             | ALTER opt_column ColId DROP IDENTITY_P
    2240             :                 {
    2241          16 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2242          16 :                     n->subtype = AT_DropIdentity;
    2243          16 :                     n->name = $3;
    2244          16 :                     n->missing_ok = false;
    2245          16 :                     $$ = (Node *)n;
    2246             :                 }
    2247             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY IF EXISTS */
    2248             :             | ALTER opt_column ColId DROP IDENTITY_P IF_P EXISTS
    2249             :                 {
    2250           4 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2251           4 :                     n->subtype = AT_DropIdentity;
    2252           4 :                     n->name = $3;
    2253           4 :                     n->missing_ok = true;
    2254           4 :                     $$ = (Node *)n;
    2255             :                 }
    2256             :             /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
    2257             :             | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
    2258             :                 {
    2259          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2260          12 :                     n->subtype = AT_DropColumn;
    2261          12 :                     n->name = $5;
    2262          12 :                     n->behavior = $6;
    2263          12 :                     n->missing_ok = true;
    2264          12 :                     $$ = (Node *)n;
    2265             :                 }
    2266             :             /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
    2267             :             | DROP opt_column ColId opt_drop_behavior
    2268             :                 {
    2269         982 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2270         982 :                     n->subtype = AT_DropColumn;
    2271         982 :                     n->name = $3;
    2272         982 :                     n->behavior = $4;
    2273         982 :                     n->missing_ok = false;
    2274         982 :                     $$ = (Node *)n;
    2275             :                 }
    2276             :             /*
    2277             :              * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
    2278             :              *      [ USING <expression> ]
    2279             :              */
    2280             :             | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using
    2281             :                 {
    2282         502 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2283         502 :                     ColumnDef *def = makeNode(ColumnDef);
    2284         502 :                     n->subtype = AT_AlterColumnType;
    2285         502 :                     n->name = $3;
    2286         502 :                     n->def = (Node *) def;
    2287             :                     /* We only use these fields of the ColumnDef node */
    2288         502 :                     def->typeName = $6;
    2289         502 :                     def->collClause = (CollateClause *) $7;
    2290         502 :                     def->raw_default = $8;
    2291         502 :                     def->location = @3;
    2292         502 :                     $$ = (Node *)n;
    2293             :                 }
    2294             :             /* ALTER FOREIGN TABLE <name> ALTER [COLUMN] <colname> OPTIONS */
    2295             :             | ALTER opt_column ColId alter_generic_options
    2296             :                 {
    2297          36 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2298          36 :                     n->subtype = AT_AlterColumnGenericOptions;
    2299          36 :                     n->name = $3;
    2300          36 :                     n->def = (Node *) $4;
    2301          36 :                     $$ = (Node *)n;
    2302             :                 }
    2303             :             /* ALTER TABLE <name> ADD CONSTRAINT ... */
    2304             :             | ADD_P TableConstraint
    2305             :                 {
    2306        1826 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2307        1826 :                     n->subtype = AT_AddConstraint;
    2308        1826 :                     n->def = $2;
    2309        1826 :                     $$ = (Node *)n;
    2310             :                 }
    2311             :             /* ALTER TABLE <name> ALTER CONSTRAINT ... */
    2312             :             | ALTER CONSTRAINT name ConstraintAttributeSpec
    2313             :                 {
    2314          24 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2315          24 :                     Constraint *c = makeNode(Constraint);
    2316          24 :                     n->subtype = AT_AlterConstraint;
    2317          24 :                     n->def = (Node *) c;
    2318          24 :                     c->contype = CONSTR_FOREIGN; /* others not supported, yet */
    2319          24 :                     c->conname = $3;
    2320          24 :                     processCASbits($4, @4, "ALTER CONSTRAINT statement",
    2321             :                                     &c->deferrable,
    2322             :                                     &c->initdeferred,
    2323             :                                     NULL, NULL, yyscanner);
    2324          24 :                     $$ = (Node *)n;
    2325             :                 }
    2326             :             /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
    2327             :             | VALIDATE CONSTRAINT name
    2328             :                 {
    2329         338 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2330         338 :                     n->subtype = AT_ValidateConstraint;
    2331         338 :                     n->name = $3;
    2332         338 :                     $$ = (Node *)n;
    2333             :                 }
    2334             :             /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
    2335             :             | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
    2336             :                 {
    2337          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2338          12 :                     n->subtype = AT_DropConstraint;
    2339          12 :                     n->name = $5;
    2340          12 :                     n->behavior = $6;
    2341          12 :                     n->missing_ok = true;
    2342          12 :                     $$ = (Node *)n;
    2343             :                 }
    2344             :             /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
    2345             :             | DROP CONSTRAINT name opt_drop_behavior
    2346             :                 {
    2347         312 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2348         312 :                     n->subtype = AT_DropConstraint;
    2349         312 :                     n->name = $3;
    2350         312 :                     n->behavior = $4;
    2351         312 :                     n->missing_ok = false;
    2352         312 :                     $$ = (Node *)n;
    2353             :                 }
    2354             :             /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat  */
    2355             :             | SET WITHOUT OIDS
    2356             :                 {
    2357           4 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2358           4 :                     n->subtype = AT_DropOids;
    2359           4 :                     $$ = (Node *)n;
    2360             :                 }
    2361             :             /* ALTER TABLE <name> CLUSTER ON <indexname> */
    2362             :             | CLUSTER ON name
    2363             :                 {
    2364          30 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2365          30 :                     n->subtype = AT_ClusterOn;
    2366          30 :                     n->name = $3;
    2367          30 :                     $$ = (Node *)n;
    2368             :                 }
    2369             :             /* ALTER TABLE <name> SET WITHOUT CLUSTER */
    2370             :             | SET WITHOUT CLUSTER
    2371             :                 {
    2372           8 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2373           8 :                     n->subtype = AT_DropCluster;
    2374           8 :                     n->name = NULL;
    2375           8 :                     $$ = (Node *)n;
    2376             :                 }
    2377             :             /* ALTER TABLE <name> SET LOGGED  */
    2378             :             | SET LOGGED
    2379             :                 {
    2380          16 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2381          16 :                     n->subtype = AT_SetLogged;
    2382          16 :                     $$ = (Node *)n;
    2383             :                 }
    2384             :             /* ALTER TABLE <name> SET UNLOGGED  */
    2385             :             | SET UNLOGGED
    2386             :                 {
    2387          20 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2388          20 :                     n->subtype = AT_SetUnLogged;
    2389          20 :                     $$ = (Node *)n;
    2390             :                 }
    2391             :             /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
    2392             :             | ENABLE_P TRIGGER name
    2393             :                 {
    2394         108 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2395         108 :                     n->subtype = AT_EnableTrig;
    2396         108 :                     n->name = $3;
    2397         108 :                     $$ = (Node *)n;
    2398             :                 }
    2399             :             /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
    2400             :             | ENABLE_P ALWAYS TRIGGER name
    2401             :                 {
    2402           4 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2403           4 :                     n->subtype = AT_EnableAlwaysTrig;
    2404           4 :                     n->name = $4;
    2405           4 :                     $$ = (Node *)n;
    2406             :                 }
    2407             :             /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
    2408             :             | ENABLE_P REPLICA TRIGGER name
    2409             :                 {
    2410           2 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2411           2 :                     n->subtype = AT_EnableReplicaTrig;
    2412           2 :                     n->name = $4;
    2413           2 :                     $$ = (Node *)n;
    2414             :                 }
    2415             :             /* ALTER TABLE <name> ENABLE TRIGGER ALL */
    2416             :             | ENABLE_P TRIGGER ALL
    2417             :                 {
    2418           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2419           0 :                     n->subtype = AT_EnableTrigAll;
    2420           0 :                     $$ = (Node *)n;
    2421             :                 }
    2422             :             /* ALTER TABLE <name> ENABLE TRIGGER USER */
    2423             :             | ENABLE_P TRIGGER USER
    2424             :                 {
    2425           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2426           0 :                     n->subtype = AT_EnableTrigUser;
    2427           0 :                     $$ = (Node *)n;
    2428             :                 }
    2429             :             /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
    2430             :             | DISABLE_P TRIGGER name
    2431             :                 {
    2432         108 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2433         108 :                     n->subtype = AT_DisableTrig;
    2434         108 :                     n->name = $3;
    2435         108 :                     $$ = (Node *)n;
    2436             :                 }
    2437             :             /* ALTER TABLE <name> DISABLE TRIGGER ALL */
    2438             :             | DISABLE_P TRIGGER ALL
    2439             :                 {
    2440           4 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2441           4 :                     n->subtype = AT_DisableTrigAll;
    2442           4 :                     $$ = (Node *)n;
    2443             :                 }
    2444             :             /* ALTER TABLE <name> DISABLE TRIGGER USER */
    2445             :             | DISABLE_P TRIGGER USER
    2446             :                 {
    2447           4 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2448           4 :                     n->subtype = AT_DisableTrigUser;
    2449           4 :                     $$ = (Node *)n;
    2450             :                 }
    2451             :             /* ALTER TABLE <name> ENABLE RULE <rule> */
    2452             :             | ENABLE_P RULE name
    2453             :                 {
    2454           4 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2455           4 :                     n->subtype = AT_EnableRule;
    2456           4 :                     n->name = $3;
    2457           4 :                     $$ = (Node *)n;
    2458             :                 }
    2459             :             /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
    2460             :             | ENABLE_P ALWAYS RULE name
    2461             :                 {
    2462           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2463           0 :                     n->subtype = AT_EnableAlwaysRule;
    2464           0 :                     n->name = $4;
    2465           0 :                     $$ = (Node *)n;
    2466             :                 }
    2467             :             /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
    2468             :             | ENABLE_P REPLICA RULE name
    2469             :                 {
    2470           4 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2471           4 :                     n->subtype = AT_EnableReplicaRule;
    2472           4 :                     n->name = $4;
    2473           4 :                     $$ = (Node *)n;
    2474             :                 }
    2475             :             /* ALTER TABLE <name> DISABLE RULE <rule> */
    2476             :             | DISABLE_P RULE name
    2477             :                 {
    2478           4 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2479           4 :                     n->subtype = AT_DisableRule;
    2480           4 :                     n->name = $3;
    2481           4 :                     $$ = (Node *)n;
    2482             :                 }
    2483             :             /* ALTER TABLE <name> INHERIT <parent> */
    2484             :             | INHERIT qualified_name
    2485             :                 {
    2486         178 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2487         178 :                     n->subtype = AT_AddInherit;
    2488         178 :                     n->def = (Node *) $2;
    2489         178 :                     $$ = (Node *)n;
    2490             :                 }
    2491             :             /* ALTER TABLE <name> NO INHERIT <parent> */
    2492             :             | NO INHERIT qualified_name
    2493             :                 {
    2494          28 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2495          28 :                     n->subtype = AT_DropInherit;
    2496          28 :                     n->def = (Node *) $3;
    2497          28 :                     $$ = (Node *)n;
    2498             :                 }
    2499             :             /* ALTER TABLE <name> OF <type_name> */
    2500             :             | OF any_name
    2501             :                 {
    2502          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2503          50 :                     TypeName *def = makeTypeNameFromNameList($2);
    2504          50 :                     def->location = @2;
    2505          50 :                     n->subtype = AT_AddOf;
    2506          50 :                     n->def = (Node *) def;
    2507          50 :                     $$ = (Node *)n;
    2508             :                 }
    2509             :             /* ALTER TABLE <name> NOT OF */
    2510             :             | NOT OF
    2511             :                 {
    2512           4 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2513           4 :                     n->subtype = AT_DropOf;
    2514           4 :                     $$ = (Node *)n;
    2515             :                 }
    2516             :             /* ALTER TABLE <name> OWNER TO RoleSpec */
    2517             :             | OWNER TO RoleSpec
    2518             :                 {
    2519        1386 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2520        1386 :                     n->subtype = AT_ChangeOwner;
    2521        1386 :                     n->newowner = $3;
    2522        1386 :                     $$ = (Node *)n;
    2523             :                 }
    2524             :             /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
    2525             :             | SET TABLESPACE name
    2526             :                 {
    2527          36 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2528          36 :                     n->subtype = AT_SetTableSpace;
    2529          36 :                     n->name = $3;
    2530          36 :                     $$ = (Node *)n;
    2531             :                 }
    2532             :             /* ALTER TABLE <name> SET (...) */
    2533             :             | SET reloptions
    2534             :                 {
    2535         402 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2536         402 :                     n->subtype = AT_SetRelOptions;
    2537         402 :                     n->def = (Node *)$2;
    2538         402 :                     $$ = (Node *)n;
    2539             :                 }
    2540             :             /* ALTER TABLE <name> RESET (...) */
    2541             :             | RESET reloptions
    2542             :                 {
    2543         108 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2544         108 :                     n->subtype = AT_ResetRelOptions;
    2545         108 :                     n->def = (Node *)$2;
    2546         108 :                     $$ = (Node *)n;
    2547             :                 }
    2548             :             /* ALTER TABLE <name> REPLICA IDENTITY  */
    2549             :             | REPLICA IDENTITY_P replica_identity
    2550             :                 {
    2551          92 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2552          92 :                     n->subtype = AT_ReplicaIdentity;
    2553          92 :                     n->def = $3;
    2554          92 :                     $$ = (Node *)n;
    2555             :                 }
    2556             :             /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
    2557             :             | ENABLE_P ROW LEVEL SECURITY
    2558             :                 {
    2559         182 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2560         182 :                     n->subtype = AT_EnableRowSecurity;
    2561         182 :                     $$ = (Node *)n;
    2562             :                 }
    2563             :             /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
    2564             :             | DISABLE_P ROW LEVEL SECURITY
    2565             :                 {
    2566           8 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2567           8 :                     n->subtype = AT_DisableRowSecurity;
    2568           8 :                     $$ = (Node *)n;
    2569             :                 }
    2570             :             /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
    2571             :             | FORCE ROW LEVEL SECURITY
    2572             :                 {
    2573          46 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2574          46 :                     n->subtype = AT_ForceRowSecurity;
    2575          46 :                     $$ = (Node *)n;
    2576             :                 }
    2577             :             /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
    2578             :             | NO FORCE ROW LEVEL SECURITY
    2579             :                 {
    2580          16 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2581          16 :                     n->subtype = AT_NoForceRowSecurity;
    2582          16 :                     $$ = (Node *)n;
    2583             :                 }
    2584             :             | alter_generic_options
    2585             :                 {
    2586          28 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2587          28 :                     n->subtype = AT_GenericOptions;
    2588          28 :                     n->def = (Node *)$1;
    2589          28 :                     $$ = (Node *) n;
    2590             :                 }
    2591             :         ;
    2592             : 
    2593             : alter_column_default:
    2594         214 :             SET DEFAULT a_expr          { $$ = $3; }
    2595         120 :             | DROP DEFAULT              { $$ = NULL; }
    2596             :         ;
    2597             : 
    2598             : opt_drop_behavior:
    2599         956 :             CASCADE                     { $$ = DROP_CASCADE; }
    2600          92 :             | RESTRICT                  { $$ = DROP_RESTRICT; }
    2601       34296 :             | /* EMPTY */               { $$ = DROP_RESTRICT; /* default */ }
    2602             :         ;
    2603             : 
    2604             : opt_collate_clause:
    2605             :             COLLATE any_name
    2606             :                 {
    2607           4 :                     CollateClause *n = makeNode(CollateClause);
    2608           4 :                     n->arg = NULL;
    2609           4 :                     n->collname = $2;
    2610           4 :                     n->location = @1;
    2611           4 :                     $$ = (Node *) n;
    2612             :                 }
    2613        2888 :             | /* EMPTY */               { $$ = NULL; }
    2614             :         ;
    2615             : 
    2616             : alter_using:
    2617          92 :             USING a_expr                { $$ = $2; }
    2618         410 :             | /* EMPTY */               { $$ = NULL; }
    2619             :         ;
    2620             : 
    2621             : replica_identity:
    2622             :             NOTHING
    2623             :                 {
    2624           8 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    2625           8 :                     n->identity_type = REPLICA_IDENTITY_NOTHING;
    2626           8 :                     n->name = NULL;
    2627           8 :                     $$ = (Node *) n;
    2628             :                 }
    2629             :             | FULL
    2630             :                 {
    2631          26 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    2632          26 :                     n->identity_type = REPLICA_IDENTITY_FULL;
    2633          26 :                     n->name = NULL;
    2634          26 :                     $$ = (Node *) n;
    2635             :                 }
    2636             :             | DEFAULT
    2637             :                 {
    2638           4 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    2639           4 :                     n->identity_type = REPLICA_IDENTITY_DEFAULT;
    2640           4 :                     n->name = NULL;
    2641           4 :                     $$ = (Node *) n;
    2642             :                 }
    2643             :             | USING INDEX name
    2644             :                 {
    2645          54 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    2646          54 :                     n->identity_type = REPLICA_IDENTITY_INDEX;
    2647          54 :                     n->name = $3;
    2648          54 :                     $$ = (Node *) n;
    2649             :                 }
    2650             : ;
    2651             : 
    2652             : reloptions:
    2653        1916 :             '(' reloption_list ')'                  { $$ = $2; }
    2654             :         ;
    2655             : 
    2656        1072 : opt_reloptions:     WITH reloptions                 { $$ = $2; }
    2657       49804 :              |      /* EMPTY */                     { $$ = NIL; }
    2658             :         ;
    2659             : 
    2660             : reloption_list:
    2661        1916 :             reloption_elem                          { $$ = list_make1($1); }
    2662         122 :             | reloption_list ',' reloption_elem     { $$ = lappend($1, $3); }
    2663             :         ;
    2664             : 
    2665             : /* This should match def_elem and also allow qualified names */
    2666             : reloption_elem:
    2667             :             ColLabel '=' def_arg
    2668             :                 {
    2669        1104 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    2670             :                 }
    2671             :             | ColLabel
    2672             :                 {
    2673         888 :                     $$ = makeDefElem($1, NULL, @1);
    2674             :                 }
    2675             :             | ColLabel '.' ColLabel '=' def_arg
    2676             :                 {
    2677          42 :                     $$ = makeDefElemExtended($1, $3, (Node *) $5,
    2678          42 :                                              DEFELEM_UNSPEC, @1);
    2679             :                 }
    2680             :             | ColLabel '.' ColLabel
    2681             :                 {
    2682           4 :                     $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC, @1);
    2683             :                 }
    2684             :         ;
    2685             : 
    2686             : alter_identity_column_option_list:
    2687             :             alter_identity_column_option
    2688          24 :                 { $$ = list_make1($1); }
    2689             :             | alter_identity_column_option_list alter_identity_column_option
    2690          16 :                 { $$ = lappend($1, $2); }
    2691             :         ;
    2692             : 
    2693             : alter_identity_column_option:
    2694             :             RESTART
    2695             :                 {
    2696           8 :                     $$ = makeDefElem("restart", NULL, @1);
    2697             :                 }
    2698             :             | RESTART opt_with NumericOnly
    2699             :                 {
    2700           0 :                     $$ = makeDefElem("restart", (Node *)$3, @1);
    2701             :                 }
    2702             :             | SET SeqOptElem
    2703             :                 {
    2704          16 :                     if (strcmp($2->defname, "as") == 0 ||
    2705          16 :                         strcmp($2->defname, "restart") == 0 ||
    2706          16 :                         strcmp($2->defname, "owned_by") == 0)
    2707           0 :                         ereport(ERROR,
    2708             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    2709             :                                  errmsg("sequence option \"%s\" not supported here", $2->defname),
    2710             :                                  parser_errposition(@2)));
    2711          16 :                     $$ = $2;
    2712             :                 }
    2713             :             | SET GENERATED generated_when
    2714             :                 {
    2715          16 :                     $$ = makeDefElem("generated", (Node *) makeInteger($3), @1);
    2716             :                 }
    2717             :         ;
    2718             : 
    2719             : PartitionBoundSpec:
    2720             :             /* a HASH partition */
    2721             :             FOR VALUES WITH '(' hash_partbound ')'
    2722             :                 {
    2723             :                     ListCell   *lc;
    2724         258 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    2725             : 
    2726         258 :                     n->strategy = PARTITION_STRATEGY_HASH;
    2727         258 :                     n->modulus = n->remainder = -1;
    2728             : 
    2729         774 :                     foreach (lc, $5)
    2730             :                     {
    2731         516 :                         DefElem    *opt = lfirst_node(DefElem, lc);
    2732             : 
    2733         516 :                         if (strcmp(opt->defname, "modulus") == 0)
    2734             :                         {
    2735         258 :                             if (n->modulus != -1)
    2736           0 :                                 ereport(ERROR,
    2737             :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    2738             :                                          errmsg("modulus for hash partition provided more than once"),
    2739             :                                          parser_errposition(opt->location)));
    2740         258 :                             n->modulus = defGetInt32(opt);
    2741             :                         }
    2742         258 :                         else if (strcmp(opt->defname, "remainder") == 0)
    2743             :                         {
    2744         258 :                             if (n->remainder != -1)
    2745           0 :                                 ereport(ERROR,
    2746             :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    2747             :                                          errmsg("remainder for hash partition provided more than once"),
    2748             :                                          parser_errposition(opt->location)));
    2749         258 :                             n->remainder = defGetInt32(opt);
    2750             :                         }
    2751             :                         else
    2752           0 :                             ereport(ERROR,
    2753             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    2754             :                                      errmsg("unrecognized hash partition bound specification \"%s\"",
    2755             :                                             opt->defname),
    2756             :                                      parser_errposition(opt->location)));
    2757             :                     }
    2758             : 
    2759         258 :                     if (n->modulus == -1)
    2760           0 :                         ereport(ERROR,
    2761             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    2762             :                                  errmsg("modulus for hash partition must be specified")));
    2763         258 :                     if (n->remainder == -1)
    2764           0 :                         ereport(ERROR,
    2765             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    2766             :                                  errmsg("remainder for hash partition must be specified")));
    2767             : 
    2768         258 :                     n->location = @3;
    2769             : 
    2770         258 :                     $$ = n;
    2771             :                 }
    2772             : 
    2773             :             /* a LIST partition */
    2774             :             | FOR VALUES IN_P '(' expr_list ')'
    2775             :                 {
    2776        2526 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    2777             : 
    2778        2526 :                     n->strategy = PARTITION_STRATEGY_LIST;
    2779        2526 :                     n->is_default = false;
    2780        2526 :                     n->listdatums = $5;
    2781        2526 :                     n->location = @3;
    2782             : 
    2783        2526 :                     $$ = n;
    2784             :                 }
    2785             : 
    2786             :             /* a RANGE partition */
    2787             :             | FOR VALUES FROM '(' expr_list ')' TO '(' expr_list ')'
    2788             :                 {
    2789        2210 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    2790             : 
    2791        2210 :                     n->strategy = PARTITION_STRATEGY_RANGE;
    2792        2210 :                     n->is_default = false;
    2793        2210 :                     n->lowerdatums = $5;
    2794        2210 :                     n->upperdatums = $9;
    2795        2210 :                     n->location = @3;
    2796             : 
    2797        2210 :                     $$ = n;
    2798             :                 }
    2799             : 
    2800             :             /* a DEFAULT partition */
    2801             :             | DEFAULT
    2802             :                 {
    2803         322 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    2804             : 
    2805         322 :                     n->is_default = true;
    2806         322 :                     n->location = @1;
    2807             : 
    2808         322 :                     $$ = n;
    2809             :                 }
    2810             :         ;
    2811             : 
    2812             : hash_partbound_elem:
    2813             :         NonReservedWord Iconst
    2814             :             {
    2815         516 :                 $$ = makeDefElem($1, (Node *)makeInteger($2), @1);
    2816             :             }
    2817             :         ;
    2818             : 
    2819             : hash_partbound:
    2820             :         hash_partbound_elem
    2821             :             {
    2822         258 :                 $$ = list_make1($1);
    2823             :             }
    2824             :         | hash_partbound ',' hash_partbound_elem
    2825             :             {
    2826         258 :                 $$ = lappend($1, $3);
    2827             :             }
    2828             :         ;
    2829             : 
    2830             : /*****************************************************************************
    2831             :  *
    2832             :  *  ALTER TYPE
    2833             :  *
    2834             :  * really variants of the ALTER TABLE subcommands with different spellings
    2835             :  *****************************************************************************/
    2836             : 
    2837             : AlterCompositeTypeStmt:
    2838             :             ALTER TYPE_P any_name alter_type_cmds
    2839             :                 {
    2840         140 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2841             : 
    2842             :                     /* can't use qualified_name, sigh */
    2843         140 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
    2844         140 :                     n->cmds = $4;
    2845         140 :                     n->relkind = OBJECT_TYPE;
    2846         140 :                     $$ = (Node *)n;
    2847             :                 }
    2848             :             ;
    2849             : 
    2850             : alter_type_cmds:
    2851         140 :             alter_type_cmd                          { $$ = list_make1($1); }
    2852           8 :             | alter_type_cmds ',' alter_type_cmd    { $$ = lappend($1, $3); }
    2853             :         ;
    2854             : 
    2855             : alter_type_cmd:
    2856             :             /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
    2857             :             ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
    2858             :                 {
    2859          44 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2860          44 :                     n->subtype = AT_AddColumn;
    2861          44 :                     n->def = $3;
    2862          44 :                     n->behavior = $4;
    2863          44 :                     $$ = (Node *)n;
    2864             :                 }
    2865             :             /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
    2866             :             | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
    2867             :                 {
    2868           4 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2869           4 :                     n->subtype = AT_DropColumn;
    2870           4 :                     n->name = $5;
    2871           4 :                     n->behavior = $6;
    2872           4 :                     n->missing_ok = true;
    2873           4 :                     $$ = (Node *)n;
    2874             :                 }
    2875             :             /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
    2876             :             | DROP ATTRIBUTE ColId opt_drop_behavior
    2877             :                 {
    2878          56 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2879          56 :                     n->subtype = AT_DropColumn;
    2880          56 :                     n->name = $3;
    2881          56 :                     n->behavior = $4;
    2882          56 :                     n->missing_ok = false;
    2883          56 :                     $$ = (Node *)n;
    2884             :                 }
    2885             :             /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
    2886             :             | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
    2887             :                 {
    2888          44 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2889          44 :                     ColumnDef *def = makeNode(ColumnDef);
    2890          44 :                     n->subtype = AT_AlterColumnType;
    2891          44 :                     n->name = $3;
    2892          44 :                     n->def = (Node *) def;
    2893          44 :                     n->behavior = $8;
    2894             :                     /* We only use these fields of the ColumnDef node */
    2895          44 :                     def->typeName = $6;
    2896          44 :                     def->collClause = (CollateClause *) $7;
    2897          44 :                     def->raw_default = NULL;
    2898          44 :                     def->location = @3;
    2899          44 :                     $$ = (Node *)n;
    2900             :                 }
    2901             :         ;
    2902             : 
    2903             : 
    2904             : /*****************************************************************************
    2905             :  *
    2906             :  *      QUERY :
    2907             :  *              close <portalname>
    2908             :  *
    2909             :  *****************************************************************************/
    2910             : 
    2911             : ClosePortalStmt:
    2912             :             CLOSE cursor_name
    2913             :                 {
    2914        1642 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    2915        1642 :                     n->portalname = $2;
    2916        1642 :                     $$ = (Node *)n;
    2917             :                 }
    2918             :             | CLOSE ALL
    2919             :                 {
    2920           8 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    2921           8 :                     n->portalname = NULL;
    2922           8 :                     $$ = (Node *)n;
    2923             :                 }
    2924             :         ;
    2925             : 
    2926             : 
    2927             : /*****************************************************************************
    2928             :  *
    2929             :  *      QUERY :
    2930             :  *              COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
    2931             :  *              COPY ( query ) TO file  [WITH] [(options)]
    2932             :  *
    2933             :  *              where 'query' can be one of:
    2934             :  *              { SELECT | UPDATE | INSERT | DELETE }
    2935             :  *
    2936             :  *              and 'file' can be one of:
    2937             :  *              { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
    2938             :  *
    2939             :  *              In the preferred syntax the options are comma-separated
    2940             :  *              and use generic identifiers instead of keywords.  The pre-9.0
    2941             :  *              syntax had a hard-wired, space-separated set of options.
    2942             :  *
    2943             :  *              Really old syntax, from versions 7.2 and prior:
    2944             :  *              COPY [ BINARY ] table FROM/TO file
    2945             :  *                  [ [ USING ] DELIMITERS 'delimiter' ] ]
    2946             :  *                  [ WITH NULL AS 'null string' ]
    2947             :  *              This option placement is not supported with COPY (query...).
    2948             :  *
    2949             :  *****************************************************************************/
    2950             : 
    2951             : CopyStmt:   COPY opt_binary qualified_name opt_column_list
    2952             :             copy_from opt_program copy_file_name copy_delimiter opt_with
    2953             :             copy_options where_clause
    2954             :                 {
    2955        3976 :                     CopyStmt *n = makeNode(CopyStmt);
    2956        3976 :                     n->relation = $3;
    2957        3976 :                     n->query = NULL;
    2958        3976 :                     n->attlist = $4;
    2959        3976 :                     n->is_from = $5;
    2960        3976 :                     n->is_program = $6;
    2961        3976 :                     n->filename = $7;
    2962        3976 :                     n->whereClause = $11;
    2963             : 
    2964        3976 :                     if (n->is_program && n->filename == NULL)
    2965           0 :                         ereport(ERROR,
    2966             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    2967             :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    2968             :                                  parser_errposition(@8)));
    2969             : 
    2970        3976 :                     if (!n->is_from && n->whereClause != NULL)
    2971           4 :                         ereport(ERROR,
    2972             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    2973             :                                  errmsg("WHERE clause not allowed with COPY TO"),
    2974             :                                  parser_errposition(@11)));
    2975             : 
    2976        3972 :                     n->options = NIL;
    2977             :                     /* Concatenate user-supplied flags */
    2978        3972 :                     if ($2)
    2979           8 :                         n->options = lappend(n->options, $2);
    2980        3972 :                     if ($8)
    2981           0 :                         n->options = lappend(n->options, $8);
    2982        3972 :                     if ($10)
    2983         220 :                         n->options = list_concat(n->options, $10);
    2984        3972 :                     $$ = (Node *)n;
    2985             :                 }
    2986             :             | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
    2987             :                 {
    2988         194 :                     CopyStmt *n = makeNode(CopyStmt);
    2989         194 :                     n->relation = NULL;
    2990         194 :                     n->query = $3;
    2991         194 :                     n->attlist = NIL;
    2992         194 :                     n->is_from = false;
    2993         194 :                     n->is_program = $6;
    2994         194 :                     n->filename = $7;
    2995         194 :                     n->options = $9;
    2996             : 
    2997         194 :                     if (n->is_program && n->filename == NULL)
    2998           0 :                         ereport(ERROR,
    2999             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3000             :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3001             :                                  parser_errposition(@5)));
    3002             : 
    3003         194 :                     $$ = (Node *)n;
    3004             :                 }
    3005             :         ;
    3006             : 
    3007             : copy_from:
    3008        1066 :             FROM                                    { $$ = true; }
    3009        2910 :             | TO                                    { $$ = false; }
    3010             :         ;
    3011             : 
    3012             : opt_program:
    3013           0 :             PROGRAM                                 { $$ = true; }
    3014        4170 :             | /* EMPTY */                           { $$ = false; }
    3015             :         ;
    3016             : 
    3017             : /*
    3018             :  * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
    3019             :  * used depends on the direction. (It really doesn't make sense to copy from
    3020             :  * stdout. We silently correct the "typo".)        - AY 9/94
    3021             :  */
    3022             : copy_file_name:
    3023         538 :             Sconst                                  { $$ = $1; }
    3024         556 :             | STDIN                                 { $$ = NULL; }
    3025        3076 :             | STDOUT                                { $$ = NULL; }
    3026             :         ;
    3027             : 
    3028        4110 : copy_options: copy_opt_list                         { $$ = $1; }
    3029          60 :             | '(' copy_generic_opt_list ')'         { $$ = $2; }
    3030             :         ;
    3031             : 
    3032             : /* old COPY option syntax */
    3033             : copy_opt_list:
    3034         296 :             copy_opt_list copy_opt_item             { $$ = lappend($1, $2); }
    3035        4110 :             | /* EMPTY */                           { $$ = NIL; }
    3036             :         ;
    3037             : 
    3038             : copy_opt_item:
    3039             :             BINARY
    3040             :                 {
    3041           0 :                     $$ = makeDefElem("format", (Node *)makeString("binary"), @1);
    3042             :                 }
    3043             :             | FREEZE
    3044             :                 {
    3045          28 :                     $$ = makeDefElem("freeze", (Node *)makeInteger(true), @1);
    3046             :                 }
    3047             :             | DELIMITER opt_as Sconst
    3048             :                 {
    3049          84 :                     $$ = makeDefElem("delimiter", (Node *)makeString($3), @1);
    3050             :                 }
    3051             :             | NULL_P opt_as Sconst
    3052             :                 {
    3053          32 :                     $$ = makeDefElem("null", (Node *)makeString($3), @1);
    3054             :                 }
    3055             :             | CSV
    3056             :                 {
    3057          96 :                     $$ = makeDefElem("format", (Node *)makeString("csv"), @1);
    3058             :                 }
    3059             :             | HEADER_P
    3060             :                 {
    3061          12 :                     $$ = makeDefElem("header", (Node *)makeInteger(true), @1);
    3062             :                 }
    3063             :             | QUOTE opt_as Sconst
    3064             :                 {
    3065          12 :                     $$ = makeDefElem("quote", (Node *)makeString($3), @1);
    3066             :                 }
    3067             :             | ESCAPE opt_as Sconst
    3068             :                 {
    3069          12 :                     $$ = makeDefElem("escape", (Node *)makeString($3), @1);
    3070             :                 }
    3071             :             | FORCE QUOTE columnList
    3072             :                 {
    3073           8 :                     $$ = makeDefElem("force_quote", (Node *)$3, @1);
    3074             :                 }
    3075             :             | FORCE QUOTE '*'
    3076             :                 {
    3077           4 :                     $$ = makeDefElem("force_quote", (Node *)makeNode(A_Star), @1);
    3078             :                 }
    3079             :             | FORCE NOT NULL_P columnList
    3080             :                 {
    3081           0 :                     $$ = makeDefElem("force_not_null", (Node *)$4, @1);
    3082             :                 }
    3083             :             | FORCE NULL_P columnList
    3084             :                 {
    3085           0 :                     $$ = makeDefElem("force_null", (Node *)$3, @1);
    3086             :                 }
    3087             :             | ENCODING Sconst
    3088             :                 {
    3089           8 :                     $$ = makeDefElem("encoding", (Node *)makeString($2), @1);
    3090             :                 }
    3091             :         ;
    3092             : 
    3093             : /* The following exist for backward compatibility with very old versions */
    3094             : 
    3095             : opt_binary:
    3096             :             BINARY
    3097             :                 {
    3098           8 :                     $$ = makeDefElem("format", (Node *)makeString("binary"), @1);
    3099             :                 }
    3100        3968 :             | /*EMPTY*/                             { $$ = NULL; }
    3101             :         ;
    3102             : 
    3103             : copy_delimiter:
    3104             :             opt_using DELIMITERS Sconst
    3105             :                 {
    3106           0 :                     $$ = makeDefElem("delimiter", (Node *)makeString($3), @2);
    3107             :                 }
    3108        3976 :             | /*EMPTY*/                             { $$ = NULL; }
    3109             :         ;
    3110             : 
    3111             : opt_using:
    3112             :             USING                                   {}
    3113             :             | /*EMPTY*/                             {}
    3114             :         ;
    3115             : 
    3116             : /* new COPY option syntax */
    3117             : copy_generic_opt_list:
    3118             :             copy_generic_opt_elem
    3119             :                 {
    3120          60 :                     $$ = list_make1($1);
    3121             :                 }
    3122             :             | copy_generic_opt_list ',' copy_generic_opt_elem
    3123             :                 {
    3124          76 :                     $$ = lappend($1, $3);
    3125             :                 }
    3126             :         ;
    3127             : 
    3128             : copy_generic_opt_elem:
    3129             :             ColLabel copy_generic_opt_arg
    3130             :                 {
    3131         136 :                     $$ = makeDefElem($1, $2, @1);
    3132             :                 }
    3133             :         ;
    3134             : 
    3135             : copy_generic_opt_arg:
    3136          84 :             opt_boolean_or_string           { $$ = (Node *) makeString($1); }
    3137           0 :             | NumericOnly                   { $$ = (Node *) $1; }
    3138           8 :             | '*'                           { $$ = (Node *) makeNode(A_Star); }
    3139          40 :             | '(' copy_generic_opt_arg_list ')'     { $$ = (Node *) $2; }
    3140           4 :             | /* EMPTY */                   { $$ = NULL; }
    3141             :         ;
    3142             : 
    3143             : copy_generic_opt_arg_list:
    3144             :               copy_generic_opt_arg_list_item
    3145             :                 {
    3146          40 :                     $$ = list_make1($1);
    3147             :                 }
    3148             :             | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
    3149             :                 {
    3150           8 :                     $$ = lappend($1, $3);
    3151             :                 }
    3152             :         ;
    3153             : 
    3154             : /* beware of emitting non-string list elements here; see commands/define.c */
    3155             : copy_generic_opt_arg_list_item:
    3156          48 :             opt_boolean_or_string   { $$ = (Node *) makeString($1); }
    3157             :         ;
    3158             : 
    3159             : 
    3160             : /*****************************************************************************
    3161             :  *
    3162             :  *      QUERY :
    3163             :  *              CREATE TABLE relname
    3164             :  *
    3165             :  *****************************************************************************/
    3166             : 
    3167             : CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
    3168             :             OptInherit OptPartitionSpec table_access_method_clause OptWith
    3169             :             OnCommitOption OptTableSpace
    3170             :                 {
    3171       17008 :                     CreateStmt *n = makeNode(CreateStmt);
    3172       17008 :                     $4->relpersistence = $2;
    3173       17008 :                     n->relation = $4;
    3174       17008 :                     n->tableElts = $6;
    3175       17008 :                     n->inhRelations = $8;
    3176       17008 :                     n->partspec = $9;
    3177       17008 :                     n->ofTypename = NULL;
    3178       17008 :                     n->constraints = NIL;
    3179       17008 :                     n->accessMethod = $10;
    3180       17008 :                     n->options = $11;
    3181       17008 :                     n->oncommit = $12;
    3182       17008 :                     n->tablespacename = $13;
    3183       17008 :                     n->if_not_exists = false;
    3184       17008 :                     $$ = (Node *)n;
    3185             :                 }
    3186             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
    3187             :             OptTableElementList ')' OptInherit OptPartitionSpec table_access_method_clause
    3188             :             OptWith OnCommitOption OptTableSpace
    3189             :                 {
    3190          18 :                     CreateStmt *n = makeNode(CreateStmt);
    3191          18 :                     $7->relpersistence = $2;
    3192          18 :                     n->relation = $7;
    3193          18 :                     n->tableElts = $9;
    3194          18 :                     n->inhRelations = $11;
    3195          18 :                     n->partspec = $12;
    3196          18 :                     n->ofTypename = NULL;
    3197          18 :                     n->constraints = NIL;
    3198          18 :                     n->accessMethod = $13;
    3199          18 :                     n->options = $14;
    3200          18 :                     n->oncommit = $15;
    3201          18 :                     n->tablespacename = $16;
    3202          18 :                     n->if_not_exists = true;
    3203          18 :                     $$ = (Node *)n;
    3204             :                 }
    3205             :         | CREATE OptTemp TABLE qualified_name OF any_name
    3206             :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3207             :             OptWith OnCommitOption OptTableSpace
    3208             :                 {
    3209          74 :                     CreateStmt *n = makeNode(CreateStmt);
    3210          74 :                     $4->relpersistence = $2;
    3211          74 :                     n->relation = $4;
    3212          74 :                     n->tableElts = $7;
    3213          74 :                     n->inhRelations = NIL;
    3214          74 :                     n->partspec = $8;
    3215          74 :                     n->ofTypename = makeTypeNameFromNameList($6);
    3216          74 :                     n->ofTypename->location = @6;
    3217          74 :                     n->constraints = NIL;
    3218          74 :                     n->accessMethod = $9;
    3219          74 :                     n->options = $10;
    3220          74 :                     n->oncommit = $11;
    3221          74 :                     n->tablespacename = $12;
    3222          74 :                     n->if_not_exists = false;
    3223          74 :                     $$ = (Node *)n;
    3224             :                 }
    3225             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
    3226             :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3227             :             OptWith OnCommitOption OptTableSpace
    3228             :                 {
    3229           4 :                     CreateStmt *n = makeNode(CreateStmt);
    3230           4 :                     $7->relpersistence = $2;
    3231           4 :                     n->relation = $7;
    3232           4 :                     n->tableElts = $10;
    3233           4 :                     n->inhRelations = NIL;
    3234           4 :                     n->partspec = $11;
    3235           4 :                     n->ofTypename = makeTypeNameFromNameList($9);
    3236           4 :                     n->ofTypename->location = @9;
    3237           4 :                     n->constraints = NIL;
    3238           4 :                     n->accessMethod = $12;
    3239           4 :                     n->options = $13;
    3240           4 :                     n->oncommit = $14;
    3241           4 :                     n->tablespacename = $15;
    3242           4 :                     n->if_not_exists = true;
    3243           4 :                     $$ = (Node *)n;
    3244             :                 }
    3245             :         | CREATE OptTemp TABLE qualified_name PARTITION OF qualified_name
    3246             :             OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3247             :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3248             :                 {
    3249        3986 :                     CreateStmt *n = makeNode(CreateStmt);
    3250        3986 :                     $4->relpersistence = $2;
    3251        3986 :                     n->relation = $4;
    3252        3986 :                     n->tableElts = $8;
    3253        3986 :                     n->inhRelations = list_make1($7);
    3254        3986 :                     n->partbound = $9;
    3255        3986 :                     n->partspec = $10;
    3256        3986 :                     n->ofTypename = NULL;
    3257        3986 :                     n->constraints = NIL;
    3258        3986 :                     n->accessMethod = $11;
    3259        3986 :                     n->options = $12;
    3260        3986 :                     n->oncommit = $13;
    3261        3986 :                     n->tablespacename = $14;
    3262        3986 :                     n->if_not_exists = false;
    3263        3986 :                     $$ = (Node *)n;
    3264             :                 }
    3265             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name PARTITION OF
    3266             :             qualified_name OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3267             :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3268             :                 {
    3269           0 :                     CreateStmt *n = makeNode(CreateStmt);
    3270           0 :                     $7->relpersistence = $2;
    3271           0 :                     n->relation = $7;
    3272           0 :                     n->tableElts = $11;
    3273           0 :                     n->inhRelations = list_make1($10);
    3274           0 :                     n->partbound = $12;
    3275           0 :                     n->partspec = $13;
    3276           0 :                     n->ofTypename = NULL;
    3277           0 :                     n->constraints = NIL;
    3278           0 :                     n->accessMethod = $14;
    3279           0 :                     n->options = $15;
    3280           0 :                     n->oncommit = $16;
    3281           0 :                     n->tablespacename = $17;
    3282           0 :                     n->if_not_exists = true;
    3283           0 :                     $$ = (Node *)n;
    3284             :                 }
    3285             :         ;
    3286             : 
    3287             : /*
    3288             :  * Redundancy here is needed to avoid shift/reduce conflicts,
    3289             :  * since TEMP is not a reserved word.  See also OptTempTableName.
    3290             :  *
    3291             :  * NOTE: we accept both GLOBAL and LOCAL options.  They currently do nothing,
    3292             :  * but future versions might consider GLOBAL to request SQL-spec-compliant
    3293             :  * temp table behavior, so warn about that.  Since we have no modules the
    3294             :  * LOCAL keyword is really meaningless; furthermore, some other products
    3295             :  * implement LOCAL as meaning the same as our default temp table behavior,
    3296             :  * so we'll probably continue to treat LOCAL as a noise word.
    3297             :  */
    3298         194 : OptTemp:    TEMPORARY                   { $$ = RELPERSISTENCE_TEMP; }
    3299        1460 :             | TEMP                      { $$ = RELPERSISTENCE_TEMP; }
    3300           0 :             | LOCAL TEMPORARY           { $$ = RELPERSISTENCE_TEMP; }
    3301           0 :             | LOCAL TEMP                { $$ = RELPERSISTENCE_TEMP; }
    3302             :             | GLOBAL TEMPORARY
    3303             :                 {
    3304           0 :                     ereport(WARNING,
    3305             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3306             :                              parser_errposition(@1)));
    3307           0 :                     $$ = RELPERSISTENCE_TEMP;
    3308             :                 }
    3309             :             | GLOBAL TEMP
    3310             :                 {
    3311           0 :                     ereport(WARNING,
    3312             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3313             :                              parser_errposition(@1)));
    3314           0 :                     $$ = RELPERSISTENCE_TEMP;
    3315             :                 }
    3316          74 :             | UNLOGGED                  { $$ = RELPERSISTENCE_UNLOGGED; }
    3317       67824 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    3318             :         ;
    3319             : 
    3320             : OptTableElementList:
    3321       16406 :             TableElementList                    { $$ = $1; }
    3322         892 :             | /*EMPTY*/                         { $$ = NIL; }
    3323             :         ;
    3324             : 
    3325             : OptTypedTableElementList:
    3326         122 :             '(' TypedTableElementList ')'       { $$ = $2; }
    3327        3988 :             | /*EMPTY*/                         { $$ = NIL; }
    3328             :         ;
    3329             : 
    3330             : TableElementList:
    3331             :             TableElement
    3332             :                 {
    3333       16434 :                     $$ = list_make1($1);
    3334             :                 }
    3335             :             | TableElementList ',' TableElement
    3336             :                 {
    3337       28506 :                     $$ = lappend($1, $3);
    3338             :                 }
    3339             :         ;
    3340             : 
    3341             : TypedTableElementList:
    3342             :             TypedTableElement
    3343             :                 {
    3344         122 :                     $$ = list_make1($1);
    3345             :                 }
    3346             :             | TypedTableElementList ',' TypedTableElement
    3347             :                 {
    3348          46 :                     $$ = lappend($1, $3);
    3349             :                 }
    3350             :         ;
    3351             : 
    3352             : TableElement:
    3353       43424 :             columnDef                           { $$ = $1; }
    3354         394 :             | TableLikeClause                   { $$ = $1; }
    3355        1122 :             | TableConstraint                   { $$ = $1; }
    3356             :         ;
    3357             : 
    3358             : TypedTableElement:
    3359         124 :             columnOptions                       { $$ = $1; }
    3360          44 :             | TableConstraint                   { $$ = $1; }
    3361             :         ;
    3362             : 
    3363             : columnDef:  ColId Typename create_generic_options ColQualList
    3364             :                 {
    3365       44646 :                     ColumnDef *n = makeNode(ColumnDef);
    3366       44646 :                     n->colname = $1;
    3367       44646 :                     n->typeName = $2;
    3368       44646 :                     n->inhcount = 0;
    3369       44646 :                     n->is_local = true;
    3370       44646 :                     n->is_not_null = false;
    3371       44646 :                     n->is_from_type = false;
    3372       44646 :                     n->storage = 0;
    3373       44646 :                     n->raw_default = NULL;
    3374       44646 :                     n->cooked_default = NULL;
    3375       44646 :                     n->collOid = InvalidOid;
    3376       44646 :                     n->fdwoptions = $3;
    3377       44646 :                     SplitColQualList($4, &n->constraints, &n->collClause,
    3378             :                                      yyscanner);
    3379       44646 :                     n->location = @1;
    3380       44646 :                     $$ = (Node *)n;
    3381             :                 }
    3382             :         ;
    3383             : 
    3384             : columnOptions:  ColId ColQualList
    3385             :                 {
    3386          78 :                     ColumnDef *n = makeNode(ColumnDef);
    3387          78 :                     n->colname = $1;
    3388          78 :                     n->typeName = NULL;
    3389          78 :                     n->inhcount = 0;
    3390          78 :                     n->is_local = true;
    3391          78 :                     n->is_not_null = false;
    3392          78 :                     n->is_from_type = false;
    3393          78 :                     n->storage = 0;
    3394          78 :                     n->raw_default = NULL;
    3395          78 :                     n->cooked_default = NULL;
    3396          78 :                     n->collOid = InvalidOid;
    3397          78 :                     SplitColQualList($2, &n->constraints, &n->collClause,
    3398             :                                      yyscanner);
    3399          78 :                     n->location = @1;
    3400          78 :                     $$ = (Node *)n;
    3401             :                 }
    3402             :                 | ColId WITH OPTIONS ColQualList
    3403             :                 {
    3404          46 :                     ColumnDef *n = makeNode(ColumnDef);
    3405          46 :                     n->colname = $1;
    3406          46 :                     n->typeName = NULL;
    3407          46 :                     n->inhcount = 0;
    3408          46 :                     n->is_local = true;
    3409          46 :                     n->is_not_null = false;
    3410          46 :                     n->is_from_type = false;
    3411          46 :                     n->storage = 0;
    3412          46 :                     n->raw_default = NULL;
    3413          46 :                     n->cooked_default = NULL;
    3414          46 :                     n->collOid = InvalidOid;
    3415          46 :                     SplitColQualList($4, &n->constraints, &n->collClause,
    3416             :                                      yyscanner);
    3417          46 :                     n->location = @1;
    3418          46 :                     $$ = (Node *)n;
    3419             :                 }
    3420             :         ;
    3421             : 
    3422             : ColQualList:
    3423       12860 :             ColQualList ColConstraint               { $$ = lappend($1, $2); }
    3424       47034 :             | /*EMPTY*/                             { $$ = NIL; }
    3425             :         ;
    3426             : 
    3427             : ColConstraint:
    3428             :             CONSTRAINT name ColConstraintElem
    3429             :                 {
    3430         804 :                     Constraint *n = castNode(Constraint, $3);
    3431         804 :                     n->conname = $2;
    3432         804 :                     n->location = @1;
    3433         804 :                     $$ = (Node *) n;
    3434             :                 }
    3435       11118 :             | ColConstraintElem                     { $$ = $1; }
    3436          74 :             | ConstraintAttr                        { $$ = $1; }
    3437             :             | COLLATE any_name
    3438             :                 {
    3439             :                     /*
    3440             :                      * Note: the CollateClause is momentarily included in
    3441             :                      * the list built by ColQualList, but we split it out
    3442             :                      * again in SplitColQualList.
    3443             :                      */
    3444         864 :                     CollateClause *n = makeNode(CollateClause);
    3445         864 :                     n->arg = NULL;
    3446         864 :                     n->collname = $2;
    3447         864 :                     n->location = @1;
    3448         864 :                     $$ = (Node *) n;
    3449             :                 }
    3450             :         ;
    3451             : 
    3452             : /* DEFAULT NULL is already the default for Postgres.
    3453             :  * But define it here and carry it forward into the system
    3454             :  * to make it explicit.
    3455             :  * - thomas 1998-09-13
    3456             :  *
    3457             :  * WITH NULL and NULL are not SQL-standard syntax elements,
    3458             :  * so leave them out. Use DEFAULT NULL to explicitly indicate
    3459             :  * that a column may have that value. WITH NULL leads to
    3460             :  * shift/reduce conflicts with WITH TIME ZONE anyway.
    3461             :  * - thomas 1999-01-08
    3462             :  *
    3463             :  * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
    3464             :  * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
    3465             :  * or be part of a_expr NOT LIKE or similar constructs).
    3466             :  */
    3467             : ColConstraintElem:
    3468             :             NOT NULL_P
    3469             :                 {
    3470        4650 :                     Constraint *n = makeNode(Constraint);
    3471        4650 :                     n->contype = CONSTR_NOTNULL;
    3472        4650 :                     n->location = @1;
    3473        4650 :                     $$ = (Node *)n;
    3474             :                 }
    3475             :             | NULL_P
    3476             :                 {
    3477          10 :                     Constraint *n = makeNode(Constraint);
    3478          10 :                     n->contype = CONSTR_NULL;
    3479          10 :                     n->location = @1;
    3480          10 :                     $$ = (Node *)n;
    3481             :                 }
    3482             :             | UNIQUE opt_definition OptConsTableSpace
    3483             :                 {
    3484         230 :                     Constraint *n = makeNode(Constraint);
    3485         230 :                     n->contype = CONSTR_UNIQUE;
    3486         230 :                     n->location = @1;
    3487         230 :                     n->keys = NULL;
    3488         230 :                     n->options = $2;
    3489         230 :                     n->indexname = NULL;
    3490         230 :                     n->indexspace = $3;
    3491         230 :                     $$ = (Node *)n;
    3492             :                 }
    3493             :             | PRIMARY KEY opt_definition OptConsTableSpace
    3494             :                 {
    3495        3676 :                     Constraint *n = makeNode(Constraint);
    3496        3676 :                     n->contype = CONSTR_PRIMARY;
    3497        3676 :                     n->location = @1;
    3498        3676 :                     n->keys = NULL;
    3499        3676 :                     n->options = $3;
    3500        3676 :                     n->indexname = NULL;
    3501        3676 :                     n->indexspace = $4;
    3502        3676 :                     $$ = (Node *)n;
    3503             :                 }
    3504             :             | CHECK '(' a_expr ')' opt_no_inherit
    3505             :                 {
    3506        1094 :                     Constraint *n = makeNode(Constraint);
    3507        1094 :                     n->contype = CONSTR_CHECK;
    3508        1094 :                     n->location = @1;
    3509        1094 :                     n->is_no_inherit = $5;
    3510        1094 :                     n->raw_expr = $3;
    3511        1094 :                     n->cooked_expr = NULL;
    3512        1094 :                     n->skip_validation = false;
    3513        1094 :                     n->initially_valid = true;
    3514        1094 :                     $$ = (Node *)n;
    3515             :                 }
    3516             :             | DEFAULT b_expr
    3517             :                 {
    3518        1398 :                     Constraint *n = makeNode(Constraint);
    3519        1398 :                     n->contype = CONSTR_DEFAULT;
    3520        1398 :                     n->location = @1;
    3521        1398 :                     n->raw_expr = $2;
    3522        1398 :                     n->cooked_expr = NULL;
    3523        1398 :                     $$ = (Node *)n;
    3524             :                 }
    3525             :             | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    3526             :                 {
    3527         108 :                     Constraint *n = makeNode(Constraint);
    3528         108 :                     n->contype = CONSTR_IDENTITY;
    3529         108 :                     n->generated_when = $2;
    3530         108 :                     n->options = $5;
    3531         108 :                     n->location = @1;
    3532         108 :                     $$ = (Node *)n;
    3533             :                 }
    3534             :             | GENERATED generated_when AS '(' a_expr ')' STORED
    3535             :                 {
    3536         316 :                     Constraint *n = makeNode(Constraint);
    3537         316 :                     n->contype = CONSTR_GENERATED;
    3538         316 :                     n->generated_when = $2;
    3539         316 :                     n->raw_expr = $5;
    3540         316 :                     n->cooked_expr = NULL;
    3541         316 :                     n->location = @1;
    3542             : 
    3543             :                     /*
    3544             :                      * Can't do this in the grammar because of shift/reduce
    3545             :                      * conflicts.  (IDENTITY allows both ALWAYS and BY
    3546             :                      * DEFAULT, but generated columns only allow ALWAYS.)  We
    3547             :                      * can also give a more useful error message and location.
    3548             :                      */
    3549         316 :                     if ($2 != ATTRIBUTE_IDENTITY_ALWAYS)
    3550           4 :                         ereport(ERROR,
    3551             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3552             :                                  errmsg("for a generated column, GENERATED ALWAYS must be specified"),
    3553             :                                  parser_errposition(@2)));
    3554             : 
    3555         312 :                     $$ = (Node *)n;
    3556             :                 }
    3557             :             | REFERENCES qualified_name opt_column_list key_match key_actions
    3558             :                 {
    3559         444 :                     Constraint *n = makeNode(Constraint);
    3560         444 :                     n->contype = CONSTR_FOREIGN;
    3561         444 :                     n->location = @1;
    3562         444 :                     n->pktable           = $2;
    3563         444 :                     n->fk_attrs          = NIL;
    3564         444 :                     n->pk_attrs          = $3;
    3565         444 :                     n->fk_matchtype      = $4;
    3566         444 :                     n->fk_upd_action = (char) ($5 >> 8);
    3567         444 :                     n->fk_del_action = (char) ($5 & 0xFF);
    3568         444 :                     n->skip_validation  = false;
    3569         444 :                     n->initially_valid  = true;
    3570         444 :                     $$ = (Node *)n;
    3571             :                 }
    3572             :         ;
    3573             : 
    3574             : generated_when:
    3575         440 :             ALWAYS          { $$ = ATTRIBUTE_IDENTITY_ALWAYS; }
    3576          76 :             | BY DEFAULT    { $$ = ATTRIBUTE_IDENTITY_BY_DEFAULT; }
    3577             :         ;
    3578             : 
    3579             : /*
    3580             :  * ConstraintAttr represents constraint attributes, which we parse as if
    3581             :  * they were independent constraint clauses, in order to avoid shift/reduce
    3582             :  * conflicts (since NOT might start either an independent NOT NULL clause
    3583             :  * or an attribute).  parse_utilcmd.c is responsible for attaching the
    3584             :  * attribute information to the preceding "real" constraint node, and for
    3585             :  * complaining if attribute clauses appear in the wrong place or wrong
    3586             :  * combinations.
    3587             :  *
    3588             :  * See also ConstraintAttributeSpec, which can be used in places where
    3589             :  * there is no parsing conflict.  (Note: currently, NOT VALID and NO INHERIT
    3590             :  * are allowed clauses in ConstraintAttributeSpec, but not here.  Someday we
    3591             :  * might need to allow them here too, but for the moment it doesn't seem
    3592             :  * useful in the statements that use ConstraintAttr.)
    3593             :  */
    3594             : ConstraintAttr:
    3595             :             DEFERRABLE
    3596             :                 {
    3597          46 :                     Constraint *n = makeNode(Constraint);
    3598          46 :                     n->contype = CONSTR_ATTR_DEFERRABLE;
    3599          46 :                     n->location = @1;
    3600          46 :                     $$ = (Node *)n;
    3601             :                 }
    3602             :             | NOT DEFERRABLE
    3603             :                 {
    3604           0 :                     Constraint *n = makeNode(Constraint);
    3605           0 :                     n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
    3606           0 :                     n->location = @1;
    3607           0 :                     $$ = (Node *)n;
    3608             :                 }
    3609             :             | INITIALLY DEFERRED
    3610             :                 {
    3611          24 :                     Constraint *n = makeNode(Constraint);
    3612          24 :                     n->contype = CONSTR_ATTR_DEFERRED;
    3613          24 :                     n->location = @1;
    3614          24 :                     $$ = (Node *)n;
    3615             :                 }
    3616             :             | INITIALLY IMMEDIATE
    3617             :                 {
    3618           4 :                     Constraint *n = makeNode(Constraint);
    3619           4 :                     n->contype = CONSTR_ATTR_IMMEDIATE;
    3620           4 :                     n->location = @1;
    3621           4 :                     $$ = (Node *)n;
    3622             :                 }
    3623             :         ;
    3624             : 
    3625             : 
    3626             : TableLikeClause:
    3627             :             LIKE qualified_name TableLikeOptionList
    3628             :                 {
    3629         394 :                     TableLikeClause *n = makeNode(TableLikeClause);
    3630         394 :                     n->relation = $2;
    3631         394 :                     n->options = $3;
    3632         394 :                     $$ = (Node *)n;
    3633             :                 }
    3634             :         ;
    3635             : 
    3636             : TableLikeOptionList:
    3637         138 :                 TableLikeOptionList INCLUDING TableLikeOption   { $$ = $1 | $3; }
    3638           2 :                 | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
    3639         394 :                 | /* EMPTY */                       { $$ = 0; }
    3640             :         ;
    3641             : 
    3642             : TableLikeOption:
    3643          16 :                 COMMENTS            { $$ = CREATE_TABLE_LIKE_COMMENTS; }
    3644          36 :                 | CONSTRAINTS       { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
    3645          14 :                 | DEFAULTS          { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
    3646           4 :                 | IDENTITY_P        { $$ = CREATE_TABLE_LIKE_IDENTITY; }
    3647          16 :                 | GENERATED         { $$ = CREATE_TABLE_LIKE_GENERATED; }
    3648          18 :                 | INDEXES           { $$ = CREATE_TABLE_LIKE_INDEXES; }
    3649           0 :                 | STATISTICS        { $$ = CREATE_TABLE_LIKE_STATISTICS; }
    3650          18 :                 | STORAGE           { $$ = CREATE_TABLE_LIKE_STORAGE; }
    3651          18 :                 | ALL               { $$ = CREATE_TABLE_LIKE_ALL; }
    3652             :         ;
    3653             : 
    3654             : 
    3655             : /* ConstraintElem specifies constraint syntax which is not embedded into
    3656             :  *  a column definition. ColConstraintElem specifies the embedded form.
    3657             :  * - thomas 1997-12-03
    3658             :  */
    3659             : TableConstraint:
    3660             :             CONSTRAINT name ConstraintElem
    3661             :                 {
    3662        1778 :                     Constraint *n = castNode(Constraint, $3);
    3663        1778 :                     n->conname = $2;
    3664        1778 :                     n->location = @1;
    3665        1778 :                     $$ = (Node *) n;
    3666             :                 }
    3667        1306 :             | ConstraintElem                        { $$ = $1; }
    3668             :         ;
    3669             : 
    3670             : ConstraintElem:
    3671             :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    3672             :                 {
    3673         738 :                     Constraint *n = makeNode(Constraint);
    3674         738 :                     n->contype = CONSTR_CHECK;
    3675         738 :                     n->location = @1;
    3676         738 :                     n->raw_expr = $3;
    3677         738 :                     n->cooked_expr = NULL;
    3678         738 :                     processCASbits($5, @5, "CHECK",
    3679             :                                    NULL, NULL, &n->skip_validation,
    3680             :                                    &n->is_no_inherit, yyscanner);
    3681         738 :                     n->initially_valid = !n->skip_validation;
    3682         738 :                     $$ = (Node *)n;
    3683             :                 }
    3684             :             | UNIQUE '(' columnList ')' opt_c_include opt_definition OptConsTableSpace
    3685             :                 ConstraintAttributeSpec
    3686             :                 {
    3687         266 :                     Constraint *n = makeNode(Constraint);
    3688         266 :                     n->contype = CONSTR_UNIQUE;
    3689         266 :                     n->location = @1;
    3690         266 :                     n->keys = $3;
    3691         266 :                     n->including = $5;
    3692         266 :                     n->options = $6;
    3693         266 :                     n->indexname = NULL;
    3694         266 :                     n->indexspace = $7;
    3695         266 :                     processCASbits($8, @8, "UNIQUE",
    3696             :                                    &n->deferrable, &n->initdeferred, NULL,
    3697             :                                    NULL, yyscanner);
    3698         266 :                     $$ = (Node *)n;
    3699             :                 }
    3700             :             | UNIQUE ExistingIndex ConstraintAttributeSpec
    3701             :                 {
    3702          16 :                     Constraint *n = makeNode(Constraint);
    3703          16 :                     n->contype = CONSTR_UNIQUE;
    3704          16 :                     n->location = @1;
    3705          16 :                     n->keys = NIL;
    3706          16 :                     n->including = NIL;
    3707          16 :                     n->options = NIL;
    3708          16 :                     n->indexname = $2;
    3709          16 :                     n->indexspace = NULL;
    3710          16 :                     processCASbits($3, @3, "UNIQUE",
    3711             :                                    &n->deferrable, &n->initdeferred, NULL,
    3712             :                                    NULL, yyscanner);
    3713          16 :                     $$ = (Node *)n;
    3714             :                 }
    3715             :             | PRIMARY KEY '(' columnList ')' opt_c_include opt_definition OptConsTableSpace
    3716             :                 ConstraintAttributeSpec
    3717             :                 {
    3718         998 :                     Constraint *n = makeNode(Constraint);
    3719         998 :                     n->contype = CONSTR_PRIMARY;
    3720         998 :                     n->location = @1;
    3721         998 :                     n->keys = $4;
    3722         998 :                     n->including = $6;
    3723         998 :                     n->options = $7;
    3724         998 :                     n->indexname = NULL;
    3725         998 :                     n->indexspace = $8;
    3726         998 :                     processCASbits($9, @9, "PRIMARY KEY",
    3727             :                                    &n->deferrable, &n->initdeferred, NULL,
    3728             :                                    NULL, yyscanner);
    3729         998 :                     $$ = (Node *)n;
    3730             :                 }
    3731             :             | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
    3732             :                 {
    3733          30 :                     Constraint *n = makeNode(Constraint);
    3734          30 :                     n->contype = CONSTR_PRIMARY;
    3735          30 :                     n->location = @1;
    3736          30 :                     n->keys = NIL;
    3737          30 :                     n->including = NIL;
    3738          30 :                     n->options = NIL;
    3739          30 :                     n->indexname = $3;
    3740          30 :                     n->indexspace = NULL;
    3741          30 :                     processCASbits($4, @4, "PRIMARY KEY",
    3742             :                                    &n->deferrable, &n->initdeferred, NULL,
    3743             :                                    NULL, yyscanner);
    3744          30 :                     $$ = (Node *)n;
    3745             :                 }
    3746             :             | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
    3747             :                 opt_c_include opt_definition OptConsTableSpace  ExclusionWhereClause
    3748             :                 ConstraintAttributeSpec
    3749             :                 {
    3750         100 :                     Constraint *n = makeNode(Constraint);
    3751         100 :                     n->contype = CONSTR_EXCLUSION;
    3752         100 :                     n->location = @1;
    3753         100 :                     n->access_method = $2;
    3754         100 :                     n->exclusions        = $4;
    3755         100 :                     n->including     = $6;
    3756         100 :                     n->options           = $7;
    3757         100 :                     n->indexname     = NULL;
    3758         100 :                     n->indexspace        = $8;
    3759         100 :                     n->where_clause      = $9;
    3760         100 :                     processCASbits($10, @10, "EXCLUDE",
    3761             :                                    &n->deferrable, &n->initdeferred, NULL,
    3762             :                                    NULL, yyscanner);
    3763         100 :                     $$ = (Node *)n;
    3764             :                 }
    3765             :             | FOREIGN KEY '(' columnList ')' REFERENCES qualified_name
    3766             :                 opt_column_list key_match key_actions ConstraintAttributeSpec
    3767             :                 {
    3768         936 :                     Constraint *n = makeNode(Constraint);
    3769         936 :                     n->contype = CONSTR_FOREIGN;
    3770         936 :                     n->location = @1;
    3771         936 :                     n->pktable           = $7;
    3772         936 :                     n->fk_attrs          = $4;
    3773         936 :                     n->pk_attrs          = $8;
    3774         936 :                     n->fk_matchtype      = $9;
    3775         936 :                     n->fk_upd_action = (char) ($10 >> 8);
    3776         936 :                     n->fk_del_action = (char) ($10 & 0xFF);
    3777         936 :                     processCASbits($11, @11, "FOREIGN KEY",
    3778             :                                    &n->deferrable, &n->initdeferred,
    3779             :                                    &n->skip_validation, NULL,
    3780             :                                    yyscanner);
    3781         936 :                     n->initially_valid = !n->skip_validation;
    3782         936 :                     $$ = (Node *)n;
    3783             :                 }
    3784             :         ;
    3785             : 
    3786           8 : opt_no_inherit: NO INHERIT                          {  $$ = true; }
    3787        1086 :             | /* EMPTY */                           {  $$ = false; }
    3788             :         ;
    3789             : 
    3790             : opt_column_list:
    3791        4486 :             '(' columnList ')'                      { $$ = $2; }
    3792       92024 :             | /*EMPTY*/                             { $$ = NIL; }
    3793             :         ;
    3794             : 
    3795             : columnList:
    3796        6918 :             columnElem                              { $$ = list_make1($1); }
    3797       13018 :             | columnList ',' columnElem             { $$ = lappend($1, $3); }
    3798             :         ;
    3799             : 
    3800             : columnElem: ColId
    3801             :                 {
    3802       19936 :                     $$ = (Node *) makeString($1);
    3803             :                 }
    3804             :         ;
    3805             : 
    3806         136 : opt_c_include:  INCLUDE '(' columnList ')'          { $$ = $3; }
    3807        1228 :              |      /* EMPTY */                     { $$ = NIL; }
    3808             :         ;
    3809             : 
    3810             : key_match:  MATCH FULL
    3811             :             {
    3812          66 :                 $$ = FKCONSTR_MATCH_FULL;
    3813             :             }
    3814             :         | MATCH PARTIAL
    3815             :             {
    3816           0 :                 ereport(ERROR,
    3817             :                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    3818             :                          errmsg("MATCH PARTIAL not yet implemented"),
    3819             :                          parser_errposition(@1)));
    3820             :                 $$ = FKCONSTR_MATCH_PARTIAL;
    3821             :             }
    3822             :         | MATCH SIMPLE
    3823             :             {
    3824           4 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    3825             :             }
    3826             :         | /*EMPTY*/
    3827             :             {
    3828        1310 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    3829             :             }
    3830             :         ;
    3831             : 
    3832             : ExclusionConstraintList:
    3833         100 :             ExclusionConstraintElem                 { $$ = list_make1($1); }
    3834             :             | ExclusionConstraintList ',' ExclusionConstraintElem
    3835          22 :                                                     { $$ = lappend($1, $3); }
    3836             :         ;
    3837             : 
    3838             : ExclusionConstraintElem: index_elem WITH any_operator
    3839             :             {
    3840         122 :                 $$ = list_make2($1, $3);
    3841             :             }
    3842             :             /* allow OPERATOR() decoration for the benefit of ruleutils.c */
    3843             :             | index_elem WITH OPERATOR '(' any_operator ')'
    3844             :             {
    3845           0 :                 $$ = list_make2($1, $5);
    3846             :             }
    3847             :         ;
    3848             : 
    3849             : ExclusionWhereClause:
    3850          24 :             WHERE '(' a_expr ')'                    { $$ = $3; }
    3851          76 :             | /*EMPTY*/                             { $$ = NULL; }
    3852             :         ;
    3853             : 
    3854             : /*
    3855             :  * We combine the update and delete actions into one value temporarily
    3856             :  * for simplicity of parsing, and then break them down again in the
    3857             :  * calling production.  update is in the left 8 bits, delete in the right.
    3858             :  * Note that NOACTION is the default.
    3859             :  */
    3860             : key_actions:
    3861             :             key_update
    3862          18 :                 { $$ = ($1 << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
    3863             :             | key_delete
    3864          40 :                 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | ($1 & 0xFF); }
    3865             :             | key_update key_delete
    3866          74 :                 { $$ = ($1 << 8) | ($2 & 0xFF); }
    3867             :             | key_delete key_update
    3868          60 :                 { $$ = ($2 << 8) | ($1 & 0xFF); }
    3869             :             | /*EMPTY*/
    3870        1188 :                 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
    3871             :         ;
    3872             : 
    3873         152 : key_update: ON UPDATE key_action        { $$ = $3; }
    3874             :         ;
    3875             : 
    3876         174 : key_delete: ON DELETE_P key_action      { $$ = $3; }
    3877             :         ;
    3878             : 
    3879             : key_action:
    3880          32 :             NO ACTION                   { $$ = FKCONSTR_ACTION_NOACTION; }
    3881          16 :             | RESTRICT                  { $$ = FKCONSTR_ACTION_RESTRICT; }
    3882         172 :             | CASCADE                   { $$ = FKCONSTR_ACTION_CASCADE; }
    3883          70 :             | SET NULL_P                { $$ = FKCONSTR_ACTION_SETNULL; }
    3884          36 :             | SET DEFAULT               { $$ = FKCONSTR_ACTION_SETDEFAULT; }
    3885             :         ;
    3886             : 
    3887        1008 : OptInherit: INHERITS '(' qualified_name_list ')'    { $$ = $3; }
    3888       16278 :             | /*EMPTY*/                             { $$ = NIL; }
    3889             :         ;
    3890             : 
    3891             : /* Optional partition key specification */
    3892        2440 : OptPartitionSpec: PartitionSpec { $$ = $1; }
    3893       18658 :             | /*EMPTY*/         { $$ = NULL; }
    3894             :         ;
    3895             : 
    3896             : PartitionSpec: PARTITION BY ColId '(' part_params ')'
    3897             :                 {
    3898        2440 :                     PartitionSpec *n = makeNode(PartitionSpec);
    3899             : 
    3900        2440 :                     n->strategy = $3;
    3901        2440 :                     n->partParams = $5;
    3902        2440 :                     n->location = @1;
    3903             : 
    3904        2440 :                     $$ = n;
    3905             :                 }
    3906             :         ;
    3907             : 
    3908        2440 : part_params:    part_elem                       { $$ = list_make1($1); }
    3909         224 :             | part_params ',' part_elem         { $$ = lappend($1, $3); }
    3910             :         ;
    3911             : 
    3912             : part_elem: ColId opt_collate opt_class
    3913             :                 {
    3914        2468 :                     PartitionElem *n = makeNode(PartitionElem);
    3915             : 
    3916        2468 :                     n->name = $1;
    3917        2468 :                     n->expr = NULL;
    3918        2468 :                     n->collation = $2;
    3919        2468 :                     n->opclass = $3;
    3920        2468 :                     n->location = @1;
    3921        2468 :                     $$ = n;
    3922             :                 }
    3923             :             | func_expr_windowless opt_collate opt_class
    3924             :                 {
    3925          88 :                     PartitionElem *n = makeNode(PartitionElem);
    3926             : 
    3927          88 :                     n->name = NULL;
    3928          88 :                     n->expr = $1;
    3929          88 :                     n->collation = $2;
    3930          88 :                     n->opclass = $3;
    3931          88 :                     n->location = @1;
    3932          88 :                     $$ = n;
    3933             :                 }
    3934             :             | '(' a_expr ')' opt_collate opt_class
    3935             :                 {
    3936         108 :                     PartitionElem *n = makeNode(PartitionElem);
    3937             : 
    3938         108 :                     n->name = NULL;
    3939         108 :                     n->expr = $2;
    3940         108 :                     n->collation = $4;
    3941         108 :                     n->opclass = $5;
    3942         108 :                     n->location = @1;
    3943         108 :                     $$ = n;
    3944             :                 }
    3945             :         ;
    3946             : 
    3947             : table_access_method_clause:
    3948          64 :             USING access_method                 { $$ = $2; }
    3949       21892 :             | /*EMPTY*/                         { $$ = NULL; }
    3950             :         ;
    3951             : 
    3952             : /* WITHOUT OIDS is legacy only */
    3953             : OptWith:
    3954         228 :             WITH reloptions             { $$ = $2; }
    3955          16 :             | WITHOUT OIDS              { $$ = NIL; }
    3956       21494 :             | /*EMPTY*/                 { $$ = NIL; }
    3957             :         ;
    3958             : 
    3959          34 : OnCommitOption:  ON COMMIT DROP             { $$ = ONCOMMIT_DROP; }
    3960          66 :             | ON COMMIT DELETE_P ROWS       { $$ = ONCOMMIT_DELETE_ROWS; }
    3961          16 :             | ON COMMIT PRESERVE ROWS       { $$ = ONCOMMIT_PRESERVE_ROWS; }
    3962       21622 :             | /*EMPTY*/                     { $$ = ONCOMMIT_NOOP; }
    3963             :         ;
    3964             : 
    3965         124 : OptTableSpace:   TABLESPACE name                    { $$ = $2; }
    3966       25074 :             | /*EMPTY*/                             { $$ = NULL; }
    3967             :         ;
    3968             : 
    3969          42 : OptConsTableSpace:   USING INDEX TABLESPACE name    { $$ = $4; }
    3970        5228 :             | /*EMPTY*/                             { $$ = NULL; }
    3971             :         ;
    3972             : 
    3973          46 : ExistingIndex:   USING INDEX index_name             { $$ = $3; }
    3974             :         ;
    3975             : 
    3976             : /*****************************************************************************
    3977             :  *
    3978             :  *      QUERY :
    3979             :  *              CREATE STATISTICS [IF NOT EXISTS] stats_name [(stat types)]
    3980             :  *                  ON expression-list FROM from_list
    3981             :  *
    3982             :  * Note: the expectation here is that the clauses after ON are a subset of
    3983             :  * SELECT syntax, allowing for expressions and joined tables, and probably
    3984             :  * someday a WHERE clause.  Much less than that is currently implemented,
    3985             :  * but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
    3986             :  * errors as necessary at execution.
    3987             :  *
    3988             :  *****************************************************************************/
    3989             : 
    3990             : CreateStatsStmt:
    3991             :             CREATE STATISTICS any_name
    3992             :             opt_name_list ON expr_list FROM from_list
    3993             :                 {
    3994         184 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    3995         184 :                     n->defnames = $3;
    3996         184 :                     n->stat_types = $4;
    3997         184 :                     n->exprs = $6;
    3998         184 :                     n->relations = $8;
    3999         184 :                     n->stxcomment = NULL;
    4000         184 :                     n->if_not_exists = false;
    4001         184 :                     $$ = (Node *)n;
    4002             :                 }
    4003             :             | CREATE STATISTICS IF_P NOT EXISTS any_name
    4004             :             opt_name_list ON expr_list FROM from_list
    4005             :                 {
    4006           8 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4007           8 :                     n->defnames = $6;
    4008           8 :                     n->stat_types = $7;
    4009           8 :                     n->exprs = $9;
    4010           8 :                     n->relations = $11;
    4011           8 :                     n->stxcomment = NULL;
    4012           8 :                     n->if_not_exists = true;
    4013           8 :                     $$ = (Node *)n;
    4014             :                 }
    4015             :             ;
    4016             : 
    4017             : 
    4018             : /*****************************************************************************
    4019             :  *
    4020             :  *      QUERY :
    4021             :  *              ALTER STATISTICS [IF EXISTS] stats_name
    4022             :  *                  SET STATISTICS  <SignedIconst>
    4023             :  *
    4024             :  *****************************************************************************/
    4025             : 
    4026             : AlterStatsStmt:
    4027             :             ALTER STATISTICS any_name SET STATISTICS SignedIconst
    4028             :                 {
    4029          14 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4030          14 :                     n->defnames = $3;
    4031          14 :                     n->missing_ok = false;
    4032          14 :                     n->stxstattarget = $6;
    4033          14 :                     $$ = (Node *)n;
    4034             :                 }
    4035             :             | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS SignedIconst
    4036             :                 {
    4037           4 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4038           4 :                     n->defnames = $5;
    4039           4 :                     n->missing_ok = true;
    4040           4 :                     n->stxstattarget = $8;
    4041           4 :                     $$ = (Node *)n;
    4042             :                 }
    4043             :             ;
    4044             : 
    4045             : /*****************************************************************************
    4046             :  *
    4047             :  *      QUERY :
    4048             :  *              CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
    4049             :  *
    4050             :  *
    4051             :  * Note: SELECT ... INTO is a now-deprecated alternative for this.
    4052             :  *
    4053             :  *****************************************************************************/
    4054             : 
    4055             : CreateAsStmt:
    4056             :         CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
    4057             :                 {
    4058         608 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4059         608 :                     ctas->query = $6;
    4060         608 :                     ctas->into = $4;
    4061         608 :                     ctas->relkind = OBJECT_TABLE;
    4062         608 :                     ctas->is_select_into = false;
    4063         608 :                     ctas->if_not_exists = false;
    4064             :                     /* cram additional flags into the IntoClause */
    4065         608 :                     $4->rel->relpersistence = $2;
    4066         608 :                     $4->skipData = !($7);
    4067         608 :                     $$ = (Node *) ctas;
    4068             :                 }
    4069             :         | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
    4070             :                 {
    4071           8 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4072           8 :                     ctas->query = $9;
    4073           8 :                     ctas->into = $7;
    4074           8 :                     ctas->relkind = OBJECT_TABLE;
    4075           8 :                     ctas->is_select_into = false;
    4076           8 :                     ctas->if_not_exists = true;
    4077             :                     /* cram additional flags into the IntoClause */
    4078           8 :                     $7->rel->relpersistence = $2;
    4079           8 :                     $7->skipData = !($10);
    4080           8 :                     $$ = (Node *) ctas;
    4081             :                 }
    4082             :         ;
    4083             : 
    4084             : create_as_target:
    4085             :             qualified_name opt_column_list table_access_method_clause
    4086             :             OptWith OnCommitOption OptTableSpace
    4087             :                 {
    4088         648 :                     $$ = makeNode(IntoClause);
    4089         648 :                     $$->rel = $1;
    4090         648 :                     $$->colNames = $2;
    4091         648 :                     $$->accessMethod = $3;
    4092         648 :                     $$->options = $4;
    4093         648 :                     $$->onCommit = $5;
    4094         648 :                     $$->tableSpaceName = $6;
    4095         648 :                     $$->viewQuery = NULL;
    4096         648 :                     $$->skipData = false;        /* might get changed later */
    4097             :                 }
    4098             :         ;
    4099             : 
    4100             : opt_with_data:
    4101           0 :             WITH DATA_P                             { $$ = true; }
    4102          88 :             | WITH NO DATA_P                        { $$ = false; }
    4103         864 :             | /*EMPTY*/                             { $$ = true; }
    4104             :         ;
    4105             : 
    4106             : 
    4107             : /*****************************************************************************
    4108             :  *
    4109             :  *      QUERY :
    4110             :  *              CREATE MATERIALIZED VIEW relname AS SelectStmt
    4111             :  *
    4112             :  *****************************************************************************/
    4113             : 
    4114             : CreateMatViewStmt:
    4115             :         CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
    4116             :                 {
    4117         210 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4118         210 :                     ctas->query = $7;
    4119         210 :                     ctas->into = $5;
    4120         210 :                     ctas->relkind = OBJECT_MATVIEW;
    4121         210 :                     ctas->is_select_into = false;
    4122         210 :                     ctas->if_not_exists = false;
    4123             :                     /* cram additional flags into the IntoClause */
    4124         210 :                     $5->rel->relpersistence = $2;
    4125         210 :                     $5->skipData = !($8);
    4126         210 :                     $$ = (Node *) ctas;
    4127             :                 }
    4128             :         | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
    4129             :                 {
    4130           4 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4131           4 :                     ctas->query = $10;
    4132           4 :                     ctas->into = $8;
    4133           4 :                     ctas->relkind = OBJECT_MATVIEW;
    4134           4 :                     ctas->is_select_into = false;
    4135           4 :                     ctas->if_not_exists = true;
    4136             :                     /* cram additional flags into the IntoClause */
    4137           4 :                     $8->rel->relpersistence = $2;
    4138           4 :                     $8->skipData = !($11);
    4139           4 :                     $$ = (Node *) ctas;
    4140             :                 }
    4141             :         ;
    4142             : 
    4143             : create_mv_target:
    4144             :             qualified_name opt_column_list table_access_method_clause opt_reloptions OptTableSpace
    4145             :                 {
    4146         214 :                     $$ = makeNode(IntoClause);
    4147         214 :                     $$->rel = $1;
    4148         214 :                     $$->colNames = $2;
    4149         214 :                     $$->accessMethod = $3;
    4150         214 :                     $$->options = $4;
    4151         214 :                     $$->onCommit = ONCOMMIT_NOOP;
    4152         214 :                     $$->tableSpaceName = $5;
    4153         214 :                     $$->viewQuery = NULL;        /* filled at analysis time */
    4154         214 :                     $$->skipData = false;        /* might get changed later */
    4155             :                 }
    4156             :         ;
    4157             : 
    4158           0 : OptNoLog:   UNLOGGED                    { $$ = RELPERSISTENCE_UNLOGGED; }
    4159         214 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    4160             :         ;
    4161             : 
    4162             : 
    4163             : /*****************************************************************************
    4164             :  *
    4165             :  *      QUERY :
    4166             :  *              REFRESH MATERIALIZED VIEW qualified_name
    4167             :  *
    4168             :  *****************************************************************************/
    4169             : 
    4170             : RefreshMatViewStmt:
    4171             :             REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
    4172             :                 {
    4173          90 :                     RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
    4174          90 :                     n->concurrent = $4;
    4175          90 :                     n->relation = $5;
    4176          90 :                     n->skipData = !($6);
    4177          90 :                     $$ = (Node *) n;
    4178             :                 }
    4179             :         ;
    4180             : 
    4181             : 
    4182             : /*****************************************************************************
    4183             :  *
    4184             :  *      QUERY :
    4185             :  *              CREATE SEQUENCE seqname
    4186             :  *              ALTER SEQUENCE seqname
    4187             :  *
    4188             :  *****************************************************************************/
    4189             : 
    4190             : CreateSeqStmt:
    4191             :             CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
    4192             :                 {
    4193         360 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    4194         360 :                     $4->relpersistence = $2;
    4195         360 :                     n->sequence = $4;
    4196         360 :                     n->options = $5;
    4197         360 :                     n->ownerId = InvalidOid;
    4198         360 :                     n->if_not_exists = false;
    4199         360 :                     $$ = (Node *)n;
    4200             :                 }
    4201             :             | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
    4202             :                 {
    4203           4 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    4204           4 :                     $7->relpersistence = $2;
    4205           4 :                     n->sequence = $7;
    4206           4 :                     n->options = $8;
    4207           4 :                     n->ownerId = InvalidOid;
    4208           4 :                     n->if_not_exists = true;
    4209           4 :                     $$ = (Node *)n;
    4210             :                 }
    4211             :         ;
    4212             : 
    4213             : AlterSeqStmt:
    4214             :             ALTER SEQUENCE qualified_name SeqOptList
    4215             :                 {
    4216         120 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    4217         120 :                     n->sequence = $3;
    4218         120 :                     n->options = $4;
    4219         120 :                     n->missing_ok = false;
    4220         120 :                     $$ = (Node *)n;
    4221             :                 }
    4222             :             | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
    4223             :                 {
    4224           8 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    4225           8 :                     n->sequence = $5;
    4226           8 :                     n->options = $6;
    4227           8 :                     n->missing_ok = true;
    4228           8 :                     $$ = (Node *)n;
    4229             :                 }
    4230             : 
    4231             :         ;
    4232             : 
    4233         172 : OptSeqOptList: SeqOptList                           { $$ = $1; }
    4234         192 :             | /*EMPTY*/                             { $$ = NIL; }
    4235             :         ;
    4236             : 
    4237          36 : OptParenthesizedSeqOptList: '(' SeqOptList ')'      { $$ = $2; }
    4238         148 :             | /*EMPTY*/                             { $$ = NIL; }
    4239             :         ;
    4240             : 
    4241         336 : SeqOptList: SeqOptElem                              { $$ = list_make1($1); }
    4242         542 :             | SeqOptList SeqOptElem                 { $$ = lappend($1, $2); }
    4243             :         ;
    4244             : 
    4245             : SeqOptElem: AS SimpleTypename
    4246             :                 {
    4247         128 :                     $$ = makeDefElem("as", (Node *)$2, @1);
    4248             :                 }
    4249             :             | CACHE NumericOnly
    4250             :                 {
    4251          88 :                     $$ = makeDefElem("cache", (Node *)$2, @1);
    4252             :                 }
    4253             :             | CYCLE
    4254             :                 {
    4255          24 :                     $$ = makeDefElem("cycle", (Node *)makeInteger(true), @1);
    4256             :                 }
    4257             :             | NO CYCLE
    4258             :                 {
    4259          10 :                     $$ = makeDefElem("cycle", (Node *)makeInteger(false), @1);
    4260             :                 }
    4261             :             | INCREMENT opt_by NumericOnly
    4262             :                 {
    4263         154 :                     $$ = makeDefElem("increment", (Node *)$3, @1);
    4264             :                 }
    4265             :             | MAXVALUE NumericOnly
    4266             :                 {
    4267          50 :                     $$ = makeDefElem("maxvalue", (Node *)$2, @1);
    4268             :                 }
    4269             :             | MINVALUE NumericOnly
    4270             :                 {
    4271          50 :                     $$ = makeDefElem("minvalue", (Node *)$2, @1);
    4272             :                 }
    4273             :             | NO MAXVALUE
    4274             :                 {
    4275          70 :                     $$ = makeDefElem("maxvalue", NULL, @1);
    4276             :                 }
    4277             :             | NO MINVALUE
    4278             :                 {
    4279          70 :                     $$ = makeDefElem("minvalue", NULL, @1);
    4280             :                 }
    4281             :             | OWNED BY any_name
    4282             :                 {
    4283          44 :                     $$ = makeDefElem("owned_by", (Node *)$3, @1);
    4284             :                 }
    4285             :             | SEQUENCE NAME_P any_name
    4286             :                 {
    4287             :                     /* not documented, only used by pg_dump */
    4288          28 :                     $$ = makeDefElem("sequence_name", (Node *)$3, @1);
    4289             :                 }
    4290             :             | START opt_with NumericOnly
    4291             :                 {
    4292         134 :                     $$ = makeDefElem("start", (Node *)$3, @1);
    4293             :                 }
    4294             :             | RESTART
    4295             :                 {
    4296           4 :                     $$ = makeDefElem("restart", NULL, @1);
    4297             :                 }
    4298             :             | RESTART opt_with NumericOnly
    4299             :                 {
    4300          40 :                     $$ = makeDefElem("restart", (Node *)$3, @1);
    4301             :                 }
    4302             :         ;
    4303             : 
    4304             : opt_by:     BY              {}
    4305             :             | /* empty */   {}
    4306             :       ;
    4307             : 
    4308             : NumericOnly:
    4309         162 :             FCONST                              { $$ = makeFloat($1); }
    4310           0 :             | '+' FCONST                        { $$ = makeFloat($2); }
    4311             :             | '-' FCONST
    4312             :                 {
    4313          14 :                     $$ = makeFloat($2);
    4314          14 :                     doNegateFloat($$);
    4315             :                 }
    4316        6526 :             | SignedIconst                      { $$ = makeInteger($1); }
    4317             :         ;
    4318             : 
    4319          50 : NumericOnly_list:   NumericOnly                     { $$ = list_make1($1); }
    4320           4 :                 | NumericOnly_list ',' NumericOnly  { $$ = lappend($1, $3); }
    4321             :         ;
    4322             : 
    4323             : /*****************************************************************************
    4324             :  *
    4325             :  *      QUERIES :
    4326             :  *              CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
    4327             :  *              DROP [PROCEDURAL] LANGUAGE ...
    4328             :  *
    4329             :  *****************************************************************************/
    4330             : 
    4331             : CreatePLangStmt:
    4332             :             CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE NonReservedWord_or_Sconst
    4333             :             {
    4334             :                 /*
    4335             :                  * We now interpret parameterless CREATE LANGUAGE as
    4336             :                  * CREATE EXTENSION.  "OR REPLACE" is silently translated
    4337             :                  * to "IF NOT EXISTS", which isn't quite the same, but
    4338             :                  * seems more useful than throwing an error.  We just
    4339             :                  * ignore TRUSTED, as the previous code would have too.
    4340             :                  */
    4341           0 :                 CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    4342           0 :                 n->if_not_exists = $2;
    4343           0 :                 n->extname = $6;
    4344           0 :                 n->options = NIL;
    4345           0 :                 $$ = (Node *)n;
    4346             :             }
    4347             :             | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE NonReservedWord_or_Sconst
    4348             :               HANDLER handler_name opt_inline_handler opt_validator
    4349             :             {
    4350         406 :                 CreatePLangStmt *n = makeNode(CreatePLangStmt);
    4351         406 :                 n->replace = $2;
    4352         406 :                 n->plname = $6;
    4353         406 :                 n->plhandler = $8;
    4354         406 :                 n->plinline = $9;
    4355         406 :                 n->plvalidator = $10;
    4356         406 :                 n->pltrusted = $3;
    4357         406 :                 $$ = (Node *)n;
    4358             :             }
    4359             :         ;
    4360             : 
    4361             : opt_trusted:
    4362         372 :             TRUSTED                                 { $$ = true; }
    4363          38 :             | /*EMPTY*/                             { $$ = false; }
    4364             :         ;
    4365             : 
    4366             : /* This ought to be just func_name, but that causes reduce/reduce conflicts
    4367             :  * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
    4368             :  * Work around by using simple names, instead.
    4369             :  */
    4370             : handler_name:
    4371        1306 :             name                        { $$ = list_make1(makeString($1)); }
    4372           2 :             | name attrs                { $$ = lcons(makeString($1), $2); }
    4373             :         ;
    4374             : 
    4375             : opt_inline_handler:
    4376         394 :             INLINE_P handler_name                   { $$ = $2; }
    4377          12 :             | /*EMPTY*/                             { $$ = NIL; }
    4378             :         ;
    4379             : 
    4380             : validator_clause:
    4381         394 :             VALIDATOR handler_name                  { $$ = $2; }
    4382           0 :             | NO VALIDATOR                          { $$ = NIL; }
    4383             :         ;
    4384             : 
    4385             : opt_validator:
    4386         394 :             validator_clause                        { $$ = $1; }
    4387          12 :             | /*EMPTY*/                             { $$ = NIL; }
    4388             :         ;
    4389             : 
    4390             : DropPLangStmt:
    4391             :             DROP opt_procedural LANGUAGE NonReservedWord_or_Sconst opt_drop_behavior
    4392             :                 {
    4393          14 :                     DropStmt *n = makeNode(DropStmt);
    4394          14 :                     n->removeType = OBJECT_LANGUAGE;
    4395          14 :                     n->objects = list_make1(makeString($4));
    4396          14 :                     n->behavior = $5;
    4397          14 :                     n->missing_ok = false;
    4398          14 :                     n->concurrent = false;
    4399          14 :                     $$ = (Node *)n;
    4400             :                 }
    4401             :             | DROP opt_procedural LANGUAGE IF_P EXISTS NonReservedWord_or_Sconst opt_drop_behavior
    4402             :                 {
    4403           4 :                     DropStmt *n = makeNode(DropStmt);
    4404           4 :                     n->removeType = OBJECT_LANGUAGE;
    4405           4 :                     n->objects = list_make1(makeString($6));
    4406           4 :                     n->behavior = $7;
    4407           4 :                     n->missing_ok = true;
    4408           4 :                     n->concurrent = false;
    4409           4 :                     $$ = (Node *)n;
    4410             :                 }
    4411             :         ;
    4412             : 
    4413             : opt_procedural:
    4414             :             PROCEDURAL                              {}
    4415             :             | /*EMPTY*/                             {}
    4416             :         ;
    4417             : 
    4418             : /*****************************************************************************
    4419             :  *
    4420             :  *      QUERY:
    4421             :  *             CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
    4422             :  *
    4423             :  *****************************************************************************/
    4424             : 
    4425             : CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
    4426             :                 {
    4427          38 :                     CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
    4428          38 :                     n->tablespacename = $3;
    4429          38 :                     n->owner = $4;
    4430          38 :                     n->location = $6;
    4431          38 :                     n->options = $7;
    4432          38 :                     $$ = (Node *) n;
    4433             :                 }
    4434             :         ;
    4435             : 
    4436           0 : OptTableSpaceOwner: OWNER RoleSpec      { $$ = $2; }
    4437          38 :             | /*EMPTY */                { $$ = NULL; }
    4438             :         ;
    4439             : 
    4440             : /*****************************************************************************
    4441             :  *
    4442             :  *      QUERY :
    4443             :  *              DROP TABLESPACE <tablespace>
    4444             :  *
    4445             :  *      No need for drop behaviour as we cannot implement dependencies for
    4446             :  *      objects in other databases; we can only support RESTRICT.
    4447             :  *
    4448             :  ****************************************************************************/
    4449             : 
    4450             : DropTableSpaceStmt: DROP TABLESPACE name
    4451             :                 {
    4452          20 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    4453          20 :                     n->tablespacename = $3;
    4454          20 :                     n->missing_ok = false;
    4455          20 :                     $$ = (Node *) n;
    4456             :                 }
    4457             :                 |  DROP TABLESPACE IF_P EXISTS name
    4458             :                 {
    4459           0 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    4460           0 :                     n->tablespacename = $5;
    4461           0 :                     n->missing_ok = true;
    4462           0 :                     $$ = (Node *) n;
    4463             :                 }
    4464             :         ;
    4465             : 
    4466             : /*****************************************************************************
    4467             :  *
    4468             :  *      QUERY:
    4469             :  *             CREATE EXTENSION extension
    4470             :  *             [ WITH ] [ SCHEMA schema ] [ VERSION version ]
    4471             :  *
    4472             :  *****************************************************************************/
    4473             : 
    4474             : CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
    4475             :                 {
    4476         530 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    4477         530 :                     n->extname = $3;
    4478         530 :                     n->if_not_exists = false;
    4479         530 :                     n->options = $5;
    4480         530 :                     $$ = (Node *) n;
    4481             :                 }
    4482             :                 | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
    4483             :                 {
    4484          24 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    4485          24 :                     n->extname = $6;
    4486          24 :                     n->if_not_exists = true;
    4487          24 :                     n->options = $8;
    4488          24 :                     $$ = (Node *) n;
    4489             :                 }
    4490             :         ;
    4491             : 
    4492             : create_extension_opt_list:
    4493             :             create_extension_opt_list create_extension_opt_item
    4494          48 :                 { $$ = lappend($1, $2); }
    4495             :             | /* EMPTY */
    4496         554 :                 { $$ = NIL; }
    4497             :         ;
    4498             : 
    4499             : create_extension_opt_item:
    4500             :             SCHEMA name
    4501             :                 {
    4502          24 :                     $$ = makeDefElem("schema", (Node *)makeString($2), @1);
    4503             :                 }
    4504             :             | VERSION_P NonReservedWord_or_Sconst
    4505             :                 {
    4506           0 :                     $$ = makeDefElem("new_version", (Node *)makeString($2), @1);
    4507             :                 }
    4508             :             | FROM NonReservedWord_or_Sconst
    4509             :                 {
    4510           0 :                     ereport(ERROR,
    4511             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4512             :                              errmsg("CREATE EXTENSION ... FROM is no longer supported"),
    4513             :                              parser_errposition(@1)));
    4514             :                 }
    4515             :             | CASCADE
    4516             :                 {
    4517          24 :                     $$ = makeDefElem("cascade", (Node *)makeInteger(true), @1);
    4518             :                 }
    4519             :         ;
    4520             : 
    4521             : /*****************************************************************************
    4522             :  *
    4523             :  * ALTER EXTENSION name UPDATE [ TO version ]
    4524             :  *
    4525             :  *****************************************************************************/
    4526             : 
    4527             : AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
    4528             :                 {
    4529           2 :                     AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
    4530           2 :                     n->extname = $3;
    4531           2 :                     n->options = $5;
    4532           2 :                     $$ = (Node *) n;
    4533             :                 }
    4534             :         ;
    4535             : 
    4536             : alter_extension_opt_list:
    4537             :             alter_extension_opt_list alter_extension_opt_item
    4538           2 :                 { $$ = lappend($1, $2); }
    4539             :             | /* EMPTY */
    4540           2 :                 { $$ = NIL; }
    4541             :         ;
    4542             : 
    4543             : alter_extension_opt_item:
    4544             :             TO NonReservedWord_or_Sconst
    4545             :                 {
    4546           2 :                     $$ = makeDefElem("new_version", (Node *)makeString($2), @1);
    4547             :                 }
    4548             :         ;
    4549             : 
    4550             : /*****************************************************************************
    4551             :  *
    4552             :  * ALTER EXTENSION name ADD/DROP object-identifier
    4553             :  *
    4554             :  *****************************************************************************/
    4555             : 
    4556             : AlterExtensionContentsStmt:
    4557             :             ALTER EXTENSION name add_drop ACCESS METHOD name
    4558             :                 {
    4559           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4560           4 :                     n->extname = $3;
    4561           4 :                     n->action = $4;
    4562           4 :                     n->objtype = OBJECT_ACCESS_METHOD;
    4563           4 :                     n->object = (Node *) makeString($7);
    4564           4 :                     $$ = (Node *)n;
    4565             :                 }
    4566             :             | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
    4567             :                 {
    4568           8 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4569           8 :                     n->extname = $3;
    4570           8 :                     n->action = $4;
    4571           8 :                     n->objtype = OBJECT_AGGREGATE;
    4572           8 :                     n->object = (Node *) $6;
    4573           8 :                     $$ = (Node *)n;
    4574             :                 }
    4575             :             | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
    4576             :                 {
    4577           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4578           4 :                     n->extname = $3;
    4579           4 :                     n->action = $4;
    4580           4 :                     n->objtype = OBJECT_CAST;
    4581           4 :                     n->object = (Node *) list_make2($7, $9);
    4582           4 :                     $$ = (Node *) n;
    4583             :                 }
    4584             :             | ALTER EXTENSION name add_drop COLLATION any_name
    4585             :                 {
    4586           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4587           0 :                     n->extname = $3;
    4588           0 :                     n->action = $4;
    4589           0 :                     n->objtype = OBJECT_COLLATION;
    4590           0 :                     n->object = (Node *) $6;
    4591           0 :                     $$ = (Node *)n;
    4592             :                 }
    4593             :             | ALTER EXTENSION name add_drop CONVERSION_P any_name
    4594             :                 {
    4595           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4596           0 :                     n->extname = $3;
    4597           0 :                     n->action = $4;
    4598           0 :                     n->objtype = OBJECT_CONVERSION;
    4599           0 :                     n->object = (Node *) $6;
    4600           0 :                     $$ = (Node *)n;
    4601             :                 }
    4602             :             | ALTER EXTENSION name add_drop DOMAIN_P Typename
    4603             :                 {
    4604           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4605           0 :                     n->extname = $3;
    4606           0 :                     n->action = $4;
    4607           0 :                     n->objtype = OBJECT_DOMAIN;
    4608           0 :                     n->object = (Node *) $6;
    4609           0 :                     $$ = (Node *)n;
    4610             :                 }
    4611             :             | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
    4612             :                 {
    4613          38 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4614          38 :                     n->extname = $3;
    4615          38 :                     n->action = $4;
    4616          38 :                     n->objtype = OBJECT_FUNCTION;
    4617          38 :                     n->object = (Node *) $6;
    4618          38 :                     $$ = (Node *)n;
    4619             :                 }
    4620             :             | ALTER EXTENSION name add_drop opt_procedural LANGUAGE name
    4621             :                 {
    4622           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4623           0 :                     n->extname = $3;
    4624           0 :                     n->action = $4;
    4625           0 :                     n->objtype = OBJECT_LANGUAGE;
    4626           0 :                     n->object = (Node *) makeString($7);
    4627           0 :                     $$ = (Node *)n;
    4628             :                 }
    4629             :             | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
    4630             :                 {
    4631          18 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4632          18 :                     n->extname = $3;
    4633          18 :                     n->action = $4;
    4634          18 :                     n->objtype = OBJECT_OPERATOR;
    4635          18 :                     n->object = (Node *) $6;
    4636          18 :                     $$ = (Node *)n;
    4637             :                 }
    4638             :             | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING access_method
    4639             :                 {
    4640           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4641           4 :                     n->extname = $3;
    4642           4 :                     n->action = $4;
    4643           4 :                     n->objtype = OBJECT_OPCLASS;
    4644           4 :                     n->object = (Node *) lcons(makeString($9), $7);
    4645           4 :                     $$ = (Node *)n;
    4646             :                 }
    4647             :             | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING access_method
    4648             :                 {
    4649           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4650           4 :                     n->extname = $3;
    4651           4 :                     n->action = $4;
    4652           4 :                     n->objtype = OBJECT_OPFAMILY;
    4653           4 :                     n->object = (Node *) lcons(makeString($9), $7);
    4654           4 :                     $$ = (Node *)n;
    4655             :                 }
    4656             :             | ALTER EXTENSION name add_drop PROCEDURE function_with_argtypes
    4657             :                 {
    4658           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4659           0 :                     n->extname = $3;
    4660           0 :                     n->action = $4;
    4661           0 :                     n->objtype = OBJECT_PROCEDURE;
    4662           0 :                     n->object = (Node *) $6;
    4663           0 :                     $$ = (Node *)n;
    4664             :                 }
    4665             :             | ALTER EXTENSION name add_drop ROUTINE function_with_argtypes
    4666             :                 {
    4667           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4668           0 :                     n->extname = $3;
    4669           0 :                     n->action = $4;
    4670           0 :                     n->objtype = OBJECT_ROUTINE;
    4671           0 :                     n->object = (Node *) $6;
    4672           0 :                     $$ = (Node *)n;
    4673             :                 }
    4674             :             | ALTER EXTENSION name add_drop SCHEMA name
    4675             :                 {
    4676           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4677           4 :                     n->extname = $3;
    4678           4 :                     n->action = $4;
    4679           4 :                     n->objtype = OBJECT_SCHEMA;
    4680           4 :                     n->object = (Node *) makeString($6);
    4681           4 :                     $$ = (Node *)n;
    4682             :                 }
    4683             :             | ALTER EXTENSION name add_drop EVENT TRIGGER name
    4684             :                 {
    4685           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4686           0 :                     n->extname = $3;
    4687           0 :                     n->action = $4;
    4688           0 :                     n->objtype = OBJECT_EVENT_TRIGGER;
    4689           0 :                     n->object = (Node *) makeString($7);
    4690           0 :                     $$ = (Node *)n;
    4691             :                 }
    4692             :             | ALTER EXTENSION name add_drop TABLE any_name
    4693             :                 {
    4694           8 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4695           8 :                     n->extname = $3;
    4696           8 :                     n->action = $4;
    4697           8 :                     n->objtype = OBJECT_TABLE;
    4698           8 :                     n->object = (Node *) $6;
    4699           8 :                     $$ = (Node *)n;
    4700             :                 }
    4701             :             | ALTER EXTENSION name add_drop TEXT_P SEARCH PARSER any_name
    4702             :                 {
    4703           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4704           0 :                     n->extname = $3;
    4705           0 :                     n->action = $4;
    4706           0 :                     n->objtype = OBJECT_TSPARSER;
    4707           0 :                     n->object = (Node *) $8;
    4708           0 :                     $$ = (Node *)n;
    4709             :                 }
    4710             :             | ALTER EXTENSION name add_drop TEXT_P SEARCH DICTIONARY any_name
    4711             :                 {
    4712           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4713           0 :                     n->extname = $3;
    4714           0 :                     n->action = $4;
    4715           0 :                     n->objtype = OBJECT_TSDICTIONARY;
    4716           0 :                     n->object = (Node *) $8;
    4717           0 :                     $$ = (Node *)n;
    4718             :                 }
    4719             :             | ALTER EXTENSION name add_drop TEXT_P SEARCH TEMPLATE any_name
    4720             :                 {
    4721           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4722           0 :                     n->extname = $3;
    4723           0 :                     n->action = $4;
    4724           0 :                     n->objtype = OBJECT_TSTEMPLATE;
    4725           0 :                     n->object = (Node *) $8;
    4726           0 :                     $$ = (Node *)n;
    4727             :                 }
    4728             :             | ALTER EXTENSION name add_drop TEXT_P SEARCH CONFIGURATION any_name
    4729             :                 {
    4730           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4731           0 :                     n->extname = $3;
    4732           0 :                     n->action = $4;
    4733           0 :                     n->objtype = OBJECT_TSCONFIGURATION;
    4734           0 :                     n->object = (Node *) $8;
    4735           0 :                     $$ = (Node *)n;
    4736             :                 }
    4737             :             | ALTER EXTENSION name add_drop SEQUENCE any_name
    4738             :                 {
    4739           2 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4740           2 :                     n->extname = $3;
    4741           2 :                     n->action = $4;
    4742           2 :                     n->objtype = OBJECT_SEQUENCE;
    4743           2 :                     n->object = (Node *) $6;
    4744           2 :                     $$ = (Node *)n;
    4745             :                 }
    4746             :             | ALTER EXTENSION name add_drop VIEW any_name
    4747             :                 {
    4748           8 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4749           8 :                     n->extname = $3;
    4750           8 :                     n->action = $4;
    4751           8 :                     n->objtype = OBJECT_VIEW;
    4752           8 :                     n->object = (Node *) $6;
    4753           8 :                     $$ = (Node *)n;
    4754             :                 }
    4755             :             | ALTER EXTENSION name add_drop MATERIALIZED VIEW any_name
    4756             :                 {
    4757           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4758           4 :                     n->extname = $3;
    4759           4 :                     n->action = $4;
    4760           4 :                     n->objtype = OBJECT_MATVIEW;
    4761           4 :                     n->object = (Node *) $7;
    4762           4 :                     $$ = (Node *)n;
    4763             :                 }
    4764             :             | ALTER EXTENSION name add_drop FOREIGN TABLE any_name
    4765             :                 {
    4766           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4767           4 :                     n->extname = $3;
    4768           4 :                     n->action = $4;
    4769           4 :                     n->objtype = OBJECT_FOREIGN_TABLE;
    4770           4 :                     n->object = (Node *) $7;
    4771           4 :                     $$ = (Node *)n;
    4772             :                 }
    4773             :             | ALTER EXTENSION name add_drop FOREIGN DATA_P WRAPPER name
    4774             :                 {
    4775           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4776           4 :                     n->extname = $3;
    4777           4 :                     n->action = $4;
    4778           4 :                     n->objtype = OBJECT_FDW;
    4779           4 :                     n->object = (Node *) makeString($8);
    4780           4 :                     $$ = (Node *)n;
    4781             :                 }
    4782             :             | ALTER EXTENSION name add_drop SERVER name
    4783             :                 {
    4784           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4785           4 :                     n->extname = $3;
    4786           4 :                     n->action = $4;
    4787           4 :                     n->objtype = OBJECT_FOREIGN_SERVER;
    4788           4 :                     n->object = (Node *) makeString($6);
    4789           4 :                     $$ = (Node *)n;
    4790             :                 }
    4791             :             | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
    4792             :                 {
    4793           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4794           4 :                     n->extname = $3;
    4795           4 :                     n->action = $4;
    4796           4 :                     n->objtype = OBJECT_TRANSFORM;
    4797           4 :                     n->object = (Node *) list_make2($7, makeString($9));
    4798           4 :                     $$ = (Node *)n;
    4799             :                 }
    4800             :             | ALTER EXTENSION name add_drop TYPE_P Typename
    4801             :                 {
    4802           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    4803           4 :                     n->extname = $3;
    4804           4 :                     n->action = $4;
    4805           4 :                     n->objtype = OBJECT_TYPE;
    4806           4 :                     n->object = (Node *) $6;
    4807           4 :                     $$ = (Node *)n;
    4808             :                 }
    4809             :         ;
    4810             : 
    4811             : /*****************************************************************************
    4812             :  *
    4813             :  *      QUERY:
    4814             :  *             CREATE FOREIGN DATA WRAPPER name options
    4815             :  *
    4816             :  *****************************************************************************/
    4817             : 
    4818             : CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
    4819             :                 {
    4820         114 :                     CreateFdwStmt *n = makeNode(CreateFdwStmt);
    4821         114 :                     n->fdwname = $5;
    4822         114 :                     n->func_options = $6;
    4823         114 :                     n->options = $7;
    4824         114 :                     $$ = (Node *) n;
    4825             :                 }
    4826             :         ;
    4827             : 
    4828             : fdw_option:
    4829          38 :             HANDLER handler_name                { $$ = makeDefElem("handler", (Node *)$2, @1); }
    4830           0 :             | NO HANDLER                        { $$ = makeDefElem("handler", NULL, @1); }
    4831          32 :             | VALIDATOR handler_name            { $$ = makeDefElem("validator", (Node *)$2, @1); }
    4832           4 :             | NO VALIDATOR                      { $$ = makeDefElem("validator", NULL, @1); }
    4833             :         ;
    4834             : 
    4835             : fdw_options:
    4836          60 :             fdw_option                          { $$ = list_make1($1); }
    4837          14 :             | fdw_options fdw_option            { $$ = lappend($1, $2); }
    4838             :         ;
    4839             : 
    4840             : opt_fdw_options:
    4841          36 :             fdw_options                         { $$ = $1; }
    4842         134 :             | /*EMPTY*/                         { $$ = NIL; }
    4843             :         ;
    4844             : 
    4845             : /*****************************************************************************
    4846             :  *
    4847             :  *      QUERY :
    4848             :  *              ALTER FOREIGN DATA WRAPPER name options
    4849             :  *
    4850             :  ****************************************************************************/
    4851             : 
    4852             : AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
    4853             :                 {
    4854          52 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    4855          52 :                     n->fdwname = $5;
    4856          52 :                     n->func_options = $6;
    4857          52 :                     n->options = $7;
    4858          52 :                     $$ = (Node *) n;
    4859             :                 }
    4860             :             | ALTER FOREIGN DATA_P WRAPPER name fdw_options
    4861             :                 {
    4862          24 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    4863          24 :                     n->fdwname = $5;
    4864          24 :                     n->func_options = $6;
    4865          24 :                     n->options = NIL;
    4866          24 :                     $$ = (Node *) n;
    4867             :                 }
    4868             :         ;
    4869             : 
    4870             : /* Options definition for CREATE FDW, SERVER and USER MAPPING */
    4871             : create_generic_options:
    4872         488 :             OPTIONS '(' generic_option_list ')'         { $$ = $3; }
    4873       44980 :             | /*EMPTY*/                                 { $$ = NIL; }
    4874             :         ;
    4875             : 
    4876             : generic_option_list:
    4877             :             generic_option_elem
    4878             :                 {
    4879         488 :                     $$ = list_make1($1);
    4880             :                 }
    4881             :             | generic_option_list ',' generic_option_elem
    4882             :                 {
    4883         312 :                     $$ = lappend($1, $3);
    4884             :                 }
    4885             :         ;
    4886             : 
    4887             : /* Options definition for ALTER FDW, SERVER and USER MAPPING */
    4888             : alter_generic_options:
    4889         268 :             OPTIONS '(' alter_generic_option_list ')'       { $$ = $3; }
    4890             :         ;
    4891             : 
    4892             : alter_generic_option_list:
    4893             :             alter_generic_option_elem
    4894             :                 {
    4895         268 :                     $$ = list_make1($1);
    4896             :                 }
    4897             :             | alter_generic_option_list ',' alter_generic_option_elem
    4898             :                 {
    4899         128 :                     $$ = lappend($1, $3);
    4900             :                 }
    4901             :         ;
    4902             : 
    4903             : alter_generic_option_elem:
    4904             :             generic_option_elem
    4905             :                 {
    4906         138 :                     $$ = $1;
    4907             :                 }
    4908             :             | SET generic_option_elem
    4909             :                 {
    4910          78 :                     $$ = $2;
    4911          78 :                     $$->defaction = DEFELEM_SET;
    4912             :                 }
    4913             :             | ADD_P generic_option_elem
    4914             :                 {
    4915         118 :                     $$ = $2;
    4916         118 :                     $$->defaction = DEFELEM_ADD;
    4917             :                 }
    4918             :             | DROP generic_option_name
    4919             :                 {
    4920          62 :                     $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP, @2);
    4921             :                 }
    4922             :         ;
    4923             : 
    4924             : generic_option_elem:
    4925             :             generic_option_name generic_option_arg
    4926             :                 {
    4927        1134 :                     $$ = makeDefElem($1, $2, @1);
    4928             :                 }
    4929             :         ;
    4930             : 
    4931             : generic_option_name:
    4932        1196 :                 ColLabel            { $$ = $1; }
    4933             :         ;
    4934             : 
    4935             : /* We could use def_arg here, but the spec only requires string literals */
    4936             : generic_option_arg:
    4937        1134 :                 Sconst              { $$ = (Node *) makeString($1); }
    4938             :         ;
    4939             : 
    4940             : /*****************************************************************************
    4941             :  *
    4942             :  *      QUERY:
    4943             :  *             CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
    4944             :  *
    4945             :  *****************************************************************************/
    4946             : 
    4947             : CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
    4948             :                          FOREIGN DATA_P WRAPPER name create_generic_options
    4949             :                 {
    4950         166 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    4951         166 :                     n->servername = $3;
    4952         166 :                     n->servertype = $4;
    4953         166 :                     n->version = $5;
    4954         166 :                     n->fdwname = $9;
    4955         166 :                     n->options = $10;
    4956         166 :                     n->if_not_exists = false;
    4957         166 :                     $$ = (Node *) n;
    4958             :                 }
    4959             :                 | CREATE SERVER IF_P NOT EXISTS name opt_type opt_foreign_server_version
    4960             :                          FOREIGN DATA_P WRAPPER name create_generic_options
    4961             :                 {
    4962           4 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    4963           4 :                     n->servername = $6;
    4964           4 :                     n->servertype = $7;
    4965           4 :                     n->version = $8;
    4966           4 :                     n->fdwname = $12;
    4967           4 :                     n->options = $13;
    4968           4 :                     n->if_not_exists = true;
    4969           4 :                     $$ = (Node *) n;
    4970             :                 }
    4971             :         ;
    4972             : 
    4973             : opt_type:
    4974          12 :             TYPE_P Sconst           { $$ = $2; }
    4975         158 :             | /*EMPTY*/             { $$ = NULL; }
    4976             :         ;
    4977             : 
    4978             : 
    4979             : foreign_server_version:
    4980          44 :             VERSION_P Sconst        { $$ = $2; }
    4981           0 :         |   VERSION_P NULL_P        { $$ = NULL; }
    4982             :         ;
    4983             : 
    4984             : opt_foreign_server_version:
    4985          12 :             foreign_server_version  { $$ = $1; }
    4986         158 :             | /*EMPTY*/             { $$ = NULL; }
    4987             :         ;
    4988             : 
    4989             : /*****************************************************************************
    4990             :  *
    4991             :  *      QUERY :
    4992             :  *              ALTER SERVER name [VERSION] [OPTIONS]
    4993             :  *
    4994             :  ****************************************************************************/
    4995             : 
    4996             : AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
    4997             :                 {
    4998           4 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    4999           4 :                     n->servername = $3;
    5000           4 :                     n->version = $4;
    5001           4 :                     n->options = $5;
    5002           4 :                     n->has_version = true;
    5003           4 :                     $$ = (Node *) n;
    5004             :                 }
    5005             :             | ALTER SERVER name foreign_server_version
    5006             :                 {
    5007          28 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5008          28 :                     n->servername = $3;
    5009          28 :                     n->version = $4;
    5010          28 :                     n->has_version = true;
    5011          28 :                     $$ = (Node *) n;
    5012             :                 }
    5013             :             | ALTER SERVER name alter_generic_options
    5014             :                 {
    5015          62 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5016          62 :                     n->servername = $3;
    5017          62 :                     n->options = $4;
    5018          62 :                     $$ = (Node *) n;
    5019             :                 }
    5020             :         ;
    5021             : 
    5022             : /*****************************************************************************
    5023             :  *
    5024             :  *      QUERY:
    5025             :  *             CREATE FOREIGN TABLE relname (...) SERVER name (...)
    5026             :  *
    5027             :  *****************************************************************************/
    5028             : 
    5029             : CreateForeignTableStmt:
    5030             :         CREATE FOREIGN TABLE qualified_name
    5031             :             '(' OptTableElementList ')'
    5032             :             OptInherit SERVER name create_generic_options
    5033             :                 {
    5034         248 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5035         248 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5036         248 :                     n->base.relation = $4;
    5037         248 :                     n->base.tableElts = $6;
    5038         248 :                     n->base.inhRelations = $8;
    5039         248 :                     n->base.ofTypename = NULL;
    5040         248 :                     n->base.constraints = NIL;
    5041         248 :                     n->base.options = NIL;
    5042         248 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5043         248 :                     n->base.tablespacename = NULL;
    5044         248 :                     n->base.if_not_exists = false;
    5045             :                     /* FDW-specific data */
    5046         248 :                     n->servername = $10;
    5047         248 :                     n->options = $11;
    5048         248 :                     $$ = (Node *) n;
    5049             :                 }
    5050             :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5051             :             '(' OptTableElementList ')'
    5052             :             OptInherit SERVER name create_generic_options
    5053             :                 {
    5054           0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5055           0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5056           0 :                     n->base.relation = $7;
    5057           0 :                     n->base.tableElts = $9;
    5058           0 :                     n->base.inhRelations = $11;
    5059           0 :                     n->base.ofTypename = NULL;
    5060           0 :                     n->base.constraints = NIL;
    5061           0 :                     n->base.options = NIL;
    5062           0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5063           0 :                     n->base.tablespacename = NULL;
    5064           0 :                     n->base.if_not_exists = true;
    5065             :                     /* FDW-specific data */
    5066           0 :                     n->servername = $13;
    5067           0 :                     n->options = $14;
    5068           0 :                     $$ = (Node *) n;
    5069             :                 }
    5070             :         | CREATE FOREIGN TABLE qualified_name
    5071             :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5072             :             SERVER name create_generic_options
    5073             :                 {
    5074          42 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5075          42 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5076          42 :                     n->base.relation = $4;
    5077          42 :                     n->base.inhRelations = list_make1($7);
    5078          42 :                     n->base.tableElts = $8;
    5079          42 :                     n->base.partbound = $9;
    5080          42 :                     n->base.ofTypename = NULL;
    5081          42 :                     n->base.constraints = NIL;
    5082          42 :                     n->base.options = NIL;
    5083          42 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5084          42 :                     n->base.tablespacename = NULL;
    5085          42 :                     n->base.if_not_exists = false;
    5086             :                     /* FDW-specific data */
    5087          42 :                     n->servername = $11;
    5088          42 :                     n->options = $12;
    5089          42 :                     $$ = (Node *) n;
    5090             :                 }
    5091             :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5092             :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5093             :             SERVER name create_generic_options
    5094             :                 {
    5095           0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5096           0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5097           0 :                     n->base.relation = $7;
    5098           0 :                     n->base.inhRelations = list_make1($10);
    5099           0 :                     n->base.tableElts = $11;
    5100           0 :                     n->base.partbound = $12;
    5101           0 :                     n->base.ofTypename = NULL;
    5102           0 :                     n->base.constraints = NIL;
    5103           0 :                     n->base.options = NIL;
    5104           0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5105           0 :                     n->base.tablespacename = NULL;
    5106           0 :                     n->base.if_not_exists = true;
    5107             :                     /* FDW-specific data */
    5108           0 :                     n->servername = $14;
    5109           0 :                     n->options = $15;
    5110           0 :                     $$ = (Node *) n;
    5111             :                 }
    5112             :         ;
    5113             : 
    5114             : /*****************************************************************************
    5115             :  *
    5116             :  *      QUERY:
    5117             :  *             ALTER FOREIGN TABLE relname [...]
    5118             :  *
    5119             :  *****************************************************************************/
    5120             : 
    5121             : AlterForeignTableStmt:
    5122             :             ALTER FOREIGN TABLE relation_expr alter_table_cmds
    5123             :                 {
    5124         228 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    5125         228 :                     n->relation = $4;
    5126         228 :                     n->cmds = $5;
    5127         228 :                     n->relkind = OBJECT_FOREIGN_TABLE;
    5128         228 :                     n->missing_ok = false;
    5129         228 :                     $$ = (Node *)n;
    5130             :                 }
    5131             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr alter_table_cmds
    5132             :                 {
    5133          72 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    5134          72 :                     n->relation = $6;
    5135          72 :                     n->cmds = $7;
    5136          72 :                     n->relkind = OBJECT_FOREIGN_TABLE;
    5137          72 :                     n->missing_ok = true;
    5138          72 :                     $$ = (Node *)n;
    5139             :                 }
    5140             :         ;
    5141             : 
    5142             : /*****************************************************************************
    5143             :  *
    5144             :  *      QUERY:
    5145             :  *              IMPORT FOREIGN SCHEMA remote_schema
    5146             :  *              [ { LIMIT TO | EXCEPT } ( table_list ) ]
    5147             :  *              FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
    5148             :  *
    5149             :  ****************************************************************************/
    5150             : 
    5151             : ImportForeignSchemaStmt:
    5152             :         IMPORT_P FOREIGN SCHEMA name import_qualification
    5153             :           FROM SERVER name INTO name create_generic_options
    5154             :             {
    5155          36 :                 ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
    5156          36 :                 n->server_name = $8;
    5157          36 :                 n->remote_schema = $4;
    5158          36 :                 n->local_schema = $10;
    5159          36 :                 n->list_type = $5->type;
    5160          36 :                 n->table_list = $5->table_names;
    5161          36 :                 n->options = $11;
    5162          36 :                 $$ = (Node *) n;
    5163             :             }
    5164             :         ;
    5165             : 
    5166             : import_qualification_type:
    5167           8 :         LIMIT TO                { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
    5168          10 :         | EXCEPT                { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
    5169             :         ;
    5170             : 
    5171             : import_qualification:
    5172             :         import_qualification_type '(' relation_expr_list ')'
    5173             :             {
    5174          18 :                 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
    5175          18 :                 n->type = $1;
    5176          18 :                 n->table_names = $3;
    5177          18 :                 $$ = n;
    5178             :             }
    5179             :         | /*EMPTY*/
    5180             :             {
    5181          18 :                 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
    5182          18 :                 n->type = FDW_IMPORT_SCHEMA_ALL;
    5183          18 :                 n->table_names = NIL;
    5184          18 :                 $$ = n;
    5185             :             }
    5186             :         ;
    5187             : 
    5188             : /*****************************************************************************
    5189             :  *
    5190             :  *      QUERY:
    5191             :  *             CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
    5192             :  *
    5193             :  *****************************************************************************/
    5194             : 
    5195             : CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
    5196             :                 {
    5197         168 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5198         168 :                     n->user = $5;
    5199         168 :                     n->servername = $7;
    5200         168 :                     n->options = $8;
    5201         168 :                     n->if_not_exists = false;
    5202         168 :                     $$ = (Node *) n;
    5203             :                 }
    5204             :                 | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
    5205             :                 {
    5206           4 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5207           4 :                     n->user = $8;
    5208           4 :                     n->servername = $10;
    5209           4 :                     n->options = $11;
    5210           4 :                     n->if_not_exists = true;
    5211           4 :                     $$ = (Node *) n;
    5212             :                 }
    5213             :         ;
    5214             : 
    5215             : /* User mapping authorization identifier */
    5216         316 : auth_ident: RoleSpec            { $$ = $1; }
    5217          34 :             | USER              { $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1); }
    5218             :         ;
    5219             : 
    5220             : /*****************************************************************************
    5221             :  *
    5222             :  *      QUERY :
    5223             :  *              DROP USER MAPPING FOR auth_ident SERVER name
    5224             :  *
    5225             :  * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
    5226             :  * only pro forma; but the SQL standard doesn't show one.
    5227             :  ****************************************************************************/
    5228             : 
    5229             : DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
    5230             :                 {
    5231          62 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5232          62 :                     n->user = $5;
    5233          62 :                     n->servername = $7;
    5234          62 :                     n->missing_ok = false;
    5235          62 :                     $$ = (Node *) n;
    5236             :                 }
    5237             :                 |  DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
    5238             :                 {
    5239          30 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5240          30 :                     n->user = $7;
    5241          30 :                     n->servername = $9;
    5242          30 :                     n->missing_ok = true;
    5243          30 :                     $$ = (Node *) n;
    5244             :                 }
    5245             :         ;
    5246             : 
    5247             : /*****************************************************************************
    5248             :  *
    5249             :  *      QUERY :
    5250             :  *              ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
    5251             :  *
    5252             :  ****************************************************************************/
    5253             : 
    5254             : AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
    5255             :                 {
    5256          86 :                     AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
    5257          86 :                     n->user = $5;
    5258          86 :                     n->servername = $7;
    5259          86 :                     n->options = $8;
    5260          86 :                     $$ = (Node *) n;
    5261             :                 }
    5262             :         ;
    5263             : 
    5264             : /*****************************************************************************
    5265             :  *
    5266             :  *      QUERIES:
    5267             :  *              CREATE POLICY name ON table
    5268             :  *                  [AS { PERMISSIVE | RESTRICTIVE } ]
    5269             :  *                  [FOR { SELECT | INSERT | UPDATE | DELETE } ]
    5270             :  *                  [TO role, ...]
    5271             :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    5272             :  *              ALTER POLICY name ON table [TO role, ...]
    5273             :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    5274             :  *
    5275             :  *****************************************************************************/
    5276             : 
    5277             : CreatePolicyStmt:
    5278             :             CREATE POLICY name ON qualified_name RowSecurityDefaultPermissive
    5279             :                 RowSecurityDefaultForCmd RowSecurityDefaultToRole
    5280             :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    5281             :                 {
    5282         394 :                     CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
    5283         394 :                     n->policy_name = $3;
    5284         394 :                     n->table = $5;
    5285         394 :                     n->permissive = $6;
    5286         394 :                     n->cmd_name = $7;
    5287         394 :                     n->roles = $8;
    5288         394 :                     n->qual = $9;
    5289         394 :                     n->with_check = $10;
    5290         394 :                     $$ = (Node *) n;
    5291             :                 }
    5292             :         ;
    5293             : 
    5294             : AlterPolicyStmt:
    5295             :             ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
    5296             :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    5297             :                 {
    5298          56 :                     AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
    5299          56 :                     n->policy_name = $3;
    5300          56 :                     n->table = $5;
    5301          56 :                     n->roles = $6;
    5302          56 :                     n->qual = $7;
    5303          56 :                     n->with_check = $8;
    5304          56 :                     $$ = (Node *) n;
    5305             :                 }
    5306             :         ;
    5307             : 
    5308             : RowSecurityOptionalExpr:
    5309         416 :             USING '(' a_expr ')'    { $$ = $3; }
    5310          34 :             | /* EMPTY */           { $$ = NULL; }
    5311             :         ;
    5312             : 
    5313             : RowSecurityOptionalWithCheck:
    5314          76 :             WITH CHECK '(' a_expr ')'       { $$ = $4; }
    5315         374 :             | /* EMPTY */                   { $$ = NULL; }
    5316             :         ;
    5317             : 
    5318             : RowSecurityDefaultToRole:
    5319          68 :             TO role_list            { $$ = $2; }
    5320         326 :             | /* EMPTY */           { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
    5321             :         ;
    5322             : 
    5323             : RowSecurityOptionalToRole:
    5324           8 :             TO role_list            { $$ = $2; }
    5325          48 :             | /* EMPTY */           { $$ = NULL; }
    5326             :         ;
    5327             : 
    5328             : RowSecurityDefaultPermissive:
    5329             :             AS IDENT
    5330             :                 {
    5331          46 :                     if (strcmp($2, "permissive") == 0)
    5332          12 :                         $$ = true;
    5333          34 :                     else if (strcmp($2, "restrictive") == 0)
    5334          30 :                         $$ = false;
    5335             :                     else
    5336           4 :                         ereport(ERROR,
    5337             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    5338             :                              errmsg("unrecognized row security option \"%s\"", $2),
    5339             :                                  errhint("Only PERMISSIVE or RESTRICTIVE policies are supported currently."),
    5340             :                                      parser_errposition(@2)));
    5341             : 
    5342             :                 }
    5343         352 :             | /* EMPTY */           { $$ = true; }
    5344             :         ;
    5345             : 
    5346             : RowSecurityDefaultForCmd:
    5347         188 :             FOR row_security_cmd    { $$ = $2; }
    5348         206 :             | /* EMPTY */           { $$ = "all"; }
    5349             :         ;
    5350             : 
    5351             : row_security_cmd:
    5352          28 :             ALL             { $$ = "all"; }
    5353          58 :         |   SELECT          { $$ = "select"; }
    5354          26 :         |   INSERT          { $$ = "insert"; }
    5355          50 :         |   UPDATE          { $$ = "update"; }
    5356          26 :         |   DELETE_P        { $$ = "delete"; }
    5357             :         ;
    5358             : 
    5359             : /*****************************************************************************
    5360             :  *
    5361             :  *      QUERY:
    5362             :  *             CREATE ACCESS METHOD name HANDLER handler_name
    5363             :  *
    5364             :  *****************************************************************************/
    5365             : 
    5366             : CreateAmStmt: CREATE ACCESS METHOD name TYPE_P am_type HANDLER handler_name
    5367             :                 {
    5368          44 :                     CreateAmStmt *n = makeNode(CreateAmStmt);
    5369          44 :                     n->amname = $4;
    5370          44 :                     n->handler_name = $8;
    5371          44 :                     n->amtype = $6;
    5372          44 :                     $$ = (Node *) n;
    5373             :                 }
    5374             :         ;
    5375             : 
    5376             : am_type:
    5377          24 :             INDEX           { $$ = AMTYPE_INDEX; }
    5378          20 :         |   TABLE           { $$ = AMTYPE_TABLE; }
    5379             :         ;
    5380             : 
    5381             : /*****************************************************************************
    5382             :  *
    5383             :  *      QUERIES :
    5384             :  *              CREATE TRIGGER ...
    5385             :  *
    5386             :  *****************************************************************************/
    5387             : 
    5388             : CreateTrigStmt:
    5389             :             CREATE TRIGGER name TriggerActionTime TriggerEvents ON
    5390             :             qualified_name TriggerReferencing TriggerForSpec TriggerWhen
    5391             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    5392             :                 {
    5393        1988 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    5394        1988 :                     n->trigname = $3;
    5395        1988 :                     n->relation = $7;
    5396        1988 :                     n->funcname = $13;
    5397        1988 :                     n->args = $15;
    5398        1988 :                     n->row = $9;
    5399        1988 :                     n->timing = $4;
    5400        1988 :                     n->events = intVal(linitial($5));
    5401        1988 :                     n->columns = (List *) lsecond($5);
    5402        1988 :                     n->whenClause = $10;
    5403        1988 :                     n->transitionRels = $8;
    5404        1988 :                     n->isconstraint  = false;
    5405        1988 :                     n->deferrable     = false;
    5406        1988 :                     n->initdeferred  = false;
    5407        1988 :                     n->constrrel = NULL;
    5408        1988 :                     $$ = (Node *)n;
    5409             :                 }
    5410             :             | CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
    5411             :             qualified_name OptConstrFromTable ConstraintAttributeSpec
    5412             :             FOR EACH ROW TriggerWhen
    5413             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    5414             :                 {
    5415          20 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    5416          20 :                     n->trigname = $4;
    5417          20 :                     n->relation = $8;
    5418          20 :                     n->funcname = $17;
    5419          20 :                     n->args = $19;
    5420          20 :                     n->row = true;
    5421          20 :                     n->timing = TRIGGER_TYPE_AFTER;
    5422          20 :                     n->events = intVal(linitial($6));
    5423          20 :                     n->columns = (List *) lsecond($6);
    5424          20 :                     n->whenClause = $14;
    5425          20 :                     n->transitionRels = NIL;
    5426          20 :                     n->isconstraint  = true;
    5427          20 :                     processCASbits($10, @10, "TRIGGER",
    5428             :                                    &n->deferrable, &n->initdeferred, NULL,
    5429             :                                    NULL, yyscanner);
    5430          20 :                     n->constrrel = $9;
    5431          20 :                     $$ = (Node *)n;
    5432             :                 }
    5433             :         ;
    5434             : 
    5435             : TriggerActionTime:
    5436         928 :             BEFORE                              { $$ = TRIGGER_TYPE_BEFORE; }
    5437         978 :             | AFTER                             { $$ = TRIGGER_TYPE_AFTER; }
    5438          90 :             | INSTEAD OF                        { $$ = TRIGGER_TYPE_INSTEAD; }
    5439             :         ;
    5440             : 
    5441             : TriggerEvents:
    5442             :             TriggerOneEvent
    5443        2016 :                 { $$ = $1; }
    5444             :             | TriggerEvents OR TriggerOneEvent
    5445             :                 {
    5446         646 :                     int     events1 = intVal(linitial($1));
    5447         646 :                     int     events2 = intVal(linitial($3));
    5448         646 :                     List   *columns1 = (List *) lsecond($1);
    5449         646 :                     List   *columns2 = (List *) lsecond($3);
    5450             : 
    5451         646 :                     if (events1 & events2)
    5452           4 :                         parser_yyerror("duplicate trigger events specified");
    5453             :                     /*
    5454             :                      * concat'ing the columns lists loses information about
    5455             :                      * which columns went with which event, but so long as
    5456             :                      * only UPDATE carries columns and we disallow multiple
    5457             :                      * UPDATE items, it doesn't matter.  Command execution
    5458             :                      * should just ignore the columns for non-UPDATE events.
    5459             :                      */
    5460         642 :                     $$ = list_make2(makeInteger(events1 | events2),
    5461             :                                     list_concat(columns1, columns2));
    5462             :                 }
    5463             :         ;
    5464             : 
    5465             : TriggerOneEvent:
    5466             :             INSERT
    5467         894 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
    5468             :             | DELETE_P
    5469         536 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
    5470             :             | UPDATE
    5471        1142 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
    5472             :             | UPDATE OF columnList
    5473          66 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
    5474             :             | TRUNCATE
    5475          24 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
    5476             :         ;
    5477             : 
    5478             : TriggerReferencing:
    5479         262 :             REFERENCING TriggerTransitions          { $$ = $2; }
    5480        1726 :             | /*EMPTY*/                             { $$ = NIL; }
    5481             :         ;
    5482             : 
    5483             : TriggerTransitions:
    5484         262 :             TriggerTransition                       { $$ = list_make1($1); }
    5485          84 :             | TriggerTransitions TriggerTransition  { $$ = lappend($1, $2); }
    5486             :         ;
    5487             : 
    5488             : TriggerTransition:
    5489             :             TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
    5490             :                 {
    5491         346 :                     TriggerTransition *n = makeNode(TriggerTransition);
    5492         346 :                     n->name = $4;
    5493         346 :                     n->isNew = $1;
    5494         346 :                     n->isTable = $2;
    5495         346 :                     $$ = (Node *)n;
    5496             :                 }
    5497             :         ;
    5498             : 
    5499             : TransitionOldOrNew:
    5500         190 :             NEW                                     { $$ = true; }
    5501         156 :             | OLD                                   { $$ = false; }
    5502             :         ;
    5503             : 
    5504             : TransitionRowOrTable:
    5505         346 :             TABLE                                   { $$ = true; }
    5506             :             /*
    5507             :              * According to the standard, lack of a keyword here implies ROW.
    5508             :              * Support for that would require prohibiting ROW entirely here,
    5509             :              * reserving the keyword ROW, and/or requiring AS (instead of
    5510             :              * allowing it to be optional, as the standard specifies) as the
    5511             :              * next token.  Requiring ROW seems cleanest and easiest to
    5512             :              * explain.
    5513             :              */
    5514           0 :             | ROW                                   { $$ = false; }
    5515             :         ;
    5516             : 
    5517             : TransitionRelName:
    5518         346 :             ColId                                   { $$ = $1; }
    5519             :         ;
    5520             : 
    5521             : TriggerForSpec:
    5522             :             FOR TriggerForOptEach TriggerForType
    5523             :                 {
    5524        1812 :                     $$ = $3;
    5525             :                 }
    5526             :             | /* EMPTY */
    5527             :                 {
    5528             :                     /*
    5529             :                      * If ROW/STATEMENT not specified, default to
    5530             :                      * STATEMENT, per SQL
    5531             :                      */
    5532         176 :                     $$ = false;
    5533             :                 }
    5534             :         ;
    5535             : 
    5536             : TriggerForOptEach:
    5537             :             EACH                                    {}
    5538             :             | /*EMPTY*/                             {}
    5539             :         ;
    5540             : 
    5541             : TriggerForType:
    5542        1356 :             ROW                                     { $$ = true; }
    5543         456 :             | STATEMENT                             { $$ = false; }
    5544             :         ;
    5545             : 
    5546             : TriggerWhen:
    5547         104 :             WHEN '(' a_expr ')'                     { $$ = $3; }
    5548        1904 :             | /*EMPTY*/                             { $$ = NULL; }
    5549             :         ;
    5550             : 
    5551             : FUNCTION_or_PROCEDURE:
    5552             :             FUNCTION
    5553             :         |   PROCEDURE
    5554             :         ;
    5555             : 
    5556             : TriggerFuncArgs:
    5557         418 :             TriggerFuncArg                          { $$ = list_make1($1); }
    5558         202 :             | TriggerFuncArgs ',' TriggerFuncArg    { $$ = lappend($1, $3); }
    5559        1590 :             | /*EMPTY*/                             { $$ = NIL; }
    5560             :         ;
    5561             : 
    5562             : TriggerFuncArg:
    5563             :             Iconst
    5564             :                 {
    5565          86 :                     $$ = makeString(psprintf("%d", $1));
    5566             :                 }
    5567           0 :             | FCONST                                { $$ = makeString($1); }
    5568         508 :             | Sconst                                { $$ = makeString($1); }
    5569          26 :             | ColLabel                              { $$ = makeString($1); }
    5570             :         ;
    5571             : 
    5572             : OptConstrFromTable:
    5573           8 :             FROM qualified_name                     { $$ = $2; }
    5574          12 :             | /*EMPTY*/                             { $$ = NULL; }
    5575             :         ;
    5576             : 
    5577             : ConstraintAttributeSpec:
    5578             :             /*EMPTY*/
    5579        3132 :                 { $$ = 0; }
    5580             :             | ConstraintAttributeSpec ConstraintAttributeElem
    5581             :                 {
    5582             :                     /*
    5583             :                      * We must complain about conflicting options.
    5584             :                      * We could, but choose not to, complain about redundant
    5585             :                      * options (ie, where $2's bit is already set in $1).
    5586             :                      */
    5587         644 :                     int     newspec = $1 | $2;
    5588             : 
    5589             :                     /* special message for this case */
    5590         644 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
    5591           4 :                         ereport(ERROR,
    5592             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    5593             :                                  errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
    5594             :                                  parser_errposition(@2)));
    5595             :                     /* generic message for other conflicts */
    5596         640 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
    5597         640 :                         (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED))
    5598           0 :                         ereport(ERROR,
    5599             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    5600             :                                  errmsg("conflicting constraint properties"),
    5601             :                                  parser_errposition(@2)));
    5602         640 :                     $$ = newspec;
    5603             :                 }
    5604             :         ;
    5605             : 
    5606             : ConstraintAttributeElem:
    5607          24 :             NOT DEFERRABLE                  { $$ = CAS_NOT_DEFERRABLE; }
    5608          62 :             | DEFERRABLE                    { $$ = CAS_DEFERRABLE; }
    5609          16 :             | INITIALLY IMMEDIATE           { $$ = CAS_INITIALLY_IMMEDIATE; }
    5610          28 :             | INITIALLY DEFERRED            { $$ = CAS_INITIALLY_DEFERRED; }
    5611         454 :             | NOT VALID                     { $$ = CAS_NOT_VALID; }
    5612          60 :             | NO INHERIT                    { $$ = CAS_NO_INHERIT; }
    5613             :         ;
    5614             : 
    5615             : 
    5616             : /*****************************************************************************
    5617             :  *
    5618             :  *      QUERIES :
    5619             :  *              CREATE EVENT TRIGGER ...
    5620             :  *              ALTER EVENT TRIGGER ...
    5621             :  *
    5622             :  *****************************************************************************/
    5623             : 
    5624             : CreateEventTrigStmt:
    5625             :             CREATE EVENT TRIGGER name ON ColLabel
    5626             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    5627             :                 {
    5628          56 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    5629          56 :                     n->trigname = $4;
    5630          56 :                     n->eventname = $6;
    5631          56 :                     n->whenclause = NULL;
    5632          56 :                     n->funcname = $9;
    5633          56 :                     $$ = (Node *)n;
    5634             :                 }
    5635             :           | CREATE EVENT TRIGGER name ON ColLabel
    5636             :             WHEN event_trigger_when_list
    5637             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    5638             :                 {
    5639          52 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    5640          52 :                     n->trigname = $4;
    5641          52 :                     n->eventname = $6;
    5642          52 :                     n->whenclause = $8;
    5643          52 :                     n->funcname = $11;
    5644          52 :                     $$ = (Node *)n;
    5645             :                 }
    5646             :         ;
    5647             : 
    5648             : event_trigger_when_list:
    5649             :           event_trigger_when_item
    5650          52 :             { $$ = list_make1($1); }
    5651             :         | event_trigger_when_list AND event_trigger_when_item
    5652           4 :             { $$ = lappend($1, $3); }
    5653             :         ;
    5654             : 
    5655             : event_trigger_when_item:
    5656             :         ColId IN_P '(' event_trigger_value_list ')'
    5657          56 :             { $$ = makeDefElem($1, (Node *) $4, @1); }
    5658             :         ;
    5659             : 
    5660             : event_trigger_value_list:
    5661             :           SCONST
    5662          56 :             { $$ = list_make1(makeString($1)); }
    5663             :         | event_trigger_value_list ',' SCONST
    5664          44 :             { $$ = lappend($1, makeString($3)); }
    5665             :         ;
    5666             : 
    5667             : AlterEventTrigStmt:
    5668             :             ALTER EVENT TRIGGER name enable_trigger
    5669             :                 {
    5670          20 :                     AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
    5671          20 :                     n->trigname = $4;
    5672          20 :                     n->tgenabled = $5;
    5673          20 :                     $$ = (Node *) n;
    5674             :                 }
    5675             :         ;
    5676             : 
    5677             : enable_trigger:
    5678           4 :             ENABLE_P                    { $$ = TRIGGER_FIRES_ON_ORIGIN; }
    5679           4 :             | ENABLE_P REPLICA          { $$ = TRIGGER_FIRES_ON_REPLICA; }
    5680           4 :             | ENABLE_P ALWAYS           { $$ = TRIGGER_FIRES_ALWAYS; }
    5681           8 :             | DISABLE_P                 { $$ = TRIGGER_DISABLED; }
    5682             :         ;
    5683             : 
    5684             : /*****************************************************************************
    5685             :  *
    5686             :  *      QUERY :
    5687             :  *              CREATE ASSERTION ...
    5688             :  *
    5689             :  *****************************************************************************/
    5690             : 
    5691             : CreateAssertionStmt:
    5692             :             CREATE ASSERTION any_name CHECK '(' a_expr ')' ConstraintAttributeSpec
    5693             :                 {
    5694           0 :                     ereport(ERROR,
    5695             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    5696             :                              errmsg("CREATE ASSERTION is not yet implemented")));
    5697             : 
    5698             :                     $$ = NULL;
    5699             :                 }
    5700             :         ;
    5701             : 
    5702             : 
    5703             : /*****************************************************************************
    5704             :  *
    5705             :  *      QUERY :
    5706             :  *              define (aggregate,operator,type)
    5707             :  *
    5708             :  *****************************************************************************/
    5709             : 
    5710             : DefineStmt:
    5711             :             CREATE opt_or_replace AGGREGATE func_name aggr_args definition
    5712             :                 {
    5713         396 :                     DefineStmt *n = makeNode(DefineStmt);
    5714         396 :                     n->kind = OBJECT_AGGREGATE;
    5715         396 :                     n->oldstyle = false;
    5716         396 :                     n->replace = $2;
    5717         396 :                     n->defnames = $4;
    5718         396 :                     n->args = $5;
    5719         396 :                     n->definition = $6;
    5720         396 :                     $$ = (Node *)n;
    5721             :                 }
    5722             :             | CREATE opt_or_replace AGGREGATE func_name old_aggr_definition
    5723             :                 {
    5724             :                     /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
    5725         244 :                     DefineStmt *n = makeNode(DefineStmt);
    5726         244 :                     n->kind = OBJECT_AGGREGATE;
    5727         244 :                     n->oldstyle = true;
    5728         244 :                     n->replace = $2;
    5729         244 :                     n->defnames = $4;
    5730         244 :                     n->args = NIL;
    5731         244 :                     n->definition = $5;
    5732         244 :                     $$ = (Node *)n;
    5733             :                 }
    5734             :             | CREATE OPERATOR any_operator definition
    5735             :                 {
    5736        1320 :                     DefineStmt *n = makeNode(DefineStmt);
    5737        1320 :                     n->kind = OBJECT_OPERATOR;
    5738        1320 :                     n->oldstyle = false;
    5739        1320 :                     n->defnames = $3;
    5740        1320 :                     n->args = NIL;
    5741        1320 :                     n->definition = $4;
    5742        1320 :                     $$ = (Node *)n;
    5743             :                 }
    5744             :             | CREATE TYPE_P any_name definition
    5745             :                 {
    5746         164 :                     DefineStmt *n = makeNode(DefineStmt);
    5747         164 :                     n->kind = OBJECT_TYPE;
    5748         164 :                     n->oldstyle = false;
    5749         164 :                     n->defnames = $3;
    5750         164 :                     n->args = NIL;
    5751         164 :                     n->definition = $4;
    5752         164 :                     $$ = (Node *)n;
    5753             :                 }
    5754             :             | CREATE TYPE_P any_name
    5755             :                 {
    5756             :                     /* Shell type (identified by lack of definition) */
    5757         112 :                     DefineStmt *n = makeNode(DefineStmt);
    5758         112 :                     n->kind = OBJECT_TYPE;
    5759         112 :                     n->oldstyle = false;
    5760         112 :                     n->defnames = $3;
    5761         112 :                     n->args = NIL;
    5762         112 :                     n->definition = NIL;
    5763         112 :                     $$ = (Node *)n;
    5764             :                 }
    5765             :             | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
    5766             :                 {
    5767         418 :                     CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
    5768             : 
    5769             :                     /* can't use qualified_name, sigh */
    5770         418 :                     n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
    5771         418 :                     n->coldeflist = $6;
    5772         418 :                     $$ = (Node *)n;
    5773             :                 }
    5774             :             | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
    5775             :                 {
    5776         108 :                     CreateEnumStmt *n = makeNode(CreateEnumStmt);
    5777         108 :                     n->typeName = $3;
    5778         108 :                     n->vals = $7;
    5779         108 :                     $$ = (Node *)n;
    5780             :                 }
    5781             :             | CREATE TYPE_P any_name AS RANGE definition
    5782             :                 {
    5783          58 :                     CreateRangeStmt *n = makeNode(CreateRangeStmt);
    5784          58 :                     n->typeName = $3;
    5785          58 :                     n->params    = $6;
    5786          58 :                     $$ = (Node *)n;
    5787             :                 }
    5788             :             | CREATE TEXT_P SEARCH PARSER any_name definition
    5789             :                 {
    5790          28 :                     DefineStmt *n = makeNode(DefineStmt);
    5791          28 :                     n->kind = OBJECT_TSPARSER;
    5792          28 :                     n->args = NIL;
    5793          28 :                     n->defnames = $5;
    5794          28 :                     n->definition = $6;
    5795          28 :                     $$ = (Node *)n;
    5796             :                 }
    5797             :             | CREATE TEXT_P SEARCH DICTIONARY any_name definition
    5798             :                 {
    5799        7982 :                     DefineStmt *n = makeNode(DefineStmt);
    5800        7982 :                     n->kind = OBJECT_TSDICTIONARY;
    5801        7982 :                     n->args = NIL;
    5802        7982 :                     n->defnames = $5;
    5803        7982 :                     n->definition = $6;
    5804        7982 :                     $$ = (Node *)n;
    5805             :                 }
    5806             :             | CREATE TEXT_P SEARCH TEMPLATE any_name definition
    5807             :                 {
    5808         390 :                     DefineStmt *n = makeNode(DefineStmt);
    5809         390 :                     n->kind = OBJECT_TSTEMPLATE;
    5810         390 :                     n->args = NIL;
    5811         390 :                     n->defnames = $5;
    5812         390 :                     n->definition = $6;
    5813         390 :                     $$ = (Node *)n;
    5814             :                 }
    5815             :             | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
    5816             :                 {
    5817        7934 :                     DefineStmt *n = makeNode(DefineStmt);
    5818        7934 :                     n->kind = OBJECT_TSCONFIGURATION;
    5819        7934 :                     n->args = NIL;
    5820        7934 :                     n->defnames = $5;
    5821        7934 :                     n->definition = $6;
    5822        7934 :                     $$ = (Node *)n;
    5823             :                 }
    5824             :             | CREATE COLLATION any_name definition
    5825             :                 {
    5826           8 :                     DefineStmt *n = makeNode(DefineStmt);
    5827           8 :                     n->kind = OBJECT_COLLATION;
    5828           8 :                     n->args = NIL;
    5829           8 :                     n->defnames = $3;
    5830           8 :                     n->definition = $4;
    5831           8 :                     $$ = (Node *)n;
    5832             :                 }
    5833             :             | CREATE COLLATION IF_P NOT EXISTS any_name definition
    5834             :                 {
    5835           0 :                     DefineStmt *n = makeNode(DefineStmt);
    5836           0 :                     n->kind = OBJECT_COLLATION;
    5837           0 :                     n->args = NIL;
    5838           0 :                     n->defnames = $6;
    5839           0 :                     n->definition = $7;
    5840           0 :                     n->if_not_exists = true;
    5841           0 :                     $$ = (Node *)n;
    5842             :                 }
    5843             :             | CREATE COLLATION any_name FROM any_name
    5844             :                 {
    5845          12 :                     DefineStmt *n = makeNode(DefineStmt);
    5846          12 :                     n->kind = OBJECT_COLLATION;
    5847          12 :                     n->args = NIL;
    5848          12 :                     n->defnames = $3;
    5849          12 :                     n->definition = list_make1(makeDefElem("from", (Node *) $5, @5));
    5850          12 :                     $$ = (Node *)n;
    5851             :                 }
    5852             :             | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
    5853             :                 {
    5854           0 :                     DefineStmt *n = makeNode(DefineStmt);
    5855           0 :                     n->kind = OBJECT_COLLATION;
    5856           0 :                     n->args = NIL;
    5857           0 :                     n->defnames = $6;
    5858           0 :                     n->definition = list_make1(makeDefElem("from", (Node *) $8, @8));
    5859           0 :                     n->if_not_exists = true;
    5860           0 :                     $$ = (Node *)n;
    5861             :                 }
    5862             :         ;
    5863             : 
    5864       18468 : definition: '(' def_list ')'                        { $$ = $2; }
    5865             :         ;
    5866             : 
    5867       18468 : def_list:   def_elem                                { $$ = list_make1($1); }
    5868       21526 :             | def_list ',' def_elem                 { $$ = lappend($1, $3); }
    5869             :         ;
    5870             : 
    5871             : def_elem:   ColLabel '=' def_arg
    5872             :                 {
    5873       39742 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    5874             :                 }
    5875             :             | ColLabel
    5876             :                 {
    5877         252 :                     $$ = makeDefElem($1, NULL, @1);
    5878             :                 }
    5879             :         ;
    5880             : 
    5881             : /* Note: any simple identifier will be returned as a type name! */
    5882       30798 : def_arg:    func_type                       { $$ = (Node *)$1; }
    5883        8334 :             | reserved_keyword              { $$ = (Node *)makeString(pstrdup($1)); }
    5884        1004 :             | qual_all_Op                   { $$ = (Node *)$1; }
    5885         678 :             | NumericOnly                   { $$ = (Node *)$1; }
    5886        1154 :             | Sconst                        { $$ = (Node *)makeString($1); }
    5887          36 :             | NONE                          { $$ = (Node *)makeString(pstrdup($1)); }
    5888             :         ;
    5889             : 
    5890         244 : old_aggr_definition: '(' old_aggr_list ')'          { $$ = $2; }
    5891             :         ;
    5892             : 
    5893         244 : old_aggr_list: old_aggr_elem                        { $$ = list_make1($1); }
    5894         872 :             | old_aggr_list ',' old_aggr_elem       { $$ = lappend($1, $3); }
    5895             :         ;
    5896             : 
    5897             : /*
    5898             :  * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
    5899             :  * the item names needed in old aggregate definitions are likely to become
    5900             :  * SQL keywords.
    5901             :  */
    5902             : old_aggr_elem:  IDENT '=' def_arg
    5903             :                 {
    5904        1116 :                     $$ = makeDefElem($1, (Node *)$3, @1);
    5905             :                 }
    5906             :         ;
    5907             : 
    5908             : opt_enum_val_list:
    5909         104 :         enum_val_list                           { $$ = $1; }
    5910           4 :         | /*EMPTY*/                             { $$ = NIL; }
    5911             :         ;
    5912             : 
    5913             : enum_val_list:  Sconst
    5914         104 :                 { $$ = list_make1(makeString($1)); }
    5915             :             | enum_val_list ',' Sconst
    5916       10196 :                 { $$ = lappend($1, makeString($3)); }
    5917             :         ;
    5918             : 
    5919             : /*****************************************************************************
    5920             :  *
    5921             :  *  ALTER TYPE enumtype ADD ...
    5922             :  *
    5923             :  *****************************************************************************/
    5924             : 
    5925             : AlterEnumStmt:
    5926             :         ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
    5927             :             {
    5928         118 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    5929         118 :                 n->typeName = $3;
    5930         118 :                 n->oldVal = NULL;
    5931         118 :                 n->newVal = $7;
    5932         118 :                 n->newValNeighbor = NULL;
    5933         118 :                 n->newValIsAfter = true;
    5934         118 :                 n->skipIfNewValExists = $6;
    5935         118 :                 $$ = (Node *) n;
    5936             :             }
    5937             :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
    5938             :             {
    5939         130 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    5940         130 :                 n->typeName = $3;
    5941         130 :                 n->oldVal = NULL;
    5942         130 :                 n->newVal = $7;
    5943         130 :                 n->newValNeighbor = $9;
    5944         130 :                 n->newValIsAfter = false;
    5945         130 :                 n->skipIfNewValExists = $6;
    5946         130 :                 $$ = (Node *) n;
    5947             :             }
    5948             :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
    5949             :             {
    5950          16 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    5951          16 :                 n->typeName = $3;
    5952          16 :                 n->oldVal = NULL;
    5953          16 :                 n->newVal = $7;
    5954          16 :                 n->newValNeighbor = $9;
    5955          16 :                 n->newValIsAfter = true;
    5956          16 :                 n->skipIfNewValExists = $6;
    5957          16 :                 $$ = (Node *) n;
    5958             :             }
    5959             :          | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
    5960             :             {
    5961          16 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    5962          16 :                 n->typeName = $3;
    5963          16 :                 n->oldVal = $6;
    5964          16 :                 n->newVal = $8;
    5965          16 :                 n->newValNeighbor = NULL;
    5966          16 :                 n->newValIsAfter = false;
    5967          16 :                 n->skipIfNewValExists = false;
    5968          16 :                 $$ = (Node *) n;
    5969             :             }
    5970             :          ;
    5971             : 
    5972           8 : opt_if_not_exists: IF_P NOT EXISTS              { $$ = true; }
    5973         256 :         | /* empty */                          { $$ = false; }
    5974             :         ;
    5975             : 
    5976             : 
    5977             : /*****************************************************************************
    5978             :  *
    5979             :  *      QUERIES :
    5980             :  *              CREATE OPERATOR CLASS ...
    5981             :  *              CREATE OPERATOR FAMILY ...
    5982             :  *              ALTER OPERATOR FAMILY ...
    5983             :  *              DROP OPERATOR CLASS ...
    5984             :  *              DROP OPERATOR FAMILY ...
    5985             :  *
    5986             :  *****************************************************************************/
    5987             : 
    5988             : CreateOpClassStmt:
    5989             :             CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
    5990             :             USING access_method opt_opfamily AS opclass_item_list
    5991             :                 {
    5992         306 :                     CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
    5993         306 :                     n->opclassname = $4;
    5994         306 :                     n->isDefault = $5;
    5995         306 :                     n->datatype = $8;
    5996         306 :                     n->amname = $10;
    5997         306 :                     n->opfamilyname = $11;
    5998         306 :                     n->items = $13;
    5999         306 :                     $$ = (Node *) n;
    6000             :                 }
    6001             :         ;
    6002             : 
    6003             : opclass_item_list:
    6004         604 :             opclass_item                            { $$ = list_make1($1); }
    6005        2748 :             | opclass_item_list ',' opclass_item    { $$ = lappend($1, $3); }
    6006             :         ;
    6007             : 
    6008             : opclass_item:
    6009             :             OPERATOR Iconst any_operator opclass_purpose opt_recheck
    6010             :                 {
    6011         996 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6012         996 :                     ObjectWithArgs *owa = makeNode(ObjectWithArgs);
    6013         996 :                     owa->objname = $3;
    6014         996 :                     owa->objargs = NIL;
    6015         996 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6016         996 :                     n->name = owa;
    6017         996 :                     n->number = $2;
    6018         996 :                     n->order_family = $4;
    6019         996 :                     $$ = (Node *) n;
    6020             :                 }
    6021             :             | OPERATOR Iconst operator_with_argtypes opclass_purpose
    6022             :               opt_recheck
    6023             :                 {
    6024         830 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6025         830 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6026         830 :                     n->name = $3;
    6027         830 :                     n->number = $2;
    6028         830 :                     n->order_family = $4;
    6029         830 :                     $$ = (Node *) n;
    6030             :                 }
    6031             :             | FUNCTION Iconst function_with_argtypes
    6032             :                 {
    6033        1224 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6034        1224 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6035        1224 :                     n->name = $3;
    6036        1224 :                     n->number = $2;
    6037        1224 :                     $$ = (Node *) n;
    6038             :                 }
    6039             :             | FUNCTION Iconst '(' type_list ')' function_with_argtypes
    6040             :                 {
    6041         126 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6042         126 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6043         126 :                     n->name = $6;
    6044         126 :                     n->number = $2;
    6045         126 :                     n->class_args = $4;
    6046         126 :                     $$ = (Node *) n;
    6047             :                 }
    6048             :             | STORAGE Typename
    6049             :                 {
    6050         176 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6051         176 :                     n->itemtype = OPCLASS_ITEM_STORAGETYPE;
    6052         176 :                     n->storedtype = $2;
    6053         176 :                     $$ = (Node *) n;
    6054             :                 }
    6055             :         ;
    6056             : 
    6057         256 : opt_default:    DEFAULT                     { $$ = true; }
    6058          94 :             | /*EMPTY*/                     { $$ = false; }
    6059             :         ;
    6060             : 
    6061          42 : opt_opfamily:   FAMILY any_name             { $$ = $2; }
    6062         264 :             | /*EMPTY*/                     { $$ = NIL; }
    6063             :         ;
    6064             : 
    6065           0 : opclass_purpose: FOR SEARCH                 { $$ = NIL; }
    6066          66 :             | FOR ORDER BY any_name         { $$ = $4; }
    6067        1760 :             | /*EMPTY*/                     { $$ = NIL; }
    6068             :         ;
    6069             : 
    6070             : opt_recheck:    RECHECK
    6071             :                 {
    6072             :                     /*
    6073             :                      * RECHECK no longer does anything in opclass definitions,
    6074             :                      * but we still accept it to ease porting of old database
    6075             :                      * dumps.
    6076             :                      */
    6077           0 :                     ereport(NOTICE,
    6078             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6079             :                              errmsg("RECHECK is no longer required"),
    6080             :                              errhint("Update your data type."),
    6081             :                              parser_errposition(@1)));
    6082           0 :                     $$ = true;
    6083             :                 }
    6084        1826 :             | /*EMPTY*/                     { $$ = false; }
    6085             :         ;
    6086             : 
    6087             : 
    6088             : CreateOpFamilyStmt:
    6089             :             CREATE OPERATOR FAMILY any_name USING access_method
    6090             :                 {
    6091         102 :                     CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
    6092         102 :                     n->opfamilyname = $4;
    6093         102 :                     n->amname = $6;
    6094         102 :                     $$ = (Node *) n;
    6095             :                 }
    6096             :         ;
    6097             : 
    6098             : AlterOpFamilyStmt:
    6099             :             ALTER OPERATOR FAMILY any_name USING access_method ADD_P opclass_item_list
    6100             :                 {
    6101         298 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6102         298 :                     n->opfamilyname = $4;
    6103         298 :                     n->amname = $6;
    6104         298 :                     n->isDrop = false;
    6105         298 :                     n->items = $8;
    6106         298 :                     $$ = (Node *) n;
    6107             :                 }
    6108             :             | ALTER OPERATOR FAMILY any_name USING access_method DROP opclass_drop_list
    6109             :                 {
    6110          40 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6111          40 :                     n->opfamilyname = $4;
    6112          40 :                     n->amname = $6;
    6113          40 :                     n->isDrop = true;
    6114          40 :                     n->items = $8;
    6115          40 :                     $$ = (Node *) n;
    6116             :                 }
    6117             :         ;
    6118             : 
    6119             : opclass_drop_list:
    6120          40 :             opclass_drop                            { $$ = list_make1($1); }
    6121          20 :             | opclass_drop_list ',' opclass_drop    { $$ = lappend($1, $3); }
    6122             :         ;
    6123             : 
    6124             : opclass_drop:
    6125             :             OPERATOR Iconst '(' type_list ')'
    6126             :                 {
    6127          32 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6128          32 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6129          32 :                     n->number = $2;
    6130          32 :                     n->class_args = $4;
    6131          32 :                     $$ = (Node *) n;
    6132             :                 }
    6133             :             | FUNCTION Iconst '(' type_list ')'
    6134             :                 {
    6135          28 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6136          28 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6137          28 :                     n->number = $2;
    6138          28 :                     n->class_args = $4;
    6139          28 :                     $$ = (Node *) n;
    6140             :                 }
    6141             :         ;
    6142             : 
    6143             : 
    6144             : DropOpClassStmt:
    6145             :             DROP OPERATOR CLASS any_name USING access_method opt_drop_behavior
    6146             :                 {
    6147          22 :                     DropStmt *n = makeNode(DropStmt);
    6148          22 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6149          22 :                     n->removeType = OBJECT_OPCLASS;
    6150          22 :                     n->behavior = $7;
    6151          22 :                     n->missing_ok = false;
    6152          22 :                     n->concurrent = false;
    6153          22 :                     $$ = (Node *) n;
    6154             :                 }
    6155             :             | DROP OPERATOR CLASS IF_P EXISTS any_name USING access_method opt_drop_behavior
    6156             :                 {
    6157          12 :                     DropStmt *n = makeNode(DropStmt);
    6158          12 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6159          12 :                     n->removeType = OBJECT_OPCLASS;
    6160          12 :                     n->behavior = $9;
    6161          12 :                     n->missing_ok = true;
    6162          12 :                     n->concurrent = false;
    6163          12 :                     $$ = (Node *) n;
    6164             :                 }
    6165             :         ;
    6166             : 
    6167             : DropOpFamilyStmt:
    6168             :             DROP OPERATOR FAMILY any_name USING access_method opt_drop_behavior
    6169             :                 {
    6170          74 :                     DropStmt *n = makeNode(DropStmt);
    6171          74 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6172          74 :                     n->removeType = OBJECT_OPFAMILY;
    6173          74 :                     n->behavior = $7;
    6174          74 :                     n->missing_ok = false;
    6175          74 :                     n->concurrent = false;
    6176          74 :                     $$ = (Node *) n;
    6177             :                 }
    6178             :             | DROP OPERATOR FAMILY IF_P EXISTS any_name USING access_method opt_drop_behavior
    6179             :                 {
    6180          12 :                     DropStmt *n = makeNode(DropStmt);
    6181          12 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6182          12 :                     n->removeType = OBJECT_OPFAMILY;
    6183          12 :                     n->behavior = $9;
    6184          12 :                     n->missing_ok = true;
    6185          12 :                     n->concurrent = false;
    6186          12 :                     $$ = (Node *) n;
    6187             :                 }
    6188             :         ;
    6189             : 
    6190             : 
    6191             : /*****************************************************************************
    6192             :  *
    6193             :  *      QUERY:
    6194             :  *
    6195             :  *      DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
    6196             :  *      REASSIGN OWNED BY username [, username ...] TO username
    6197             :  *
    6198             :  *****************************************************************************/
    6199             : DropOwnedStmt:
    6200             :             DROP OWNED BY role_list opt_drop_behavior
    6201             :                 {
    6202          72 :                     DropOwnedStmt *n = makeNode(DropOwnedStmt);
    6203          72 :                     n->roles = $4;
    6204          72 :                     n->behavior = $5;
    6205          72 :                     $$ = (Node *)n;
    6206             :                 }
    6207             :         ;
    6208             : 
    6209             : ReassignOwnedStmt:
    6210             :             REASSIGN OWNED BY role_list TO RoleSpec
    6211             :                 {
    6212          16 :                     ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
    6213          16 :                     n->roles = $4;
    6214          16 :                     n->newrole = $6;
    6215          16 :                     $$ = (Node *)n;
    6216             :                 }
    6217             :         ;
    6218             : 
    6219             : /*****************************************************************************
    6220             :  *
    6221             :  *      QUERY:
    6222             :  *
    6223             :  *      DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
    6224             :  *           [ RESTRICT | CASCADE ]
    6225             :  *
    6226             :  *****************************************************************************/
    6227             : 
    6228             : DropStmt:   DROP drop_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
    6229             :                 {
    6230         652 :                     DropStmt *n = makeNode(DropStmt);
    6231         652 :                     n->removeType = $2;
    6232         652 :                     n->missing_ok = true;
    6233         652 :                     n->objects = $5;
    6234         652 :                     n->behavior = $6;
    6235         652 :                     n->concurrent = false;
    6236         652 :                     $$ = (Node *)n;
    6237             :                 }
    6238             :             | DROP drop_type_any_name any_name_list opt_drop_behavior
    6239             :                 {
    6240        8716 :                     DropStmt *n = makeNode(DropStmt);
    6241        8716 :                     n->removeType = $2;
    6242        8716 :                     n->missing_ok = false;
    6243        8716 :                     n->objects = $3;
    6244        8716 :                     n->behavior = $4;
    6245        8716 :                     n->concurrent = false;
    6246        8716 :                     $$ = (Node *)n;
    6247             :                 }
    6248             :             | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
    6249             :                 {
    6250          52 :                     DropStmt *n = makeNode(DropStmt);
    6251          52 :                     n->removeType = $2;
    6252          52 :                     n->missing_ok = true;
    6253          52 :                     n->objects = $5;
    6254          52 :                     n->behavior = $6;
    6255          52 :                     n->concurrent = false;
    6256          52 :                     $$ = (Node *)n;
    6257             :                 }
    6258             :             | DROP drop_type_name name_list opt_drop_behavior
    6259             :                 {
    6260         514 :                     DropStmt *n = makeNode(DropStmt);
    6261         514 :                     n->removeType = $2;
    6262         514 :                     n->missing_ok = false;
    6263         514 :                     n->objects = $3;
    6264         514 :                     n->behavior = $4;
    6265         514 :                     n->concurrent = false;
    6266         514 :                     $$ = (Node *)n;
    6267             :                 }
    6268             :             | DROP drop_type_name_on_any_name name ON any_name opt_drop_behavior
    6269             :                 {
    6270         706 :                     DropStmt *n = makeNode(DropStmt);
    6271         706 :                     n->removeType = $2;
    6272         706 :                     n->objects = list_make1(lappend($5, makeString($3)));
    6273         706 :                     n->behavior = $6;
    6274         706 :                     n->missing_ok = false;
    6275         706 :                     n->concurrent = false;
    6276         706 :                     $$ = (Node *) n;
    6277             :                 }
    6278             :             | DROP drop_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
    6279             :                 {
    6280          32 :                     DropStmt *n = makeNode(DropStmt);
    6281          32 :                     n->removeType = $2;
    6282          32 :                     n->objects = list_make1(lappend($7, makeString($5)));
    6283          32 :                     n->behavior = $8;
    6284          32 :                     n->missing_ok = true;
    6285          32 :                     n->concurrent = false;
    6286          32 :                     $$ = (Node *) n;
    6287             :                 }
    6288             :             | DROP TYPE_P type_name_list opt_drop_behavior
    6289             :                 {
    6290         264 :                     DropStmt *n = makeNode(DropStmt);
    6291         264 :                     n->removeType = OBJECT_TYPE;
    6292         264 :                     n->missing_ok = false;
    6293         264 :                     n->objects = $3;
    6294         264 :                     n->behavior = $4;
    6295         264 :                     n->concurrent = false;
    6296         264 :                     $$ = (Node *) n;
    6297             :                 }
    6298             :             | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
    6299             :                 {
    6300          16 :                     DropStmt *n = makeNode(DropStmt);
    6301          16 :                     n->removeType = OBJECT_TYPE;
    6302          16 :                     n->missing_ok = true;
    6303          16 :                     n->objects = $5;
    6304          16 :                     n->behavior = $6;
    6305          16 :                     n->concurrent = false;
    6306          16 :                     $$ = (Node *) n;
    6307             :                 }
    6308             :             | DROP DOMAIN_P type_name_list opt_drop_behavior
    6309             :                 {
    6310         220 :                     DropStmt *n = makeNode(DropStmt);
    6311         220 :                     n->removeType = OBJECT_DOMAIN;
    6312         220 :                     n->missing_ok = false;
    6313         220 :                     n->objects = $3;
    6314         220 :                     n->behavior = $4;
    6315         220 :                     n->concurrent = false;
    6316         220 :                     $$ = (Node *) n;
    6317             :                 }
    6318             :             | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
    6319             :                 {
    6320          12 :                     DropStmt *n = makeNode(DropStmt);
    6321          12 :                     n->removeType = OBJECT_DOMAIN;
    6322          12 :                     n->missing_ok = true;
    6323          12 :                     n->objects = $5;
    6324          12 :                     n->behavior = $6;
    6325          12 :                     n->concurrent = false;
    6326          12 :                     $$ = (Node *) n;
    6327             :                 }
    6328             :             | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
    6329             :                 {
    6330          38 :                     DropStmt *n = makeNode(DropStmt);
    6331          38 :                     n->removeType = OBJECT_INDEX;
    6332          38 :                     n->missing_ok = false;
    6333          38 :                     n->objects = $4;
    6334          38 :                     n->behavior = $5;
    6335          38 :                     n->concurrent = true;
    6336          38 :                     $$ = (Node *)n;
    6337             :                 }
    6338             :             | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
    6339             :                 {
    6340           8 :                     DropStmt *n = makeNode(DropStmt);
    6341           8 :                     n->removeType = OBJECT_INDEX;
    6342           8 :                     n->missing_ok = true;
    6343           8 :                     n->objects = $6;
    6344           8 :                     n->behavior = $7;
    6345           8 :                     n->concurrent = true;
    6346           8 :                     $$ = (Node *)n;
    6347             :                 }
    6348             :         ;
    6349             : 
    6350             : /* object types taking any_name_list */
    6351             : drop_type_any_name:
    6352        8254 :             TABLE                                   { $$ = OBJECT_TABLE; }
    6353         104 :             | SEQUENCE                              { $$ = OBJECT_SEQUENCE; }
    6354         438 :             | VIEW                                  { $$ = OBJECT_VIEW; }
    6355          38 :             | MATERIALIZED VIEW                     { $$ = OBJECT_MATVIEW; }
    6356         342 :             | INDEX                                 { $$ = OBJECT_INDEX; }
    6357          78 :             | FOREIGN TABLE                         { $$ = OBJECT_FOREIGN_TABLE; }
    6358          18 :             | COLLATION                             { $$ = OBJECT_COLLATION; }
    6359          24 :             | CONVERSION_P                          { $$ = OBJECT_CONVERSION; }
    6360          28 :             | STATISTICS                            { $$ = OBJECT_STATISTIC_EXT; }
    6361          12 :             | TEXT_P SEARCH PARSER                  { $$ = OBJECT_TSPARSER; }
    6362          16 :             | TEXT_P SEARCH DICTIONARY              { $$ = OBJECT_TSDICTIONARY; }
    6363          12 :             | TEXT_P SEARCH TEMPLATE                { $$ = OBJECT_TSTEMPLATE; }
    6364          16 :             | TEXT_P SEARCH CONFIGURATION           { $$ = OBJECT_TSCONFIGURATION; }
    6365             :         ;
    6366             : 
    6367             : /* object types taking name_list */
    6368             : drop_type_name:
    6369          24 :             ACCESS METHOD                           { $$ = OBJECT_ACCESS_METHOD; }
    6370          62 :             | EVENT TRIGGER                         { $$ = OBJECT_EVENT_TRIGGER; }
    6371          78 :             | EXTENSION                             { $$ = OBJECT_EXTENSION; }
    6372          88 :             | FOREIGN DATA_P WRAPPER                { $$ = OBJECT_FDW; }
    6373          38 :             | PUBLICATION                           { $$ = OBJECT_PUBLICATION; }
    6374         202 :             | SCHEMA                                { $$ = OBJECT_SCHEMA; }
    6375          74 :             | SERVER                                { $$ = OBJECT_FOREIGN_SERVER; }
    6376             :         ;
    6377             : 
    6378             : /* object types attached to a table */
    6379             : drop_type_name_on_any_name:
    6380          82 :             POLICY                                  { $$ = OBJECT_POLICY; }
    6381         142 :             | RULE                                  { $$ = OBJECT_RULE; }
    6382         522 :             | TRIGGER                               { $$ = OBJECT_TRIGGER; }
    6383             :         ;
    6384             : 
    6385             : any_name_list:
    6386       33284 :             any_name                                { $$ = list_make1($1); }
    6387        2428 :             | any_name_list ',' any_name            { $$ = lappend($1, $3); }
    6388             :         ;
    6389             : 
    6390       99428 : any_name:   ColId                       { $$ = list_make1(makeString($1)); }
    6391        3784 :             | ColId attrs               { $$ = lcons(makeString($1), $2); }
    6392             :         ;
    6393             : 
    6394             : attrs:      '.' attr_name
    6395       63292 :                     { $$ = list_make1(makeString($2)); }
    6396             :             | attrs '.' attr_name
    6397          26 :                     { $$ = lappend($1, makeString($3)); }
    6398             :         ;
    6399             : 
    6400             : type_name_list:
    6401         512 :             Typename                                { $$ = list_make1($1); }
    6402          32 :             | type_name_list ',' Typename           { $$ = lappend($1, $3); }
    6403             :         ;
    6404             : 
    6405             : /*****************************************************************************
    6406             :  *
    6407             :  *      QUERY:
    6408             :  *              truncate table relname1, relname2, ...
    6409             :  *
    6410             :  *****************************************************************************/
    6411             : 
    6412             : TruncateStmt:
    6413             :             TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
    6414             :                 {
    6415         794 :                     TruncateStmt *n = makeNode(TruncateStmt);
    6416         794 :                     n->relations = $3;
    6417         794 :                     n->restart_seqs = $4;
    6418         794 :                     n->behavior = $5;
    6419         794 :                     $$ = (Node *)n;
    6420             :                 }
    6421             :         ;
    6422             : 
    6423             : opt_restart_seqs:
    6424           0 :             CONTINUE_P IDENTITY_P       { $$ = false; }
    6425          16 :             | RESTART IDENTITY_P        { $$ = true; }
    6426         778 :             | /* EMPTY */               { $$ = false; }
    6427             :         ;
    6428             : 
    6429             : /*****************************************************************************
    6430             :  *
    6431             :  *  The COMMENT ON statement can take different forms based upon the type of
    6432             :  *  the object associated with the comment. The form of the statement is:
    6433             :  *
    6434             :  *  COMMENT ON [ [ ACCESS METHOD | CONVERSION | COLLATION |
    6435             :  *                 DATABASE | DOMAIN |
    6436             :  *                 EXTENSION | EVENT TRIGGER | FOREIGN DATA WRAPPER |
    6437             :  *                 FOREIGN TABLE | INDEX | [PROCEDURAL] LANGUAGE |
    6438             :  *                 MATERIALIZED VIEW | POLICY | ROLE | SCHEMA | SEQUENCE |
    6439             :  *                 SERVER | STATISTICS | TABLE | TABLESPACE |
    6440             :  *                 TEXT SEARCH CONFIGURATION | TEXT SEARCH DICTIONARY |
    6441             :  *                 TEXT SEARCH PARSER | TEXT SEARCH TEMPLATE | TYPE |
    6442             :  *                 VIEW] <objname> |
    6443             :  *               AGGREGATE <aggname> (arg1, ...) |
    6444             :  *               CAST (<src type> AS <dst type>) |
    6445             :  *               COLUMN <relname>.<colname> |
    6446             :  *               CONSTRAINT <constraintname> ON <relname> |
    6447             :  *               CONSTRAINT <constraintname> ON DOMAIN <domainname> |
    6448             :  *               FUNCTION <funcname> (arg1, arg2, ...) |
    6449             :  *               LARGE OBJECT <oid> |
    6450             :  *               OPERATOR <op> (leftoperand_typ, rightoperand_typ) |
    6451             :  *               OPERATOR CLASS <name> USING <access-method> |
    6452             :  *               OPERATOR FAMILY <name> USING <access-method> |
    6453             :  *               RULE <rulename> ON <relname> |
    6454             :  *               TRIGGER <triggername> ON <relname> ]
    6455             :  *             IS { 'text' | NULL }
    6456             :  *
    6457             :  *****************************************************************************/
    6458             : 
    6459             : CommentStmt:
    6460             :             COMMENT ON comment_type_any_name any_name IS comment_text
    6461             :                 {
    6462       16336 :                     CommentStmt *n = makeNode(CommentStmt);
    6463       16336 :                     n->objtype = $3;
    6464       16336 :                     n->object = (Node *) $4;
    6465       16336 :                     n->comment = $6;
    6466       16336 :                     $$ = (Node *) n;
    6467             :                 }
    6468             :             | COMMENT ON comment_type_name name IS comment_text
    6469             :                 {
    6470        1148 :                     CommentStmt *n = makeNode(CommentStmt);
    6471        1148 :                     n->objtype = $3;
    6472        1148 :                     n->object = (Node *) makeString($4);
    6473        1148 :                     n->comment = $6;
    6474        1148 :                     $$ = (Node *) n;
    6475             :                 }
    6476             :             | COMMENT ON TYPE_P Typename IS comment_text
    6477             :                 {
    6478          48 :                     CommentStmt *n = makeNode(CommentStmt);
    6479          48 :                     n->objtype = OBJECT_TYPE;
    6480          48 :                     n->object = (Node *) $4;
    6481          48 :                     n->comment = $6;
    6482          48 :                     $$ = (Node *) n;
    6483             :                 }
    6484             :             | COMMENT ON DOMAIN_P Typename IS comment_text
    6485             :                 {
    6486           6 :                     CommentStmt *n = makeNode(CommentStmt);
    6487           6 :                     n->objtype = OBJECT_DOMAIN;
    6488           6 :                     n->object = (Node *) $4;
    6489           6 :                     n->comment = $6;
    6490           6 :                     $$ = (Node *) n;
    6491             :                 }
    6492             :             | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
    6493             :                 {
    6494          28 :                     CommentStmt *n = makeNode(CommentStmt);
    6495          28 :                     n->objtype = OBJECT_AGGREGATE;
    6496          28 :                     n->object = (Node *) $4;
    6497          28 :                     n->comment = $6;
    6498          28 :                     $$ = (Node *) n;
    6499             :                 }
    6500             :             | COMMENT ON FUNCTION function_with_argtypes IS comment_text
    6501             :                 {
    6502         842 :                     CommentStmt *n = makeNode(CommentStmt);
    6503         842 :                     n->objtype = OBJECT_FUNCTION;
    6504         842 :                     n->object = (Node *) $4;
    6505         842 :                     n->comment = $6;
    6506         842 :                     $$ = (Node *) n;
    6507             :                 }
    6508             :             | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
    6509             :                 {
    6510           4 :                     CommentStmt *n = makeNode(CommentStmt);
    6511           4 :                     n->objtype = OBJECT_OPERATOR;
    6512           4 :                     n->object = (Node *) $4;
    6513           4 :                     n->comment = $6;
    6514           4 :                     $$ = (Node *) n;
    6515             :                 }
    6516             :             | COMMENT ON CONSTRAINT name ON any_name IS comment_text
    6517             :                 {
    6518          70 :                     CommentStmt *n = makeNode(CommentStmt);
    6519          70 :                     n->objtype = OBJECT_TABCONSTRAINT;
    6520          70 :                     n->object = (Node *) lappend($6, makeString($4));
    6521          70 :                     n->comment = $8;
    6522          70 :                     $$ = (Node *) n;
    6523             :                 }
    6524             :             | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
    6525             :                 {
    6526          24 :                     CommentStmt *n = makeNode(CommentStmt);
    6527          24 :                     n->objtype = OBJECT_DOMCONSTRAINT;
    6528             :                     /*
    6529             :                      * should use Typename not any_name in the production, but
    6530             :                      * there's a shift/reduce conflict if we do that, so fix it
    6531             :                      * up here.
    6532             :                      */
    6533          24 :                     n->object = (Node *) list_make2(makeTypeNameFromNameList($7), makeString($4));
    6534          24 :                     n->comment = $9;
    6535          24 :                     $$ = (Node *) n;
    6536             :                 }
    6537             :             | COMMENT ON POLICY name ON any_name IS comment_text
    6538             :                 {
    6539           0 :                     CommentStmt *n = makeNode(CommentStmt);
    6540           0 :                     n->objtype = OBJECT_POLICY;
    6541           0 :                     n->object = (Node *) lappend($6, makeString($4));
    6542           0 :                     n->comment = $8;
    6543           0 :                     $$ = (Node *) n;
    6544             :                 }
    6545             :             | COMMENT ON PROCEDURE function_with_argtypes IS comment_text
    6546             :                 {
    6547           0 :                     CommentStmt *n = makeNode(CommentStmt);
    6548           0 :                     n->objtype = OBJECT_PROCEDURE;
    6549           0 :                     n->object = (Node *) $4;
    6550           0 :                     n->comment = $6;
    6551           0 :                     $$ = (Node *) n;
    6552             :                 }
    6553             :             | COMMENT ON ROUTINE function_with_argtypes IS comment_text
    6554             :                 {
    6555           0 :                     CommentStmt *n = makeNode(CommentStmt);
    6556           0 :                     n->objtype = OBJECT_ROUTINE;
    6557           0 :                     n->object = (Node *) $4;
    6558           0 :                     n->comment = $6;
    6559           0 :                     $$ = (Node *) n;
    6560             :                 }
    6561             :             | COMMENT ON RULE name ON any_name IS comment_text
    6562             :                 {
    6563          14 :                     CommentStmt *n = makeNode(CommentStmt);
    6564          14 :                     n->objtype = OBJECT_RULE;
    6565          14 :                     n->object = (Node *) lappend($6, makeString($4));
    6566          14 :                     n->comment = $8;
    6567          14 :                     $$ = (Node *) n;
    6568             :                 }
    6569             :             | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
    6570             :                 {
    6571          18 :                     CommentStmt *n = makeNode(CommentStmt);
    6572          18 :                     n->objtype = OBJECT_TRANSFORM;
    6573          18 :                     n->object = (Node *) list_make2($5, makeString($7));
    6574          18 :                     n->comment = $9;
    6575          18 :                     $$ = (Node *) n;
    6576             :                 }
    6577             :             | COMMENT ON TRIGGER name ON any_name IS comment_text
    6578             :                 {
    6579          14 :                     CommentStmt *n = makeNode(CommentStmt);
    6580          14 :                     n->objtype = OBJECT_TRIGGER;
    6581          14 :                     n->object = (Node *) lappend($6, makeString($4));
    6582          14 :                     n->comment = $8;
    6583          14 :                     $$ = (Node *) n;
    6584             :                 }
    6585             :             | COMMENT ON OPERATOR CLASS any_name USING access_method IS comment_text
    6586             :                 {
    6587           0 :                     CommentStmt *n = makeNode(CommentStmt);
    6588           0 :                     n->objtype = OBJECT_OPCLASS;
    6589           0 :                     n->object = (Node *) lcons(makeString($7), $5);
    6590           0 :                     n->comment = $9;
    6591           0 :                     $$ = (Node *) n;
    6592             :                 }
    6593             :             | COMMENT ON OPERATOR FAMILY any_name USING access_method IS comment_text
    6594             :                 {
    6595           0 :                     CommentStmt *n = makeNode(CommentStmt);
    6596           0 :                     n->objtype = OBJECT_OPFAMILY;
    6597           0 :                     n->object = (Node *) lcons(makeString($7), $5);
    6598           0 :                     n->comment = $9;
    6599           0 :                     $$ = (Node *) n;
    6600             :                 }
    6601             :             | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
    6602             :                 {
    6603          14 :                     CommentStmt *n = makeNode(CommentStmt);
    6604          14 :                     n->objtype = OBJECT_LARGEOBJECT;
    6605          14 :                     n->object = (Node *) $5;
    6606          14 :                     n->comment = $7;
    6607          14 :                     $$ = (Node *) n;
    6608             :                 }
    6609             :             | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
    6610             :                 {
    6611           0 :                     CommentStmt *n = makeNode(CommentStmt);
    6612           0 :                     n->objtype = OBJECT_CAST;
    6613           0 :                     n->object = (Node *) list_make2($5, $7);
    6614           0 :                     n->comment = $10;
    6615           0 :                     $$ = (Node *) n;
    6616             :                 }
    6617             :         ;
    6618             : 
    6619             : /* object types taking any_name */
    6620             : comment_type_any_name:
    6621          76 :             COLUMN                              { $$ = OBJECT_COLUMN; }
    6622          54 :             | INDEX                             { $$ = OBJECT_INDEX; }
    6623          14 :             | SEQUENCE                          { $$ = OBJECT_SEQUENCE; }
    6624           4 :             | STATISTICS                        { $$ = OBJECT_STATISTIC_EXT; }
    6625          24 :             | TABLE                             { $$ = OBJECT_TABLE; }
    6626          14 :             | VIEW                              { $$ = OBJECT_VIEW; }
    6627           0 :             | MATERIALIZED VIEW                 { $$ = OBJECT_MATVIEW; }
    6628           2 :             | COLLATION                         { $$ = OBJECT_COLLATION; }
    6629          14 :             | CONVERSION_P                      { $$ = OBJECT_CONVERSION; }
    6630          12 :             | FOREIGN TABLE                     { $$ = OBJECT_FOREIGN_TABLE; }
    6631        7878 :             | TEXT_P SEARCH CONFIGURATION       { $$ = OBJECT_TSCONFIGURATION; }
    6632        7882 :             | TEXT_P SEARCH DICTIONARY          { $$ = OBJECT_TSDICTIONARY; }
    6633           2 :             | TEXT_P SEARCH PARSER              { $$ = OBJECT_TSPARSER; }
    6634         360 :             | TEXT_P SEARCH TEMPLATE            { $$ = OBJECT_TSTEMPLATE; }
    6635             :         ;
    6636             : 
    6637             : /* object types taking name */
    6638             : comment_type_name:
    6639           4 :             ACCESS METHOD                       { $$ = OBJECT_ACCESS_METHOD; }
    6640         720 :             | DATABASE                          { $$ = OBJECT_DATABASE; }
    6641           4 :             | EVENT TRIGGER                     { $$ = OBJECT_EVENT_TRIGGER; }
    6642           0 :             | EXTENSION                         { $$ = OBJECT_EXTENSION; }
    6643           4 :             | FOREIGN DATA_P WRAPPER            { $$ = OBJECT_FDW; }
    6644         396 :             | opt_procedural LANGUAGE           { $$ = OBJECT_LANGUAGE; }
    6645           6 :             | PUBLICATION                       { $$ = OBJECT_PUBLICATION; }
    6646           2 :             | ROLE                              { $$ = OBJECT_ROLE; }
    6647           2 :             | SCHEMA                            { $$ = OBJECT_SCHEMA; }
    6648           4 :             | SERVER                            { $$ = OBJECT_FOREIGN_SERVER; }
    6649           6 :             | SUBSCRIPTION                      { $$ = OBJECT_SUBSCRIPTION; }
    6650           0 :             | TABLESPACE                        { $$ = OBJECT_TABLESPACE; }
    6651             :         ;
    6652             : 
    6653             : comment_text:
    6654       18502 :             Sconst                              { $$ = $1; }
    6655          64 :             | NULL_P                            { $$ = NULL; }
    6656             :         ;
    6657             : 
    6658             : 
    6659             : /*****************************************************************************
    6660             :  *
    6661             :  *  SECURITY LABEL [FOR <provider>] ON <object> IS <label>
    6662             :  *
    6663             :  *  As with COMMENT ON, <object> can refer to various types of database
    6664             :  *  objects (e.g. TABLE, COLUMN, etc.).
    6665             :  *
    6666             :  *****************************************************************************/
    6667             : 
    6668             : SecLabelStmt:
    6669             :             SECURITY LABEL opt_provider ON security_label_type_any_name any_name
    6670             :             IS security_label
    6671             :                 {
    6672          44 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    6673          44 :                     n->provider = $3;
    6674          44 :                     n->objtype = $5;
    6675          44 :                     n->object = (Node *) $6;
    6676          44 :                     n->label = $8;
    6677          44 :                     $$ = (Node *) n;
    6678             :                 }
    6679             :             | SECURITY LABEL opt_provider ON security_label_type_name name
    6680             :               IS security_label
    6681             :                 {
    6682          36 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    6683          36 :                     n->provider = $3;
    6684          36 :                     n->objtype = $5;
    6685          36 :                     n->object = (Node *) makeString($6);
    6686          36 :                     n->label = $8;
    6687          36 :                     $$ = (Node *) n;
    6688             :                 }
    6689             :             | SECURITY LABEL opt_provider ON TYPE_P Typename
    6690             :               IS security_label
    6691             :                 {
    6692           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    6693           0 :                     n->provider = $3;
    6694           0 :                     n->objtype = OBJECT_TYPE;
    6695           0 :                     n->object = (Node *) $6;
    6696           0 :                     n->label = $8;
    6697           0 :                     $$ = (Node *) n;
    6698             :                 }
    6699             :             | SECURITY LABEL opt_provider ON DOMAIN_P Typename
    6700             :               IS security_label
    6701             :                 {
    6702           2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    6703           2 :                     n->provider = $3;
    6704           2 :                     n->objtype = OBJECT_DOMAIN;
    6705           2 :                     n->object = (Node *) $6;
    6706           2 :                     n->label = $8;
    6707           2 :                     $$ = (Node *) n;
    6708             :                 }
    6709             :             | SECURITY LABEL opt_provider ON AGGREGATE aggregate_with_argtypes
    6710             :               IS security_label
    6711             :                 {
    6712           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    6713           0 :                     n->provider = $3;
    6714           0 :                     n->objtype = OBJECT_AGGREGATE;
    6715           0 :                     n->object = (Node *) $6;
    6716           0 :                     n->label = $8;
    6717           0 :                     $$ = (Node *) n;
    6718             :                 }
    6719             :             | SECURITY LABEL opt_provider ON FUNCTION function_with_argtypes
    6720             :               IS security_label
    6721             :                 {
    6722           2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    6723           2 :                     n->provider = $3;
    6724           2 :                     n->objtype = OBJECT_FUNCTION;
    6725           2 :                     n->object = (Node *) $6;
    6726           2 :                     n->label = $8;
    6727           2 :                     $$ = (Node *) n;
    6728             :                 }
    6729             :             | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
    6730             :               IS security_label
    6731             :                 {
    6732           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    6733           0 :                     n->provider = $3;
    6734           0 :                     n->objtype = OBJECT_LARGEOBJECT;
    6735           0 :                     n->object = (Node *) $7;
    6736           0 :                     n->label = $9;
    6737           0 :                     $$ = (Node *) n;
    6738             :                 }
    6739             :             | SECURITY LABEL opt_provider ON PROCEDURE function_with_argtypes
    6740             :               IS security_label
    6741             :                 {
    6742           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    6743           0 :                     n->provider = $3;
    6744           0 :                     n->objtype = OBJECT_PROCEDURE;
    6745           0 :                     n->object = (Node *) $6;
    6746           0 :                     n->label = $8;
    6747           0 :                     $$ = (Node *) n;
    6748             :                 }
    6749             :             | SECURITY LABEL opt_provider ON ROUTINE function_with_argtypes
    6750             :               IS security_label
    6751             :                 {
    6752           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    6753           0 :                     n->provider = $3;
    6754           0 :                     n->objtype = OBJECT_ROUTINE;
    6755           0 :                     n->object = (Node *) $6;
    6756           0 :                     n->label = $8;
    6757           0 :                     $$ = (Node *) n;
    6758             :                 }
    6759             :         ;
    6760             : 
    6761          16 : opt_provider:   FOR NonReservedWord_or_Sconst   { $$ = $2; }
    6762          68 :                 | /* empty */                   { $$ = NULL; }
    6763             :         ;
    6764             : 
    6765             : /* object types taking any_name */
    6766             : security_label_type_any_name:
    6767           4 :             COLUMN                              { $$ = OBJECT_COLUMN; }
    6768           0 :             | FOREIGN TABLE                     { $$ = OBJECT_FOREIGN_TABLE; }
    6769           0 :             | SEQUENCE                          { $$ = OBJECT_SEQUENCE; }
    6770          38 :             | TABLE                             { $$ = OBJECT_TABLE; }
    6771           2 :             | VIEW                              { $$ = OBJECT_VIEW; }
    6772           0 :             | MATERIALIZED VIEW                 { $$ = OBJECT_MATVIEW; }
    6773             :         ;
    6774             : 
    6775             : /* object types taking name */
    6776             : security_label_type_name:
    6777           0 :             DATABASE                            { $$ = OBJECT_DATABASE; }
    6778           0 :             | EVENT TRIGGER                     { $$ = OBJECT_EVENT_TRIGGER; }
    6779           0 :             | opt_procedural LANGUAGE           { $$ = OBJECT_LANGUAGE; }
    6780           2 :             | PUBLICATION                       { $$ = OBJECT_PUBLICATION; }
    6781          30 :             | ROLE                              { $$ = OBJECT_ROLE; }
    6782           2 :             | SCHEMA                            { $$ = OBJECT_SCHEMA; }
    6783           2 :             | SUBSCRIPTION                      { $$ = OBJECT_SUBSCRIPTION; }
    6784           0 :             | TABLESPACE                        { $$ = OBJECT_TABLESPACE; }
    6785             :         ;
    6786             : 
    6787          84 : security_label: Sconst              { $$ = $1; }
    6788           0 :                 | NULL_P            { $$ = NULL; }
    6789             :         ;
    6790             : 
    6791             : /*****************************************************************************
    6792             :  *
    6793             :  *      QUERY:
    6794             :  *          fetch/move
    6795             :  *
    6796             :  *****************************************************************************/
    6797             : 
    6798             : FetchStmt:  FETCH fetch_args
    6799             :                 {
    6800        4346 :                     FetchStmt *n = (FetchStmt *) $2;
    6801        4346 :                     n->ismove = false;
    6802        4346 :                     $$ = (Node *)n;
    6803             :                 }
    6804             :             | MOVE fetch_args
    6805             :                 {
    6806          52 :                     FetchStmt *n = (FetchStmt *) $2;
    6807          52 :                     n->ismove = true;
    6808          52 :                     $$ = (Node *)n;
    6809             :                 }
    6810             :         ;
    6811             : 
    6812             : fetch_args: cursor_name
    6813             :                 {
    6814         210 :                     FetchStmt *n = makeNode(FetchStmt);
    6815         210 :                     n->portalname = $1;
    6816         210 :                     n->direction = FETCH_FORWARD;
    6817         210 :                     n->howMany = 1;
    6818         210 :                     $$ = (Node *)n;
    6819             :                 }
    6820             :             | from_in cursor_name
    6821             :                 {
    6822         166 :                     FetchStmt *n = makeNode(FetchStmt);
    6823         166 :                     n->portalname = $2;
    6824         166 :                     n->direction = FETCH_FORWARD;
    6825         166 :                     n->howMany = 1;
    6826         166 :                     $$ = (Node *)n;
    6827             :                 }
    6828             :             | NEXT opt_from_in cursor_name
    6829             :                 {
    6830         150 :                     FetchStmt *n = makeNode(FetchStmt);
    6831         150 :                     n->portalname = $3;
    6832         150 :                     n->direction = FETCH_FORWARD;
    6833         150 :                     n->howMany = 1;
    6834         150 :                     $$ = (Node *)n;
    6835             :                 }
    6836             :             | PRIOR opt_from_in cursor_name
    6837             :                 {
    6838          16 :                     FetchStmt *n = makeNode(FetchStmt);
    6839          16 :                     n->portalname = $3;
    6840          16 :                     n->direction = FETCH_BACKWARD;
    6841          16 :                     n->howMany = 1;
    6842          16 :                     $$ = (Node *)n;
    6843             :                 }
    6844             :             | FIRST_P opt_from_in cursor_name
    6845             :                 {
    6846          32 :                     FetchStmt *n = makeNode(FetchStmt);
    6847          32 :                     n->portalname = $3;
    6848          32 :                     n->direction = FETCH_ABSOLUTE;
    6849          32 :                     n->howMany = 1;
    6850          32 :                     $$ = (Node *)n;
    6851             :                 }
    6852             :             | LAST_P opt_from_in cursor_name
    6853             :                 {
    6854           8 :                     FetchStmt *n = makeNode(FetchStmt);
    6855           8 :                     n->portalname = $3;
    6856           8 :                     n->direction = FETCH_ABSOLUTE;
    6857           8 :                     n->howMany = -1;
    6858           8 :                     $$ = (Node *)n;
    6859             :                 }
    6860             :             | ABSOLUTE_P SignedIconst opt_from_in cursor_name
    6861             :                 {
    6862          48 :                     FetchStmt *n = makeNode(FetchStmt);
    6863          48 :                     n->portalname = $4;
    6864          48 :                     n->direction = FETCH_ABSOLUTE;
    6865          48 :                     n->howMany = $2;
    6866          48 :                     $$ = (Node *)n;
    6867             :                 }
    6868             :             | RELATIVE_P SignedIconst opt_from_in cursor_name
    6869             :                 {
    6870          20 :                     FetchStmt *n = makeNode(FetchStmt);
    6871          20 :                     n->portalname = $4;
    6872          20 :                     n->direction = FETCH_RELATIVE;
    6873          20 :                     n->howMany = $2;
    6874          20 :                     $$ = (Node *)n;
    6875             :                 }
    6876             :             | SignedIconst opt_from_in cursor_name
    6877             :                 {
    6878        3200 :                     FetchStmt *n = makeNode(FetchStmt);
    6879        3200 :                     n->portalname = $3;
    6880        3200 :                     n->direction = FETCH_FORWARD;
    6881        3200 :                     n->howMany = $1;
    6882        3200 :                     $$ = (Node *)n;
    6883             :                 }
    6884             :             | ALL opt_from_in cursor_name
    6885             :                 {
    6886         160 :                     FetchStmt *n = makeNode(FetchStmt);
    6887         160 :                     n->portalname = $3;
    6888         160 :                     n->direction = FETCH_FORWARD;
    6889         160 :                     n->howMany = FETCH_ALL;
    6890         160 :                     $$ = (Node *)n;
    6891             :                 }
    6892             :             | FORWARD opt_from_in cursor_name
    6893             :                 {
    6894          20 :                     FetchStmt *n = makeNode(FetchStmt);
    6895          20 :                     n->portalname = $3;
    6896          20 :                     n->direction = FETCH_FORWARD;
    6897          20 :                     n->howMany = 1;
    6898          20 :                     $$ = (Node *)n;
    6899             :                 }
    6900             :             | FORWARD SignedIconst opt_from_in cursor_name
    6901             :                 {
    6902         100 :                     FetchStmt *n = makeNode(FetchStmt);
    6903         100 :                     n->portalname = $4;
    6904         100 :                     n->direction = FETCH_FORWARD;
    6905         100 :                     n->howMany = $2;
    6906         100 :                     $$ = (Node *)n;
    6907             :                 }
    6908             :             | FORWARD ALL opt_from_in cursor_name
    6909             :                 {
    6910           8 :                     FetchStmt *n = makeNode(FetchStmt);
    6911           8 :                     n->portalname = $4;
    6912           8 :                     n->direction = FETCH_FORWARD;
    6913           8 :                     n->howMany = FETCH_ALL;
    6914           8 :                     $$ = (Node *)n;
    6915             :                 }
    6916             :             | BACKWARD opt_from_in cursor_name
    6917             :                 {
    6918          52 :                     FetchStmt *n = makeNode(FetchStmt);
    6919          52 :                     n->portalname = $3;
    6920          52 :                     n->direction = FETCH_BACKWARD;
    6921          52 :                     n->howMany = 1;
    6922          52 :                     $$ = (Node *)n;
    6923             :                 }
    6924             :             | BACKWARD SignedIconst opt_from_in cursor_name
    6925             :                 {
    6926         148 :                     FetchStmt *n = makeNode(FetchStmt);
    6927         148 :                     n->portalname = $4;
    6928         148 :                     n->direction = FETCH_BACKWARD;
    6929         148 :                     n->howMany = $2;
    6930         148 :                     $$ = (Node *)n;
    6931             :                 }
    6932             :             | BACKWARD ALL opt_from_in cursor_name
    6933             :                 {
    6934          60 :                     FetchStmt *n = makeNode(FetchStmt);
    6935          60 :                     n->portalname = $4;
    6936          60 :                     n->direction = FETCH_BACKWARD;
    6937          60 :                     n->howMany = FETCH_ALL;
    6938          60 :                     $$ = (Node *)n;
    6939             :                 }
    6940             :         ;
    6941             : 
    6942             : from_in:    FROM                                    {}
    6943             :             | IN_P                                  {}
    6944             :         ;
    6945             : 
    6946             : opt_from_in:    from_in                             {}
    6947             :             | /* EMPTY */                           {}
    6948             :         ;
    6949             : 
    6950             : 
    6951             : /*****************************************************************************
    6952             :  *
    6953             :  * GRANT and REVOKE statements
    6954             :  *
    6955             :  *****************************************************************************/
    6956             : 
    6957             : GrantStmt:  GRANT privileges ON privilege_target TO grantee_list
    6958             :             opt_grant_grant_option
    6959             :                 {
    6960       25494 :                     GrantStmt *n = makeNode(GrantStmt);
    6961       25494 :                     n->is_grant = true;
    6962       25494 :                     n->privileges = $2;
    6963       25494 :                     n->targtype = ($4)->targtype;
    6964       25494 :                     n->objtype = ($4)->objtype;
    6965       25494 :                     n->objects = ($4)->objs;
    6966       25494 :                     n->grantees = $6;
    6967       25494 :                     n->grant_option = $7;
    6968       25494 :                     $$ = (Node*)n;
    6969             :                 }
    6970             :         ;
    6971             : 
    6972             : RevokeStmt:
    6973             :             REVOKE privileges ON privilege_target
    6974             :             FROM grantee_list opt_drop_behavior
    6975             :                 {
    6976       19428 :                     GrantStmt *n = makeNode(GrantStmt);
    6977       19428 :                     n->is_grant = false;
    6978       19428 :                     n->grant_option = false;
    6979       19428 :                     n->privileges = $2;
    6980       19428 :                     n->targtype = ($4)->targtype;
    6981       19428 :                     n->objtype = ($4)->objtype;
    6982       19428 :                     n->objects = ($4)->objs;
    6983       19428 :                     n->grantees = $6;
    6984       19428 :                     n->behavior = $7;
    6985       19428 :                     $$ = (Node *)n;
    6986             :                 }
    6987             :             | REVOKE GRANT OPTION FOR privileges ON privilege_target
    6988             :             FROM grantee_list opt_drop_behavior
    6989             :                 {
    6990           4 :                     GrantStmt *n = makeNode(GrantStmt);
    6991           4 :                     n->is_grant = false;
    6992           4 :                     n->grant_option = true;
    6993           4 :                     n->privileges = $5;
    6994           4 :                     n->targtype = ($7)->targtype;
    6995           4 :                     n->objtype = ($7)->objtype;
    6996           4 :                     n->objects = ($7)->objs;
    6997           4 :                     n->grantees = $9;
    6998           4 :                     n->behavior = $10;
    6999           4 :                     $$ = (Node *)n;
    7000             :                 }
    7001             :         ;
    7002             : 
    7003             : 
    7004             : /*
    7005             :  * Privilege names are represented as strings; the validity of the privilege
    7006             :  * names gets checked at execution.  This is a bit annoying but we have little
    7007             :  * choice because of the syntactic conflict with lists of role names in
    7008             :  * GRANT/REVOKE.  What's more, we have to call out in the "privilege"
    7009             :  * production any reserved keywords that need to be usable as privilege names.
    7010             :  */
    7011             : 
    7012             : /* either ALL [PRIVILEGES] or a list of individual privileges */
    7013             : privileges: privilege_list
    7014       40248 :                 { $$ = $1; }
    7015             :             | ALL
    7016        4672 :                 { $$ = NIL; }
    7017             :             | ALL PRIVILEGES
    7018          90 :                 { $$ = NIL; }
    7019             :             | ALL '(' columnList ')'
    7020             :                 {
    7021          12 :                     AccessPriv *n = makeNode(AccessPriv);
    7022          12 :                     n->priv_name = NULL;
    7023          12 :                     n->cols = $3;
    7024          12 :                     $$ = list_make1(n);
    7025             :                 }
    7026             :             | ALL PRIVILEGES '(' columnList ')'
    7027             :                 {
    7028           0 :                     AccessPriv *n = makeNode(AccessPriv);
    7029           0 :                     n->priv_name = NULL;
    7030           0 :                     n->cols = $4;
    7031           0 :                     $$ = list_make1(n);
    7032             :                 }
    7033             :         ;
    7034             : 
    7035       41410 : privilege_list: privilege                           { $$ = list_make1($1); }
    7036        1514 :             | privilege_list ',' privilege          { $$ = lappend($1, $3); }
    7037             :         ;
    7038             : 
    7039             : privilege:  SELECT opt_column_list
    7040             :             {
    7041       21958 :                 AccessPriv *n = makeNode(AccessPriv);
    7042       21958 :                 n->priv_name = pstrdup($1);
    7043       21958 :                 n->cols = $2;
    7044       21958 :                 $$ = n;
    7045             :             }
    7046             :         | REFERENCES opt_column_list
    7047             :             {
    7048           8 :                 AccessPriv *n = makeNode(AccessPriv);
    7049           8 :                 n->priv_name = pstrdup($1);
    7050           8 :                 n->cols = $2;
    7051           8 :                 $$ = n;
    7052             :             }
    7053             :         | CREATE opt_column_list
    7054             :             {
    7055        1092 :                 AccessPriv *n = makeNode(AccessPriv);
    7056        1092 :                 n->priv_name = pstrdup($1);
    7057        1092 :                 n->cols = $2;
    7058        1092 :                 $$ = n;
    7059             :             }
    7060             :         | ColId opt_column_list
    7061             :             {
    7062       19866 :                 AccessPriv *n = makeNode(AccessPriv);
    7063       19866 :                 n->priv_name = $1;
    7064       19866 :                 n->cols = $2;
    7065       19866 :                 $$ = n;
    7066             :             }
    7067             :         ;
    7068             : 
    7069             : 
    7070             : /* Don't bother trying to fold the first two rules into one using
    7071             :  * opt_table.  You're going to get conflicts.
    7072             :  */
    7073             : privilege_target:
    7074             :             qualified_name_list
    7075             :                 {
    7076       25856 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7077       25856 :                     n->targtype = ACL_TARGET_OBJECT;
    7078       25856 :                     n->objtype = OBJECT_TABLE;
    7079       25856 :                     n->objs = $1;
    7080       25856 :                     $$ = n;
    7081             :                 }
    7082             :             | TABLE qualified_name_list
    7083             :                 {
    7084         786 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7085         786 :                     n->targtype = ACL_TARGET_OBJECT;
    7086         786 :                     n->objtype = OBJECT_TABLE;
    7087         786 :                     n->objs = $2;
    7088         786 :                     $$ = n;
    7089             :                 }
    7090             :             | SEQUENCE qualified_name_list
    7091             :                 {
    7092           2 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7093           2 :                     n->targtype = ACL_TARGET_OBJECT;
    7094           2 :                     n->objtype = OBJECT_SEQUENCE;
    7095           2 :                     n->objs = $2;
    7096           2 :                     $$ = n;
    7097             :                 }
    7098             :             | FOREIGN DATA_P WRAPPER name_list
    7099             :                 {
    7100          64 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7101          64 :                     n->targtype = ACL_TARGET_OBJECT;
    7102          64 :                     n->objtype = OBJECT_FDW;
    7103          64 :                     n->objs = $4;
    7104          64 :                     $$ = n;
    7105             :                 }
    7106             :             | FOREIGN SERVER name_list
    7107             :                 {
    7108          54 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7109          54 :                     n->targtype = ACL_TARGET_OBJECT;
    7110          54 :                     n->objtype = OBJECT_FOREIGN_SERVER;
    7111          54 :                     n->objs = $3;
    7112          54 :                     $$ = n;
    7113             :                 }
    7114             :             | FUNCTION function_with_argtypes_list
    7115             :                 {
    7116       16092 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7117       16092 :                     n->targtype = ACL_TARGET_OBJECT;
    7118       16092 :                     n->objtype = OBJECT_FUNCTION;
    7119       16092 :                     n->objs = $2;
    7120       16092 :                     $$ = n;
    7121             :                 }
    7122             :             | PROCEDURE function_with_argtypes_list
    7123             :                 {
    7124          24 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7125          24 :                     n->targtype = ACL_TARGET_OBJECT;
    7126          24 :                     n->objtype = OBJECT_PROCEDURE;
    7127          24 :                     n->objs = $2;
    7128          24 :                     $$ = n;
    7129             :                 }
    7130             :             | ROUTINE function_with_argtypes_list
    7131             :                 {
    7132           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7133           0 :                     n->targtype = ACL_TARGET_OBJECT;
    7134           0 :                     n->objtype = OBJECT_ROUTINE;
    7135           0 :                     n->objs = $2;
    7136           0 :                     $$ = n;
    7137             :                 }
    7138             :             | DATABASE name_list
    7139             :                 {
    7140         754 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7141         754 :                     n->targtype = ACL_TARGET_OBJECT;
    7142         754 :                     n->objtype = OBJECT_DATABASE;
    7143         754 :                     n->objs = $2;
    7144         754 :                     $$ = n;
    7145             :                 }
    7146             :             | DOMAIN_P any_name_list
    7147             :                 {
    7148          14 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7149          14 :                     n->targtype = ACL_TARGET_OBJECT;
    7150          14 :                     n->objtype = OBJECT_DOMAIN;
    7151          14 :                     n->objs = $2;
    7152          14 :                     $$ = n;
    7153             :                 }
    7154             :             | LANGUAGE name_list
    7155             :                 {
    7156          30 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7157          30 :                     n->targtype = ACL_TARGET_OBJECT;
    7158          30 :                     n->objtype = OBJECT_LANGUAGE;
    7159          30 :                     n->objs = $2;
    7160          30 :                     $$ = n;
    7161             :                 }
    7162             :             | LARGE_P OBJECT_P NumericOnly_list
    7163             :                 {
    7164          50 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7165          50 :                     n->targtype = ACL_TARGET_OBJECT;
    7166          50 :                     n->objtype = OBJECT_LARGEOBJECT;
    7167          50 :                     n->objs = $3;
    7168          50 :                     $$ = n;
    7169             :                 }
    7170             :             | SCHEMA name_list
    7171             :                 {
    7172        1136 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7173        1136 :                     n->targtype = ACL_TARGET_OBJECT;
    7174        1136 :                     n->objtype = OBJECT_SCHEMA;
    7175        1136 :                     n->objs = $2;
    7176        1136 :                     $$ = n;
    7177             :                 }
    7178             :             | TABLESPACE name_list
    7179             :                 {
    7180           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7181           0 :                     n->targtype = ACL_TARGET_OBJECT;
    7182           0 :                     n->objtype = OBJECT_TABLESPACE;
    7183           0 :                     n->objs = $2;
    7184           0 :                     $$ = n;
    7185             :                 }
    7186             :             | TYPE_P any_name_list
    7187             :                 {
    7188          60 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7189          60 :                     n->targtype = ACL_TARGET_OBJECT;
    7190          60 :                     n->objtype = OBJECT_TYPE;
    7191          60 :                     n->objs = $2;
    7192          60 :                     $$ = n;
    7193             :                 }
    7194             :             | ALL TABLES IN_P SCHEMA name_list
    7195             :                 {
    7196           8 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7197           8 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7198           8 :                     n->objtype = OBJECT_TABLE;
    7199           8 :                     n->objs = $5;
    7200           8 :                     $$ = n;
    7201             :                 }
    7202             :             | ALL SEQUENCES IN_P SCHEMA name_list
    7203             :                 {
    7204           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7205           0 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7206           0 :                     n->objtype = OBJECT_SEQUENCE;
    7207           0 :                     n->objs = $5;
    7208           0 :                     $$ = n;
    7209             :                 }
    7210             :             | ALL FUNCTIONS IN_P SCHEMA name_list
    7211             :                 {
    7212           4 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7213           4 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7214           4 :                     n->objtype = OBJECT_FUNCTION;
    7215           4 :                     n->objs = $5;
    7216           4 :                     $$ = n;
    7217             :                 }
    7218             :             | ALL PROCEDURES IN_P SCHEMA name_list
    7219             :                 {
    7220           4 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7221           4 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7222           4 :                     n->objtype = OBJECT_PROCEDURE;
    7223           4 :                     n->objs = $5;
    7224           4 :                     $$ = n;
    7225             :                 }
    7226             :             | ALL ROUTINES IN_P SCHEMA name_list
    7227             :                 {
    7228           4 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7229           4 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7230           4 :                     n->objtype = OBJECT_ROUTINE;
    7231           4 :                     n->objs = $5;
    7232           4 :                     $$ = n;
    7233             :                 }
    7234             :         ;
    7235             : 
    7236             : 
    7237             : grantee_list:
    7238       45006 :             grantee                                 { $$ = list_make1($1); }
    7239          40 :             | grantee_list ',' grantee              { $$ = lappend($1, $3); }
    7240             :         ;
    7241             : 
    7242             : grantee:
    7243       45030 :             RoleSpec                                { $$ = $1; }
    7244          16 :             | GROUP_P RoleSpec                      { $$ = $2; }
    7245             :         ;
    7246             : 
    7247             : 
    7248             : opt_grant_grant_option:
    7249          40 :             WITH GRANT OPTION { $$ = true; }
    7250       25496 :             | /*EMPTY*/ { $$ = false; }
    7251             :         ;
    7252             : 
    7253             : /*****************************************************************************
    7254             :  *
    7255             :  * GRANT and REVOKE ROLE statements
    7256             :  *
    7257             :  *****************************************************************************/
    7258             : 
    7259             : GrantRoleStmt:
    7260             :             GRANT privilege_list TO role_list opt_grant_admin_option opt_granted_by
    7261             :                 {
    7262        1148 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    7263        1148 :                     n->is_grant = true;
    7264        1148 :                     n->granted_roles = $2;
    7265        1148 :                     n->grantee_roles = $4;
    7266        1148 :                     n->admin_opt = $5;
    7267        1148 :                     n->grantor = $6;
    7268        1148 :                     $$ = (Node*)n;
    7269             :                 }
    7270             :         ;
    7271             : 
    7272             : RevokeRoleStmt:
    7273             :             REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
    7274             :                 {
    7275          14 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    7276          14 :                     n->is_grant = false;
    7277          14 :                     n->admin_opt = false;
    7278          14 :                     n->granted_roles = $2;
    7279          14 :                     n->grantee_roles = $4;
    7280          14 :                     n->behavior = $6;
    7281          14 :                     $$ = (Node*)n;
    7282             :                 }
    7283             :             | REVOKE ADMIN OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
    7284             :                 {
    7285           0 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    7286           0 :                     n->is_grant = false;
    7287           0 :                     n->admin_opt = true;
    7288           0 :                     n->granted_roles = $5;
    7289           0 :                     n->grantee_roles = $7;
    7290           0 :                     n->behavior = $9;
    7291           0 :                     $$ = (Node*)n;
    7292             :                 }
    7293             :         ;
    7294             : 
    7295           4 : opt_grant_admin_option: WITH ADMIN OPTION               { $$ = true; }
    7296        1144 :             | /*EMPTY*/                                 { $$ = false; }
    7297             :         ;
    7298             : 
    7299           0 : opt_granted_by: GRANTED BY RoleSpec                     { $$ = $3; }
    7300        1162 :             | /*EMPTY*/                                 { $$ = NULL; }
    7301             :         ;
    7302             : 
    7303             : /*****************************************************************************
    7304             :  *
    7305             :  * ALTER DEFAULT PRIVILEGES statement
    7306             :  *
    7307             :  *****************************************************************************/
    7308             : 
    7309             : AlterDefaultPrivilegesStmt:
    7310             :             ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
    7311             :                 {
    7312          80 :                     AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
    7313          80 :                     n->options = $4;
    7314          80 :                     n->action = (GrantStmt *) $5;
    7315          80 :                     $$ = (Node*)n;
    7316             :                 }
    7317             :         ;
    7318             : 
    7319             : DefACLOptionList:
    7320          74 :             DefACLOptionList DefACLOption           { $$ = lappend($1, $2); }
    7321          80 :             | /* EMPTY */                           { $$ = NIL; }
    7322             :         ;
    7323             : 
    7324             : DefACLOption:
    7325             :             IN_P SCHEMA name_list
    7326             :                 {
    7327          36 :                     $$ = makeDefElem("schemas", (Node *)$3, @1);
    7328             :                 }
    7329             :             | FOR ROLE role_list
    7330             :                 {
    7331          38 :                     $$ = makeDefElem("roles", (Node *)$3, @1);
    7332             :                 }
    7333             :             | FOR USER role_list
    7334             :                 {
    7335           0 :                     $$ = makeDefElem("roles", (Node *)$3, @1);
    7336             :                 }
    7337             :         ;
    7338             : 
    7339             : /*
    7340             :  * This should match GRANT/REVOKE, except that individual target objects
    7341             :  * are not mentioned and we only allow a subset of object types.
    7342             :  */
    7343             : DefACLAction:
    7344             :             GRANT privileges ON defacl_privilege_target TO grantee_list
    7345             :             opt_grant_grant_option
    7346             :                 {
    7347          42 :                     GrantStmt *n = makeNode(GrantStmt);
    7348          42 :                     n->is_grant = true;
    7349          42 :                     n->privileges = $2;
    7350          42 :                     n->targtype = ACL_TARGET_DEFAULTS;
    7351          42 :                     n->objtype = $4;
    7352          42 :                     n->objects = NIL;
    7353          42 :                     n->grantees = $6;
    7354          42 :                     n->grant_option = $7;
    7355          42 :                     $$ = (Node*)n;
    7356             :                 }
    7357             :             | REVOKE privileges ON defacl_privilege_target
    7358             :             FROM grantee_list opt_drop_behavior
    7359             :                 {
    7360          38 :                     GrantStmt *n = makeNode(GrantStmt);
    7361          38 :                     n->is_grant = false;
    7362          38 :                     n->grant_option = false;
    7363          38 :                     n->privileges = $2;
    7364          38 :                     n->targtype = ACL_TARGET_DEFAULTS;
    7365          38 :                     n->objtype = $4;
    7366          38 :                     n->objects = NIL;
    7367          38 :                     n->grantees = $6;
    7368          38 :                     n->behavior = $7;
    7369          38 :                     $$ = (Node *)n;
    7370             :                 }
    7371             :             | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
    7372             :             FROM grantee_list opt_drop_behavior
    7373             :                 {
    7374           0 :                     GrantStmt *n = makeNode(GrantStmt);
    7375           0 :                     n->is_grant = false;
    7376           0 :                     n->grant_option = true;
    7377           0 :                     n->privileges = $5;
    7378           0 :                     n->targtype = ACL_TARGET_DEFAULTS;
    7379           0 :                     n->objtype = $7;
    7380           0 :                     n->objects = NIL;
    7381           0 :                     n->grantees = $9;
    7382           0 :                     n->behavior = $10;
    7383           0 :                     $$ = (Node *)n;
    7384             :                 }
    7385             :         ;
    7386             : 
    7387             : defacl_privilege_target:
    7388          42 :             TABLES          { $$ = OBJECT_TABLE; }
    7389           6 :             | FUNCTIONS     { $$ = OBJECT_FUNCTION; }
    7390           4 :             | ROUTINES      { $$ = OBJECT_FUNCTION; }
    7391           0 :             | SEQUENCES     { $$ = OBJECT_SEQUENCE; }
    7392           8 :             | TYPES_P       { $$ = OBJECT_TYPE; }
    7393          20 :             | SCHEMAS       { $$ = OBJECT_SCHEMA; }
    7394             :         ;
    7395             : 
    7396             : 
    7397             : /*****************************************************************************
    7398             :  *
    7399             :  *      QUERY: CREATE INDEX
    7400             :  *
    7401             :  * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
    7402             :  * willing to make TABLESPACE a fully reserved word.
    7403             :  *****************************************************************************/
    7404             : 
    7405             : IndexStmt:  CREATE opt_unique INDEX opt_concurrently opt_index_name
    7406             :             ON relation_expr access_method_clause '(' index_params ')'
    7407             :             opt_include opt_reloptions OptTableSpace where_clause
    7408             :                 {
    7409        3234 :                     IndexStmt *n = makeNode(IndexStmt);
    7410        3234 :                     n->unique = $2;
    7411        3234 :                     n->concurrent = $4;
    7412        3234 :                     n->idxname = $5;
    7413        3234 :                     n->relation = $7;
    7414        3234 :                     n->accessMethod = $8;
    7415        3234 :                     n->indexParams = $10;
    7416        3234 :                     n->indexIncludingParams = $12;
    7417        3234 :                     n->options = $13;
    7418        3234 :                     n->tableSpace = $14;
    7419        3234 :                     n->whereClause = $15;
    7420        3234 :                     n->excludeOpNames = NIL;
    7421        3234 :                     n->idxcomment = NULL;
    7422        3234 :                     n->indexOid = InvalidOid;
    7423        3234 :                     n->oldNode = InvalidOid;
    7424        3234 :                     n->oldCreateSubid = InvalidSubTransactionId;
    7425        3234 :                     n->oldFirstRelfilenodeSubid = InvalidSubTransactionId;
    7426        3234 :                     n->primary = false;
    7427        3234 :                     n->isconstraint = false;
    7428        3234 :                     n->deferrable = false;
    7429        3234 :                     n->initdeferred = false;
    7430        3234 :                     n->transformed = false;
    7431        3234 :                     n->if_not_exists = false;
    7432        3234 :                     n->reset_default_tblspc = false;
    7433        3234 :                     $$ = (Node *)n;
    7434             :                 }
    7435             :             | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS index_name
    7436             :             ON relation_expr access_method_clause '(' index_params ')'
    7437             :             opt_include opt_reloptions OptTableSpace where_clause
    7438             :                 {
    7439          12 :                     IndexStmt *n = makeNode(IndexStmt);
    7440          12 :                     n->unique = $2;
    7441          12 :                     n->concurrent = $4;
    7442          12 :                     n->idxname = $8;
    7443          12 :                     n->relation = $10;
    7444          12 :                     n->accessMethod = $11;
    7445          12 :                     n->indexParams = $13;
    7446          12 :                     n->indexIncludingParams = $15;
    7447          12 :                     n->options = $16;
    7448          12 :                     n->tableSpace = $17;
    7449          12 :                     n->whereClause = $18;
    7450          12 :                     n->excludeOpNames = NIL;
    7451          12 :                     n->idxcomment = NULL;
    7452          12 :                     n->indexOid = InvalidOid;
    7453          12 :                     n->oldNode = InvalidOid;
    7454          12 :                     n->oldCreateSubid = InvalidSubTransactionId;
    7455          12 :                     n->oldFirstRelfilenodeSubid = InvalidSubTransactionId;
    7456          12 :                     n->primary = false;
    7457          12 :                     n->isconstraint = false;
    7458          12 :                     n->deferrable = false;
    7459          12 :                     n->initdeferred = false;
    7460          12 :                     n->transformed = false;
    7461          12 :                     n->if_not_exists = true;
    7462          12 :                     n->reset_default_tblspc = false;
    7463          12 :                     $$ = (Node *)n;
    7464             :                 }
    7465             :         ;
    7466             : 
    7467             : opt_unique:
    7468         622 :             UNIQUE                                  { $$ = true; }
    7469        2628 :             | /*EMPTY*/                             { $$ = false; }
    7470             :         ;
    7471             : 
    7472             : opt_concurrently:
    7473         256 :             CONCURRENTLY                            { $$ = true; }
    7474        3390 :             | /*EMPTY*/                             { $$ = false; }
    7475             :         ;
    7476             : 
    7477             : opt_index_name:
    7478        2614 :             index_name                              { $$ = $1; }
    7479         620 :             | /*EMPTY*/                             { $$ = NULL; }
    7480             :         ;
    7481             : 
    7482             : access_method_clause:
    7483        1512 :             USING access_method                     { $$ = $2; }
    7484        1834 :             | /*EMPTY*/                             { $$ = DEFAULT_INDEX_TYPE; }
    7485             :         ;
    7486             : 
    7487        4086 : index_params:   index_elem                          { $$ = list_make1($1); }
    7488         904 :             | index_params ',' index_elem           { $$ = lappend($1, $3); }
    7489             :         ;
    7490             : 
    7491             : 
    7492             : index_elem_options:
    7493             :     opt_collate opt_class opt_asc_desc opt_nulls_order
    7494             :         {
    7495        5292 :             $$ = makeNode(IndexElem);
    7496        5292 :             $$->name = NULL;
    7497        5292 :             $$->expr = NULL;
    7498        5292 :             $$->indexcolname = NULL;
    7499        5292 :             $$->collation = $1;
    7500        5292 :             $$->opclass = $2;
    7501        5292 :             $$->opclassopts = NIL;
    7502        5292 :             $$->ordering = $3;
    7503        5292 :             $$->nulls_ordering = $4;
    7504             :         }
    7505             :     | opt_collate any_name reloptions opt_asc_desc opt_nulls_order
    7506             :         {
    7507          68 :             $$ = makeNode(IndexElem);
    7508          68 :             $$->name = NULL;
    7509          68 :             $$->expr = NULL;
    7510          68 :             $$->indexcolname = NULL;
    7511          68 :             $$->collation = $1;
    7512          68 :             $$->opclass = $2;
    7513          68 :             $$->opclassopts = $3;
    7514          68 :             $$->ordering = $4;
    7515          68 :             $$->nulls_ordering = $5;
    7516             :         }
    7517             :     ;
    7518             : 
    7519             : /*
    7520             :  * Index attributes can be either simple column references, or arbitrary
    7521             :  * expressions in parens.  For backwards-compatibility reasons, we allow
    7522             :  * an expression that's just a function call to be written without parens.
    7523             :  */
    7524             : index_elem: ColId index_elem_options
    7525             :                 {
    7526        4914 :                     $$ = $2;
    7527        4914 :                     $$->name = $1;
    7528             :                 }
    7529             :             | func_expr_windowless index_elem_options
    7530             :                 {
    7531         222 :                     $$ = $2;
    7532         222 :                     $$->expr = $1;
    7533             :                 }
    7534             :             | '(' a_expr ')' index_elem_options
    7535             :                 {
    7536         224 :                     $$ = $4;
    7537         224 :                     $$->expr = $2;
    7538             :                 }
    7539             :         ;
    7540             : 
    7541         140 : opt_include:        INCLUDE '(' index_including_params ')'          { $$ = $3; }
    7542        3106 :              |      /* EMPTY */                     { $$ = NIL; }
    7543             :         ;
    7544             : 
    7545         140 : index_including_params: index_elem                      { $$ = list_make1($1); }
    7546         108 :             | index_including_params ',' index_elem     { $$ = lappend($1, $3); }
    7547             :         ;
    7548             : 
    7549          92 : opt_collate: COLLATE any_name                       { $$ = $2; }
    7550        7932 :             | /*EMPTY*/                             { $$ = NIL; }
    7551             :         ;
    7552             : 
    7553         366 : opt_class:  any_name                                { $$ = $1; }
    7554        7590 :             | /*EMPTY*/                             { $$ = NIL; }
    7555             :         ;
    7556             : 
    7557        1536 : opt_asc_desc: ASC                           { $$ = SORTBY_ASC; }
    7558        1740 :             | DESC                          { $$ = SORTBY_DESC; }
    7559       66290 :             | /*EMPTY*/                     { $$ = SORTBY_DEFAULT; }
    7560             :         ;
    7561             : 
    7562         120 : opt_nulls_order: NULLS_LA FIRST_P           { $$ = SORTBY_NULLS_FIRST; }
    7563        1166 :             | NULLS_LA LAST_P               { $$ = SORTBY_NULLS_LAST; }
    7564       68426 :             | /*EMPTY*/                     { $$ = SORTBY_NULLS_DEFAULT; }
    7565             :         ;
    7566             : 
    7567             : 
    7568             : /*****************************************************************************
    7569             :  *
    7570             :  *      QUERY:
    7571             :  *              create [or replace] function <fname>
    7572             :  *                      [(<type-1> { , <type-n>})]
    7573             :  *                      returns <type-r>
    7574             :  *                      as <filename or code in language as appropriate>
    7575             :  *                      language <lang> [with parameters]
    7576             :  *
    7577             :  *****************************************************************************/
    7578             : 
    7579             : CreateFunctionStmt:
    7580             :             CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    7581             :             RETURNS func_return createfunc_opt_list
    7582             :                 {
    7583       24788 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    7584       24788 :                     n->is_procedure = false;
    7585       24788 :                     n->replace = $2;
    7586       24788 :                     n->funcname = $4;
    7587       24788 :                     n->parameters = $5;
    7588       24788 :                     n->returnType = $7;
    7589       24788 :                     n->options = $8;
    7590       24788 :                     $$ = (Node *)n;
    7591             :                 }
    7592             :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    7593             :               RETURNS TABLE '(' table_func_column_list ')' createfunc_opt_list
    7594             :                 {
    7595          96 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    7596          96 :                     n->is_procedure = false;
    7597          96 :                     n->replace = $2;
    7598          96 :                     n->funcname = $4;
    7599          96 :                     n->parameters = mergeTableFuncParameters($5, $9);
    7600          96 :                     n->returnType = TableFuncTypeName($9);
    7601          96 :                     n->returnType->location = @7;
    7602          96 :                     n->options = $11;
    7603          96 :                     $$ = (Node *)n;
    7604             :                 }
    7605             :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    7606             :               createfunc_opt_list
    7607             :                 {
    7608         220 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    7609         220 :                     n->is_procedure = false;
    7610         220 :                     n->replace = $2;
    7611         220 :                     n->funcname = $4;
    7612         220 :                     n->parameters = $5;
    7613         220 :                     n->returnType = NULL;
    7614         220 :                     n->options = $6;
    7615         220 :                     $$ = (Node *)n;
    7616             :                 }
    7617             :             | CREATE opt_or_replace PROCEDURE func_name func_args_with_defaults
    7618             :               createfunc_opt_list
    7619             :                 {
    7620         178 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    7621         178 :                     n->is_procedure = true;
    7622         178 :                     n->replace = $2;
    7623         178 :                     n->funcname = $4;
    7624         178 :                     n->parameters = $5;
    7625         178 :                     n->returnType = NULL;
    7626         178 :                     n->options = $6;
    7627         178 :                     $$ = (Node *)n;
    7628             :                 }
    7629             :         ;
    7630             : 
    7631             : opt_or_replace:
    7632       11202 :             OR REPLACE                              { $$ = true; }
    7633       16412 :             | /*EMPTY*/                             { $$ = false; }
    7634             :         ;
    7635             : 
    7636       12824 : func_args:  '(' func_args_list ')'                  { $$ = $2; }
    7637        8194 :             | '(' ')'                               { $$ = NIL; }
    7638             :         ;
    7639             : 
    7640             : func_args_list:
    7641       12824 :             func_arg                                { $$ = list_make1($1); }
    7642       10762 :             | func_args_list ',' func_arg           { $$ = lappend($1, $3); }
    7643             :         ;
    7644             : 
    7645             : function_with_argtypes_list:
    7646       17992 :             function_with_argtypes                  { $$ = list_make1($1); }
    7647             :             | function_with_argtypes_list ',' function_with_argtypes
    7648          32 :                                                     { $$ = lappend($1, $3); }
    7649             :         ;
    7650             : 
    7651             : function_with_argtypes:
    7652             :             func_name func_args
    7653             :                 {
    7654       21018 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    7655       21018 :                     n->objname = $1;
    7656       21018 :                     n->objargs = extractArgTypes($2);
    7657       21018 :                     $$ = n;
    7658             :                 }
    7659             :             /*
    7660             :              * Because of reduce/reduce conflicts, we can't use func_name
    7661             :              * below, but we can write it out the long way, which actually
    7662             :              * allows more cases.
    7663             :              */
    7664             :             | type_func_name_keyword
    7665             :                 {
    7666           0 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    7667           0 :                     n->objname = list_make1(makeString(pstrdup($1)));
    7668           0 :                     n->args_unspecified = true;
    7669           0 :                     $$ = n;
    7670             :                 }
    7671             :             | ColId
    7672             :                 {
    7673          92 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    7674          92 :                     n->objname = list_make1(makeString($1));
    7675          92 :                     n->args_unspecified = true;
    7676          92 :                     $$ = n;
    7677             :                 }
    7678             :             | ColId indirection
    7679             :                 {
    7680           0 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    7681           0 :                     n->objname = check_func_name(lcons(makeString($1), $2),
    7682             :                                                   yyscanner);
    7683           0 :                     n->args_unspecified = true;
    7684           0 :                     $$ = n;
    7685             :                 }
    7686             :         ;
    7687             : 
    7688             : /*
    7689             :  * func_args_with_defaults is separate because we only want to accept
    7690             :  * defaults in CREATE FUNCTION, not in ALTER etc.
    7691             :  */
    7692             : func_args_with_defaults:
    7693       22578 :         '(' func_args_with_defaults_list ')'        { $$ = $2; }
    7694        2704 :         | '(' ')'                                   { $$ = NIL; }
    7695             :         ;
    7696             : 
    7697             : func_args_with_defaults_list:
    7698       22578 :         func_arg_with_default                       { $$ = list_make1($1); }
    7699             :         | func_args_with_defaults_list ',' func_arg_with_default
    7700       50060 :                                                     { $$ = lappend($1, $3); }
    7701             :         ;
    7702             : 
    7703             : /*
    7704             :  * The style with arg_class first is SQL99 standard, but Oracle puts
    7705             :  * param_name first; accept both since it's likely people will try both
    7706             :  * anyway.  Don't bother trying to save productions by letting arg_class
    7707             :  * have an empty alternative ... you'll get shift/reduce conflicts.
    7708             :  *
    7709             :  * We can catch over-specified arguments here if we want to,
    7710             :  * but for now better to silently swallow typmod, etc.
    7711             :  * - thomas 2000-03-22
    7712             :  */
    7713             : func_arg:
    7714             :             arg_class param_name func_type
    7715             :                 {
    7716       23176 :                     FunctionParameter *n = makeNode(FunctionParameter);
    7717       23176 :                     n->name = $2;
    7718       23176 :                     n->argType = $3;
    7719       23176 :                     n->mode = $1;
    7720       23176 :                     n->defexpr = NULL;
    7721       23176 :                     $$ = n;
    7722             :                 }
    7723             :             | param_name arg_class func_type
    7724             :                 {
    7725         108 :                     FunctionParameter *n = makeNode(FunctionParameter);
    7726         108 :                     n->name = $1;
    7727         108 :                     n->argType = $3;
    7728         108 :                     n->mode = $2;
    7729         108 :                     n->defexpr = NULL;
    7730         108 :                     $$ = n;
    7731             :                 }
    7732             :             | param_name func_type
    7733             :                 {
    7734       34476 :                     FunctionParameter *n = makeNode(FunctionParameter);
    7735       34476 :                     n->name = $1;
    7736       34476 :                     n->argType = $2;
    7737       34476 :                     n->mode = FUNC_PARAM_IN;
    7738       34476 :                     n->defexpr = NULL;
    7739       34476 :                     $$ = n;
    7740             :                 }
    7741             :             | arg_class func_type
    7742             :                 {
    7743         520 :                     FunctionParameter *n = makeNode(FunctionParameter);
    7744         520 :                     n->name = NULL;
    7745         520 :                     n->argType = $2;
    7746         520 :                     n->mode = $1;
    7747         520 :                     n->defexpr = NULL;
    7748         520 :                     $$ = n;
    7749             :                 }
    7750             :             | func_type
    7751             :                 {
    7752       38622 :                     FunctionParameter *n = makeNode(FunctionParameter);
    7753       38622 :                     n->name = NULL;
    7754       38622 :                     n->argType = $1;
    7755       38622 :                     n->mode = FUNC_PARAM_IN;
    7756       38622 :                     n->defexpr = NULL;
    7757       38622 :                     $$ = n;
    7758             :                 }
    7759             :         ;
    7760             : 
    7761             : /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
    7762        8230 : arg_class:  IN_P                                { $$ = FUNC_PARAM_IN; }
    7763       13906 :             | OUT_P                             { $$ = FUNC_PARAM_OUT; }
    7764         112 :             | INOUT                             { $$ = FUNC_PARAM_INOUT; }
    7765           0 :             | IN_P OUT_P                        { $$ = FUNC_PARAM_INOUT; }
    7766        1556 :             | VARIADIC                          { $$ = FUNC_PARAM_VARIADIC; }
    7767             :         ;
    7768             : 
    7769             : /*
    7770             :  * Ideally param_name should be ColId, but that causes too many conflicts.
    7771             :  */
    7772             : param_name: type_function_name
    7773             :         ;
    7774             : 
    7775             : func_return:
    7776             :             func_type
    7777             :                 {
    7778             :                     /* We can catch over-specified results here if we want to,
    7779             :                      * but for now better to silently swallow typmod, etc.
    7780             :                      * - thomas 2000-03-22
    7781             :                      */
    7782       24788 :                     $$ = $1;
    7783             :                 }
    7784             :         ;
    7785             : 
    7786             : /*
    7787             :  * We would like to make the %TYPE productions here be ColId attrs etc,
    7788             :  * but that causes reduce/reduce conflicts.  type_function_name
    7789             :  * is next best choice.
    7790             :  */
    7791      153590 : func_type:  Typename                                { $$ = $1; }
    7792             :             | type_function_name attrs '%' TYPE_P
    7793             :                 {
    7794          12 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
    7795          12 :                     $$->pct_type = true;
    7796          12 :                     $$->location = @1;
    7797             :                 }
    7798             :             | SETOF type_function_name attrs '%' TYPE_P
    7799             :                 {
    7800           4 :                     $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
    7801           4 :                     $$->pct_type = true;
    7802           4 :                     $$->setof = true;
    7803           4 :                     $$->location = @2;
    7804             :                 }
    7805             :         ;
    7806             : 
    7807             : func_arg_with_default:
    7808             :         func_arg
    7809             :                 {
    7810       55230 :                     $$ = $1;
    7811             :                 }
    7812             :         | func_arg DEFAULT a_expr
    7813             :                 {
    7814       17272 :                     $$ = $1;
    7815       17272 :                     $$->defexpr = $3;
    7816             :                 }
    7817             :         | func_arg '=' a_expr
    7818             :                 {
    7819         136 :                     $$ = $1;
    7820         136 :                     $$->defexpr = $3;
    7821             :                 }
    7822             :         ;
    7823             : 
    7824             : /* Aggregate args can be most things that function args can be */
    7825             : aggr_arg:   func_arg
    7826             :                 {
    7827         678 :                     if (!($1->mode == FUNC_PARAM_IN ||
    7828          48 :                           $1->mode == FUNC_PARAM_VARIADIC))
    7829           0 :                         ereport(ERROR,
    7830             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    7831             :                                  errmsg("aggregates cannot have output arguments"),
    7832             :                                  parser_errposition(@1)));
    7833         678 :                     $$ = $1;
    7834             :                 }
    7835             :         ;
    7836             : 
    7837             : /*
    7838             :  * The SQL standard offers no guidance on how to declare aggregate argument
    7839             :  * lists, since it doesn't have CREATE AGGREGATE etc.  We accept these cases:
    7840             :  *
    7841             :  * (*)                                  - normal agg with no args
    7842             :  * (aggr_arg,...)                       - normal agg with args
    7843             :  * (ORDER BY aggr_arg,...)              - ordered-set agg with no direct args
    7844             :  * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
    7845             :  *
    7846             :  * The zero-argument case is spelled with '*' for consistency with COUNT(*).
    7847             :  *
    7848             :  * An additional restriction is that if the direct-args list ends in a
    7849             :  * VARIADIC item, the ordered-args list must contain exactly one item that
    7850             :  * is also VARIADIC with the same type.  This allows us to collapse the two
    7851             :  * VARIADIC items into one, which is necessary to represent the aggregate in
    7852             :  * pg_proc.  We check this at the grammar stage so that we can return a list
    7853             :  * in which the second VARIADIC item is already discarded, avoiding extra work
    7854             :  * in cases such as DROP AGGREGATE.
    7855             :  *
    7856             :  * The return value of this production is a two-element list, in which the
    7857             :  * first item is a sublist of FunctionParameter nodes (with any duplicate
    7858             :  * VARIADIC item already dropped, as per above) and the second is an integer
    7859             :  * Value node, containing -1 if there was no ORDER BY and otherwise the number
    7860             :  * of argument declarations before the ORDER BY.  (If this number is equal
    7861             :  * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
    7862             :  * This representation is passed as-is to CREATE AGGREGATE; for operations
    7863             :  * on existing aggregates, we can just apply extractArgTypes to the first
    7864             :  * sublist.
    7865             :  */
    7866             : aggr_args:  '(' '*' ')'
    7867             :                 {
    7868         102 :                     $$ = list_make2(NIL, makeInteger(-1));
    7869             :                 }
    7870             :             | '(' aggr_args_list ')'
    7871             :                 {
    7872         550 :                     $$ = list_make2($2, makeInteger(-1));
    7873             :                 }
    7874             :             | '(' ORDER BY aggr_args_list ')'
    7875             :                 {
    7876           4 :                     $$ = list_make2($4, makeInteger(0));
    7877             :                 }
    7878             :             | '(' aggr_args_list ORDER BY aggr_args_list ')'
    7879             :                 {
    7880             :                     /* this is the only case requiring consistency checking */
    7881          24 :                     $$ = makeOrderedSetArgs($2, $5, yyscanner);
    7882             :                 }
    7883             :         ;
    7884             : 
    7885             : aggr_args_list:
    7886         602 :             aggr_arg                                { $$ = list_make1($1); }
    7887          76 :             | aggr_args_list ',' aggr_arg           { $$ = lappend($1, $3); }
    7888             :         ;
    7889             : 
    7890             : aggregate_with_argtypes:
    7891             :             func_name aggr_args
    7892             :                 {
    7893         284 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    7894         284 :                     n->objname = $1;
    7895         284 :                     n->objargs = extractAggrArgTypes($2);
    7896         284 :                     $$ = n;
    7897             :                 }
    7898             :         ;
    7899             : 
    7900             : aggregate_with_argtypes_list:
    7901          70 :             aggregate_with_argtypes                 { $$ = list_make1($1); }
    7902             :             | aggregate_with_argtypes_list ',' aggregate_with_argtypes
    7903           0 :                                                     { $$ = lappend($1, $3); }
    7904             :         ;
    7905             : 
    7906             : createfunc_opt_list:
    7907             :             /* Must be at least one to prevent conflict */
    7908       25282 :             createfunc_opt_item                     { $$ = list_make1($1); }
    7909       79634 :             | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
    7910             :     ;
    7911             : 
    7912             : /*
    7913             :  * Options common to both CREATE FUNCTION and ALTER FUNCTION
    7914             :  */
    7915             : common_func_opt_item:
    7916             :             CALLED ON NULL_P INPUT_P
    7917             :                 {
    7918         378 :                     $$ = makeDefElem("strict", (Node *)makeInteger(false), @1);
    7919             :                 }
    7920             :             | RETURNS NULL_P ON NULL_P INPUT_P
    7921             :                 {
    7922        3234 :                     $$ = makeDefElem("strict", (Node *)makeInteger(true), @1);
    7923             :                 }
    7924             :             | STRICT_P
    7925             :                 {
    7926       14084 :                     $$ = makeDefElem("strict", (Node *)makeInteger(true), @1);
    7927             :                 }
    7928             :             | IMMUTABLE
    7929             :                 {
    7930       11250 :                     $$ = makeDefElem("volatility", (Node *)makeString("immutable"), @1);
    7931             :                 }
    7932             :             | STABLE
    7933             :                 {
    7934        3752 :                     $$ = makeDefElem("volatility", (Node *)makeString("stable"), @1);
    7935             :                 }
    7936             :             | VOLATILE
    7937             :                 {
    7938        3338 :                     $$ = makeDefElem("volatility", (Node *)makeString("volatile"), @1);
    7939             :                 }
    7940             :             | EXTERNAL SECURITY DEFINER
    7941             :                 {
    7942           0 :                     $$ = makeDefElem("security", (Node *)makeInteger(true), @1);
    7943             :                 }
    7944             :             | EXTERNAL SECURITY INVOKER
    7945             :                 {
    7946           0 :                     $$ = makeDefElem("security", (Node *)makeInteger(false), @1);
    7947             :                 }
    7948             :             | SECURITY DEFINER
    7949             :                 {
    7950          28 :                     $$ = makeDefElem("security", (Node *)makeInteger(true), @1);
    7951             :                 }
    7952             :             | SECURITY INVOKER
    7953             :                 {
    7954           8 :                     $$ = makeDefElem("security", (Node *)makeInteger(false), @1);
    7955             :                 }
    7956             :             | LEAKPROOF
    7957             :                 {
    7958          20 :                     $$ = makeDefElem("leakproof", (Node *)makeInteger(true), @1);
    7959             :                 }
    7960             :             | NOT LEAKPROOF
    7961             :                 {
    7962           8 :                     $$ = makeDefElem("leakproof", (Node *)makeInteger(false), @1);
    7963             :                 }
    7964             :             | COST NumericOnly
    7965             :                 {
    7966        1460 :                     $$ = makeDefElem("cost", (Node *)$2, @1);
    7967             :                 }
    7968             :             | ROWS NumericOnly
    7969             :                 {
    7970        1794 :                     $$ = makeDefElem("rows", (Node *)$2, @1);
    7971             :                 }
    7972             :             | SUPPORT any_name
    7973             :                 {
    7974          14 :                     $$ = makeDefElem("support", (Node *)$2, @1);
    7975             :                 }
    7976             :             | FunctionSetResetClause
    7977             :                 {
    7978             :                     /* we abuse the normal content of a DefElem here */
    7979          72 :                     $$ = makeDefElem("set", (Node *)$1, @1);
    7980             :                 }
    7981             :             | PARALLEL ColId
    7982             :                 {
    7983       14888 :                     $$ = makeDefElem("parallel", (Node *)makeString($2), @1);
    7984             :                 }
    7985             :         ;
    7986             : 
    7987             : createfunc_opt_item:
    7988             :             AS func_as
    7989             :                 {
    7990       25282 :                     $$ = makeDefElem("as", (Node *)$2, @1);
    7991             :                 }
    7992             :             | LANGUAGE NonReservedWord_or_Sconst
    7993             :                 {
    7994       25282 :                     $$ = makeDefElem("language", (Node *)makeString($2), @1);
    7995             :                 }
    7996             :             | TRANSFORM transform_type_list
    7997             :                 {
    7998         116 :                     $$ = makeDefElem("transform", (Node *)$2, @1);
    7999             :                 }
    8000             :             | WINDOW
    8001             :                 {
    8002          14 :                     $$ = makeDefElem("window", (Node *)makeInteger(true), @1);
    8003             :                 }
    8004             :             | common_func_opt_item
    8005             :                 {
    8006       54222 :                     $$ = $1;
    8007             :                 }
    8008             :         ;
    8009             : 
    8010       23296 : func_as:    Sconst                      { $$ = list_make1(makeString($1)); }
    8011             :             | Sconst ',' Sconst
    8012             :                 {
    8013        1986 :                     $$ = list_make2(makeString($1), makeString($3));
    8014             :                 }
    8015             :         ;
    8016             : 
    8017             : transform_type_list:
    8018         116 :             FOR TYPE_P Typename { $$ = list_make1($3); }
    8019           0 :             | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
    8020             :         ;
    8021             : 
    8022             : opt_definition:
    8023         106 :             WITH definition                         { $$ = $2; }
    8024        5398 :             | /*EMPTY*/                             { $$ = NIL; }
    8025             :         ;
    8026             : 
    8027             : table_func_column:  param_name func_type
    8028             :                 {
    8029         174 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8030         174 :                     n->name = $1;
    8031         174 :                     n->argType = $2;
    8032         174 :                     n->mode = FUNC_PARAM_TABLE;
    8033         174 :                     n->defexpr = NULL;
    8034         174 :                     $$ = n;
    8035             :                 }
    8036             :         ;
    8037             : 
    8038             : table_func_column_list:
    8039             :             table_func_column
    8040             :                 {
    8041          96 :                     $$ = list_make1($1);
    8042             :                 }
    8043             :             | table_func_column_list ',' table_func_column
    8044             :                 {
    8045          78 :                     $$ = lappend($1, $3);
    8046             :                 }
    8047             :         ;
    8048             : 
    8049             : /*****************************************************************************
    8050             :  * ALTER FUNCTION / ALTER PROCEDURE / ALTER ROUTINE
    8051             :  *
    8052             :  * RENAME and OWNER subcommands are already provided by the generic
    8053             :  * ALTER infrastructure, here we just specify alterations that can
    8054             :  * only be applied to functions.
    8055             :  *
    8056             :  *****************************************************************************/
    8057             : AlterFunctionStmt:
    8058             :             ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
    8059             :                 {
    8060          94 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8061          94 :                     n->objtype = OBJECT_FUNCTION;
    8062          94 :                     n->func = $3;
    8063          94 :                     n->actions = $4;
    8064          94 :                     $$ = (Node *) n;
    8065             :                 }
    8066             :             | ALTER PROCEDURE function_with_argtypes alterfunc_opt_list opt_restrict
    8067             :                 {
    8068          12 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8069          12 :                     n->objtype = OBJECT_PROCEDURE;
    8070          12 :                     n->func = $3;
    8071          12 :                     n->actions = $4;
    8072          12 :                     $$ = (Node *) n;
    8073             :                 }
    8074             :             | ALTER ROUTINE function_with_argtypes alterfunc_opt_list opt_restrict
    8075             :                 {
    8076           0 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8077           0 :                     n->objtype = OBJECT_ROUTINE;
    8078           0 :                     n->func = $3;
    8079           0 :                     n->actions = $4;
    8080           0 :                     $$ = (Node *) n;
    8081             :                 }
    8082             :         ;
    8083             : 
    8084             : alterfunc_opt_list:
    8085             :             /* At least one option must be specified */
    8086         106 :             common_func_opt_item                    { $$ = list_make1($1); }
    8087           0 :             | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
    8088             :         ;
    8089             : 
    8090             : /* Ignored, merely for SQL compliance */
    8091             : opt_restrict:
    8092             :             RESTRICT
    8093             :             | /* EMPTY */
    8094             :         ;
    8095             : 
    8096             : 
    8097             : /*****************************************************************************
    8098             :  *
    8099             :  *      QUERY:
    8100             :  *
    8101             :  *      DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    8102             :  *      DROP PROCEDURE procname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    8103             :  *      DROP ROUTINE routname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    8104             :  *      DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
    8105             :  *      DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
    8106             :  *
    8107             :  *****************************************************************************/
    8108             : 
    8109             : RemoveFuncStmt:
    8110             :             DROP FUNCTION function_with_argtypes_list opt_drop_behavior
    8111             :                 {
    8112        1762 :                     DropStmt *n = makeNode(DropStmt);
    8113        1762 :                     n->removeType = OBJECT_FUNCTION;
    8114        1762 :                     n->objects = $3;
    8115        1762 :                     n->behavior = $4;
    8116        1762 :                     n->missing_ok = false;
    8117        1762 :                     n->concurrent = false;
    8118        1762 :                     $$ = (Node *)n;
    8119             :                 }
    8120             :             | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    8121             :                 {
    8122          26 :                     DropStmt *n = makeNode(DropStmt);
    8123          26 :                     n->removeType = OBJECT_FUNCTION;
    8124          26 :                     n->objects = $5;
    8125          26 :                     n->behavior = $6;
    8126          26 :                     n->missing_ok = true;
    8127          26 :                     n->concurrent = false;
    8128          26 :                     $$ = (Node *)n;
    8129             :                 }
    8130             :             | DROP PROCEDURE function_with_argtypes_list opt_drop_behavior
    8131             :                 {
    8132          72 :                     DropStmt *n = makeNode(DropStmt);
    8133          72 :                     n->removeType = OBJECT_PROCEDURE;
    8134          72 :                     n->objects = $3;
    8135          72 :                     n->behavior = $4;
    8136          72 :                     n->missing_ok = false;
    8137          72 :                     n->concurrent = false;
    8138          72 :                     $$ = (Node *)n;
    8139             :                 }
    8140             :             | DROP PROCEDURE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    8141             :                 {
    8142           4 :                     DropStmt *n = makeNode(DropStmt);
    8143           4 :                     n->removeType = OBJECT_PROCEDURE;
    8144           4 :                     n->objects = $5;
    8145           4 :                     n->behavior = $6;
    8146           4 :                     n->missing_ok = true;
    8147           4 :                     n->concurrent = false;
    8148           4 :                     $$ = (Node *)n;
    8149             :                 }
    8150             :             | DROP ROUTINE function_with_argtypes_list opt_drop_behavior
    8151             :                 {
    8152           8 :                     DropStmt *n = makeNode(DropStmt);
    8153           8 :                     n->removeType = OBJECT_ROUTINE;
    8154           8 :                     n->objects = $3;
    8155           8 :                     n->behavior = $4;
    8156           8 :                     n->missing_ok = false;
    8157           8 :                     n->concurrent = false;
    8158           8 :                     $$ = (Node *)n;
    8159             :                 }
    8160             :             | DROP ROUTINE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    8161             :                 {
    8162           4 :                     DropStmt *n = makeNode(DropStmt);
    8163           4 :                     n->removeType = OBJECT_ROUTINE;
    8164           4 :                     n->objects = $5;
    8165           4 :                     n->behavior = $6;
    8166           4 :                     n->missing_ok = true;
    8167           4 :                     n->concurrent = false;
    8168           4 :                     $$ = (Node *)n;
    8169             :                 }
    8170             :         ;
    8171             : 
    8172             : RemoveAggrStmt:
    8173             :             DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
    8174             :                 {
    8175          50 :                     DropStmt *n = makeNode(DropStmt);
    8176          50 :                     n->removeType = OBJECT_AGGREGATE;
    8177          50 :                     n->objects = $3;
    8178          50 :                     n->behavior = $4;
    8179          50 :                     n->missing_ok = false;
    8180          50 :                     n->concurrent = false;
    8181          50 :                     $$ = (Node *)n;
    8182             :                 }
    8183             :             | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
    8184             :                 {
    8185          20 :                     DropStmt *n = makeNode(DropStmt);
    8186          20 :                     n->removeType = OBJECT_AGGREGATE;
    8187          20 :                     n->objects = $5;
    8188          20 :                     n->behavior = $6;
    8189          20 :                     n->missing_ok = true;
    8190          20 :                     n->concurrent = false;
    8191          20 :                     $$ = (Node *)n;
    8192             :                 }
    8193             :         ;
    8194             : 
    8195             : RemoveOperStmt:
    8196             :             DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
    8197             :                 {
    8198          58 :                     DropStmt *n = makeNode(DropStmt);
    8199          58 :                     n->removeType = OBJECT_OPERATOR;
    8200          58 :                     n->objects = $3;
    8201          58 :                     n->behavior = $4;
    8202          58 :                     n->missing_ok = false;
    8203          58 :                     n->concurrent = false;
    8204          58 :                     $$ = (Node *)n;
    8205             :                 }
    8206             :             | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
    8207             :                 {
    8208          20 :                     DropStmt *n = makeNode(DropStmt);
    8209          20 :                     n->removeType = OBJECT_OPERATOR;
    8210          20 :                     n->objects = $5;
    8211          20 :                     n->behavior = $6;
    8212          20 :                     n->missing_ok = true;
    8213          20 :                     n->concurrent = false;
    8214          20 :                     $$ = (Node *)n;
    8215             :                 }
    8216             :         ;
    8217             : 
    8218             : oper_argtypes:
    8219             :             '(' Typename ')'
    8220             :                 {
    8221           8 :                    ereport(ERROR,
    8222             :                            (errcode(ERRCODE_SYNTAX_ERROR),
    8223             :                             errmsg("missing argument"),
    8224             :                             errhint("Use NONE to denote the missing argument of a unary operator."),
    8225             :                             parser_errposition(@3)));
    8226             :                 }
    8227             :             | '(' Typename ',' Typename ')'
    8228        1444 :                     { $$ = list_make2($2, $4); }
    8229             :             | '(' NONE ',' Typename ')'                 /* left unary */
    8230          12 :                     { $$ = list_make2(NULL, $4); }
    8231             :             | '(' Typename ',' NONE ')'                 /* right unary */
    8232          12 :                     { $$ = list_make2($2, NULL); }
    8233             :         ;
    8234             : 
    8235             : any_operator:
    8236             :             all_Op
    8237       10252 :                     { $$ = list_make1(makeString($1)); }
    8238             :             | ColId '.' any_operator
    8239        6448 :                     { $$ = lcons(makeString($1), $3); }
    8240             :         ;
    8241             : 
    8242             : operator_with_argtypes_list:
    8243          78 :             operator_with_argtypes                  { $$ = list_make1($1); }
    8244             :             | operator_with_argtypes_list ',' operator_with_argtypes
    8245           0 :                                                     { $$ = lappend($1, $3); }
    8246             :         ;
    8247             : 
    8248             : operator_with_argtypes:
    8249             :             any_operator oper_argtypes
    8250             :                 {
    8251        1468 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8252        1468 :                     n->objname = $1;
    8253        1468 :                     n->objargs = $2;
    8254        1468 :                     $$ = n;
    8255             :                 }
    8256             :         ;
    8257             : 
    8258             : /*****************************************************************************
    8259             :  *
    8260             :  *      DO <anonymous code block> [ LANGUAGE language ]
    8261             :  *
    8262             :  * We use a DefElem list for future extensibility, and to allow flexibility
    8263             :  * in the clause order.
    8264             :  *
    8265             :  *****************************************************************************/
    8266             : 
    8267             : DoStmt: DO dostmt_opt_list
    8268             :                 {
    8269         536 :                     DoStmt *n = makeNode(DoStmt);
    8270         536 :                     n->args = $2;
    8271         536 :                     $$ = (Node *)n;
    8272             :                 }
    8273             :         ;
    8274             : 
    8275             : dostmt_opt_list:
    8276         536 :             dostmt_opt_item                     { $$ = list_make1($1); }
    8277         150 :             | dostmt_opt_list dostmt_opt_item   { $$ = lappend($1, $2); }
    8278             :         ;
    8279             : 
    8280             : dostmt_opt_item:
    8281             :             Sconst
    8282             :                 {
    8283         536 :                     $$ = makeDefElem("as", (Node *)makeString($1), @1);
    8284             :                 }
    8285             :             | LANGUAGE NonReservedWord_or_Sconst
    8286             :                 {
    8287         150 :                     $$ = makeDefElem("language", (Node *)makeString($2), @1);
    8288             :                 }
    8289             :         ;
    8290             : 
    8291             : /*****************************************************************************
    8292             :  *
    8293             :  *      CREATE CAST / DROP CAST
    8294             :  *
    8295             :  *****************************************************************************/
    8296             : 
    8297             : CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
    8298             :                     WITH FUNCTION function_with_argtypes cast_context
    8299             :                 {
    8300          82 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    8301          82 :                     n->sourcetype = $4;
    8302          82 :                     n->targettype = $6;
    8303          82 :                     n->func = $10;
    8304          82 :                     n->context = (CoercionContext) $11;
    8305          82 :                     n->inout = false;
    8306          82 :                     $$ = (Node *)n;
    8307             :                 }
    8308             :             | CREATE CAST '(' Typename AS Typename ')'
    8309             :                     WITHOUT FUNCTION cast_context
    8310             :                 {
    8311         112 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    8312         112 :                     n->sourcetype = $4;
    8313         112 :                     n->targettype = $6;
    8314         112 :                     n->func = NULL;
    8315         112 :                     n->context = (CoercionContext) $10;
    8316         112 :                     n->inout = false;
    8317         112 :                     $$ = (Node *)n;
    8318             :                 }
    8319             :             | CREATE CAST '(' Typename AS Typename ')'
    8320             :                     WITH INOUT cast_context
    8321             :                 {
    8322           4 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    8323           4 :                     n->sourcetype = $4;
    8324           4 :                     n->targettype = $6;
    8325           4 :                     n->func = NULL;
    8326           4 :                     n->context = (CoercionContext) $10;
    8327           4 :                     n->inout = true;
    8328           4 :                     $$ = (Node *)n;
    8329             :                 }
    8330             :         ;
    8331             : 
    8332          16 : cast_context:  AS IMPLICIT_P                    { $$ = COERCION_IMPLICIT; }
    8333          44 :         | AS ASSIGNMENT                         { $$ = COERCION_ASSIGNMENT; }
    8334         138 :         | /*EMPTY*/                             { $$ = COERCION_EXPLICIT; }
    8335             :         ;
    8336             : 
    8337             : 
    8338             : DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
    8339             :                 {
    8340          36 :                     DropStmt *n = makeNode(DropStmt);
    8341          36 :                     n->removeType = OBJECT_CAST;
    8342          36 :                     n->objects = list_make1(list_make2($5, $7));
    8343          36 :                     n->behavior = $9;
    8344          36 :                     n->missing_ok = $3;
    8345          36 :                     n->concurrent = false;
    8346          36 :                     $$ = (Node *)n;
    8347             :                 }
    8348             :         ;
    8349             : 
    8350          26 : opt_if_exists: IF_P EXISTS                      { $$ = true; }
    8351          24 :         | /*EMPTY*/                             { $$ = false; }
    8352             :         ;
    8353             : 
    8354             : 
    8355             : /*****************************************************************************
    8356             :  *
    8357             :  *      CREATE TRANSFORM / DROP TRANSFORM
    8358             :  *
    8359             :  *****************************************************************************/
    8360             : 
    8361             : CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name '(' transform_element_list ')'
    8362             :                 {
    8363          54 :                     CreateTransformStmt *n = makeNode(CreateTransformStmt);
    8364          54 :                     n->replace = $2;
    8365          54 :                     n->type_name = $5;
    8366          54 :                     n->lang = $7;
    8367          54 :                     n->fromsql = linitial($9);
    8368          54 :                     n->tosql = lsecond($9);
    8369          54 :                     $$ = (Node *)n;
    8370             :                 }
    8371             :         ;
    8372             : 
    8373             : transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes ',' TO SQL_P WITH FUNCTION function_with_argtypes
    8374             :                 {
    8375          46 :                     $$ = list_make2($5, $11);
    8376             :                 }
    8377             :                 | TO SQL_P WITH FUNCTION function_with_argtypes ',' FROM SQL_P WITH FUNCTION function_with_argtypes
    8378             :                 {
    8379           0 :                     $$ = list_make2($11, $5);
    8380             :                 }
    8381             :                 | FROM SQL_P WITH FUNCTION function_with_argtypes
    8382             :                 {
    8383           6 :                     $$ = list_make2($5, NULL);
    8384             :                 }
    8385             :                 | TO SQL_P WITH FUNCTION function_with_argtypes
    8386             :                 {
    8387           2 :                     $$ = list_make2(NULL, $5);
    8388             :                 }
    8389             :         ;
    8390             : 
    8391             : 
    8392             : DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
    8393             :                 {
    8394          14 :                     DropStmt *n = makeNode(DropStmt);
    8395          14 :                     n->removeType = OBJECT_TRANSFORM;
    8396          14 :                     n->objects = list_make1(list_make2($5, makeString($7)));
    8397          14 :                     n->behavior = $8;
    8398          14 :                     n->missing_ok = $3;
    8399          14 :                     $$ = (Node *)n;
    8400             :                 }
    8401             :         ;
    8402             : 
    8403             : 
    8404             : /*****************************************************************************
    8405             :  *
    8406             :  *      QUERY:
    8407             :  *
    8408             :  *      REINDEX [ (options) ] type [CONCURRENTLY] <name>
    8409             :  *****************************************************************************/
    8410             : 
    8411             : ReindexStmt:
    8412             :             REINDEX reindex_target_type opt_concurrently qualified_name
    8413             :                 {
    8414         226 :                     ReindexStmt *n = makeNode(ReindexStmt);
    8415         226 :                     n->kind = $2;
    8416         226 :                     n->concurrent = $3;
    8417         226 :                     n->relation = $4;
    8418         226 :                     n->name = NULL;
    8419         226 :                     n->options = 0;
    8420         226 :                     $$ = (Node *)n;
    8421             :                 }
    8422             :             | REINDEX reindex_target_multitable opt_concurrently name
    8423             :                 {
    8424          72 :                     ReindexStmt *n = makeNode(ReindexStmt);
    8425          72 :                     n->kind = $2;
    8426          72 :                     n->concurrent = $3;
    8427          72 :                     n->name = $4;
    8428          72 :                     n->relation = NULL;
    8429          72 :                     n->options = 0;
    8430          72 :                     $$ = (Node *)n;
    8431             :                 }
    8432             :             | REINDEX '(' reindex_option_list ')' reindex_target_type opt_concurrently qualified_name
    8433             :                 {
    8434           8 :                     ReindexStmt *n = makeNode(ReindexStmt);
    8435           8 :                     n->kind = $5;
    8436           8 :                     n->concurrent = $6;
    8437           8 :                     n->relation = $7;
    8438           8 :                     n->name = NULL;
    8439           8 :                     n->options = $3;
    8440           8 :                     $$ = (Node *)n;
    8441             :                 }
    8442             :             | REINDEX '(' reindex_option_list ')' reindex_target_multitable opt_concurrently name
    8443             :                 {
    8444           0 :                     ReindexStmt *n = makeNode(ReindexStmt);
    8445           0 :                     n->kind = $5;
    8446           0 :                     n->concurrent = $6;
    8447           0 :                     n->name = $7;
    8448           0 :                     n->relation = NULL;
    8449           0 :                     n->options = $3;
    8450           0 :                     $$ = (Node *)n;
    8451             :                 }
    8452             :         ;
    8453             : reindex_target_type:
    8454         100 :             INDEX                   { $$ = REINDEX_OBJECT_INDEX; }
    8455         134 :             | TABLE                 { $$ = REINDEX_OBJECT_TABLE; }
    8456             :         ;
    8457             : reindex_target_multitable:
    8458          36 :             SCHEMA                  { $$ = REINDEX_OBJECT_SCHEMA; }
    8459          12 :             | SYSTEM_P              { $$ = REINDEX_OBJECT_SYSTEM; }
    8460          24 :             | DATABASE              { $$ = REINDEX_OBJECT_DATABASE; }
    8461             :         ;
    8462             : reindex_option_list:
    8463           8 :             reindex_option_elem                             { $$ = $1; }
    8464           0 :             | reindex_option_list ',' reindex_option_elem   { $$ = $1 | $3; }
    8465             :         ;
    8466             : reindex_option_elem:
    8467           8 :             VERBOSE { $$ = REINDEXOPT_VERBOSE; }
    8468             :         ;
    8469             : 
    8470             : /*****************************************************************************
    8471             :  *
    8472             :  * ALTER TABLESPACE
    8473             :  *
    8474             :  *****************************************************************************/
    8475             : 
    8476             : AlterTblSpcStmt:
    8477             :             ALTER TABLESPACE name SET reloptions
    8478             :                 {
    8479           8 :                     AlterTableSpaceOptionsStmt *n =
    8480           8 :                         makeNode(AlterTableSpaceOptionsStmt);
    8481           8 :                     n->tablespacename = $3;
    8482           8 :                     n->options = $5;
    8483           8 :                     n->isReset = false;
    8484           8 :                     $$ = (Node *)n;
    8485             :                 }
    8486             :             | ALTER TABLESPACE name RESET reloptions
    8487             :                 {
    8488           8 :                     AlterTableSpaceOptionsStmt *n =
    8489           8 :                         makeNode(AlterTableSpaceOptionsStmt);
    8490           8 :                     n->tablespacename = $3;
    8491           8 :                     n->options = $5;
    8492           8 :                     n->isReset = true;
    8493           8 :                     $$ = (Node *)n;
    8494             :                 }
    8495             :         ;
    8496             : 
    8497             : /*****************************************************************************
    8498             :  *
    8499             :  * ALTER THING name RENAME TO newname
    8500             :  *
    8501             :  *****************************************************************************/
    8502             : 
    8503             : RenameStmt: ALTER AGGREGATE aggregate_with_argtypes RENAME TO name
    8504             :                 {
    8505          28 :                     RenameStmt *n = makeNode(RenameStmt);
    8506          28 :                     n->renameType = OBJECT_AGGREGATE;
    8507          28 :                     n->object = (Node *) $3;
    8508          28 :                     n->newname = $6;
    8509          28 :                     n->missing_ok = false;
    8510          28 :                     $$ = (Node *)n;
    8511             :                 }
    8512             :             | ALTER COLLATION any_name RENAME TO name
    8513             :                 {
    8514           0 :                     RenameStmt *n = makeNode(RenameStmt);
    8515           0 :                     n->renameType = OBJECT_COLLATION;
    8516           0 :                     n->object = (Node *) $3;
    8517           0 :                     n->newname = $6;
    8518           0 :                     n->missing_ok = false;
    8519           0 :                     $$ = (Node *)n;
    8520             :                 }
    8521             :             | ALTER CONVERSION_P any_name RENAME TO name
    8522             :                 {
    8523          16 :                     RenameStmt *n = makeNode(RenameStmt);
    8524          16 :                     n->renameType = OBJECT_CONVERSION;
    8525          16 :                     n->object = (Node *) $3;
    8526          16 :                     n->newname = $6;
    8527          16 :                     n->missing_ok = false;
    8528          16 :                     $$ = (Node *)n;
    8529             :                 }
    8530             :             | ALTER DATABASE database_name RENAME TO database_name
    8531             :                 {
    8532           0 :                     RenameStmt *n = makeNode(RenameStmt);
    8533           0 :                     n->renameType = OBJECT_DATABASE;
    8534           0 :                     n->subname = $3;
    8535           0 :                     n->newname = $6;
    8536           0 :                     n->missing_ok = false;
    8537           0 :                     $$ = (Node *)n;
    8538             :                 }
    8539             :             | ALTER DOMAIN_P any_name RENAME TO name
    8540             :                 {
    8541           4 :                     RenameStmt *n = makeNode(RenameStmt);
    8542           4 :                     n->renameType = OBJECT_DOMAIN;
    8543           4 :                     n->object = (Node *) $3;
    8544           4 :                     n->newname = $6;
    8545           4 :                     n->missing_ok = false;
    8546           4 :                     $$ = (Node *)n;
    8547             :                 }
    8548             :             | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
    8549             :                 {
    8550           4 :                     RenameStmt *n = makeNode(RenameStmt);
    8551           4 :                     n->renameType = OBJECT_DOMCONSTRAINT;
    8552           4 :                     n->object = (Node *) $3;
    8553           4 :                     n->subname = $6;
    8554           4 :                     n->newname = $8;
    8555           4 :                     $$ = (Node *)n;
    8556             :                 }
    8557             :             | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
    8558             :                 {
    8559          16 :                     RenameStmt *n = makeNode(RenameStmt);
    8560          16 :                     n->renameType = OBJECT_FDW;
    8561          16 :                     n->object = (Node *) makeString($5);
    8562          16 :                     n->newname = $8;
    8563          16 :                     n->missing_ok = false;
    8564          16 :                     $$ = (Node *)n;
    8565             :                 }
    8566             :             | ALTER FUNCTION function_with_argtypes RENAME TO name
    8567             :                 {
    8568          16 :                     RenameStmt *n = makeNode(RenameStmt);
    8569          16 :                     n->renameType = OBJECT_FUNCTION;
    8570          16 :                     n->object = (Node *) $3;
    8571          16 :                     n->newname = $6;
    8572          16 :                     n->missing_ok = false;
    8573          16 :                     $$ = (Node *)n;
    8574             :                 }
    8575             :             | ALTER GROUP_P RoleId RENAME TO RoleId
    8576             :                 {
    8577           0 :                     RenameStmt *n = makeNode(RenameStmt);
    8578           0 :                     n->renameType = OBJECT_ROLE;
    8579           0 :                     n->subname = $3;
    8580           0 :                     n->newname = $6;
    8581           0 :                     n->missing_ok = false;
    8582           0 :                     $$ = (Node *)n;
    8583             :                 }
    8584             :             | ALTER opt_procedural LANGUAGE name RENAME TO name
    8585             :                 {
    8586          12 :                     RenameStmt *n = makeNode(RenameStmt);
    8587          12 :                     n->renameType = OBJECT_LANGUAGE;
    8588          12 :                     n->object = (Node *) makeString($4);
    8589          12 :                     n->newname = $7;
    8590          12 :                     n->missing_ok = false;
    8591          12 :                     $$ = (Node *)n;
    8592             :                 }
    8593             :             | ALTER OPERATOR CLASS any_name USING access_method RENAME TO name
    8594             :                 {
    8595          16 :                     RenameStmt *n = makeNode(RenameStmt);
    8596          16 :                     n->renameType = OBJECT_OPCLASS;
    8597          16 :                     n->object = (Node *) lcons(makeString($6), $4);
    8598          16 :                     n->newname = $9;
    8599          16 :                     n->missing_ok = false;
    8600          16 :                     $$ = (Node *)n;
    8601             :                 }
    8602             :             | ALTER OPERATOR FAMILY any_name USING access_method RENAME TO name
    8603             :                 {
    8604          16 :                     RenameStmt *n = makeNode(RenameStmt);
    8605          16 :                     n->renameType = OBJECT_OPFAMILY;
    8606          16 :                     n->object = (Node *) lcons(makeString($6), $4);
    8607          16 :                     n->newname = $9;
    8608          16 :                     n->missing_ok = false;
    8609          16 :                     $$ = (Node *)n;
    8610             :                 }
    8611             :             | ALTER POLICY name ON qualified_name RENAME TO name
    8612             :                 {
    8613          12 :                     RenameStmt *n = makeNode(RenameStmt);
    8614          12 :                     n->renameType = OBJECT_POLICY;
    8615          12 :                     n->relation = $5;
    8616          12 :                     n->subname = $3;
    8617          12 :                     n->newname = $8;
    8618          12 :                     n->missing_ok = false;
    8619          12 :                     $$ = (Node *)n;
    8620             :                 }
    8621             :             | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
    8622             :                 {
    8623           0 :                     RenameStmt *n = makeNode(RenameStmt);
    8624           0 :                     n->renameType = OBJECT_POLICY;
    8625           0 :                     n->relation = $7;
    8626           0 :                     n->subname = $5;
    8627           0 :                     n->newname = $10;
    8628           0 :                     n->missing_ok = true;
    8629           0 :                     $$ = (Node *)n;
    8630             :                 }
    8631             :             | ALTER PROCEDURE function_with_argtypes RENAME TO name
    8632             :                 {
    8633           0 :                     RenameStmt *n = makeNode(RenameStmt);
    8634           0 :                     n->renameType = OBJECT_PROCEDURE;
    8635           0 :                     n->object = (Node *) $3;
    8636           0 :                     n->newname = $6;
    8637           0 :                     n->missing_ok = false;
    8638           0 :                     $$ = (Node *)n;
    8639             :                 }
    8640             :             | ALTER PUBLICATION name RENAME TO name
    8641             :                 {
    8642          12 :                     RenameStmt *n = makeNode(RenameStmt);
    8643          12 :                     n->renameType = OBJECT_PUBLICATION;
    8644          12 :                     n->object = (Node *) makeString($3);
    8645          12 :                     n->newname = $6;
    8646          12 :                     n->missing_ok = false;
    8647          12 :                     $$ = (Node *)n;
    8648             :                 }
    8649             :             | ALTER ROUTINE function_with_argtypes RENAME TO name
    8650             :                 {
    8651          16 :                     RenameStmt *n = makeNode(RenameStmt);
    8652          16 :                     n->renameType = OBJECT_ROUTINE;
    8653          16 :                     n->object = (Node *) $3;
    8654          16 :                     n->newname = $6;
    8655          16 :                     n->missing_ok = false;
    8656          16 :                     $$ = (Node *)n;
    8657             :                 }
    8658             :             | ALTER SCHEMA name RENAME TO name
    8659             :                 {
    8660           4 :                     RenameStmt *n = makeNode(RenameStmt);
    8661           4 :                     n->renameType = OBJECT_SCHEMA;
    8662           4 :                     n->subname = $3;
    8663           4 :                     n->newname = $6;
    8664           4 :                     n->missing_ok = false;
    8665           4 :                     $$ = (Node *)n;
    8666             :                 }
    8667             :             | ALTER SERVER name RENAME TO name
    8668             :                 {
    8669          16 :                     RenameStmt *n = makeNode(RenameStmt);
    8670          16 :                     n->renameType = OBJECT_FOREIGN_SERVER;
    8671          16 :                     n->object = (Node *) makeString($3);
    8672          16 :                     n->newname = $6;
    8673          16 :                     n->missing_ok = false;
    8674          16 :                     $$ = (Node *)n;
    8675             :                 }
    8676             :             | ALTER SUBSCRIPTION name RENAME TO name
    8677             :                 {
    8678          14 :                     RenameStmt *n = makeNode(RenameStmt);
    8679          14 :                     n->renameType = OBJECT_SUBSCRIPTION;
    8680          14 :                     n->object = (Node *) makeString($3);
    8681          14 :                     n->newname = $6;
    8682          14 :                     n->missing_ok = false;
    8683          14 :                     $$ = (Node *)n;
    8684             :                 }
    8685             :             | ALTER TABLE relation_expr RENAME TO name
    8686             :                 {
    8687         106 :                     RenameStmt *n = makeNode(RenameStmt);
    8688         106 :                     n->renameType = OBJECT_TABLE;
    8689         106 :                     n->relation = $3;
    8690         106 :                     n->subname = NULL;
    8691         106 :                     n->newname = $6;
    8692         106 :                     n->missing_ok = false;
    8693         106 :                     $$ = (Node *)n;
    8694             :                 }
    8695             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
    8696             :                 {
    8697           0 :                     RenameStmt *n = makeNode(RenameStmt);
    8698           0 :                     n->renameType = OBJECT_TABLE;
    8699           0 :                     n->relation = $5;
    8700           0 :                     n->subname = NULL;
    8701           0 :                     n->newname = $8;
    8702           0 :                     n->missing_ok = true;
    8703           0 :                     $$ = (Node *)n;
    8704             :                 }
    8705             :             | ALTER SEQUENCE qualified_name RENAME TO name
    8706             :                 {
    8707           2 :                     RenameStmt *n = makeNode(RenameStmt);
    8708           2 :                     n->renameType = OBJECT_SEQUENCE;
    8709           2 :                     n->relation = $3;
    8710           2 :                     n->subname = NULL;
    8711           2 :                     n->newname = $6;
    8712           2 :                     n->missing_ok = false;
    8713           2 :                     $$ = (Node *)n;
    8714             :                 }
    8715             :             | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
    8716             :                 {
    8717           0 :                     RenameStmt *n = makeNode(RenameStmt);
    8718           0 :                     n->renameType = OBJECT_SEQUENCE;
    8719           0 :                     n->relation = $5;
    8720           0 :                     n->subname = NULL;
    8721           0 :                     n->newname = $8;
    8722           0 :                     n->missing_ok = true;
    8723           0 :                     $$ = (Node *)n;
    8724             :                 }
    8725             :             | ALTER VIEW qualified_name RENAME TO name
    8726             :                 {
    8727           4 :                     RenameStmt *n = makeNode(RenameStmt);
    8728           4 :                     n->renameType = OBJECT_VIEW;
    8729           4 :                     n->relation = $3;
    8730           4 :                     n->subname = NULL;
    8731           4 :                     n->newname = $6;
    8732           4 :                     n->missing_ok = false;
    8733           4 :                     $$ = (Node *)n;
    8734             :                 }
    8735             :             | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
    8736             :                 {
    8737           0 :                     RenameStmt *n = makeNode(RenameStmt);
    8738           0 :                     n->renameType = OBJECT_VIEW;
    8739           0 :                     n->relation = $5;
    8740           0 :                     n->subname = NULL;
    8741           0 :                     n->newname = $8;
    8742           0 :                     n->missing_ok = true;
    8743           0 :                     $$ = (Node *)n;
    8744             :                 }
    8745             :             | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
    8746             :                 {
    8747           0 :                     RenameStmt *n = makeNode(RenameStmt);
    8748           0 :                     n->renameType = OBJECT_MATVIEW;
    8749           0 :                     n->relation = $4;
    8750           0 :                     n->subname = NULL;
    8751           0 :                     n->newname = $7;
    8752           0 :                     n->missing_ok = false;
    8753           0 :                     $$ = (Node *)n;
    8754             :                 }
    8755             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
    8756             :                 {
    8757           0 :                     RenameStmt *n = makeNode(RenameStmt);
    8758           0 :                     n->renameType = OBJECT_MATVIEW;
    8759           0 :                     n->relation = $6;
    8760           0 :                     n->subname = NULL;
    8761           0 :                     n->newname = $9;
    8762           0 :                     n->missing_ok = true;
    8763           0 :                     $$ = (Node *)n;
    8764             :                 }
    8765             :             | ALTER INDEX qualified_name RENAME TO name
    8766             :                 {
    8767          32 :                     RenameStmt *n = makeNode(RenameStmt);
    8768          32 :                     n->renameType = OBJECT_INDEX;
    8769          32 :                     n->relation = $3;
    8770          32 :                     n->subname = NULL;
    8771          32 :                     n->newname = $6;
    8772          32 :                     n->missing_ok = false;
    8773          32 :                     $$ = (Node *)n;
    8774             :                 }
    8775             :             | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
    8776             :                 {
    8777           8 :                     RenameStmt *n = makeNode(RenameStmt);
    8778           8 :                     n->renameType = OBJECT_INDEX;
    8779           8 :                     n->relation = $5;
    8780           8 :                     n->subname = NULL;
    8781           8 :                     n->newname = $8;
    8782           8 :                     n->missing_ok = true;
    8783           8 :                     $$ = (Node *)n;
    8784             :                 }
    8785             :             | ALTER FOREIGN TABLE relation_expr RENAME TO name
    8786             :                 {
    8787           4 :                     RenameStmt *n = makeNode(RenameStmt);
    8788           4 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    8789           4 :                     n->relation = $4;
    8790           4 :                     n->subname = NULL;
    8791           4 :                     n->newname = $7;
    8792           4 :                     n->missing_ok = false;
    8793           4 :                     $$ = (Node *)n;
    8794             :                 }
    8795             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
    8796             :                 {
    8797           4 :                     RenameStmt *n = makeNode(RenameStmt);
    8798           4 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    8799           4 :                     n->relation = $6;
    8800           4 :                     n->subname = NULL;
    8801           4 :                     n->newname = $9;
    8802           4 :                     n->missing_ok = true;
    8803           4 :                     $$ = (Node *)n;
    8804             :                 }
    8805             :             | ALTER TABLE relation_expr RENAME opt_column name TO name
    8806             :                 {
    8807         150 :                     RenameStmt *n = makeNode(RenameStmt);
    8808         150 :                     n->renameType = OBJECT_COLUMN;
    8809         150 :                     n->relationType = OBJECT_TABLE;
    8810         150 :                     n->relation = $3;
    8811         150 :                     n->subname = $6;
    8812         150 :                     n->newname = $8;
    8813         150 :                     n->missing_ok = false;
    8814         150 :                     $$ = (Node *)n;
    8815             :                 }
    8816             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    8817             :                 {
    8818          16 :                     RenameStmt *n = makeNode(RenameStmt);
    8819          16 :                     n->renameType = OBJECT_COLUMN;
    8820          16 :                     n->relationType = OBJECT_TABLE;
    8821          16 :                     n->relation = $5;
    8822          16 :                     n->subname = $8;
    8823          16 :                     n->newname = $10;
    8824          16 :                     n->missing_ok = true;
    8825          16 :                     $$ = (Node *)n;
    8826             :                 }
    8827             :             | ALTER VIEW qualified_name RENAME opt_column name TO name
    8828             :                 {
    8829           4 :                     RenameStmt *n = makeNode(RenameStmt);
    8830           4 :                     n->renameType = OBJECT_COLUMN;
    8831           4 :                     n->relationType = OBJECT_VIEW;
    8832           4 :                     n->relation = $3;
    8833           4 :                     n->subname = $6;
    8834           4 :                     n->newname = $8;
    8835           4 :                     n->missing_ok = false;
    8836           4 :                     $$ = (Node *)n;
    8837             :                 }
    8838             :             | ALTER VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    8839             :                 {
    8840           0 :                     RenameStmt *n = makeNode(RenameStmt);
    8841           0 :                     n->renameType = OBJECT_COLUMN;
    8842           0 :                     n->relationType = OBJECT_VIEW;
    8843           0 :                     n->relation = $5;
    8844           0 :                     n->subname = $8;
    8845           0 :                     n->newname = $10;
    8846           0 :                     n->missing_ok = true;
    8847           0 :                     $$ = (Node *)n;
    8848             :                 }
    8849             :             | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
    8850             :                 {
    8851           0 :                     RenameStmt *n = makeNode(RenameStmt);
    8852           0 :                     n->renameType = OBJECT_COLUMN;
    8853           0 :                     n->relationType = OBJECT_MATVIEW;
    8854           0 :                     n->relation = $4;
    8855           0 :                     n->subname = $7;
    8856           0 :                     n->newname = $9;
    8857           0 :                     n->missing_ok = false;
    8858           0 :                     $$ = (Node *)n;
    8859             :                 }
    8860             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    8861             :                 {
    8862           0 :                     RenameStmt *n = makeNode(RenameStmt);
    8863           0 :                     n->renameType = OBJECT_COLUMN;
    8864           0 :                     n->relationType = OBJECT_MATVIEW;
    8865           0 :                     n->relation = $6;
    8866           0 :                     n->subname = $9;
    8867           0 :                     n->newname = $11;
    8868           0 :                     n->missing_ok = true;
    8869           0 :                     $$ = (Node *)n;
    8870             :                 }
    8871             :             | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
    8872             :                 {
    8873          44 :                     RenameStmt *n = makeNode(RenameStmt);
    8874          44 :                     n->renameType = OBJECT_TABCONSTRAINT;
    8875          44 :                     n->relation = $3;
    8876          44 :                     n->subname = $6;
    8877          44 :                     n->newname = $8;
    8878          44 :                     n->missing_ok = false;
    8879          44 :                     $$ = (Node *)n;
    8880             :                 }
    8881             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
    8882             :                 {
    8883           4 :                     RenameStmt *n = makeNode(RenameStmt);
    8884           4 :                     n->renameType = OBJECT_TABCONSTRAINT;
    8885           4 :                     n->relation = $5;
    8886           4 :                     n->subname = $8;
    8887           4 :                     n->newname = $10;
    8888           4 :                     n->missing_ok = true;
    8889           4 :                     $$ = (Node *)n;
    8890             :                 }
    8891             :             | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
    8892             :                 {
    8893           4 :                     RenameStmt *n = makeNode(RenameStmt);
    8894           4 :                     n->renameType = OBJECT_COLUMN;
    8895           4 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    8896           4 :                     n->relation = $4;
    8897           4 :                     n->subname = $7;
    8898           4 :                     n->newname = $9;
    8899           4 :                     n->missing_ok = false;
    8900           4 :                     $$ = (Node *)n;
    8901             :                 }
    8902             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    8903             :                 {
    8904           4 :                     RenameStmt *n = makeNode(RenameStmt);
    8905           4 :                     n->renameType = OBJECT_COLUMN;
    8906           4 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    8907           4 :                     n->relation = $6;
    8908           4 :                     n->subname = $9;
    8909           4 :                     n->newname = $11;
    8910           4 :                     n->missing_ok = true;
    8911           4 :                     $$ = (Node *)n;
    8912             :                 }
    8913             :             | ALTER RULE name ON qualified_name RENAME TO name
    8914             :                 {
    8915          24 :                     RenameStmt *n = makeNode(RenameStmt);
    8916          24 :                     n->renameType = OBJECT_RULE;
    8917          24 :                     n->relation = $5;
    8918          24 :                     n->subname = $3;
    8919          24 :                     n->newname = $8;
    8920          24 :                     n->missing_ok = false;
    8921          24 :                     $$ = (Node *)n;
    8922             :                 }
    8923             :             | ALTER TRIGGER name ON qualified_name RENAME TO name
    8924             :                 {
    8925           8 :                     RenameStmt *n = makeNode(RenameStmt);
    8926           8 :                     n->renameType = OBJECT_TRIGGER;
    8927           8 :                     n->relation = $5;
    8928           8 :                     n->subname = $3;
    8929           8 :                     n->newname = $8;
    8930           8 :                     n->missing_ok = false;
    8931           8 :                     $$ = (Node *)n;
    8932             :                 }
    8933             :             | ALTER EVENT TRIGGER name RENAME TO name
    8934             :                 {
    8935           8 :                     RenameStmt *n = makeNode(RenameStmt);
    8936           8 :                     n->renameType = OBJECT_EVENT_TRIGGER;
    8937           8 :                     n->object = (Node *) makeString($4);
    8938           8 :                     n->newname = $7;
    8939           8 :                     $$ = (Node *)n;
    8940             :                 }
    8941             :             | ALTER ROLE RoleId RENAME TO RoleId
    8942             :                 {
    8943          12 :                     RenameStmt *n = makeNode(RenameStmt);
    8944          12 :                     n->renameType = OBJECT_ROLE;
    8945          12 :                     n->subname = $3;
    8946          12 :                     n->newname = $6;
    8947          12 :                     n->missing_ok = false;
    8948          12 :                     $$ = (Node *)n;
    8949             :                 }
    8950             :             | ALTER USER RoleId RENAME TO RoleId
    8951             :                 {
    8952           0 :                     RenameStmt *n = makeNode(RenameStmt);
    8953           0 :                     n->renameType = OBJECT_ROLE;
    8954           0 :                     n->subname = $3;
    8955           0 :                     n->newname = $6;
    8956           0 :                     n->missing_ok = false;
    8957           0 :                     $$ = (Node *)n;
    8958             :                 }
    8959             :             | ALTER TABLESPACE name RENAME TO name
    8960             :                 {
    8961           4 :                     RenameStmt *n = makeNode(RenameStmt);
    8962           4 :                     n->renameType = OBJECT_TABLESPACE;
    8963           4 :                     n->subname = $3;
    8964           4 :                     n->newname = $6;
    8965           4 :                     n->missing_ok = false;
    8966           4 :                     $$ = (Node *)n;
    8967             :                 }
    8968             :             | ALTER STATISTICS any_name RENAME TO name
    8969             :                 {
    8970          16 :                     RenameStmt *n = makeNode(RenameStmt);
    8971          16 :                     n->renameType = OBJECT_STATISTIC_EXT;
    8972          16 :                     n->object = (Node *) $3;
    8973          16 :                     n->newname = $6;
    8974          16 :                     n->missing_ok = false;
    8975          16 :                     $$ = (Node *)n;
    8976             :                 }
    8977             :             | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
    8978             :                 {
    8979           8 :                     RenameStmt *n = makeNode(RenameStmt);
    8980           8 :                     n->renameType = OBJECT_TSPARSER;
    8981           8 :                     n->object = (Node *) $5;
    8982           8 :                     n->newname = $8;
    8983           8 :                     n->missing_ok = false;
    8984           8 :                     $$ = (Node *)n;
    8985             :                 }
    8986             :             | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
    8987             :                 {
    8988          16 :                     RenameStmt *n = makeNode(RenameStmt);
    8989          16 :                     n->renameType = OBJECT_TSDICTIONARY;
    8990          16 :                     n->object = (Node *) $5;
    8991          16 :                     n->newname = $8;
    8992          16 :                     n->missing_ok = false;
    8993          16 :                     $$ = (Node *)n;
    8994             :                 }
    8995             :             | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
    8996             :                 {
    8997           8 :                     RenameStmt *n = makeNode(RenameStmt);
    8998           8 :                     n->renameType = OBJECT_TSTEMPLATE;
    8999           8 :                     n->object = (Node *) $5;
    9000           8 :                     n->newname = $8;
    9001           8 :                     n->missing_ok = false;
    9002           8 :                     $$ = (Node *)n;
    9003             :                 }
    9004             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
    9005             :                 {
    9006          16 :                     RenameStmt *n = makeNode(RenameStmt);
    9007          16 :                     n->renameType = OBJECT_TSCONFIGURATION;
    9008          16 :                     n->object = (Node *) $5;
    9009          16 :                     n->newname = $8;
    9010          16 :                     n->missing_ok = false;
    9011          16 :                     $$ = (Node *)n;
    9012             :                 }
    9013             :             | ALTER TYPE_P any_name RENAME TO name
    9014             :                 {
    9015          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9016          18 :                     n->renameType = OBJECT_TYPE;
    9017          18 :                     n->object = (Node *) $3;
    9018          18 :                     n->newname = $6;
    9019          18 :                     n->missing_ok = false;
    9020          18 :                     $$ = (Node *)n;
    9021             :                 }
    9022             :             | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
    9023             :                 {
    9024          16 :                     RenameStmt *n = makeNode(RenameStmt);
    9025          16 :                     n->renameType = OBJECT_ATTRIBUTE;
    9026          16 :                     n->relationType = OBJECT_TYPE;
    9027          16 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
    9028          16 :                     n->subname = $6;
    9029          16 :                     n->newname = $8;
    9030          16 :                     n->behavior = $9;
    9031          16 :                     n->missing_ok = false;
    9032          16 :                     $$ = (Node *)n;
    9033             :                 }
    9034             :         ;
    9035             : 
    9036        2094 : opt_column: COLUMN                                  { $$ = COLUMN; }
    9037         594 :             | /*EMPTY*/                             { $$ = 0; }
    9038             :         ;
    9039             : 
    9040          76 : opt_set_data: SET DATA_P                            { $$ = 1; }
    9041         470 :             | /*EMPTY*/                             { $$ = 0; }
    9042             :         ;
    9043             : 
    9044             : /*****************************************************************************
    9045             :  *
    9046             :  * ALTER THING name DEPENDS ON EXTENSION name
    9047             :  *
    9048             :  *****************************************************************************/
    9049             : 
    9050             : AlterObjectDependsStmt:
    9051             :             ALTER FUNCTION function_with_argtypes opt_no DEPENDS ON EXTENSION name
    9052             :                 {
    9053          12 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9054          12 :                     n->objectType = OBJECT_FUNCTION;
    9055          12 :                     n->object = (Node *) $3;
    9056          12 :                     n->extname = makeString($8);
    9057          12 :                     n->remove = $4;
    9058          12 :                     $$ = (Node *)n;
    9059             :                 }
    9060             :             | ALTER PROCEDURE function_with_argtypes opt_no DEPENDS ON EXTENSION name
    9061             :                 {
    9062           0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9063           0 :                     n->objectType = OBJECT_PROCEDURE;
    9064           0 :                     n->object = (Node *) $3;
    9065           0 :                     n->extname = makeString($8);
    9066           0 :                     n->remove = $4;
    9067           0 :                     $$ = (Node *)n;
    9068             :                 }
    9069             :             | ALTER ROUTINE function_with_argtypes opt_no DEPENDS ON EXTENSION name
    9070             :                 {
    9071           0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9072           0 :                     n->objectType = OBJECT_ROUTINE;
    9073           0 :                     n->object = (Node *) $3;
    9074           0 :                     n->extname = makeString($8);
    9075           0 :                     n->remove = $4;
    9076           0 :                     $$ = (Node *)n;
    9077             :                 }
    9078             :             | ALTER TRIGGER name ON qualified_name opt_no DEPENDS ON EXTENSION name
    9079             :                 {
    9080          10 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9081          10 :                     n->objectType = OBJECT_TRIGGER;
    9082          10 :                     n->relation = $5;
    9083          10 :                     n->object = (Node *) list_make1(makeString($3));
    9084          10 :                     n->extname = makeString($10);
    9085          10 :                     n->remove = $6;
    9086          10 :                     $$ = (Node *)n;
    9087             :                 }
    9088             :             | ALTER MATERIALIZED VIEW qualified_name opt_no DEPENDS ON EXTENSION name
    9089             :                 {
    9090          10 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9091          10 :                     n->objectType = OBJECT_MATVIEW;
    9092          10 :                     n->relation = $4;
    9093          10 :                     n->extname = makeString($9);
    9094          10 :                     n->remove = $5;
    9095          10 :                     $$ = (Node *)n;
    9096             :                 }
    9097             :             | ALTER INDEX qualified_name opt_no DEPENDS ON EXTENSION name
    9098             :                 {
    9099          14 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9100          14 :                     n->objectType = OBJECT_INDEX;
    9101          14 :                     n->relation = $3;
    9102          14 :                     n->extname = makeString($8);
    9103          14 :                     n->remove = $4;
    9104          14 :                     $$ = (Node *)n;
    9105             :                 }
    9106             :         ;
    9107             : 
    9108           8 : opt_no:     NO              { $$ = true; }
    9109          38 :             | /* EMPTY */   { $$ = false;   }
    9110             :         ;
    9111             : 
    9112             : /*****************************************************************************
    9113             :  *
    9114             :  * ALTER THING name SET SCHEMA name
    9115             :  *
    9116             :  *****************************************************************************/
    9117             : 
    9118             : AlterObjectSchemaStmt:
    9119             :             ALTER AGGREGATE aggregate_with_argtypes SET SCHEMA name
    9120             :                 {
    9121          16 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9122          16 :                     n->objectType = OBJECT_AGGREGATE;
    9123          16 :                     n->object = (Node *) $3;
    9124          16 :                     n->newschema = $6;
    9125          16 :                     n->missing_ok = false;
    9126          16 :                     $$ = (Node *)n;
    9127             :                 }
    9128             :             | ALTER COLLATION any_name SET SCHEMA name
    9129             :                 {
    9130           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9131           0 :                     n->objectType = OBJECT_COLLATION;
    9132           0 :                     n->object = (Node *) $3;
    9133           0 :                     n->newschema = $6;
    9134           0 :                     n->missing_ok = false;
    9135           0 :                     $$ = (Node *)n;
    9136             :                 }
    9137             :             | ALTER CONVERSION_P any_name SET SCHEMA name
    9138             :                 {
    9139          16 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9140          16 :                     n->objectType = OBJECT_CONVERSION;
    9141          16 :                     n->object = (Node *) $3;
    9142          16 :                     n->newschema = $6;
    9143          16 :                     n->missing_ok = false;
    9144          16 :                     $$ = (Node *)n;
    9145             :                 }
    9146             :             | ALTER DOMAIN_P any_name SET SCHEMA name
    9147             :                 {
    9148           4 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9149           4 :                     n->objectType = OBJECT_DOMAIN;
    9150           4 :                     n->object = (Node *) $3;
    9151           4 :                     n->newschema = $6;
    9152           4 :                     n->missing_ok = false;
    9153           4 :                     $$ = (Node *)n;
    9154             :                 }
    9155             :             | ALTER EXTENSION name SET SCHEMA name
    9156             :                 {
    9157           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9158           0 :                     n->objectType = OBJECT_EXTENSION;
    9159           0 :                     n->object = (Node *) makeString($3);
    9160           0 :                     n->newschema = $6;
    9161           0 :                     n->missing_ok = false;
    9162           0 :                     $$ = (Node *)n;
    9163             :                 }
    9164             :             | ALTER FUNCTION function_with_argtypes SET SCHEMA name
    9165             :                 {
    9166          26 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9167          26 :                     n->objectType = OBJECT_FUNCTION;
    9168          26 :                     n->object = (Node *) $3;
    9169          26 :                     n->newschema = $6;
    9170          26 :                     n->missing_ok = false;
    9171          26 :                     $$ = (Node *)n;
    9172             :                 }
    9173             :             | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
    9174             :                 {
    9175          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9176          12 :                     n->objectType = OBJECT_OPERATOR;
    9177          12 :                     n->object = (Node *) $3;
    9178          12 :                     n->newschema = $6;
    9179          12 :                     n->missing_ok = false;
    9180          12 :                     $$ = (Node *)n;
    9181             :                 }
    9182             :             | ALTER OPERATOR CLASS any_name USING access_method SET SCHEMA name
    9183             :                 {
    9184          16 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9185          16 :                     n->objectType = OBJECT_OPCLASS;
    9186          16 :                     n->object = (Node *) lcons(makeString($6), $4);
    9187          16 :                     n->newschema = $9;
    9188          16 :                     n->missing_ok = false;
    9189          16 :                     $$ = (Node *)n;
    9190             :                 }
    9191             :             | ALTER OPERATOR FAMILY any_name USING access_method SET SCHEMA name
    9192             :                 {
    9193          16 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9194          16 :                     n->objectType = OBJECT_OPFAMILY;
    9195          16 :                     n->object = (Node *) lcons(makeString($6), $4);
    9196          16 :                     n->newschema = $9;
    9197          16 :                     n->missing_ok = false;
    9198          16 :                     $$ = (Node *)n;
    9199             :                 }
    9200             :             | ALTER PROCEDURE function_with_argtypes SET SCHEMA name
    9201             :                 {
    9202           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9203           0 :                     n->objectType = OBJECT_PROCEDURE;
    9204           0 :                     n->object = (Node *) $3;
    9205           0 :                     n->newschema = $6;
    9206           0 :                     n->missing_ok = false;
    9207           0 :                     $$ = (Node *)n;
    9208             :                 }
    9209             :             | ALTER ROUTINE function_with_argtypes SET SCHEMA name
    9210             :                 {
    9211           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9212           0 :                     n->objectType = OBJECT_ROUTINE;
    9213           0 :                     n->object = (Node *) $3;
    9214           0 :                     n->newschema = $6;
    9215           0 :                     n->missing_ok = false;
    9216           0 :                     $$ = (Node *)n;
    9217             :                 }
    9218             :             | ALTER TABLE relation_expr SET SCHEMA name
    9219             :                 {
    9220          40 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9221          40 :                     n->objectType = OBJECT_TABLE;
    9222          40 :                     n->relation = $3;
    9223          40 :                     n->newschema = $6;
    9224          40 :                     n->missing_ok = false;
    9225          40 :                     $$ = (Node *)n;
    9226             :                 }
    9227             :             | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
    9228             :                 {
    9229           8 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9230           8 :                     n->objectType = OBJECT_TABLE;
    9231           8 :                     n->relation = $5;
    9232           8 :                     n->newschema = $8;
    9233           8 :                     n->missing_ok = true;
    9234           8 :                     $$ = (Node *)n;
    9235             :                 }
    9236             :             | ALTER STATISTICS any_name SET SCHEMA name
    9237             :                 {
    9238          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9239          12 :                     n->objectType = OBJECT_STATISTIC_EXT;
    9240          12 :                     n->object = (Node *) $3;
    9241          12 :                     n->newschema = $6;
    9242          12 :                     n->missing_ok = false;
    9243          12 :                     $$ = (Node *)n;
    9244             :                 }
    9245             :             | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
    9246             :                 {
    9247          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9248          12 :                     n->objectType = OBJECT_TSPARSER;
    9249          12 :                     n->object = (Node *) $5;
    9250          12 :                     n->newschema = $8;
    9251          12 :                     n->missing_ok = false;
    9252          12 :                     $$ = (Node *)n;
    9253             :                 }
    9254             :             | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
    9255             :                 {
    9256          16 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9257          16 :                     n->objectType = OBJECT_TSDICTIONARY;
    9258          16 :                     n->object = (Node *) $5;
    9259          16 :                     n->newschema = $8;
    9260          16 :                     n->missing_ok = false;
    9261          16 :                     $$ = (Node *)n;
    9262             :                 }
    9263             :             | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
    9264             :                 {
    9265          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9266          12 :                     n->objectType = OBJECT_TSTEMPLATE;
    9267          12 :                     n->object = (Node *) $5;
    9268          12 :                     n->newschema = $8;
    9269          12 :                     n->missing_ok = false;
    9270          12 :                     $$ = (Node *)n;
    9271             :                 }
    9272             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
    9273             :                 {
    9274          16 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9275          16 :                     n->objectType = OBJECT_TSCONFIGURATION;
    9276          16 :                     n->object = (Node *) $5;
    9277          16 :                     n->newschema = $8;
    9278          16 :                     n->missing_ok = false;
    9279          16 :                     $$ = (Node *)n;
    9280             :                 }
    9281             :             | ALTER SEQUENCE qualified_name SET SCHEMA name
    9282             :                 {
    9283           2 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9284           2 :                     n->objectType = OBJECT_SEQUENCE;
    9285           2 :                     n->relation = $3;
    9286           2 :                     n->newschema = $6;
    9287           2 :                     n->missing_ok = false;
    9288           2 :                     $$ = (Node *)n;
    9289             :                 }
    9290             :             | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
    9291             :                 {
    9292           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9293           0 :                     n->objectType = OBJECT_SEQUENCE;
    9294           0 :                     n->relation = $5;
    9295           0 :                     n->newschema = $8;
    9296           0 :                     n->missing_ok = true;
    9297           0 :                     $$ = (Node *)n;
    9298             :                 }
    9299             :             | ALTER VIEW qualified_name SET SCHEMA name
    9300             :                 {
    9301           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9302           0 :                     n->objectType = OBJECT_VIEW;
    9303           0 :                     n->relation = $3;
    9304           0 :                     n->newschema = $6;
    9305           0 :                     n->missing_ok = false;
    9306           0 :                     $$ = (Node *)n;
    9307             :                 }
    9308             :             | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
    9309             :                 {
    9310           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9311           0 :                     n->objectType = OBJECT_VIEW;
    9312           0 :                     n->relation = $5;
    9313           0 :                     n->newschema = $8;
    9314           0 :                     n->missing_ok = true;
    9315           0 :                     $$ = (Node *)n;
    9316             :                 }
    9317             :             | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
    9318             :                 {
    9319           4 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9320           4 :                     n->objectType = OBJECT_MATVIEW;
    9321           4 :                     n->relation = $4;
    9322           4 :                     n->newschema = $7;
    9323           4 :                     n->missing_ok = false;
    9324           4 :                     $$ = (Node *)n;
    9325             :                 }
    9326             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
    9327             :                 {
    9328           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9329           0 :                     n->objectType = OBJECT_MATVIEW;
    9330           0 :                     n->relation = $6;
    9331           0 :                     n->newschema = $9;
    9332           0 :                     n->missing_ok = true;
    9333           0 :                     $$ = (Node *)n;
    9334             :                 }
    9335             :             | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
    9336             :                 {
    9337           4 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9338           4 :                     n->objectType = OBJECT_FOREIGN_TABLE;
    9339           4 :                     n->relation = $4;
    9340           4 :                     n->newschema = $7;
    9341           4 :                     n->missing_ok = false;
    9342           4 :                     $$ = (Node *)n;
    9343             :                 }
    9344             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
    9345             :                 {
    9346           4 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9347           4 :                     n->objectType = OBJECT_FOREIGN_TABLE;
    9348           4 :                     n->relation = $6;
    9349           4 :                     n->newschema = $9;
    9350           4 :                     n->missing_ok = true;
    9351           4 :                     $$ = (Node *)n;
    9352             :                 }
    9353             :             | ALTER TYPE_P any_name SET SCHEMA name
    9354             :                 {
    9355           8 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9356           8 :                     n->objectType = OBJECT_TYPE;
    9357           8 :                     n->object = (Node *) $3;
    9358           8 :                     n->newschema = $6;
    9359           8 :                     n->missing_ok = false;
    9360           8 :                     $$ = (Node *)n;
    9361             :                 }
    9362             :         ;
    9363             : 
    9364             : /*****************************************************************************
    9365             :  *
    9366             :  * ALTER OPERATOR name SET define
    9367             :  *
    9368             :  *****************************************************************************/
    9369             : 
    9370             : AlterOperatorStmt:
    9371             :             ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
    9372             :                 {
    9373         484 :                     AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
    9374         484 :                     n->opername = $3;
    9375         484 :                     n->options = $6;
    9376         484 :                     $$ = (Node *)n;
    9377             :                 }
    9378             :         ;
    9379             : 
    9380         512 : operator_def_list:  operator_def_elem                               { $$ = list_make1($1); }
    9381         468 :             | operator_def_list ',' operator_def_elem               { $$ = lappend($1, $3); }
    9382             :         ;
    9383             : 
    9384             : operator_def_elem: ColLabel '=' NONE
    9385          20 :                         { $$ = makeDefElem($1, NULL, @1); }
    9386             :                    | ColLabel '=' operator_def_arg
    9387         960 :                         { $$ = makeDefElem($1, (Node *) $3, @1); }
    9388             :         ;
    9389             : 
    9390             : /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
    9391             : operator_def_arg:
    9392         944 :             func_type                       { $$ = (Node *)$1; }
    9393           0 :             | reserved_keyword              { $$ = (Node *)makeString(pstrdup($1)); }
    9394          16 :             | qual_all_Op                   { $$ = (Node *)$1; }
    9395           0 :             | NumericOnly                   { $$ = (Node *)$1; }
    9396           0 :             | Sconst                        { $$ = (Node *)makeString($1); }
    9397             :         ;
    9398             : 
    9399             : /*****************************************************************************
    9400             :  *
    9401             :  * ALTER TYPE name SET define
    9402             :  *
    9403             :  * We repurpose ALTER OPERATOR's version of "definition" here
    9404             :  *
    9405             :  *****************************************************************************/
    9406             : 
    9407             : AlterTypeStmt:
    9408             :             ALTER TYPE_P any_name SET '(' operator_def_list ')'
    9409             :                 {
    9410          28 :                     AlterTypeStmt *n = makeNode(AlterTypeStmt);
    9411          28 :                     n->typeName = $3;
    9412          28 :                     n->options = $6;
    9413          28 :                     $$ = (Node *)n;
    9414             :                 }
    9415             :         ;
    9416             : 
    9417             : /*****************************************************************************
    9418             :  *
    9419             :  * ALTER THING name OWNER TO newname
    9420             :  *
    9421             :  *****************************************************************************/
    9422             : 
    9423             : AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec
    9424             :                 {
    9425         130 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
    9426         130 :                     n->objectType = OBJECT_AGGREGATE;
    9427         130 :                     n->object = (Node *) $3;
    9428         130 :                     n->newowner = $6;
    9429         130 :                     $$ = (Node *)n;
    9430             :                 }
    9431             :             | ALTER COLLATION any_name OWNER TO RoleSpec
    9432             :                 {
    9433           0 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
    9434           0 :                     n->objectType = OBJECT_COLLATION;
    9435           0 :                     n->object = (Node *) $3;
    9436           0 :                     n->newowner = $6;
    9437           0 :                     $$ = (Node *)n;
    9438             :                 }
    9439             :             | ALTER CONVERSION_P any_name OWNER TO RoleSpec
    9440             :                 {
    9441          16 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
    9442          16 :                     n->objectType = OBJECT_CONVERSION;
    9443          16 :                     n->object = (Node *) $3;
    9444          16 :                     n->newowner = $6;
    9445          16 :                     $$ = (Node *)n;
    9446             :                 }
    9447             :             | ALTER DATABASE database_name OWNER TO RoleSpec
    9448             :                 {
    9449          30 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
    9450          30 :                     n->objectType = OBJECT_DATABASE;
    9451          30 :                     n->object = (Node *) makeString($3);
    9452          30 :                     n->newowner = $6;
    9453          30 :                     $$ = (Node *)n;
    9454             :                 }
    9455             :             | ALTER DOMAIN_P any_name OWNER TO RoleSpec
    9456             :                 {
    9457          32 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
    9458          32 :                     n->objectType = OBJECT_DOMAIN;
    9459          32 :                     n->object = (Node *) $3;
    9460          32 :                     n->newowner = $6;
    9461          32 :                     $$ = (Node *)n;
    9462             :                 }
    9463             :             | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
    9464             :                 {
    9465         488 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
    9466         488 :                     n->objectType = OBJECT_FUNCTION;
    9467         488 :                     n->object = (Node *) $3;
    9468         488 :                     n->newowner = $6;
    9469         488 :                     $$ = (Node *)n;
    9470             :                 }
    9471             :             | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
    9472             :                 {
    9473         392 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
    9474         392 :                     n->objectType = OBJECT_LANGUAGE;
    9475         392 :                     n->object = (Node *) makeString($4);
    9476         392 :                     n->newowner = $7;
    9477         392 :                     $$ = (Node *)n;
    9478             :                 }
    9479             :             | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
    9480             :                 {
    9481          10 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
    9482          10 :                     n->objectType = OBJECT_LARGEOBJECT;
    9483          10 :                     n->object = (Node *) $4;
    9484          10 :                     n->newowner = $7;
    9485          10 :                     $$ = (Node *)n;
    9486             :                 }
    9487             :             | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
    9488             :                 {
    9489          42 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
    9490          42 :                     n->objectType = OBJECT_OPERATOR;
    9491          42 :                     n->object = (Node *) $3;
    9492          42 :                     n->newowner = $6;
    9493          42 :                     $$ = (Node *)n;
    9494             :                 }
    9495             :             | ALTER OPERATOR CLASS any_name USING access_method OWNER TO RoleSpec
    9496             :                 {
    9497          36 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
    9498          36 :                     n->objectType = OBJECT_OPCLASS;
    9499          36 :                     n->object = (Node *) lcons(makeString($6), $4);
    9500          36 :                     n->newowner = $9;
    9501          36 :                     $$ = (Node *)n;
    9502             :                 }
    9503             :             | ALTER OPERATOR FAMILY any_name USING access_method OWNER TO RoleSpec
    9504             :                 {
    9505          42 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
    9506          42 :                     n->objectType = OBJECT_OPFAMILY;
    9507          42 :                     n->object = (Node *) lcons(makeString($6), $4);
    9508          42 :                     n->newowner = $9;
    9509          42 :                     $$ = (Node *)n;
    9510             :                 }
    9511             :             | ALTER PROCEDURE function_with_argtypes OWNER TO RoleSpec
    9512             :                 {
    9513           8 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
    9514           8 :                     n->objectType = OBJECT_PROCEDURE;
    9515           8 :                     n->object = (Node *) $3;
    9516           8 :                     n->newowner = $6;
    9517           8 :                     $$ = (Node *)n;
    9518             :                 }
    9519             :             | ALTER ROUTINE function_with_argtypes OWNER TO RoleSpec
    9520             :                 {
    9521           0 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
    9522           0 :                     n->objectType = OBJECT_ROUTINE;
    9523           0 :                     n->object = (Node *) $3;
    9524           0 :                     n->newowner = $6;
    9525           0 :                     $$ = (Node *)n;
    9526             :                 }
    9527             :             | ALTER SCHEMA name OWNER TO RoleSpec
    9528             :                 {
    9529          26 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
    9530          26 :                     n->objectType = OBJECT_SCHEMA;
    9531          26 :                     n->object = (Node *) makeString($3);
    9532          26 :                     n->newowner = $6;
    9533          26 :                     $$ = (Node *)n;
    9534             :                 }
    9535             :             | ALTER TYPE_P any_name OWNER TO RoleSpec
    9536             :                 {
    9537          60 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
    9538          60 :                     n->objectType = OBJECT_TYPE;
    9539          60 :                     n->object = (Node *) $3;
    9540          60 :                     n->newowner = $6;
    9541          60 :                     $$ = (Node *)n;
    9542             :                 }
    9543             :             | ALTER TABLESPACE name OWNER TO RoleSpec
    9544             :                 {
    9545           4 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
    9546           4 :                     n->objectType = OBJECT_TABLESPACE;
    9547           4 :                     n->object = (Node *) makeString($3);
    9548           4 :                     n->newowner = $6;
    9549           4 :                     $$ = (Node *)n;
    9550             :                 }
    9551             :             | ALTER STATISTICS any_name OWNER TO RoleSpec
    9552             :                 {
    9553          24 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
    9554          24 :                     n->objectType = OBJECT_STATISTIC_EXT;
    9555          24 :                     n->object = (Node *) $3;
    9556          24 :                     n->newowner = $6;
    9557          24 :                     $$ = (Node *)n;
    9558             :                 }
    9559             :             | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
    9560             :                 {
    9561          34 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
    9562          34 :                     n->objectType = OBJECT_TSDICTIONARY;
    9563          34 :                     n->object = (Node *) $5;
    9564          34 :                     n->newowner = $8;
    9565          34 :                     $$ = (Node *)n;
    9566             :                 }
    9567             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
    9568             :                 {
    9569          24 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
    9570          24 :                     n->objectType = OBJECT_TSCONFIGURATION;
    9571          24 :                     n->object = (Node *) $5;
    9572          24 :                     n->newowner = $8;
    9573          24 :                     $$ = (Node *)n;
    9574             :                 }
    9575             :             | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
    9576             :                 {
    9577          14 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
    9578          14 :                     n->objectType = OBJECT_FDW;
    9579          14 :                     n->object = (Node *) makeString($5);
    9580          14 :                     n->newowner = $8;
    9581          14 :                     $$ = (Node *)n;
    9582             :                 }
    9583             :             | ALTER SERVER name OWNER TO RoleSpec
    9584             :                 {
    9585          46 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
    9586          46 :                     n->objectType = OBJECT_FOREIGN_SERVER;
    9587          46 :                     n->object = (Node *) makeString($3);
    9588          46 :                     n->newowner = $6;
    9589          46 :                     $$ = (Node *)n;
    9590             :                 }
    9591             :             | ALTER EVENT TRIGGER name OWNER TO RoleSpec
    9592             :                 {
    9593           8 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
    9594           8 :                     n->objectType = OBJECT_EVENT_TRIGGER;
    9595           8 :                     n->object = (Node *) makeString($4);
    9596           8 :                     n->newowner = $7;
    9597           8 :                     $$ = (Node *)n;
    9598             :                 }
    9599             :             | ALTER PUBLICATION name OWNER TO RoleSpec
    9600             :                 {
    9601           4 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
    9602           4 :                     n->objectType = OBJECT_PUBLICATION;
    9603           4 :                     n->object = (Node *) makeString($3);
    9604           4 :                     n->newowner = $6;
    9605           4 :                     $$ = (Node *)n;
    9606             :                 }
    9607             :             | ALTER SUBSCRIPTION name OWNER TO RoleSpec
    9608             :                 {
    9609           8 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
    9610           8 :                     n->objectType = OBJECT_SUBSCRIPTION;
    9611           8 :                     n->object = (Node *) makeString($3);
    9612           8 :                     n->newowner = $6;
    9613           8 :                     $$ = (Node *)n;
    9614             :                 }
    9615             :         ;
    9616             : 
    9617             : 
    9618             : /*****************************************************************************
    9619             :  *
    9620             :  * CREATE PUBLICATION name [ FOR TABLE ] [ WITH options ]
    9621             :  *
    9622             :  *****************************************************************************/
    9623             : 
    9624             : CreatePublicationStmt:
    9625             :             CREATE PUBLICATION name opt_publication_for_tables opt_definition
    9626             :                 {
    9627         108 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
    9628         108 :                     n->pubname = $3;
    9629         108 :                     n->options = $5;
    9630         108 :                     if ($4 != NULL)
    9631             :                     {
    9632             :                         /* FOR TABLE */
    9633          62 :                         if (IsA($4, List))
    9634          32 :                             n->tables = (List *)$4;
    9635             :                         /* FOR ALL TABLES */
    9636             :                         else
    9637          30 :                             n->for_all_tables = true;
    9638             :                     }
    9639         108 :                     $$ = (Node *)n;
    9640             :                 }
    9641             :         ;
    9642             : 
    9643             : opt_publication_for_tables:
    9644          62 :             publication_for_tables                  { $$ = $1; }
    9645          46 :             | /* EMPTY */                           { $$ = NULL; }
    9646             :         ;
    9647             : 
    9648             : publication_for_tables:
    9649             :             FOR TABLE relation_expr_list
    9650             :                 {
    9651          32 :                     $$ = (Node *) $3;
    9652             :                 }
    9653             :             | FOR ALL TABLES
    9654             :                 {
    9655          30 :                     $$ = (Node *) makeInteger(true);
    9656             :                 }
    9657             :         ;
    9658             : 
    9659             : 
    9660             : /*****************************************************************************
    9661             :  *
    9662             :  * ALTER PUBLICATION name SET ( options )
    9663             :  *
    9664             :  * ALTER PUBLICATION name ADD TABLE table [, table2]
    9665             :  *
    9666             :  * ALTER PUBLICATION name DROP TABLE table [, table2]
    9667             :  *
    9668             :  * ALTER PUBLICATION name SET TABLE table [, table2]
    9669             :  *
    9670             :  *****************************************************************************/
    9671             : 
    9672             : AlterPublicationStmt:
    9673             :             ALTER PUBLICATION name SET definition
    9674             :                 {
    9675          26 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
    9676          26 :                     n->pubname = $3;
    9677          26 :                     n->options = $5;
    9678          26 :                     $$ = (Node *)n;
    9679             :                 }
    9680             :             | ALTER PUBLICATION name ADD_P TABLE relation_expr_list
    9681             :                 {
    9682          48 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
    9683          48 :                     n->pubname = $3;
    9684          48 :                     n->tables = $6;
    9685          48 :                     n->tableAction = DEFELEM_ADD;
    9686          48 :                     $$ = (Node *)n;
    9687             :                 }
    9688             :             | ALTER PUBLICATION name SET TABLE relation_expr_list
    9689             :                 {
    9690           8 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
    9691           8 :                     n->pubname = $3;
    9692           8 :                     n->tables = $6;
    9693           8 :                     n->tableAction = DEFELEM_SET;
    9694           8 :                     $$ = (Node *)n;
    9695             :                 }
    9696             :             | ALTER PUBLICATION name DROP TABLE relation_expr_list
    9697             :                 {
    9698          12 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
    9699          12 :                     n->pubname = $3;
    9700          12 :                     n->tables = $6;
    9701          12 :                     n->tableAction = DEFELEM_DROP;
    9702          12 :                     $$ = (Node *)n;
    9703             :                 }
    9704             :         ;
    9705             : 
    9706             : /*****************************************************************************
    9707             :  *
    9708             :  * CREATE SUBSCRIPTION name ...
    9709             :  *
    9710             :  *****************************************************************************/
    9711             : 
    9712             : CreateSubscriptionStmt:
    9713             :             CREATE SUBSCRIPTION name CONNECTION Sconst PUBLICATION publication_name_list opt_definition
    9714             :                 {
    9715         108 :                     CreateSubscriptionStmt *n =
    9716         108 :                         makeNode(CreateSubscriptionStmt);
    9717         108 :                     n->subname = $3;
    9718         108 :                     n->conninfo = $5;
    9719         108 :                     n->publication = $7;
    9720         108 :                     n->options = $8;
    9721         108 :                     $$ = (Node *)n;
    9722             :                 }
    9723             :         ;
    9724             : 
    9725             : publication_name_list:
    9726             :             publication_name_item
    9727             :                 {
    9728         114 :                     $$ = list_make1($1);
    9729             :                 }
    9730             :             | publication_name_list ',' publication_name_item
    9731             :                 {
    9732          14 :                     $$ = lappend($1, $3);
    9733             :                 }
    9734             :         ;
    9735             : 
    9736             : publication_name_item:
    9737         128 :             ColLabel            { $$ = makeString($1); };
    9738             : 
    9739             : /*****************************************************************************
    9740             :  *
    9741             :  * ALTER SUBSCRIPTION name ...
    9742             :  *
    9743             :  *****************************************************************************/
    9744             : 
    9745             : AlterSubscriptionStmt:
    9746             :             ALTER SUBSCRIPTION name SET definition
    9747             :                 {
    9748          22 :                     AlterSubscriptionStmt *n =
    9749          22 :                         makeNode(AlterSubscriptionStmt);
    9750          22 :                     n->kind = ALTER_SUBSCRIPTION_OPTIONS;
    9751          22 :                     n->subname = $3;
    9752          22 :                     n->options = $5;
    9753          22 :                     $$ = (Node *)n;
    9754             :                 }
    9755             :             | ALTER SUBSCRIPTION name CONNECTION Sconst
    9756             :                 {
    9757          14 :                     AlterSubscriptionStmt *n =
    9758          14 :                         makeNode(AlterSubscriptionStmt);
    9759          14 :                     n->kind = ALTER_SUBSCRIPTION_CONNECTION;
    9760          14 :                     n->subname = $3;
    9761          14 :                     n->conninfo = $5;
    9762          14 :                     $$ = (Node *)n;
    9763             :                 }
    9764             :             | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
    9765             :                 {
    9766          12 :                     AlterSubscriptionStmt *n =
    9767          12 :                         makeNode(AlterSubscriptionStmt);
    9768          12 :                     n->kind = ALTER_SUBSCRIPTION_REFRESH;
    9769          12 :                     n->subname = $3;
    9770          12 :                     n->options = $6;
    9771          12 :                     $$ = (Node *)n;
    9772             :                 }
    9773             :             | ALTER SUBSCRIPTION name SET PUBLICATION publication_name_list opt_definition
    9774             :                 {
    9775           6 :                     AlterSubscriptionStmt *n =
    9776           6 :                         makeNode(AlterSubscriptionStmt);
    9777           6 :                     n->kind = ALTER_SUBSCRIPTION_PUBLICATION;
    9778           6 :                     n->subname = $3;
    9779           6 :                     n->publication = $6;
    9780           6 :                     n->options = $7;
    9781           6 :                     $$ = (Node *)n;
    9782             :                 }
    9783             :             | ALTER SUBSCRIPTION name ENABLE_P
    9784             :                 {
    9785           8 :                     AlterSubscriptionStmt *n =
    9786           8 :                         makeNode(AlterSubscriptionStmt);
    9787           8 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
    9788           8 :                     n->subname = $3;
    9789           8 :                     n->options = list_make1(makeDefElem("enabled",
    9790             :                                             (Node *)makeInteger(true), @1));
    9791           8 :                     $$ = (Node *)n;
    9792             :                 }
    9793             :             | ALTER SUBSCRIPTION name DISABLE_P
    9794             :                 {
    9795           6 :                     AlterSubscriptionStmt *n =
    9796           6 :                         makeNode(AlterSubscriptionStmt);
    9797           6 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
    9798           6 :                     n->subname = $3;
    9799           6 :                     n->options = list_make1(makeDefElem("enabled",
    9800             :                                             (Node *)makeInteger(false), @1));
    9801           6 :                     $$ = (Node *)n;
    9802             :                 }
    9803             :         ;
    9804             : 
    9805             : /*****************************************************************************
    9806             :  *
    9807             :  * DROP SUBSCRIPTION [ IF EXISTS ] name
    9808             :  *
    9809             :  *****************************************************************************/
    9810             : 
    9811             : DropSubscriptionStmt: DROP SUBSCRIPTION name opt_drop_behavior
    9812             :                 {
    9813          38 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
    9814          38 :                     n->subname = $3;
    9815          38 :                     n->missing_ok = false;
    9816          38 :                     n->behavior = $4;
    9817          38 :                     $$ = (Node *) n;
    9818             :                 }
    9819             :                 |  DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
    9820             :                 {
    9821           4 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
    9822           4 :                     n->subname = $5;
    9823           4 :                     n->missing_ok = true;
    9824           4 :                     n->behavior = $6;
    9825           4 :                     $$ = (Node *) n;
    9826             :                 }
    9827             :         ;
    9828             : 
    9829             : /*****************************************************************************
    9830             :  *
    9831             :  *      QUERY:  Define Rewrite Rule
    9832             :  *
    9833             :  *****************************************************************************/
    9834             : 
    9835             : RuleStmt:   CREATE opt_or_replace RULE name AS
    9836             :             ON event TO qualified_name where_clause
    9837             :             DO opt_instead RuleActionList
    9838             :                 {
    9839        1228 :                     RuleStmt *n = makeNode(RuleStmt);
    9840        1228 :                     n->replace = $2;
    9841        1228 :                     n->relation = $9;
    9842        1228 :                     n->rulename = $4;
    9843        1228 :                     n->whereClause = $10;
    9844        1228 :                     n->event = $7;
    9845        1228 :                     n->instead = $12;
    9846        1228 :                     n->actions = $13;
    9847        1228 :                     $$ = (Node *)n;
    9848             :                 }
    9849             :         ;
    9850             : 
    9851             : RuleActionList:
    9852         404 :             NOTHING                                 { $$ = NIL; }
    9853         796 :             | RuleActionStmt                        { $$ = list_make1($1); }
    9854          28 :             | '(' RuleActionMulti ')'               { $$ = $2; }
    9855             :         ;
    9856             : 
    9857             : /* the thrashing around here is to discard "empty" statements... */
    9858             : RuleActionMulti:
    9859             :             RuleActionMulti ';' RuleActionStmtOrEmpty
    9860          40 :                 { if ($3 != NULL)
    9861          28 :                     $$ = lappend($1, $3);
    9862             :                   else
    9863          12 :                     $$ = $1;
    9864             :                 }
    9865             :             | RuleActionStmtOrEmpty
    9866          28 :                 { if ($1 != NULL)
    9867          28 :                     $$ = list_make1($1);
    9868             :                   else
    9869           0 :                     $$ = NIL;
    9870             :                 }
    9871             :         ;
    9872             : 
    9873             : RuleActionStmt:
    9874             :             SelectStmt
    9875             :             | InsertStmt
    9876             :             | UpdateStmt
    9877             :             | DeleteStmt
    9878             :             | NotifyStmt
    9879             :         ;
    9880             : 
    9881             : RuleActionStmtOrEmpty:
    9882          56 :             RuleActionStmt                          { $$ = $1; }
    9883          12 :             |   /*EMPTY*/                           { $$ = NULL; }
    9884             :         ;
    9885             : 
    9886          26 : event:      SELECT                                  { $$ = CMD_SELECT; }
    9887         840 :             | UPDATE                                { $$ = CMD_UPDATE; }
    9888          96 :             | DELETE_P                              { $$ = CMD_DELETE; }
    9889         266 :             | INSERT                                { $$ = CMD_INSERT; }
    9890             :          ;
    9891             : 
    9892             : opt_instead:
    9893         742 :             INSTEAD                                 { $$ = true; }
    9894          60 :             | ALSO                                  { $$ = false; }
    9895         426 :             | /*EMPTY*/                             { $$ = false; }
    9896             :         ;
    9897             : 
    9898             : 
    9899             : /*****************************************************************************
    9900             :  *
    9901             :  *      QUERY:
    9902             :  *              NOTIFY <identifier> can appear both in rule bodies and
    9903             :  *              as a query-level command
    9904             :  *
    9905             :  *****************************************************************************/
    9906             : 
    9907             : NotifyStmt: NOTIFY ColId notify_payload
    9908             :                 {
    9909          88 :                     NotifyStmt *n = makeNode(NotifyStmt);
    9910          88 :                     n->conditionname = $2;
    9911          88 :                     n->payload = $3;
    9912          88 :                     $$ = (Node *)n;
    9913             :                 }
    9914             :         ;
    9915             : 
    9916             : notify_payload:
    9917          60 :             ',' Sconst                          { $$ = $2; }
    9918          28 :             | /*EMPTY*/                         { $$ = NULL; }
    9919             :         ;
    9920             : 
    9921             : ListenStmt: LISTEN ColId
    9922             :                 {
    9923          42 :                     ListenStmt *n = makeNode(ListenStmt);
    9924          42 :                     n->conditionname = $2;
    9925          42 :                     $$ = (Node *)n;
    9926             :                 }
    9927             :         ;
    9928             : 
    9929             : UnlistenStmt:
    9930             :             UNLISTEN ColId
    9931             :                 {
    9932           4 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
    9933           4 :                     n->conditionname = $2;
    9934           4 :                     $$ = (Node *)n;
    9935             :                 }
    9936             :             | UNLISTEN '*'
    9937             :                 {
    9938          30 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
    9939          30 :                     n->conditionname = NULL;
    9940          30 :                     $$ = (Node *)n;
    9941             :                 }
    9942             :         ;
    9943             : 
    9944             : 
    9945             : /*****************************************************************************
    9946             :  *
    9947             :  *      Transactions:
    9948             :  *
    9949             :  *      BEGIN / COMMIT / ROLLBACK
    9950             :  *      (also older versions END / ABORT)
    9951             :  *
    9952             :  *****************************************************************************/
    9953             : 
    9954             : TransactionStmt:
    9955             :             ABORT_P opt_transaction opt_transaction_chain
    9956             :                 {
    9957         110 :                     TransactionStmt *n = makeNode(TransactionStmt);
    9958         110 :                     n->kind = TRANS_STMT_ROLLBACK;
    9959         110 :                     n->options = NIL;
    9960         110 :                     n->chain = $3;
    9961         110 :                     $$ = (Node *)n;
    9962             :                 }
    9963             :             | BEGIN_P opt_transaction transaction_mode_list_or_empty
    9964             :                 {
    9965        8970 :                     TransactionStmt *n = makeNode(TransactionStmt);
    9966        8970 :                     n->kind = TRANS_STMT_BEGIN;
    9967        8970 :                     n->options = $3;
    9968        8970 :                     $$ = (Node *)n;
    9969             :                 }
    9970             :             | START TRANSACTION transaction_mode_list_or_empty
    9971             :                 {
    9972         996 :                     TransactionStmt *n = makeNode(TransactionStmt);
    9973         996 :                     n->kind = TRANS_STMT_START;
    9974         996 :                     n->options = $3;
    9975         996 :                     $$ = (Node *)n;
    9976             :                 }
    9977             :             | COMMIT opt_transaction opt_transaction_chain
    9978             :                 {
    9979        8262 :                     TransactionStmt *n = makeNode(TransactionStmt);
    9980        8262 :                     n->kind = TRANS_STMT_COMMIT;
    9981        8262 :