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