LCOV - code coverage report
Current view: top level - src/backend/parser - gram.y (source / functions) Hit Total Coverage
Test: PostgreSQL 15devel Lines: 5999 6825 87.9 %
Date: 2021-12-04 22:09:09 Functions: 41 41 100.0 %
Legend: Lines: hit not hit

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