LCOV - code coverage report
Current view: top level - src/backend/parser - gram.y (source / functions) Hit Total Coverage
Test: PostgreSQL 17devel Lines: 6641 7376 90.0 %
Date: 2024-05-09 07:11:19 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-2024, 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 "gramparse.h"
      59             : #include "nodes/makefuncs.h"
      60             : #include "nodes/nodeFuncs.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.
     107             :  */
     108             : #define YYMALLOC palloc
     109             : #define YYFREE   pfree
     110             : 
     111             : /* Private struct for the result of privilege_target production */
     112             : typedef struct PrivTarget
     113             : {
     114             :     GrantTargetType targtype;
     115             :     ObjectType  objtype;
     116             :     List       *objs;
     117             : } PrivTarget;
     118             : 
     119             : /* Private struct for the result of import_qualification production */
     120             : typedef struct ImportQual
     121             : {
     122             :     ImportForeignSchemaType type;
     123             :     List       *table_names;
     124             : } ImportQual;
     125             : 
     126             : /* Private struct for the result of opt_select_limit production */
     127             : typedef struct SelectLimit
     128             : {
     129             :     Node       *limitOffset;
     130             :     Node       *limitCount;
     131             :     LimitOption limitOption;
     132             : } SelectLimit;
     133             : 
     134             : /* Private struct for the result of group_clause production */
     135             : typedef struct GroupClause
     136             : {
     137             :     bool        distinct;
     138             :     List       *list;
     139             : } GroupClause;
     140             : 
     141             : /* Private structs for the result of key_actions and key_action productions */
     142             : typedef struct KeyAction
     143             : {
     144             :     char        action;
     145             :     List       *cols;
     146             : } KeyAction;
     147             : 
     148             : typedef struct KeyActions
     149             : {
     150             :     KeyAction *updateAction;
     151             :     KeyAction *deleteAction;
     152             : } KeyActions;
     153             : 
     154             : /* ConstraintAttributeSpec yields an integer bitmask of these flags: */
     155             : #define CAS_NOT_DEFERRABLE          0x01
     156             : #define CAS_DEFERRABLE              0x02
     157             : #define CAS_INITIALLY_IMMEDIATE     0x04
     158             : #define CAS_INITIALLY_DEFERRED      0x08
     159             : #define CAS_NOT_VALID               0x10
     160             : #define CAS_NO_INHERIT              0x20
     161             : 
     162             : 
     163             : #define parser_yyerror(msg)  scanner_yyerror(msg, yyscanner)
     164             : #define parser_errposition(pos)  scanner_errposition(pos, yyscanner)
     165             : 
     166             : static void base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner,
     167             :                          const char *msg);
     168             : static RawStmt *makeRawStmt(Node *stmt, int stmt_location);
     169             : static void updateRawStmtEnd(RawStmt *rs, int end_location);
     170             : static Node *makeColumnRef(char *colname, List *indirection,
     171             :                            int location, core_yyscan_t yyscanner);
     172             : static Node *makeTypeCast(Node *arg, TypeName *typename, int location);
     173             : static Node *makeStringConstCast(char *str, int location, TypeName *typename);
     174             : static Node *makeIntConst(int val, int location);
     175             : static Node *makeFloatConst(char *str, int location);
     176             : static Node *makeBoolAConst(bool state, int location);
     177             : static Node *makeBitStringConst(char *str, int location);
     178             : static Node *makeNullAConst(int location);
     179             : static Node *makeAConst(Node *v, int location);
     180             : static RoleSpec *makeRoleSpec(RoleSpecType type, int location);
     181             : static void check_qualified_name(List *names, core_yyscan_t yyscanner);
     182             : static List *check_func_name(List *names, core_yyscan_t yyscanner);
     183             : static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
     184             : static List *extractArgTypes(List *parameters);
     185             : static List *extractAggrArgTypes(List *aggrargs);
     186             : static List *makeOrderedSetArgs(List *directargs, List *orderedargs,
     187             :                                 core_yyscan_t yyscanner);
     188             : static void insertSelectOptions(SelectStmt *stmt,
     189             :                                 List *sortClause, List *lockingClause,
     190             :                                 SelectLimit *limitClause,
     191             :                                 WithClause *withClause,
     192             :                                 core_yyscan_t yyscanner);
     193             : static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
     194             : static Node *doNegate(Node *n, int location);
     195             : static void doNegateFloat(Float *v);
     196             : static Node *makeAndExpr(Node *lexpr, Node *rexpr, int location);
     197             : static Node *makeOrExpr(Node *lexpr, Node *rexpr, int location);
     198             : static Node *makeNotExpr(Node *expr, int location);
     199             : static Node *makeAArrayExpr(List *elements, int location);
     200             : static Node *makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod,
     201             :                                   int location);
     202             : static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
     203             :                          List *args, int location);
     204             : static List *mergeTableFuncParameters(List *func_args, List *columns);
     205             : static TypeName *TableFuncTypeName(List *columns);
     206             : static RangeVar *makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner);
     207             : static RangeVar *makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
     208             :                                                core_yyscan_t yyscanner);
     209             : static void SplitColQualList(List *qualList,
     210             :                              List **constraintList, CollateClause **collClause,
     211             :                              core_yyscan_t yyscanner);
     212             : static void processCASbits(int cas_bits, int location, const char *constrType,
     213             :                bool *deferrable, bool *initdeferred, bool *not_valid,
     214             :                bool *no_inherit, core_yyscan_t yyscanner);
     215             : static PartitionStrategy parsePartitionStrategy(char *strategy);
     216             : static void preprocess_pubobj_list(List *pubobjspec_list,
     217             :                                    core_yyscan_t yyscanner);
     218             : static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
     219             : 
     220             : %}
     221             : 
     222             : %pure-parser
     223             : %expect 0
     224             : %name-prefix="base_yy"
     225             : %locations
     226             : 
     227             : %parse-param {core_yyscan_t yyscanner}
     228             : %lex-param   {core_yyscan_t yyscanner}
     229             : 
     230             : %union
     231             : {
     232             :     core_YYSTYPE core_yystype;
     233             :     /* these fields must match core_YYSTYPE: */
     234             :     int         ival;
     235             :     char       *str;
     236             :     const char *keyword;
     237             : 
     238             :     char        chr;
     239             :     bool        boolean;
     240             :     JoinType    jtype;
     241             :     DropBehavior dbehavior;
     242             :     OnCommitAction oncommit;
     243             :     List       *list;
     244             :     Node       *node;
     245             :     ObjectType  objtype;
     246             :     TypeName   *typnam;
     247             :     FunctionParameter *fun_param;
     248             :     FunctionParameterMode fun_param_mode;
     249             :     ObjectWithArgs *objwithargs;
     250             :     DefElem    *defelt;
     251             :     SortBy     *sortby;
     252             :     WindowDef  *windef;
     253             :     JoinExpr   *jexpr;
     254             :     IndexElem  *ielem;
     255             :     StatsElem  *selem;
     256             :     Alias      *alias;
     257             :     RangeVar   *range;
     258             :     IntoClause *into;
     259             :     WithClause *with;
     260             :     InferClause *infer;
     261             :     OnConflictClause *onconflict;
     262             :     A_Indices  *aind;
     263             :     ResTarget  *target;
     264             :     struct PrivTarget *privtarget;
     265             :     AccessPriv *accesspriv;
     266             :     struct ImportQual *importqual;
     267             :     InsertStmt *istmt;
     268             :     VariableSetStmt *vsetstmt;
     269             :     PartitionElem *partelem;
     270             :     PartitionSpec *partspec;
     271             :     PartitionBoundSpec *partboundspec;
     272             :     SinglePartitionSpec *singlepartspec;
     273             :     RoleSpec   *rolespec;
     274             :     PublicationObjSpec *publicationobjectspec;
     275             :     struct SelectLimit *selectlimit;
     276             :     SetQuantifier setquantifier;
     277             :     struct GroupClause *groupclause;
     278             :     MergeMatchKind mergematch;
     279             :     MergeWhenClause *mergewhen;
     280             :     struct KeyActions *keyactions;
     281             :     struct KeyAction *keyaction;
     282             : }
     283             : 
     284             : %type <node>  stmt toplevel_stmt schema_stmt routine_body_stmt
     285             :         AlterEventTrigStmt AlterCollationStmt
     286             :         AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt
     287             :         AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
     288             :         AlterObjectDependsStmt AlterObjectSchemaStmt AlterOwnerStmt
     289             :         AlterOperatorStmt AlterTypeStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
     290             :         AlterTblSpcStmt AlterExtensionStmt AlterExtensionContentsStmt
     291             :         AlterCompositeTypeStmt AlterUserMappingStmt
     292             :         AlterRoleStmt AlterRoleSetStmt AlterPolicyStmt AlterStatsStmt
     293             :         AlterDefaultPrivilegesStmt DefACLAction
     294             :         AnalyzeStmt CallStmt ClosePortalStmt ClusterStmt CommentStmt
     295             :         ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
     296             :         CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt
     297             :         CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
     298             :         CreateSchemaStmt CreateSeqStmt CreateStmt CreateStatsStmt CreateTableSpaceStmt
     299             :         CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt
     300             :         CreateAssertionStmt CreateTransformStmt CreateTrigStmt CreateEventTrigStmt
     301             :         CreateUserStmt CreateUserMappingStmt CreateRoleStmt CreatePolicyStmt
     302             :         CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
     303             :         DropOpClassStmt DropOpFamilyStmt DropStmt
     304             :         DropCastStmt DropRoleStmt
     305             :         DropdbStmt DropTableSpaceStmt
     306             :         DropTransformStmt
     307             :         DropUserMappingStmt ExplainStmt FetchStmt
     308             :         GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
     309             :         ListenStmt LoadStmt LockStmt MergeStmt NotifyStmt ExplainableStmt PreparableStmt
     310             :         CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
     311             :         RemoveFuncStmt RemoveOperStmt RenameStmt ReturnStmt RevokeStmt RevokeRoleStmt
     312             :         RuleActionStmt RuleActionStmtOrEmpty RuleStmt
     313             :         SecLabelStmt SelectStmt TransactionStmt TransactionStmtLegacy TruncateStmt
     314             :         UnlistenStmt UpdateStmt VacuumStmt
     315             :         VariableResetStmt VariableSetStmt VariableShowStmt
     316             :         ViewStmt CheckPointStmt CreateConversionStmt
     317             :         DeallocateStmt PrepareStmt ExecuteStmt
     318             :         DropOwnedStmt ReassignOwnedStmt
     319             :         AlterTSConfigurationStmt AlterTSDictionaryStmt
     320             :         CreateMatViewStmt RefreshMatViewStmt CreateAmStmt
     321             :         CreatePublicationStmt AlterPublicationStmt
     322             :         CreateSubscriptionStmt AlterSubscriptionStmt DropSubscriptionStmt
     323             : 
     324             : %type <node>  select_no_parens select_with_parens select_clause
     325             :                 simple_select values_clause
     326             :                 PLpgSQL_Expr PLAssignStmt
     327             : 
     328             : %type <str>           opt_single_name
     329             : %type <list>      opt_qualified_name
     330             : %type <boolean>       opt_concurrently
     331             : %type <dbehavior> opt_drop_behavior
     332             : 
     333             : %type <node>  alter_column_default opclass_item opclass_drop alter_using
     334             : %type <ival>  add_drop opt_asc_desc opt_nulls_order
     335             : 
     336             : %type <node>  alter_table_cmd alter_type_cmd opt_collate_clause
     337             :        replica_identity partition_cmd index_partition_cmd
     338             : %type <list>  alter_table_cmds alter_type_cmds
     339             : %type <list>    alter_identity_column_option_list
     340             : %type <defelt>  alter_identity_column_option
     341             : %type <node>  set_statistics_value
     342             : %type <str>       set_access_method_name
     343             : 
     344             : %type <list>  createdb_opt_list createdb_opt_items copy_opt_list
     345             :                 transaction_mode_list
     346             :                 create_extension_opt_list alter_extension_opt_list
     347             : %type <defelt>    createdb_opt_item copy_opt_item
     348             :                 transaction_mode_item
     349             :                 create_extension_opt_item alter_extension_opt_item
     350             : 
     351             : %type <ival>  opt_lock lock_type cast_context
     352             : %type <str>       utility_option_name
     353             : %type <defelt>    utility_option_elem
     354             : %type <list>  utility_option_list
     355             : %type <node>  utility_option_arg
     356             : %type <defelt>    drop_option
     357             : %type <boolean>   opt_or_replace opt_no
     358             :                 opt_grant_grant_option
     359             :                 opt_nowait opt_if_exists opt_with_data
     360             :                 opt_transaction_chain
     361             : %type <list>  grant_role_opt_list
     362             : %type <defelt>    grant_role_opt
     363             : %type <node>  grant_role_opt_value
     364             : %type <ival>  opt_nowait_or_skip
     365             : 
     366             : %type <list>  OptRoleList AlterOptRoleList
     367             : %type <defelt>    CreateOptRoleElem AlterOptRoleElem
     368             : 
     369             : %type <str>       opt_type
     370             : %type <str>       foreign_server_version opt_foreign_server_version
     371             : %type <str>       opt_in_database
     372             : 
     373             : %type <str>       parameter_name
     374             : %type <list>  OptSchemaEltList parameter_name_list
     375             : 
     376             : %type <chr>       am_type
     377             : 
     378             : %type <boolean> TriggerForSpec TriggerForType
     379             : %type <ival>  TriggerActionTime
     380             : %type <list>  TriggerEvents TriggerOneEvent
     381             : %type <node>  TriggerFuncArg
     382             : %type <node>  TriggerWhen
     383             : %type <str>       TransitionRelName
     384             : %type <boolean>   TransitionRowOrTable TransitionOldOrNew
     385             : %type <node>  TriggerTransition
     386             : 
     387             : %type <list>  event_trigger_when_list event_trigger_value_list
     388             : %type <defelt>    event_trigger_when_item
     389             : %type <chr>       enable_trigger
     390             : 
     391             : %type <str>       copy_file_name
     392             :                 access_method_clause attr_name
     393             :                 table_access_method_clause name cursor_name file_name
     394             :                 cluster_index_specification
     395             : 
     396             : %type <list>  func_name handler_name qual_Op qual_all_Op subquery_Op
     397             :                 opt_inline_handler opt_validator validator_clause
     398             :                 opt_collate
     399             : 
     400             : %type <range> qualified_name insert_target OptConstrFromTable
     401             : 
     402             : %type <str>       all_Op MathOp
     403             : 
     404             : %type <str>       row_security_cmd RowSecurityDefaultForCmd
     405             : %type <boolean> RowSecurityDefaultPermissive
     406             : %type <node>  RowSecurityOptionalWithCheck RowSecurityOptionalExpr
     407             : %type <list>  RowSecurityDefaultToRole RowSecurityOptionalToRole
     408             : 
     409             : %type <str>       iso_level opt_encoding
     410             : %type <rolespec> grantee
     411             : %type <list>  grantee_list
     412             : %type <accesspriv> privilege
     413             : %type <list>  privileges privilege_list
     414             : %type <privtarget> privilege_target
     415             : %type <objwithargs> function_with_argtypes aggregate_with_argtypes operator_with_argtypes
     416             : %type <list>  function_with_argtypes_list aggregate_with_argtypes_list operator_with_argtypes_list
     417             : %type <ival>  defacl_privilege_target
     418             : %type <defelt>    DefACLOption
     419             : %type <list>  DefACLOptionList
     420             : %type <ival>  import_qualification_type
     421             : %type <importqual> import_qualification
     422             : %type <node>  vacuum_relation
     423             : %type <selectlimit> opt_select_limit select_limit limit_clause
     424             : 
     425             : %type <list>  parse_toplevel stmtmulti routine_body_stmt_list
     426             :                 OptTableElementList TableElementList OptInherit definition
     427             :                 OptTypedTableElementList TypedTableElementList
     428             :                 reloptions opt_reloptions
     429             :                 OptWith opt_definition func_args func_args_list
     430             :                 func_args_with_defaults func_args_with_defaults_list
     431             :                 aggr_args aggr_args_list
     432             :                 func_as createfunc_opt_list opt_createfunc_opt_list alterfunc_opt_list
     433             :                 old_aggr_definition old_aggr_list
     434             :                 oper_argtypes RuleActionList RuleActionMulti
     435             :                 opt_column_list columnList opt_name_list
     436             :                 sort_clause opt_sort_clause sortby_list index_params
     437             :                 stats_params
     438             :                 opt_include opt_c_include index_including_params
     439             :                 name_list role_list from_clause from_list opt_array_bounds
     440             :                 qualified_name_list any_name any_name_list type_name_list
     441             :                 any_operator expr_list attrs
     442             :                 distinct_clause opt_distinct_clause
     443             :                 target_list opt_target_list insert_column_list set_target_list
     444             :                 merge_values_clause
     445             :                 set_clause_list set_clause
     446             :                 def_list operator_def_list indirection opt_indirection
     447             :                 reloption_list TriggerFuncArgs opclass_item_list opclass_drop_list
     448             :                 opclass_purpose opt_opfamily transaction_mode_list_or_empty
     449             :                 OptTableFuncElementList TableFuncElementList opt_type_modifiers
     450             :                 prep_type_clause
     451             :                 execute_param_clause using_clause returning_clause
     452             :                 opt_enum_val_list enum_val_list table_func_column_list
     453             :                 create_generic_options alter_generic_options
     454             :                 relation_expr_list dostmt_opt_list
     455             :                 transform_element_list transform_type_list
     456             :                 TriggerTransitions TriggerReferencing
     457             :                 vacuum_relation_list opt_vacuum_relation_list
     458             :                 drop_option_list pub_obj_list
     459             : 
     460             : %type <node>  opt_routine_body
     461             : %type <groupclause> group_clause
     462             : %type <list>  group_by_list
     463             : %type <node>  group_by_item empty_grouping_set rollup_clause cube_clause
     464             : %type <node>  grouping_sets_clause
     465             : 
     466             : %type <list>  opt_fdw_options fdw_options
     467             : %type <defelt>    fdw_option
     468             : 
     469             : %type <range> OptTempTableName
     470             : %type <into>  into_clause create_as_target create_mv_target
     471             : 
     472             : %type <defelt>    createfunc_opt_item common_func_opt_item dostmt_opt_item
     473             : %type <fun_param> func_arg func_arg_with_default table_func_column aggr_arg
     474             : %type <fun_param_mode> arg_class
     475             : %type <typnam>    func_return func_type
     476             : 
     477             : %type <boolean>  opt_trusted opt_restart_seqs
     478             : %type <ival>   OptTemp
     479             : %type <ival>   OptNoLog
     480             : %type <oncommit> OnCommitOption
     481             : 
     482             : %type <ival>  for_locking_strength
     483             : %type <node>  for_locking_item
     484             : %type <list>  for_locking_clause opt_for_locking_clause for_locking_items
     485             : %type <list>  locked_rels_list
     486             : %type <setquantifier> set_quantifier
     487             : 
     488             : %type <node>  join_qual
     489             : %type <jtype> join_type
     490             : 
     491             : %type <list>  extract_list overlay_list position_list
     492             : %type <list>  substr_list trim_list
     493             : %type <list>  opt_interval interval_second
     494             : %type <str>       unicode_normal_form
     495             : 
     496             : %type <boolean> opt_instead
     497             : %type <boolean> opt_unique opt_verbose opt_full
     498             : %type <boolean> opt_freeze opt_analyze opt_default opt_recheck
     499             : %type <defelt>    opt_binary copy_delimiter
     500             : 
     501             : %type <boolean> copy_from opt_program
     502             : 
     503             : %type <ival>  event cursor_options opt_hold opt_set_data
     504             : %type <objtype>   object_type_any_name object_type_name object_type_name_on_any_name
     505             :                 drop_type_name
     506             : 
     507             : %type <node>  fetch_args select_limit_value
     508             :                 offset_clause select_offset_value
     509             :                 select_fetch_first_value I_or_F_const
     510             : %type <ival>  row_or_rows first_or_next
     511             : 
     512             : %type <list>  OptSeqOptList SeqOptList OptParenthesizedSeqOptList
     513             : %type <defelt>    SeqOptElem
     514             : 
     515             : %type <istmt> insert_rest
     516             : %type <infer> opt_conf_expr
     517             : %type <onconflict> opt_on_conflict
     518             : %type <mergewhen> merge_insert merge_update merge_delete
     519             : 
     520             : %type <mergematch> merge_when_tgt_matched merge_when_tgt_not_matched
     521             : %type <node>  merge_when_clause opt_merge_when_condition
     522             : %type <list>  merge_when_list
     523             : 
     524             : %type <vsetstmt> generic_set set_rest set_rest_more generic_reset reset_rest
     525             :                  SetResetClause FunctionSetResetClause
     526             : 
     527             : %type <node>  TableElement TypedTableElement ConstraintElem DomainConstraintElem TableFuncElement
     528             : %type <node>  columnDef columnOptions optionalPeriodName
     529             : %type <defelt>    def_elem reloption_elem old_aggr_elem operator_def_elem
     530             : %type <node>  def_arg columnElem where_clause where_or_current_clause
     531             :                 a_expr b_expr c_expr AexprConst indirection_el opt_slice_bound
     532             :                 columnref in_expr having_clause func_table xmltable array_expr
     533             :                 OptWhereClause operator_def_arg
     534             : %type <list>  opt_column_and_period_list
     535             : %type <list>  rowsfrom_item rowsfrom_list opt_col_def_list
     536             : %type <boolean> opt_ordinality opt_without_overlaps
     537             : %type <list>  ExclusionConstraintList ExclusionConstraintElem
     538             : %type <list>  func_arg_list func_arg_list_opt
     539             : %type <node>  func_arg_expr
     540             : %type <list>  row explicit_row implicit_row type_list array_expr_list
     541             : %type <node>  case_expr case_arg when_clause case_default
     542             : %type <list>  when_clause_list
     543             : %type <node>  opt_search_clause opt_cycle_clause
     544             : %type <ival>  sub_type opt_materialized
     545             : %type <node>  NumericOnly
     546             : %type <list>  NumericOnly_list
     547             : %type <alias> alias_clause opt_alias_clause opt_alias_clause_for_join_using
     548             : %type <list>  func_alias_clause
     549             : %type <sortby>    sortby
     550             : %type <ielem> index_elem index_elem_options
     551             : %type <selem> stats_param
     552             : %type <node>  table_ref
     553             : %type <jexpr> joined_table
     554             : %type <range> relation_expr
     555             : %type <range> extended_relation_expr
     556             : %type <range> relation_expr_opt_alias
     557             : %type <node>  tablesample_clause opt_repeatable_clause
     558             : %type <target>    target_el set_target insert_column_item
     559             : 
     560             : %type <str>       generic_option_name
     561             : %type <node>  generic_option_arg
     562             : %type <defelt>    generic_option_elem alter_generic_option_elem
     563             : %type <list>  generic_option_list alter_generic_option_list
     564             : 
     565             : %type <ival>  reindex_target_relation reindex_target_all
     566             : %type <list>  opt_reindex_option_list
     567             : 
     568             : %type <node>  copy_generic_opt_arg copy_generic_opt_arg_list_item
     569             : %type <defelt>    copy_generic_opt_elem
     570             : %type <list>  copy_generic_opt_list copy_generic_opt_arg_list
     571             : %type <list>  copy_options
     572             : 
     573             : %type <typnam>    Typename SimpleTypename ConstTypename
     574             :                 GenericType Numeric opt_float JsonType
     575             :                 Character ConstCharacter
     576             :                 CharacterWithLength CharacterWithoutLength
     577             :                 ConstDatetime ConstInterval
     578             :                 Bit ConstBit BitWithLength BitWithoutLength
     579             : %type <str>       character
     580             : %type <str>       extract_arg
     581             : %type <boolean> opt_varying opt_timezone opt_no_inherit
     582             : 
     583             : %type <ival>  Iconst SignedIconst
     584             : %type <str>       Sconst comment_text notify_payload
     585             : %type <str>       RoleId opt_boolean_or_string
     586             : %type <list>  var_list
     587             : %type <str>       ColId ColLabel BareColLabel
     588             : %type <str>       NonReservedWord NonReservedWord_or_Sconst
     589             : %type <str>       var_name type_function_name param_name
     590             : %type <str>       createdb_opt_name plassign_target
     591             : %type <node>  var_value zone_value
     592             : %type <rolespec> auth_ident RoleSpec opt_granted_by
     593             : %type <publicationobjectspec> PublicationObjSpec
     594             : 
     595             : %type <keyword> unreserved_keyword type_func_name_keyword
     596             : %type <keyword> col_name_keyword reserved_keyword
     597             : %type <keyword> bare_label_keyword
     598             : 
     599             : %type <node>  DomainConstraint TableConstraint TableLikeClause
     600             : %type <ival>  TableLikeOptionList TableLikeOption
     601             : %type <str>       column_compression opt_column_compression column_storage opt_column_storage
     602             : %type <list>  ColQualList
     603             : %type <node>  ColConstraint ColConstraintElem ConstraintAttr
     604             : %type <ival>  key_match
     605             : %type <keyaction> key_delete key_update key_action
     606             : %type <keyactions> key_actions
     607             : %type <ival>  ConstraintAttributeSpec ConstraintAttributeElem
     608             : %type <str>       ExistingIndex
     609             : 
     610             : %type <list>  constraints_set_list
     611             : %type <boolean> constraints_set_mode
     612             : %type <str>       OptTableSpace OptConsTableSpace
     613             : %type <rolespec> OptTableSpaceOwner
     614             : %type <ival>  opt_check_option
     615             : 
     616             : %type <str>       opt_provider security_label
     617             : 
     618             : %type <target>    xml_attribute_el
     619             : %type <list>  xml_attribute_list xml_attributes
     620             : %type <node>  xml_root_version opt_xml_root_standalone
     621             : %type <node>  xmlexists_argument
     622             : %type <ival>  document_or_content
     623             : %type <boolean>   xml_indent_option xml_whitespace_option
     624             : %type <list>  xmltable_column_list xmltable_column_option_list
     625             : %type <node>  xmltable_column_el
     626             : %type <defelt>    xmltable_column_option_el
     627             : %type <list>  xml_namespace_list
     628             : %type <target>    xml_namespace_el
     629             : 
     630             : %type <node>  func_application func_expr_common_subexpr
     631             : %type <node>  func_expr func_expr_windowless
     632             : %type <node>  common_table_expr
     633             : %type <with>  with_clause opt_with_clause
     634             : %type <list>  cte_list
     635             : 
     636             : %type <list>  within_group_clause
     637             : %type <node>  filter_clause
     638             : %type <list>  window_clause window_definition_list opt_partition_clause
     639             : %type <windef>    window_definition over_clause window_specification
     640             :                 opt_frame_clause frame_extent frame_bound
     641             : %type <ival>  opt_window_exclusion_clause
     642             : %type <str>       opt_existing_window_name
     643             : %type <boolean> opt_if_not_exists
     644             : %type <boolean> opt_unique_null_treatment
     645             : %type <ival>  generated_when override_kind
     646             : %type <partspec>  PartitionSpec OptPartitionSpec
     647             : %type <partelem>  part_elem
     648             : %type <list>      part_params
     649             : %type <partboundspec> PartitionBoundSpec
     650             : %type <singlepartspec>    SinglePartitionSpec
     651             : %type <list>      partitions_list
     652             : %type <list>      hash_partbound
     653             : %type <defelt>        hash_partbound_elem
     654             : 
     655             : %type <node>  json_format_clause
     656             :                 json_format_clause_opt
     657             :                 json_value_expr
     658             :                 json_returning_clause_opt
     659             :                 json_name_and_value
     660             :                 json_aggregate_func
     661             :                 json_argument
     662             :                 json_behavior
     663             :                 json_on_error_clause_opt
     664             :                 json_table
     665             :                 json_table_column_definition
     666             :                 json_table_column_path_clause_opt
     667             : %type <list>  json_name_and_value_list
     668             :                 json_value_expr_list
     669             :                 json_array_aggregate_order_by_clause_opt
     670             :                 json_arguments
     671             :                 json_behavior_clause_opt
     672             :                 json_passing_clause_opt
     673             :                 json_table_column_definition_list
     674             : %type <str>       json_table_path_name_opt
     675             : %type <ival>  json_behavior_type
     676             :                 json_predicate_type_constraint
     677             :                 json_quotes_clause_opt
     678             :                 json_wrapper_behavior
     679             : %type <boolean>   json_key_uniqueness_constraint_opt
     680             :                 json_object_constructor_null_clause_opt
     681             :                 json_array_constructor_null_clause_opt
     682             : 
     683             : 
     684             : /*
     685             :  * Non-keyword token types.  These are hard-wired into the "flex" lexer.
     686             :  * They must be listed first so that their numeric codes do not depend on
     687             :  * the set of keywords.  PL/pgSQL depends on this so that it can share the
     688             :  * same lexer.  If you add/change tokens here, fix PL/pgSQL to match!
     689             :  *
     690             :  * UIDENT and USCONST are reduced to IDENT and SCONST in parser.c, so that
     691             :  * they need no productions here; but we must assign token codes to them.
     692             :  *
     693             :  * DOT_DOT is unused in the core SQL grammar, and so will always provoke
     694             :  * parse errors.  It is needed by PL/pgSQL.
     695             :  */
     696             : %token <str>  IDENT UIDENT FCONST SCONST USCONST BCONST XCONST Op
     697             : %token <ival> ICONST PARAM
     698             : %token          TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
     699             : %token          LESS_EQUALS GREATER_EQUALS NOT_EQUALS
     700             : 
     701             : /*
     702             :  * If you want to make any keyword changes, update the keyword table in
     703             :  * src/include/parser/kwlist.h and add new keywords to the appropriate one
     704             :  * of the reserved-or-not-so-reserved keyword lists, below; search
     705             :  * this file for "Keyword category lists".
     706             :  */
     707             : 
     708             : /* ordinary key words in alphabetical order */
     709             : %token <keyword> ABORT_P ABSENT ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
     710             :     AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
     711             :     ASENSITIVE ASSERTION ASSIGNMENT ASYMMETRIC ATOMIC AT ATTACH ATTRIBUTE AUTHORIZATION
     712             : 
     713             :     BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
     714             :     BOOLEAN_P BOTH BREADTH BY
     715             : 
     716             :     CACHE CALL CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
     717             :     CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
     718             :     CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
     719             :     COMMITTED COMPRESSION CONCURRENTLY CONDITIONAL CONFIGURATION CONFLICT
     720             :     CONNECTION CONSTRAINT CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY
     721             :     COST CREATE CROSS CSV CUBE CURRENT_P
     722             :     CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
     723             :     CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
     724             : 
     725             :     DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
     726             :     DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DEPENDS DEPTH DESC
     727             :     DETACH DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P
     728             :     DOUBLE_P DROP
     729             : 
     730             :     EACH ELSE EMPTY_P ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ERROR_P ESCAPE
     731             :     EVENT EXCEPT EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN EXPRESSION
     732             :     EXTENSION EXTERNAL EXTRACT
     733             : 
     734             :     FALSE_P FAMILY FETCH FILTER FINALIZE FIRST_P FLOAT_P FOLLOWING FOR
     735             :     FORCE FOREIGN FORMAT FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
     736             : 
     737             :     GENERATED GLOBAL GRANT GRANTED GREATEST GROUP_P GROUPING GROUPS
     738             : 
     739             :     HANDLER HAVING HEADER_P HOLD HOUR_P
     740             : 
     741             :     IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P INCLUDE
     742             :     INCLUDING INCREMENT INDENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
     743             :     INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
     744             :     INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
     745             : 
     746             :     JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_EXISTS JSON_OBJECT JSON_OBJECTAGG
     747             :     JSON_QUERY JSON_SCALAR JSON_SERIALIZE JSON_TABLE JSON_VALUE
     748             : 
     749             :     KEEP KEY KEYS
     750             : 
     751             :     LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
     752             :     LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
     753             :     LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED
     754             : 
     755             :     MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE MERGE_ACTION METHOD
     756             :     MINUTE_P MINVALUE MODE MONTH_P MOVE
     757             : 
     758             :     NAME_P NAMES NATIONAL NATURAL NCHAR NESTED NEW NEXT NFC NFD NFKC NFKD NO
     759             :     NONE NORMALIZE NORMALIZED
     760             :     NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
     761             :     NULLS_P NUMERIC
     762             : 
     763             :     OBJECT_P OF OFF OFFSET OIDS OLD OMIT ON ONLY OPERATOR OPTION OPTIONS OR
     764             :     ORDER ORDINALITY OTHERS OUT_P OUTER_P
     765             :     OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
     766             : 
     767             :     PARALLEL PARAMETER PARSER PARTIAL PARTITION PARTITIONS PASSING PASSWORD PATH
     768             :     PERIOD PLACING PLAN PLANS POLICY
     769             : 
     770             :     POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
     771             :     PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PUBLICATION
     772             : 
     773             :     QUOTE QUOTES
     774             : 
     775             :     RANGE READ REAL REASSIGN RECHECK RECURSIVE REF_P REFERENCES REFERENCING
     776             :     REFRESH REINDEX RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
     777             :     RESET RESTART RESTRICT RETURN RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
     778             :     ROUTINE ROUTINES ROW ROWS RULE
     779             : 
     780             :     SAVEPOINT SCALAR SCHEMA SCHEMAS SCROLL SEARCH SECOND_P SECURITY SELECT
     781             :     SEQUENCE SEQUENCES
     782             :     SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
     783             :     SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SPLIT SOURCE SQL_P STABLE STANDALONE_P
     784             :     START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRING_P STRIP_P
     785             :     SUBSCRIPTION SUBSTRING SUPPORT SYMMETRIC SYSID SYSTEM_P SYSTEM_USER
     786             : 
     787             :     TABLE TABLES TABLESAMPLE TABLESPACE TARGET TEMP TEMPLATE TEMPORARY TEXT_P THEN
     788             :     TIES TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM
     789             :     TREAT TRIGGER TRIM TRUE_P
     790             :     TRUNCATE TRUSTED TYPE_P TYPES_P
     791             : 
     792             :     UESCAPE UNBOUNDED UNCONDITIONAL UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
     793             :     UNLISTEN UNLOGGED UNTIL UPDATE USER USING
     794             : 
     795             :     VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
     796             :     VERBOSE VERSION_P VIEW VIEWS VOLATILE
     797             : 
     798             :     WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
     799             : 
     800             :     XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLNAMESPACES
     801             :     XMLPARSE XMLPI XMLROOT XMLSERIALIZE XMLTABLE
     802             : 
     803             :     YEAR_P YES_P
     804             : 
     805             :     ZONE
     806             : 
     807             : /*
     808             :  * The grammar thinks these are keywords, but they are not in the kwlist.h
     809             :  * list and so can never be entered directly.  The filter in parser.c
     810             :  * creates these tokens when required (based on looking one token ahead).
     811             :  *
     812             :  * NOT_LA exists so that productions such as NOT LIKE can be given the same
     813             :  * precedence as LIKE; otherwise they'd effectively have the same precedence
     814             :  * as NOT, at least with respect to their left-hand subexpression.
     815             :  * FORMAT_LA, NULLS_LA, WITH_LA, and WITHOUT_LA are needed to make the grammar
     816             :  * LALR(1).
     817             :  */
     818             : %token      FORMAT_LA NOT_LA NULLS_LA WITH_LA WITHOUT_LA
     819             : 
     820             : /*
     821             :  * The grammar likewise thinks these tokens are keywords, but they are never
     822             :  * generated by the scanner.  Rather, they can be injected by parser.c as
     823             :  * the initial token of the string (using the lookahead-token mechanism
     824             :  * implemented there).  This provides a way to tell the grammar to parse
     825             :  * something other than the usual list of SQL commands.
     826             :  */
     827             : %token      MODE_TYPE_NAME
     828             : %token      MODE_PLPGSQL_EXPR
     829             : %token      MODE_PLPGSQL_ASSIGN1
     830             : %token      MODE_PLPGSQL_ASSIGN2
     831             : %token      MODE_PLPGSQL_ASSIGN3
     832             : 
     833             : 
     834             : /* Precedence: lowest to highest */
     835             : %left       UNION EXCEPT
     836             : %left       INTERSECT
     837             : %left       OR
     838             : %left       AND
     839             : %right      NOT
     840             : %nonassoc   IS ISNULL NOTNULL   /* IS sets precedence for IS NULL, etc */
     841             : %nonassoc   '<' '>' '=' LESS_EQUALS GREATER_EQUALS NOT_EQUALS
     842             : %nonassoc   BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
     843             : %nonassoc   ESCAPE          /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
     844             : 
     845             : /*
     846             :  * Sometimes it is necessary to assign precedence to keywords that are not
     847             :  * really part of the operator hierarchy, in order to resolve grammar
     848             :  * ambiguities.  It's best to avoid doing so whenever possible, because such
     849             :  * assignments have global effect and may hide ambiguities besides the one
     850             :  * you intended to solve.  (Attaching a precedence to a single rule with
     851             :  * %prec is far safer and should be preferred.)  If you must give precedence
     852             :  * to a new keyword, try very hard to give it the same precedence as IDENT.
     853             :  * If the keyword has IDENT's precedence then it clearly acts the same as
     854             :  * non-keywords and other similar keywords, thus reducing the risk of
     855             :  * unexpected precedence effects.
     856             :  *
     857             :  * We used to need to assign IDENT an explicit precedence just less than Op,
     858             :  * to support target_el without AS.  While that's not really necessary since
     859             :  * we removed postfix operators, we continue to do so because it provides a
     860             :  * reference point for a precedence level that we can assign to other
     861             :  * keywords that lack a natural precedence level.
     862             :  *
     863             :  * We need to do this for PARTITION, RANGE, ROWS, and GROUPS to support
     864             :  * opt_existing_window_name (see comment there).
     865             :  *
     866             :  * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
     867             :  * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
     868             :  * there is no principled way to distinguish these from the productions
     869             :  * a_expr PRECEDING/FOLLOWING.  We hack this up by giving UNBOUNDED slightly
     870             :  * lower precedence than PRECEDING and FOLLOWING.  At present this doesn't
     871             :  * appear to cause UNBOUNDED to be treated differently from other unreserved
     872             :  * keywords anywhere else in the grammar, but it's definitely risky.  We can
     873             :  * blame any funny behavior of UNBOUNDED on the SQL standard, though.
     874             :  *
     875             :  * To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
     876             :  * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
     877             :  * rather than reducing a conflicting rule that takes CUBE as a function name.
     878             :  * Using the same precedence as IDENT seems right for the reasons given above.
     879             :  *
     880             :  * SET is likewise assigned the same precedence as IDENT, to support the
     881             :  * relation_expr_opt_alias production (see comment there).
     882             :  *
     883             :  * KEYS, OBJECT_P, SCALAR, VALUE_P, WITH, and WITHOUT are similarly assigned
     884             :  * the same precedence as IDENT.  This allows resolving conflicts in the
     885             :  * json_predicate_type_constraint and json_key_uniqueness_constraint_opt
     886             :  * productions (see comments there).
     887             :  *
     888             :  * Like the UNBOUNDED PRECEDING/FOLLOWING case, NESTED is assigned a lower
     889             :  * precedence than PATH to fix ambiguity in the json_table production.
     890             :  */
     891             : %nonassoc   UNBOUNDED NESTED /* ideally would have same precedence as IDENT */
     892             : %nonassoc   IDENT PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
     893             :             SET KEYS OBJECT_P SCALAR VALUE_P WITH WITHOUT PATH
     894             : %left       Op OPERATOR     /* multi-character ops and user-defined operators */
     895             : %left       '+' '-'
     896             : %left       '*' '/' '%'
     897             : %left       '^'
     898             : /* Unary Operators */
     899             : %left       AT              /* sets precedence for AT TIME ZONE, AT LOCAL */
     900             : %left       COLLATE
     901             : %right      UMINUS
     902             : %left       '[' ']'
     903             : %left       '(' ')'
     904             : %left       TYPECAST
     905             : %left       '.'
     906             : /*
     907             :  * These might seem to be low-precedence, but actually they are not part
     908             :  * of the arithmetic hierarchy at all in their use as JOIN operators.
     909             :  * We make them high-precedence to support their use as function names.
     910             :  * They wouldn't be given a precedence at all, were it not that we need
     911             :  * left-associativity among the JOIN rules themselves.
     912             :  */
     913             : %left       JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
     914             : 
     915             : %%
     916             : 
     917             : /*
     918             :  *  The target production for the whole parse.
     919             :  *
     920             :  * Ordinarily we parse a list of statements, but if we see one of the
     921             :  * special MODE_XXX symbols as first token, we parse something else.
     922             :  * The options here correspond to enum RawParseMode, which see for details.
     923             :  */
     924             : parse_toplevel:
     925             :             stmtmulti
     926             :             {
     927      676278 :                 pg_yyget_extra(yyscanner)->parsetree = $1;
     928             :                 (void) yynerrs;     /* suppress compiler warning */
     929             :             }
     930             :             | MODE_TYPE_NAME Typename
     931             :             {
     932        9334 :                 pg_yyget_extra(yyscanner)->parsetree = list_make1($2);
     933             :             }
     934             :             | MODE_PLPGSQL_EXPR PLpgSQL_Expr
     935             :             {
     936       30152 :                 pg_yyget_extra(yyscanner)->parsetree =
     937       30152 :                     list_make1(makeRawStmt($2, 0));
     938             :             }
     939             :             | MODE_PLPGSQL_ASSIGN1 PLAssignStmt
     940             :             {
     941        5966 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     942             : 
     943        5966 :                 n->nnames = 1;
     944        5966 :                 pg_yyget_extra(yyscanner)->parsetree =
     945        5966 :                     list_make1(makeRawStmt((Node *) n, 0));
     946             :             }
     947             :             | MODE_PLPGSQL_ASSIGN2 PLAssignStmt
     948             :             {
     949         620 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     950             : 
     951         620 :                 n->nnames = 2;
     952         620 :                 pg_yyget_extra(yyscanner)->parsetree =
     953         620 :                     list_make1(makeRawStmt((Node *) n, 0));
     954             :             }
     955             :             | MODE_PLPGSQL_ASSIGN3 PLAssignStmt
     956             :             {
     957          28 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     958             : 
     959          28 :                 n->nnames = 3;
     960          28 :                 pg_yyget_extra(yyscanner)->parsetree =
     961          28 :                     list_make1(makeRawStmt((Node *) n, 0));
     962             :             }
     963             :         ;
     964             : 
     965             : /*
     966             :  * At top level, we wrap each stmt with a RawStmt node carrying start location
     967             :  * and length of the stmt's text.  Notice that the start loc/len are driven
     968             :  * entirely from semicolon locations (@2).  It would seem natural to use
     969             :  * @1 or @3 to get the true start location of a stmt, but that doesn't work
     970             :  * for statements that can start with empty nonterminals (opt_with_clause is
     971             :  * the main offender here); as noted in the comments for YYLLOC_DEFAULT,
     972             :  * we'd get -1 for the location in such cases.
     973             :  * We also take care to discard empty statements entirely.
     974             :  */
     975             : stmtmulti:  stmtmulti ';' toplevel_stmt
     976             :                 {
     977      549156 :                     if ($1 != NIL)
     978             :                     {
     979             :                         /* update length of previous stmt */
     980      549066 :                         updateRawStmtEnd(llast_node(RawStmt, $1), @2);
     981             :                     }
     982      549156 :                     if ($3 != NULL)
     983       48590 :                         $$ = lappend($1, makeRawStmt($3, @2 + 1));
     984             :                     else
     985      500566 :                         $$ = $1;
     986             :                 }
     987             :             | toplevel_stmt
     988             :                 {
     989      676284 :                     if ($1 != NULL)
     990      675812 :                         $$ = list_make1(makeRawStmt($1, 0));
     991             :                     else
     992         472 :                         $$ = NIL;
     993             :                 }
     994             :         ;
     995             : 
     996             : /*
     997             :  * toplevel_stmt includes BEGIN and END.  stmt does not include them, because
     998             :  * those words have different meanings in function bodies.
     999             :  */
    1000             : toplevel_stmt:
    1001             :             stmt
    1002             :             | TransactionStmtLegacy
    1003             :         ;
    1004             : 
    1005             : stmt:
    1006             :             AlterEventTrigStmt
    1007             :             | AlterCollationStmt
    1008             :             | AlterDatabaseStmt
    1009             :             | AlterDatabaseSetStmt
    1010             :             | AlterDefaultPrivilegesStmt
    1011             :             | AlterDomainStmt
    1012             :             | AlterEnumStmt
    1013             :             | AlterExtensionStmt
    1014             :             | AlterExtensionContentsStmt
    1015             :             | AlterFdwStmt
    1016             :             | AlterForeignServerStmt
    1017             :             | AlterFunctionStmt
    1018             :             | AlterGroupStmt
    1019             :             | AlterObjectDependsStmt
    1020             :             | AlterObjectSchemaStmt
    1021             :             | AlterOwnerStmt
    1022             :             | AlterOperatorStmt
    1023             :             | AlterTypeStmt
    1024             :             | AlterPolicyStmt
    1025             :             | AlterSeqStmt
    1026             :             | AlterSystemStmt
    1027             :             | AlterTableStmt
    1028             :             | AlterTblSpcStmt
    1029             :             | AlterCompositeTypeStmt
    1030             :             | AlterPublicationStmt
    1031             :             | AlterRoleSetStmt
    1032             :             | AlterRoleStmt
    1033             :             | AlterSubscriptionStmt
    1034             :             | AlterStatsStmt
    1035             :             | AlterTSConfigurationStmt
    1036             :             | AlterTSDictionaryStmt
    1037             :             | AlterUserMappingStmt
    1038             :             | AnalyzeStmt
    1039             :             | CallStmt
    1040             :             | CheckPointStmt
    1041             :             | ClosePortalStmt
    1042             :             | ClusterStmt
    1043             :             | CommentStmt
    1044             :             | ConstraintsSetStmt
    1045             :             | CopyStmt
    1046             :             | CreateAmStmt
    1047             :             | CreateAsStmt
    1048             :             | CreateAssertionStmt
    1049             :             | CreateCastStmt
    1050             :             | CreateConversionStmt
    1051             :             | CreateDomainStmt
    1052             :             | CreateExtensionStmt
    1053             :             | CreateFdwStmt
    1054             :             | CreateForeignServerStmt
    1055             :             | CreateForeignTableStmt
    1056             :             | CreateFunctionStmt
    1057             :             | CreateGroupStmt
    1058             :             | CreateMatViewStmt
    1059             :             | CreateOpClassStmt
    1060             :             | CreateOpFamilyStmt
    1061             :             | CreatePublicationStmt
    1062             :             | AlterOpFamilyStmt
    1063             :             | CreatePolicyStmt
    1064             :             | CreatePLangStmt
    1065             :             | CreateSchemaStmt
    1066             :             | CreateSeqStmt
    1067             :             | CreateStmt
    1068             :             | CreateSubscriptionStmt
    1069             :             | CreateStatsStmt
    1070             :             | CreateTableSpaceStmt
    1071             :             | CreateTransformStmt
    1072             :             | CreateTrigStmt
    1073             :             | CreateEventTrigStmt
    1074             :             | CreateRoleStmt
    1075             :             | CreateUserStmt
    1076             :             | CreateUserMappingStmt
    1077             :             | CreatedbStmt
    1078             :             | DeallocateStmt
    1079             :             | DeclareCursorStmt
    1080             :             | DefineStmt
    1081             :             | DeleteStmt
    1082             :             | DiscardStmt
    1083             :             | DoStmt
    1084             :             | DropCastStmt
    1085             :             | DropOpClassStmt
    1086             :             | DropOpFamilyStmt
    1087             :             | DropOwnedStmt
    1088             :             | DropStmt
    1089             :             | DropSubscriptionStmt
    1090             :             | DropTableSpaceStmt
    1091             :             | DropTransformStmt
    1092             :             | DropRoleStmt
    1093             :             | DropUserMappingStmt
    1094             :             | DropdbStmt
    1095             :             | ExecuteStmt
    1096             :             | ExplainStmt
    1097             :             | FetchStmt
    1098             :             | GrantStmt
    1099             :             | GrantRoleStmt
    1100             :             | ImportForeignSchemaStmt
    1101             :             | IndexStmt
    1102             :             | InsertStmt
    1103             :             | ListenStmt
    1104             :             | RefreshMatViewStmt
    1105             :             | LoadStmt
    1106             :             | LockStmt
    1107             :             | MergeStmt
    1108             :             | NotifyStmt
    1109             :             | PrepareStmt
    1110             :             | ReassignOwnedStmt
    1111             :             | ReindexStmt
    1112             :             | RemoveAggrStmt
    1113             :             | RemoveFuncStmt
    1114             :             | RemoveOperStmt
    1115             :             | RenameStmt
    1116             :             | RevokeStmt
    1117             :             | RevokeRoleStmt
    1118             :             | RuleStmt
    1119             :             | SecLabelStmt
    1120             :             | SelectStmt
    1121             :             | TransactionStmt
    1122             :             | TruncateStmt
    1123             :             | UnlistenStmt
    1124             :             | UpdateStmt
    1125             :             | VacuumStmt
    1126             :             | VariableResetStmt
    1127             :             | VariableSetStmt
    1128             :             | VariableShowStmt
    1129             :             | ViewStmt
    1130             :             | /*EMPTY*/
    1131      501056 :                 { $$ = NULL; }
    1132             :         ;
    1133             : 
    1134             : /*
    1135             :  * Generic supporting productions for DDL
    1136             :  */
    1137             : opt_single_name:
    1138        5088 :             ColId                           { $$ = $1; }
    1139        1430 :             | /* EMPTY */                   { $$ = NULL; }
    1140             :         ;
    1141             : 
    1142             : opt_qualified_name:
    1143        1696 :             any_name                        { $$ = $1; }
    1144       14356 :             | /*EMPTY*/                     { $$ = NIL; }
    1145             :         ;
    1146             : 
    1147             : opt_concurrently:
    1148         956 :             CONCURRENTLY                    { $$ = true; }
    1149        7178 :             | /*EMPTY*/                     { $$ = false; }
    1150             :         ;
    1151             : 
    1152             : opt_drop_behavior:
    1153        1930 :             CASCADE                         { $$ = DROP_CASCADE; }
    1154         168 :             | RESTRICT                      { $$ = DROP_RESTRICT; }
    1155       34008 :             | /* EMPTY */                   { $$ = DROP_RESTRICT; /* default */ }
    1156             :         ;
    1157             : 
    1158             : /*****************************************************************************
    1159             :  *
    1160             :  * CALL statement
    1161             :  *
    1162             :  *****************************************************************************/
    1163             : 
    1164             : CallStmt:   CALL func_application
    1165             :                 {
    1166         528 :                     CallStmt   *n = makeNode(CallStmt);
    1167             : 
    1168         528 :                     n->funccall = castNode(FuncCall, $2);
    1169         528 :                     $$ = (Node *) n;
    1170             :                 }
    1171             :         ;
    1172             : 
    1173             : /*****************************************************************************
    1174             :  *
    1175             :  * Create a new Postgres DBMS role
    1176             :  *
    1177             :  *****************************************************************************/
    1178             : 
    1179             : CreateRoleStmt:
    1180             :             CREATE ROLE RoleId opt_with OptRoleList
    1181             :                 {
    1182        1238 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1183             : 
    1184        1238 :                     n->stmt_type = ROLESTMT_ROLE;
    1185        1238 :                     n->role = $3;
    1186        1238 :                     n->options = $5;
    1187        1238 :                     $$ = (Node *) n;
    1188             :                 }
    1189             :         ;
    1190             : 
    1191             : 
    1192             : opt_with:   WITH
    1193             :             | WITH_LA
    1194             :             | /*EMPTY*/
    1195             :         ;
    1196             : 
    1197             : /*
    1198             :  * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
    1199             :  * for backwards compatibility).  Note: the only option required by SQL99
    1200             :  * is "WITH ADMIN name".
    1201             :  */
    1202             : OptRoleList:
    1203        1146 :             OptRoleList CreateOptRoleElem           { $$ = lappend($1, $2); }
    1204        1686 :             | /* EMPTY */                           { $$ = NIL; }
    1205             :         ;
    1206             : 
    1207             : AlterOptRoleList:
    1208         572 :             AlterOptRoleList AlterOptRoleElem       { $$ = lappend($1, $2); }
    1209         392 :             | /* EMPTY */                           { $$ = NIL; }
    1210             :         ;
    1211             : 
    1212             : AlterOptRoleElem:
    1213             :             PASSWORD Sconst
    1214             :                 {
    1215         162 :                     $$ = makeDefElem("password",
    1216         162 :                                      (Node *) makeString($2), @1);
    1217             :                 }
    1218             :             | PASSWORD NULL_P
    1219             :                 {
    1220          12 :                     $$ = makeDefElem("password", NULL, @1);
    1221             :                 }
    1222             :             | ENCRYPTED PASSWORD Sconst
    1223             :                 {
    1224             :                     /*
    1225             :                      * These days, passwords are always stored in encrypted
    1226             :                      * form, so there is no difference between PASSWORD and
    1227             :                      * ENCRYPTED PASSWORD.
    1228             :                      */
    1229          16 :                     $$ = makeDefElem("password",
    1230          16 :                                      (Node *) makeString($3), @1);
    1231             :                 }
    1232             :             | UNENCRYPTED PASSWORD Sconst
    1233             :                 {
    1234           0 :                     ereport(ERROR,
    1235             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1236             :                              errmsg("UNENCRYPTED PASSWORD is no longer supported"),
    1237             :                              errhint("Remove UNENCRYPTED to store the password in encrypted form instead."),
    1238             :                              parser_errposition(@1)));
    1239             :                 }
    1240             :             | INHERIT
    1241             :                 {
    1242          86 :                     $$ = makeDefElem("inherit", (Node *) makeBoolean(true), @1);
    1243             :                 }
    1244             :             | CONNECTION LIMIT SignedIconst
    1245             :                 {
    1246          24 :                     $$ = makeDefElem("connectionlimit", (Node *) makeInteger($3), @1);
    1247             :                 }
    1248             :             | VALID UNTIL Sconst
    1249             :                 {
    1250           2 :                     $$ = makeDefElem("validUntil", (Node *) makeString($3), @1);
    1251             :                 }
    1252             :         /*  Supported but not documented for roles, for use by ALTER GROUP. */
    1253             :             | USER role_list
    1254             :                 {
    1255           6 :                     $$ = makeDefElem("rolemembers", (Node *) $2, @1);
    1256             :                 }
    1257             :             | IDENT
    1258             :                 {
    1259             :                     /*
    1260             :                      * We handle identifiers that aren't parser keywords with
    1261             :                      * the following special-case codes, to avoid bloating the
    1262             :                      * size of the main parser.
    1263             :                      */
    1264        1266 :                     if (strcmp($1, "superuser") == 0)
    1265         172 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(true), @1);
    1266        1094 :                     else if (strcmp($1, "nosuperuser") == 0)
    1267         100 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(false), @1);
    1268         994 :                     else if (strcmp($1, "createrole") == 0)
    1269          92 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(true), @1);
    1270         902 :                     else if (strcmp($1, "nocreaterole") == 0)
    1271          38 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(false), @1);
    1272         864 :                     else if (strcmp($1, "replication") == 0)
    1273         120 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(true), @1);
    1274         744 :                     else if (strcmp($1, "noreplication") == 0)
    1275          96 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(false), @1);
    1276         648 :                     else if (strcmp($1, "createdb") == 0)
    1277          82 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(true), @1);
    1278         566 :                     else if (strcmp($1, "nocreatedb") == 0)
    1279          46 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(false), @1);
    1280         520 :                     else if (strcmp($1, "login") == 0)
    1281         258 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(true), @1);
    1282         262 :                     else if (strcmp($1, "nologin") == 0)
    1283          86 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(false), @1);
    1284         176 :                     else if (strcmp($1, "bypassrls") == 0)
    1285          72 :                         $$ = makeDefElem("bypassrls", (Node *) makeBoolean(true), @1);
    1286         104 :                     else if (strcmp($1, "nobypassrls") == 0)
    1287          68 :                         $$ = makeDefElem("bypassrls", (Node *) makeBoolean(false), @1);
    1288          36 :                     else if (strcmp($1, "noinherit") == 0)
    1289             :                     {
    1290             :                         /*
    1291             :                          * Note that INHERIT is a keyword, so it's handled by main parser, but
    1292             :                          * NOINHERIT is handled here.
    1293             :                          */
    1294          36 :                         $$ = makeDefElem("inherit", (Node *) makeBoolean(false), @1);
    1295             :                     }
    1296             :                     else
    1297           0 :                         ereport(ERROR,
    1298             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    1299             :                                  errmsg("unrecognized role option \"%s\"", $1),
    1300             :                                      parser_errposition(@1)));
    1301             :                 }
    1302             :         ;
    1303             : 
    1304             : CreateOptRoleElem:
    1305        1002 :             AlterOptRoleElem            { $$ = $1; }
    1306             :             /* The following are not supported by ALTER ROLE/USER/GROUP */
    1307             :             | SYSID Iconst
    1308             :                 {
    1309           6 :                     $$ = makeDefElem("sysid", (Node *) makeInteger($2), @1);
    1310             :                 }
    1311             :             | ADMIN role_list
    1312             :                 {
    1313          22 :                     $$ = makeDefElem("adminmembers", (Node *) $2, @1);
    1314             :                 }
    1315             :             | ROLE role_list
    1316             :                 {
    1317          16 :                     $$ = makeDefElem("rolemembers", (Node *) $2, @1);
    1318             :                 }
    1319             :             | IN_P ROLE role_list
    1320             :                 {
    1321         100 :                     $$ = makeDefElem("addroleto", (Node *) $3, @1);
    1322             :                 }
    1323             :             | IN_P GROUP_P role_list
    1324             :                 {
    1325           0 :                     $$ = makeDefElem("addroleto", (Node *) $3, @1);
    1326             :                 }
    1327             :         ;
    1328             : 
    1329             : 
    1330             : /*****************************************************************************
    1331             :  *
    1332             :  * Create a new Postgres DBMS user (role with implied login ability)
    1333             :  *
    1334             :  *****************************************************************************/
    1335             : 
    1336             : CreateUserStmt:
    1337             :             CREATE USER RoleId opt_with OptRoleList
    1338             :                 {
    1339         424 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1340             : 
    1341         424 :                     n->stmt_type = ROLESTMT_USER;
    1342         424 :                     n->role = $3;
    1343         424 :                     n->options = $5;
    1344         424 :                     $$ = (Node *) n;
    1345             :                 }
    1346             :         ;
    1347             : 
    1348             : 
    1349             : /*****************************************************************************
    1350             :  *
    1351             :  * Alter a postgresql DBMS role
    1352             :  *
    1353             :  *****************************************************************************/
    1354             : 
    1355             : AlterRoleStmt:
    1356             :             ALTER ROLE RoleSpec opt_with AlterOptRoleList
    1357             :                  {
    1358         306 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1359             : 
    1360         306 :                     n->role = $3;
    1361         306 :                     n->action = +1;  /* add, if there are members */
    1362         306 :                     n->options = $5;
    1363         306 :                     $$ = (Node *) n;
    1364             :                  }
    1365             :             | ALTER USER RoleSpec opt_with AlterOptRoleList
    1366             :                  {
    1367          86 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1368             : 
    1369          86 :                     n->role = $3;
    1370          86 :                     n->action = +1;  /* add, if there are members */
    1371          86 :                     n->options = $5;
    1372          86 :                     $$ = (Node *) n;
    1373             :                  }
    1374             :         ;
    1375             : 
    1376             : opt_in_database:
    1377          82 :                /* EMPTY */                  { $$ = NULL; }
    1378           0 :             | IN_P DATABASE name    { $$ = $3; }
    1379             :         ;
    1380             : 
    1381             : AlterRoleSetStmt:
    1382             :             ALTER ROLE RoleSpec opt_in_database SetResetClause
    1383             :                 {
    1384          44 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1385             : 
    1386          44 :                     n->role = $3;
    1387          44 :                     n->database = $4;
    1388          44 :                     n->setstmt = $5;
    1389          44 :                     $$ = (Node *) n;
    1390             :                 }
    1391             :             | ALTER ROLE ALL opt_in_database SetResetClause
    1392             :                 {
    1393           4 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1394             : 
    1395           4 :                     n->role = NULL;
    1396           4 :                     n->database = $4;
    1397           4 :                     n->setstmt = $5;
    1398           4 :                     $$ = (Node *) n;
    1399             :                 }
    1400             :             | ALTER USER RoleSpec opt_in_database SetResetClause
    1401             :                 {
    1402          26 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1403             : 
    1404          26 :                     n->role = $3;
    1405          26 :                     n->database = $4;
    1406          26 :                     n->setstmt = $5;
    1407          26 :                     $$ = (Node *) n;
    1408             :                 }
    1409             :             | ALTER USER ALL opt_in_database SetResetClause
    1410             :                 {
    1411           4 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1412             : 
    1413           4 :                     n->role = NULL;
    1414           4 :                     n->database = $4;
    1415           4 :                     n->setstmt = $5;
    1416           4 :                     $$ = (Node *) n;
    1417             :                 }
    1418             :         ;
    1419             : 
    1420             : 
    1421             : /*****************************************************************************
    1422             :  *
    1423             :  * Drop a postgresql DBMS role
    1424             :  *
    1425             :  * XXX Ideally this would have CASCADE/RESTRICT options, but a role
    1426             :  * might own objects in multiple databases, and there is presently no way to
    1427             :  * implement cascading to other databases.  So we always behave as RESTRICT.
    1428             :  *****************************************************************************/
    1429             : 
    1430             : DropRoleStmt:
    1431             :             DROP ROLE role_list
    1432             :                 {
    1433        1038 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1434             : 
    1435        1038 :                     n->missing_ok = false;
    1436        1038 :                     n->roles = $3;
    1437        1038 :                     $$ = (Node *) n;
    1438             :                 }
    1439             :             | DROP ROLE IF_P EXISTS role_list
    1440             :                 {
    1441         134 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1442             : 
    1443         134 :                     n->missing_ok = true;
    1444         134 :                     n->roles = $5;
    1445         134 :                     $$ = (Node *) n;
    1446             :                 }
    1447             :             | DROP USER role_list
    1448             :                 {
    1449         394 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1450             : 
    1451         394 :                     n->missing_ok = false;
    1452         394 :                     n->roles = $3;
    1453         394 :                     $$ = (Node *) n;
    1454             :                 }
    1455             :             | DROP USER IF_P EXISTS role_list
    1456             :                 {
    1457          36 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1458             : 
    1459          36 :                     n->roles = $5;
    1460          36 :                     n->missing_ok = true;
    1461          36 :                     $$ = (Node *) n;
    1462             :                 }
    1463             :             | DROP GROUP_P role_list
    1464             :                 {
    1465          36 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1466             : 
    1467          36 :                     n->missing_ok = false;
    1468          36 :                     n->roles = $3;
    1469          36 :                     $$ = (Node *) n;
    1470             :                 }
    1471             :             | DROP GROUP_P IF_P EXISTS role_list
    1472             :                 {
    1473           6 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1474             : 
    1475           6 :                     n->missing_ok = true;
    1476           6 :                     n->roles = $5;
    1477           6 :                     $$ = (Node *) n;
    1478             :                 }
    1479             :             ;
    1480             : 
    1481             : 
    1482             : /*****************************************************************************
    1483             :  *
    1484             :  * Create a postgresql group (role without login ability)
    1485             :  *
    1486             :  *****************************************************************************/
    1487             : 
    1488             : CreateGroupStmt:
    1489             :             CREATE GROUP_P RoleId opt_with OptRoleList
    1490             :                 {
    1491          24 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1492             : 
    1493          24 :                     n->stmt_type = ROLESTMT_GROUP;
    1494          24 :                     n->role = $3;
    1495          24 :                     n->options = $5;
    1496          24 :                     $$ = (Node *) n;
    1497             :                 }
    1498             :         ;
    1499             : 
    1500             : 
    1501             : /*****************************************************************************
    1502             :  *
    1503             :  * Alter a postgresql group
    1504             :  *
    1505             :  *****************************************************************************/
    1506             : 
    1507             : AlterGroupStmt:
    1508             :             ALTER GROUP_P RoleSpec add_drop USER role_list
    1509             :                 {
    1510          30 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1511             : 
    1512          30 :                     n->role = $3;
    1513          30 :                     n->action = $4;
    1514          30 :                     n->options = list_make1(makeDefElem("rolemembers",
    1515             :                                                         (Node *) $6, @6));
    1516          30 :                     $$ = (Node *) n;
    1517             :                 }
    1518             :         ;
    1519             : 
    1520          80 : add_drop:   ADD_P                                   { $$ = +1; }
    1521         150 :             | DROP                                  { $$ = -1; }
    1522             :         ;
    1523             : 
    1524             : 
    1525             : /*****************************************************************************
    1526             :  *
    1527             :  * Manipulate a schema
    1528             :  *
    1529             :  *****************************************************************************/
    1530             : 
    1531             : CreateSchemaStmt:
    1532             :             CREATE SCHEMA opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
    1533             :                 {
    1534         158 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1535             : 
    1536             :                     /* One can omit the schema name or the authorization id. */
    1537         158 :                     n->schemaname = $3;
    1538         158 :                     n->authrole = $5;
    1539         158 :                     n->schemaElts = $6;
    1540         158 :                     n->if_not_exists = false;
    1541         158 :                     $$ = (Node *) n;
    1542             :                 }
    1543             :             | CREATE SCHEMA ColId OptSchemaEltList
    1544             :                 {
    1545         782 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1546             : 
    1547             :                     /* ...but not both */
    1548         782 :                     n->schemaname = $3;
    1549         782 :                     n->authrole = NULL;
    1550         782 :                     n->schemaElts = $4;
    1551         782 :                     n->if_not_exists = false;
    1552         782 :                     $$ = (Node *) n;
    1553             :                 }
    1554             :             | CREATE SCHEMA IF_P NOT EXISTS opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
    1555             :                 {
    1556          18 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1557             : 
    1558             :                     /* schema name can be omitted here, too */
    1559          18 :                     n->schemaname = $6;
    1560          18 :                     n->authrole = $8;
    1561          18 :                     if ($9 != NIL)
    1562           0 :                         ereport(ERROR,
    1563             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1564             :                                  errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
    1565             :                                  parser_errposition(@9)));
    1566          18 :                     n->schemaElts = $9;
    1567          18 :                     n->if_not_exists = true;
    1568          18 :                     $$ = (Node *) n;
    1569             :                 }
    1570             :             | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
    1571             :                 {
    1572          34 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1573             : 
    1574             :                     /* ...but not here */
    1575          34 :                     n->schemaname = $6;
    1576          34 :                     n->authrole = NULL;
    1577          34 :                     if ($7 != NIL)
    1578           6 :                         ereport(ERROR,
    1579             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1580             :                                  errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
    1581             :                                  parser_errposition(@7)));
    1582          28 :                     n->schemaElts = $7;
    1583          28 :                     n->if_not_exists = true;
    1584          28 :                     $$ = (Node *) n;
    1585             :                 }
    1586             :         ;
    1587             : 
    1588             : OptSchemaEltList:
    1589             :             OptSchemaEltList schema_stmt
    1590             :                 {
    1591         480 :                     if (@$ < 0)          /* see comments for YYLLOC_DEFAULT */
    1592         222 :                         @$ = @2;
    1593         480 :                     $$ = lappend($1, $2);
    1594             :                 }
    1595             :             | /* EMPTY */
    1596         992 :                 { $$ = NIL; }
    1597             :         ;
    1598             : 
    1599             : /*
    1600             :  *  schema_stmt are the ones that can show up inside a CREATE SCHEMA
    1601             :  *  statement (in addition to by themselves).
    1602             :  */
    1603             : schema_stmt:
    1604             :             CreateStmt
    1605             :             | IndexStmt
    1606             :             | CreateSeqStmt
    1607             :             | CreateTrigStmt
    1608             :             | GrantStmt
    1609             :             | ViewStmt
    1610             :         ;
    1611             : 
    1612             : 
    1613             : /*****************************************************************************
    1614             :  *
    1615             :  * Set PG internal variable
    1616             :  *    SET name TO 'var_value'
    1617             :  * Include SQL syntax (thomas 1997-10-22):
    1618             :  *    SET TIME ZONE 'var_value'
    1619             :  *
    1620             :  *****************************************************************************/
    1621             : 
    1622             : VariableSetStmt:
    1623             :             SET set_rest
    1624             :                 {
    1625       18518 :                     VariableSetStmt *n = $2;
    1626             : 
    1627       18518 :                     n->is_local = false;
    1628       18518 :                     $$ = (Node *) n;
    1629             :                 }
    1630             :             | SET LOCAL set_rest
    1631             :                 {
    1632        1108 :                     VariableSetStmt *n = $3;
    1633             : 
    1634        1108 :                     n->is_local = true;
    1635        1108 :                     $$ = (Node *) n;
    1636             :                 }
    1637             :             | SET SESSION set_rest
    1638             :                 {
    1639          80 :                     VariableSetStmt *n = $3;
    1640             : 
    1641          80 :                     n->is_local = false;
    1642          80 :                     $$ = (Node *) n;
    1643             :                 }
    1644             :         ;
    1645             : 
    1646             : set_rest:
    1647             :             TRANSACTION transaction_mode_list
    1648             :                 {
    1649         516 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1650             : 
    1651         516 :                     n->kind = VAR_SET_MULTI;
    1652         516 :                     n->name = "TRANSACTION";
    1653         516 :                     n->args = $2;
    1654         516 :                     $$ = n;
    1655             :                 }
    1656             :             | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
    1657             :                 {
    1658          12 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1659             : 
    1660          12 :                     n->kind = VAR_SET_MULTI;
    1661          12 :                     n->name = "SESSION CHARACTERISTICS";
    1662          12 :                     n->args = $5;
    1663          12 :                     $$ = n;
    1664             :                 }
    1665             :             | set_rest_more
    1666             :             ;
    1667             : 
    1668             : generic_set:
    1669             :             var_name TO var_list
    1670             :                 {
    1671        4340 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1672             : 
    1673        4340 :                     n->kind = VAR_SET_VALUE;
    1674        4340 :                     n->name = $1;
    1675        4340 :                     n->args = $3;
    1676        4340 :                     $$ = n;
    1677             :                 }
    1678             :             | var_name '=' var_list
    1679             :                 {
    1680       12538 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1681             : 
    1682       12538 :                     n->kind = VAR_SET_VALUE;
    1683       12538 :                     n->name = $1;
    1684       12538 :                     n->args = $3;
    1685       12538 :                     $$ = n;
    1686             :                 }
    1687             :             | var_name TO DEFAULT
    1688             :                 {
    1689         126 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1690             : 
    1691         126 :                     n->kind = VAR_SET_DEFAULT;
    1692         126 :                     n->name = $1;
    1693         126 :                     $$ = n;
    1694             :                 }
    1695             :             | var_name '=' DEFAULT
    1696             :                 {
    1697           6 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1698             : 
    1699           6 :                     n->kind = VAR_SET_DEFAULT;
    1700           6 :                     n->name = $1;
    1701           6 :                     $$ = n;
    1702             :                 }
    1703             :         ;
    1704             : 
    1705             : set_rest_more:  /* Generic SET syntaxes: */
    1706       16904 :             generic_set                         {$$ = $1;}
    1707             :             | var_name FROM CURRENT_P
    1708             :                 {
    1709           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1710             : 
    1711           0 :                     n->kind = VAR_SET_CURRENT;
    1712           0 :                     n->name = $1;
    1713           0 :                     $$ = n;
    1714             :                 }
    1715             :             /* Special syntaxes mandated by SQL standard: */
    1716             :             | TIME ZONE zone_value
    1717             :                 {
    1718          94 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1719             : 
    1720          94 :                     n->kind = VAR_SET_VALUE;
    1721          94 :                     n->name = "timezone";
    1722          94 :                     if ($3 != NULL)
    1723          82 :                         n->args = list_make1($3);
    1724             :                     else
    1725          12 :                         n->kind = VAR_SET_DEFAULT;
    1726          94 :                     $$ = n;
    1727             :                 }
    1728             :             | CATALOG_P Sconst
    1729             :                 {
    1730           0 :                     ereport(ERROR,
    1731             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1732             :                              errmsg("current database cannot be changed"),
    1733             :                              parser_errposition(@2)));
    1734             :                     $$ = NULL; /*not reached*/
    1735             :                 }
    1736             :             | SCHEMA Sconst
    1737             :                 {
    1738           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1739             : 
    1740           0 :                     n->kind = VAR_SET_VALUE;
    1741           0 :                     n->name = "search_path";
    1742           0 :                     n->args = list_make1(makeStringConst($2, @2));
    1743           0 :                     $$ = n;
    1744             :                 }
    1745             :             | NAMES opt_encoding
    1746             :                 {
    1747           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1748             : 
    1749           0 :                     n->kind = VAR_SET_VALUE;
    1750           0 :                     n->name = "client_encoding";
    1751           0 :                     if ($2 != NULL)
    1752           0 :                         n->args = list_make1(makeStringConst($2, @2));
    1753             :                     else
    1754           0 :                         n->kind = VAR_SET_DEFAULT;
    1755           0 :                     $$ = n;
    1756             :                 }
    1757             :             | ROLE NonReservedWord_or_Sconst
    1758             :                 {
    1759         822 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1760             : 
    1761         822 :                     n->kind = VAR_SET_VALUE;
    1762         822 :                     n->name = "role";
    1763         822 :                     n->args = list_make1(makeStringConst($2, @2));
    1764         822 :                     $$ = n;
    1765             :                 }
    1766             :             | SESSION AUTHORIZATION NonReservedWord_or_Sconst
    1767             :                 {
    1768        2506 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1769             : 
    1770        2506 :                     n->kind = VAR_SET_VALUE;
    1771        2506 :                     n->name = "session_authorization";
    1772        2506 :                     n->args = list_make1(makeStringConst($3, @3));
    1773        2506 :                     $$ = n;
    1774             :                 }
    1775             :             | SESSION AUTHORIZATION DEFAULT
    1776             :                 {
    1777           4 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1778             : 
    1779           4 :                     n->kind = VAR_SET_DEFAULT;
    1780           4 :                     n->name = "session_authorization";
    1781           4 :                     $$ = n;
    1782             :                 }
    1783             :             | XML_P OPTION document_or_content
    1784             :                 {
    1785          12 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1786             : 
    1787          12 :                     n->kind = VAR_SET_VALUE;
    1788          12 :                     n->name = "xmloption";
    1789          12 :                     n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
    1790          12 :                     $$ = n;
    1791             :                 }
    1792             :             /* Special syntaxes invented by PostgreSQL: */
    1793             :             | TRANSACTION SNAPSHOT Sconst
    1794             :                 {
    1795          44 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1796             : 
    1797          44 :                     n->kind = VAR_SET_MULTI;
    1798          44 :                     n->name = "TRANSACTION SNAPSHOT";
    1799          44 :                     n->args = list_make1(makeStringConst($3, @3));
    1800          44 :                     $$ = n;
    1801             :                 }
    1802             :         ;
    1803             : 
    1804       21062 : var_name:   ColId                               { $$ = $1; }
    1805             :             | var_name '.' ColId
    1806         386 :                 { $$ = psprintf("%s.%s", $1, $3); }
    1807             :         ;
    1808             : 
    1809       16878 : var_list:   var_value                               { $$ = list_make1($1); }
    1810         262 :             | var_list ',' var_value                { $$ = lappend($1, $3); }
    1811             :         ;
    1812             : 
    1813             : var_value:  opt_boolean_or_string
    1814       12904 :                 { $$ = makeStringConst($1, @1); }
    1815             :             | NumericOnly
    1816        4236 :                 { $$ = makeAConst($1, @1); }
    1817             :         ;
    1818             : 
    1819           0 : iso_level:  READ UNCOMMITTED                        { $$ = "read uncommitted"; }
    1820         886 :             | READ COMMITTED                        { $$ = "read committed"; }
    1821        2454 :             | REPEATABLE READ                       { $$ = "repeatable read"; }
    1822        3220 :             | SERIALIZABLE                          { $$ = "serializable"; }
    1823             :         ;
    1824             : 
    1825             : opt_boolean_or_string:
    1826         550 :             TRUE_P                                  { $$ = "true"; }
    1827        1258 :             | FALSE_P                               { $$ = "false"; }
    1828        1930 :             | ON                                    { $$ = "on"; }
    1829             :             /*
    1830             :              * OFF is also accepted as a boolean value, but is handled by
    1831             :              * the NonReservedWord rule.  The action for booleans and strings
    1832             :              * is the same, so we don't need to distinguish them here.
    1833             :              */
    1834       25148 :             | NonReservedWord_or_Sconst             { $$ = $1; }
    1835             :         ;
    1836             : 
    1837             : /* Timezone values can be:
    1838             :  * - a string such as 'pst8pdt'
    1839             :  * - an identifier such as "pst8pdt"
    1840             :  * - an integer or floating point number
    1841             :  * - a time interval per SQL99
    1842             :  * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
    1843             :  * so use IDENT (meaning we reject anything that is a key word).
    1844             :  */
    1845             : zone_value:
    1846             :             Sconst
    1847             :                 {
    1848          54 :                     $$ = makeStringConst($1, @1);
    1849             :                 }
    1850             :             | IDENT
    1851             :                 {
    1852           4 :                     $$ = makeStringConst($1, @1);
    1853             :                 }
    1854             :             | ConstInterval Sconst opt_interval
    1855             :                 {
    1856           0 :                     TypeName   *t = $1;
    1857             : 
    1858           0 :                     if ($3 != NIL)
    1859             :                     {
    1860           0 :                         A_Const    *n = (A_Const *) linitial($3);
    1861             : 
    1862           0 :                         if ((n->val.ival.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
    1863           0 :                             ereport(ERROR,
    1864             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    1865             :                                      errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
    1866             :                                      parser_errposition(@3)));
    1867             :                     }
    1868           0 :                     t->typmods = $3;
    1869           0 :                     $$ = makeStringConstCast($2, @2, t);
    1870             :                 }
    1871             :             | ConstInterval '(' Iconst ')' Sconst
    1872             :                 {
    1873           0 :                     TypeName   *t = $1;
    1874             : 
    1875           0 :                     t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
    1876             :                                             makeIntConst($3, @3));
    1877           0 :                     $$ = makeStringConstCast($5, @5, t);
    1878             :                 }
    1879          24 :             | NumericOnly                           { $$ = makeAConst($1, @1); }
    1880          12 :             | DEFAULT                               { $$ = NULL; }
    1881           0 :             | LOCAL                                 { $$ = NULL; }
    1882             :         ;
    1883             : 
    1884             : opt_encoding:
    1885           0 :             Sconst                                  { $$ = $1; }
    1886           0 :             | DEFAULT                               { $$ = NULL; }
    1887           0 :             | /*EMPTY*/                             { $$ = NULL; }
    1888             :         ;
    1889             : 
    1890             : NonReservedWord_or_Sconst:
    1891       44410 :             NonReservedWord                         { $$ = $1; }
    1892        4746 :             | Sconst                                { $$ = $1; }
    1893             :         ;
    1894             : 
    1895             : VariableResetStmt:
    1896        3986 :             RESET reset_rest                        { $$ = (Node *) $2; }
    1897             :         ;
    1898             : 
    1899             : reset_rest:
    1900        3218 :             generic_reset                           { $$ = $1; }
    1901             :             | TIME ZONE
    1902             :                 {
    1903          12 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1904             : 
    1905          12 :                     n->kind = VAR_RESET;
    1906          12 :                     n->name = "timezone";
    1907          12 :                     $$ = n;
    1908             :                 }
    1909             :             | TRANSACTION ISOLATION LEVEL
    1910             :                 {
    1911           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1912             : 
    1913           0 :                     n->kind = VAR_RESET;
    1914           0 :                     n->name = "transaction_isolation";
    1915           0 :                     $$ = n;
    1916             :                 }
    1917             :             | SESSION AUTHORIZATION
    1918             :                 {
    1919         756 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1920             : 
    1921         756 :                     n->kind = VAR_RESET;
    1922         756 :                     n->name = "session_authorization";
    1923         756 :                     $$ = n;
    1924             :                 }
    1925             :         ;
    1926             : 
    1927             : generic_reset:
    1928             :             var_name
    1929             :                 {
    1930        3250 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1931             : 
    1932        3250 :                     n->kind = VAR_RESET;
    1933        3250 :                     n->name = $1;
    1934        3250 :                     $$ = n;
    1935             :                 }
    1936             :             | ALL
    1937             :                 {
    1938          16 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1939             : 
    1940          16 :                     n->kind = VAR_RESET_ALL;
    1941          16 :                     $$ = n;
    1942             :                 }
    1943             :         ;
    1944             : 
    1945             : /* SetResetClause allows SET or RESET without LOCAL */
    1946             : SetResetClause:
    1947        1108 :             SET set_rest                    { $$ = $2; }
    1948          28 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    1949             :         ;
    1950             : 
    1951             : /* SetResetClause allows SET or RESET without LOCAL */
    1952             : FunctionSetResetClause:
    1953         100 :             SET set_rest_more               { $$ = $2; }
    1954          12 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    1955             :         ;
    1956             : 
    1957             : 
    1958             : VariableShowStmt:
    1959             :             SHOW var_name
    1960             :                 {
    1961         802 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1962             : 
    1963         802 :                     n->name = $2;
    1964         802 :                     $$ = (Node *) n;
    1965             :                 }
    1966             :             | SHOW TIME ZONE
    1967             :                 {
    1968          10 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1969             : 
    1970          10 :                     n->name = "timezone";
    1971          10 :                     $$ = (Node *) n;
    1972             :                 }
    1973             :             | SHOW TRANSACTION ISOLATION LEVEL
    1974             :                 {
    1975           4 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1976             : 
    1977           4 :                     n->name = "transaction_isolation";
    1978           4 :                     $$ = (Node *) n;
    1979             :                 }
    1980             :             | SHOW SESSION AUTHORIZATION
    1981             :                 {
    1982           0 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1983             : 
    1984           0 :                     n->name = "session_authorization";
    1985           0 :                     $$ = (Node *) n;
    1986             :                 }
    1987             :             | SHOW ALL
    1988             :                 {
    1989           0 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1990             : 
    1991           0 :                     n->name = "all";
    1992           0 :                     $$ = (Node *) n;
    1993             :                 }
    1994             :         ;
    1995             : 
    1996             : 
    1997             : ConstraintsSetStmt:
    1998             :             SET CONSTRAINTS constraints_set_list constraints_set_mode
    1999             :                 {
    2000         104 :                     ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
    2001             : 
    2002         104 :                     n->constraints = $3;
    2003         104 :                     n->deferred = $4;
    2004         104 :                     $$ = (Node *) n;
    2005             :                 }
    2006             :         ;
    2007             : 
    2008             : constraints_set_list:
    2009          56 :             ALL                                     { $$ = NIL; }
    2010          48 :             | qualified_name_list                   { $$ = $1; }
    2011             :         ;
    2012             : 
    2013             : constraints_set_mode:
    2014          68 :             DEFERRED                                { $$ = true; }
    2015          36 :             | IMMEDIATE                             { $$ = false; }
    2016             :         ;
    2017             : 
    2018             : 
    2019             : /*
    2020             :  * Checkpoint statement
    2021             :  */
    2022             : CheckPointStmt:
    2023             :             CHECKPOINT
    2024             :                 {
    2025         184 :                     CheckPointStmt *n = makeNode(CheckPointStmt);
    2026             : 
    2027         184 :                     $$ = (Node *) n;
    2028             :                 }
    2029             :         ;
    2030             : 
    2031             : 
    2032             : /*****************************************************************************
    2033             :  *
    2034             :  * DISCARD { ALL | TEMP | PLANS | SEQUENCES }
    2035             :  *
    2036             :  *****************************************************************************/
    2037             : 
    2038             : DiscardStmt:
    2039             :             DISCARD ALL
    2040             :                 {
    2041           6 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2042             : 
    2043           6 :                     n->target = DISCARD_ALL;
    2044           6 :                     $$ = (Node *) n;
    2045             :                 }
    2046             :             | DISCARD TEMP
    2047             :                 {
    2048           8 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2049             : 
    2050           8 :                     n->target = DISCARD_TEMP;
    2051           8 :                     $$ = (Node *) n;
    2052             :                 }
    2053             :             | DISCARD TEMPORARY
    2054             :                 {
    2055           0 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2056             : 
    2057           0 :                     n->target = DISCARD_TEMP;
    2058           0 :                     $$ = (Node *) n;
    2059             :                 }
    2060             :             | DISCARD PLANS
    2061             :                 {
    2062           4 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2063             : 
    2064           4 :                     n->target = DISCARD_PLANS;
    2065           4 :                     $$ = (Node *) n;
    2066             :                 }
    2067             :             | DISCARD SEQUENCES
    2068             :                 {
    2069          12 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2070             : 
    2071          12 :                     n->target = DISCARD_SEQUENCES;
    2072          12 :                     $$ = (Node *) n;
    2073             :                 }
    2074             : 
    2075             :         ;
    2076             : 
    2077             : 
    2078             : /*****************************************************************************
    2079             :  *
    2080             :  *  ALTER [ TABLE | INDEX | SEQUENCE | VIEW | MATERIALIZED VIEW | FOREIGN TABLE ] variations
    2081             :  *
    2082             :  * Note: we accept all subcommands for each of the variants, and sort
    2083             :  * out what's really legal at execution time.
    2084             :  *****************************************************************************/
    2085             : 
    2086             : AlterTableStmt:
    2087             :             ALTER TABLE relation_expr alter_table_cmds
    2088             :                 {
    2089       22210 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2090             : 
    2091       22210 :                     n->relation = $3;
    2092       22210 :                     n->cmds = $4;
    2093       22210 :                     n->objtype = OBJECT_TABLE;
    2094       22210 :                     n->missing_ok = false;
    2095       22210 :                     $$ = (Node *) n;
    2096             :                 }
    2097             :         |   ALTER TABLE IF_P EXISTS relation_expr alter_table_cmds
    2098             :                 {
    2099          54 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2100             : 
    2101          54 :                     n->relation = $5;
    2102          54 :                     n->cmds = $6;
    2103          54 :                     n->objtype = OBJECT_TABLE;
    2104          54 :                     n->missing_ok = true;
    2105          54 :                     $$ = (Node *) n;
    2106             :                 }
    2107             :         |   ALTER TABLE relation_expr partition_cmd
    2108             :                 {
    2109        3192 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2110             : 
    2111        3192 :                     n->relation = $3;
    2112        3192 :                     n->cmds = list_make1($4);
    2113        3192 :                     n->objtype = OBJECT_TABLE;
    2114        3192 :                     n->missing_ok = false;
    2115        3192 :                     $$ = (Node *) n;
    2116             :                 }
    2117             :         |   ALTER TABLE IF_P EXISTS relation_expr partition_cmd
    2118             :                 {
    2119           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2120             : 
    2121           0 :                     n->relation = $5;
    2122           0 :                     n->cmds = list_make1($6);
    2123           0 :                     n->objtype = OBJECT_TABLE;
    2124           0 :                     n->missing_ok = true;
    2125           0 :                     $$ = (Node *) n;
    2126             :                 }
    2127             :         |   ALTER TABLE ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2128             :                 {
    2129             :                     AlterTableMoveAllStmt *n =
    2130          12 :                         makeNode(AlterTableMoveAllStmt);
    2131             : 
    2132          12 :                     n->orig_tablespacename = $6;
    2133          12 :                     n->objtype = OBJECT_TABLE;
    2134          12 :                     n->roles = NIL;
    2135          12 :                     n->new_tablespacename = $9;
    2136          12 :                     n->nowait = $10;
    2137          12 :                     $$ = (Node *) n;
    2138             :                 }
    2139             :         |   ALTER TABLE ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2140             :                 {
    2141             :                     AlterTableMoveAllStmt *n =
    2142           0 :                         makeNode(AlterTableMoveAllStmt);
    2143             : 
    2144           0 :                     n->orig_tablespacename = $6;
    2145           0 :                     n->objtype = OBJECT_TABLE;
    2146           0 :                     n->roles = $9;
    2147           0 :                     n->new_tablespacename = $12;
    2148           0 :                     n->nowait = $13;
    2149           0 :                     $$ = (Node *) n;
    2150             :                 }
    2151             :         |   ALTER INDEX qualified_name alter_table_cmds
    2152             :                 {
    2153         226 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2154             : 
    2155         226 :                     n->relation = $3;
    2156         226 :                     n->cmds = $4;
    2157         226 :                     n->objtype = OBJECT_INDEX;
    2158         226 :                     n->missing_ok = false;
    2159         226 :                     $$ = (Node *) n;
    2160             :                 }
    2161             :         |   ALTER INDEX IF_P EXISTS qualified_name alter_table_cmds
    2162             :                 {
    2163           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2164             : 
    2165           0 :                     n->relation = $5;
    2166           0 :                     n->cmds = $6;
    2167           0 :                     n->objtype = OBJECT_INDEX;
    2168           0 :                     n->missing_ok = true;
    2169           0 :                     $$ = (Node *) n;
    2170             :                 }
    2171             :         |   ALTER INDEX qualified_name index_partition_cmd
    2172             :                 {
    2173         390 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2174             : 
    2175         390 :                     n->relation = $3;
    2176         390 :                     n->cmds = list_make1($4);
    2177         390 :                     n->objtype = OBJECT_INDEX;
    2178         390 :                     n->missing_ok = false;
    2179         390 :                     $$ = (Node *) n;
    2180             :                 }
    2181             :         |   ALTER INDEX ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2182             :                 {
    2183             :                     AlterTableMoveAllStmt *n =
    2184           6 :                         makeNode(AlterTableMoveAllStmt);
    2185             : 
    2186           6 :                     n->orig_tablespacename = $6;
    2187           6 :                     n->objtype = OBJECT_INDEX;
    2188           6 :                     n->roles = NIL;
    2189           6 :                     n->new_tablespacename = $9;
    2190           6 :                     n->nowait = $10;
    2191           6 :                     $$ = (Node *) n;
    2192             :                 }
    2193             :         |   ALTER INDEX ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2194             :                 {
    2195             :                     AlterTableMoveAllStmt *n =
    2196           0 :                         makeNode(AlterTableMoveAllStmt);
    2197             : 
    2198           0 :                     n->orig_tablespacename = $6;
    2199           0 :                     n->objtype = OBJECT_INDEX;
    2200           0 :                     n->roles = $9;
    2201           0 :                     n->new_tablespacename = $12;
    2202           0 :                     n->nowait = $13;
    2203           0 :                     $$ = (Node *) n;
    2204             :                 }
    2205             :         |   ALTER SEQUENCE qualified_name alter_table_cmds
    2206             :                 {
    2207          64 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2208             : 
    2209          64 :                     n->relation = $3;
    2210          64 :                     n->cmds = $4;
    2211          64 :                     n->objtype = OBJECT_SEQUENCE;
    2212          64 :                     n->missing_ok = false;
    2213          64 :                     $$ = (Node *) n;
    2214             :                 }
    2215             :         |   ALTER SEQUENCE IF_P EXISTS qualified_name alter_table_cmds
    2216             :                 {
    2217           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2218             : 
    2219           0 :                     n->relation = $5;
    2220           0 :                     n->cmds = $6;
    2221           0 :                     n->objtype = OBJECT_SEQUENCE;
    2222           0 :                     n->missing_ok = true;
    2223           0 :                     $$ = (Node *) n;
    2224             :                 }
    2225             :         |   ALTER VIEW qualified_name alter_table_cmds
    2226             :                 {
    2227         240 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2228             : 
    2229         240 :                     n->relation = $3;
    2230         240 :                     n->cmds = $4;
    2231         240 :                     n->objtype = OBJECT_VIEW;
    2232         240 :                     n->missing_ok = false;
    2233         240 :                     $$ = (Node *) n;
    2234             :                 }
    2235             :         |   ALTER VIEW IF_P EXISTS qualified_name alter_table_cmds
    2236             :                 {
    2237           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2238             : 
    2239           0 :                     n->relation = $5;
    2240           0 :                     n->cmds = $6;
    2241           0 :                     n->objtype = OBJECT_VIEW;
    2242           0 :                     n->missing_ok = true;
    2243           0 :                     $$ = (Node *) n;
    2244             :                 }
    2245             :         |   ALTER MATERIALIZED VIEW qualified_name alter_table_cmds
    2246             :                 {
    2247          48 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2248             : 
    2249          48 :                     n->relation = $4;
    2250          48 :                     n->cmds = $5;
    2251          48 :                     n->objtype = OBJECT_MATVIEW;
    2252          48 :                     n->missing_ok = false;
    2253          48 :                     $$ = (Node *) n;
    2254             :                 }
    2255             :         |   ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name alter_table_cmds
    2256             :                 {
    2257           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2258             : 
    2259           0 :                     n->relation = $6;
    2260           0 :                     n->cmds = $7;
    2261           0 :                     n->objtype = OBJECT_MATVIEW;
    2262           0 :                     n->missing_ok = true;
    2263           0 :                     $$ = (Node *) n;
    2264             :                 }
    2265             :         |   ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2266             :                 {
    2267             :                     AlterTableMoveAllStmt *n =
    2268          12 :                         makeNode(AlterTableMoveAllStmt);
    2269             : 
    2270          12 :                     n->orig_tablespacename = $7;
    2271          12 :                     n->objtype = OBJECT_MATVIEW;
    2272          12 :                     n->roles = NIL;
    2273          12 :                     n->new_tablespacename = $10;
    2274          12 :                     n->nowait = $11;
    2275          12 :                     $$ = (Node *) n;
    2276             :                 }
    2277             :         |   ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2278             :                 {
    2279             :                     AlterTableMoveAllStmt *n =
    2280           0 :                         makeNode(AlterTableMoveAllStmt);
    2281             : 
    2282           0 :                     n->orig_tablespacename = $7;
    2283           0 :                     n->objtype = OBJECT_MATVIEW;
    2284           0 :                     n->roles = $10;
    2285           0 :                     n->new_tablespacename = $13;
    2286           0 :                     n->nowait = $14;
    2287           0 :                     $$ = (Node *) n;
    2288             :                 }
    2289             :         |   ALTER FOREIGN TABLE relation_expr alter_table_cmds
    2290             :                 {
    2291         366 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2292             : 
    2293         366 :                     n->relation = $4;
    2294         366 :                     n->cmds = $5;
    2295         366 :                     n->objtype = OBJECT_FOREIGN_TABLE;
    2296         366 :                     n->missing_ok = false;
    2297         366 :                     $$ = (Node *) n;
    2298             :                 }
    2299             :         |   ALTER FOREIGN TABLE IF_P EXISTS relation_expr alter_table_cmds
    2300             :                 {
    2301         108 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2302             : 
    2303         108 :                     n->relation = $6;
    2304         108 :                     n->cmds = $7;
    2305         108 :                     n->objtype = OBJECT_FOREIGN_TABLE;
    2306         108 :                     n->missing_ok = true;
    2307         108 :                     $$ = (Node *) n;
    2308             :                 }
    2309             :         ;
    2310             : 
    2311             : alter_table_cmds:
    2312       23316 :             alter_table_cmd                         { $$ = list_make1($1); }
    2313         930 :             | alter_table_cmds ',' alter_table_cmd  { $$ = lappend($1, $3); }
    2314             :         ;
    2315             : 
    2316             : partitions_list:
    2317         270 :             SinglePartitionSpec                         { $$ = list_make1($1); }
    2318         546 :             | partitions_list ',' SinglePartitionSpec   { $$ = lappend($1, $3); }
    2319             :         ;
    2320             : 
    2321             : SinglePartitionSpec:
    2322             :             PARTITION qualified_name PartitionBoundSpec
    2323             :                 {
    2324         816 :                     SinglePartitionSpec *n = makeNode(SinglePartitionSpec);
    2325             : 
    2326         816 :                     n->name = $2;
    2327         816 :                     n->bound = $3;
    2328             : 
    2329         816 :                     $$ = n;
    2330             :                 }
    2331             :         ;
    2332             : 
    2333             : partition_cmd:
    2334             :             /* ALTER TABLE <name> ATTACH PARTITION <table_name> FOR VALUES */
    2335             :             ATTACH PARTITION qualified_name PartitionBoundSpec
    2336             :                 {
    2337        2218 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2338        2218 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2339             : 
    2340        2218 :                     n->subtype = AT_AttachPartition;
    2341        2218 :                     cmd->name = $3;
    2342        2218 :                     cmd->bound = $4;
    2343        2218 :                     cmd->partlist = NULL;
    2344        2218 :                     cmd->concurrent = false;
    2345        2218 :                     n->def = (Node *) cmd;
    2346             : 
    2347        2218 :                     $$ = (Node *) n;
    2348             :                 }
    2349             :             /* ALTER TABLE <name> DETACH PARTITION <partition_name> [CONCURRENTLY] */
    2350             :             | DETACH PARTITION qualified_name opt_concurrently
    2351             :                 {
    2352         534 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2353         534 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2354             : 
    2355         534 :                     n->subtype = AT_DetachPartition;
    2356         534 :                     cmd->name = $3;
    2357         534 :                     cmd->bound = NULL;
    2358         534 :                     cmd->partlist = NULL;
    2359         534 :                     cmd->concurrent = $4;
    2360         534 :                     n->def = (Node *) cmd;
    2361             : 
    2362         534 :                     $$ = (Node *) n;
    2363             :                 }
    2364             :             | DETACH PARTITION qualified_name FINALIZE
    2365             :                 {
    2366          14 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2367          14 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2368             : 
    2369          14 :                     n->subtype = AT_DetachPartitionFinalize;
    2370          14 :                     cmd->name = $3;
    2371          14 :                     cmd->bound = NULL;
    2372          14 :                     cmd->partlist = NULL;
    2373          14 :                     cmd->concurrent = false;
    2374          14 :                     n->def = (Node *) cmd;
    2375          14 :                     $$ = (Node *) n;
    2376             :                 }
    2377             :             /* ALTER TABLE <name> SPLIT PARTITION <partition_name> INTO () */
    2378             :             | SPLIT PARTITION qualified_name INTO '(' partitions_list ')'
    2379             :                 {
    2380         270 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2381         270 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2382             : 
    2383         270 :                     n->subtype = AT_SplitPartition;
    2384         270 :                     cmd->name = $3;
    2385         270 :                     cmd->bound = NULL;
    2386         270 :                     cmd->partlist = $6;
    2387         270 :                     cmd->concurrent = false;
    2388         270 :                     n->def = (Node *) cmd;
    2389         270 :                     $$ = (Node *) n;
    2390             :                 }
    2391             :             /* ALTER TABLE <name> MERGE PARTITIONS () INTO <partition_name> */
    2392             :             | MERGE PARTITIONS '(' qualified_name_list ')' INTO qualified_name
    2393             :                 {
    2394         156 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2395         156 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2396             : 
    2397         156 :                     n->subtype = AT_MergePartitions;
    2398         156 :                     cmd->name = $7;
    2399         156 :                     cmd->bound = NULL;
    2400         156 :                     cmd->partlist = $4;
    2401         156 :                     cmd->concurrent = false;
    2402         156 :                     n->def = (Node *) cmd;
    2403         156 :                     $$ = (Node *) n;
    2404             :                 }
    2405             :         ;
    2406             : 
    2407             : index_partition_cmd:
    2408             :             /* ALTER INDEX <name> ATTACH PARTITION <index_name> */
    2409             :             ATTACH PARTITION qualified_name
    2410             :                 {
    2411         390 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2412         390 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2413             : 
    2414         390 :                     n->subtype = AT_AttachPartition;
    2415         390 :                     cmd->name = $3;
    2416         390 :                     cmd->bound = NULL;
    2417         390 :                     cmd->partlist = NULL;
    2418         390 :                     cmd->concurrent = false;
    2419         390 :                     n->def = (Node *) cmd;
    2420             : 
    2421         390 :                     $$ = (Node *) n;
    2422             :                 }
    2423             :         ;
    2424             : 
    2425             : alter_table_cmd:
    2426             :             /* ALTER TABLE <name> ADD <coldef> */
    2427             :             ADD_P columnDef
    2428             :                 {
    2429         164 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2430             : 
    2431         164 :                     n->subtype = AT_AddColumn;
    2432         164 :                     n->def = $2;
    2433         164 :                     n->missing_ok = false;
    2434         164 :                     $$ = (Node *) n;
    2435             :                 }
    2436             :             /* ALTER TABLE <name> ADD IF NOT EXISTS <coldef> */
    2437             :             | ADD_P IF_P NOT EXISTS columnDef
    2438             :                 {
    2439           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2440             : 
    2441           0 :                     n->subtype = AT_AddColumn;
    2442           0 :                     n->def = $5;
    2443           0 :                     n->missing_ok = true;
    2444           0 :                     $$ = (Node *) n;
    2445             :                 }
    2446             :             /* ALTER TABLE <name> ADD COLUMN <coldef> */
    2447             :             | ADD_P COLUMN columnDef
    2448             :                 {
    2449        1722 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2450             : 
    2451        1722 :                     n->subtype = AT_AddColumn;
    2452        1722 :                     n->def = $3;
    2453        1722 :                     n->missing_ok = false;
    2454        1722 :                     $$ = (Node *) n;
    2455             :                 }
    2456             :             /* ALTER TABLE <name> ADD COLUMN IF NOT EXISTS <coldef> */
    2457             :             | ADD_P COLUMN IF_P NOT EXISTS columnDef
    2458             :                 {
    2459          60 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2460             : 
    2461          60 :                     n->subtype = AT_AddColumn;
    2462          60 :                     n->def = $6;
    2463          60 :                     n->missing_ok = true;
    2464          60 :                     $$ = (Node *) n;
    2465             :                 }
    2466             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
    2467             :             | ALTER opt_column ColId alter_column_default
    2468             :                 {
    2469         522 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2470             : 
    2471         522 :                     n->subtype = AT_ColumnDefault;
    2472         522 :                     n->name = $3;
    2473         522 :                     n->def = $4;
    2474         522 :                     $$ = (Node *) n;
    2475             :                 }
    2476             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
    2477             :             | ALTER opt_column ColId DROP NOT NULL_P
    2478             :                 {
    2479         282 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2480             : 
    2481         282 :                     n->subtype = AT_DropNotNull;
    2482         282 :                     n->name = $3;
    2483         282 :                     $$ = (Node *) n;
    2484             :                 }
    2485             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
    2486             :             | ALTER opt_column ColId SET NOT NULL_P
    2487             :                 {
    2488         398 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2489             : 
    2490         398 :                     n->subtype = AT_SetNotNull;
    2491         398 :                     n->name = $3;
    2492         398 :                     $$ = (Node *) n;
    2493             :                 }
    2494             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET EXPRESSION AS <expr> */
    2495             :             | ALTER opt_column ColId SET EXPRESSION AS '(' a_expr ')'
    2496             :                 {
    2497          66 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2498             : 
    2499          66 :                     n->subtype = AT_SetExpression;
    2500          66 :                     n->name = $3;
    2501          66 :                     n->def = $8;
    2502          66 :                     $$ = (Node *) n;
    2503             :                 }
    2504             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
    2505             :             | ALTER opt_column ColId DROP EXPRESSION
    2506             :                 {
    2507          32 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2508             : 
    2509          32 :                     n->subtype = AT_DropExpression;
    2510          32 :                     n->name = $3;
    2511          32 :                     $$ = (Node *) n;
    2512             :                 }
    2513             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION IF EXISTS */
    2514             :             | ALTER opt_column ColId DROP EXPRESSION IF_P EXISTS
    2515             :                 {
    2516           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2517             : 
    2518           6 :                     n->subtype = AT_DropExpression;
    2519           6 :                     n->name = $3;
    2520           6 :                     n->missing_ok = true;
    2521           6 :                     $$ = (Node *) n;
    2522             :                 }
    2523             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS */
    2524             :             | ALTER opt_column ColId SET STATISTICS set_statistics_value
    2525             :                 {
    2526          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2527             : 
    2528          62 :                     n->subtype = AT_SetStatistics;
    2529          62 :                     n->name = $3;
    2530          62 :                     n->def = $6;
    2531          62 :                     $$ = (Node *) n;
    2532             :                 }
    2533             :             /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS */
    2534             :             | ALTER opt_column Iconst SET STATISTICS set_statistics_value
    2535             :                 {
    2536          70 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2537             : 
    2538          70 :                     if ($3 <= 0 || $3 > PG_INT16_MAX)
    2539           6 :                         ereport(ERROR,
    2540             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
    2541             :                                  errmsg("column number must be in range from 1 to %d", PG_INT16_MAX),
    2542             :                                  parser_errposition(@3)));
    2543             : 
    2544          64 :                     n->subtype = AT_SetStatistics;
    2545          64 :                     n->num = (int16) $3;
    2546          64 :                     n->def = $6;
    2547          64 :                     $$ = (Node *) n;
    2548             :                 }
    2549             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
    2550             :             | ALTER opt_column ColId SET reloptions
    2551             :                 {
    2552          38 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2553             : 
    2554          38 :                     n->subtype = AT_SetOptions;
    2555          38 :                     n->name = $3;
    2556          38 :                     n->def = (Node *) $5;
    2557          38 :                     $$ = (Node *) n;
    2558             :                 }
    2559             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> RESET ( column_parameter [, ... ] ) */
    2560             :             | ALTER opt_column ColId RESET reloptions
    2561             :                 {
    2562           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2563             : 
    2564           6 :                     n->subtype = AT_ResetOptions;
    2565           6 :                     n->name = $3;
    2566           6 :                     n->def = (Node *) $5;
    2567           6 :                     $$ = (Node *) n;
    2568             :                 }
    2569             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
    2570             :             | ALTER opt_column ColId SET column_storage
    2571             :                 {
    2572         212 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2573             : 
    2574         212 :                     n->subtype = AT_SetStorage;
    2575         212 :                     n->name = $3;
    2576         212 :                     n->def = (Node *) makeString($5);
    2577         212 :                     $$ = (Node *) n;
    2578             :                 }
    2579             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET COMPRESSION <cm> */
    2580             :             | ALTER opt_column ColId SET column_compression
    2581             :                 {
    2582          68 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2583             : 
    2584          68 :                     n->subtype = AT_SetCompression;
    2585          68 :                     n->name = $3;
    2586          68 :                     n->def = (Node *) makeString($5);
    2587          68 :                     $$ = (Node *) n;
    2588             :                 }
    2589             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> ADD GENERATED ... AS IDENTITY ... */
    2590             :             | ALTER opt_column ColId ADD_P GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    2591             :                 {
    2592         158 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2593         158 :                     Constraint *c = makeNode(Constraint);
    2594             : 
    2595         158 :                     c->contype = CONSTR_IDENTITY;
    2596         158 :                     c->generated_when = $6;
    2597         158 :                     c->options = $9;
    2598         158 :                     c->location = @5;
    2599             : 
    2600         158 :                     n->subtype = AT_AddIdentity;
    2601         158 :                     n->name = $3;
    2602         158 :                     n->def = (Node *) c;
    2603             : 
    2604         158 :                     $$ = (Node *) n;
    2605             :                 }
    2606             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET <sequence options>/RESET */
    2607             :             | ALTER opt_column ColId alter_identity_column_option_list
    2608             :                 {
    2609          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2610             : 
    2611          62 :                     n->subtype = AT_SetIdentity;
    2612          62 :                     n->name = $3;
    2613          62 :                     n->def = (Node *) $4;
    2614          62 :                     $$ = (Node *) n;
    2615             :                 }
    2616             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY */
    2617             :             | ALTER opt_column ColId DROP IDENTITY_P
    2618             :                 {
    2619          56 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2620             : 
    2621          56 :                     n->subtype = AT_DropIdentity;
    2622          56 :                     n->name = $3;
    2623          56 :                     n->missing_ok = false;
    2624          56 :                     $$ = (Node *) n;
    2625             :                 }
    2626             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY IF EXISTS */
    2627             :             | ALTER opt_column ColId DROP IDENTITY_P IF_P EXISTS
    2628             :                 {
    2629           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2630             : 
    2631           6 :                     n->subtype = AT_DropIdentity;
    2632           6 :                     n->name = $3;
    2633           6 :                     n->missing_ok = true;
    2634           6 :                     $$ = (Node *) n;
    2635             :                 }
    2636             :             /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
    2637             :             | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
    2638             :                 {
    2639          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2640             : 
    2641          18 :                     n->subtype = AT_DropColumn;
    2642          18 :                     n->name = $5;
    2643          18 :                     n->behavior = $6;
    2644          18 :                     n->missing_ok = true;
    2645          18 :                     $$ = (Node *) n;
    2646             :                 }
    2647             :             /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
    2648             :             | DROP opt_column ColId opt_drop_behavior
    2649             :                 {
    2650        1542 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2651             : 
    2652        1542 :                     n->subtype = AT_DropColumn;
    2653        1542 :                     n->name = $3;
    2654        1542 :                     n->behavior = $4;
    2655        1542 :                     n->missing_ok = false;
    2656        1542 :                     $$ = (Node *) n;
    2657             :                 }
    2658             :             /*
    2659             :              * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
    2660             :              *      [ USING <expression> ]
    2661             :              */
    2662             :             | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using
    2663             :                 {
    2664         852 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2665         852 :                     ColumnDef *def = makeNode(ColumnDef);
    2666             : 
    2667         852 :                     n->subtype = AT_AlterColumnType;
    2668         852 :                     n->name = $3;
    2669         852 :                     n->def = (Node *) def;
    2670             :                     /* We only use these fields of the ColumnDef node */
    2671         852 :                     def->typeName = $6;
    2672         852 :                     def->collClause = (CollateClause *) $7;
    2673         852 :                     def->raw_default = $8;
    2674         852 :                     def->location = @3;
    2675         852 :                     $$ = (Node *) n;
    2676             :                 }
    2677             :             /* ALTER FOREIGN TABLE <name> ALTER [COLUMN] <colname> OPTIONS */
    2678             :             | ALTER opt_column ColId alter_generic_options
    2679             :                 {
    2680          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2681             : 
    2682          50 :                     n->subtype = AT_AlterColumnGenericOptions;
    2683          50 :                     n->name = $3;
    2684          50 :                     n->def = (Node *) $4;
    2685          50 :                     $$ = (Node *) n;
    2686             :                 }
    2687             :             /* ALTER TABLE <name> ADD CONSTRAINT ... */
    2688             :             | ADD_P TableConstraint
    2689             :                 {
    2690       11614 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2691             : 
    2692       11614 :                     n->subtype = AT_AddConstraint;
    2693       11614 :                     n->def = $2;
    2694       11614 :                     $$ = (Node *) n;
    2695             :                 }
    2696             :             /* ALTER TABLE <name> ALTER CONSTRAINT ... */
    2697             :             | ALTER CONSTRAINT name ConstraintAttributeSpec
    2698             :                 {
    2699         132 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2700         132 :                     Constraint *c = makeNode(Constraint);
    2701             : 
    2702         132 :                     n->subtype = AT_AlterConstraint;
    2703         132 :                     n->def = (Node *) c;
    2704         132 :                     c->contype = CONSTR_FOREIGN; /* others not supported, yet */
    2705         132 :                     c->conname = $3;
    2706         132 :                     processCASbits($4, @4, "ALTER CONSTRAINT statement",
    2707             :                                     &c->deferrable,
    2708             :                                     &c->initdeferred,
    2709             :                                     NULL, NULL, yyscanner);
    2710         132 :                     $$ = (Node *) n;
    2711             :                 }
    2712             :             /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
    2713             :             | VALIDATE CONSTRAINT name
    2714             :                 {
    2715         388 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2716             : 
    2717         388 :                     n->subtype = AT_ValidateConstraint;
    2718         388 :                     n->name = $3;
    2719         388 :                     $$ = (Node *) n;
    2720             :                 }
    2721             :             /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
    2722             :             | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
    2723             :                 {
    2724          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2725             : 
    2726          18 :                     n->subtype = AT_DropConstraint;
    2727          18 :                     n->name = $5;
    2728          18 :                     n->behavior = $6;
    2729          18 :                     n->missing_ok = true;
    2730          18 :                     $$ = (Node *) n;
    2731             :                 }
    2732             :             /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
    2733             :             | DROP CONSTRAINT name opt_drop_behavior
    2734             :                 {
    2735         942 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2736             : 
    2737         942 :                     n->subtype = AT_DropConstraint;
    2738         942 :                     n->name = $3;
    2739         942 :                     n->behavior = $4;
    2740         942 :                     n->missing_ok = false;
    2741         942 :                     $$ = (Node *) n;
    2742             :                 }
    2743             :             /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat */
    2744             :             | SET WITHOUT OIDS
    2745             :                 {
    2746           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2747             : 
    2748           6 :                     n->subtype = AT_DropOids;
    2749           6 :                     $$ = (Node *) n;
    2750             :                 }
    2751             :             /* ALTER TABLE <name> CLUSTER ON <indexname> */
    2752             :             | CLUSTER ON name
    2753             :                 {
    2754          46 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2755             : 
    2756          46 :                     n->subtype = AT_ClusterOn;
    2757          46 :                     n->name = $3;
    2758          46 :                     $$ = (Node *) n;
    2759             :                 }
    2760             :             /* ALTER TABLE <name> SET WITHOUT CLUSTER */
    2761             :             | SET WITHOUT CLUSTER
    2762             :                 {
    2763          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2764             : 
    2765          18 :                     n->subtype = AT_DropCluster;
    2766          18 :                     n->name = NULL;
    2767          18 :                     $$ = (Node *) n;
    2768             :                 }
    2769             :             /* ALTER TABLE <name> SET LOGGED */
    2770             :             | SET LOGGED
    2771             :                 {
    2772          38 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2773             : 
    2774          38 :                     n->subtype = AT_SetLogged;
    2775          38 :                     $$ = (Node *) n;
    2776             :                 }
    2777             :             /* ALTER TABLE <name> SET UNLOGGED */
    2778             :             | SET UNLOGGED
    2779             :                 {
    2780          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2781             : 
    2782          50 :                     n->subtype = AT_SetUnLogged;
    2783          50 :                     $$ = (Node *) n;
    2784             :                 }
    2785             :             /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
    2786             :             | ENABLE_P TRIGGER name
    2787             :                 {
    2788         122 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2789             : 
    2790         122 :                     n->subtype = AT_EnableTrig;
    2791         122 :                     n->name = $3;
    2792         122 :                     $$ = (Node *) n;
    2793             :                 }
    2794             :             /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
    2795             :             | ENABLE_P ALWAYS TRIGGER name
    2796             :                 {
    2797          40 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2798             : 
    2799          40 :                     n->subtype = AT_EnableAlwaysTrig;
    2800          40 :                     n->name = $4;
    2801          40 :                     $$ = (Node *) n;
    2802             :                 }
    2803             :             /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
    2804             :             | ENABLE_P REPLICA TRIGGER name
    2805             :                 {
    2806          16 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2807             : 
    2808          16 :                     n->subtype = AT_EnableReplicaTrig;
    2809          16 :                     n->name = $4;
    2810          16 :                     $$ = (Node *) n;
    2811             :                 }
    2812             :             /* ALTER TABLE <name> ENABLE TRIGGER ALL */
    2813             :             | ENABLE_P TRIGGER ALL
    2814             :                 {
    2815           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2816             : 
    2817           0 :                     n->subtype = AT_EnableTrigAll;
    2818           0 :                     $$ = (Node *) n;
    2819             :                 }
    2820             :             /* ALTER TABLE <name> ENABLE TRIGGER USER */
    2821             :             | ENABLE_P TRIGGER USER
    2822             :                 {
    2823           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2824             : 
    2825           0 :                     n->subtype = AT_EnableTrigUser;
    2826           0 :                     $$ = (Node *) n;
    2827             :                 }
    2828             :             /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
    2829             :             | DISABLE_P TRIGGER name
    2830             :                 {
    2831         138 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2832             : 
    2833         138 :                     n->subtype = AT_DisableTrig;
    2834         138 :                     n->name = $3;
    2835         138 :                     $$ = (Node *) n;
    2836             :                 }
    2837             :             /* ALTER TABLE <name> DISABLE TRIGGER ALL */
    2838             :             | DISABLE_P TRIGGER ALL
    2839             :                 {
    2840          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2841             : 
    2842          12 :                     n->subtype = AT_DisableTrigAll;
    2843          12 :                     $$ = (Node *) n;
    2844             :                 }
    2845             :             /* ALTER TABLE <name> DISABLE TRIGGER USER */
    2846             :             | DISABLE_P TRIGGER USER
    2847             :                 {
    2848          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2849             : 
    2850          12 :                     n->subtype = AT_DisableTrigUser;
    2851          12 :                     $$ = (Node *) n;
    2852             :                 }
    2853             :             /* ALTER TABLE <name> ENABLE RULE <rule> */
    2854             :             | ENABLE_P RULE name
    2855             :                 {
    2856           8 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2857             : 
    2858           8 :                     n->subtype = AT_EnableRule;
    2859           8 :                     n->name = $3;
    2860           8 :                     $$ = (Node *) n;
    2861             :                 }
    2862             :             /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
    2863             :             | ENABLE_P ALWAYS RULE name
    2864             :                 {
    2865           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2866             : 
    2867           0 :                     n->subtype = AT_EnableAlwaysRule;
    2868           0 :                     n->name = $4;
    2869           0 :                     $$ = (Node *) n;
    2870             :                 }
    2871             :             /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
    2872             :             | ENABLE_P REPLICA RULE name
    2873             :                 {
    2874           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2875             : 
    2876           6 :                     n->subtype = AT_EnableReplicaRule;
    2877           6 :                     n->name = $4;
    2878           6 :                     $$ = (Node *) n;
    2879             :                 }
    2880             :             /* ALTER TABLE <name> DISABLE RULE <rule> */
    2881             :             | DISABLE_P RULE name
    2882             :                 {
    2883          32 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2884             : 
    2885          32 :                     n->subtype = AT_DisableRule;
    2886          32 :                     n->name = $3;
    2887          32 :                     $$ = (Node *) n;
    2888             :                 }
    2889             :             /* ALTER TABLE <name> INHERIT <parent> */
    2890             :             | INHERIT qualified_name
    2891             :                 {
    2892         342 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2893             : 
    2894         342 :                     n->subtype = AT_AddInherit;
    2895         342 :                     n->def = (Node *) $2;
    2896         342 :                     $$ = (Node *) n;
    2897             :                 }
    2898             :             /* ALTER TABLE <name> NO INHERIT <parent> */
    2899             :             | NO INHERIT qualified_name
    2900             :                 {
    2901          44 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2902             : 
    2903          44 :                     n->subtype = AT_DropInherit;
    2904          44 :                     n->def = (Node *) $3;
    2905          44 :                     $$ = (Node *) n;
    2906             :                 }
    2907             :             /* ALTER TABLE <name> OF <type_name> */
    2908             :             | OF any_name
    2909             :                 {
    2910          66 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2911          66 :                     TypeName   *def = makeTypeNameFromNameList($2);
    2912             : 
    2913          66 :                     def->location = @2;
    2914          66 :                     n->subtype = AT_AddOf;
    2915          66 :                     n->def = (Node *) def;
    2916          66 :                     $$ = (Node *) n;
    2917             :                 }
    2918             :             /* ALTER TABLE <name> NOT OF */
    2919             :             | NOT OF
    2920             :                 {
    2921           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2922             : 
    2923           6 :                     n->subtype = AT_DropOf;
    2924           6 :                     $$ = (Node *) n;
    2925             :                 }
    2926             :             /* ALTER TABLE <name> OWNER TO RoleSpec */
    2927             :             | OWNER TO RoleSpec
    2928             :                 {
    2929        1806 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2930             : 
    2931        1806 :                     n->subtype = AT_ChangeOwner;
    2932        1806 :                     n->newowner = $3;
    2933        1806 :                     $$ = (Node *) n;
    2934             :                 }
    2935             :             /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
    2936             :             | SET ACCESS METHOD set_access_method_name
    2937             :                 {
    2938         128 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2939             : 
    2940         128 :                     n->subtype = AT_SetAccessMethod;
    2941         128 :                     n->name = $4;
    2942         128 :                     $$ = (Node *) n;
    2943             :                 }
    2944             :             /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
    2945             :             | SET TABLESPACE name
    2946             :                 {
    2947         104 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2948             : 
    2949         104 :                     n->subtype = AT_SetTableSpace;
    2950         104 :                     n->name = $3;
    2951         104 :                     $$ = (Node *) n;
    2952             :                 }
    2953             :             /* ALTER TABLE <name> SET (...) */
    2954             :             | SET reloptions
    2955             :                 {
    2956         582 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2957             : 
    2958         582 :                     n->subtype = AT_SetRelOptions;
    2959         582 :                     n->def = (Node *) $2;
    2960         582 :                     $$ = (Node *) n;
    2961             :                 }
    2962             :             /* ALTER TABLE <name> RESET (...) */
    2963             :             | RESET reloptions
    2964             :                 {
    2965         158 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2966             : 
    2967         158 :                     n->subtype = AT_ResetRelOptions;
    2968         158 :                     n->def = (Node *) $2;
    2969         158 :                     $$ = (Node *) n;
    2970             :                 }
    2971             :             /* ALTER TABLE <name> REPLICA IDENTITY */
    2972             :             | REPLICA IDENTITY_P replica_identity
    2973             :                 {
    2974         456 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2975             : 
    2976         456 :                     n->subtype = AT_ReplicaIdentity;
    2977         456 :                     n->def = $3;
    2978         456 :                     $$ = (Node *) n;
    2979             :                 }
    2980             :             /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
    2981             :             | ENABLE_P ROW LEVEL SECURITY
    2982             :                 {
    2983         284 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2984             : 
    2985         284 :                     n->subtype = AT_EnableRowSecurity;
    2986         284 :                     $$ = (Node *) n;
    2987             :                 }
    2988             :             /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
    2989             :             | DISABLE_P ROW LEVEL SECURITY
    2990             :                 {
    2991          10 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2992             : 
    2993          10 :                     n->subtype = AT_DisableRowSecurity;
    2994          10 :                     $$ = (Node *) n;
    2995             :                 }
    2996             :             /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
    2997             :             | FORCE ROW LEVEL SECURITY
    2998             :                 {
    2999          88 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3000             : 
    3001          88 :                     n->subtype = AT_ForceRowSecurity;
    3002          88 :                     $$ = (Node *) n;
    3003             :                 }
    3004             :             /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
    3005             :             | NO FORCE ROW LEVEL SECURITY
    3006             :                 {
    3007          32 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3008             : 
    3009          32 :                     n->subtype = AT_NoForceRowSecurity;
    3010          32 :                     $$ = (Node *) n;
    3011             :                 }
    3012             :             | alter_generic_options
    3013             :                 {
    3014          56 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3015             : 
    3016          56 :                     n->subtype = AT_GenericOptions;
    3017          56 :                     n->def = (Node *) $1;
    3018          56 :                     $$ = (Node *) n;
    3019             :                 }
    3020             :         ;
    3021             : 
    3022             : alter_column_default:
    3023         356 :             SET DEFAULT a_expr          { $$ = $3; }
    3024         180 :             | DROP DEFAULT              { $$ = NULL; }
    3025             :         ;
    3026             : 
    3027             : opt_collate_clause:
    3028             :             COLLATE any_name
    3029             :                 {
    3030          12 :                     CollateClause *n = makeNode(CollateClause);
    3031             : 
    3032          12 :                     n->arg = NULL;
    3033          12 :                     n->collname = $2;
    3034          12 :                     n->location = @1;
    3035          12 :                     $$ = (Node *) n;
    3036             :                 }
    3037        4440 :             | /* EMPTY */               { $$ = NULL; }
    3038             :         ;
    3039             : 
    3040             : alter_using:
    3041         168 :             USING a_expr                { $$ = $2; }
    3042         684 :             | /* EMPTY */               { $$ = NULL; }
    3043             :         ;
    3044             : 
    3045             : replica_identity:
    3046             :             NOTHING
    3047             :                 {
    3048          36 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3049             : 
    3050          36 :                     n->identity_type = REPLICA_IDENTITY_NOTHING;
    3051          36 :                     n->name = NULL;
    3052          36 :                     $$ = (Node *) n;
    3053             :                 }
    3054             :             | FULL
    3055             :                 {
    3056         144 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3057             : 
    3058         144 :                     n->identity_type = REPLICA_IDENTITY_FULL;
    3059         144 :                     n->name = NULL;
    3060         144 :                     $$ = (Node *) n;
    3061             :                 }
    3062             :             | DEFAULT
    3063             :                 {
    3064           6 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3065             : 
    3066           6 :                     n->identity_type = REPLICA_IDENTITY_DEFAULT;
    3067           6 :                     n->name = NULL;
    3068           6 :                     $$ = (Node *) n;
    3069             :                 }
    3070             :             | USING INDEX name
    3071             :                 {
    3072         270 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3073             : 
    3074         270 :                     n->identity_type = REPLICA_IDENTITY_INDEX;
    3075         270 :                     n->name = $3;
    3076         270 :                     $$ = (Node *) n;
    3077             :                 }
    3078             : ;
    3079             : 
    3080             : reloptions:
    3081        2460 :             '(' reloption_list ')'                  { $$ = $2; }
    3082             :         ;
    3083             : 
    3084         896 : opt_reloptions:     WITH reloptions                 { $$ = $2; }
    3085       19712 :              |      /* EMPTY */                     { $$ = NIL; }
    3086             :         ;
    3087             : 
    3088             : reloption_list:
    3089        2460 :             reloption_elem                          { $$ = list_make1($1); }
    3090         220 :             | reloption_list ',' reloption_elem     { $$ = lappend($1, $3); }
    3091             :         ;
    3092             : 
    3093             : /* This should match def_elem and also allow qualified names */
    3094             : reloption_elem:
    3095             :             ColLabel '=' def_arg
    3096             :                 {
    3097        2106 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    3098             :                 }
    3099             :             | ColLabel
    3100             :                 {
    3101         506 :                     $$ = makeDefElem($1, NULL, @1);
    3102             :                 }
    3103             :             | ColLabel '.' ColLabel '=' def_arg
    3104             :                 {
    3105          62 :                     $$ = makeDefElemExtended($1, $3, (Node *) $5,
    3106          62 :                                              DEFELEM_UNSPEC, @1);
    3107             :                 }
    3108             :             | ColLabel '.' ColLabel
    3109             :                 {
    3110           6 :                     $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC, @1);
    3111             :                 }
    3112             :         ;
    3113             : 
    3114             : alter_identity_column_option_list:
    3115             :             alter_identity_column_option
    3116          62 :                 { $$ = list_make1($1); }
    3117             :             | alter_identity_column_option_list alter_identity_column_option
    3118          60 :                 { $$ = lappend($1, $2); }
    3119             :         ;
    3120             : 
    3121             : alter_identity_column_option:
    3122             :             RESTART
    3123             :                 {
    3124          24 :                     $$ = makeDefElem("restart", NULL, @1);
    3125             :                 }
    3126             :             | RESTART opt_with NumericOnly
    3127             :                 {
    3128           0 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    3129             :                 }
    3130             :             | SET SeqOptElem
    3131             :                 {
    3132          54 :                     if (strcmp($2->defname, "as") == 0 ||
    3133          54 :                         strcmp($2->defname, "restart") == 0 ||
    3134          54 :                         strcmp($2->defname, "owned_by") == 0)
    3135           0 :                         ereport(ERROR,
    3136             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3137             :                                  errmsg("sequence option \"%s\" not supported here", $2->defname),
    3138             :                                  parser_errposition(@2)));
    3139          54 :                     $$ = $2;
    3140             :                 }
    3141             :             | SET GENERATED generated_when
    3142             :                 {
    3143          44 :                     $$ = makeDefElem("generated", (Node *) makeInteger($3), @1);
    3144             :                 }
    3145             :         ;
    3146             : 
    3147             : set_statistics_value:
    3148         158 :             SignedIconst                    { $$ = (Node *) makeInteger($1); }
    3149           0 :             | DEFAULT                       { $$ = NULL; }
    3150             :         ;
    3151             : 
    3152             : set_access_method_name:
    3153          92 :             ColId                           { $$ = $1; }
    3154          36 :             | DEFAULT                       { $$ = NULL; }
    3155             :         ;
    3156             : 
    3157             : PartitionBoundSpec:
    3158             :             /* a HASH partition */
    3159             :             FOR VALUES WITH '(' hash_partbound ')'
    3160             :                 {
    3161             :                     ListCell   *lc;
    3162         698 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3163             : 
    3164         698 :                     n->strategy = PARTITION_STRATEGY_HASH;
    3165         698 :                     n->modulus = n->remainder = -1;
    3166             : 
    3167        2094 :                     foreach (lc, $5)
    3168             :                     {
    3169        1396 :                         DefElem    *opt = lfirst_node(DefElem, lc);
    3170             : 
    3171        1396 :                         if (strcmp(opt->defname, "modulus") == 0)
    3172             :                         {
    3173         698 :                             if (n->modulus != -1)
    3174           0 :                                 ereport(ERROR,
    3175             :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    3176             :                                          errmsg("modulus for hash partition provided more than once"),
    3177             :                                          parser_errposition(opt->location)));
    3178         698 :                             n->modulus = defGetInt32(opt);
    3179             :                         }
    3180         698 :                         else if (strcmp(opt->defname, "remainder") == 0)
    3181             :                         {
    3182         698 :                             if (n->remainder != -1)
    3183           0 :                                 ereport(ERROR,
    3184             :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    3185             :                                          errmsg("remainder for hash partition provided more than once"),
    3186             :                                          parser_errposition(opt->location)));
    3187         698 :                             n->remainder = defGetInt32(opt);
    3188             :                         }
    3189             :                         else
    3190           0 :                             ereport(ERROR,
    3191             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    3192             :                                      errmsg("unrecognized hash partition bound specification \"%s\"",
    3193             :                                             opt->defname),
    3194             :                                      parser_errposition(opt->location)));
    3195             :                     }
    3196             : 
    3197         698 :                     if (n->modulus == -1)
    3198           0 :                         ereport(ERROR,
    3199             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3200             :                                  errmsg("modulus for hash partition must be specified")));
    3201         698 :                     if (n->remainder == -1)
    3202           0 :                         ereport(ERROR,
    3203             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3204             :                                  errmsg("remainder for hash partition must be specified")));
    3205             : 
    3206         698 :                     n->location = @3;
    3207             : 
    3208         698 :                     $$ = n;
    3209             :                 }
    3210             : 
    3211             :             /* a LIST partition */
    3212             :             | FOR VALUES IN_P '(' expr_list ')'
    3213             :                 {
    3214        4772 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3215             : 
    3216        4772 :                     n->strategy = PARTITION_STRATEGY_LIST;
    3217        4772 :                     n->is_default = false;
    3218        4772 :                     n->listdatums = $5;
    3219        4772 :                     n->location = @3;
    3220             : 
    3221        4772 :                     $$ = n;
    3222             :                 }
    3223             : 
    3224             :             /* a RANGE partition */
    3225             :             | FOR VALUES FROM '(' expr_list ')' TO '(' expr_list ')'
    3226             :                 {
    3227        5140 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3228             : 
    3229        5140 :                     n->strategy = PARTITION_STRATEGY_RANGE;
    3230        5140 :                     n->is_default = false;
    3231        5140 :                     n->lowerdatums = $5;
    3232        5140 :                     n->upperdatums = $9;
    3233        5140 :                     n->location = @3;
    3234             : 
    3235        5140 :                     $$ = n;
    3236             :                 }
    3237             : 
    3238             :             /* a DEFAULT partition */
    3239             :             | DEFAULT
    3240             :                 {
    3241         794 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3242             : 
    3243         794 :                     n->is_default = true;
    3244         794 :                     n->location = @1;
    3245             : 
    3246         794 :                     $$ = n;
    3247             :                 }
    3248             :         ;
    3249             : 
    3250             : hash_partbound_elem:
    3251             :         NonReservedWord Iconst
    3252             :             {
    3253        1396 :                 $$ = makeDefElem($1, (Node *) makeInteger($2), @1);
    3254             :             }
    3255             :         ;
    3256             : 
    3257             : hash_partbound:
    3258             :         hash_partbound_elem
    3259             :             {
    3260         698 :                 $$ = list_make1($1);
    3261             :             }
    3262             :         | hash_partbound ',' hash_partbound_elem
    3263             :             {
    3264         698 :                 $$ = lappend($1, $3);
    3265             :             }
    3266             :         ;
    3267             : 
    3268             : /*****************************************************************************
    3269             :  *
    3270             :  *  ALTER TYPE
    3271             :  *
    3272             :  * really variants of the ALTER TABLE subcommands with different spellings
    3273             :  *****************************************************************************/
    3274             : 
    3275             : AlterCompositeTypeStmt:
    3276             :             ALTER TYPE_P any_name alter_type_cmds
    3277             :                 {
    3278         208 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    3279             : 
    3280             :                     /* can't use qualified_name, sigh */
    3281         208 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
    3282         208 :                     n->cmds = $4;
    3283         208 :                     n->objtype = OBJECT_TYPE;
    3284         208 :                     $$ = (Node *) n;
    3285             :                 }
    3286             :             ;
    3287             : 
    3288             : alter_type_cmds:
    3289         208 :             alter_type_cmd                          { $$ = list_make1($1); }
    3290          12 :             | alter_type_cmds ',' alter_type_cmd    { $$ = lappend($1, $3); }
    3291             :         ;
    3292             : 
    3293             : alter_type_cmd:
    3294             :             /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
    3295             :             ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
    3296             :                 {
    3297          64 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3298             : 
    3299          64 :                     n->subtype = AT_AddColumn;
    3300          64 :                     n->def = $3;
    3301          64 :                     n->behavior = $4;
    3302          64 :                     $$ = (Node *) n;
    3303             :                 }
    3304             :             /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
    3305             :             | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
    3306             :                 {
    3307           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3308             : 
    3309           6 :                     n->subtype = AT_DropColumn;
    3310           6 :                     n->name = $5;
    3311           6 :                     n->behavior = $6;
    3312           6 :                     n->missing_ok = true;
    3313           6 :                     $$ = (Node *) n;
    3314             :                 }
    3315             :             /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
    3316             :             | DROP ATTRIBUTE ColId opt_drop_behavior
    3317             :                 {
    3318          76 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3319             : 
    3320          76 :                     n->subtype = AT_DropColumn;
    3321          76 :                     n->name = $3;
    3322          76 :                     n->behavior = $4;
    3323          76 :                     n->missing_ok = false;
    3324          76 :                     $$ = (Node *) n;
    3325             :                 }
    3326             :             /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
    3327             :             | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
    3328             :                 {
    3329          74 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3330          74 :                     ColumnDef *def = makeNode(ColumnDef);
    3331             : 
    3332          74 :                     n->subtype = AT_AlterColumnType;
    3333          74 :                     n->name = $3;
    3334          74 :                     n->def = (Node *) def;
    3335          74 :                     n->behavior = $8;
    3336             :                     /* We only use these fields of the ColumnDef node */
    3337          74 :                     def->typeName = $6;
    3338          74 :                     def->collClause = (CollateClause *) $7;
    3339          74 :                     def->raw_default = NULL;
    3340          74 :                     def->location = @3;
    3341          74 :                     $$ = (Node *) n;
    3342             :                 }
    3343             :         ;
    3344             : 
    3345             : 
    3346             : /*****************************************************************************
    3347             :  *
    3348             :  *      QUERY :
    3349             :  *              close <portalname>
    3350             :  *
    3351             :  *****************************************************************************/
    3352             : 
    3353             : ClosePortalStmt:
    3354             :             CLOSE cursor_name
    3355             :                 {
    3356        2118 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3357             : 
    3358        2118 :                     n->portalname = $2;
    3359        2118 :                     $$ = (Node *) n;
    3360             :                 }
    3361             :             | CLOSE ALL
    3362             :                 {
    3363          12 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3364             : 
    3365          12 :                     n->portalname = NULL;
    3366          12 :                     $$ = (Node *) n;
    3367             :                 }
    3368             :         ;
    3369             : 
    3370             : 
    3371             : /*****************************************************************************
    3372             :  *
    3373             :  *      QUERY :
    3374             :  *              COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
    3375             :  *              COPY ( query ) TO file  [WITH] [(options)]
    3376             :  *
    3377             :  *              where 'query' can be one of:
    3378             :  *              { SELECT | UPDATE | INSERT | DELETE }
    3379             :  *
    3380             :  *              and 'file' can be one of:
    3381             :  *              { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
    3382             :  *
    3383             :  *              In the preferred syntax the options are comma-separated
    3384             :  *              and use generic identifiers instead of keywords.  The pre-9.0
    3385             :  *              syntax had a hard-wired, space-separated set of options.
    3386             :  *
    3387             :  *              Really old syntax, from versions 7.2 and prior:
    3388             :  *              COPY [ BINARY ] table FROM/TO file
    3389             :  *                  [ [ USING ] DELIMITERS 'delimiter' ] ]
    3390             :  *                  [ WITH NULL AS 'null string' ]
    3391             :  *              This option placement is not supported with COPY (query...).
    3392             :  *
    3393             :  *****************************************************************************/
    3394             : 
    3395             : CopyStmt:   COPY opt_binary qualified_name opt_column_list
    3396             :             copy_from opt_program copy_file_name copy_delimiter opt_with
    3397             :             copy_options where_clause
    3398             :                 {
    3399        9056 :                     CopyStmt *n = makeNode(CopyStmt);
    3400             : 
    3401        9056 :                     n->relation = $3;
    3402        9056 :                     n->query = NULL;
    3403        9056 :                     n->attlist = $4;
    3404        9056 :                     n->is_from = $5;
    3405        9056 :                     n->is_program = $6;
    3406        9056 :                     n->filename = $7;
    3407        9056 :                     n->whereClause = $11;
    3408             : 
    3409        9056 :                     if (n->is_program && n->filename == NULL)
    3410           0 :                         ereport(ERROR,
    3411             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3412             :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3413             :                                  parser_errposition(@8)));
    3414             : 
    3415        9056 :                     if (!n->is_from && n->whereClause != NULL)
    3416           6 :                         ereport(ERROR,
    3417             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3418             :                                  errmsg("WHERE clause not allowed with COPY TO"),
    3419             :                                  parser_errposition(@11)));
    3420             : 
    3421        9050 :                     n->options = NIL;
    3422             :                     /* Concatenate user-supplied flags */
    3423        9050 :                     if ($2)
    3424          12 :                         n->options = lappend(n->options, $2);
    3425        9050 :                     if ($8)
    3426           0 :                         n->options = lappend(n->options, $8);
    3427        9050 :                     if ($10)
    3428         806 :                         n->options = list_concat(n->options, $10);
    3429        9050 :                     $$ = (Node *) n;
    3430             :                 }
    3431             :             | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
    3432             :                 {
    3433         400 :                     CopyStmt *n = makeNode(CopyStmt);
    3434             : 
    3435         400 :                     n->relation = NULL;
    3436         400 :                     n->query = $3;
    3437         400 :                     n->attlist = NIL;
    3438         400 :                     n->is_from = false;
    3439         400 :                     n->is_program = $6;
    3440         400 :                     n->filename = $7;
    3441         400 :                     n->options = $9;
    3442             : 
    3443         400 :                     if (n->is_program && n->filename == NULL)
    3444           0 :                         ereport(ERROR,
    3445             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3446             :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3447             :                                  parser_errposition(@5)));
    3448             : 
    3449         400 :                     $$ = (Node *) n;
    3450             :                 }
    3451             :         ;
    3452             : 
    3453             : copy_from:
    3454        1518 :             FROM                                    { $$ = true; }
    3455        7538 :             | TO                                    { $$ = false; }
    3456             :         ;
    3457             : 
    3458             : opt_program:
    3459           0 :             PROGRAM                                 { $$ = true; }
    3460        9456 :             | /* EMPTY */                           { $$ = false; }
    3461             :         ;
    3462             : 
    3463             : /*
    3464             :  * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
    3465             :  * used depends on the direction. (It really doesn't make sense to copy from
    3466             :  * stdout. We silently correct the "typo".)        - AY 9/94
    3467             :  */
    3468             : copy_file_name:
    3469         378 :             Sconst                                  { $$ = $1; }
    3470        1216 :             | STDIN                                 { $$ = NULL; }
    3471        7862 :             | STDOUT                                { $$ = NULL; }
    3472             :         ;
    3473             : 
    3474        8938 : copy_options: copy_opt_list                         { $$ = $1; }
    3475         518 :             | '(' copy_generic_opt_list ')'         { $$ = $2; }
    3476             :         ;
    3477             : 
    3478             : /* old COPY option syntax */
    3479             : copy_opt_list:
    3480         498 :             copy_opt_list copy_opt_item             { $$ = lappend($1, $2); }
    3481        8938 :             | /* EMPTY */                           { $$ = NIL; }
    3482             :         ;
    3483             : 
    3484             : copy_opt_item:
    3485             :             BINARY
    3486             :                 {
    3487           0 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3488             :                 }
    3489             :             | FREEZE
    3490             :                 {
    3491          50 :                     $$ = makeDefElem("freeze", (Node *) makeBoolean(true), @1);
    3492             :                 }
    3493             :             | DELIMITER opt_as Sconst
    3494             :                 {
    3495         172 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @1);
    3496             :                 }
    3497             :             | NULL_P opt_as Sconst
    3498             :                 {
    3499          48 :                     $$ = makeDefElem("null", (Node *) makeString($3), @1);
    3500             :                 }
    3501             :             | CSV
    3502             :                 {
    3503         144 :                     $$ = makeDefElem("format", (Node *) makeString("csv"), @1);
    3504             :                 }
    3505             :             | HEADER_P
    3506             :                 {
    3507          18 :                     $$ = makeDefElem("header", (Node *) makeBoolean(true), @1);
    3508             :                 }
    3509             :             | QUOTE opt_as Sconst
    3510             :                 {
    3511          18 :                     $$ = makeDefElem("quote", (Node *) makeString($3), @1);
    3512             :                 }
    3513             :             | ESCAPE opt_as Sconst
    3514             :                 {
    3515          18 :                     $$ = makeDefElem("escape", (Node *) makeString($3), @1);
    3516             :                 }
    3517             :             | FORCE QUOTE columnList
    3518             :                 {
    3519          12 :                     $$ = makeDefElem("force_quote", (Node *) $3, @1);
    3520             :                 }
    3521             :             | FORCE QUOTE '*'
    3522             :                 {
    3523           6 :                     $$ = makeDefElem("force_quote", (Node *) makeNode(A_Star), @1);
    3524             :                 }
    3525             :             | FORCE NOT NULL_P columnList
    3526             :                 {
    3527           0 :                     $$ = makeDefElem("force_not_null", (Node *) $4, @1);
    3528             :                 }
    3529             :             | FORCE NOT NULL_P '*'
    3530             :                 {
    3531           0 :                     $$ = makeDefElem("force_not_null", (Node *) makeNode(A_Star), @1);
    3532             :                 }
    3533             :             | FORCE NULL_P columnList
    3534             :                 {
    3535           0 :                     $$ = makeDefElem("force_null", (Node *) $3, @1);
    3536             :                 }
    3537             :             | FORCE NULL_P '*'
    3538             :                 {
    3539           0 :                     $$ = makeDefElem("force_null", (Node *) makeNode(A_Star), @1);
    3540             :                 }
    3541             :             | ENCODING Sconst
    3542             :                 {
    3543          12 :                     $$ = makeDefElem("encoding", (Node *) makeString($2), @1);
    3544             :                 }
    3545             :         ;
    3546             : 
    3547             : /* The following exist for backward compatibility with very old versions */
    3548             : 
    3549             : opt_binary:
    3550             :             BINARY
    3551             :                 {
    3552          12 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3553             :                 }
    3554        9044 :             | /*EMPTY*/                             { $$ = NULL; }
    3555             :         ;
    3556             : 
    3557             : copy_delimiter:
    3558             :             opt_using DELIMITERS Sconst
    3559             :                 {
    3560           0 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @2);
    3561             :                 }
    3562        9056 :             | /*EMPTY*/                             { $$ = NULL; }
    3563             :         ;
    3564             : 
    3565             : opt_using:
    3566             :             USING
    3567             :             | /*EMPTY*/
    3568             :         ;
    3569             : 
    3570             : /* new COPY option syntax */
    3571             : copy_generic_opt_list:
    3572             :             copy_generic_opt_elem
    3573             :                 {
    3574         518 :                     $$ = list_make1($1);
    3575             :                 }
    3576             :             | copy_generic_opt_list ',' copy_generic_opt_elem
    3577             :                 {
    3578         366 :                     $$ = lappend($1, $3);
    3579             :                 }
    3580             :         ;
    3581             : 
    3582             : copy_generic_opt_elem:
    3583             :             ColLabel copy_generic_opt_arg
    3584             :                 {
    3585         884 :                     $$ = makeDefElem($1, $2, @1);
    3586             :                 }
    3587             :         ;
    3588             : 
    3589             : copy_generic_opt_arg:
    3590         656 :             opt_boolean_or_string           { $$ = (Node *) makeString($1); }
    3591           0 :             | NumericOnly                   { $$ = (Node *) $1; }
    3592          54 :             | '*'                           { $$ = (Node *) makeNode(A_Star); }
    3593           6 :             | DEFAULT                       { $$ = (Node *) makeString("default"); }
    3594         150 :             | '(' copy_generic_opt_arg_list ')'     { $$ = (Node *) $2; }
    3595          18 :             | /* EMPTY */                   { $$ = NULL; }
    3596             :         ;
    3597             : 
    3598             : copy_generic_opt_arg_list:
    3599             :               copy_generic_opt_arg_list_item
    3600             :                 {
    3601         150 :                     $$ = list_make1($1);
    3602             :                 }
    3603             :             | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
    3604             :                 {
    3605          12 :                     $$ = lappend($1, $3);
    3606             :                 }
    3607             :         ;
    3608             : 
    3609             : /* beware of emitting non-string list elements here; see commands/define.c */
    3610             : copy_generic_opt_arg_list_item:
    3611         162 :             opt_boolean_or_string   { $$ = (Node *) makeString($1); }
    3612             :         ;
    3613             : 
    3614             : 
    3615             : /*****************************************************************************
    3616             :  *
    3617             :  *      QUERY :
    3618             :  *              CREATE TABLE relname
    3619             :  *
    3620             :  *****************************************************************************/
    3621             : 
    3622             : CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
    3623             :             OptInherit OptPartitionSpec table_access_method_clause OptWith
    3624             :             OnCommitOption OptTableSpace
    3625             :                 {
    3626       26996 :                     CreateStmt *n = makeNode(CreateStmt);
    3627             : 
    3628       26996 :                     $4->relpersistence = $2;
    3629       26996 :                     n->relation = $4;
    3630       26996 :                     n->tableElts = $6;
    3631       26996 :                     n->inhRelations = $8;
    3632       26996 :                     n->partspec = $9;
    3633       26996 :                     n->ofTypename = NULL;
    3634       26996 :                     n->constraints = NIL;
    3635       26996 :                     n->accessMethod = $10;
    3636       26996 :                     n->options = $11;
    3637       26996 :                     n->oncommit = $12;
    3638       26996 :                     n->tablespacename = $13;
    3639       26996 :                     n->if_not_exists = false;
    3640       26996 :                     $$ = (Node *) n;
    3641             :                 }
    3642             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
    3643             :             OptTableElementList ')' OptInherit OptPartitionSpec table_access_method_clause
    3644             :             OptWith OnCommitOption OptTableSpace
    3645             :                 {
    3646          30 :                     CreateStmt *n = makeNode(CreateStmt);
    3647             : 
    3648          30 :                     $7->relpersistence = $2;
    3649          30 :                     n->relation = $7;
    3650          30 :                     n->tableElts = $9;
    3651          30 :                     n->inhRelations = $11;
    3652          30 :                     n->partspec = $12;
    3653          30 :                     n->ofTypename = NULL;
    3654          30 :                     n->constraints = NIL;
    3655          30 :                     n->accessMethod = $13;
    3656          30 :                     n->options = $14;
    3657          30 :                     n->oncommit = $15;
    3658          30 :                     n->tablespacename = $16;
    3659          30 :                     n->if_not_exists = true;
    3660          30 :                     $$ = (Node *) n;
    3661             :                 }
    3662             :         | CREATE OptTemp TABLE qualified_name OF any_name
    3663             :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3664             :             OptWith OnCommitOption OptTableSpace
    3665             :                 {
    3666         110 :                     CreateStmt *n = makeNode(CreateStmt);
    3667             : 
    3668         110 :                     $4->relpersistence = $2;
    3669         110 :                     n->relation = $4;
    3670         110 :                     n->tableElts = $7;
    3671         110 :                     n->inhRelations = NIL;
    3672         110 :                     n->partspec = $8;
    3673         110 :                     n->ofTypename = makeTypeNameFromNameList($6);
    3674         110 :                     n->ofTypename->location = @6;
    3675         110 :                     n->constraints = NIL;
    3676         110 :                     n->accessMethod = $9;
    3677         110 :                     n->options = $10;
    3678         110 :                     n->oncommit = $11;
    3679         110 :                     n->tablespacename = $12;
    3680         110 :                     n->if_not_exists = false;
    3681         110 :                     $$ = (Node *) n;
    3682             :                 }
    3683             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
    3684             :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3685             :             OptWith OnCommitOption OptTableSpace
    3686             :                 {
    3687           6 :                     CreateStmt *n = makeNode(CreateStmt);
    3688             : 
    3689           6 :                     $7->relpersistence = $2;
    3690           6 :                     n->relation = $7;
    3691           6 :                     n->tableElts = $10;
    3692           6 :                     n->inhRelations = NIL;
    3693           6 :                     n->partspec = $11;
    3694           6 :                     n->ofTypename = makeTypeNameFromNameList($9);
    3695           6 :                     n->ofTypename->location = @9;
    3696           6 :                     n->constraints = NIL;
    3697           6 :                     n->accessMethod = $12;
    3698           6 :                     n->options = $13;
    3699           6 :                     n->oncommit = $14;
    3700           6 :                     n->tablespacename = $15;
    3701           6 :                     n->if_not_exists = true;
    3702           6 :                     $$ = (Node *) n;
    3703             :                 }
    3704             :         | CREATE OptTemp TABLE qualified_name PARTITION OF qualified_name
    3705             :             OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3706             :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3707             :                 {
    3708        8280 :                     CreateStmt *n = makeNode(CreateStmt);
    3709             : 
    3710        8280 :                     $4->relpersistence = $2;
    3711        8280 :                     n->relation = $4;
    3712        8280 :                     n->tableElts = $8;
    3713        8280 :                     n->inhRelations = list_make1($7);
    3714        8280 :                     n->partbound = $9;
    3715        8280 :                     n->partspec = $10;
    3716        8280 :                     n->ofTypename = NULL;
    3717        8280 :                     n->constraints = NIL;
    3718        8280 :                     n->accessMethod = $11;
    3719        8280 :                     n->options = $12;
    3720        8280 :                     n->oncommit = $13;
    3721        8280 :                     n->tablespacename = $14;
    3722        8280 :                     n->if_not_exists = false;
    3723        8280 :                     $$ = (Node *) n;
    3724             :                 }
    3725             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name PARTITION OF
    3726             :             qualified_name OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3727             :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3728             :                 {
    3729           0 :                     CreateStmt *n = makeNode(CreateStmt);
    3730             : 
    3731           0 :                     $7->relpersistence = $2;
    3732           0 :                     n->relation = $7;
    3733           0 :                     n->tableElts = $11;
    3734           0 :                     n->inhRelations = list_make1($10);
    3735           0 :                     n->partbound = $12;
    3736           0 :                     n->partspec = $13;
    3737           0 :                     n->ofTypename = NULL;
    3738           0 :                     n->constraints = NIL;
    3739           0 :                     n->accessMethod = $14;
    3740           0 :                     n->options = $15;
    3741           0 :                     n->oncommit = $16;
    3742           0 :                     n->tablespacename = $17;
    3743           0 :                     n->if_not_exists = true;
    3744           0 :                     $$ = (Node *) n;
    3745             :                 }
    3746             :         ;
    3747             : 
    3748             : /*
    3749             :  * Redundancy here is needed to avoid shift/reduce conflicts,
    3750             :  * since TEMP is not a reserved word.  See also OptTempTableName.
    3751             :  *
    3752             :  * NOTE: we accept both GLOBAL and LOCAL options.  They currently do nothing,
    3753             :  * but future versions might consider GLOBAL to request SQL-spec-compliant
    3754             :  * temp table behavior, so warn about that.  Since we have no modules the
    3755             :  * LOCAL keyword is really meaningless; furthermore, some other products
    3756             :  * implement LOCAL as meaning the same as our default temp table behavior,
    3757             :  * so we'll probably continue to treat LOCAL as a noise word.
    3758             :  */
    3759         294 : OptTemp:    TEMPORARY                   { $$ = RELPERSISTENCE_TEMP; }
    3760        2616 :             | TEMP                      { $$ = RELPERSISTENCE_TEMP; }
    3761           0 :             | LOCAL TEMPORARY           { $$ = RELPERSISTENCE_TEMP; }
    3762           0 :             | LOCAL TEMP                { $$ = RELPERSISTENCE_TEMP; }
    3763             :             | GLOBAL TEMPORARY
    3764             :                 {
    3765           0 :                     ereport(WARNING,
    3766             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3767             :                              parser_errposition(@1)));
    3768           0 :                     $$ = RELPERSISTENCE_TEMP;
    3769             :                 }
    3770             :             | GLOBAL TEMP
    3771             :                 {
    3772           0 :                     ereport(WARNING,
    3773             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3774             :                              parser_errposition(@1)));
    3775           0 :                     $$ = RELPERSISTENCE_TEMP;
    3776             :                 }
    3777         152 :             | UNLOGGED                  { $$ = RELPERSISTENCE_UNLOGGED; }
    3778       48030 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    3779             :         ;
    3780             : 
    3781             : OptTableElementList:
    3782       26010 :             TableElementList                    { $$ = $1; }
    3783        1414 :             | /*EMPTY*/                         { $$ = NIL; }
    3784             :         ;
    3785             : 
    3786             : OptTypedTableElementList:
    3787         302 :             '(' TypedTableElementList ')'       { $$ = $2; }
    3788        8190 :             | /*EMPTY*/                         { $$ = NIL; }
    3789             :         ;
    3790             : 
    3791             : TableElementList:
    3792             :             TableElement
    3793             :                 {
    3794       26058 :                     $$ = list_make1($1);
    3795             :                 }
    3796             :             | TableElementList ',' TableElement
    3797             :                 {
    3798       38008 :                     $$ = lappend($1, $3);
    3799             :                 }
    3800             :         ;
    3801             : 
    3802             : TypedTableElementList:
    3803             :             TypedTableElement
    3804             :                 {
    3805         302 :                     $$ = list_make1($1);
    3806             :                 }
    3807             :             | TypedTableElementList ',' TypedTableElement
    3808             :                 {
    3809          68 :                     $$ = lappend($1, $3);
    3810             :                 }
    3811             :         ;
    3812             : 
    3813             : TableElement:
    3814       60916 :             columnDef                           { $$ = $1; }
    3815         732 :             | TableLikeClause                   { $$ = $1; }
    3816        2418 :             | TableConstraint                   { $$ = $1; }
    3817             :         ;
    3818             : 
    3819             : TypedTableElement:
    3820         300 :             columnOptions                       { $$ = $1; }
    3821          70 :             | TableConstraint                   { $$ = $1; }
    3822             :         ;
    3823             : 
    3824             : columnDef:  ColId Typename opt_column_storage opt_column_compression create_generic_options ColQualList
    3825             :                 {
    3826       62862 :                     ColumnDef *n = makeNode(ColumnDef);
    3827             : 
    3828       62862 :                     n->colname = $1;
    3829       62862 :                     n->typeName = $2;
    3830       62862 :                     n->storage_name = $3;
    3831       62862 :                     n->compression = $4;
    3832       62862 :                     n->inhcount = 0;
    3833       62862 :                     n->is_local = true;
    3834       62862 :                     n->is_not_null = false;
    3835       62862 :                     n->is_from_type = false;
    3836       62862 :                     n->storage = 0;
    3837       62862 :                     n->raw_default = NULL;
    3838       62862 :                     n->cooked_default = NULL;
    3839       62862 :                     n->collOid = InvalidOid;
    3840       62862 :                     n->fdwoptions = $5;
    3841       62862 :                     SplitColQualList($6, &n->constraints, &n->collClause,
    3842             :                                      yyscanner);
    3843       62862 :                     n->location = @1;
    3844       62862 :                     $$ = (Node *) n;
    3845             :                 }
    3846             :         ;
    3847             : 
    3848             : columnOptions:  ColId ColQualList
    3849             :                 {
    3850         120 :                     ColumnDef *n = makeNode(ColumnDef);
    3851             : 
    3852         120 :                     n->colname = $1;
    3853         120 :                     n->typeName = NULL;
    3854         120 :                     n->inhcount = 0;
    3855         120 :                     n->is_local = true;
    3856         120 :                     n->is_not_null = false;
    3857         120 :                     n->is_from_type = false;
    3858         120 :                     n->storage = 0;
    3859         120 :                     n->raw_default = NULL;
    3860         120 :                     n->cooked_default = NULL;
    3861         120 :                     n->collOid = InvalidOid;
    3862         120 :                     SplitColQualList($2, &n->constraints, &n->collClause,
    3863             :                                      yyscanner);
    3864         120 :                     n->location = @1;
    3865         120 :                     $$ = (Node *) n;
    3866             :                 }
    3867             :                 | ColId WITH OPTIONS ColQualList
    3868             :                 {
    3869         180 :                     ColumnDef *n = makeNode(ColumnDef);
    3870             : 
    3871         180 :                     n->colname = $1;
    3872         180 :                     n->typeName = NULL;
    3873         180 :                     n->inhcount = 0;
    3874         180 :                     n->is_local = true;
    3875         180 :                     n->is_not_null = false;
    3876         180 :                     n->is_from_type = false;
    3877         180 :                     n->storage = 0;
    3878         180 :                     n->raw_default = NULL;
    3879         180 :                     n->cooked_default = NULL;
    3880         180 :                     n->collOid = InvalidOid;
    3881         180 :                     SplitColQualList($4, &n->constraints, &n->collClause,
    3882             :                                      yyscanner);
    3883         180 :                     n->location = @1;
    3884         180 :                     $$ = (Node *) n;
    3885             :                 }
    3886             :         ;
    3887             : 
    3888             : column_compression:
    3889         138 :             COMPRESSION ColId                       { $$ = $2; }
    3890           6 :             | COMPRESSION DEFAULT                   { $$ = pstrdup("default"); }
    3891             :         ;
    3892             : 
    3893             : opt_column_compression:
    3894          76 :             column_compression                      { $$ = $1; }
    3895       62846 :             | /*EMPTY*/                             { $$ = NULL; }
    3896             :         ;
    3897             : 
    3898             : column_storage:
    3899         226 :             STORAGE ColId                           { $$ = $2; }
    3900           6 :             | STORAGE DEFAULT                       { $$ = pstrdup("default"); }
    3901             :         ;
    3902             : 
    3903             : opt_column_storage:
    3904          20 :             column_storage                          { $$ = $1; }
    3905       62902 :             | /*EMPTY*/                             { $$ = NULL; }
    3906             :         ;
    3907             : 
    3908             : ColQualList:
    3909       16982 :             ColQualList ColConstraint               { $$ = lappend($1, $2); }
    3910       64384 :             | /*EMPTY*/                             { $$ = NIL; }
    3911             :         ;
    3912             : 
    3913             : ColConstraint:
    3914             :             CONSTRAINT name ColConstraintElem
    3915             :                 {
    3916         662 :                     Constraint *n = castNode(Constraint, $3);
    3917             : 
    3918         662 :                     n->conname = $2;
    3919         662 :                     n->location = @1;
    3920         662 :                     $$ = (Node *) n;
    3921             :                 }
    3922       15532 :             | ColConstraintElem                     { $$ = $1; }
    3923         174 :             | ConstraintAttr                        { $$ = $1; }
    3924             :             | COLLATE any_name
    3925             :                 {
    3926             :                     /*
    3927             :                      * Note: the CollateClause is momentarily included in
    3928             :                      * the list built by ColQualList, but we split it out
    3929             :                      * again in SplitColQualList.
    3930             :                      */
    3931         614 :                     CollateClause *n = makeNode(CollateClause);
    3932             : 
    3933         614 :                     n->arg = NULL;
    3934         614 :                     n->collname = $2;
    3935         614 :                     n->location = @1;
    3936         614 :                     $$ = (Node *) n;
    3937             :                 }
    3938             :         ;
    3939             : 
    3940             : /* DEFAULT NULL is already the default for Postgres.
    3941             :  * But define it here and carry it forward into the system
    3942             :  * to make it explicit.
    3943             :  * - thomas 1998-09-13
    3944             :  *
    3945             :  * WITH NULL and NULL are not SQL-standard syntax elements,
    3946             :  * so leave them out. Use DEFAULT NULL to explicitly indicate
    3947             :  * that a column may have that value. WITH NULL leads to
    3948             :  * shift/reduce conflicts with WITH TIME ZONE anyway.
    3949             :  * - thomas 1999-01-08
    3950             :  *
    3951             :  * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
    3952             :  * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
    3953             :  * or be part of a_expr NOT LIKE or similar constructs).
    3954             :  */
    3955             : ColConstraintElem:
    3956             :             NOT NULL_P opt_no_inherit
    3957             :                 {
    3958        5974 :                     Constraint *n = makeNode(Constraint);
    3959             : 
    3960        5974 :                     n->contype = CONSTR_NOTNULL;
    3961        5974 :                     n->location = @1;
    3962        5974 :                     n->is_no_inherit = $3;
    3963        5974 :                     n->skip_validation = false;
    3964        5974 :                     n->initially_valid = true;
    3965        5974 :                     $$ = (Node *) n;
    3966             :                 }
    3967             :             | NULL_P
    3968             :                 {
    3969          24 :                     Constraint *n = makeNode(Constraint);
    3970             : 
    3971          24 :                     n->contype = CONSTR_NULL;
    3972          24 :                     n->location = @1;
    3973          24 :                     $$ = (Node *) n;
    3974             :                 }
    3975             :             | UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace
    3976             :                 {
    3977         404 :                     Constraint *n = makeNode(Constraint);
    3978             : 
    3979         404 :                     n->contype = CONSTR_UNIQUE;
    3980         404 :                     n->location = @1;
    3981         404 :                     n->nulls_not_distinct = !$2;
    3982         404 :                     n->keys = NULL;
    3983         404 :                     n->options = $3;
    3984         404 :                     n->indexname = NULL;
    3985         404 :                     n->indexspace = $4;
    3986         404 :                     $$ = (Node *) n;
    3987             :                 }
    3988             :             | PRIMARY KEY opt_definition OptConsTableSpace
    3989             :                 {
    3990        5370 :                     Constraint *n = makeNode(Constraint);
    3991             : 
    3992        5370 :                     n->contype = CONSTR_PRIMARY;
    3993        5370 :                     n->location = @1;
    3994        5370 :                     n->keys = NULL;
    3995        5370 :                     n->options = $3;
    3996        5370 :                     n->indexname = NULL;
    3997        5370 :                     n->indexspace = $4;
    3998        5370 :                     $$ = (Node *) n;
    3999             :                 }
    4000             :             | CHECK '(' a_expr ')' opt_no_inherit
    4001             :                 {
    4002         870 :                     Constraint *n = makeNode(Constraint);
    4003             : 
    4004         870 :                     n->contype = CONSTR_CHECK;
    4005         870 :                     n->location = @1;
    4006         870 :                     n->is_no_inherit = $5;
    4007         870 :                     n->raw_expr = $3;
    4008         870 :                     n->cooked_expr = NULL;
    4009         870 :                     n->skip_validation = false;
    4010         870 :                     n->initially_valid = true;
    4011         870 :                     $$ = (Node *) n;
    4012             :                 }
    4013             :             | DEFAULT b_expr
    4014             :                 {
    4015        1634 :                     Constraint *n = makeNode(Constraint);
    4016             : 
    4017        1634 :                     n->contype = CONSTR_DEFAULT;
    4018        1634 :                     n->location = @1;
    4019        1634 :                     n->raw_expr = $2;
    4020        1634 :                     n->cooked_expr = NULL;
    4021        1634 :                     $$ = (Node *) n;
    4022             :                 }
    4023             :             | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    4024             :                 {
    4025         296 :                     Constraint *n = makeNode(Constraint);
    4026             : 
    4027         296 :                     n->contype = CONSTR_IDENTITY;
    4028         296 :                     n->generated_when = $2;
    4029         296 :                     n->options = $5;
    4030         296 :                     n->location = @1;
    4031         296 :                     $$ = (Node *) n;
    4032             :                 }
    4033             :             | GENERATED generated_when AS '(' a_expr ')' STORED
    4034             :                 {
    4035         872 :                     Constraint *n = makeNode(Constraint);
    4036             : 
    4037         872 :                     n->contype = CONSTR_GENERATED;
    4038         872 :                     n->generated_when = $2;
    4039         872 :                     n->raw_expr = $5;
    4040         872 :                     n->cooked_expr = NULL;
    4041         872 :                     n->location = @1;
    4042             : 
    4043             :                     /*
    4044             :                      * Can't do this in the grammar because of shift/reduce
    4045             :                      * conflicts.  (IDENTITY allows both ALWAYS and BY
    4046             :                      * DEFAULT, but generated columns only allow ALWAYS.)  We
    4047             :                      * can also give a more useful error message and location.
    4048             :                      */
    4049         872 :                     if ($2 != ATTRIBUTE_IDENTITY_ALWAYS)
    4050           6 :                         ereport(ERROR,
    4051             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    4052             :                                  errmsg("for a generated column, GENERATED ALWAYS must be specified"),
    4053             :                                  parser_errposition(@2)));
    4054             : 
    4055         866 :                     $$ = (Node *) n;
    4056             :                 }
    4057             :             | REFERENCES qualified_name opt_column_list key_match key_actions
    4058             :                 {
    4059         756 :                     Constraint *n = makeNode(Constraint);
    4060             : 
    4061         756 :                     n->contype = CONSTR_FOREIGN;
    4062         756 :                     n->location = @1;
    4063         756 :                     n->pktable = $2;
    4064         756 :                     n->fk_attrs = NIL;
    4065         756 :                     n->pk_attrs = $3;
    4066         756 :                     n->fk_matchtype = $4;
    4067         756 :                     n->fk_upd_action = ($5)->updateAction->action;
    4068         756 :                     n->fk_del_action = ($5)->deleteAction->action;
    4069         756 :                     n->fk_del_set_cols = ($5)->deleteAction->cols;
    4070         756 :                     n->skip_validation = false;
    4071         756 :                     n->initially_valid = true;
    4072         756 :                     $$ = (Node *) n;
    4073             :                 }
    4074             :         ;
    4075             : 
    4076             : opt_unique_null_treatment:
    4077          12 :             NULLS_P DISTINCT        { $$ = true; }
    4078          30 :             | NULLS_P NOT DISTINCT  { $$ = false; }
    4079        7156 :             | /*EMPTY*/             { $$ = true; }
    4080             :         ;
    4081             : 
    4082             : generated_when:
    4083        1204 :             ALWAYS          { $$ = ATTRIBUTE_IDENTITY_ALWAYS; }
    4084         166 :             | BY DEFAULT    { $$ = ATTRIBUTE_IDENTITY_BY_DEFAULT; }
    4085             :         ;
    4086             : 
    4087             : /*
    4088             :  * ConstraintAttr represents constraint attributes, which we parse as if
    4089             :  * they were independent constraint clauses, in order to avoid shift/reduce
    4090             :  * conflicts (since NOT might start either an independent NOT NULL clause
    4091             :  * or an attribute).  parse_utilcmd.c is responsible for attaching the
    4092             :  * attribute information to the preceding "real" constraint node, and for
    4093             :  * complaining if attribute clauses appear in the wrong place or wrong
    4094             :  * combinations.
    4095             :  *
    4096             :  * See also ConstraintAttributeSpec, which can be used in places where
    4097             :  * there is no parsing conflict.  (Note: currently, NOT VALID and NO INHERIT
    4098             :  * are allowed clauses in ConstraintAttributeSpec, but not here.  Someday we
    4099             :  * might need to allow them here too, but for the moment it doesn't seem
    4100             :  * useful in the statements that use ConstraintAttr.)
    4101             :  */
    4102             : ConstraintAttr:
    4103             :             DEFERRABLE
    4104             :                 {
    4105          96 :                     Constraint *n = makeNode(Constraint);
    4106             : 
    4107          96 :                     n->contype = CONSTR_ATTR_DEFERRABLE;
    4108          96 :                     n->location = @1;
    4109          96 :                     $$ = (Node *) n;
    4110             :                 }
    4111             :             | NOT DEFERRABLE
    4112             :                 {
    4113           0 :                     Constraint *n = makeNode(Constraint);
    4114             : 
    4115           0 :                     n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
    4116           0 :                     n->location = @1;
    4117           0 :                     $$ = (Node *) n;
    4118             :                 }
    4119             :             | INITIALLY DEFERRED
    4120             :                 {
    4121          72 :                     Constraint *n = makeNode(Constraint);
    4122             : 
    4123          72 :                     n->contype = CONSTR_ATTR_DEFERRED;
    4124          72 :                     n->location = @1;
    4125          72 :                     $$ = (Node *) n;
    4126             :                 }
    4127             :             | INITIALLY IMMEDIATE
    4128             :                 {
    4129           6 :                     Constraint *n = makeNode(Constraint);
    4130             : 
    4131           6 :                     n->contype = CONSTR_ATTR_IMMEDIATE;
    4132           6 :                     n->location = @1;
    4133           6 :                     $$ = (Node *) n;
    4134             :                 }
    4135             :         ;
    4136             : 
    4137             : 
    4138             : TableLikeClause:
    4139             :             LIKE qualified_name TableLikeOptionList
    4140             :                 {
    4141         732 :                     TableLikeClause *n = makeNode(TableLikeClause);
    4142             : 
    4143         732 :                     n->relation = $2;
    4144         732 :                     n->options = $3;
    4145         732 :                     n->relationOid = InvalidOid;
    4146         732 :                     $$ = (Node *) n;
    4147             :                 }
    4148             :         ;
    4149             : 
    4150             : TableLikeOptionList:
    4151         258 :                 TableLikeOptionList INCLUDING TableLikeOption   { $$ = $1 | $3; }
    4152           2 :                 | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
    4153         732 :                 | /* EMPTY */                       { $$ = 0; }
    4154             :         ;
    4155             : 
    4156             : TableLikeOption:
    4157          24 :                 COMMENTS            { $$ = CREATE_TABLE_LIKE_COMMENTS; }
    4158           6 :                 | COMPRESSION       { $$ = CREATE_TABLE_LIKE_COMPRESSION; }
    4159          54 :                 | CONSTRAINTS       { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
    4160          20 :                 | DEFAULTS          { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
    4161          12 :                 | IDENTITY_P        { $$ = CREATE_TABLE_LIKE_IDENTITY; }
    4162          24 :                 | GENERATED         { $$ = CREATE_TABLE_LIKE_GENERATED; }
    4163          50 :                 | INDEXES           { $$ = CREATE_TABLE_LIKE_INDEXES; }
    4164           0 :                 | STATISTICS        { $$ = CREATE_TABLE_LIKE_STATISTICS; }
    4165          26 :                 | STORAGE           { $$ = CREATE_TABLE_LIKE_STORAGE; }
    4166          44 :                 | ALL               { $$ = CREATE_TABLE_LIKE_ALL; }
    4167             :         ;
    4168             : 
    4169             : 
    4170             : /* ConstraintElem specifies constraint syntax which is not embedded into
    4171             :  *  a column definition. ColConstraintElem specifies the embedded form.
    4172             :  * - thomas 1997-12-03
    4173             :  */
    4174             : TableConstraint:
    4175             :             CONSTRAINT name ConstraintElem
    4176             :                 {
    4177        3308 :                     Constraint *n = castNode(Constraint, $3);
    4178             : 
    4179        3308 :                     n->conname = $2;
    4180        3308 :                     n->location = @1;
    4181        3308 :                     $$ = (Node *) n;
    4182             :                 }
    4183       10794 :             | ConstraintElem                        { $$ = $1; }
    4184             :         ;
    4185             : 
    4186             : ConstraintElem:
    4187             :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    4188             :                 {
    4189        1038 :                     Constraint *n = makeNode(Constraint);
    4190             : 
    4191        1038 :                     n->contype = CONSTR_CHECK;
    4192        1038 :                     n->location = @1;
    4193        1038 :                     n->raw_expr = $3;
    4194        1038 :                     n->cooked_expr = NULL;
    4195        1038 :                     processCASbits($5, @5, "CHECK",
    4196             :                                    NULL, NULL, &n->skip_validation,
    4197             :                                    &n->is_no_inherit, yyscanner);
    4198        1038 :                     n->initially_valid = !n->skip_validation;
    4199        1038 :                     $$ = (Node *) n;
    4200             :                 }
    4201             :             | NOT NULL_P ColId ConstraintAttributeSpec
    4202             :                 {
    4203         206 :                     Constraint *n = makeNode(Constraint);
    4204             : 
    4205         206 :                     n->contype = CONSTR_NOTNULL;
    4206         206 :                     n->location = @1;
    4207         206 :                     n->keys = list_make1(makeString($3));
    4208             :                     /* no NOT VALID support yet */
    4209         206 :                     processCASbits($4, @4, "NOT NULL",
    4210             :                                    NULL, NULL, NULL,
    4211             :                                    &n->is_no_inherit, yyscanner);
    4212         206 :                     n->initially_valid = true;
    4213         206 :                     $$ = (Node *) n;
    4214             :                 }
    4215             :             | UNIQUE opt_unique_null_treatment '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
    4216             :                 ConstraintAttributeSpec
    4217             :                 {
    4218         510 :                     Constraint *n = makeNode(Constraint);
    4219             : 
    4220         510 :                     n->contype = CONSTR_UNIQUE;
    4221         510 :                     n->location = @1;
    4222         510 :                     n->nulls_not_distinct = !$2;
    4223         510 :                     n->keys = $4;
    4224         510 :                     n->without_overlaps = $5;
    4225         510 :                     n->including = $7;
    4226         510 :                     n->options = $8;
    4227         510 :                     n->indexname = NULL;
    4228         510 :                     n->indexspace = $9;
    4229         510 :                     processCASbits($10, @10, "UNIQUE",
    4230             :                                    &n->deferrable, &n->initdeferred, NULL,
    4231             :                                    NULL, yyscanner);
    4232         510 :                     $$ = (Node *) n;
    4233             :                 }
    4234             :             | UNIQUE ExistingIndex ConstraintAttributeSpec
    4235             :                 {
    4236        3682 :                     Constraint *n = makeNode(Constraint);
    4237             : 
    4238        3682 :                     n->contype = CONSTR_UNIQUE;
    4239        3682 :                     n->location = @1;
    4240        3682 :                     n->keys = NIL;
    4241        3682 :                     n->including = NIL;
    4242        3682 :                     n->options = NIL;
    4243        3682 :                     n->indexname = $2;
    4244        3682 :                     n->indexspace = NULL;
    4245        3682 :                     processCASbits($3, @3, "UNIQUE",
    4246             :                                    &n->deferrable, &n->initdeferred, NULL,
    4247             :                                    NULL, yyscanner);
    4248        3682 :                     $$ = (Node *) n;
    4249             :                 }
    4250             :             | PRIMARY KEY '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
    4251             :                 ConstraintAttributeSpec
    4252             :                 {
    4253        1934 :                     Constraint *n = makeNode(Constraint);
    4254             : 
    4255        1934 :                     n->contype = CONSTR_PRIMARY;
    4256        1934 :                     n->location = @1;
    4257        1934 :                     n->keys = $4;
    4258        1934 :                     n->without_overlaps = $5;
    4259        1934 :                     n->including = $7;
    4260        1934 :                     n->options = $8;
    4261        1934 :                     n->indexname = NULL;
    4262        1934 :                     n->indexspace = $9;
    4263        1934 :                     processCASbits($10, @10, "PRIMARY KEY",
    4264             :                                    &n->deferrable, &n->initdeferred, NULL,
    4265             :                                    NULL, yyscanner);
    4266        1934 :                     $$ = (Node *) n;
    4267             :                 }
    4268             :             | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
    4269             :                 {
    4270        4778 :                     Constraint *n = makeNode(Constraint);
    4271             : 
    4272        4778 :                     n->contype = CONSTR_PRIMARY;
    4273        4778 :                     n->location = @1;
    4274        4778 :                     n->keys = NIL;
    4275        4778 :                     n->including = NIL;
    4276        4778 :                     n->options = NIL;
    4277        4778 :                     n->indexname = $3;
    4278        4778 :                     n->indexspace = NULL;
    4279        4778 :                     processCASbits($4, @4, "PRIMARY KEY",
    4280             :                                    &n->deferrable, &n->initdeferred, NULL,
    4281             :                                    NULL, yyscanner);
    4282        4778 :                     $$ = (Node *) n;
    4283             :                 }
    4284             :             | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
    4285             :                 opt_c_include opt_definition OptConsTableSpace OptWhereClause
    4286             :                 ConstraintAttributeSpec
    4287             :                 {
    4288         234 :                     Constraint *n = makeNode(Constraint);
    4289             : 
    4290         234 :                     n->contype = CONSTR_EXCLUSION;
    4291         234 :                     n->location = @1;
    4292         234 :                     n->access_method = $2;
    4293         234 :                     n->exclusions = $4;
    4294         234 :                     n->including = $6;
    4295         234 :                     n->options = $7;
    4296         234 :                     n->indexname = NULL;
    4297         234 :                     n->indexspace = $8;
    4298         234 :                     n->where_clause = $9;
    4299         234 :                     processCASbits($10, @10, "EXCLUDE",
    4300             :                                    &n->deferrable, &n->initdeferred, NULL,
    4301             :                                    NULL, yyscanner);
    4302         234 :                     $$ = (Node *) n;
    4303             :                 }
    4304             :             | FOREIGN KEY '(' columnList optionalPeriodName ')' REFERENCES qualified_name
    4305             :                 opt_column_and_period_list key_match key_actions ConstraintAttributeSpec
    4306             :                 {
    4307        1720 :                     Constraint *n = makeNode(Constraint);
    4308             : 
    4309        1720 :                     n->contype = CONSTR_FOREIGN;
    4310        1720 :                     n->location = @1;
    4311        1720 :                     n->pktable = $8;
    4312        1720 :                     n->fk_attrs = $4;
    4313        1720 :                     if ($5)
    4314             :                     {
    4315         286 :                         n->fk_attrs = lappend(n->fk_attrs, $5);
    4316         286 :                         n->fk_with_period = true;
    4317             :                     }
    4318        1720 :                     n->pk_attrs = linitial($9);
    4319        1720 :                     if (lsecond($9))
    4320             :                     {
    4321         178 :                         n->pk_attrs = lappend(n->pk_attrs, lsecond($9));
    4322         178 :                         n->pk_with_period = true;
    4323             :                     }
    4324        1720 :                     n->fk_matchtype = $10;
    4325        1720 :                     n->fk_upd_action = ($11)->updateAction->action;
    4326        1720 :                     n->fk_del_action = ($11)->deleteAction->action;
    4327        1720 :                     n->fk_del_set_cols = ($11)->deleteAction->cols;
    4328        1720 :                     processCASbits($12, @12, "FOREIGN KEY",
    4329             :                                    &n->deferrable, &n->initdeferred,
    4330             :                                    &n->skip_validation, NULL,
    4331             :                                    yyscanner);
    4332        1720 :                     n->initially_valid = !n->skip_validation;
    4333        1720 :                     $$ = (Node *) n;
    4334             :                 }
    4335             :         ;
    4336             : 
    4337             : /*
    4338             :  * DomainConstraint is separate from TableConstraint because the syntax for
    4339             :  * NOT NULL constraints is different.  For table constraints, we need to
    4340             :  * accept a column name, but for domain constraints, we don't.  (We could
    4341             :  * accept something like NOT NULL VALUE, but that seems weird.)  CREATE DOMAIN
    4342             :  * (which uses ColQualList) has for a long time accepted NOT NULL without a
    4343             :  * column name, so it makes sense that ALTER DOMAIN (which uses
    4344             :  * DomainConstraint) does as well.  None of these syntaxes are per SQL
    4345             :  * standard; we are just living with the bits of inconsistency that have built
    4346             :  * up over time.
    4347             :  */
    4348             : DomainConstraint:
    4349             :             CONSTRAINT name DomainConstraintElem
    4350             :                 {
    4351         150 :                     Constraint *n = castNode(Constraint, $3);
    4352             : 
    4353         150 :                     n->conname = $2;
    4354         150 :                     n->location = @1;
    4355         150 :                     $$ = (Node *) n;
    4356             :                 }
    4357          18 :             | DomainConstraintElem                  { $$ = $1; }
    4358             :         ;
    4359             : 
    4360             : DomainConstraintElem:
    4361             :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    4362             :                 {
    4363         144 :                     Constraint *n = makeNode(Constraint);
    4364             : 
    4365         144 :                     n->contype = CONSTR_CHECK;
    4366         144 :                     n->location = @1;
    4367         144 :                     n->raw_expr = $3;
    4368         144 :                     n->cooked_expr = NULL;
    4369         144 :                     processCASbits($5, @5, "CHECK",
    4370             :                                    NULL, NULL, &n->skip_validation,
    4371             :                                    &n->is_no_inherit, yyscanner);
    4372         144 :                     n->initially_valid = !n->skip_validation;
    4373         144 :                     $$ = (Node *) n;
    4374             :                 }
    4375             :             | NOT NULL_P ConstraintAttributeSpec
    4376             :                 {
    4377          24 :                     Constraint *n = makeNode(Constraint);
    4378             : 
    4379          24 :                     n->contype = CONSTR_NOTNULL;
    4380          24 :                     n->location = @1;
    4381          24 :                     n->keys = list_make1(makeString("value"));
    4382             :                     /* no NOT VALID support yet */
    4383          24 :                     processCASbits($3, @3, "NOT NULL",
    4384             :                                    NULL, NULL, NULL,
    4385             :                                    &n->is_no_inherit, yyscanner);
    4386          24 :                     n->initially_valid = true;
    4387          24 :                     $$ = (Node *) n;
    4388             :                 }
    4389             :         ;
    4390             : 
    4391         206 : opt_no_inherit: NO INHERIT                          {  $$ = true; }
    4392        6638 :             | /* EMPTY */                           {  $$ = false; }
    4393             :         ;
    4394             : 
    4395             : opt_without_overlaps:
    4396         392 :             WITHOUT OVERLAPS                        { $$ = true; }
    4397        2052 :             | /*EMPTY*/                             { $$ = false; }
    4398             :     ;
    4399             : 
    4400             : opt_column_list:
    4401        8662 :             '(' columnList ')'                      { $$ = $2; }
    4402       32930 :             | /*EMPTY*/                             { $$ = NIL; }
    4403             :         ;
    4404             : 
    4405             : columnList:
    4406       14516 :             columnElem                              { $$ = list_make1($1); }
    4407       24454 :             | columnList ',' columnElem             { $$ = lappend($1, $3); }
    4408             :         ;
    4409             : 
    4410             : optionalPeriodName:
    4411         464 :             ',' PERIOD columnElem { $$ = $3; }
    4412        2388 :             | /*EMPTY*/               { $$ = NULL; }
    4413             :     ;
    4414             : 
    4415             : opt_column_and_period_list:
    4416        1126 :             '(' columnList optionalPeriodName ')'           { $$ = list_make2($2, $3); }
    4417         600 :             | /*EMPTY*/                             { $$ = list_make2(NIL, NULL); }
    4418             :         ;
    4419             : 
    4420             : columnElem: ColId
    4421             :                 {
    4422       39434 :                     $$ = (Node *) makeString($1);
    4423             :                 }
    4424             :         ;
    4425             : 
    4426         168 : opt_c_include:  INCLUDE '(' columnList ')'          { $$ = $3; }
    4427        2510 :              |      /* EMPTY */                     { $$ = NIL; }
    4428             :         ;
    4429             : 
    4430             : key_match:  MATCH FULL
    4431             :             {
    4432          98 :                 $$ = FKCONSTR_MATCH_FULL;
    4433             :             }
    4434             :         | MATCH PARTIAL
    4435             :             {
    4436           0 :                 ereport(ERROR,
    4437             :                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4438             :                          errmsg("MATCH PARTIAL not yet implemented"),
    4439             :                          parser_errposition(@1)));
    4440             :                 $$ = FKCONSTR_MATCH_PARTIAL;
    4441             :             }
    4442             :         | MATCH SIMPLE
    4443             :             {
    4444           6 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4445             :             }
    4446             :         | /*EMPTY*/
    4447             :             {
    4448        2378 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4449             :             }
    4450             :         ;
    4451             : 
    4452             : ExclusionConstraintList:
    4453         234 :             ExclusionConstraintElem                 { $$ = list_make1($1); }
    4454             :             | ExclusionConstraintList ',' ExclusionConstraintElem
    4455         106 :                                                     { $$ = lappend($1, $3); }
    4456             :         ;
    4457             : 
    4458             : ExclusionConstraintElem: index_elem WITH any_operator
    4459             :             {
    4460         340 :                 $$ = list_make2($1, $3);
    4461             :             }
    4462             :             /* allow OPERATOR() decoration for the benefit of ruleutils.c */
    4463             :             | index_elem WITH OPERATOR '(' any_operator ')'
    4464             :             {
    4465           0 :                 $$ = list_make2($1, $5);
    4466             :             }
    4467             :         ;
    4468             : 
    4469             : OptWhereClause:
    4470         426 :             WHERE '(' a_expr ')'                    { $$ = $3; }
    4471        1134 :             | /*EMPTY*/                             { $$ = NULL; }
    4472             :         ;
    4473             : 
    4474             : key_actions:
    4475             :             key_update
    4476             :                 {
    4477          50 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4478             : 
    4479          50 :                     n->updateAction = $1;
    4480          50 :                     n->deleteAction = palloc(sizeof(KeyAction));
    4481          50 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4482          50 :                     n->deleteAction->cols = NIL;
    4483          50 :                     $$ = n;
    4484             :                 }
    4485             :             | key_delete
    4486             :                 {
    4487         160 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4488             : 
    4489         160 :                     n->updateAction = palloc(sizeof(KeyAction));
    4490         160 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4491         160 :                     n->updateAction->cols = NIL;
    4492         160 :                     n->deleteAction = $1;
    4493         160 :                     $$ = n;
    4494             :                 }
    4495             :             | key_update key_delete
    4496             :                 {
    4497         150 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4498             : 
    4499         150 :                     n->updateAction = $1;
    4500         150 :                     n->deleteAction = $2;
    4501         150 :                     $$ = n;
    4502             :                 }
    4503             :             | key_delete key_update
    4504             :                 {
    4505         132 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4506             : 
    4507         132 :                     n->updateAction = $2;
    4508         132 :                     n->deleteAction = $1;
    4509         132 :                     $$ = n;
    4510             :                 }
    4511             :             | /*EMPTY*/
    4512             :                 {
    4513        1984 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4514             : 
    4515        1984 :                     n->updateAction = palloc(sizeof(KeyAction));
    4516        1984 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4517        1984 :                     n->updateAction->cols = NIL;
    4518        1984 :                     n->deleteAction = palloc(sizeof(KeyAction));
    4519        1984 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4520        1984 :                     n->deleteAction->cols = NIL;
    4521        1984 :                     $$ = n;
    4522             :                 }
    4523             :         ;
    4524             : 
    4525             : key_update: ON UPDATE key_action
    4526             :                 {
    4527         338 :                     if (($3)->cols)
    4528           6 :                         ereport(ERROR,
    4529             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4530             :                                  errmsg("a column list with %s is only supported for ON DELETE actions",
    4531             :                                         ($3)->action == FKCONSTR_ACTION_SETNULL ? "SET NULL" : "SET DEFAULT"),
    4532             :                                  parser_errposition(@1)));
    4533         332 :                     $$ = $3;
    4534             :                 }
    4535             :         ;
    4536             : 
    4537             : key_delete: ON DELETE_P key_action
    4538             :                 {
    4539         442 :                     $$ = $3;
    4540             :                 }
    4541             :         ;
    4542             : 
    4543             : key_action:
    4544             :             NO ACTION
    4545             :                 {
    4546          74 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4547             : 
    4548          74 :                     n->action = FKCONSTR_ACTION_NOACTION;
    4549          74 :                     n->cols = NIL;
    4550          74 :                     $$ = n;
    4551             :                 }
    4552             :             | RESTRICT
    4553             :                 {
    4554          58 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4555             : 
    4556          58 :                     n->action = FKCONSTR_ACTION_RESTRICT;
    4557          58 :                     n->cols = NIL;
    4558          58 :                     $$ = n;
    4559             :                 }
    4560             :             | CASCADE
    4561             :                 {
    4562         386 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4563             : 
    4564         386 :                     n->action = FKCONSTR_ACTION_CASCADE;
    4565         386 :                     n->cols = NIL;
    4566         386 :                     $$ = n;
    4567             :                 }
    4568             :             | SET NULL_P opt_column_list
    4569             :                 {
    4570         172 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4571             : 
    4572         172 :                     n->action = FKCONSTR_ACTION_SETNULL;
    4573         172 :                     n->cols = $3;
    4574         172 :                     $$ = n;
    4575             :                 }
    4576             :             | SET DEFAULT opt_column_list
    4577             :                 {
    4578          90 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4579             : 
    4580          90 :                     n->action = FKCONSTR_ACTION_SETDEFAULT;
    4581          90 :                     n->cols = $3;
    4582          90 :                     $$ = n;
    4583             :                 }
    4584             :         ;
    4585             : 
    4586        1830 : OptInherit: INHERITS '(' qualified_name_list ')'    { $$ = $3; }
    4587       25576 :             | /*EMPTY*/                             { $$ = NIL; }
    4588             :         ;
    4589             : 
    4590             : /* Optional partition key specification */
    4591        4942 : OptPartitionSpec: PartitionSpec { $$ = $1; }
    4592       30492 :             | /*EMPTY*/         { $$ = NULL; }
    4593             :         ;
    4594             : 
    4595             : PartitionSpec: PARTITION BY ColId '(' part_params ')'
    4596             :                 {
    4597        4948 :                     PartitionSpec *n = makeNode(PartitionSpec);
    4598             : 
    4599        4948 :                     n->strategy = parsePartitionStrategy($3);
    4600        4942 :                     n->partParams = $5;
    4601        4942 :                     n->location = @1;
    4602             : 
    4603        4942 :                     $$ = n;
    4604             :                 }
    4605             :         ;
    4606             : 
    4607        4948 : part_params:    part_elem                       { $$ = list_make1($1); }
    4608         462 :             | part_params ',' part_elem         { $$ = lappend($1, $3); }
    4609             :         ;
    4610             : 
    4611             : part_elem: ColId opt_collate opt_qualified_name
    4612             :                 {
    4613        5112 :                     PartitionElem *n = makeNode(PartitionElem);
    4614             : 
    4615        5112 :                     n->name = $1;
    4616        5112 :                     n->expr = NULL;
    4617        5112 :                     n->collation = $2;
    4618        5112 :                     n->opclass = $3;
    4619        5112 :                     n->location = @1;
    4620        5112 :                     $$ = n;
    4621             :                 }
    4622             :             | func_expr_windowless opt_collate opt_qualified_name
    4623             :                 {
    4624         130 :                     PartitionElem *n = makeNode(PartitionElem);
    4625             : 
    4626         130 :                     n->name = NULL;
    4627         130 :                     n->expr = $1;
    4628         130 :                     n->collation = $2;
    4629         130 :                     n->opclass = $3;
    4630         130 :                     n->location = @1;
    4631         130 :                     $$ = n;
    4632             :                 }
    4633             :             | '(' a_expr ')' opt_collate opt_qualified_name
    4634             :                 {
    4635         168 :                     PartitionElem *n = makeNode(PartitionElem);
    4636             : 
    4637         168 :                     n->name = NULL;
    4638         168 :                     n->expr = $2;
    4639         168 :                     n->collation = $4;
    4640         168 :                     n->opclass = $5;
    4641         168 :                     n->location = @1;
    4642         168 :                     $$ = n;
    4643             :                 }
    4644             :         ;
    4645             : 
    4646             : table_access_method_clause:
    4647         128 :             USING name                          { $$ = $2; }
    4648       37116 :             | /*EMPTY*/                         { $$ = NULL; }
    4649             :         ;
    4650             : 
    4651             : /* WITHOUT OIDS is legacy only */
    4652             : OptWith:
    4653         618 :             WITH reloptions             { $$ = $2; }
    4654          24 :             | WITHOUT OIDS              { $$ = NIL; }
    4655       36038 :             | /*EMPTY*/                 { $$ = NIL; }
    4656             :         ;
    4657             : 
    4658          56 : OnCommitOption:  ON COMMIT DROP             { $$ = ONCOMMIT_DROP; }
    4659          98 :             | ON COMMIT DELETE_P ROWS       { $$ = ONCOMMIT_DELETE_ROWS; }
    4660          24 :             | ON COMMIT PRESERVE ROWS       { $$ = ONCOMMIT_PRESERVE_ROWS; }
    4661       36502 :             | /*EMPTY*/                     { $$ = ONCOMMIT_NOOP; }
    4662             :         ;
    4663             : 
    4664         204 : OptTableSpace:   TABLESPACE name                    { $$ = $2; }
    4665       43318 :             | /*EMPTY*/                             { $$ = NULL; }
    4666             :         ;
    4667             : 
    4668          66 : OptConsTableSpace:   USING INDEX TABLESPACE name    { $$ = $4; }
    4669        8386 :             | /*EMPTY*/                             { $$ = NULL; }
    4670             :         ;
    4671             : 
    4672        8460 : ExistingIndex:   USING INDEX name                   { $$ = $3; }
    4673             :         ;
    4674             : 
    4675             : /*****************************************************************************
    4676             :  *
    4677             :  *      QUERY :
    4678             :  *              CREATE STATISTICS [[IF NOT EXISTS] stats_name] [(stat types)]
    4679             :  *                  ON expression-list FROM from_list
    4680             :  *
    4681             :  * Note: the expectation here is that the clauses after ON are a subset of
    4682             :  * SELECT syntax, allowing for expressions and joined tables, and probably
    4683             :  * someday a WHERE clause.  Much less than that is currently implemented,
    4684             :  * but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
    4685             :  * errors as necessary at execution.
    4686             :  *
    4687             :  * Statistics name is optional unless IF NOT EXISTS is specified.
    4688             :  *
    4689             :  *****************************************************************************/
    4690             : 
    4691             : CreateStatsStmt:
    4692             :             CREATE STATISTICS opt_qualified_name
    4693             :             opt_name_list ON stats_params FROM from_list
    4694             :                 {
    4695         560 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4696             : 
    4697         560 :                     n->defnames = $3;
    4698         560 :                     n->stat_types = $4;
    4699         560 :                     n->exprs = $6;
    4700         560 :                     n->relations = $8;
    4701         560 :                     n->stxcomment = NULL;
    4702         560 :                     n->if_not_exists = false;
    4703         560 :                     $$ = (Node *) n;
    4704             :                 }
    4705             :             | CREATE STATISTICS IF_P NOT EXISTS any_name
    4706             :             opt_name_list ON stats_params FROM from_list
    4707             :                 {
    4708          12 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4709             : 
    4710          12 :                     n->defnames = $6;
    4711          12 :                     n->stat_types = $7;
    4712          12 :                     n->exprs = $9;
    4713          12 :                     n->relations = $11;
    4714          12 :                     n->stxcomment = NULL;
    4715          12 :                     n->if_not_exists = true;
    4716          12 :                     $$ = (Node *) n;
    4717             :                 }
    4718             :             ;
    4719             : 
    4720             : /*
    4721             :  * Statistics attributes can be either simple column references, or arbitrary
    4722             :  * expressions in parens.  For compatibility with index attributes permitted
    4723             :  * in CREATE INDEX, we allow an expression that's just a function call to be
    4724             :  * written without parens.
    4725             :  */
    4726             : 
    4727         584 : stats_params:   stats_param                         { $$ = list_make1($1); }
    4728         934 :             | stats_params ',' stats_param          { $$ = lappend($1, $3); }
    4729             :         ;
    4730             : 
    4731             : stats_param:    ColId
    4732             :                 {
    4733        1074 :                     $$ = makeNode(StatsElem);
    4734        1074 :                     $$->name = $1;
    4735        1074 :                     $$->expr = NULL;
    4736             :                 }
    4737             :             | func_expr_windowless
    4738             :                 {
    4739          32 :                     $$ = makeNode(StatsElem);
    4740          32 :                     $$->name = NULL;
    4741          32 :                     $$->expr = $1;
    4742             :                 }
    4743             :             | '(' a_expr ')'
    4744             :                 {
    4745         412 :                     $$ = makeNode(StatsElem);
    4746         412 :                     $$->name = NULL;
    4747         412 :                     $$->expr = $2;
    4748             :                 }
    4749             :         ;
    4750             : 
    4751             : /*****************************************************************************
    4752             :  *
    4753             :  *      QUERY :
    4754             :  *              ALTER STATISTICS [IF EXISTS] stats_name
    4755             :  *                  SET STATISTICS  <SignedIconst>
    4756             :  *
    4757             :  *****************************************************************************/
    4758             : 
    4759             : AlterStatsStmt:
    4760             :             ALTER STATISTICS any_name SET STATISTICS set_statistics_value
    4761             :                 {
    4762          20 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4763             : 
    4764          20 :                     n->defnames = $3;
    4765          20 :                     n->missing_ok = false;
    4766          20 :                     n->stxstattarget = $6;
    4767          20 :                     $$ = (Node *) n;
    4768             :                 }
    4769             :             | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
    4770             :                 {
    4771           6 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4772             : 
    4773           6 :                     n->defnames = $5;
    4774           6 :                     n->missing_ok = true;
    4775           6 :                     n->stxstattarget = $8;
    4776           6 :                     $$ = (Node *) n;
    4777             :                 }
    4778             :             ;
    4779             : 
    4780             : /*****************************************************************************
    4781             :  *
    4782             :  *      QUERY :
    4783             :  *              CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
    4784             :  *
    4785             :  *
    4786             :  * Note: SELECT ... INTO is a now-deprecated alternative for this.
    4787             :  *
    4788             :  *****************************************************************************/
    4789             : 
    4790             : CreateAsStmt:
    4791             :         CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
    4792             :                 {
    4793        1122 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4794             : 
    4795        1122 :                     ctas->query = $6;
    4796        1122 :                     ctas->into = $4;
    4797        1122 :                     ctas->objtype = OBJECT_TABLE;
    4798        1122 :                     ctas->is_select_into = false;
    4799        1122 :                     ctas->if_not_exists = false;
    4800             :                     /* cram additional flags into the IntoClause */
    4801        1122 :                     $4->rel->relpersistence = $2;
    4802        1122 :                     $4->skipData = !($7);
    4803        1122 :                     $$ = (Node *) ctas;
    4804             :                 }
    4805             :         | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
    4806             :                 {
    4807          52 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4808             : 
    4809          52 :                     ctas->query = $9;
    4810          52 :                     ctas->into = $7;
    4811          52 :                     ctas->objtype = OBJECT_TABLE;
    4812          52 :                     ctas->is_select_into = false;
    4813          52 :                     ctas->if_not_exists = true;
    4814             :                     /* cram additional flags into the IntoClause */
    4815          52 :                     $7->rel->relpersistence = $2;
    4816          52 :                     $7->skipData = !($10);
    4817          52 :                     $$ = (Node *) ctas;
    4818             :                 }
    4819             :         ;
    4820             : 
    4821             : create_as_target:
    4822             :             qualified_name opt_column_list table_access_method_clause
    4823             :             OptWith OnCommitOption OptTableSpace
    4824             :                 {
    4825        1258 :                     $$ = makeNode(IntoClause);
    4826        1258 :                     $$->rel = $1;
    4827        1258 :                     $$->colNames = $2;
    4828        1258 :                     $$->accessMethod = $3;
    4829        1258 :                     $$->options = $4;
    4830        1258 :                     $$->onCommit = $5;
    4831        1258 :                     $$->tableSpaceName = $6;
    4832        1258 :                     $$->viewQuery = NULL;
    4833        1258 :                     $$->skipData = false;        /* might get changed later */
    4834             :                 }
    4835             :         ;
    4836             : 
    4837             : opt_with_data:
    4838          36 :             WITH DATA_P                             { $$ = true; }
    4839         212 :             | WITH NO DATA_P                        { $$ = false; }
    4840        1826 :             | /*EMPTY*/                             { $$ = true; }
    4841             :         ;
    4842             : 
    4843             : 
    4844             : /*****************************************************************************
    4845             :  *
    4846             :  *      QUERY :
    4847             :  *              CREATE MATERIALIZED VIEW relname AS SelectStmt
    4848             :  *
    4849             :  *****************************************************************************/
    4850             : 
    4851             : CreateMatViewStmt:
    4852             :         CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
    4853             :                 {
    4854         510 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4855             : 
    4856         510 :                     ctas->query = $7;
    4857         510 :                     ctas->into = $5;
    4858         510 :                     ctas->objtype = OBJECT_MATVIEW;
    4859         510 :                     ctas->is_select_into = false;
    4860         510 :                     ctas->if_not_exists = false;
    4861             :                     /* cram additional flags into the IntoClause */
    4862         510 :                     $5->rel->relpersistence = $2;
    4863         510 :                     $5->skipData = !($8);
    4864         510 :                     $$ = (Node *) ctas;
    4865             :                 }
    4866             :         | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
    4867             :                 {
    4868          48 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4869             : 
    4870          48 :                     ctas->query = $10;
    4871          48 :                     ctas->into = $8;
    4872          48 :                     ctas->objtype = OBJECT_MATVIEW;
    4873          48 :                     ctas->is_select_into = false;
    4874          48 :                     ctas->if_not_exists = true;
    4875             :                     /* cram additional flags into the IntoClause */
    4876          48 :                     $8->rel->relpersistence = $2;
    4877          48 :                     $8->skipData = !($11);
    4878          48 :                     $$ = (Node *) ctas;
    4879             :                 }
    4880             :         ;
    4881             : 
    4882             : create_mv_target:
    4883             :             qualified_name opt_column_list table_access_method_clause opt_reloptions OptTableSpace
    4884             :                 {
    4885         558 :                     $$ = makeNode(IntoClause);
    4886         558 :                     $$->rel = $1;
    4887         558 :                     $$->colNames = $2;
    4888         558 :                     $$->accessMethod = $3;
    4889         558 :                     $$->options = $4;
    4890         558 :                     $$->onCommit = ONCOMMIT_NOOP;
    4891         558 :                     $$->tableSpaceName = $5;
    4892         558 :                     $$->viewQuery = NULL;        /* filled at analysis time */
    4893         558 :                     $$->skipData = false;        /* might get changed later */
    4894             :                 }
    4895             :         ;
    4896             : 
    4897           0 : OptNoLog:   UNLOGGED                    { $$ = RELPERSISTENCE_UNLOGGED; }
    4898         558 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    4899             :         ;
    4900             : 
    4901             : 
    4902             : /*****************************************************************************
    4903             :  *
    4904             :  *      QUERY :
    4905             :  *              REFRESH MATERIALIZED VIEW qualified_name
    4906             :  *
    4907             :  *****************************************************************************/
    4908             : 
    4909             : RefreshMatViewStmt:
    4910             :             REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
    4911             :                 {
    4912         258 :                     RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
    4913             : 
    4914         258 :                     n->concurrent = $4;
    4915         258 :                     n->relation = $5;
    4916         258 :                     n->skipData = !($6);
    4917         258 :                     $$ = (Node *) n;
    4918             :                 }
    4919             :         ;
    4920             : 
    4921             : 
    4922             : /*****************************************************************************
    4923             :  *
    4924             :  *      QUERY :
    4925             :  *              CREATE SEQUENCE seqname
    4926             :  *              ALTER SEQUENCE seqname
    4927             :  *
    4928             :  *****************************************************************************/
    4929             : 
    4930             : CreateSeqStmt:
    4931             :             CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
    4932             :                 {
    4933         612 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    4934             : 
    4935         612 :                     $4->relpersistence = $2;
    4936         612 :                     n->sequence = $4;
    4937         612 :                     n->options = $5;
    4938         612 :                     n->ownerId = InvalidOid;
    4939         612 :                     n->if_not_exists = false;
    4940         612 :                     $$ = (Node *) n;
    4941             :                 }
    4942             :             | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
    4943             :                 {
    4944          24 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    4945             : 
    4946          24 :                     $7->relpersistence = $2;
    4947          24 :                     n->sequence = $7;
    4948          24 :                     n->options = $8;
    4949          24 :                     n->ownerId = InvalidOid;
    4950          24 :                     n->if_not_exists = true;
    4951          24 :                     $$ = (Node *) n;
    4952             :                 }
    4953             :         ;
    4954             : 
    4955             : AlterSeqStmt:
    4956             :             ALTER SEQUENCE qualified_name SeqOptList
    4957             :                 {
    4958         174 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    4959             : 
    4960         174 :                     n->sequence = $3;
    4961         174 :                     n->options = $4;
    4962         174 :                     n->missing_ok = false;
    4963         174 :                     $$ = (Node *) n;
    4964             :                 }
    4965             :             | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
    4966             :                 {
    4967          12 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    4968             : 
    4969          12 :                     n->sequence = $5;
    4970          12 :                     n->options = $6;
    4971          12 :                     n->missing_ok = true;
    4972          12 :                     $$ = (Node *) n;
    4973             :                 }
    4974             : 
    4975             :         ;
    4976             : 
    4977         236 : OptSeqOptList: SeqOptList                           { $$ = $1; }
    4978         400 :             | /*EMPTY*/                             { $$ = NIL; }
    4979             :         ;
    4980             : 
    4981          72 : OptParenthesizedSeqOptList: '(' SeqOptList ')'      { $$ = $2; }
    4982         382 :             | /*EMPTY*/                             { $$ = NIL; }
    4983             :         ;
    4984             : 
    4985         494 : SeqOptList: SeqOptElem                              { $$ = list_make1($1); }
    4986         714 :             | SeqOptList SeqOptElem                 { $$ = lappend($1, $2); }
    4987             :         ;
    4988             : 
    4989             : SeqOptElem: AS SimpleTypename
    4990             :                 {
    4991         180 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    4992             :                 }
    4993             :             | CACHE NumericOnly
    4994             :                 {
    4995         110 :                     $$ = makeDefElem("cache", (Node *) $2, @1);
    4996             :                 }
    4997             :             | CYCLE
    4998             :                 {
    4999          34 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(true), @1);
    5000             :                 }
    5001             :             | NO CYCLE
    5002             :                 {
    5003          14 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(false), @1);
    5004             :                 }
    5005             :             | INCREMENT opt_by NumericOnly
    5006             :                 {
    5007         230 :                     $$ = makeDefElem("increment", (Node *) $3, @1);
    5008             :                 }
    5009             :             | MAXVALUE NumericOnly
    5010             :                 {
    5011          68 :                     $$ = makeDefElem("maxvalue", (Node *) $2, @1);
    5012             :                 }
    5013             :             | MINVALUE NumericOnly
    5014             :                 {
    5015          72 :                     $$ = makeDefElem("minvalue", (Node *) $2, @1);
    5016             :                 }
    5017             :             | NO MAXVALUE
    5018             :                 {
    5019          88 :                     $$ = makeDefElem("maxvalue", NULL, @1);
    5020             :                 }
    5021             :             | NO MINVALUE
    5022             :                 {
    5023          88 :                     $$ = makeDefElem("minvalue", NULL, @1);
    5024             :                 }
    5025             :             | OWNED BY any_name
    5026             :                 {
    5027          62 :                     $$ = makeDefElem("owned_by", (Node *) $3, @1);
    5028             :                 }
    5029             :             | SEQUENCE NAME_P any_name
    5030             :                 {
    5031             :                     /* not documented, only used by pg_dump */
    5032          42 :                     $$ = makeDefElem("sequence_name", (Node *) $3, @1);
    5033             :                 }
    5034             :             | START opt_with NumericOnly
    5035             :                 {
    5036         208 :                     $$ = makeDefElem("start", (Node *) $3, @1);
    5037             :                 }
    5038             :             | RESTART
    5039             :                 {
    5040           6 :                     $$ = makeDefElem("restart", NULL, @1);
    5041             :                 }
    5042             :             | RESTART opt_with NumericOnly
    5043             :                 {
    5044          60 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    5045             :                 }
    5046             :         ;
    5047             : 
    5048             : opt_by:     BY
    5049             :             | /* EMPTY */
    5050             :       ;
    5051             : 
    5052             : NumericOnly:
    5053         316 :             FCONST                              { $$ = (Node *) makeFloat($1); }
    5054           0 :             | '+' FCONST                        { $$ = (Node *) makeFloat($2); }
    5055             :             | '-' FCONST
    5056             :                 {
    5057          20 :                     Float      *f = makeFloat($2);
    5058             : 
    5059          20 :                     doNegateFloat(f);
    5060          20 :                     $$ = (Node *) f;
    5061             :                 }
    5062       10538 :             | SignedIconst                      { $$ = (Node *) makeInteger($1); }
    5063             :         ;
    5064             : 
    5065          80 : NumericOnly_list:   NumericOnly                     { $$ = list_make1($1); }
    5066           6 :                 | NumericOnly_list ',' NumericOnly  { $$ = lappend($1, $3); }
    5067             :         ;
    5068             : 
    5069             : /*****************************************************************************
    5070             :  *
    5071             :  *      QUERIES :
    5072             :  *              CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
    5073             :  *              DROP [PROCEDURAL] LANGUAGE ...
    5074             :  *
    5075             :  *****************************************************************************/
    5076             : 
    5077             : CreatePLangStmt:
    5078             :             CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
    5079             :             {
    5080             :                 /*
    5081             :                  * We now interpret parameterless CREATE LANGUAGE as
    5082             :                  * CREATE EXTENSION.  "OR REPLACE" is silently translated
    5083             :                  * to "IF NOT EXISTS", which isn't quite the same, but
    5084             :                  * seems more useful than throwing an error.  We just
    5085             :                  * ignore TRUSTED, as the previous code would have too.
    5086             :                  */
    5087           0 :                 CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5088             : 
    5089           0 :                 n->if_not_exists = $2;
    5090           0 :                 n->extname = $6;
    5091           0 :                 n->options = NIL;
    5092           0 :                 $$ = (Node *) n;
    5093             :             }
    5094             :             | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
    5095             :               HANDLER handler_name opt_inline_handler opt_validator
    5096             :             {
    5097         122 :                 CreatePLangStmt *n = makeNode(CreatePLangStmt);
    5098             : 
    5099         122 :                 n->replace = $2;
    5100         122 :                 n->plname = $6;
    5101         122 :                 n->plhandler = $8;
    5102         122 :                 n->plinline = $9;
    5103         122 :                 n->plvalidator = $10;
    5104         122 :                 n->pltrusted = $3;
    5105         122 :                 $$ = (Node *) n;
    5106             :             }
    5107             :         ;
    5108             : 
    5109             : opt_trusted:
    5110          92 :             TRUSTED                                 { $$ = true; }
    5111          36 :             | /*EMPTY*/                             { $$ = false; }
    5112             :         ;
    5113             : 
    5114             : /* This ought to be just func_name, but that causes reduce/reduce conflicts
    5115             :  * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
    5116             :  * Work around by using simple names, instead.
    5117             :  */
    5118             : handler_name:
    5119         498 :             name                        { $$ = list_make1(makeString($1)); }
    5120           2 :             | name attrs                { $$ = lcons(makeString($1), $2); }
    5121             :         ;
    5122             : 
    5123             : opt_inline_handler:
    5124         104 :             INLINE_P handler_name                   { $$ = $2; }
    5125          18 :             | /*EMPTY*/                             { $$ = NIL; }
    5126             :         ;
    5127             : 
    5128             : validator_clause:
    5129         104 :             VALIDATOR handler_name                  { $$ = $2; }
    5130           0 :             | NO VALIDATOR                          { $$ = NIL; }
    5131             :         ;
    5132             : 
    5133             : opt_validator:
    5134         104 :             validator_clause                        { $$ = $1; }
    5135          18 :             | /*EMPTY*/                             { $$ = NIL; }
    5136             :         ;
    5137             : 
    5138             : opt_procedural:
    5139             :             PROCEDURAL
    5140             :             | /*EMPTY*/
    5141             :         ;
    5142             : 
    5143             : /*****************************************************************************
    5144             :  *
    5145             :  *      QUERY:
    5146             :  *             CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
    5147             :  *
    5148             :  *****************************************************************************/
    5149             : 
    5150             : CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
    5151             :                 {
    5152         110 :                     CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
    5153             : 
    5154         110 :                     n->tablespacename = $3;
    5155         110 :                     n->owner = $4;
    5156         110 :                     n->location = $6;
    5157         110 :                     n->options = $7;
    5158         110 :                     $$ = (Node *) n;
    5159             :                 }
    5160             :         ;
    5161             : 
    5162           2 : OptTableSpaceOwner: OWNER RoleSpec      { $$ = $2; }
    5163         108 :             | /*EMPTY */                { $$ = NULL; }
    5164             :         ;
    5165             : 
    5166             : /*****************************************************************************
    5167             :  *
    5168             :  *      QUERY :
    5169             :  *              DROP TABLESPACE <tablespace>
    5170             :  *
    5171             :  *      No need for drop behaviour as we cannot implement dependencies for
    5172             :  *      objects in other databases; we can only support RESTRICT.
    5173             :  *
    5174             :  ****************************************************************************/
    5175             : 
    5176             : DropTableSpaceStmt: DROP TABLESPACE name
    5177             :                 {
    5178          64 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    5179             : 
    5180          64 :                     n->tablespacename = $3;
    5181          64 :                     n->missing_ok = false;
    5182          64 :                     $$ = (Node *) n;
    5183             :                 }
    5184             :                 |  DROP TABLESPACE IF_P EXISTS name
    5185             :                 {
    5186           0 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    5187             : 
    5188           0 :                     n->tablespacename = $5;
    5189           0 :                     n->missing_ok = true;
    5190           0 :                     $$ = (Node *) n;
    5191             :                 }
    5192             :         ;
    5193             : 
    5194             : /*****************************************************************************
    5195             :  *
    5196             :  *      QUERY:
    5197             :  *             CREATE EXTENSION extension
    5198             :  *             [ WITH ] [ SCHEMA schema ] [ VERSION version ]
    5199             :  *
    5200             :  *****************************************************************************/
    5201             : 
    5202             : CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
    5203             :                 {
    5204         394 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5205             : 
    5206         394 :                     n->extname = $3;
    5207         394 :                     n->if_not_exists = false;
    5208         394 :                     n->options = $5;
    5209         394 :                     $$ = (Node *) n;
    5210             :                 }
    5211             :                 | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
    5212             :                 {
    5213          14 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5214             : 
    5215          14 :                     n->extname = $6;
    5216          14 :                     n->if_not_exists = true;
    5217          14 :                     n->options = $8;
    5218          14 :                     $$ = (Node *) n;
    5219             :                 }
    5220             :         ;
    5221             : 
    5222             : create_extension_opt_list:
    5223             :             create_extension_opt_list create_extension_opt_item
    5224          96 :                 { $$ = lappend($1, $2); }
    5225             :             | /* EMPTY */
    5226         408 :                 { $$ = NIL; }
    5227             :         ;
    5228             : 
    5229             : create_extension_opt_item:
    5230             :             SCHEMA name
    5231             :                 {
    5232          44 :                     $$ = makeDefElem("schema", (Node *) makeString($2), @1);
    5233             :                 }
    5234             :             | VERSION_P NonReservedWord_or_Sconst
    5235             :                 {
    5236          12 :                     $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
    5237             :                 }
    5238             :             | FROM NonReservedWord_or_Sconst
    5239             :                 {
    5240           0 :                     ereport(ERROR,
    5241             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    5242             :                              errmsg("CREATE EXTENSION ... FROM is no longer supported"),
    5243             :                              parser_errposition(@1)));
    5244             :                 }
    5245             :             | CASCADE
    5246             :                 {
    5247          40 :                     $$ = makeDefElem("cascade", (Node *) makeBoolean(true), @1);
    5248             :                 }
    5249             :         ;
    5250             : 
    5251             : /*****************************************************************************
    5252             :  *
    5253             :  * ALTER EXTENSION name UPDATE [ TO version ]
    5254             :  *
    5255             :  *****************************************************************************/
    5256             : 
    5257             : AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
    5258             :                 {
    5259          28 :                     AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
    5260             : 
    5261          28 :                     n->extname = $3;
    5262          28 :                     n->options = $5;
    5263          28 :                     $$ = (Node *) n;
    5264             :                 }
    5265             :         ;
    5266             : 
    5267             : alter_extension_opt_list:
    5268             :             alter_extension_opt_list alter_extension_opt_item
    5269          28 :                 { $$ = lappend($1, $2); }
    5270             :             | /* EMPTY */
    5271          28 :                 { $$ = NIL; }
    5272             :         ;
    5273             : 
    5274             : alter_extension_opt_item:
    5275             :             TO NonReservedWord_or_Sconst
    5276             :                 {
    5277          28 :                     $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
    5278             :                 }
    5279             :         ;
    5280             : 
    5281             : /*****************************************************************************
    5282             :  *
    5283             :  * ALTER EXTENSION name ADD/DROP object-identifier
    5284             :  *
    5285             :  *****************************************************************************/
    5286             : 
    5287             : AlterExtensionContentsStmt:
    5288             :             ALTER EXTENSION name add_drop object_type_name name
    5289             :                 {
    5290          18 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5291             : 
    5292          18 :                     n->extname = $3;
    5293          18 :                     n->action = $4;
    5294          18 :                     n->objtype = $5;
    5295          18 :                     n->object = (Node *) makeString($6);
    5296          18 :                     $$ = (Node *) n;
    5297             :                 }
    5298             :             | ALTER EXTENSION name add_drop object_type_any_name any_name
    5299             :                 {
    5300          58 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5301             : 
    5302          58 :                     n->extname = $3;
    5303          58 :                     n->action = $4;
    5304          58 :                     n->objtype = $5;
    5305          58 :                     n->object = (Node *) $6;
    5306          58 :                     $$ = (Node *) n;
    5307             :                 }
    5308             :             | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
    5309             :                 {
    5310           8 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5311             : 
    5312           8 :                     n->extname = $3;
    5313           8 :                     n->action = $4;
    5314           8 :                     n->objtype = OBJECT_AGGREGATE;
    5315           8 :                     n->object = (Node *) $6;
    5316           8 :                     $$ = (Node *) n;
    5317             :                 }
    5318             :             | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
    5319             :                 {
    5320           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5321             : 
    5322           4 :                     n->extname = $3;
    5323           4 :                     n->action = $4;
    5324           4 :                     n->objtype = OBJECT_CAST;
    5325           4 :                     n->object = (Node *) list_make2($7, $9);
    5326           4 :                     $$ = (Node *) n;
    5327             :                 }
    5328             :             | ALTER EXTENSION name add_drop DOMAIN_P Typename
    5329             :                 {
    5330           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5331             : 
    5332           0 :                     n->extname = $3;
    5333           0 :                     n->action = $4;
    5334           0 :                     n->objtype = OBJECT_DOMAIN;
    5335           0 :                     n->object = (Node *) $6;
    5336           0 :                     $$ = (Node *) n;
    5337             :                 }
    5338             :             | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
    5339             :                 {
    5340          74 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5341             : 
    5342          74 :                     n->extname = $3;
    5343          74 :                     n->action = $4;
    5344          74 :                     n->objtype = OBJECT_FUNCTION;
    5345          74 :                     n->object = (Node *) $6;
    5346          74 :                     $$ = (Node *) n;
    5347             :                 }
    5348             :             | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
    5349             :                 {
    5350          18 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5351             : 
    5352          18 :                     n->extname = $3;
    5353          18 :                     n->action = $4;
    5354          18 :                     n->objtype = OBJECT_OPERATOR;
    5355          18 :                     n->object = (Node *) $6;
    5356          18 :                     $$ = (Node *) n;
    5357             :                 }
    5358             :             | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING name
    5359             :                 {
    5360           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5361             : 
    5362           4 :                     n->extname = $3;
    5363           4 :                     n->action = $4;
    5364           4 :                     n->objtype = OBJECT_OPCLASS;
    5365           4 :                     n->object = (Node *) lcons(makeString($9), $7);
    5366           4 :                     $$ = (Node *) n;
    5367             :                 }
    5368             :             | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING name
    5369             :                 {
    5370           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5371             : 
    5372           4 :                     n->extname = $3;
    5373           4 :                     n->action = $4;
    5374           4 :                     n->objtype = OBJECT_OPFAMILY;
    5375           4 :                     n->object = (Node *) lcons(makeString($9), $7);
    5376           4 :                     $$ = (Node *) n;
    5377             :                 }
    5378             :             | ALTER EXTENSION name add_drop PROCEDURE function_with_argtypes
    5379             :                 {
    5380           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5381             : 
    5382           0 :                     n->extname = $3;
    5383           0 :                     n->action = $4;
    5384           0 :                     n->objtype = OBJECT_PROCEDURE;
    5385           0 :                     n->object = (Node *) $6;
    5386           0 :                     $$ = (Node *) n;
    5387             :                 }
    5388             :             | ALTER EXTENSION name add_drop ROUTINE function_with_argtypes
    5389             :                 {
    5390           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5391             : 
    5392           0 :                     n->extname = $3;
    5393           0 :                     n->action = $4;
    5394           0 :                     n->objtype = OBJECT_ROUTINE;
    5395           0 :                     n->object = (Node *) $6;
    5396           0 :                     $$ = (Node *) n;
    5397             :                 }
    5398             :             | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
    5399             :                 {
    5400           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5401             : 
    5402           4 :                     n->extname = $3;
    5403           4 :                     n->action = $4;
    5404           4 :                     n->objtype = OBJECT_TRANSFORM;
    5405           4 :                     n->object = (Node *) list_make2($7, makeString($9));
    5406           4 :                     $$ = (Node *) n;
    5407             :                 }
    5408             :             | ALTER EXTENSION name add_drop TYPE_P Typename
    5409             :                 {
    5410           8 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5411             : 
    5412           8 :                     n->extname = $3;
    5413           8 :                     n->action = $4;
    5414           8 :                     n->objtype = OBJECT_TYPE;
    5415           8 :                     n->object = (Node *) $6;
    5416           8 :                     $$ = (Node *) n;
    5417             :                 }
    5418             :         ;
    5419             : 
    5420             : /*****************************************************************************
    5421             :  *
    5422             :  *      QUERY:
    5423             :  *             CREATE FOREIGN DATA WRAPPER name options
    5424             :  *
    5425             :  *****************************************************************************/
    5426             : 
    5427             : CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
    5428             :                 {
    5429         190 :                     CreateFdwStmt *n = makeNode(CreateFdwStmt);
    5430             : 
    5431         190 :                     n->fdwname = $5;
    5432         190 :                     n->func_options = $6;
    5433         190 :                     n->options = $7;
    5434         190 :                     $$ = (Node *) n;
    5435             :                 }
    5436             :         ;
    5437             : 
    5438             : fdw_option:
    5439          54 :             HANDLER handler_name                { $$ = makeDefElem("handler", (Node *) $2, @1); }
    5440           0 :             | NO HANDLER                        { $$ = makeDefElem("handler", NULL, @1); }
    5441          44 :             | VALIDATOR handler_name            { $$ = makeDefElem("validator", (Node *) $2, @1); }
    5442           6 :             | NO VALIDATOR                      { $$ = makeDefElem("validator", NULL, @1); }
    5443             :         ;
    5444             : 
    5445             : fdw_options:
    5446          86 :             fdw_option                          { $$ = list_make1($1); }
    5447          18 :             | fdw_options fdw_option            { $$ = lappend($1, $2); }
    5448             :         ;
    5449             : 
    5450             : opt_fdw_options:
    5451          50 :             fdw_options                         { $$ = $1; }
    5452         232 :             | /*EMPTY*/                         { $$ = NIL; }
    5453             :         ;
    5454             : 
    5455             : /*****************************************************************************
    5456             :  *
    5457             :  *      QUERY :
    5458             :  *              ALTER FOREIGN DATA WRAPPER name options
    5459             :  *
    5460             :  ****************************************************************************/
    5461             : 
    5462             : AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
    5463             :                 {
    5464          86 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5465             : 
    5466          86 :                     n->fdwname = $5;
    5467          86 :                     n->func_options = $6;
    5468          86 :                     n->options = $7;
    5469          86 :                     $$ = (Node *) n;
    5470             :                 }
    5471             :             | ALTER FOREIGN DATA_P WRAPPER name fdw_options
    5472             :                 {
    5473          36 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5474             : 
    5475          36 :                     n->fdwname = $5;
    5476          36 :                     n->func_options = $6;
    5477          36 :                     n->options = NIL;
    5478          36 :                     $$ = (Node *) n;
    5479             :                 }
    5480             :         ;
    5481             : 
    5482             : /* Options definition for CREATE FDW, SERVER and USER MAPPING */
    5483             : create_generic_options:
    5484         684 :             OPTIONS '(' generic_option_list ')'         { $$ = $3; }
    5485       63428 :             | /*EMPTY*/                                 { $$ = NIL; }
    5486             :         ;
    5487             : 
    5488             : generic_option_list:
    5489             :             generic_option_elem
    5490             :                 {
    5491         684 :                     $$ = list_make1($1);
    5492             :                 }
    5493             :             | generic_option_list ',' generic_option_elem
    5494             :                 {
    5495         430 :                     $$ = lappend($1, $3);
    5496             :                 }
    5497             :         ;
    5498             : 
    5499             : /* Options definition for ALTER FDW, SERVER and USER MAPPING */
    5500             : alter_generic_options:
    5501         478 :             OPTIONS '(' alter_generic_option_list ')'       { $$ = $3; }
    5502             :         ;
    5503             : 
    5504             : alter_generic_option_list:
    5505             :             alter_generic_option_elem
    5506             :                 {
    5507         478 :                     $$ = list_make1($1);
    5508             :                 }
    5509             :             | alter_generic_option_list ',' alter_generic_option_elem
    5510             :                 {
    5511         168 :                     $$ = lappend($1, $3);
    5512             :                 }
    5513             :         ;
    5514             : 
    5515             : alter_generic_option_elem:
    5516             :             generic_option_elem
    5517             :                 {
    5518         200 :                     $$ = $1;
    5519             :                 }
    5520             :             | SET generic_option_elem
    5521             :                 {
    5522         124 :                     $$ = $2;
    5523         124 :                     $$->defaction = DEFELEM_SET;
    5524             :                 }
    5525             :             | ADD_P generic_option_elem
    5526             :                 {
    5527         196 :                     $$ = $2;
    5528         196 :                     $$->defaction = DEFELEM_ADD;
    5529             :                 }
    5530             :             | DROP generic_option_name
    5531             :                 {
    5532         126 :                     $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP, @2);
    5533             :                 }
    5534             :         ;
    5535             : 
    5536             : generic_option_elem:
    5537             :             generic_option_name generic_option_arg
    5538             :                 {
    5539        1634 :                     $$ = makeDefElem($1, $2, @1);
    5540             :                 }
    5541             :         ;
    5542             : 
    5543             : generic_option_name:
    5544        1760 :                 ColLabel            { $$ = $1; }
    5545             :         ;
    5546             : 
    5547             : /* We could use def_arg here, but the spec only requires string literals */
    5548             : generic_option_arg:
    5549        1634 :                 Sconst              { $$ = (Node *) makeString($1); }
    5550             :         ;
    5551             : 
    5552             : /*****************************************************************************
    5553             :  *
    5554             :  *      QUERY:
    5555             :  *             CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
    5556             :  *
    5557             :  *****************************************************************************/
    5558             : 
    5559             : CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
    5560             :                          FOREIGN DATA_P WRAPPER name create_generic_options
    5561             :                 {
    5562         248 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5563             : 
    5564         248 :                     n->servername = $3;
    5565         248 :                     n->servertype = $4;
    5566         248 :                     n->version = $5;
    5567         248 :                     n->fdwname = $9;
    5568         248 :                     n->options = $10;
    5569         248 :                     n->if_not_exists = false;
    5570         248 :                     $$ = (Node *) n;
    5571             :                 }
    5572             :                 | CREATE SERVER IF_P NOT EXISTS name opt_type opt_foreign_server_version
    5573             :                          FOREIGN DATA_P WRAPPER name create_generic_options
    5574             :                 {
    5575          24 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5576             : 
    5577          24 :                     n->servername = $6;
    5578          24 :                     n->servertype = $7;
    5579          24 :                     n->version = $8;
    5580          24 :                     n->fdwname = $12;
    5581          24 :                     n->options = $13;
    5582          24 :                     n->if_not_exists = true;
    5583          24 :                     $$ = (Node *) n;
    5584             :                 }
    5585             :         ;
    5586             : 
    5587             : opt_type:
    5588          18 :             TYPE_P Sconst           { $$ = $2; }
    5589         254 :             | /*EMPTY*/             { $$ = NULL; }
    5590             :         ;
    5591             : 
    5592             : 
    5593             : foreign_server_version:
    5594          66 :             VERSION_P Sconst        { $$ = $2; }
    5595           0 :         |   VERSION_P NULL_P        { $$ = NULL; }
    5596             :         ;
    5597             : 
    5598             : opt_foreign_server_version:
    5599          18 :             foreign_server_version  { $$ = $1; }
    5600         254 :             | /*EMPTY*/             { $$ = NULL; }
    5601             :         ;
    5602             : 
    5603             : /*****************************************************************************
    5604             :  *
    5605             :  *      QUERY :
    5606             :  *              ALTER SERVER name [VERSION] [OPTIONS]
    5607             :  *
    5608             :  ****************************************************************************/
    5609             : 
    5610             : AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
    5611             :                 {
    5612           6 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5613             : 
    5614           6 :                     n->servername = $3;
    5615           6 :                     n->version = $4;
    5616           6 :                     n->options = $5;
    5617           6 :                     n->has_version = true;
    5618           6 :                     $$ = (Node *) n;
    5619             :                 }
    5620             :             | ALTER SERVER name foreign_server_version
    5621             :                 {
    5622          42 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5623             : 
    5624          42 :                     n->servername = $3;
    5625          42 :                     n->version = $4;
    5626          42 :                     n->has_version = true;
    5627          42 :                     $$ = (Node *) n;
    5628             :                 }
    5629             :             | ALTER SERVER name alter_generic_options
    5630             :                 {
    5631         170 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5632             : 
    5633         170 :                     n->servername = $3;
    5634         170 :                     n->options = $4;
    5635         170 :                     $$ = (Node *) n;
    5636             :                 }
    5637             :         ;
    5638             : 
    5639             : /*****************************************************************************
    5640             :  *
    5641             :  *      QUERY:
    5642             :  *             CREATE FOREIGN TABLE relname (...) SERVER name (...)
    5643             :  *
    5644             :  *****************************************************************************/
    5645             : 
    5646             : CreateForeignTableStmt:
    5647             :         CREATE FOREIGN TABLE qualified_name
    5648             :             '(' OptTableElementList ')'
    5649             :             OptInherit SERVER name create_generic_options
    5650             :                 {
    5651         356 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5652             : 
    5653         356 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5654         356 :                     n->base.relation = $4;
    5655         356 :                     n->base.tableElts = $6;
    5656         356 :                     n->base.inhRelations = $8;
    5657         356 :                     n->base.ofTypename = NULL;
    5658         356 :                     n->base.constraints = NIL;
    5659         356 :                     n->base.options = NIL;
    5660         356 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5661         356 :                     n->base.tablespacename = NULL;
    5662         356 :                     n->base.if_not_exists = false;
    5663             :                     /* FDW-specific data */
    5664         356 :                     n->servername = $10;
    5665         356 :                     n->options = $11;
    5666         356 :                     $$ = (Node *) n;
    5667             :                 }
    5668             :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5669             :             '(' OptTableElementList ')'
    5670             :             OptInherit SERVER name create_generic_options
    5671             :                 {
    5672           0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5673             : 
    5674           0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5675           0 :                     n->base.relation = $7;
    5676           0 :                     n->base.tableElts = $9;
    5677           0 :                     n->base.inhRelations = $11;
    5678           0 :                     n->base.ofTypename = NULL;
    5679           0 :                     n->base.constraints = NIL;
    5680           0 :                     n->base.options = NIL;
    5681           0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5682           0 :                     n->base.tablespacename = NULL;
    5683           0 :                     n->base.if_not_exists = true;
    5684             :                     /* FDW-specific data */
    5685           0 :                     n->servername = $13;
    5686           0 :                     n->options = $14;
    5687           0 :                     $$ = (Node *) n;
    5688             :                 }
    5689             :         | CREATE FOREIGN TABLE qualified_name
    5690             :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5691             :             SERVER name create_generic_options
    5692             :                 {
    5693          90 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5694             : 
    5695          90 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5696          90 :                     n->base.relation = $4;
    5697          90 :                     n->base.inhRelations = list_make1($7);
    5698          90 :                     n->base.tableElts = $8;
    5699          90 :                     n->base.partbound = $9;
    5700          90 :                     n->base.ofTypename = NULL;
    5701          90 :                     n->base.constraints = NIL;
    5702          90 :                     n->base.options = NIL;
    5703          90 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5704          90 :                     n->base.tablespacename = NULL;
    5705          90 :                     n->base.if_not_exists = false;
    5706             :                     /* FDW-specific data */
    5707          90 :                     n->servername = $11;
    5708          90 :                     n->options = $12;
    5709          90 :                     $$ = (Node *) n;
    5710             :                 }
    5711             :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5712             :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5713             :             SERVER name create_generic_options
    5714             :                 {
    5715           0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5716             : 
    5717           0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5718           0 :                     n->base.relation = $7;
    5719           0 :                     n->base.inhRelations = list_make1($10);
    5720           0 :                     n->base.tableElts = $11;
    5721           0 :                     n->base.partbound = $12;
    5722           0 :                     n->base.ofTypename = NULL;
    5723           0 :                     n->base.constraints = NIL;
    5724           0 :                     n->base.options = NIL;
    5725           0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5726           0 :                     n->base.tablespacename = NULL;
    5727           0 :                     n->base.if_not_exists = true;
    5728             :                     /* FDW-specific data */
    5729           0 :                     n->servername = $14;
    5730           0 :                     n->options = $15;
    5731           0 :                     $$ = (Node *) n;
    5732             :                 }
    5733             :         ;
    5734             : 
    5735             : /*****************************************************************************
    5736             :  *
    5737             :  *      QUERY:
    5738             :  *              IMPORT FOREIGN SCHEMA remote_schema
    5739             :  *              [ { LIMIT TO | EXCEPT } ( table_list ) ]
    5740             :  *              FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
    5741             :  *
    5742             :  ****************************************************************************/
    5743             : 
    5744             : ImportForeignSchemaStmt:
    5745             :         IMPORT_P FOREIGN SCHEMA name import_qualification
    5746             :           FROM SERVER name INTO name create_generic_options
    5747             :             {
    5748          44 :                 ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
    5749             : 
    5750          44 :                 n->server_name = $8;
    5751          44 :                 n->remote_schema = $4;
    5752          44 :                 n->local_schema = $10;
    5753          44 :                 n->list_type = $5->type;
    5754          44 :                 n->table_list = $5->table_names;
    5755          44 :                 n->options = $11;
    5756          44 :                 $$ = (Node *) n;
    5757             :             }
    5758             :         ;
    5759             : 
    5760             : import_qualification_type:
    5761          10 :         LIMIT TO                { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
    5762          14 :         | EXCEPT                { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
    5763             :         ;
    5764             : 
    5765             : import_qualification:
    5766             :         import_qualification_type '(' relation_expr_list ')'
    5767             :             {
    5768          24 :                 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
    5769             : 
    5770          24 :                 n->type = $1;
    5771          24 :                 n->table_names = $3;
    5772          24 :                 $$ = n;
    5773             :             }
    5774             :         | /*EMPTY*/
    5775             :             {
    5776          20 :                 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
    5777          20 :                 n->type = FDW_IMPORT_SCHEMA_ALL;
    5778          20 :                 n->table_names = NIL;
    5779          20 :                 $$ = n;
    5780             :             }
    5781             :         ;
    5782             : 
    5783             : /*****************************************************************************
    5784             :  *
    5785             :  *      QUERY:
    5786             :  *             CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
    5787             :  *
    5788             :  *****************************************************************************/
    5789             : 
    5790             : CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
    5791             :                 {
    5792         232 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5793             : 
    5794         232 :                     n->user = $5;
    5795         232 :                     n->servername = $7;
    5796         232 :                     n->options = $8;
    5797         232 :                     n->if_not_exists = false;
    5798         232 :                     $$ = (Node *) n;
    5799             :                 }
    5800             :                 | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
    5801             :                 {
    5802           6 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5803             : 
    5804           6 :                     n->user = $8;
    5805           6 :                     n->servername = $10;
    5806           6 :                     n->options = $11;
    5807           6 :                     n->if_not_exists = true;
    5808           6 :                     $$ = (Node *) n;
    5809             :                 }
    5810             :         ;
    5811             : 
    5812             : /* User mapping authorization identifier */
    5813         428 : auth_ident: RoleSpec            { $$ = $1; }
    5814          46 :             | USER              { $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1); }
    5815             :         ;
    5816             : 
    5817             : /*****************************************************************************
    5818             :  *
    5819             :  *      QUERY :
    5820             :  *              DROP USER MAPPING FOR auth_ident SERVER name
    5821             :  *
    5822             :  * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
    5823             :  * only pro forma; but the SQL standard doesn't show one.
    5824             :  ****************************************************************************/
    5825             : 
    5826             : DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
    5827             :                 {
    5828          88 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5829             : 
    5830          88 :                     n->user = $5;
    5831          88 :                     n->servername = $7;
    5832          88 :                     n->missing_ok = false;
    5833          88 :                     $$ = (Node *) n;
    5834             :                 }
    5835             :                 |  DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
    5836             :                 {
    5837          38 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5838             : 
    5839          38 :                     n->user = $7;
    5840          38 :                     n->servername = $9;
    5841          38 :                     n->missing_ok = true;
    5842          38 :                     $$ = (Node *) n;
    5843             :                 }
    5844             :         ;
    5845             : 
    5846             : /*****************************************************************************
    5847             :  *
    5848             :  *      QUERY :
    5849             :  *              ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
    5850             :  *
    5851             :  ****************************************************************************/
    5852             : 
    5853             : AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
    5854             :                 {
    5855         110 :                     AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
    5856             : 
    5857         110 :                     n->user = $5;
    5858         110 :                     n->servername = $7;
    5859         110 :                     n->options = $8;
    5860         110 :                     $$ = (Node *) n;
    5861             :                 }
    5862             :         ;
    5863             : 
    5864             : /*****************************************************************************
    5865             :  *
    5866             :  *      QUERIES:
    5867             :  *              CREATE POLICY name ON table
    5868             :  *                  [AS { PERMISSIVE | RESTRICTIVE } ]
    5869             :  *                  [FOR { SELECT | INSERT | UPDATE | DELETE } ]
    5870             :  *                  [TO role, ...]
    5871             :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    5872             :  *              ALTER POLICY name ON table [TO role, ...]
    5873             :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    5874             :  *
    5875             :  *****************************************************************************/
    5876             : 
    5877             : CreatePolicyStmt:
    5878             :             CREATE POLICY name ON qualified_name RowSecurityDefaultPermissive
    5879             :                 RowSecurityDefaultForCmd RowSecurityDefaultToRole
    5880             :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    5881             :                 {
    5882         658 :                     CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
    5883             : 
    5884         658 :                     n->policy_name = $3;
    5885         658 :                     n->table = $5;
    5886         658 :                     n->permissive = $6;
    5887         658 :                     n->cmd_name = $7;
    5888         658 :                     n->roles = $8;
    5889         658 :                     n->qual = $9;
    5890         658 :                     n->with_check = $10;
    5891         658 :                     $$ = (Node *) n;
    5892             :                 }
    5893             :         ;
    5894             : 
    5895             : AlterPolicyStmt:
    5896             :             ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
    5897             :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    5898             :                 {
    5899          84 :                     AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
    5900             : 
    5901          84 :                     n->policy_name = $3;
    5902          84 :                     n->table = $5;
    5903          84 :                     n->roles = $6;
    5904          84 :                     n->qual = $7;
    5905          84 :                     n->with_check = $8;
    5906          84 :                     $$ = (Node *) n;
    5907             :                 }
    5908             :         ;
    5909             : 
    5910             : RowSecurityOptionalExpr:
    5911         684 :             USING '(' a_expr ')'    { $$ = $3; }
    5912          58 :             | /* EMPTY */           { $$ = NULL; }
    5913             :         ;
    5914             : 
    5915             : RowSecurityOptionalWithCheck:
    5916         122 :             WITH CHECK '(' a_expr ')'       { $$ = $4; }
    5917         620 :             | /* EMPTY */                   { $$ = NULL; }
    5918             :         ;
    5919             : 
    5920             : RowSecurityDefaultToRole:
    5921         124 :             TO role_list            { $$ = $2; }
    5922         534 :             | /* EMPTY */           { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
    5923             :         ;
    5924             : 
    5925             : RowSecurityOptionalToRole:
    5926          12 :             TO role_list            { $$ = $2; }
    5927          72 :             | /* EMPTY */           { $$ = NULL; }
    5928             :         ;
    5929             : 
    5930             : RowSecurityDefaultPermissive:
    5931             :             AS IDENT
    5932             :                 {
    5933          86 :                     if (strcmp($2, "permissive") == 0)
    5934          24 :                         $$ = true;
    5935          62 :                     else if (strcmp($2, "restrictive") == 0)
    5936          56 :                         $$ = false;
    5937             :                     else
    5938           6 :                         ereport(ERROR,
    5939             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    5940             :                                  errmsg("unrecognized row security option \"%s\"", $2),
    5941             :                                  errhint("Only PERMISSIVE or RESTRICTIVE policies are supported currently."),
    5942             :                                  parser_errposition(@2)));
    5943             : 
    5944             :                 }
    5945         578 :             | /* EMPTY */           { $$ = true; }
    5946             :         ;
    5947             : 
    5948             : RowSecurityDefaultForCmd:
    5949         314 :             FOR row_security_cmd    { $$ = $2; }
    5950         344 :             | /* EMPTY */           { $$ = "all"; }
    5951             :         ;
    5952             : 
    5953             : row_security_cmd:
    5954          44 :             ALL             { $$ = "all"; }
    5955         106 :         |   SELECT          { $$ = "select"; }
    5956          44 :         |   INSERT          { $$ = "insert"; }
    5957          78 :         |   UPDATE          { $$ = "update"; }
    5958          42 :         |   DELETE_P        { $$ = "delete"; }
    5959             :         ;
    5960             : 
    5961             : /*****************************************************************************
    5962             :  *
    5963             :  *      QUERY:
    5964             :  *             CREATE ACCESS METHOD name HANDLER handler_name
    5965             :  *
    5966             :  *****************************************************************************/
    5967             : 
    5968             : CreateAmStmt: CREATE ACCESS METHOD name TYPE_P am_type HANDLER handler_name
    5969             :                 {
    5970          72 :                     CreateAmStmt *n = makeNode(CreateAmStmt);
    5971             : 
    5972          72 :                     n->amname = $4;
    5973          72 :                     n->handler_name = $8;
    5974          72 :                     n->amtype = $6;
    5975          72 :                     $$ = (Node *) n;
    5976             :                 }
    5977             :         ;
    5978             : 
    5979             : am_type:
    5980          32 :             INDEX           { $$ = AMTYPE_INDEX; }
    5981          40 :         |   TABLE           { $$ = AMTYPE_TABLE; }
    5982             :         ;
    5983             : 
    5984             : /*****************************************************************************
    5985             :  *
    5986             :  *      QUERIES :
    5987             :  *              CREATE TRIGGER ...
    5988             :  *
    5989             :  *****************************************************************************/
    5990             : 
    5991             : CreateTrigStmt:
    5992             :             CREATE opt_or_replace TRIGGER name TriggerActionTime TriggerEvents ON
    5993             :             qualified_name TriggerReferencing TriggerForSpec TriggerWhen
    5994             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    5995             :                 {
    5996        3076 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    5997             : 
    5998        3076 :                     n->replace = $2;
    5999        3076 :                     n->isconstraint = false;
    6000        3076 :                     n->trigname = $4;
    6001        3076 :                     n->relation = $8;
    6002        3076 :                     n->funcname = $14;
    6003        3076 :                     n->args = $16;
    6004        3076 :                     n->row = $10;
    6005        3076 :                     n->timing = $5;
    6006        3076 :                     n->events = intVal(linitial($6));
    6007        3076 :                     n->columns = (List *) lsecond($6);
    6008        3076 :                     n->whenClause = $11;
    6009        3076 :                     n->transitionRels = $9;
    6010        3076 :                     n->deferrable = false;
    6011        3076 :                     n->initdeferred = false;
    6012        3076 :                     n->constrrel = NULL;
    6013        3076 :                     $$ = (Node *) n;
    6014             :                 }
    6015             :           | CREATE opt_or_replace CONSTRAINT TRIGGER name AFTER TriggerEvents ON
    6016             :             qualified_name OptConstrFromTable ConstraintAttributeSpec
    6017             :             FOR EACH ROW TriggerWhen
    6018             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    6019             :                 {
    6020          54 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    6021             : 
    6022          54 :                     n->replace = $2;
    6023          54 :                     if (n->replace) /* not supported, see CreateTrigger */
    6024           0 :                         ereport(ERROR,
    6025             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6026             :                                  errmsg("CREATE OR REPLACE CONSTRAINT TRIGGER is not supported")));
    6027          54 :                     n->isconstraint = true;
    6028          54 :                     n->trigname = $5;
    6029          54 :                     n->relation = $9;
    6030          54 :                     n->funcname = $18;
    6031          54 :                     n->args = $20;
    6032          54 :                     n->row = true;
    6033          54 :                     n->timing = TRIGGER_TYPE_AFTER;
    6034          54 :                     n->events = intVal(linitial($7));
    6035          54 :                     n->columns = (List *) lsecond($7);
    6036          54 :                     n->whenClause = $15;
    6037          54 :                     n->transitionRels = NIL;
    6038          54 :                     processCASbits($11, @11, "TRIGGER",
    6039             :                                    &n->deferrable, &n->initdeferred, NULL,
    6040             :                                    NULL, yyscanner);
    6041          54 :                     n->constrrel = $10;
    6042          54 :                     $$ = (Node *) n;
    6043             :                 }
    6044             :         ;
    6045             : 
    6046             : TriggerActionTime:
    6047        1392 :             BEFORE                              { $$ = TRIGGER_TYPE_BEFORE; }
    6048        1558 :             | AFTER                             { $$ = TRIGGER_TYPE_AFTER; }
    6049         138 :             | INSTEAD OF                        { $$ = TRIGGER_TYPE_INSTEAD; }
    6050             :         ;
    6051             : 
    6052             : TriggerEvents:
    6053             :             TriggerOneEvent
    6054        3142 :                 { $$ = $1; }
    6055             :             | TriggerEvents OR TriggerOneEvent
    6056             :                 {
    6057        1078 :                     int         events1 = intVal(linitial($1));
    6058        1078 :                     int         events2 = intVal(linitial($3));
    6059        1078 :                     List       *columns1 = (List *) lsecond($1);
    6060        1078 :                     List       *columns2 = (List *) lsecond($3);
    6061             : 
    6062        1078 :                     if (events1 & events2)
    6063           6 :                         parser_yyerror("duplicate trigger events specified");
    6064             :                     /*
    6065             :                      * concat'ing the columns lists loses information about
    6066             :                      * which columns went with which event, but so long as
    6067             :                      * only UPDATE carries columns and we disallow multiple
    6068             :                      * UPDATE items, it doesn't matter.  Command execution
    6069             :                      * should just ignore the columns for non-UPDATE events.
    6070             :                      */
    6071        1072 :                     $$ = list_make2(makeInteger(events1 | events2),
    6072             :                                     list_concat(columns1, columns2));
    6073             :                 }
    6074             :         ;
    6075             : 
    6076             : TriggerOneEvent:
    6077             :             INSERT
    6078        1576 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
    6079             :             | DELETE_P
    6080         864 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
    6081             :             | UPDATE
    6082        1648 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
    6083             :             | UPDATE OF columnList
    6084          94 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
    6085             :             | TRUNCATE
    6086          38 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
    6087             :         ;
    6088             : 
    6089             : TriggerReferencing:
    6090         424 :             REFERENCING TriggerTransitions          { $$ = $2; }
    6091        2652 :             | /*EMPTY*/                             { $$ = NIL; }
    6092             :         ;
    6093             : 
    6094             : TriggerTransitions:
    6095         424 :             TriggerTransition                       { $$ = list_make1($1); }
    6096         138 :             | TriggerTransitions TriggerTransition  { $$ = lappend($1, $2); }
    6097             :         ;
    6098             : 
    6099             : TriggerTransition:
    6100             :             TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
    6101             :                 {
    6102         562 :                     TriggerTransition *n = makeNode(TriggerTransition);
    6103             : 
    6104         562 :                     n->name = $4;
    6105         562 :                     n->isNew = $1;
    6106         562 :                     n->isTable = $2;
    6107         562 :                     $$ = (Node *) n;
    6108             :                 }
    6109             :         ;
    6110             : 
    6111             : TransitionOldOrNew:
    6112         306 :             NEW                                     { $$ = true; }
    6113         256 :             | OLD                                   { $$ = false; }
    6114             :         ;
    6115             : 
    6116             : TransitionRowOrTable:
    6117         562 :             TABLE                                   { $$ = true; }
    6118             :             /*
    6119             :              * According to the standard, lack of a keyword here implies ROW.
    6120             :              * Support for that would require prohibiting ROW entirely here,
    6121             :              * reserving the keyword ROW, and/or requiring AS (instead of
    6122             :              * allowing it to be optional, as the standard specifies) as the
    6123             :              * next token.  Requiring ROW seems cleanest and easiest to
    6124             :              * explain.
    6125             :              */
    6126           0 :             | ROW                                   { $$ = false; }
    6127             :         ;
    6128             : 
    6129             : TransitionRelName:
    6130         562 :             ColId                                   { $$ = $1; }
    6131             :         ;
    6132             : 
    6133             : TriggerForSpec:
    6134             :             FOR TriggerForOptEach TriggerForType
    6135             :                 {
    6136        2848 :                     $$ = $3;
    6137             :                 }
    6138             :             | /* EMPTY */
    6139             :                 {
    6140             :                     /*
    6141             :                      * If ROW/STATEMENT not specified, default to
    6142             :                      * STATEMENT, per SQL
    6143             :                      */
    6144         228 :                     $$ = false;
    6145             :                 }
    6146             :         ;
    6147             : 
    6148             : TriggerForOptEach:
    6149             :             EACH
    6150             :             | /*EMPTY*/
    6151             :         ;
    6152             : 
    6153             : TriggerForType:
    6154        2056 :             ROW                                     { $$ = true; }
    6155         792 :             | STATEMENT                             { $$ = false; }
    6156             :         ;
    6157             : 
    6158             : TriggerWhen:
    6159         152 :             WHEN '(' a_expr ')'                     { $$ = $3; }
    6160        2978 :             | /*EMPTY*/                             { $$ = NULL; }
    6161             :         ;
    6162             : 
    6163             : FUNCTION_or_PROCEDURE:
    6164             :             FUNCTION
    6165             :         |   PROCEDURE
    6166             :         ;
    6167             : 
    6168             : TriggerFuncArgs:
    6169         598 :             TriggerFuncArg                          { $$ = list_make1($1); }
    6170         264 :             | TriggerFuncArgs ',' TriggerFuncArg    { $$ = lappend($1, $3); }
    6171        2532 :             | /*EMPTY*/                             { $$ = NIL; }
    6172             :         ;
    6173             : 
    6174             : TriggerFuncArg:
    6175             :             Iconst
    6176             :                 {
    6177         102 :                     $$ = (Node *) makeString(psprintf("%d", $1));
    6178             :                 }
    6179           0 :             | FCONST                                { $$ = (Node *) makeString($1); }
    6180         720 :             | Sconst                                { $$ = (Node *) makeString($1); }
    6181          40 :             | ColLabel                              { $$ = (Node *) makeString($1); }
    6182             :         ;
    6183             : 
    6184             : OptConstrFromTable:
    6185          12 :             FROM qualified_name                     { $$ = $2; }
    6186          42 :             | /*EMPTY*/                             { $$ = NULL; }
    6187             :         ;
    6188             : 
    6189             : ConstraintAttributeSpec:
    6190             :             /*EMPTY*/
    6191       14462 :                 { $$ = 0; }
    6192             :             | ConstraintAttributeSpec ConstraintAttributeElem
    6193             :                 {
    6194             :                     /*
    6195             :                      * We must complain about conflicting options.
    6196             :                      * We could, but choose not to, complain about redundant
    6197             :                      * options (ie, where $2's bit is already set in $1).
    6198             :                      */
    6199        1132 :                     int     newspec = $1 | $2;
    6200             : 
    6201             :                     /* special message for this case */
    6202        1132 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
    6203           6 :                         ereport(ERROR,
    6204             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6205             :                                  errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
    6206             :                                  parser_errposition(@2)));
    6207             :                     /* generic message for other conflicts */
    6208        1126 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
    6209        1126 :                         (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED))
    6210           0 :                         ereport(ERROR,
    6211             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6212             :                                  errmsg("conflicting constraint properties"),
    6213             :                                  parser_errposition(@2)));
    6214        1126 :                     $$ = newspec;
    6215             :                 }
    6216             :         ;
    6217             : 
    6218             : ConstraintAttributeElem:
    6219          36 :             NOT DEFERRABLE                  { $$ = CAS_NOT_DEFERRABLE; }
    6220         216 :             | DEFERRABLE                    { $$ = CAS_DEFERRABLE; }
    6221          30 :             | INITIALLY IMMEDIATE           { $$ = CAS_INITIALLY_IMMEDIATE; }
    6222         162 :             | INITIALLY DEFERRED            { $$ = CAS_INITIALLY_DEFERRED; }
    6223         516 :             | NOT VALID                     { $$ = CAS_NOT_VALID; }
    6224         172 :             | NO INHERIT                    { $$ = CAS_NO_INHERIT; }
    6225             :         ;
    6226             : 
    6227             : 
    6228             : /*****************************************************************************
    6229             :  *
    6230             :  *      QUERIES :
    6231             :  *              CREATE EVENT TRIGGER ...
    6232             :  *              ALTER EVENT TRIGGER ...
    6233             :  *
    6234             :  *****************************************************************************/
    6235             : 
    6236             : CreateEventTrigStmt:
    6237             :             CREATE EVENT TRIGGER name ON ColLabel
    6238             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    6239             :                 {
    6240          98 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6241             : 
    6242          98 :                     n->trigname = $4;
    6243          98 :                     n->eventname = $6;
    6244          98 :                     n->whenclause = NULL;
    6245          98 :                     n->funcname = $9;
    6246          98 :                     $$ = (Node *) n;
    6247             :                 }
    6248             :           | CREATE EVENT TRIGGER name ON ColLabel
    6249             :             WHEN event_trigger_when_list
    6250             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    6251             :                 {
    6252          98 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6253             : 
    6254          98 :                     n->trigname = $4;
    6255          98 :                     n->eventname = $6;
    6256          98 :                     n->whenclause = $8;
    6257          98 :                     n->funcname = $11;
    6258          98 :                     $$ = (Node *) n;
    6259             :                 }
    6260             :         ;
    6261             : 
    6262             : event_trigger_when_list:
    6263             :           event_trigger_when_item
    6264          98 :             { $$ = list_make1($1); }
    6265             :         | event_trigger_when_list AND event_trigger_when_item
    6266           6 :             { $$ = lappend($1, $3); }
    6267             :         ;
    6268             : 
    6269             : event_trigger_when_item:
    6270             :         ColId IN_P '(' event_trigger_value_list ')'
    6271         104 :             { $$ = makeDefElem($1, (Node *) $4, @1); }
    6272             :         ;
    6273             : 
    6274             : event_trigger_value_list:
    6275             :           SCONST
    6276         104 :             { $$ = list_make1(makeString($1)); }
    6277             :         | event_trigger_value_list ',' SCONST
    6278          66 :             { $$ = lappend($1, makeString($3)); }
    6279             :         ;
    6280             : 
    6281             : AlterEventTrigStmt:
    6282             :             ALTER EVENT TRIGGER name enable_trigger
    6283             :                 {
    6284          48 :                     AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
    6285             : 
    6286          48 :                     n->trigname = $4;
    6287          48 :                     n->tgenabled = $5;
    6288          48 :                     $$ = (Node *) n;
    6289             :                 }
    6290             :         ;
    6291             : 
    6292             : enable_trigger:
    6293           6 :             ENABLE_P                    { $$ = TRIGGER_FIRES_ON_ORIGIN; }
    6294           6 :             | ENABLE_P REPLICA          { $$ = TRIGGER_FIRES_ON_REPLICA; }
    6295          16 :             | ENABLE_P ALWAYS           { $$ = TRIGGER_FIRES_ALWAYS; }
    6296          20 :             | DISABLE_P                 { $$ = TRIGGER_DISABLED; }
    6297             :         ;
    6298             : 
    6299             : /*****************************************************************************
    6300             :  *
    6301             :  *      QUERY :
    6302             :  *              CREATE ASSERTION ...
    6303             :  *
    6304             :  *****************************************************************************/
    6305             : 
    6306             : CreateAssertionStmt:
    6307             :             CREATE ASSERTION any_name CHECK '(' a_expr ')' ConstraintAttributeSpec
    6308             :                 {
    6309           0 :                     ereport(ERROR,
    6310             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6311             :                              errmsg("CREATE ASSERTION is not yet implemented")));
    6312             : 
    6313             :                     $$ = NULL;
    6314             :                 }
    6315             :         ;
    6316             : 
    6317             : 
    6318             : /*****************************************************************************
    6319             :  *
    6320             :  *      QUERY :
    6321             :  *              define (aggregate,operator,type)
    6322             :  *
    6323             :  *****************************************************************************/
    6324             : 
    6325             : DefineStmt:
    6326             :             CREATE opt_or_replace AGGREGATE func_name aggr_args definition
    6327             :                 {
    6328         542 :                     DefineStmt *n = makeNode(DefineStmt);
    6329             : 
    6330         542 :                     n->kind = OBJECT_AGGREGATE;
    6331         542 :                     n->oldstyle = false;
    6332         542 :                     n->replace = $2;
    6333         542 :                     n->defnames = $4;
    6334         542 :                     n->args = $5;
    6335         542 :                     n->definition = $6;
    6336         542 :                     $$ = (Node *) n;
    6337             :                 }
    6338             :             | CREATE opt_or_replace AGGREGATE func_name old_aggr_definition
    6339             :                 {
    6340             :                     /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
    6341         362 :                     DefineStmt *n = makeNode(DefineStmt);
    6342             : 
    6343         362 :                     n->kind = OBJECT_AGGREGATE;
    6344         362 :                     n->oldstyle = true;
    6345         362 :                     n->replace = $2;
    6346         362 :                     n->defnames = $4;
    6347         362 :                     n->args = NIL;
    6348         362 :                     n->definition = $5;
    6349         362 :                     $$ = (Node *) n;
    6350             :                 }
    6351             :             | CREATE OPERATOR any_operator definition
    6352             :                 {
    6353        1586 :                     DefineStmt *n = makeNode(DefineStmt);
    6354             : 
    6355        1586 :                     n->kind = OBJECT_OPERATOR;
    6356        1586 :                     n->oldstyle = false;
    6357        1586 :                     n->defnames = $3;
    6358        1586 :                     n->args = NIL;
    6359        1586 :                     n->definition = $4;
    6360        1586 :                     $$ = (Node *) n;
    6361             :                 }
    6362             :             | CREATE TYPE_P any_name definition
    6363             :                 {
    6364         208 :                     DefineStmt *n = makeNode(DefineStmt);
    6365             : 
    6366         208 :                     n->kind = OBJECT_TYPE;
    6367         208 :                     n->oldstyle = false;
    6368         208 :                     n->defnames = $3;
    6369         208 :                     n->args = NIL;
    6370         208 :                     n->definition = $4;
    6371         208 :                     $$ = (Node *) n;
    6372             :                 }
    6373             :             | CREATE TYPE_P any_name
    6374             :                 {
    6375             :                     /* Shell type (identified by lack of definition) */
    6376         154 :                     DefineStmt *n = makeNode(DefineStmt);
    6377             : 
    6378         154 :                     n->kind = OBJECT_TYPE;
    6379         154 :                     n->oldstyle = false;
    6380         154 :                     n->defnames = $3;
    6381         154 :                     n->args = NIL;
    6382         154 :                     n->definition = NIL;
    6383         154 :                     $$ = (Node *) n;
    6384             :                 }
    6385             :             | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
    6386             :                 {
    6387         690 :                     CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
    6388             : 
    6389             :                     /* can't use qualified_name, sigh */
    6390         690 :                     n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
    6391         690 :                     n->coldeflist = $6;
    6392         690 :                     $$ = (Node *) n;
    6393             :                 }
    6394             :             | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
    6395             :                 {
    6396         188 :                     CreateEnumStmt *n = makeNode(CreateEnumStmt);
    6397             : 
    6398         188 :                     n->typeName = $3;
    6399         188 :                     n->vals = $7;
    6400         188 :                     $$ = (Node *) n;
    6401             :                 }
    6402             :             | CREATE TYPE_P any_name AS RANGE definition
    6403             :                 {
    6404         166 :                     CreateRangeStmt *n = makeNode(CreateRangeStmt);
    6405             : 
    6406         166 :                     n->typeName = $3;
    6407         166 :                     n->params = $6;
    6408         166 :                     $$ = (Node *) n;
    6409             :                 }
    6410             :             | CREATE TEXT_P SEARCH PARSER any_name definition
    6411             :                 {
    6412          40 :                     DefineStmt *n = makeNode(DefineStmt);
    6413             : 
    6414          40 :                     n->kind = OBJECT_TSPARSER;
    6415          40 :                     n->args = NIL;
    6416          40 :                     n->defnames = $5;
    6417          40 :                     n->definition = $6;
    6418          40 :                     $$ = (Node *) n;
    6419             :                 }
    6420             :             | CREATE TEXT_P SEARCH DICTIONARY any_name definition
    6421             :                 {
    6422        2274 :                     DefineStmt *n = makeNode(DefineStmt);
    6423             : 
    6424        2274 :                     n->kind = OBJECT_TSDICTIONARY;
    6425        2274 :                     n->args = NIL;
    6426        2274 :                     n->defnames = $5;
    6427        2274 :                     n->definition = $6;
    6428        2274 :                     $$ = (Node *) n;
    6429             :                 }
    6430             :             | CREATE TEXT_P SEARCH TEMPLATE any_name definition
    6431             :                 {
    6432         120 :                     DefineStmt *n = makeNode(DefineStmt);
    6433             : 
    6434         120 :                     n->kind = OBJECT_TSTEMPLATE;
    6435         120 :                     n->args = NIL;
    6436         120 :                     n->defnames = $5;
    6437         120 :                     n->definition = $6;
    6438         120 :                     $$ = (Node *) n;
    6439             :                 }
    6440             :             | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
    6441             :                 {
    6442        2216 :                     DefineStmt *n = makeNode(DefineStmt);
    6443             : 
    6444        2216 :                     n->kind = OBJECT_TSCONFIGURATION;
    6445        2216 :                     n->args = NIL;
    6446        2216 :                     n->defnames = $5;
    6447        2216 :                     n->definition = $6;
    6448        2216 :                     $$ = (Node *) n;
    6449             :                 }
    6450             :             | CREATE COLLATION any_name definition
    6451             :                 {
    6452         272 :                     DefineStmt *n = makeNode(DefineStmt);
    6453             : 
    6454         272 :                     n->kind = OBJECT_COLLATION;
    6455         272 :                     n->args = NIL;
    6456         272 :                     n->defnames = $3;
    6457         272 :                     n->definition = $4;
    6458         272 :                     $$ = (Node *) n;
    6459             :                 }
    6460             :             | CREATE COLLATION IF_P NOT EXISTS any_name definition
    6461             :                 {
    6462          18 :                     DefineStmt *n = makeNode(DefineStmt);
    6463             : 
    6464          18 :                     n->kind = OBJECT_COLLATION;
    6465          18 :                     n->args = NIL;
    6466          18 :                     n->defnames = $6;
    6467          18 :                     n->definition = $7;
    6468          18 :                     n->if_not_exists = true;
    6469          18 :                     $$ = (Node *) n;
    6470             :                 }
    6471             :             | CREATE COLLATION any_name FROM any_name
    6472             :                 {
    6473          52 :                     DefineStmt *n = makeNode(DefineStmt);
    6474             : 
    6475          52 :                     n->kind = OBJECT_COLLATION;
    6476          52 :                     n->args = NIL;
    6477          52 :                     n->defnames = $3;
    6478          52 :                     n->definition = list_make1(makeDefElem("from", (Node *) $5, @5));
    6479          52 :                     $$ = (Node *) n;
    6480             :                 }
    6481             :             | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
    6482             :                 {
    6483           0 :                     DefineStmt *n = makeNode(DefineStmt);
    6484             : 
    6485           0 :                     n->kind = OBJECT_COLLATION;
    6486           0 :                     n->args = NIL;
    6487           0 :                     n->defnames = $6;
    6488           0 :                     n->definition = list_make1(makeDefElem("from", (Node *) $8, @8));
    6489           0 :                     n->if_not_exists = true;
    6490           0 :                     $$ = (Node *) n;
    6491             :                 }
    6492             :         ;
    6493             : 
    6494        8326 : definition: '(' def_list ')'                        { $$ = $2; }
    6495             :         ;
    6496             : 
    6497        8326 : def_list:   def_elem                                { $$ = list_make1($1); }
    6498       13508 :             | def_list ',' def_elem                 { $$ = lappend($1, $3); }
    6499             :         ;
    6500             : 
    6501             : def_elem:   ColLabel '=' def_arg
    6502             :                 {
    6503       21504 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6504             :                 }
    6505             :             | ColLabel
    6506             :                 {
    6507         330 :                     $$ = makeDefElem($1, NULL, @1);
    6508             :                 }
    6509             :         ;
    6510             : 
    6511             : /* Note: any simple identifier will be returned as a type name! */
    6512       17668 : def_arg:    func_type                       { $$ = (Node *) $1; }
    6513        3280 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
    6514        1174 :             | qual_all_Op                   { $$ = (Node *) $1; }
    6515        1270 :             | NumericOnly                   { $$ = (Node *) $1; }
    6516        1804 :             | Sconst                        { $$ = (Node *) makeString($1); }
    6517         130 :             | NONE                          { $$ = (Node *) makeString(pstrdup($1)); }
    6518             :         ;
    6519             : 
    6520         362 : old_aggr_definition: '(' old_aggr_list ')'          { $$ = $2; }
    6521             :         ;
    6522             : 
    6523         362 : old_aggr_list: old_aggr_elem                        { $$ = list_make1($1); }
    6524        1292 :             | old_aggr_list ',' old_aggr_elem       { $$ = lappend($1, $3); }
    6525             :         ;
    6526             : 
    6527             : /*
    6528             :  * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
    6529             :  * the item names needed in old aggregate definitions are likely to become
    6530             :  * SQL keywords.
    6531             :  */
    6532             : old_aggr_elem:  IDENT '=' def_arg
    6533             :                 {
    6534        1654 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6535             :                 }
    6536             :         ;
    6537             : 
    6538             : opt_enum_val_list:
    6539         180 :         enum_val_list                           { $$ = $1; }
    6540           8 :         | /*EMPTY*/                             { $$ = NIL; }
    6541             :         ;
    6542             : 
    6543             : enum_val_list:  Sconst
    6544         180 :                 { $$ = list_make1(makeString($1)); }
    6545             :             | enum_val_list ',' Sconst
    6546       10394 :                 { $$ = lappend($1, makeString($3)); }
    6547             :         ;
    6548             : 
    6549             : /*****************************************************************************
    6550             :  *
    6551             :  *  ALTER TYPE enumtype ADD ...
    6552             :  *
    6553             :  *****************************************************************************/
    6554             : 
    6555             : AlterEnumStmt:
    6556             :         ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
    6557             :             {
    6558         154 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6559             : 
    6560         154 :                 n->typeName = $3;
    6561         154 :                 n->oldVal = NULL;
    6562         154 :                 n->newVal = $7;
    6563         154 :                 n->newValNeighbor = NULL;
    6564         154 :                 n->newValIsAfter = true;
    6565         154 :                 n->skipIfNewValExists = $6;
    6566         154 :                 $$ = (Node *) n;
    6567             :             }
    6568             :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
    6569             :             {
    6570         194 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6571             : 
    6572         194 :                 n->typeName = $3;
    6573         194 :                 n->oldVal = NULL;
    6574         194 :                 n->newVal = $7;
    6575         194 :                 n->newValNeighbor = $9;
    6576         194 :                 n->newValIsAfter = false;
    6577         194 :                 n->skipIfNewValExists = $6;
    6578         194 :                 $$ = (Node *) n;
    6579             :             }
    6580             :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
    6581             :             {
    6582          22 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6583             : 
    6584          22 :                 n->typeName = $3;
    6585          22 :                 n->oldVal = NULL;
    6586          22 :                 n->newVal = $7;
    6587          22 :                 n->newValNeighbor = $9;
    6588          22 :                 n->newValIsAfter = true;
    6589          22 :                 n->skipIfNewValExists = $6;
    6590          22 :                 $$ = (Node *) n;
    6591             :             }
    6592             :          | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
    6593             :             {
    6594          24 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6595             : 
    6596          24 :                 n->typeName = $3;
    6597          24 :                 n->oldVal = $6;
    6598          24 :                 n->newVal = $8;
    6599          24 :                 n->newValNeighbor = NULL;
    6600          24 :                 n->newValIsAfter = false;
    6601          24 :                 n->skipIfNewValExists = false;
    6602          24 :                 $$ = (Node *) n;
    6603             :             }
    6604             :          | ALTER TYPE_P any_name DROP VALUE_P Sconst
    6605             :             {
    6606             :                 /*
    6607             :                  * The following problems must be solved before this can be
    6608             :                  * implemented:
    6609             :                  *
    6610             :                  * - There must be no instance of the target value in
    6611             :                  *   any table.
    6612             :                  *
    6613             :                  * - The value must not appear in any catalog metadata,
    6614             :                  *   such as stored view expressions or column defaults.
    6615             :                  *
    6616             :                  * - The value must not appear in any non-leaf page of a
    6617             :                  *   btree (and similar issues with other index types).
    6618             :                  *   This is problematic because a value could persist
    6619             :                  *   there long after it's gone from user-visible data.
    6620             :                  *
    6621             :                  * - Concurrent sessions must not be able to insert the
    6622             :                  *   value while the preceding conditions are being checked.
    6623             :                  *
    6624             :                  * - Possibly more...
    6625             :                  */
    6626           0 :                 ereport(ERROR,
    6627             :                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6628             :                          errmsg("dropping an enum value is not implemented"),
    6629             :                          parser_errposition(@4)));
    6630             :             }
    6631             :          ;
    6632             : 
    6633          12 : opt_if_not_exists: IF_P NOT EXISTS              { $$ = true; }
    6634         358 :         | /* EMPTY */                          { $$ = false; }
    6635             :         ;
    6636             : 
    6637             : 
    6638             : /*****************************************************************************
    6639             :  *
    6640             :  *      QUERIES :
    6641             :  *              CREATE OPERATOR CLASS ...
    6642             :  *              CREATE OPERATOR FAMILY ...
    6643             :  *              ALTER OPERATOR FAMILY ...
    6644             :  *              DROP OPERATOR CLASS ...
    6645             :  *              DROP OPERATOR FAMILY ...
    6646             :  *
    6647             :  *****************************************************************************/
    6648             : 
    6649             : CreateOpClassStmt:
    6650             :             CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
    6651             :             USING name opt_opfamily AS opclass_item_list
    6652             :                 {
    6653         382 :                     CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
    6654             : 
    6655         382 :                     n->opclassname = $4;
    6656         382 :                     n->isDefault = $5;
    6657         382 :                     n->datatype = $8;
    6658         382 :                     n->amname = $10;
    6659         382 :                     n->opfamilyname = $11;
    6660         382 :                     n->items = $13;
    6661         382 :                     $$ = (Node *) n;
    6662             :                 }
    6663             :         ;
    6664             : 
    6665             : opclass_item_list:
    6666         820 :             opclass_item                            { $$ = list_make1($1); }
    6667        3058 :             | opclass_item_list ',' opclass_item    { $$ = lappend($1, $3); }
    6668             :         ;
    6669             : 
    6670             : opclass_item:
    6671             :             OPERATOR Iconst any_operator opclass_purpose opt_recheck
    6672             :                 {
    6673        1092 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6674        1092 :                     ObjectWithArgs *owa = makeNode(ObjectWithArgs);
    6675             : 
    6676        1092 :                     owa->objname = $3;
    6677        1092 :                     owa->objargs = NIL;
    6678        1092 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6679        1092 :                     n->name = owa;
    6680        1092 :                     n->number = $2;
    6681        1092 :                     n->order_family = $4;
    6682        1092 :                     $$ = (Node *) n;
    6683             :                 }
    6684             :             | OPERATOR Iconst operator_with_argtypes opclass_purpose
    6685             :               opt_recheck
    6686             :                 {
    6687        1026 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6688             : 
    6689        1026 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6690        1026 :                     n->name = $3;
    6691        1026 :                     n->number = $2;
    6692        1026 :                     n->order_family = $4;
    6693        1026 :                     $$ = (Node *) n;
    6694             :                 }
    6695             :             | FUNCTION Iconst function_with_argtypes
    6696             :                 {
    6697        1374 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6698             : 
    6699        1374 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6700        1374 :                     n->name = $3;
    6701        1374 :                     n->number = $2;
    6702        1374 :                     $$ = (Node *) n;
    6703             :                 }
    6704             :             | FUNCTION Iconst '(' type_list ')' function_with_argtypes
    6705             :                 {
    6706         188 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6707             : 
    6708         188 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6709         188 :                     n->name = $6;
    6710         188 :                     n->number = $2;
    6711         188 :                     n->class_args = $4;
    6712         188 :                     $$ = (Node *) n;
    6713             :                 }
    6714             :             | STORAGE Typename
    6715             :                 {
    6716         198 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6717             : 
    6718         198 :                     n->itemtype = OPCLASS_ITEM_STORAGETYPE;
    6719         198 :                     n->storedtype = $2;
    6720         198 :                     $$ = (Node *) n;
    6721             :                 }
    6722             :         ;
    6723             : 
    6724         290 : opt_default:    DEFAULT                     { $$ = true; }
    6725         156 :             | /*EMPTY*/                     { $$ = false; }
    6726             :         ;
    6727             : 
    6728          44 : opt_opfamily:   FAMILY any_name             { $$ = $2; }
    6729         338 :             | /*EMPTY*/                     { $$ = NIL; }
    6730             :         ;
    6731             : 
    6732           0 : opclass_purpose: FOR SEARCH                 { $$ = NIL; }
    6733          72 :             | FOR ORDER BY any_name         { $$ = $4; }
    6734        2046 :             | /*EMPTY*/                     { $$ = NIL; }
    6735             :         ;
    6736             : 
    6737             : opt_recheck:    RECHECK
    6738             :                 {
    6739             :                     /*
    6740             :                      * RECHECK no longer does anything in opclass definitions,
    6741             :                      * but we still accept it to ease porting of old database
    6742             :                      * dumps.
    6743             :                      */
    6744           0 :                     ereport(NOTICE,
    6745             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6746             :                              errmsg("RECHECK is no longer required"),
    6747             :                              errhint("Update your data type."),
    6748             :                              parser_errposition(@1)));
    6749           0 :                     $$ = true;
    6750             :                 }
    6751        2118 :             | /*EMPTY*/                     { $$ = false; }
    6752             :         ;
    6753             : 
    6754             : 
    6755             : CreateOpFamilyStmt:
    6756             :             CREATE OPERATOR FAMILY any_name USING name
    6757             :                 {
    6758         148 :                     CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
    6759             : 
    6760         148 :                     n->opfamilyname = $4;
    6761         148 :                     n->amname = $6;
    6762         148 :                     $$ = (Node *) n;
    6763             :                 }
    6764             :         ;
    6765             : 
    6766             : AlterOpFamilyStmt:
    6767             :             ALTER OPERATOR FAMILY any_name USING name ADD_P opclass_item_list
    6768             :                 {
    6769         438 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6770             : 
    6771         438 :                     n->opfamilyname = $4;
    6772         438 :                     n->amname = $6;
    6773         438 :                     n->isDrop = false;
    6774         438 :                     n->items = $8;
    6775         438 :                     $$ = (Node *) n;
    6776             :                 }
    6777             :             | ALTER OPERATOR FAMILY any_name USING name DROP opclass_drop_list
    6778             :                 {
    6779          64 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6780             : 
    6781          64 :                     n->opfamilyname = $4;
    6782          64 :                     n->amname = $6;
    6783          64 :                     n->isDrop = true;
    6784          64 :                     n->items = $8;
    6785          64 :                     $$ = (Node *) n;
    6786             :                 }
    6787             :         ;
    6788             : 
    6789             : opclass_drop_list:
    6790          64 :             opclass_drop                            { $$ = list_make1($1); }
    6791          30 :             | opclass_drop_list ',' opclass_drop    { $$ = lappend($1, $3); }
    6792             :         ;
    6793             : 
    6794             : opclass_drop:
    6795             :             OPERATOR Iconst '(' type_list ')'
    6796             :                 {
    6797          56 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6798             : 
    6799          56 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6800          56 :                     n->number = $2;
    6801          56 :                     n->class_args = $4;
    6802          56 :                     $$ = (Node *) n;
    6803             :                 }
    6804             :             | FUNCTION Iconst '(' type_list ')'
    6805             :                 {
    6806          38 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6807             : 
    6808          38 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6809          38 :                     n->number = $2;
    6810          38 :                     n->class_args = $4;
    6811          38 :                     $$ = (Node *) n;
    6812             :                 }
    6813             :         ;
    6814             : 
    6815             : 
    6816             : DropOpClassStmt:
    6817             :             DROP OPERATOR CLASS any_name USING name opt_drop_behavior
    6818             :                 {
    6819          38 :                     DropStmt *n = makeNode(DropStmt);
    6820             : 
    6821          38 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6822          38 :                     n->removeType = OBJECT_OPCLASS;
    6823          38 :                     n->behavior = $7;
    6824          38 :                     n->missing_ok = false;
    6825          38 :                     n->concurrent = false;
    6826          38 :                     $$ = (Node *) n;
    6827             :                 }
    6828             :             | DROP OPERATOR CLASS IF_P EXISTS any_name USING name opt_drop_behavior
    6829             :                 {
    6830          18 :                     DropStmt *n = makeNode(DropStmt);
    6831             : 
    6832          18 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6833          18 :                     n->removeType = OBJECT_OPCLASS;
    6834          18 :                     n->behavior = $9;
    6835          18 :                     n->missing_ok = true;
    6836          18 :                     n->concurrent = false;
    6837          18 :                     $$ = (Node *) n;
    6838             :                 }
    6839             :         ;
    6840             : 
    6841             : DropOpFamilyStmt:
    6842             :             DROP OPERATOR FAMILY any_name USING name opt_drop_behavior
    6843             :                 {
    6844         110 :                     DropStmt *n = makeNode(DropStmt);
    6845             : 
    6846         110 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6847         110 :                     n->removeType = OBJECT_OPFAMILY;
    6848         110 :                     n->behavior = $7;
    6849         110 :                     n->missing_ok = false;
    6850         110 :                     n->concurrent = false;
    6851         110 :                     $$ = (Node *) n;
    6852             :                 }
    6853             :             | DROP OPERATOR FAMILY IF_P EXISTS any_name USING name opt_drop_behavior
    6854             :                 {
    6855          18 :                     DropStmt *n = makeNode(DropStmt);
    6856             : 
    6857          18 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6858          18 :                     n->removeType = OBJECT_OPFAMILY;
    6859          18 :                     n->behavior = $9;
    6860          18 :                     n->missing_ok = true;
    6861          18 :                     n->concurrent = false;
    6862          18 :                     $$ = (Node *) n;
    6863             :                 }
    6864             :         ;
    6865             : 
    6866             : 
    6867             : /*****************************************************************************
    6868             :  *
    6869             :  *      QUERY:
    6870             :  *
    6871             :  *      DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
    6872             :  *      REASSIGN OWNED BY username [, username ...] TO username
    6873             :  *
    6874             :  *****************************************************************************/
    6875             : DropOwnedStmt:
    6876             :             DROP OWNED BY role_list opt_drop_behavior
    6877             :                 {
    6878         146 :                     DropOwnedStmt *n = makeNode(DropOwnedStmt);
    6879             : 
    6880         146 :                     n->roles = $4;
    6881         146 :                     n->behavior = $5;
    6882         146 :                     $$ = (Node *) n;
    6883             :                 }
    6884             :         ;
    6885             : 
    6886             : ReassignOwnedStmt:
    6887             :             REASSIGN OWNED BY role_list TO RoleSpec
    6888             :                 {
    6889          38 :                     ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
    6890             : 
    6891          38 :                     n->roles = $4;
    6892          38 :                     n->newrole = $6;
    6893          38 :                     $$ = (Node *) n;
    6894             :                 }
    6895             :         ;
    6896             : 
    6897             : /*****************************************************************************
    6898             :  *
    6899             :  *      QUERY:
    6900             :  *
    6901             :  *      DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
    6902             :  *           [ RESTRICT | CASCADE ]
    6903             :  *
    6904             :  *****************************************************************************/
    6905             : 
    6906             : DropStmt:   DROP object_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
    6907             :                 {
    6908        1268 :                     DropStmt *n = makeNode(DropStmt);
    6909             : 
    6910        1268 :                     n->removeType = $2;
    6911        1268 :                     n->missing_ok = true;
    6912        1268 :                     n->objects = $5;
    6913        1268 :                     n->behavior = $6;
    6914        1268 :                     n->concurrent = false;
    6915        1268 :                     $$ = (Node *) n;
    6916             :                 }
    6917             :             | DROP object_type_any_name any_name_list opt_drop_behavior
    6918             :                 {
    6919       15240 :                     DropStmt *n = makeNode(DropStmt);
    6920             : 
    6921       15240 :                     n->removeType = $2;
    6922       15240 :                     n->missing_ok = false;
    6923       15240 :                     n->objects = $3;
    6924       15240 :                     n->behavior = $4;
    6925       15240 :                     n->concurrent = false;
    6926       15240 :                     $$ = (Node *) n;
    6927             :                 }
    6928             :             | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
    6929             :                 {
    6930          78 :                     DropStmt *n = makeNode(DropStmt);
    6931             : 
    6932          78 :                     n->removeType = $2;
    6933          78 :                     n->missing_ok = true;
    6934          78 :                     n->objects = $5;
    6935          78 :                     n->behavior = $6;
    6936          78 :                     n->concurrent = false;
    6937          78 :                     $$ = (Node *) n;
    6938             :                 }
    6939             :             | DROP drop_type_name name_list opt_drop_behavior
    6940             :                 {
    6941        1264 :                     DropStmt *n = makeNode(DropStmt);
    6942             : 
    6943        1264 :                     n->removeType = $2;
    6944        1264 :                     n->missing_ok = false;
    6945        1264 :                     n->objects = $3;
    6946        1264 :                     n->behavior = $4;
    6947        1264 :                     n->concurrent = false;
    6948        1264 :                     $$ = (Node *) n;
    6949             :                 }
    6950             :             | DROP object_type_name_on_any_name name ON any_name opt_drop_behavior
    6951             :                 {
    6952        1068 :                     DropStmt *n = makeNode(DropStmt);
    6953             : 
    6954        1068 :                     n->removeType = $2;
    6955        1068 :                     n->objects = list_make1(lappend($5, makeString($3)));
    6956        1068 :                     n->behavior = $6;
    6957        1068 :                     n->missing_ok = false;
    6958        1068 :                     n->concurrent = false;
    6959        1068 :                     $$ = (Node *) n;
    6960             :                 }
    6961             :             | DROP object_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
    6962             :                 {
    6963          48 :                     DropStmt *n = makeNode(DropStmt);
    6964             : 
    6965          48 :                     n->removeType = $2;
    6966          48 :                     n->objects = list_make1(lappend($7, makeString($5)));
    6967          48 :                     n->behavior = $8;
    6968          48 :                     n->missing_ok = true;
    6969          48 :                     n->concurrent = false;
    6970          48 :                     $$ = (Node *) n;
    6971             :                 }
    6972             :             | DROP TYPE_P type_name_list opt_drop_behavior
    6973             :                 {
    6974         530 :                     DropStmt *n = makeNode(DropStmt);
    6975             : 
    6976         530 :                     n->removeType = OBJECT_TYPE;
    6977         530 :                     n->missing_ok = false;
    6978         530 :                     n->objects = $3;
    6979         530 :                     n->behavior = $4;
    6980         530 :                     n->concurrent = false;
    6981         530 :                     $$ = (Node *) n;
    6982             :                 }
    6983             :             | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
    6984             :                 {
    6985          22 :                     DropStmt *n = makeNode(DropStmt);
    6986             : 
    6987          22 :                     n->removeType = OBJECT_TYPE;
    6988          22 :                     n->missing_ok = true;
    6989          22 :                     n->objects = $5;
    6990          22 :                     n->behavior = $6;
    6991          22 :                     n->concurrent = false;
    6992          22 :                     $$ = (Node *) n;
    6993             :                 }
    6994             :             | DROP DOMAIN_P type_name_list opt_drop_behavior
    6995             :                 {
    6996         428 :                     DropStmt *n = makeNode(DropStmt);
    6997             : 
    6998         428 :                     n->removeType = OBJECT_DOMAIN;
    6999         428 :                     n->missing_ok = false;
    7000         428 :                     n->objects = $3;
    7001         428 :                     n->behavior = $4;
    7002         428 :                     n->concurrent = false;
    7003         428 :                     $$ = (Node *) n;
    7004             :                 }
    7005             :             | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
    7006             :                 {
    7007          18 :                     DropStmt *n = makeNode(DropStmt);
    7008             : 
    7009          18 :                     n->removeType = OBJECT_DOMAIN;
    7010          18 :                     n->missing_ok = true;
    7011          18 :                     n->objects = $5;
    7012          18 :                     n->behavior = $6;
    7013          18 :                     n->concurrent = false;
    7014          18 :                     $$ = (Node *) n;
    7015             :                 }
    7016             :             | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
    7017             :                 {
    7018         112 :                     DropStmt *n = makeNode(DropStmt);
    7019             : 
    7020         112 :                     n->removeType = OBJECT_INDEX;
    7021         112 :                     n->missing_ok = false;
    7022         112 :                     n->objects = $4;
    7023         112 :                     n->behavior = $5;
    7024         112 :                     n->concurrent = true;
    7025         112 :                     $$ = (Node *) n;
    7026             :                 }
    7027             :             | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
    7028             :                 {
    7029          12 :                     DropStmt *n = makeNode(DropStmt);
    7030             : 
    7031          12 :                     n->removeType = OBJECT_INDEX;
    7032          12 :                     n->missing_ok = true;
    7033          12 :                     n->objects = $6;
    7034          12 :                     n->behavior = $7;
    7035          12 :                     n->concurrent = true;
    7036          12 :                     $$ = (Node *) n;
    7037             :                 }
    7038             :         ;
    7039             : 
    7040             : /* object types taking any_name/any_name_list */
    7041             : object_type_any_name:
    7042       14264 :             TABLE                                   { $$ = OBJECT_TABLE; }
    7043         194 :             | SEQUENCE                              { $$ = OBJECT_SEQUENCE; }
    7044         936 :             | VIEW                                  { $$ = OBJECT_VIEW; }
    7045         124 :             | MATERIALIZED VIEW                     { $$ = OBJECT_MATVIEW; }
    7046         736 :             | INDEX                                 { $$ = OBJECT_INDEX; }
    7047         170 :             | FOREIGN TABLE                         { $$ = OBJECT_FOREIGN_TABLE; }
    7048          90 :             | COLLATION                             { $$ = OBJECT_COLLATION; }
    7049          56 :             | CONVERSION_P                          { $$ = OBJECT_CONVERSION; }
    7050         192 :             | STATISTICS                            { $$ = OBJECT_STATISTIC_EXT; }
    7051          20 :             | TEXT_P SEARCH PARSER                  { $$ = OBJECT_TSPARSER; }
    7052        2158 :             | TEXT_P SEARCH DICTIONARY              { $$ = OBJECT_TSDICTIONARY; }
    7053          96 :             | TEXT_P SEARCH TEMPLATE                { $$ = OBJECT_TSTEMPLATE; }
    7054        2162 :             | TEXT_P SEARCH CONFIGURATION           { $$ = OBJECT_TSCONFIGURATION; }
    7055             :         ;
    7056             : 
    7057             : /*
    7058             :  * object types taking name/name_list
    7059             :  *
    7060             :  * DROP handles some of them separately
    7061             :  */
    7062             : 
    7063             : object_type_name:
    7064         184 :             drop_type_name                          { $$ = $1; }
    7065         178 :             | DATABASE                              { $$ = OBJECT_DATABASE; }
    7066          52 :             | ROLE                                  { $$ = OBJECT_ROLE; }
    7067          10 :             | SUBSCRIPTION                          { $$ = OBJECT_SUBSCRIPTION; }
    7068           0 :             | TABLESPACE                            { $$ = OBJECT_TABLESPACE; }
    7069             :         ;
    7070             : 
    7071             : drop_type_name:
    7072          58 :             ACCESS METHOD                           { $$ = OBJECT_ACCESS_METHOD; }
    7073         126 :             | EVENT TRIGGER                         { $$ = OBJECT_EVENT_TRIGGER; }
    7074         108 :             | EXTENSION                             { $$ = OBJECT_EXTENSION; }
    7075         148 :             | FOREIGN DATA_P WRAPPER                { $$ = OBJECT_FDW; }
    7076         134 :             | opt_procedural LANGUAGE               { $$ = OBJECT_LANGUAGE; }
    7077         282 :             | PUBLICATION                           { $$ = OBJECT_PUBLICATION; }
    7078         540 :             | SCHEMA                                { $$ = OBJECT_SCHEMA; }
    7079         130 :             | SERVER                                { $$ = OBJECT_FOREIGN_SERVER; }
    7080             :         ;
    7081             : 
    7082             : /* object types attached to a table */
    7083             : object_type_name_on_any_name:
    7084         164 :             POLICY                                  { $$ = OBJECT_POLICY; }
    7085         244 :             | RULE                                  { $$ = OBJECT_RULE; }
    7086         760 :             | TRIGGER                               { $$ = OBJECT_TRIGGER; }
    7087             :         ;
    7088             : 
    7089             : any_name_list:
    7090       23344 :             any_name                                { $$ = list_make1($1); }
    7091        3766 :             | any_name_list ',' any_name            { $$ = lappend($1, $3); }
    7092             :         ;
    7093             : 
    7094       53200 : any_name:   ColId                       { $$ = list_make1(makeString($1)); }
    7095        8372 :             | ColId attrs               { $$ = lcons(makeString($1), $2); }
    7096             :         ;
    7097             : 
    7098             : attrs:      '.' attr_name
    7099       93296 :                     { $$ = list_make1(makeString($2)); }
    7100             :             | attrs '.' attr_name
    7101          54 :                     { $$ = lappend($1, makeString($3)); }
    7102             :         ;
    7103             : 
    7104             : type_name_list:
    7105         998 :             Typename                                { $$ = list_make1($1); }
    7106          78 :             | type_name_list ',' Typename           { $$ = lappend($1, $3); }
    7107             :         ;
    7108             : 
    7109             : /*****************************************************************************
    7110             :  *
    7111             :  *      QUERY:
    7112             :  *              truncate table relname1, relname2, ...
    7113             :  *
    7114             :  *****************************************************************************/
    7115             : 
    7116             : TruncateStmt:
    7117             :             TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
    7118             :                 {
    7119        1444 :                     TruncateStmt *n = makeNode(TruncateStmt);
    7120             : 
    7121        1444 :                     n->relations = $3;
    7122        1444 :                     n->restart_seqs = $4;
    7123        1444 :                     n->behavior = $5;
    7124        1444 :                     $$ = (Node *) n;
    7125             :                 }
    7126             :         ;
    7127             : 
    7128             : opt_restart_seqs:
    7129          24 :             CONTINUE_P IDENTITY_P       { $$ = false; }
    7130          24 :             | RESTART IDENTITY_P        { $$ = true; }
    7131        1396 :             | /* EMPTY */               { $$ = false; }
    7132             :         ;
    7133             : 
    7134             : /*****************************************************************************
    7135             :  *
    7136             :  * COMMENT ON <object> IS <text>
    7137             :  *
    7138             :  *****************************************************************************/
    7139             : 
    7140             : CommentStmt:
    7141             :             COMMENT ON object_type_any_name any_name IS comment_text
    7142             :                 {
    7143        4566 :                     CommentStmt *n = makeNode(CommentStmt);
    7144             : 
    7145        4566 :                     n->objtype = $3;
    7146        4566 :                     n->object = (Node *) $4;
    7147        4566 :                     n->comment = $6;
    7148        4566 :                     $$ = (Node *) n;
    7149             :                 }
    7150             :             | COMMENT ON COLUMN any_name IS comment_text
    7151             :                 {
    7152         108 :                     CommentStmt *n = makeNode(CommentStmt);
    7153             : 
    7154         108 :                     n->objtype = OBJECT_COLUMN;
    7155         108 :                     n->object = (Node *) $4;
    7156         108 :                     n->comment = $6;
    7157         108 :                     $$ = (Node *) n;
    7158             :                 }
    7159             :             | COMMENT ON object_type_name name IS comment_text
    7160             :                 {
    7161         362 :                     CommentStmt *n = makeNode(CommentStmt);
    7162             : 
    7163         362 :                     n->objtype = $3;
    7164         362 :                     n->object = (Node *) makeString($4);
    7165         362 :                     n->comment = $6;
    7166         362 :                     $$ = (Node *) n;
    7167             :                 }
    7168             :             | COMMENT ON TYPE_P Typename IS comment_text
    7169             :                 {
    7170          56 :                     CommentStmt *n = makeNode(CommentStmt);
    7171             : 
    7172          56 :                     n->objtype = OBJECT_TYPE;
    7173          56 :                     n->object = (Node *) $4;
    7174          56 :                     n->comment = $6;
    7175          56 :                     $$ = (Node *) n;
    7176             :                 }
    7177             :             | COMMENT ON DOMAIN_P Typename IS comment_text
    7178             :                 {
    7179           8 :                     CommentStmt *n = makeNode(CommentStmt);
    7180             : 
    7181           8 :                     n->objtype = OBJECT_DOMAIN;
    7182           8 :                     n->object = (Node *) $4;
    7183           8 :                     n->comment = $6;
    7184           8 :                     $$ = (Node *) n;
    7185             :                 }
    7186             :             | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
    7187             :                 {
    7188          40 :                     CommentStmt *n = makeNode(CommentStmt);
    7189             : 
    7190          40 :                     n->objtype = OBJECT_AGGREGATE;
    7191          40 :                     n->object = (Node *) $4;
    7192          40 :                     n->comment = $6;
    7193          40 :                     $$ = (Node *) n;
    7194             :                 }
    7195             :             | COMMENT ON FUNCTION function_with_argtypes IS comment_text
    7196             :                 {
    7197         170 :                     CommentStmt *n = makeNode(CommentStmt);
    7198             : 
    7199         170 :                     n->objtype = OBJECT_FUNCTION;
    7200         170 :                     n->object = (Node *) $4;
    7201         170 :                     n->comment = $6;
    7202         170 :                     $$ = (Node *) n;
    7203             :                 }
    7204             :             | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
    7205             :                 {
    7206          18 :                     CommentStmt *n = makeNode(CommentStmt);
    7207             : 
    7208          18 :                     n->objtype = OBJECT_OPERATOR;
    7209          18 :                     n->object = (Node *) $4;
    7210          18 :                     n->comment = $6;
    7211          18 :                     $$ = (Node *) n;
    7212             :                 }
    7213             :             | COMMENT ON CONSTRAINT name ON any_name IS comment_text
    7214             :                 {
    7215         104 :                     CommentStmt *n = makeNode(CommentStmt);
    7216             : 
    7217         104 :                     n->objtype = OBJECT_TABCONSTRAINT;
    7218         104 :                     n->object = (Node *) lappend($6, makeString($4));
    7219         104 :                     n->comment = $8;
    7220         104 :                     $$ = (Node *) n;
    7221             :                 }
    7222             :             | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
    7223             :                 {
    7224          38 :                     CommentStmt *n = makeNode(CommentStmt);
    7225             : 
    7226          38 :                     n->objtype = OBJECT_DOMCONSTRAINT;
    7227             :                     /*
    7228             :                      * should use Typename not any_name in the production, but
    7229             :                      * there's a shift/reduce conflict if we do that, so fix it
    7230             :                      * up here.
    7231             :                      */
    7232          38 :                     n->object = (Node *) list_make2(makeTypeNameFromNameList($7), makeString($4));
    7233          38 :                     n->comment = $9;
    7234          38 :                     $$ = (Node *) n;
    7235             :                 }
    7236             :             | COMMENT ON object_type_name_on_any_name name ON any_name IS comment_text
    7237             :                 {
    7238          40 :                     CommentStmt *n = makeNode(CommentStmt);
    7239             : 
    7240          40 :                     n->objtype = $3;
    7241          40 :                     n->object = (Node *) lappend($6, makeString($4));
    7242          40 :                     n->comment = $8;
    7243          40 :                     $$ = (Node *) n;
    7244             :                 }
    7245             :             | COMMENT ON PROCEDURE function_with_argtypes IS comment_text
    7246             :                 {
    7247           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7248             : 
    7249           0 :                     n->objtype = OBJECT_PROCEDURE;
    7250           0 :                     n->object = (Node *) $4;
    7251           0 :                     n->comment = $6;
    7252           0 :                     $$ = (Node *) n;
    7253             :                 }
    7254             :             | COMMENT ON ROUTINE function_with_argtypes IS comment_text
    7255             :                 {
    7256           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7257             : 
    7258           0 :                     n->objtype = OBJECT_ROUTINE;
    7259           0 :                     n->object = (Node *) $4;
    7260           0 :                     n->comment = $6;
    7261           0 :                     $$ = (Node *) n;
    7262             :                 }
    7263             :             | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
    7264             :                 {
    7265          14 :                     CommentStmt *n = makeNode(CommentStmt);
    7266             : 
    7267          14 :                     n->objtype = OBJECT_TRANSFORM;
    7268          14 :                     n->object = (Node *) list_make2($5, makeString($7));
    7269          14 :                     n->comment = $9;
    7270          14 :                     $$ = (Node *) n;
    7271             :                 }
    7272             :             | COMMENT ON OPERATOR CLASS any_name USING name IS comment_text
    7273             :                 {
    7274           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7275             : 
    7276           0 :                     n->objtype = OBJECT_OPCLASS;
    7277           0 :                     n->object = (Node *) lcons(makeString($7), $5);
    7278           0 :                     n->comment = $9;
    7279           0 :                     $$ = (Node *) n;
    7280             :                 }
    7281             :             | COMMENT ON OPERATOR FAMILY any_name USING name IS comment_text
    7282             :                 {
    7283           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7284             : 
    7285           0 :                     n->objtype = OBJECT_OPFAMILY;
    7286           0 :                     n->object = (Node *) lcons(makeString($7), $5);
    7287           0 :                     n->comment = $9;
    7288           0 :                     $$ = (Node *) n;
    7289             :                 }
    7290             :             | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
    7291             :                 {
    7292          24 :                     CommentStmt *n = makeNode(CommentStmt);
    7293             : 
    7294          24 :                     n->objtype = OBJECT_LARGEOBJECT;
    7295          24 :                     n->object = (Node *) $5;
    7296          24 :                     n->comment = $7;
    7297          24 :                     $$ = (Node *) n;
    7298             :                 }
    7299             :             | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
    7300             :                 {
    7301           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7302             : 
    7303           0 :                     n->objtype = OBJECT_CAST;
    7304           0 :                     n->object = (Node *) list_make2($5, $7);
    7305           0 :                     n->comment = $10;
    7306           0 :                     $$ = (Node *) n;
    7307             :                 }
    7308             :         ;
    7309             : 
    7310             : comment_text:
    7311        5444 :             Sconst                              { $$ = $1; }
    7312         104 :             | NULL_P                            { $$ = NULL; }
    7313             :         ;
    7314             : 
    7315             : 
    7316             : /*****************************************************************************
    7317             :  *
    7318             :  *  SECURITY LABEL [FOR <provider>] ON <object> IS <label>
    7319             :  *
    7320             :  *  As with COMMENT ON, <object> can refer to various types of database
    7321             :  *  objects (e.g. TABLE, COLUMN, etc.).
    7322             :  *
    7323             :  *****************************************************************************/
    7324             : 
    7325             : SecLabelStmt:
    7326             :             SECURITY LABEL opt_provider ON object_type_any_name any_name
    7327             :             IS security_label
    7328             :                 {
    7329          48 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7330             : 
    7331          48 :                     n->provider = $3;
    7332          48 :                     n->objtype = $5;
    7333          48 :                     n->object = (Node *) $6;
    7334          48 :                     n->label = $8;
    7335          48 :                     $$ = (Node *) n;
    7336             :                 }
    7337             :             | SECURITY LABEL opt_provider ON COLUMN any_name
    7338             :               IS security_label
    7339             :                 {
    7340           4 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7341             : 
    7342           4 :                     n->provider = $3;
    7343           4 :                     n->objtype = OBJECT_COLUMN;
    7344           4 :                     n->object = (Node *) $6;
    7345           4 :                     n->label = $8;
    7346           4 :                     $$ = (Node *) n;
    7347             :                 }
    7348             :             | SECURITY LABEL opt_provider ON object_type_name name
    7349             :               IS security_label
    7350             :                 {
    7351          44 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7352             : 
    7353          44 :                     n->provider = $3;
    7354          44 :                     n->objtype = $5;
    7355          44 :                     n->object = (Node *) makeString($6);
    7356          44 :                     n->label = $8;
    7357          44 :                     $$ = (Node *) n;
    7358             :                 }
    7359             :             | SECURITY LABEL opt_provider ON TYPE_P Typename
    7360             :               IS security_label
    7361             :                 {
    7362           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7363             : 
    7364           0 :                     n->provider = $3;
    7365           0 :                     n->objtype = OBJECT_TYPE;
    7366           0 :                     n->object = (Node *) $6;
    7367           0 :                     n->label = $8;
    7368           0 :                     $$ = (Node *) n;
    7369             :                 }
    7370             :             | SECURITY LABEL opt_provider ON DOMAIN_P Typename
    7371             :               IS security_label
    7372             :                 {
    7373           2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7374             : 
    7375           2 :                     n->provider = $3;
    7376           2 :                     n->objtype = OBJECT_DOMAIN;
    7377           2 :                     n->object = (Node *) $6;
    7378           2 :                     n->label = $8;
    7379           2 :                     $$ = (Node *) n;
    7380             :                 }
    7381             :             | SECURITY LABEL opt_provider ON AGGREGATE aggregate_with_argtypes
    7382             :               IS security_label
    7383             :                 {
    7384           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7385             : 
    7386           0 :                     n->provider = $3;
    7387           0 :                     n->objtype = OBJECT_AGGREGATE;
    7388           0 :                     n->object = (Node *) $6;
    7389           0 :                     n->label = $8;
    7390           0 :                     $$ = (Node *) n;
    7391             :                 }
    7392             :             | SECURITY LABEL opt_provider ON FUNCTION function_with_argtypes
    7393             :               IS security_label
    7394             :                 {
    7395           2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7396             : 
    7397           2 :                     n->provider = $3;
    7398           2 :                     n->objtype = OBJECT_FUNCTION;
    7399           2 :                     n->object = (Node *) $6;
    7400           2 :                     n->label = $8;
    7401           2 :                     $$ = (Node *) n;
    7402             :                 }
    7403             :             | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
    7404             :               IS security_label
    7405             :                 {
    7406           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7407             : 
    7408           0 :                     n->provider = $3;
    7409           0 :                     n->objtype = OBJECT_LARGEOBJECT;
    7410           0 :                     n->object = (Node *) $7;
    7411           0 :                     n->label = $9;
    7412           0 :                     $$ = (Node *) n;
    7413             :                 }
    7414             :             | SECURITY LABEL opt_provider ON PROCEDURE function_with_argtypes
    7415             :               IS security_label
    7416             :                 {
    7417           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7418             : 
    7419           0 :                     n->provider = $3;
    7420           0 :                     n->objtype = OBJECT_PROCEDURE;
    7421           0 :                     n->object = (Node *) $6;
    7422           0 :                     n->label = $8;
    7423           0 :                     $$ = (Node *) n;
    7424             :                 }
    7425             :             | SECURITY LABEL opt_provider ON ROUTINE function_with_argtypes
    7426             :               IS security_label
    7427             :                 {
    7428           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7429             : 
    7430           0 :                     n->provider = $3;
    7431           0 :                     n->objtype = OBJECT_ROUTINE;
    7432           0 :                     n->object = (Node *) $6;
    7433           0 :                     n->label = $8;
    7434           0 :                     $$ = (Node *) n;
    7435             :                 }
    7436             :         ;
    7437             : 
    7438          20 : opt_provider:   FOR NonReservedWord_or_Sconst   { $$ = $2; }
    7439          80 :                 | /* EMPTY */                   { $$ = NULL; }
    7440             :         ;
    7441             : 
    7442         100 : security_label: Sconst              { $$ = $1; }
    7443           0 :                 | NULL_P            { $$ = NULL; }
    7444             :         ;
    7445             : 
    7446             : /*****************************************************************************
    7447             :  *
    7448             :  *      QUERY:
    7449             :  *          fetch/move
    7450             :  *
    7451             :  *****************************************************************************/
    7452             : 
    7453             : FetchStmt:  FETCH fetch_args
    7454             :                 {
    7455        5574 :                     FetchStmt *n = (FetchStmt *) $2;
    7456             : 
    7457        5574 :                     n->ismove = false;
    7458        5574 :                     $$ = (Node *) n;
    7459             :                 }
    7460             :             | MOVE fetch_args
    7461             :                 {
    7462         104 :                     FetchStmt *n = (FetchStmt *) $2;
    7463             : 
    7464         104 :                     n->ismove = true;
    7465         104 :                     $$ = (Node *) n;
    7466             :                 }
    7467             :         ;
    7468             : 
    7469             : fetch_args: cursor_name
    7470             :                 {
    7471         266 :                     FetchStmt *n = makeNode(FetchStmt);
    7472             : 
    7473         266 :                     n->portalname = $1;
    7474         266 :                     n->direction = FETCH_FORWARD;
    7475         266 :                     n->howMany = 1;
    7476         266 :                     $$ = (Node *) n;
    7477             :                 }
    7478             :             | from_in cursor_name
    7479             :                 {
    7480         216 :                     FetchStmt *n = makeNode(FetchStmt);
    7481             : 
    7482         216 :                     n->portalname = $2;
    7483         216 :                     n->direction = FETCH_FORWARD;
    7484         216 :                     n->howMany = 1;
    7485         216 :                     $$ = (Node *) n;
    7486             :                 }
    7487             :             | NEXT opt_from_in cursor_name
    7488             :                 {
    7489         262 :                     FetchStmt *n = makeNode(FetchStmt);
    7490             : 
    7491         262 :                     n->portalname = $3;
    7492         262 :                     n->direction = FETCH_FORWARD;
    7493         262 :                     n->howMany = 1;
    7494         262 :                     $$ = (Node *) n;
    7495             :                 }
    7496             :             | PRIOR opt_from_in cursor_name
    7497             :                 {
    7498          30 :                     FetchStmt *n = makeNode(FetchStmt);
    7499             : 
    7500          30 :                     n->portalname = $3;
    7501          30 :                     n->direction = FETCH_BACKWARD;
    7502          30 :                     n->howMany = 1;
    7503          30 :                     $$ = (Node *) n;
    7504             :                 }
    7505             :             | FIRST_P opt_from_in cursor_name
    7506             :                 {
    7507          24 :                     FetchStmt *n = makeNode(FetchStmt);
    7508             : 
    7509          24 :                     n->portalname = $3;
    7510          24 :                     n->direction = FETCH_ABSOLUTE;
    7511          24 :                     n->howMany = 1;
    7512          24 :                     $$ = (Node *) n;
    7513             :                 }
    7514             :             | LAST_P opt_from_in cursor_name
    7515             :                 {
    7516          18 :                     FetchStmt *n = makeNode(FetchStmt);
    7517             : 
    7518          18 :                     n->portalname = $3;
    7519          18 :                     n->direction = FETCH_ABSOLUTE;
    7520          18 :                     n->howMany = -1;
    7521          18 :                     $$ = (Node *) n;
    7522             :                 }
    7523             :             | ABSOLUTE_P SignedIconst opt_from_in cursor_name
    7524             :                 {
    7525          88 :                     FetchStmt *n = makeNode(FetchStmt);
    7526             : 
    7527          88 :                     n->portalname = $4;
    7528          88 :                     n->direction = FETCH_ABSOLUTE;
    7529          88 :                     n->howMany = $2;
    7530          88 :                     $$ = (Node *) n;
    7531             :                 }
    7532             :             | RELATIVE_P SignedIconst opt_from_in cursor_name
    7533             :                 {
    7534          30 :                     FetchStmt *n = makeNode(FetchStmt);
    7535             : 
    7536          30 :                     n->portalname = $4;
    7537          30 :                     n->direction = FETCH_RELATIVE;
    7538          30 :                     n->howMany = $2;
    7539          30 :                     $$ = (Node *) n;
    7540             :                 }
    7541             :             | SignedIconst opt_from_in cursor_name
    7542             :                 {
    7543        4010 :                     FetchStmt *n = makeNode(FetchStmt);
    7544             : 
    7545        4010 :                     n->portalname = $3;
    7546        4010 :                     n->direction = FETCH_FORWARD;
    7547        4010 :                     n->howMany = $1;
    7548        4010 :                     $$ = (Node *) n;
    7549             :                 }
    7550             :             | ALL opt_from_in cursor_name
    7551             :                 {
    7552         266 :                     FetchStmt *n = makeNode(FetchStmt);
    7553             : 
    7554         266 :                     n->portalname = $3;
    7555         266 :                     n->direction = FETCH_FORWARD;
    7556         266 :                     n->howMany = FETCH_ALL;
    7557         266 :                     $$ = (Node *) n;
    7558             :                 }
    7559             :             | FORWARD opt_from_in cursor_name
    7560             :                 {
    7561          28 :                     FetchStmt *n = makeNode(FetchStmt);
    7562             : 
    7563          28 :                     n->portalname = $3;
    7564          28 :                     n->direction = FETCH_FORWARD;
    7565          28 :                     n->howMany = 1;
    7566          28 :                     $$ = (Node *) n;
    7567             :                 }
    7568             :             | FORWARD SignedIconst opt_from_in cursor_name
    7569             :                 {
    7570           2 :                     FetchStmt *n = makeNode(FetchStmt);
    7571             : 
    7572           2 :                     n->portalname = $4;
    7573           2 :                     n->direction = FETCH_FORWARD;
    7574           2 :                     n->howMany = $2;
    7575           2 :                     $$ = (Node *) n;
    7576             :                 }
    7577             :             | FORWARD ALL opt_from_in cursor_name
    7578             :                 {
    7579          14 :                     FetchStmt *n = makeNode(FetchStmt);
    7580             : 
    7581          14 :                     n->portalname = $4;
    7582          14 :                     n->direction = FETCH_FORWARD;
    7583          14 :                     n->howMany = FETCH_ALL;
    7584          14 :                     $$ = (Node *) n;
    7585             :                 }
    7586             :             | BACKWARD opt_from_in cursor_name
    7587             :                 {
    7588          78 :                     FetchStmt *n = makeNode(FetchStmt);
    7589             : 
    7590          78 :                     n->portalname = $3;
    7591          78 :                     n->direction = FETCH_BACKWARD;
    7592          78 :                     n->howMany = 1;
    7593          78 :                     $$ = (Node *) n;
    7594             :                 }
    7595             :             | BACKWARD SignedIconst opt_from_in cursor_name
    7596             :                 {
    7597         220 :                     FetchStmt *n = makeNode(FetchStmt);
    7598             : 
    7599         220 :                     n->portalname = $4;
    7600         220 :                     n->direction = FETCH_BACKWARD;
    7601         220 :                     n->howMany = $2;
    7602         220 :                     $$ = (Node *) n;
    7603             :                 }
    7604             :             | BACKWARD ALL opt_from_in cursor_name
    7605             :                 {
    7606         126 :                     FetchStmt *n = makeNode(FetchStmt);
    7607             : 
    7608         126 :                     n->portalname = $4;
    7609         126 :                     n->direction = FETCH_BACKWARD;
    7610         126 :                     n->howMany = FETCH_ALL;
    7611         126 :                     $$ = (Node *) n;
    7612             :                 }
    7613             :         ;
    7614             : 
    7615             : from_in:    FROM
    7616             :             | IN_P
    7617             :         ;
    7618             : 
    7619             : opt_from_in:    from_in
    7620             :             | /* EMPTY */
    7621             :         ;
    7622             : 
    7623             : 
    7624             : /*****************************************************************************
    7625             :  *
    7626             :  * GRANT and REVOKE statements
    7627             :  *
    7628             :  *****************************************************************************/
    7629             : 
    7630             : GrantStmt:  GRANT privileges ON privilege_target TO grantee_list
    7631             :             opt_grant_grant_option opt_granted_by
    7632             :                 {
    7633        8294 :                     GrantStmt *n = makeNode(GrantStmt);
    7634             : 
    7635        8294 :                     n->is_grant = true;
    7636        8294 :                     n->privileges = $2;
    7637        8294 :                     n->targtype = ($4)->targtype;
    7638        8294 :                     n->objtype = ($4)->objtype;
    7639        8294 :                     n->objects = ($4)->objs;
    7640        8294 :                     n->grantees = $6;
    7641        8294 :                     n->grant_option = $7;
    7642        8294 :                     n->grantor = $8;
    7643        8294 :                     $$ = (Node *) n;
    7644             :                 }
    7645             :         ;
    7646             : 
    7647             : RevokeStmt:
    7648             :             REVOKE privileges ON privilege_target
    7649             :             FROM grantee_list opt_granted_by opt_drop_behavior
    7650             :                 {
    7651        7074 :                     GrantStmt *n = makeNode(GrantStmt);
    7652             : 
    7653        7074 :                     n->is_grant = false;
    7654        7074 :                     n->grant_option = false;
    7655        7074 :                     n->privileges = $2;
    7656        7074 :                     n->targtype = ($4)->targtype;
    7657        7074 :                     n->objtype = ($4)->objtype;
    7658        7074 :                     n->objects = ($4)->objs;
    7659        7074 :                     n->grantees = $6;
    7660        7074 :                     n->grantor = $7;
    7661        7074 :                     n->behavior = $8;
    7662        7074 :                     $$ = (Node *) n;
    7663             :                 }
    7664             :             | REVOKE GRANT OPTION FOR privileges ON privilege_target
    7665             :             FROM grantee_list opt_granted_by opt_drop_behavior
    7666             :                 {
    7667          14 :                     GrantStmt *n = makeNode(GrantStmt);
    7668             : 
    7669          14 :                     n->is_grant = false;
    7670          14 :                     n->grant_option = true;
    7671          14 :                     n->privileges = $5;
    7672          14 :                     n->targtype = ($7)->targtype;
    7673          14 :                     n->objtype = ($7)->objtype;
    7674          14 :                     n->objects = ($7)->objs;
    7675          14 :                     n->grantees = $9;
    7676          14 :                     n->grantor = $10;
    7677          14 :                     n->behavior = $11;
    7678          14 :                     $$ = (Node *) n;
    7679             :                 }
    7680             :         ;
    7681             : 
    7682             : 
    7683             : /*
    7684             :  * Privilege names are represented as strings; the validity of the privilege
    7685             :  * names gets checked at execution.  This is a bit annoying but we have little
    7686             :  * choice because of the syntactic conflict with lists of role names in
    7687             :  * GRANT/REVOKE.  What's more, we have to call out in the "privilege"
    7688             :  * production any reserved keywords that need to be usable as privilege names.
    7689             :  */
    7690             : 
    7691             : /* either ALL [PRIVILEGES] or a list of individual privileges */
    7692             : privileges: privilege_list
    7693       13422 :                 { $$ = $1; }
    7694             :             | ALL
    7695        1994 :                 { $$ = NIL; }
    7696             :             | ALL PRIVILEGES
    7697         120 :                 { $$ = NIL; }
    7698             :             | ALL '(' columnList ')'
    7699             :                 {
    7700          18 :                     AccessPriv *n = makeNode(AccessPriv);
    7701             : 
    7702          18 :                     n->priv_name = NULL;
    7703          18 :                     n->cols = $3;
    7704          18 :                     $$ = list_make1(n);
    7705             :                 }
    7706             :             | ALL PRIVILEGES '(' columnList ')'
    7707             :                 {
    7708           0 :                     AccessPriv *n = makeNode(AccessPriv);
    7709             : 
    7710           0 :                     n->priv_name = NULL;
    7711           0 :                     n->cols = $4;
    7712           0 :                     $$ = list_make1(n);
    7713             :                 }
    7714             :         ;
    7715             : 
    7716       14314 : privilege_list: privilege                           { $$ = list_make1($1); }
    7717         444 :             | privilege_list ',' privilege          { $$ = lappend($1, $3); }
    7718             :         ;
    7719             : 
    7720             : privilege:  SELECT opt_column_list
    7721             :             {
    7722        5926 :                 AccessPriv *n = makeNode(AccessPriv);
    7723             : 
    7724        5926 :                 n->priv_name = pstrdup($1);
    7725        5926 :                 n->cols = $2;
    7726        5926 :                 $$ = n;
    7727             :             }
    7728             :         | REFERENCES opt_column_list
    7729             :             {
    7730          14 :                 AccessPriv *n = makeNode(AccessPriv);
    7731             : 
    7732          14 :                 n->priv_name = pstrdup($1);
    7733          14 :                 n->cols = $2;
    7734          14 :                 $$ = n;
    7735             :             }
    7736             :         | CREATE opt_column_list
    7737             :             {
    7738         250 :                 AccessPriv *n = makeNode(AccessPriv);
    7739             : 
    7740         250 :                 n->priv_name = pstrdup($1);
    7741         250 :                 n->cols = $2;
    7742         250 :                 $$ = n;
    7743             :             }
    7744             :         | ALTER SYSTEM_P
    7745             :             {
    7746          24 :                 AccessPriv *n = makeNode(AccessPriv);
    7747          24 :                 n->priv_name = pstrdup("alter system");
    7748          24 :                 n->cols = NIL;
    7749          24 :                 $$ = n;
    7750             :             }
    7751             :         | ColId opt_column_list
    7752             :             {
    7753        8544 :                 AccessPriv *n = makeNode(AccessPriv);
    7754             : 
    7755        8544 :                 n->priv_name = $1;
    7756        8544 :                 n->cols = $2;
    7757        8544 :                 $$ = n;
    7758             :             }
    7759             :         ;
    7760             : 
    7761             : parameter_name_list:
    7762             :         parameter_name
    7763             :             {
    7764          74 :                 $$ = list_make1(makeString($1));
    7765             :             }
    7766             :         | parameter_name_list ',' parameter_name
    7767             :             {
    7768          50 :                 $$ = lappend($1, makeString($3));
    7769             :             }
    7770             :         ;
    7771             : 
    7772             : parameter_name:
    7773             :         ColId
    7774             :             {
    7775         124 :                 $$ = $1;
    7776             :             }
    7777             :         | parameter_name '.' ColId
    7778             :             {
    7779          30 :                 $$ = psprintf("%s.%s", $1, $3);
    7780             :             }
    7781             :         ;
    7782             : 
    7783             : 
    7784             : /* Don't bother trying to fold the first two rules into one using
    7785             :  * opt_table.  You're going to get conflicts.
    7786             :  */
    7787             : privilege_target:
    7788             :             qualified_name_list
    7789             :                 {
    7790        7460 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7791             : 
    7792        7460 :                     n->targtype = ACL_TARGET_OBJECT;
    7793        7460 :                     n->objtype = OBJECT_TABLE;
    7794        7460 :                     n->objs = $1;
    7795        7460 :                     $$ = n;
    7796             :                 }
    7797             :             | TABLE qualified_name_list
    7798             :                 {
    7799         324 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7800             : 
    7801         324 :                     n->targtype = ACL_TARGET_OBJECT;
    7802         324 :                     n->objtype = OBJECT_TABLE;
    7803         324 :                     n->objs = $2;
    7804         324 :                     $$ = n;
    7805             :                 }
    7806             :             | SEQUENCE qualified_name_list
    7807             :                 {
    7808          16 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7809             : 
    7810          16 :                     n->targtype = ACL_TARGET_OBJECT;
    7811          16 :                     n->objtype = OBJECT_SEQUENCE;
    7812          16 :                     n->objs = $2;
    7813          16 :                     $$ = n;
    7814             :                 }
    7815             :             | FOREIGN DATA_P WRAPPER name_list
    7816             :                 {
    7817          92 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7818             : 
    7819          92 :                     n->targtype = ACL_TARGET_OBJECT;
    7820          92 :                     n->objtype = OBJECT_FDW;
    7821          92 :                     n->objs = $4;
    7822          92 :                     $$ = n;
    7823             :                 }
    7824             :             | FOREIGN SERVER name_list
    7825             :                 {
    7826          76 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7827             : 
    7828          76 :                     n->targtype = ACL_TARGET_OBJECT;
    7829          76 :                     n->objtype = OBJECT_FOREIGN_SERVER;
    7830          76 :                     n->objs = $3;
    7831          76 :                     $$ = n;
    7832             :                 }
    7833             :             | FUNCTION function_with_argtypes_list
    7834             :                 {
    7835        6462 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7836             : 
    7837        6462 :                     n->targtype = ACL_TARGET_OBJECT;
    7838        6462 :                     n->objtype = OBJECT_FUNCTION;
    7839        6462 :                     n->objs = $2;
    7840        6462 :                     $$ = n;
    7841             :                 }
    7842             :             | PROCEDURE function_with_argtypes_list
    7843             :                 {
    7844          42 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7845             : 
    7846          42 :                     n->targtype = ACL_TARGET_OBJECT;
    7847          42 :                     n->objtype = OBJECT_PROCEDURE;
    7848          42 :                     n->objs = $2;
    7849          42 :                     $$ = n;
    7850             :                 }
    7851             :             | ROUTINE function_with_argtypes_list
    7852             :                 {
    7853           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7854             : 
    7855           0 :                     n->targtype = ACL_TARGET_OBJECT;
    7856           0 :                     n->objtype = OBJECT_ROUTINE;
    7857           0 :                     n->objs = $2;
    7858           0 :                     $$ = n;
    7859             :                 }
    7860             :             | DATABASE name_list
    7861             :                 {
    7862         274 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7863             : 
    7864         274 :                     n->targtype = ACL_TARGET_OBJECT;
    7865         274 :                     n->objtype = OBJECT_DATABASE;
    7866         274 :                     n->objs = $2;
    7867         274 :                     $$ = n;
    7868             :                 }
    7869             :             | DOMAIN_P any_name_list
    7870             :                 {
    7871          26 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7872             : 
    7873          26 :                     n->targtype = ACL_TARGET_OBJECT;
    7874          26 :                     n->objtype = OBJECT_DOMAIN;
    7875          26 :                     n->objs = $2;
    7876          26 :                     $$ = n;
    7877             :                 }
    7878             :             | LANGUAGE name_list
    7879             :                 {
    7880          42 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7881             : 
    7882          42 :                     n->targtype = ACL_TARGET_OBJECT;
    7883          42 :                     n->objtype = OBJECT_LANGUAGE;
    7884          42 :                     n->objs = $2;
    7885          42 :                     $$ = n;
    7886             :                 }
    7887             :             | LARGE_P OBJECT_P NumericOnly_list
    7888             :                 {
    7889          80 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7890             : 
    7891          80 :                     n->targtype = ACL_TARGET_OBJECT;
    7892          80 :                     n->objtype = OBJECT_LARGEOBJECT;
    7893          80 :                     n->objs = $3;
    7894          80 :                     $$ = n;
    7895             :                 }
    7896             :             | PARAMETER parameter_name_list
    7897             :                 {
    7898          74 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7899          74 :                     n->targtype = ACL_TARGET_OBJECT;
    7900          74 :                     n->objtype = OBJECT_PARAMETER_ACL;
    7901          74 :                     n->objs = $2;
    7902          74 :                     $$ = n;
    7903             :                 }
    7904             :             | SCHEMA name_list
    7905             :                 {
    7906         286 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7907             : 
    7908         286 :                     n->targtype = ACL_TARGET_OBJECT;
    7909         286 :                     n->objtype = OBJECT_SCHEMA;
    7910         286 :                     n->objs = $2;
    7911         286 :                     $$ = n;
    7912             :                 }
    7913             :             | TABLESPACE name_list
    7914             :                 {
    7915           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7916             : 
    7917           0 :                     n->targtype = ACL_TARGET_OBJECT;
    7918           0 :                     n->objtype = OBJECT_TABLESPACE;
    7919           0 :                     n->objs = $2;
    7920           0 :                     $$ = n;
    7921             :                 }
    7922             :             | TYPE_P any_name_list
    7923             :                 {
    7924         110 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7925             : 
    7926         110 :                     n->targtype = ACL_TARGET_OBJECT;
    7927         110 :                     n->objtype = OBJECT_TYPE;
    7928         110 :                     n->objs = $2;
    7929         110 :                     $$ = n;
    7930             :                 }
    7931             :             | ALL TABLES IN_P SCHEMA name_list
    7932             :                 {
    7933          12 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7934             : 
    7935          12 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7936          12 :                     n->objtype = OBJECT_TABLE;
    7937          12 :                     n->objs = $5;
    7938          12 :                     $$ = n;
    7939             :                 }
    7940             :             | ALL SEQUENCES IN_P SCHEMA name_list
    7941             :                 {
    7942           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7943             : 
    7944           0 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7945           0 :                     n->objtype = OBJECT_SEQUENCE;
    7946           0 :                     n->objs = $5;
    7947           0 :                     $$ = n;
    7948             :                 }
    7949             :             | ALL FUNCTIONS IN_P SCHEMA name_list
    7950             :                 {
    7951           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7952             : 
    7953           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7954           6 :                     n->objtype = OBJECT_FUNCTION;
    7955           6 :                     n->objs = $5;
    7956           6 :                     $$ = n;
    7957             :                 }
    7958             :             | ALL PROCEDURES IN_P SCHEMA name_list
    7959             :                 {
    7960           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7961             : 
    7962           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7963           6 :                     n->objtype = OBJECT_PROCEDURE;
    7964           6 :                     n->objs = $5;
    7965           6 :                     $$ = n;
    7966             :                 }
    7967             :             | ALL ROUTINES IN_P SCHEMA name_list
    7968             :                 {
    7969           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7970             : 
    7971           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7972           6 :                     n->objtype = OBJECT_ROUTINE;
    7973           6 :                     n->objs = $5;
    7974           6 :                     $$ = n;
    7975             :                 }
    7976             :         ;
    7977             : 
    7978             : 
    7979             : grantee_list:
    7980       15542 :             grantee                                 { $$ = list_make1($1); }
    7981         102 :             | grantee_list ',' grantee              { $$ = lappend($1, $3); }
    7982             :         ;
    7983             : 
    7984             : grantee:
    7985       15620 :             RoleSpec                                { $$ = $1; }
    7986          24 :             | GROUP_P RoleSpec                      { $$ = $2; }
    7987             :         ;
    7988             : 
    7989             : 
    7990             : opt_grant_grant_option:
    7991          86 :             WITH GRANT OPTION { $$ = true; }
    7992        8308 :             | /*EMPTY*/ { $$ = false; }
    7993             :         ;
    7994             : 
    7995             : /*****************************************************************************
    7996             :  *
    7997             :  * GRANT and REVOKE ROLE statements
    7998             :  *
    7999             :  *****************************************************************************/
    8000             : 
    8001             : GrantRoleStmt:
    8002             :             GRANT privilege_list TO role_list opt_granted_by
    8003             :                 {
    8004         558 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8005             : 
    8006         558 :                     n->is_grant = true;
    8007         558 :                     n->granted_roles = $2;
    8008         558 :                     n->grantee_roles = $4;
    8009         558 :                     n->opt = NIL;
    8010         558 :                     n->grantor = $5;
    8011         558 :                     $$ = (Node *) n;
    8012             :                 }
    8013             :           | GRANT privilege_list TO role_list WITH grant_role_opt_list opt_granted_by
    8014             :                 {
    8015         178 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8016             : 
    8017         178 :                     n->is_grant = true;
    8018         178 :                     n->granted_roles = $2;
    8019         178 :                     n->grantee_roles = $4;
    8020         178 :                     n->opt = $6;
    8021         178 :                     n->grantor = $7;
    8022         178 :                     $$ = (Node *) n;
    8023             :                 }
    8024             :         ;
    8025             : 
    8026             : RevokeRoleStmt:
    8027             :             REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
    8028             :                 {
    8029          90 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8030             : 
    8031          90 :                     n->is_grant = false;
    8032          90 :                     n->opt = NIL;
    8033          90 :                     n->granted_roles = $2;
    8034          90 :                     n->grantee_roles = $4;
    8035          90 :                     n->grantor = $5;
    8036          90 :                     n->behavior = $6;
    8037          90 :                     $$ = (Node *) n;
    8038             :                 }
    8039             :             | REVOKE ColId OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
    8040             :                 {
    8041          66 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8042             :                     DefElem *opt;
    8043             : 
    8044          66 :                     opt = makeDefElem(pstrdup($2),
    8045          66 :                                       (Node *) makeBoolean(false), @2);
    8046          66 :                     n->is_grant = false;
    8047          66 :                     n->opt = list_make1(opt);
    8048          66 :                     n->granted_roles = $5;
    8049          66 :                     n->grantee_roles = $7;
    8050          66 :                     n->grantor = $8;
    8051          66 :                     n->behavior = $9;
    8052          66 :                     $$ = (Node *) n;
    8053             :                 }
    8054             :         ;
    8055             : 
    8056             : grant_role_opt_list:
    8057         120 :             grant_role_opt_list ',' grant_role_opt  { $$ = lappend($1, $3); }
    8058         178 :             | grant_role_opt                        { $$ = list_make1($1); }
    8059             :         ;
    8060             : 
    8061             : grant_role_opt:
    8062             :         ColLabel grant_role_opt_value
    8063             :             {
    8064         298 :                 $$ = makeDefElem(pstrdup($1), $2, @1);
    8065             :             }
    8066             :         ;
    8067             : 
    8068             : grant_role_opt_value:
    8069          72 :         OPTION          { $$ = (Node *) makeBoolean(true); }
    8070         112 :         | TRUE_P        { $$ = (Node *) makeBoolean(true); }
    8071         114 :         | FALSE_P       { $$ = (Node *) makeBoolean(false); }
    8072             :         ;
    8073             : 
    8074         138 : opt_granted_by: GRANTED BY RoleSpec                     { $$ = $3; }
    8075       16136 :             | /*EMPTY*/                                 { $$ = NULL; }
    8076             :         ;
    8077             : 
    8078             : /*****************************************************************************
    8079             :  *
    8080             :  * ALTER DEFAULT PRIVILEGES statement
    8081             :  *
    8082             :  *****************************************************************************/
    8083             : 
    8084             : AlterDefaultPrivilegesStmt:
    8085             :             ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
    8086             :                 {
    8087         160 :                     AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
    8088             : 
    8089         160 :                     n->options = $4;
    8090         160 :                     n->action = (GrantStmt *) $5;
    8091         160 :                     $$ = (Node *) n;
    8092             :                 }
    8093             :         ;
    8094             : 
    8095             : DefACLOptionList:
    8096         122 :             DefACLOptionList DefACLOption           { $$ = lappend($1, $2); }
    8097         160 :             | /* EMPTY */                           { $$ = NIL; }
    8098             :         ;
    8099             : 
    8100             : DefACLOption:
    8101             :             IN_P SCHEMA name_list
    8102             :                 {
    8103          54 :                     $$ = makeDefElem("schemas", (Node *) $3, @1);
    8104             :                 }
    8105             :             | FOR ROLE role_list
    8106             :                 {
    8107          68 :                     $$ = makeDefElem("roles", (Node *) $3, @1);
    8108             :                 }
    8109             :             | FOR USER role_list
    8110             :                 {
    8111           0 :                     $$ = makeDefElem("roles", (Node *) $3, @1);
    8112             :                 }
    8113             :         ;
    8114             : 
    8115             : /*
    8116             :  * This should match GRANT/REVOKE, except that individual target objects
    8117             :  * are not mentioned and we only allow a subset of object types.
    8118             :  */
    8119             : DefACLAction:
    8120             :             GRANT privileges ON defacl_privilege_target TO grantee_list
    8121             :             opt_grant_grant_option
    8122             :                 {
    8123         100 :                     GrantStmt *n = makeNode(GrantStmt);
    8124             : 
    8125         100 :                     n->is_grant = true;
    8126         100 :                     n->privileges = $2;
    8127         100 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8128         100 :                     n->objtype = $4;
    8129         100 :                     n->objects = NIL;
    8130         100 :                     n->grantees = $6;
    8131         100 :                     n->grant_option = $7;
    8132         100 :                     $$ = (Node *) n;
    8133             :                 }
    8134             :             | REVOKE privileges ON defacl_privilege_target
    8135             :             FROM grantee_list opt_drop_behavior
    8136             :                 {
    8137          60 :                     GrantStmt *n = makeNode(GrantStmt);
    8138             : 
    8139          60 :                     n->is_grant = false;
    8140          60 :                     n->grant_option = false;
    8141          60 :                     n->privileges = $2;
    8142          60 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8143          60 :                     n->objtype = $4;
    8144          60 :                     n->objects = NIL;
    8145          60 :                     n->grantees = $6;
    8146          60 :                     n->behavior = $7;
    8147          60 :                     $$ = (Node *) n;
    8148             :                 }
    8149             :             | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
    8150             :             FROM grantee_list opt_drop_behavior
    8151             :                 {
    8152           0 :                     GrantStmt *n = makeNode(GrantStmt);
    8153             : 
    8154           0 :                     n->is_grant = false;
    8155           0 :                     n->grant_option = true;
    8156           0 :                     n->privileges = $5;
    8157           0 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8158           0 :                     n->objtype = $7;
    8159           0 :                     n->objects = NIL;
    8160           0 :                     n->grantees = $9;
    8161           0 :                     n->behavior = $10;
    8162           0 :                     $$ = (Node *) n;
    8163             :                 }
    8164             :         ;
    8165             : 
    8166             : defacl_privilege_target:
    8167          78 :             TABLES          { $$ = OBJECT_TABLE; }
    8168          16 :             | FUNCTIONS     { $$ = OBJECT_FUNCTION; }
    8169           6 :             | ROUTINES      { $$ = OBJECT_FUNCTION; }
    8170           6 :             | SEQUENCES     { $$ = OBJECT_SEQUENCE; }
    8171          18 :             | TYPES_P       { $$ = OBJECT_TYPE; }
    8172          36 :             | SCHEMAS       { $$ = OBJECT_SCHEMA; }
    8173             :         ;
    8174             : 
    8175             : 
    8176             : /*****************************************************************************
    8177             :  *
    8178             :  *      QUERY: CREATE INDEX
    8179             :  *
    8180             :  * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
    8181             :  * willing to make TABLESPACE a fully reserved word.
    8182             :  *****************************************************************************/
    8183             : 
    8184             : IndexStmt:  CREATE opt_unique INDEX opt_concurrently opt_single_name
    8185             :             ON relation_expr access_method_clause '(' index_params ')'
    8186             :             opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
    8187             :                 {
    8188        6266 :                     IndexStmt *n = makeNode(IndexStmt);
    8189             : 
    8190        6266 :                     n->unique = $2;
    8191        6266 :                     n->concurrent = $4;
    8192        6266 :                     n->idxname = $5;
    8193        6266 :                     n->relation = $7;
    8194        6266 :                     n->accessMethod = $8;
    8195        6266 :                     n->indexParams = $10;
    8196        6266 :                     n->indexIncludingParams = $12;
    8197        6266 :                     n->nulls_not_distinct = !$13;
    8198        6266 :                     n->options = $14;
    8199        6266 :                     n->tableSpace = $15;
    8200        6266 :                     n->whereClause = $16;
    8201        6266 :                     n->excludeOpNames = NIL;
    8202        6266 :                     n->idxcomment = NULL;
    8203        6266 :                     n->indexOid = InvalidOid;
    8204        6266 :                     n->oldNumber = InvalidRelFileNumber;
    8205        6266 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8206        6266 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8207        6266 :                     n->primary = false;
    8208        6266 :                     n->isconstraint = false;
    8209        6266 :                     n->deferrable = false;
    8210        6266 :                     n->initdeferred = false;
    8211        6266 :                     n->transformed = false;
    8212        6266 :                     n->if_not_exists = false;
    8213        6266 :                     n->reset_default_tblspc = false;
    8214        6266 :                     $$ = (Node *) n;
    8215             :                 }
    8216             :             | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS name
    8217             :             ON relation_expr access_method_clause '(' index_params ')'
    8218             :             opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
    8219             :                 {
    8220          18 :                     IndexStmt *n = makeNode(IndexStmt);
    8221             : 
    8222          18 :                     n->unique = $2;
    8223          18 :                     n->concurrent = $4;
    8224          18 :                     n->idxname = $8;
    8225          18 :                     n->relation = $10;
    8226          18 :                     n->accessMethod = $11;
    8227          18 :                     n->indexParams = $13;
    8228          18 :                     n->indexIncludingParams = $15;
    8229          18 :                     n->nulls_not_distinct = !$16;
    8230          18 :                     n->options = $17;
    8231          18 :                     n->tableSpace = $18;
    8232          18 :                     n->whereClause = $19;
    8233          18 :                     n->excludeOpNames = NIL;
    8234          18 :                     n->idxcomment = NULL;
    8235          18 :                     n->indexOid = InvalidOid;
    8236          18 :                     n->oldNumber = InvalidRelFileNumber;
    8237          18 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8238          18 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8239          18 :                     n->primary = false;
    8240          18 :                     n->isconstraint = false;
    8241          18 :                     n->deferrable = false;
    8242          18 :                     n->initdeferred = false;
    8243          18 :                     n->transformed = false;
    8244          18 :                     n->if_not_exists = true;
    8245          18 :                     n->reset_default_tblspc = false;
    8246          18 :                     $$ = (Node *) n;
    8247             :                 }
    8248             :         ;
    8249             : 
    8250             : opt_unique:
    8251        1172 :             UNIQUE                                  { $$ = true; }
    8252        5118 :             | /*EMPTY*/                             { $$ = false; }
    8253             :         ;
    8254             : 
    8255             : access_method_clause:
    8256        2932 :             USING name                              { $$ = $2; }
    8257        3586 :             | /*EMPTY*/                             { $$ = DEFAULT_INDEX_TYPE; }
    8258             :         ;
    8259             : 
    8260        7546 : index_params:   index_elem                          { $$ = list_make1($1); }
    8261        1920 :             | index_params ',' index_elem           { $$ = lappend($1, $3); }
    8262             :         ;
    8263             : 
    8264             : 
    8265             : index_elem_options:
    8266             :     opt_collate opt_qualified_name opt_asc_desc opt_nulls_order
    8267             :         {
    8268       10052 :             $$ = makeNode(IndexElem);
    8269       10052 :             $$->name = NULL;
    8270       10052 :             $$->expr = NULL;
    8271       10052 :             $$->indexcolname = NULL;
    8272       10052 :             $$->collation = $1;
    8273       10052 :             $$->opclass = $2;
    8274       10052 :             $$->opclassopts = NIL;
    8275       10052 :             $$->ordering = $3;
    8276       10052 :             $$->nulls_ordering = $4;
    8277             :         }
    8278             :     | opt_collate any_name reloptions opt_asc_desc opt_nulls_order
    8279             :         {
    8280         138 :             $$ = makeNode(IndexElem);
    8281         138 :             $$->name = NULL;
    8282         138 :             $$->expr = NULL;
    8283         138 :             $$->indexcolname = NULL;
    8284         138 :             $$->collation = $1;
    8285         138 :             $$->opclass = $2;
    8286         138 :             $$->opclassopts = $3;
    8287         138 :             $$->ordering = $4;
    8288         138 :             $$->nulls_ordering = $5;
    8289             :         }
    8290             :     ;
    8291             : 
    8292             : /*
    8293             :  * Index attributes can be either simple column references, or arbitrary
    8294             :  * expressions in parens.  For backwards-compatibility reasons, we allow
    8295             :  * an expression that's just a function call to be written without parens.
    8296             :  */
    8297             : index_elem: ColId index_elem_options
    8298             :                 {
    8299        9172 :                     $$ = $2;
    8300        9172 :                     $$->name = $1;
    8301             :                 }
    8302             :             | func_expr_windowless index_elem_options
    8303             :                 {
    8304         568 :                     $$ = $2;
    8305         568 :                     $$->expr = $1;
    8306             :                 }
    8307             :             | '(' a_expr ')' index_elem_options
    8308             :                 {
    8309         450 :                     $$ = $4;
    8310         450 :                     $$->expr = $2;
    8311             :                 }
    8312             :         ;
    8313             : 
    8314         218 : opt_include:        INCLUDE '(' index_including_params ')'          { $$ = $3; }
    8315        6066 :              |      /* EMPTY */                     { $$ = NIL; }
    8316             :         ;
    8317             : 
    8318         218 : index_including_params: index_elem                      { $$ = list_make1($1); }
    8319         166 :             | index_including_params ',' index_elem     { $$ = lappend($1, $3); }
    8320             :         ;
    8321             : 
    8322         166 : opt_collate: COLLATE any_name                       { $$ = $2; }
    8323       15434 :             | /*EMPTY*/                             { $$ = NIL; }
    8324             :         ;
    8325             : 
    8326             : 
    8327        1736 : opt_asc_desc: ASC                           { $$ = SORTBY_ASC; }
    8328        2756 :             | DESC                          { $$ = SORTBY_DESC; }
    8329       92676 :             | /*EMPTY*/                     { $$ = SORTBY_DEFAULT; }
    8330             :         ;
    8331             : 
    8332         286 : opt_nulls_order: NULLS_LA FIRST_P           { $$ = SORTBY_NULLS_FIRST; }
    8333        1686 :             | NULLS_LA LAST_P               { $$ = SORTBY_NULLS_LAST; }
    8334       95416 :             | /*EMPTY*/                     { $$ = SORTBY_NULLS_DEFAULT; }
    8335             :         ;
    8336             : 
    8337             : 
    8338             : /*****************************************************************************
    8339             :  *
    8340             :  *      QUERY:
    8341             :  *              create [or replace] function <fname>
    8342             :  *                      [(<type-1> { , <type-n>})]
    8343             :  *                      returns <type-r>
    8344             :  *                      as <filename or code in language as appropriate>
    8345             :  *                      language <lang> [with parameters]
    8346             :  *
    8347             :  *****************************************************************************/
    8348             : 
    8349             : CreateFunctionStmt:
    8350             :             CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8351             :             RETURNS func_return opt_createfunc_opt_list opt_routine_body
    8352             :                 {
    8353       19498 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8354             : 
    8355       19498 :                     n->is_procedure = false;
    8356       19498 :                     n->replace = $2;
    8357       19498 :                     n->funcname = $4;
    8358       19498 :                     n->parameters = $5;
    8359       19498 :                     n->returnType = $7;
    8360       19498 :                     n->options = $8;
    8361       19498 :                     n->sql_body = $9;
    8362       19498 :                     $$ = (Node *) n;
    8363             :                 }
    8364             :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8365             :               RETURNS TABLE '(' table_func_column_list ')' opt_createfunc_opt_list opt_routine_body
    8366             :                 {
    8367         188 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8368             : 
    8369         188 :                     n->is_procedure = false;
    8370         188 :                     n->replace = $2;
    8371         188 :                     n->funcname = $4;
    8372         188 :                     n->parameters = mergeTableFuncParameters($5, $9);
    8373         188 :                     n->returnType = TableFuncTypeName($9);
    8374         188 :                     n->returnType->location = @7;
    8375         188 :                     n->options = $11;
    8376         188 :                     n->sql_body = $12;
    8377         188 :                     $$ = (Node *) n;
    8378             :                 }
    8379             :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8380             :               opt_createfunc_opt_list opt_routine_body
    8381             :                 {
    8382         472 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8383             : 
    8384         472 :                     n->is_procedure = false;
    8385         472 :                     n->replace = $2;
    8386         472 :                     n->funcname = $4;
    8387         472 :                     n->parameters = $5;
    8388         472 :                     n->returnType = NULL;
    8389         472 :                     n->options = $6;
    8390         472 :                     n->sql_body = $7;
    8391         472 :                     $$ = (Node *) n;
    8392             :                 }
    8393             :             | CREATE opt_or_replace PROCEDURE func_name func_args_with_defaults
    8394             :               opt_createfunc_opt_list opt_routine_body
    8395             :                 {
    8396         330 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8397             : 
    8398         330 :                     n->is_procedure = true;
    8399         330 :                     n->replace = $2;
    8400         330 :                     n->funcname = $4;
    8401         330 :                     n->parameters = $5;
    8402         330 :                     n->returnType = NULL;
    8403         330 :                     n->options = $6;
    8404         330 :                     n->sql_body = $7;
    8405         330 :                     $$ = (Node *) n;
    8406             :                 }
    8407             :         ;
    8408             : 
    8409             : opt_or_replace:
    8410        7960 :             OR REPLACE                              { $$ = true; }
    8411       17780 :             | /*EMPTY*/                             { $$ = false; }
    8412             :         ;
    8413             : 
    8414        8738 : func_args:  '(' func_args_list ')'                  { $$ = $2; }
    8415        4372 :             | '(' ')'                               { $$ = NIL; }
    8416             :         ;
    8417             : 
    8418             : func_args_list:
    8419        8738 :             func_arg                                { $$ = list_make1($1); }
    8420        7478 :             | func_args_list ',' func_arg           { $$ = lappend($1, $3); }
    8421             :         ;
    8422             : 
    8423             : function_with_argtypes_list:
    8424       10038 :             function_with_argtypes                  { $$ = list_make1($1); }
    8425             :             | function_with_argtypes_list ',' function_with_argtypes
    8426          72 :                                                     { $$ = lappend($1, $3); }
    8427             :         ;
    8428             : 
    8429             : function_with_argtypes:
    8430             :             func_name func_args
    8431             :                 {
    8432       13110 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8433             : 
    8434       13110 :                     n->objname = $1;
    8435       13110 :                     n->objargs = extractArgTypes($2);
    8436       13110 :                     n->objfuncargs = $2;
    8437       13110 :                     $$ = n;
    8438             :                 }
    8439             :             /*
    8440             :              * Because of reduce/reduce conflicts, we can't use func_name
    8441             :              * below, but we can write it out the long way, which actually
    8442             :              * allows more cases.
    8443             :              */
    8444             :             | type_func_name_keyword
    8445             :                 {
    8446           0 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8447             : 
    8448           0 :                     n->objname = list_make1(makeString(pstrdup($1)));
    8449           0 :                     n->args_unspecified = true;
    8450           0 :                     $$ = n;
    8451             :                 }
    8452             :             | ColId
    8453             :                 {
    8454         302 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8455             : 
    8456         302 :                     n->objname = list_make1(makeString($1));
    8457         302 :                     n->args_unspecified = true;
    8458         302 :                     $$ = n;
    8459             :                 }
    8460             :             | ColId indirection
    8461             :                 {
    8462          28 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8463             : 
    8464          28 :                     n->objname = check_func_name(lcons(makeString($1), $2),
    8465             :                                                   yyscanner);
    8466          28 :                     n->args_unspecified = true;
    8467          28 :                     $$ = n;
    8468             :                 }
    8469             :         ;
    8470             : 
    8471             : /*
    8472             :  * func_args_with_defaults is separate because we only want to accept
    8473             :  * defaults in CREATE FUNCTION, not in ALTER etc.
    8474             :  */
    8475             : func_args_with_defaults:
    8476       16422 :         '(' func_args_with_defaults_list ')'        { $$ = $2; }
    8477        4066 :         | '(' ')'                                   { $$ = NIL; }
    8478             :         ;
    8479             : 
    8480             : func_args_with_defaults_list:
    8481       16422 :         func_arg_with_default                       { $$ = list_make1($1); }
    8482             :         | func_args_with_defaults_list ',' func_arg_with_default
    8483       27068 :                                                     { $$ = lappend($1, $3); }
    8484             :         ;
    8485             : 
    8486             : /*
    8487             :  * The style with arg_class first is SQL99 standard, but Oracle puts
    8488             :  * param_name first; accept both since it's likely people will try both
    8489             :  * anyway.  Don't bother trying to save productions by letting arg_class
    8490             :  * have an empty alternative ... you'll get shift/reduce conflicts.
    8491             :  *
    8492             :  * We can catch over-specified arguments here if we want to,
    8493             :  * but for now better to silently swallow typmod, etc.
    8494             :  * - thomas 2000-03-22
    8495             :  */
    8496             : func_arg:
    8497             :             arg_class param_name func_type
    8498             :                 {
    8499       12376 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8500             : 
    8501       12376 :                     n->name = $2;
    8502       12376 :                     n->argType = $3;
    8503       12376 :                     n->mode = $1;
    8504       12376 :                     n->defexpr = NULL;
    8505       12376 :                     $$ = n;
    8506             :                 }
    8507             :             | param_name arg_class func_type
    8508             :                 {
    8509         380 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8510             : 
    8511         380 :                     n->name = $1;
    8512         380 :                     n->argType = $3;
    8513         380 :                     n->mode = $2;
    8514         380 :                     n->defexpr = NULL;
    8515         380 :                     $$ = n;
    8516             :                 }
    8517             :             | param_name func_type
    8518             :                 {
    8519       12448 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8520             : 
    8521       12448 :                     n->name = $1;
    8522       12448 :                     n->argType = $2;
    8523       12448 :                     n->mode = FUNC_PARAM_DEFAULT;
    8524       12448 :                     n->defexpr = NULL;
    8525       12448 :                     $$ = n;
    8526             :                 }
    8527             :             | arg_class func_type
    8528             :                 {
    8529         304 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8530             : 
    8531         304 :                     n->name = NULL;
    8532         304 :                     n->argType = $2;
    8533         304 :                     n->mode = $1;
    8534         304 :                     n->defexpr = NULL;
    8535         304 :                     $$ = n;
    8536             :                 }
    8537             :             | func_type
    8538             :                 {
    8539       35096 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8540             : 
    8541       35096 :                     n->name = NULL;
    8542       35096 :                     n->argType = $1;
    8543       35096 :                     n->mode = FUNC_PARAM_DEFAULT;
    8544       35096 :                     n->defexpr = NULL;
    8545       35096 :                     $$ = n;
    8546             :                 }
    8547             :         ;
    8548             : 
    8549             : /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
    8550        2842 : arg_class:  IN_P                                { $$ = FUNC_PARAM_IN; }
    8551        9566 :             | OUT_P                             { $$ = FUNC_PARAM_OUT; }
    8552         166 :             | INOUT                             { $$ = FUNC_PARAM_INOUT; }
    8553           0 :             | IN_P OUT_P                        { $$ = FUNC_PARAM_INOUT; }
    8554         486 :             | VARIADIC                          { $$ = FUNC_PARAM_VARIADIC; }
    8555             :         ;
    8556             : 
    8557             : /*
    8558             :  * Ideally param_name should be ColId, but that causes too many conflicts.
    8559             :  */
    8560             : param_name: type_function_name
    8561             :         ;
    8562             : 
    8563             : func_return:
    8564             :             func_type
    8565             :                 {
    8566             :                     /* We can catch over-specified results here if we want to,
    8567             :                      * but for now better to silently swallow typmod, etc.
    8568             :                      * - thomas 2000-03-22
    8569             :                      */
    8570       19498 :                     $$ = $1;
    8571             :                 }
    8572             :         ;
    8573             : 
    8574             : /*
    8575             :  * We would like to make the %TYPE productions here be ColId attrs etc,
    8576             :  * but that causes reduce/reduce conflicts.  type_function_name
    8577             :  * is next best choice.
    8578             :  */
    8579       99184 : func_type:  Typename                                { $$ = $1; }
    8580             :             | type_function_name attrs '%' TYPE_P
    8581             :                 {
    8582          18 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
    8583          18 :                     $$->pct_type = true;
    8584          18 :                     $$->location = @1;
    8585             :                 }
    8586             :             | SETOF type_function_name attrs '%' TYPE_P
    8587             :                 {
    8588           6 :                     $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
    8589           6 :                     $$->pct_type = true;
    8590           6 :                     $$->setof = true;
    8591           6 :                     $$->location = @2;
    8592             :                 }
    8593             :         ;
    8594             : 
    8595             : func_arg_with_default:
    8596             :         func_arg
    8597             :                 {
    8598       38604 :                     $$ = $1;
    8599             :                 }
    8600             :         | func_arg DEFAULT a_expr
    8601             :                 {
    8602        4690 :                     $$ = $1;
    8603        4690 :                     $$->defexpr = $3;
    8604             :                 }
    8605             :         | func_arg '=' a_expr
    8606             :                 {
    8607         196 :                     $$ = $1;
    8608         196 :                     $$->defexpr = $3;
    8609             :                 }
    8610             :         ;
    8611             : 
    8612             : /* Aggregate args can be most things that function args can be */
    8613             : aggr_arg:   func_arg
    8614             :                 {
    8615         898 :                     if (!($1->mode == FUNC_PARAM_DEFAULT ||
    8616          60 :                           $1->mode == FUNC_PARAM_IN ||
    8617          60 :                           $1->mode == FUNC_PARAM_VARIADIC))
    8618           0 :                         ereport(ERROR,
    8619             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    8620             :                                  errmsg("aggregates cannot have output arguments"),
    8621             :                                  parser_errposition(@1)));
    8622         898 :                     $$ = $1;
    8623             :                 }
    8624             :         ;
    8625             : 
    8626             : /*
    8627             :  * The SQL standard offers no guidance on how to declare aggregate argument
    8628             :  * lists, since it doesn't have CREATE AGGREGATE etc.  We accept these cases:
    8629             :  *
    8630             :  * (*)                                  - normal agg with no args
    8631             :  * (aggr_arg,...)                       - normal agg with args
    8632             :  * (ORDER BY aggr_arg,...)              - ordered-set agg with no direct args
    8633             :  * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
    8634             :  *
    8635             :  * The zero-argument case is spelled with '*' for consistency with COUNT(*).
    8636             :  *
    8637             :  * An additional restriction is that if the direct-args list ends in a
    8638             :  * VARIADIC item, the ordered-args list must contain exactly one item that
    8639             :  * is also VARIADIC with the same type.  This allows us to collapse the two
    8640             :  * VARIADIC items into one, which is necessary to represent the aggregate in
    8641             :  * pg_proc.  We check this at the grammar stage so that we can return a list
    8642             :  * in which the second VARIADIC item is already discarded, avoiding extra work
    8643             :  * in cases such as DROP AGGREGATE.
    8644             :  *
    8645             :  * The return value of this production is a two-element list, in which the
    8646             :  * first item is a sublist of FunctionParameter nodes (with any duplicate
    8647             :  * VARIADIC item already dropped, as per above) and the second is an Integer
    8648             :  * node, containing -1 if there was no ORDER BY and otherwise the number
    8649             :  * of argument declarations before the ORDER BY.  (If this number is equal
    8650             :  * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
    8651             :  * This representation is passed as-is to CREATE AGGREGATE; for operations
    8652             :  * on existing aggregates, we can just apply extractArgTypes to the first
    8653             :  * sublist.
    8654             :  */
    8655             : aggr_args:  '(' '*' ')'
    8656             :                 {
    8657         136 :                     $$ = list_make2(NIL, makeInteger(-1));
    8658             :                 }
    8659             :             | '(' aggr_args_list ')'
    8660             :                 {
    8661         730 :                     $$ = list_make2($2, makeInteger(-1));
    8662             :                 }
    8663             :             | '(' ORDER BY aggr_args_list ')'
    8664             :                 {
    8665           6 :                     $$ = list_make2($4, makeInteger(0));
    8666             :                 }
    8667             :             | '(' aggr_args_list ORDER BY aggr_args_list ')'
    8668             :                 {
    8669             :                     /* this is the only case requiring consistency checking */
    8670          32 :                     $$ = makeOrderedSetArgs($2, $5, yyscanner);
    8671             :                 }
    8672             :         ;
    8673             : 
    8674             : aggr_args_list:
    8675         800 :             aggr_arg                                { $$ = list_make1($1); }
    8676          98 :             | aggr_args_list ',' aggr_arg           { $$ = lappend($1, $3); }
    8677             :         ;
    8678             : 
    8679             : aggregate_with_argtypes:
    8680             :             func_name aggr_args
    8681             :                 {
    8682         362 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8683             : 
    8684         362 :                     n->objname = $1;
    8685         362 :                     n->objargs = extractAggrArgTypes($2);
    8686         362 :                     n->objfuncargs = (List *) linitial($2);
    8687         362 :                     $$ = n;
    8688             :                 }
    8689             :         ;
    8690             : 
    8691             : aggregate_with_argtypes_list:
    8692         104 :             aggregate_with_argtypes                 { $$ = list_make1($1); }
    8693             :             | aggregate_with_argtypes_list ',' aggregate_with_argtypes
    8694           0 :                                                     { $$ = lappend($1, $3); }
    8695             :         ;
    8696             : 
    8697             : opt_createfunc_opt_list:
    8698             :             createfunc_opt_list
    8699          46 :             | /*EMPTY*/ { $$ = NIL; }
    8700             :     ;
    8701             : 
    8702             : createfunc_opt_list:
    8703             :             /* Must be at least one to prevent conflict */
    8704       20442 :             createfunc_opt_item                     { $$ = list_make1($1); }
    8705       52442 :             | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
    8706             :     ;
    8707             : 
    8708             : /*
    8709             :  * Options common to both CREATE FUNCTION and ALTER FUNCTION
    8710             :  */
    8711             : common_func_opt_item:
    8712             :             CALLED ON NULL_P INPUT_P
    8713             :                 {
    8714         258 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(false), @1);
    8715             :                 }
    8716             :             | RETURNS NULL_P ON NULL_P INPUT_P
    8717             :                 {
    8718         702 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8719             :                 }
    8720             :             | STRICT_P
    8721             :                 {
    8722       10060 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8723             :                 }
    8724             :             | IMMUTABLE
    8725             :                 {
    8726        7908 :                     $$ = makeDefElem("volatility", (Node *) makeString("immutable"), @1);
    8727             :                 }
    8728             :             | STABLE
    8729             :                 {
    8730        1852 :                     $$ = makeDefElem("volatility", (Node *) makeString("stable"), @1);
    8731             :                 }
    8732             :             | VOLATILE
    8733             :                 {
    8734        1322 :                     $$ = makeDefElem("volatility", (Node *) makeString("volatile"), @1);
    8735             :                 }
    8736             :             | EXTERNAL SECURITY DEFINER
    8737             :                 {
    8738           0 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8739             :                 }
    8740             :             | EXTERNAL SECURITY INVOKER
    8741             :                 {
    8742           0 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8743             :                 }
    8744             :             | SECURITY DEFINER
    8745             :                 {
    8746          48 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8747             :                 }
    8748             :             | SECURITY INVOKER
    8749             :                 {
    8750          12 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8751             :                 }
    8752             :             | LEAKPROOF
    8753             :                 {
    8754          46 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(true), @1);
    8755             :                 }
    8756             :             | NOT LEAKPROOF
    8757             :                 {
    8758          12 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(false), @1);
    8759             :                 }
    8760             :             | COST NumericOnly
    8761             :                 {
    8762        3458 :                     $$ = makeDefElem("cost", (Node *) $2, @1);
    8763             :                 }
    8764             :             | ROWS NumericOnly
    8765             :                 {
    8766         464 :                     $$ = makeDefElem("rows", (Node *) $2, @1);
    8767             :                 }
    8768             :             | SUPPORT any_name
    8769             :                 {
    8770          94 :                     $$ = makeDefElem("support", (Node *) $2, @1);
    8771             :                 }
    8772             :             | FunctionSetResetClause
    8773             :                 {
    8774             :                     /* we abuse the normal content of a DefElem here */
    8775         112 :                     $$ = makeDefElem("set", (Node *) $1, @1);
    8776             :                 }
    8777             :             | PARALLEL ColId
    8778             :                 {
    8779       10542 :                     $$ = makeDefElem("parallel", (Node *) makeString($2), @1);
    8780             :                 }
    8781             :         ;
    8782             : 
    8783             : createfunc_opt_item:
    8784             :             AS func_as
    8785             :                 {
    8786       16064 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    8787             :                 }
    8788             :             | LANGUAGE NonReservedWord_or_Sconst
    8789             :                 {
    8790       20424 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    8791             :                 }
    8792             :             | TRANSFORM transform_type_list
    8793             :                 {
    8794         118 :                     $$ = makeDefElem("transform", (Node *) $2, @1);
    8795             :                 }
    8796             :             | WINDOW
    8797             :                 {
    8798          20 :                     $$ = makeDefElem("window", (Node *) makeBoolean(true), @1);
    8799             :                 }
    8800             :             | common_func_opt_item
    8801             :                 {
    8802       36258 :                     $$ = $1;
    8803             :                 }
    8804             :         ;
    8805             : 
    8806       13792 : func_as:    Sconst                      { $$ = list_make1(makeString($1)); }
    8807             :             | Sconst ',' Sconst
    8808             :                 {
    8809        2272 :                     $$ = list_make2(makeString($1), makeString($3));
    8810             :                 }
    8811             :         ;
    8812             : 
    8813             : ReturnStmt: RETURN a_expr
    8814             :                 {
    8815        3806 :                     ReturnStmt *r = makeNode(ReturnStmt);
    8816             : 
    8817        3806 :                     r->returnval = (Node *) $2;
    8818        3806 :                     $$ = (Node *) r;
    8819             :                 }
    8820             :         ;
    8821             : 
    8822             : opt_routine_body:
    8823             :             ReturnStmt
    8824             :                 {
    8825        3800 :                     $$ = $1;
    8826             :                 }
    8827             :             | BEGIN_P ATOMIC routine_body_stmt_list END_P
    8828             :                 {
    8829             :                     /*
    8830             :                      * A compound statement is stored as a single-item list
    8831             :                      * containing the list of statements as its member.  That
    8832             :                      * way, the parse analysis code can tell apart an empty
    8833             :                      * body from no body at all.
    8834             :                      */
    8835         630 :                     $$ = (Node *) list_make1($3);
    8836             :                 }
    8837             :             | /*EMPTY*/
    8838             :                 {
    8839       16058 :                     $$ = NULL;
    8840             :                 }
    8841             :         ;
    8842             : 
    8843             : routine_body_stmt_list:
    8844             :             routine_body_stmt_list routine_body_stmt ';'
    8845             :                 {
    8846             :                     /* As in stmtmulti, discard empty statements */
    8847         646 :                     if ($2 != NULL)
    8848         628 :                         $$ = lappend($1, $2);
    8849             :                     else
    8850          18 :                         $$ = $1;
    8851             :                 }
    8852             :             | /*EMPTY*/
    8853             :                 {
    8854         630 :                     $$ = NIL;
    8855             :                 }
    8856             :         ;
    8857             : 
    8858             : routine_body_stmt:
    8859             :             stmt
    8860             :             | ReturnStmt
    8861             :         ;
    8862             : 
    8863             : transform_type_list:
    8864         118 :             FOR TYPE_P Typename { $$ = list_make1($3); }
    8865           4 :             | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
    8866             :         ;
    8867             : 
    8868             : opt_definition:
    8869         526 :             WITH definition                         { $$ = $2; }
    8870        9210 :             | /*EMPTY*/                             { $$ = NIL; }
    8871             :         ;
    8872             : 
    8873             : table_func_column:  param_name func_type
    8874             :                 {
    8875         406 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8876             : 
    8877         406 :                     n->name = $1;
    8878         406 :                     n->argType = $2;
    8879         406 :                     n->mode = FUNC_PARAM_TABLE;
    8880         406 :                     n->defexpr = NULL;
    8881         406 :                     $$ = n;
    8882             :                 }
    8883             :         ;
    8884             : 
    8885             : table_func_column_list:
    8886             :             table_func_column
    8887             :                 {
    8888         188 :                     $$ = list_make1($1);
    8889             :                 }
    8890             :             | table_func_column_list ',' table_func_column
    8891             :                 {
    8892         218 :                     $$ = lappend($1, $3);
    8893             :                 }
    8894             :         ;
    8895             : 
    8896             : /*****************************************************************************
    8897             :  * ALTER FUNCTION / ALTER PROCEDURE / ALTER ROUTINE
    8898             :  *
    8899             :  * RENAME and OWNER subcommands are already provided by the generic
    8900             :  * ALTER infrastructure, here we just specify alterations that can
    8901             :  * only be applied to functions.
    8902             :  *
    8903             :  *****************************************************************************/
    8904             : AlterFunctionStmt:
    8905             :             ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
    8906             :                 {
    8907         614 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8908             : 
    8909         614 :                     n->objtype = OBJECT_FUNCTION;
    8910         614 :                     n->func = $3;
    8911         614 :                     n->actions = $4;
    8912         614 :                     $$ = (Node *) n;
    8913             :                 }
    8914             :             | ALTER PROCEDURE function_with_argtypes alterfunc_opt_list opt_restrict
    8915             :                 {
    8916          18 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8917             : 
    8918          18 :                     n->objtype = OBJECT_PROCEDURE;
    8919          18 :                     n->func = $3;
    8920          18 :                     n->actions = $4;
    8921          18 :                     $$ = (Node *) n;
    8922             :                 }
    8923             :             | ALTER ROUTINE function_with_argtypes alterfunc_opt_list opt_restrict
    8924             :                 {
    8925           0 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8926             : 
    8927           0 :                     n->objtype = OBJECT_ROUTINE;
    8928           0 :                     n->func = $3;
    8929           0 :                     n->actions = $4;
    8930           0 :                     $$ = (Node *) n;
    8931             :                 }
    8932             :         ;
    8933             : 
    8934             : alterfunc_opt_list:
    8935             :             /* At least one option must be specified */
    8936         632 :             common_func_opt_item                    { $$ = list_make1($1); }
    8937           0 :             | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
    8938             :         ;
    8939             : 
    8940             : /* Ignored, merely for SQL compliance */
    8941             : opt_restrict:
    8942             :             RESTRICT
    8943             :             | /* EMPTY */
    8944             :         ;
    8945             : 
    8946             : 
    8947             : /*****************************************************************************
    8948             :  *
    8949             :  *      QUERY:
    8950             :  *
    8951             :  *      DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    8952             :  *      DROP PROCEDURE procname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    8953             :  *      DROP ROUTINE routname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    8954             :  *      DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
    8955             :  *      DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
    8956             :  *
    8957             :  *****************************************************************************/
    8958             : 
    8959             : RemoveFuncStmt:
    8960             :             DROP FUNCTION function_with_argtypes_list opt_drop_behavior
    8961             :                 {
    8962        3112 :                     DropStmt *n = makeNode(DropStmt);
    8963             : 
    8964        3112 :                     n->removeType = OBJECT_FUNCTION;
    8965        3112 :                     n->objects = $3;
    8966        3112 :                     n->behavior = $4;
    8967        3112 :                     n->missing_ok = false;
    8968        3112 :                     n->concurrent = false;
    8969        3112 :                     $$ = (Node *) n;
    8970             :                 }
    8971             :             | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    8972             :                 {
    8973         260 :                     DropStmt *n = makeNode(DropStmt);
    8974             : 
    8975         260 :                     n->removeType = OBJECT_FUNCTION;
    8976         260 :                     n->objects = $5;
    8977         260 :                     n->behavior = $6;
    8978         260 :                     n->missing_ok = true;
    8979         260 :                     n->concurrent = false;
    8980         260 :                     $$ = (Node *) n;
    8981             :                 }
    8982             :             | DROP PROCEDURE function_with_argtypes_list opt_drop_behavior
    8983             :                 {
    8984         138 :                     DropStmt *n = makeNode(DropStmt);
    8985             : 
    8986         138 :                     n->removeType = OBJECT_PROCEDURE;
    8987         138 :                     n->objects = $3;
    8988         138 :                     n->behavior = $4;
    8989         138 :                     n->missing_ok = false;
    8990         138 :                     n->concurrent = false;
    8991         138 :                     $$ = (Node *) n;
    8992             :                 }
    8993             :             | DROP PROCEDURE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    8994             :                 {
    8995           6 :                     DropStmt *n = makeNode(DropStmt);
    8996             : 
    8997           6 :                     n->removeType = OBJECT_PROCEDURE;
    8998           6 :                     n->objects = $5;
    8999           6 :                     n->behavior = $6;
    9000           6 :                     n->missing_ok = true;
    9001           6 :                     n->concurrent = false;
    9002           6 :                     $$ = (Node *) n;
    9003             :                 }
    9004             :             | DROP ROUTINE function_with_argtypes_list opt_drop_behavior
    9005             :                 {
    9006          12 :                     DropStmt *n = makeNode(DropStmt);
    9007             : 
    9008          12 :                     n->removeType = OBJECT_ROUTINE;
    9009          12 :                     n->objects = $3;
    9010          12 :                     n->behavior = $4;
    9011          12 :                     n->missing_ok = false;
    9012          12 :                     n->concurrent = false;
    9013          12 :                     $$ = (Node *) n;
    9014             :                 }
    9015             :             | DROP ROUTINE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9016             :                 {
    9017           6 :                     DropStmt *n = makeNode(DropStmt);
    9018             : 
    9019           6 :                     n->removeType = OBJECT_ROUTINE;
    9020           6 :                     n->objects = $5;
    9021           6 :                     n->behavior = $6;
    9022           6 :                     n->missing_ok = true;
    9023           6 :                     n->concurrent = false;
    9024           6 :                     $$ = (Node *) n;
    9025             :                 }
    9026             :         ;
    9027             : 
    9028             : RemoveAggrStmt:
    9029             :             DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
    9030             :                 {
    9031          74 :                     DropStmt *n = makeNode(DropStmt);
    9032             : 
    9033          74 :                     n->removeType = OBJECT_AGGREGATE;
    9034          74 :                     n->objects = $3;
    9035          74 :                     n->behavior = $4;
    9036          74 :                     n->missing_ok = false;
    9037          74 :                     n->concurrent = false;
    9038          74 :                     $$ = (Node *) n;
    9039             :                 }
    9040             :             | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
    9041             :                 {
    9042          30 :                     DropStmt *n = makeNode(DropStmt);
    9043             : 
    9044          30 :                     n->removeType = OBJECT_AGGREGATE;
    9045          30 :                     n->objects = $5;
    9046          30 :                     n->behavior = $6;
    9047          30 :                     n->missing_ok = true;
    9048          30 :                     n->concurrent = false;
    9049          30 :                     $$ = (Node *) n;
    9050             :                 }
    9051             :         ;
    9052             : 
    9053             : RemoveOperStmt:
    9054             :             DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
    9055             :                 {
    9056         194 :                     DropStmt *n = makeNode(DropStmt);
    9057             : 
    9058         194 :                     n->removeType = OBJECT_OPERATOR;
    9059         194 :                     n->objects = $3;
    9060         194 :                     n->behavior = $4;
    9061         194 :                     n->missing_ok = false;
    9062         194 :                     n->concurrent = false;
    9063         194 :                     $$ = (Node *) n;
    9064             :                 }
    9065             :             | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
    9066             :                 {
    9067          30 :                     DropStmt *n = makeNode(DropStmt);
    9068             : 
    9069          30 :                     n->removeType = OBJECT_OPERATOR;
    9070          30 :                     n->objects = $5;
    9071          30 :                     n->behavior = $6;
    9072          30 :                     n->missing_ok = true;
    9073          30 :                     n->concurrent = false;
    9074          30 :                     $$ = (Node *) n;
    9075             :                 }
    9076             :         ;
    9077             : 
    9078             : oper_argtypes:
    9079             :             '(' Typename ')'
    9080             :                 {
    9081          12 :                    ereport(ERROR,
    9082             :                            (errcode(ERRCODE_SYNTAX_ERROR),
    9083             :                             errmsg("missing argument"),
    9084             :                             errhint("Use NONE to denote the missing argument of a unary operator."),
    9085             :                             parser_errposition(@3)));
    9086             :                 }
    9087             :             | '(' Typename ',' Typename ')'
    9088        1908 :                     { $$ = list_make2($2, $4); }
    9089             :             | '(' NONE ',' Typename ')'                 /* left unary */
    9090          32 :                     { $$ = list_make2(NULL, $4); }
    9091             :             | '(' Typename ',' NONE ')'                 /* right unary */
    9092          12 :                     { $$ = list_make2($2, NULL); }
    9093             :         ;
    9094             : 
    9095             : any_operator:
    9096             :             all_Op
    9097       19222 :                     { $$ = list_make1(makeString($1)); }
    9098             :             | ColId '.' any_operator
    9099       14358 :                     { $$ = lcons(makeString($1), $3); }
    9100             :         ;
    9101             : 
    9102             : operator_with_argtypes_list:
    9103         224 :             operator_with_argtypes                  { $$ = list_make1($1); }
    9104             :             | operator_with_argtypes_list ',' operator_with_argtypes
    9105           0 :                                                     { $$ = lappend($1, $3); }
    9106             :         ;
    9107             : 
    9108             : operator_with_argtypes:
    9109             :             any_operator oper_argtypes
    9110             :                 {
    9111        1952 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    9112             : 
    9113        1952 :                     n->objname = $1;
    9114        1952 :                     n->objargs = $2;
    9115        1952 :                     $$ = n;
    9116             :                 }
    9117             :         ;
    9118             : 
    9119             : /*****************************************************************************
    9120             :  *
    9121             :  *      DO <anonymous code block> [ LANGUAGE language ]
    9122             :  *
    9123             :  * We use a DefElem list for future extensibility, and to allow flexibility
    9124             :  * in the clause order.
    9125             :  *
    9126             :  *****************************************************************************/
    9127             : 
    9128             : DoStmt: DO dostmt_opt_list
    9129             :                 {
    9130        1086 :                     DoStmt *n = makeNode(DoStmt);
    9131             : 
    9132        1086 :                     n->args = $2;
    9133        1086 :                     $$ = (Node *) n;
    9134             :                 }
    9135             :         ;
    9136             : 
    9137             : dostmt_opt_list:
    9138        1086 :             dostmt_opt_item                     { $$ = list_make1($1); }
    9139         196 :             | dostmt_opt_list dostmt_opt_item   { $$ = lappend($1, $2); }
    9140             :         ;
    9141             : 
    9142             : dostmt_opt_item:
    9143             :             Sconst
    9144             :                 {
    9145        1086 :                     $$ = makeDefElem("as", (Node *) makeString($1), @1);
    9146             :                 }
    9147             :             | LANGUAGE NonReservedWord_or_Sconst
    9148             :                 {
    9149         196 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    9150             :                 }
    9151             :         ;
    9152             : 
    9153             : /*****************************************************************************
    9154             :  *
    9155             :  *      CREATE CAST / DROP CAST
    9156             :  *
    9157             :  *****************************************************************************/
    9158             : 
    9159             : CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
    9160             :                     WITH FUNCTION function_with_argtypes cast_context
    9161             :                 {
    9162         102 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9163             : 
    9164         102 :                     n->sourcetype = $4;
    9165         102 :                     n->targettype = $6;
    9166         102 :                     n->func = $10;
    9167         102 :                     n->context = (CoercionContext) $11;
    9168         102 :                     n->inout = false;
    9169         102 :                     $$ = (Node *) n;
    9170             :                 }
    9171             :             | CREATE CAST '(' Typename AS Typename ')'
    9172             :                     WITHOUT FUNCTION cast_context
    9173             :                 {
    9174         162 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9175             : 
    9176         162 :                     n->sourcetype = $4;
    9177         162 :                     n->targettype = $6;
    9178         162 :                     n->func = NULL;
    9179         162 :                     n->context = (CoercionContext) $10;
    9180         162 :                     n->inout = false;
    9181         162 :                     $$ = (Node *) n;
    9182             :                 }
    9183             :             | CREATE CAST '(' Typename AS Typename ')'
    9184             :                     WITH INOUT cast_context
    9185             :                 {
    9186           6 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9187             : 
    9188           6 :                     n->sourcetype = $4;
    9189           6 :                     n->targettype = $6;
    9190           6 :                     n->func = NULL;
    9191           6 :                     n->context = (CoercionContext) $10;
    9192           6 :                     n->inout = true;
    9193           6 :                     $$ = (Node *) n;
    9194             :                 }
    9195             :         ;
    9196             : 
    9197          30 : cast_context:  AS IMPLICIT_P                    { $$ = COERCION_IMPLICIT; }
    9198          58 :         | AS ASSIGNMENT                         { $$ = COERCION_ASSIGNMENT; }
    9199         182 :         | /*EMPTY*/                             { $$ = COERCION_EXPLICIT; }
    9200             :         ;
    9201             : 
    9202             : 
    9203             : DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
    9204             :                 {
    9205          54 :                     DropStmt *n = makeNode(DropStmt);
    9206             : 
    9207          54 :                     n->removeType = OBJECT_CAST;
    9208          54 :                     n->objects = list_make1(list_make2($5, $7));
    9209          54 :                     n->behavior = $9;
    9210          54 :                     n->missing_ok = $3;
    9211          54 :                     n->concurrent = false;
    9212          54 :                     $$ = (Node *) n;
    9213             :                 }
    9214             :         ;
    9215             : 
    9216          36 : opt_if_exists: IF_P EXISTS                      { $$ = true; }
    9217          32 :         | /*EMPTY*/                             { $$ = false; }
    9218             :         ;
    9219             : 
    9220             : 
    9221             : /*****************************************************************************
    9222             :  *
    9223             :  *      CREATE TRANSFORM / DROP TRANSFORM
    9224             :  *
    9225             :  *****************************************************************************/
    9226             : 
    9227             : CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name '(' transform_element_list ')'
    9228             :                 {
    9229          50 :                     CreateTransformStmt *n = makeNode(CreateTransformStmt);
    9230             : 
    9231          50 :                     n->replace = $2;
    9232          50 :                     n->type_name = $5;
    9233          50 :                     n->lang = $7;
    9234          50 :                     n->fromsql = linitial($9);
    9235          50 :                     n->tosql = lsecond($9);
    9236          50 :                     $$ = (Node *) n;
    9237             :                 }
    9238             :         ;
    9239             : 
    9240             : transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes ',' TO SQL_P WITH FUNCTION function_with_argtypes
    9241             :                 {
    9242          44 :                     $$ = list_make2($5, $11);
    9243             :                 }
    9244             :                 | TO SQL_P WITH FUNCTION function_with_argtypes ',' FROM SQL_P WITH FUNCTION function_with_argtypes
    9245             :                 {
    9246           0 :                     $$ = list_make2($11, $5);
    9247             :                 }
    9248             :                 | FROM SQL_P WITH FUNCTION function_with_argtypes
    9249             :                 {
    9250           4 :                     $$ = list_make2($5, NULL);
    9251             :                 }
    9252             :                 | TO SQL_P WITH FUNCTION function_with_argtypes
    9253             :                 {
    9254           2 :                     $$ = list_make2(NULL, $5);
    9255             :                 }
    9256             :         ;
    9257             : 
    9258             : 
    9259             : DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
    9260             :                 {
    9261          14 :                     DropStmt *n = makeNode(DropStmt);
    9262             : 
    9263          14 :                     n->removeType = OBJECT_TRANSFORM;
    9264          14 :                     n->objects = list_make1(list_make2($5, makeString($7)));
    9265          14 :                     n->behavior = $8;
    9266          14 :                     n->missing_ok = $3;
    9267          14 :                     $$ = (Node *) n;
    9268             :                 }
    9269             :         ;
    9270             : 
    9271             : 
    9272             : /*****************************************************************************
    9273             :  *
    9274             :  *      QUERY:
    9275             :  *
    9276             :  *      REINDEX [ (options) ] {INDEX | TABLE | SCHEMA} [CONCURRENTLY] <name>
    9277             :  *      REINDEX [ (options) ] {DATABASE | SYSTEM} [CONCURRENTLY] [<name>]
    9278             :  *****************************************************************************/
    9279             : 
    9280             : ReindexStmt:
    9281             :             REINDEX opt_reindex_option_list reindex_target_relation opt_concurrently qualified_name
    9282             :                 {
    9283         870 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9284             : 
    9285         870 :                     n->kind = $3;
    9286         870 :                     n->relation = $5;
    9287         870 :                     n->name = NULL;
    9288         870 :                     n->params = $2;
    9289         870 :                     if ($4)
    9290         490 :                         n->params = lappend(n->params,
    9291         490 :                                             makeDefElem("concurrently", NULL, @4));
    9292         870 :                     $$ = (Node *) n;
    9293             :                 }
    9294             :             | REINDEX opt_reindex_option_list SCHEMA opt_concurrently name
    9295             :                 {
    9296         114 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9297             : 
    9298         114 :                     n->kind = REINDEX_OBJECT_SCHEMA;
    9299         114 :                     n->relation = NULL;
    9300         114 :                     n->name = $5;
    9301         114 :                     n->params = $2;
    9302         114 :                     if ($4)
    9303          40 :                         n->params = lappend(n->params,
    9304          40 :                                             makeDefElem("concurrently", NULL, @4));
    9305         114 :                     $$ = (Node *) n;
    9306             :                 }
    9307             :             | REINDEX opt_reindex_option_list reindex_target_all opt_concurrently opt_single_name
    9308             :                 {
    9309          68 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9310             : 
    9311          68 :                     n->kind = $3;
    9312          68 :                     n->relation = NULL;
    9313          68 :                     n->name = $5;
    9314          68 :                     n->params = $2;
    9315          68 :                     if ($4)
    9316          10 :                         n->params = lappend(n->params,
    9317          10 :                                             makeDefElem("concurrently", NULL, @4));
    9318          68 :                     $$ = (Node *) n;
    9319             :                 }
    9320             :         ;
    9321             : reindex_target_relation:
    9322         372 :             INDEX                   { $$ = REINDEX_OBJECT_INDEX; }
    9323         498 :             | TABLE                 { $$ = REINDEX_OBJECT_TABLE; }
    9324             :         ;
    9325             : reindex_target_all:
    9326          34 :             SYSTEM_P                { $$ = REINDEX_OBJECT_SYSTEM; }
    9327          34 :             | DATABASE              { $$ = REINDEX_OBJECT_DATABASE; }
    9328             :         ;
    9329             : opt_reindex_option_list:
    9330         156 :             '(' utility_option_list ')'             { $$ = $2; }
    9331         896 :             | /* EMPTY */                           { $$ = NULL; }
    9332             :         ;
    9333             : 
    9334             : /*****************************************************************************
    9335             :  *
    9336             :  * ALTER TABLESPACE
    9337             :  *
    9338             :  *****************************************************************************/
    9339             : 
    9340             : AlterTblSpcStmt:
    9341             :             ALTER TABLESPACE name SET reloptions
    9342             :                 {
    9343             :                     AlterTableSpaceOptionsStmt *n =
    9344          12 :                         makeNode(AlterTableSpaceOptionsStmt);
    9345             : 
    9346          12 :                     n->tablespacename = $3;
    9347          12 :                     n->options = $5;
    9348          12 :                     n->isReset = false;
    9349          12 :                     $$ = (Node *) n;
    9350             :                 }
    9351             :             | ALTER TABLESPACE name RESET reloptions
    9352             :                 {
    9353             :                     AlterTableSpaceOptionsStmt *n =
    9354          12 :                         makeNode(AlterTableSpaceOptionsStmt);
    9355             : 
    9356          12 :                     n->tablespacename = $3;
    9357          12 :                     n->options = $5;
    9358          12 :                     n->isReset = true;
    9359          12 :                     $$ = (Node *) n;
    9360             :                 }
    9361             :         ;
    9362             : 
    9363             : /*****************************************************************************
    9364             :  *
    9365             :  * ALTER THING name RENAME TO newname
    9366             :  *
    9367             :  *****************************************************************************/
    9368             : 
    9369             : RenameStmt: ALTER AGGREGATE aggregate_with_argtypes RENAME TO name
    9370             :                 {
    9371          42 :                     RenameStmt *n = makeNode(RenameStmt);
    9372             : 
    9373          42 :                     n->renameType = OBJECT_AGGREGATE;
    9374          42 :                     n->object = (Node *) $3;
    9375          42 :                     n->newname = $6;
    9376          42 :                     n->missing_ok = false;
    9377          42 :                     $$ = (Node *) n;
    9378             :                 }
    9379             :             | ALTER COLLATION any_name RENAME TO name
    9380             :                 {
    9381          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9382             : 
    9383          18 :                     n->renameType = OBJECT_COLLATION;
    9384          18 :                     n->object = (Node *) $3;
    9385          18 :                     n->newname = $6;
    9386          18 :                     n->missing_ok = false;
    9387          18 :                     $$ = (Node *) n;
    9388             :                 }
    9389             :             | ALTER CONVERSION_P any_name RENAME TO name
    9390             :                 {
    9391          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9392             : 
    9393          24 :                     n->renameType = OBJECT_CONVERSION;
    9394          24 :                     n->object = (Node *) $3;
    9395          24 :                     n->newname = $6;
    9396          24 :                     n->missing_ok = false;
    9397          24 :                     $$ = (Node *) n;
    9398             :                 }
    9399             :             | ALTER DATABASE name RENAME TO name
    9400             :                 {
    9401           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9402             : 
    9403           0 :                     n->renameType = OBJECT_DATABASE;
    9404           0 :                     n->subname = $3;
    9405           0 :                     n->newname = $6;
    9406           0 :                     n->missing_ok = false;
    9407           0 :                     $$ = (Node *) n;
    9408             :                 }
    9409             :             | ALTER DOMAIN_P any_name RENAME TO name
    9410             :                 {
    9411           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9412             : 
    9413           6 :                     n->renameType = OBJECT_DOMAIN;
    9414           6 :                     n->object = (Node *) $3;
    9415           6 :                     n->newname = $6;
    9416           6 :                     n->missing_ok = false;
    9417           6 :                     $$ = (Node *) n;
    9418             :                 }
    9419             :             | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
    9420             :                 {
    9421           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9422             : 
    9423           6 :                     n->renameType = OBJECT_DOMCONSTRAINT;
    9424           6 :                     n->object = (Node *) $3;
    9425           6 :                     n->subname = $6;
    9426           6 :                     n->newname = $8;
    9427           6 :                     $$ = (Node *) n;
    9428             :                 }
    9429             :             | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
    9430             :                 {
    9431          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9432             : 
    9433          24 :                     n->renameType = OBJECT_FDW;
    9434          24 :                     n->object = (Node *) makeString($5);
    9435          24 :                     n->newname = $8;
    9436          24 :                     n->missing_ok = false;
    9437          24 :                     $$ = (Node *) n;
    9438             :                 }
    9439             :             | ALTER FUNCTION function_with_argtypes RENAME TO name
    9440             :                 {
    9441          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9442             : 
    9443          24 :                     n->renameType = OBJECT_FUNCTION;
    9444          24 :                     n->object = (Node *) $3;
    9445          24 :                     n->newname = $6;
    9446          24 :                     n->missing_ok = false;
    9447          24 :                     $$ = (Node *) n;
    9448             :                 }
    9449             :             | ALTER GROUP_P RoleId RENAME TO RoleId
    9450             :                 {
    9451           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9452             : 
    9453           0 :                     n->renameType = OBJECT_ROLE;
    9454           0 :                     n->subname = $3;
    9455           0 :                     n->newname = $6;
    9456           0 :                     n->missing_ok = false;
    9457           0 :                     $$ = (Node *) n;
    9458             :                 }
    9459             :             | ALTER opt_procedural LANGUAGE name RENAME TO name
    9460             :                 {
    9461          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9462             : 
    9463          18 :                     n->renameType = OBJECT_LANGUAGE;
    9464          18 :                     n->object = (Node *) makeString($4);
    9465          18 :                     n->newname = $7;
    9466          18 :                     n->missing_ok = false;
    9467          18 :                     $$ = (Node *) n;
    9468             :                 }
    9469             :             | ALTER OPERATOR CLASS any_name USING name RENAME TO name
    9470             :                 {
    9471          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9472             : 
    9473          24 :                     n->renameType = OBJECT_OPCLASS;
    9474          24 :                     n->object = (Node *) lcons(makeString($6), $4);
    9475          24 :                     n->newname = $9;
    9476          24 :                     n->missing_ok = false;
    9477          24 :                     $$ = (Node *) n;
    9478             :                 }
    9479             :             | ALTER OPERATOR FAMILY any_name USING name RENAME TO name
    9480             :                 {
    9481          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9482             : 
    9483          24 :                     n->renameType = OBJECT_OPFAMILY;
    9484          24 :                     n->object = (Node *) lcons(makeString($6), $4);
    9485          24 :                     n->newname = $9;
    9486          24 :                     n->missing_ok = false;
    9487          24 :                     $$ = (Node *) n;
    9488             :                 }
    9489             :             | ALTER POLICY name ON qualified_name RENAME TO name
    9490             :                 {
    9491          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9492             : 
    9493          18 :                     n->renameType = OBJECT_POLICY;
    9494          18 :                     n->relation = $5;
    9495          18 :                     n->subname = $3;
    9496          18 :                     n->newname = $8;
    9497          18 :                     n->missing_ok = false;
    9498          18 :                     $$ = (Node *) n;
    9499             :                 }
    9500             :             | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
    9501             :                 {
    9502           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9503             : 
    9504           0 :                     n->renameType = OBJECT_POLICY;
    9505           0 :                     n->relation = $7;
    9506           0 :                     n->subname = $5;
    9507           0 :                     n->newname = $10;
    9508           0 :                     n->missing_ok = true;
    9509           0 :                     $$ = (Node *) n;
    9510             :                 }
    9511             :             | ALTER PROCEDURE function_with_argtypes RENAME TO name
    9512             :                 {
    9513           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9514             : 
    9515           0 :                     n->renameType = OBJECT_PROCEDURE;
    9516           0 :                     n->object = (Node *) $3;
    9517           0 :                     n->newname = $6;
    9518           0 :                     n->missing_ok = false;
    9519           0 :                     $$ = (Node *) n;
    9520             :                 }
    9521             :             | ALTER PUBLICATION name RENAME TO name
    9522             :                 {
    9523          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9524             : 
    9525          18 :                     n->renameType = OBJECT_PUBLICATION;
    9526          18 :                     n->object = (Node *) makeString($3);
    9527          18 :                     n->newname = $6;
    9528          18 :                     n->missing_ok = false;
    9529          18 :                     $$ = (Node *) n;
    9530             :                 }
    9531             :             | ALTER ROUTINE function_with_argtypes RENAME TO name
    9532             :                 {
    9533          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9534             : 
    9535          24 :                     n->renameType = OBJECT_ROUTINE;
    9536          24 :                     n->object = (Node *) $3;
    9537          24 :                     n->newname = $6;
    9538          24 :                     n->missing_ok = false;
    9539          24 :                     $$ = (Node *) n;
    9540             :                 }
    9541             :             | ALTER SCHEMA name RENAME TO name
    9542             :                 {
    9543          20 :                     RenameStmt *n = makeNode(RenameStmt);
    9544             : 
    9545          20 :                     n->renameType = OBJECT_SCHEMA;
    9546          20 :                     n->subname = $3;
    9547          20 :                     n->newname = $6;
    9548          20 :                     n->missing_ok = false;
    9549          20 :                     $$ = (Node *) n;
    9550             :                 }
    9551             :             | ALTER SERVER name RENAME TO name
    9552             :                 {
    9553          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9554             : 
    9555          24 :                     n->renameType = OBJECT_FOREIGN_SERVER;
    9556          24 :                     n->object = (Node *) makeString($3);
    9557          24 :                     n->newname = $6;
    9558          24 :                     n->missing_ok = false;
    9559          24 :                     $$ = (Node *) n;
    9560             :                 }
    9561             :             | ALTER SUBSCRIPTION name RENAME TO name
    9562             :                 {
    9563          38 :                     RenameStmt *n = makeNode(RenameStmt);
    9564             : 
    9565          38 :                     n->renameType = OBJECT_SUBSCRIPTION;
    9566          38 :                     n->object = (Node *) makeString($3);
    9567          38 :                     n->newname = $6;
    9568          38 :                     n->missing_ok = false;
    9569          38 :                     $$ = (Node *) n;
    9570             :                 }
    9571             :             | ALTER TABLE relation_expr RENAME TO name
    9572             :                 {
    9573         286 :                     RenameStmt *n = makeNode(RenameStmt);
    9574             : 
    9575         286 :                     n->renameType = OBJECT_TABLE;
    9576         286 :                     n->relation = $3;
    9577         286 :                     n->subname = NULL;
    9578         286 :                     n->newname = $6;
    9579         286 :                     n->missing_ok = false;
    9580         286 :                     $$ = (Node *) n;
    9581             :                 }
    9582             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
    9583             :                 {
    9584           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9585             : 
    9586           0 :                     n->renameType = OBJECT_TABLE;
    9587           0 :                     n->relation = $5;
    9588           0 :                     n->subname = NULL;
    9589           0 :                     n->newname = $8;
    9590           0 :                     n->missing_ok = true;
    9591           0 :                     $$ = (Node *) n;
    9592             :                 }
    9593             :             | ALTER SEQUENCE qualified_name RENAME TO name
    9594             :                 {
    9595           2 :                     RenameStmt *n = makeNode(RenameStmt);
    9596             : 
    9597           2 :                     n->renameType = OBJECT_SEQUENCE;
    9598           2 :                     n->relation = $3;
    9599           2 :                     n->subname = NULL;
    9600           2 :                     n->newname = $6;
    9601           2 :                     n->missing_ok = false;
    9602           2 :                     $$ = (Node *) n;
    9603             :                 }
    9604             :             | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
    9605             :                 {
    9606           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9607             : 
    9608           0 :                     n->renameType = OBJECT_SEQUENCE;
    9609           0 :                     n->relation = $5;
    9610           0 :                     n->subname = NULL;
    9611           0 :                     n->newname = $8;
    9612           0 :                     n->missing_ok = true;
    9613           0 :                     $$ = (Node *) n;
    9614             :                 }
    9615             :             | ALTER VIEW qualified_name RENAME TO name
    9616             :                 {
    9617           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9618             : 
    9619           6 :                     n->renameType = OBJECT_VIEW;
    9620           6 :                     n->relation = $3;
    9621           6 :                     n->subname = NULL;
    9622           6 :                     n->newname = $6;
    9623           6 :                     n->missing_ok = false;
    9624           6 :                     $$ = (Node *) n;
    9625             :                 }
    9626             :             | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
    9627             :                 {
    9628           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9629             : 
    9630           0 :                     n->renameType = OBJECT_VIEW;
    9631           0 :                     n->relation = $5;
    9632           0 :                     n->subname = NULL;
    9633           0 :                     n->newname = $8;
    9634           0 :                     n->missing_ok = true;
    9635           0 :                     $$ = (Node *) n;
    9636             :                 }
    9637             :             | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
    9638             :                 {
    9639           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9640             : 
    9641           0 :                     n->renameType = OBJECT_MATVIEW;
    9642           0 :                     n->relation = $4;
    9643           0 :                     n->subname = NULL;
    9644           0 :                     n->newname = $7;
    9645           0 :                     n->missing_ok = false;
    9646           0 :                     $$ = (Node *) n;
    9647             :                 }
    9648             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
    9649             :                 {
    9650           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9651             : 
    9652           0 :                     n->renameType = OBJECT_MATVIEW;
    9653           0 :                     n->relation = $6;
    9654           0 :                     n->subname = NULL;
    9655           0 :                     n->newname = $9;
    9656           0 :                     n->missing_ok = true;
    9657           0 :                     $$ = (Node *) n;
    9658             :                 }
    9659             :             | ALTER INDEX qualified_name RENAME TO name
    9660             :                 {
    9661         192 :                     RenameStmt *n = makeNode(RenameStmt);
    9662             : 
    9663         192 :                     n->renameType = OBJECT_INDEX;
    9664         192 :                     n->relation = $3;
    9665         192 :                     n->subname = NULL;
    9666         192 :                     n->newname = $6;
    9667         192 :                     n->missing_ok = false;
    9668         192 :                     $$ = (Node *) n;
    9669             :                 }
    9670             :             | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
    9671             :                 {
    9672          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9673             : 
    9674          12 :                     n->renameType = OBJECT_INDEX;
    9675          12 :                     n->relation = $5;
    9676          12 :                     n->subname = NULL;
    9677          12 :                     n->newname = $8;
    9678          12 :                     n->missing_ok = true;
    9679          12 :                     $$ = (Node *) n;
    9680             :                 }
    9681             :             | ALTER FOREIGN TABLE relation_expr RENAME TO name
    9682             :                 {
    9683           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9684             : 
    9685           6 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9686           6 :                     n->relation = $4;
    9687           6 :                     n->subname = NULL;
    9688           6 :                     n->newname = $7;
    9689           6 :                     n->missing_ok = false;
    9690           6 :                     $$ = (Node *) n;
    9691             :                 }
    9692             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
    9693             :                 {
    9694           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9695             : 
    9696           6 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9697           6 :                     n->relation = $6;
    9698           6 :                     n->subname = NULL;
    9699           6 :                     n->newname = $9;
    9700           6 :                     n->missing_ok = true;
    9701           6 :                     $$ = (Node *) n;
    9702             :                 }
    9703             :             | ALTER TABLE relation_expr RENAME opt_column name TO name
    9704             :                 {
    9705         238 :                     RenameStmt *n = makeNode(RenameStmt);
    9706             : 
    9707         238 :                     n->renameType = OBJECT_COLUMN;
    9708         238 :                     n->relationType = OBJECT_TABLE;
    9709         238 :                     n->relation = $3;
    9710         238 :                     n->subname = $6;
    9711         238 :                     n->newname = $8;
    9712         238 :                     n->missing_ok = false;
    9713         238 :                     $$ = (Node *) n;
    9714             :                 }
    9715             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9716             :                 {
    9717          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9718             : 
    9719          24 :                     n->renameType = OBJECT_COLUMN;
    9720          24 :                     n->relationType = OBJECT_TABLE;
    9721          24 :                     n->relation = $5;
    9722          24 :                     n->subname = $8;
    9723          24 :                     n->newname = $10;
    9724          24 :                     n->missing_ok = true;
    9725          24 :                     $$ = (Node *) n;
    9726             :                 }
    9727             :             | ALTER VIEW qualified_name RENAME opt_column name TO name
    9728             :                 {
    9729           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9730             : 
    9731           6 :                     n->renameType = OBJECT_COLUMN;
    9732           6 :                     n->relationType = OBJECT_VIEW;
    9733           6 :                     n->relation = $3;
    9734           6 :                     n->subname = $6;
    9735           6 :                     n->newname = $8;
    9736           6 :                     n->missing_ok = false;
    9737           6 :                     $$ = (Node *) n;
    9738             :                 }
    9739             :             | ALTER VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    9740             :                 {
    9741           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9742             : 
    9743           0 :                     n->renameType = OBJECT_COLUMN;
    9744           0 :                     n->relationType = OBJECT_VIEW;
    9745           0 :                     n->relation = $5;
    9746           0 :                     n->subname = $8;
    9747           0 :                     n->newname = $10;
    9748           0 :                     n->missing_ok = true;
    9749           0 :                     $$ = (Node *) n;
    9750             :                 }
    9751             :             | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
    9752             :                 {
    9753           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9754             : 
    9755           0 :                     n->renameType = OBJECT_COLUMN;
    9756           0 :                     n->relationType = OBJECT_MATVIEW;
    9757           0 :                     n->relation = $4;
    9758           0 :                     n->subname = $7;
    9759           0 :                     n->newname = $9;
    9760           0 :                     n->missing_ok = false;
    9761           0 :                     $$ = (Node *) n;
    9762             :                 }
    9763             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    9764             :                 {
    9765           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9766             : 
    9767           0 :                     n->renameType = OBJECT_COLUMN;
    9768           0 :                     n->relationType = OBJECT_MATVIEW;
    9769           0 :                     n->relation = $6;
    9770           0 :                     n->subname = $9;
    9771           0 :                     n->newname = $11;
    9772           0 :                     n->missing_ok = true;
    9773           0 :                     $$ = (Node *) n;
    9774             :                 }
    9775             :             | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
    9776             :                 {
    9777          66 :                     RenameStmt *n = makeNode(RenameStmt);
    9778             : 
    9779          66 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9780          66 :                     n->relation = $3;
    9781          66 :                     n->subname = $6;
    9782          66 :                     n->newname = $8;
    9783          66 :                     n->missing_ok = false;
    9784          66 :                     $$ = (Node *) n;
    9785             :                 }
    9786             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
    9787             :                 {
    9788           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9789             : 
    9790           6 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9791           6 :                     n->relation = $5;
    9792           6 :                     n->subname = $8;
    9793           6 :                     n->newname = $10;
    9794           6 :                     n->missing_ok = true;
    9795           6 :                     $$ = (Node *) n;
    9796             :                 }
    9797             :             | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
    9798             :                 {
    9799           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9800             : 
    9801           6 :                     n->renameType = OBJECT_COLUMN;
    9802           6 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    9803           6 :                     n->relation = $4;
    9804           6 :                     n->subname = $7;
    9805           6 :                     n->newname = $9;
    9806           6 :                     n->missing_ok = false;
    9807           6 :                     $$ = (Node *) n;
    9808             :                 }
    9809             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9810             :                 {
    9811           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9812             : 
    9813           6 :                     n->renameType = OBJECT_COLUMN;
    9814           6 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    9815           6 :                     n->relation = $6;
    9816           6 :                     n->subname = $9;
    9817           6 :                     n->newname = $11;
    9818           6 :                     n->missing_ok = true;
    9819           6 :                     $$ = (Node *) n;
    9820             :                 }
    9821             :             | ALTER RULE name ON qualified_name RENAME TO name
    9822             :                 {
    9823          34 :                     RenameStmt *n = makeNode(RenameStmt);
    9824             : 
    9825          34 :                     n->renameType = OBJECT_RULE;
    9826          34 :                     n->relation = $5;
    9827          34 :                     n->subname = $3;
    9828          34 :                     n->newname = $8;
    9829          34 :                     n->missing_ok = false;
    9830          34 :                     $$ = (Node *) n;
    9831             :                 }
    9832             :             | ALTER TRIGGER name ON qualified_name RENAME TO name
    9833             :                 {
    9834          40 :                     RenameStmt *n = makeNode(RenameStmt);
    9835             : 
    9836          40 :                     n->renameType = OBJECT_TRIGGER;
    9837          40 :                     n->relation = $5;
    9838          40 :                     n->subname = $3;
    9839          40 :                     n->newname = $8;
    9840          40 :                     n->missing_ok = false;
    9841          40 :                     $$ = (Node *) n;
    9842             :                 }
    9843             :             | ALTER EVENT TRIGGER name RENAME TO name
    9844             :                 {
    9845          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9846             : 
    9847          12 :                     n->renameType = OBJECT_EVENT_TRIGGER;
    9848          12 :                     n->object = (Node *) makeString($4);
    9849          12 :                     n->newname = $7;
    9850          12 :                     $$ = (Node *) n;
    9851             :                 }
    9852             :             | ALTER ROLE RoleId RENAME TO RoleId
    9853             :                 {
    9854          30 :                     RenameStmt *n = makeNode(RenameStmt);
    9855             : 
    9856          30 :                     n->renameType = OBJECT_ROLE;
    9857          30 :                     n->subname = $3;
    9858          30 :                     n->newname = $6;
    9859          30 :                     n->missing_ok = false;
    9860          30 :                     $$ = (Node *) n;
    9861             :                 }
    9862             :             | ALTER USER RoleId RENAME TO RoleId
    9863             :                 {
    9864           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9865             : 
    9866           0 :                     n->renameType = OBJECT_ROLE;
    9867           0 :                     n->subname = $3;
    9868           0 :                     n->newname = $6;
    9869           0 :                     n->missing_ok = false;
    9870           0 :                     $$ = (Node *) n;
    9871             :                 }
    9872             :             | ALTER TABLESPACE name RENAME TO name
    9873             :                 {
    9874           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9875             : 
    9876           6 :                     n->renameType = OBJECT_TABLESPACE;
    9877           6 :                     n->subname = $3;
    9878           6 :                     n->newname = $6;
    9879           6 :                     n->missing_ok = false;
    9880           6 :                     $$ = (Node *) n;
    9881             :                 }
    9882             :             | ALTER STATISTICS any_name RENAME TO name
    9883             :                 {
    9884          30 :                     RenameStmt *n = makeNode(RenameStmt);
    9885             : 
    9886          30 :                     n->renameType = OBJECT_STATISTIC_EXT;
    9887          30 :                     n->object = (Node *) $3;
    9888          30 :                     n->newname = $6;
    9889          30 :                     n->missing_ok = false;
    9890          30 :                     $$ = (Node *) n;
    9891             :                 }
    9892             :             | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
    9893             :                 {
    9894          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9895             : 
    9896          12 :                     n->renameType = OBJECT_TSPARSER;
    9897          12 :                     n->object = (Node *) $5;
    9898          12 :                     n->newname = $8;
    9899          12 :                     n->missing_ok = false;
    9900          12 :                     $$ = (Node *) n;
    9901             :                 }
    9902             :             | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
    9903             :                 {
    9904          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9905             : 
    9906          24 :                     n->renameType = OBJECT_TSDICTIONARY;
    9907          24 :                     n->object = (Node *) $5;
    9908          24 :                     n->newname = $8;
    9909          24 :                     n->missing_ok = false;
    9910          24 :                     $$ = (Node *) n;
    9911             :                 }
    9912             :             | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
    9913             :                 {
    9914          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9915             : 
    9916          12 :                     n->renameType = OBJECT_TSTEMPLATE;
    9917          12 :                     n->object = (Node *) $5;
    9918          12 :                     n->newname = $8;
    9919          12 :                     n->missing_ok = false;
    9920          12 :                     $$ = (Node *) n;
    9921             :                 }
    9922             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
    9923             :                 {
    9924          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9925             : 
    9926          24 :                     n->renameType = OBJECT_TSCONFIGURATION;
    9927          24 :                     n->object = (Node *) $5;
    9928          24 :                     n->newname = $8;
    9929          24 :                     n->missing_ok = false;
    9930          24 :                     $$ = (Node *) n;
    9931             :                 }
    9932             :             | ALTER TYPE_P any_name RENAME TO name
    9933             :                 {
    9934          26 :                     RenameStmt *n = makeNode(RenameStmt);
    9935             : 
    9936          26 :                     n->renameType = OBJECT_TYPE;
    9937          26 :                     n->object = (Node *) $3;
    9938          26 :                     n->newname = $6;
    9939          26 :                     n->missing_ok = false;
    9940          26 :                     $$ = (Node *) n;
    9941             :                 }
    9942             :             | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
    9943             :                 {
    9944          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9945             : 
    9946          24 :                     n->renameType = OBJECT_ATTRIBUTE;
    9947          24 :                     n->relationType = OBJECT_TYPE;
    9948          24 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
    9949          24 :                     n->subname = $6;
    9950          24 :                     n->newname = $8;
    9951          24 :                     n->behavior = $9;
    9952          24 :                     n->missing_ok = false;
    9953          24 :                     $$ = (Node *) n;
    9954             :                 }
    9955             :         ;
    9956             : 
    9957             : opt_column: COLUMN
    9958             :             | /*EMPTY*/
    9959             :         ;
    9960             : 
    9961         154 : opt_set_data: SET DATA_P                            { $$ = 1; }
    9962         772 :             | /*EMPTY*/                             { $$ = 0; }
    9963             :         ;
    9964             : 
    9965             : /*****************************************************************************
    9966             :  *
    9967             :  * ALTER THING name DEPENDS ON EXTENSION name
    9968             :  *
    9969             :  *****************************************************************************/
    9970             : 
    9971             : AlterObjectDependsStmt:
    9972             :             ALTER FUNCTION function_with_argtypes opt_no DEPENDS ON EXTENSION name
    9973             :                 {
    9974          12 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9975             : 
    9976          12 :                     n->objectType = OBJECT_FUNCTION;
    9977          12 :                     n->object = (Node *) $3;
    9978          12 :                     n->extname = makeString($8);
    9979          12 :                     n->remove = $4;
    9980          12 :                     $$ = (Node *) n;
    9981             :                 }
    9982             :             | ALTER PROCEDURE function_with_argtypes opt_no DEPENDS ON EXTENSION name
    9983             :                 {
    9984           0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9985             : 
    9986           0 :                     n->objectType = OBJECT_PROCEDURE;
    9987           0 :                     n->object = (Node *) $3;
    9988           0 :                     n->extname = makeString($8);
    9989           0 :                     n->remove = $4;
    9990           0 :                     $$ = (Node *) n;
    9991             :                 }
    9992             :             | ALTER ROUTINE function_with_argtypes opt_no DEPENDS ON EXTENSION name
    9993             :                 {
    9994           0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9995             : 
    9996           0 :                     n->objectType = OBJECT_ROUTINE;
    9997           0 :                     n->object = (Node *) $3;
    9998           0 :                     n->extname = makeString($8);
    9999           0 :                     n->remove = $4;
   10000           0 :                     $$ = (Node *) n;
   10001             :                 }
   10002             :             | ALTER TRIGGER name ON qualified_name opt_no DEPENDS ON EXTENSION name
   10003             :                 {
   10004          10 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10005             : 
   10006          10 :                     n->objectType = OBJECT_TRIGGER;
   10007          10 :                     n->relation = $5;
   10008          10 :                     n->object = (Node *) list_make1(makeString($3));
   10009          10 :                     n->extname = makeString($10);
   10010          10 :                     n->remove = $6;
   10011          10 :                     $$ = (Node *) n;
   10012             :                 }
   10013             :             | ALTER MATERIALIZED VIEW qualified_name opt_no DEPENDS ON EXTENSION name
   10014             :                 {
   10015          10 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10016             : 
   10017          10 :                     n->objectType = OBJECT_MATVIEW;
   10018          10 :                     n->relation = $4;
   10019          10 :                     n->extname = makeString($9);
   10020          10 :                     n->remove = $5;
   10021          10 :                     $$ = (Node *) n;
   10022             :                 }
   10023             :             | ALTER INDEX qualified_name opt_no DEPENDS ON EXTENSION name
   10024             :                 {
   10025          14 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10026             : 
   10027          14 :                     n->objectType = OBJECT_INDEX;
   10028          14 :                     n->relation = $3;
   10029          14 :                     n->extname = makeString($8);
   10030          14 :                     n->remove = $4;
   10031          14 :                     $$ = (Node *) n;
   10032             :                 }
   10033             :         ;
   10034             : 
   10035           8 : opt_no:     NO              { $$ = true; }
   10036          38 :             | /* EMPTY */   { $$ = false;   }
   10037             :         ;
   10038             : 
   10039             : /*****************************************************************************
   10040             :  *
   10041             :  * ALTER THING name SET SCHEMA name
   10042             :  *
   10043             :  *****************************************************************************/
   10044             : 
   10045             : AlterObjectSchemaStmt:
   10046             :             ALTER AGGREGATE aggregate_with_argtypes SET SCHEMA name
   10047             :                 {
   10048          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10049             : 
   10050          24 :                     n->objectType = OBJECT_AGGREGATE;
   10051          24 :                     n->object = (Node *) $3;
   10052          24 :                     n->newschema = $6;
   10053          24 :                     n->missing_ok = false;
   10054          24 :                     $$ = (Node *) n;
   10055             :                 }
   10056             :             | ALTER COLLATION any_name SET SCHEMA name
   10057             :                 {
   10058           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10059             : 
   10060           6 :                     n->objectType = OBJECT_COLLATION;
   10061           6 :                     n->object = (Node *) $3;
   10062           6 :                     n->newschema = $6;
   10063           6 :                     n->missing_ok = false;
   10064           6 :                     $$ = (Node *) n;
   10065             :                 }
   10066             :             | ALTER CONVERSION_P any_name SET SCHEMA name
   10067             :                 {
   10068          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10069             : 
   10070          24 :                     n->objectType = OBJECT_CONVERSION;
   10071          24 :                     n->object = (Node *) $3;
   10072          24 :                     n->newschema = $6;
   10073          24 :                     n->missing_ok = false;
   10074          24 :                     $$ = (Node *) n;
   10075             :                 }
   10076             :             | ALTER DOMAIN_P any_name SET SCHEMA name
   10077             :                 {
   10078           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10079             : 
   10080           6 :                     n->objectType = OBJECT_DOMAIN;
   10081           6 :                     n->object = (Node *) $3;
   10082           6 :                     n->newschema = $6;
   10083           6 :                     n->missing_ok = false;
   10084           6 :                     $$ = (Node *) n;
   10085             :                 }
   10086             :             | ALTER EXTENSION name SET SCHEMA name
   10087             :                 {
   10088          10 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10089             : 
   10090          10 :                     n->objectType = OBJECT_EXTENSION;
   10091          10 :                     n->object = (Node *) makeString($3);
   10092          10 :                     n->newschema = $6;
   10093          10 :                     n->missing_ok = false;
   10094          10 :                     $$ = (Node *) n;
   10095             :                 }
   10096             :             | ALTER FUNCTION function_with_argtypes SET SCHEMA name
   10097             :                 {
   10098          42 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10099             : 
   10100          42 :                     n->objectType = OBJECT_FUNCTION;
   10101          42 :                     n->object = (Node *) $3;
   10102          42 :                     n->newschema = $6;
   10103          42 :                     n->missing_ok = false;
   10104          42 :                     $$ = (Node *) n;
   10105             :                 }
   10106             :             | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
   10107             :                 {
   10108          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10109             : 
   10110          18 :                     n->objectType = OBJECT_OPERATOR;
   10111          18 :                     n->object = (Node *) $3;
   10112          18 :                     n->newschema = $6;
   10113          18 :                     n->missing_ok = false;
   10114          18 :                     $$ = (Node *) n;
   10115             :                 }
   10116             :             | ALTER OPERATOR CLASS any_name USING name SET SCHEMA name
   10117             :                 {
   10118          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10119             : 
   10120          24 :                     n->objectType = OBJECT_OPCLASS;
   10121          24 :                     n->object = (Node *) lcons(makeString($6), $4);
   10122          24 :                     n->newschema = $9;
   10123          24 :                     n->missing_ok = false;
   10124          24 :                     $$ = (Node *) n;
   10125             :                 }
   10126             :             | ALTER OPERATOR FAMILY any_name USING name SET SCHEMA name
   10127             :                 {
   10128          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10129             : 
   10130          24 :                     n->objectType = OBJECT_OPFAMILY;
   10131          24 :                     n->object = (Node *) lcons(makeString($6), $4);
   10132          24 :                     n->newschema = $9;
   10133          24 :                     n->missing_ok = false;
   10134          24 :                     $$ = (Node *) n;
   10135             :                 }
   10136             :             | ALTER PROCEDURE function_with_argtypes SET SCHEMA name
   10137             :                 {
   10138           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10139             : 
   10140           0 :                     n->objectType = OBJECT_PROCEDURE;
   10141           0 :                     n->object = (Node *) $3;
   10142           0 :                     n->newschema = $6;
   10143           0 :                     n->missing_ok = false;
   10144           0 :                     $$ = (Node *) n;
   10145             :                 }
   10146             :             | ALTER ROUTINE function_with_argtypes SET SCHEMA name
   10147             :                 {
   10148           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10149             : 
   10150           0 :                     n->objectType = OBJECT_ROUTINE;
   10151           0 :                     n->object = (Node *) $3;
   10152           0 :                     n->newschema = $6;
   10153           0 :                     n->missing_ok = false;
   10154           0 :                     $$ = (Node *) n;
   10155             :                 }
   10156             :             | ALTER TABLE relation_expr SET SCHEMA name
   10157             :                 {
   10158          66 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10159             : 
   10160          66 :                     n->objectType = OBJECT_TABLE;
   10161          66 :                     n->relation = $3;
   10162          66 :                     n->newschema = $6;
   10163          66 :                     n->missing_ok = false;
   10164          66 :                     $$ = (Node *) n;
   10165             :                 }
   10166             :             | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10167             :                 {
   10168          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10169             : 
   10170          12 :                     n->objectType = OBJECT_TABLE;
   10171          12 :                     n->relation = $5;
   10172          12 :                     n->newschema = $8;
   10173          12 :                     n->missing_ok = true;
   10174          12 :                     $$ = (Node *) n;
   10175             :                 }
   10176             :             | ALTER STATISTICS any_name SET SCHEMA name
   10177             :                 {
   10178          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10179             : 
   10180          18 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10181          18 :                     n->object = (Node *) $3;
   10182          18 :                     n->newschema = $6;
   10183          18 :                     n->missing_ok = false;
   10184          18 :                     $$ = (Node *) n;
   10185             :                 }
   10186             :             | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
   10187             :                 {
   10188          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10189             : 
   10190          18 :                     n->objectType = OBJECT_TSPARSER;
   10191          18 :                     n->object = (Node *) $5;
   10192          18 :                     n->newschema = $8;
   10193          18 :                     n->missing_ok = false;
   10194          18 :                     $$ = (Node *) n;
   10195             :                 }
   10196             :             | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
   10197             :                 {
   10198          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10199             : 
   10200          24 :                     n->objectType = OBJECT_TSDICTIONARY;
   10201          24 :                     n->object = (Node *) $5;
   10202          24 :                     n->newschema = $8;
   10203          24 :                     n->missing_ok = false;
   10204          24 :                     $$ = (Node *) n;
   10205             :                 }
   10206             :             | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
   10207             :                 {
   10208          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10209             : 
   10210          18 :                     n->objectType = OBJECT_TSTEMPLATE;
   10211          18 :                     n->object = (Node *) $5;
   10212          18 :                     n->newschema = $8;
   10213          18 :                     n->missing_ok = false;
   10214          18 :                     $$ = (Node *) n;
   10215             :                 }
   10216             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
   10217             :                 {
   10218          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10219             : 
   10220          24 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10221          24 :                     n->object = (Node *) $5;
   10222          24 :                     n->newschema = $8;
   10223          24 :                     n->missing_ok = false;
   10224          24 :                     $$ = (Node *) n;
   10225             :                 }
   10226             :             | ALTER SEQUENCE qualified_name SET SCHEMA name
   10227             :                 {
   10228           8 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10229             : 
   10230           8 :                     n->objectType = OBJECT_SEQUENCE;
   10231           8 :                     n->relation = $3;
   10232           8 :                     n->newschema = $6;
   10233           8 :                     n->missing_ok = false;
   10234           8 :                     $$ = (Node *) n;
   10235             :                 }
   10236             :             | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
   10237             :                 {
   10238           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10239             : 
   10240           0 :                     n->objectType = OBJECT_SEQUENCE;
   10241           0 :                     n->relation = $5;
   10242           0 :                     n->newschema = $8;
   10243           0 :                     n->missing_ok = true;
   10244           0 :                     $$ = (Node *) n;
   10245             :                 }
   10246             :             | ALTER VIEW qualified_name SET SCHEMA name
   10247             :                 {
   10248           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10249             : 
   10250           0 :                     n->objectType = OBJECT_VIEW;
   10251           0 :                     n->relation = $3;
   10252           0 :                     n->newschema = $6;
   10253           0 :                     n->missing_ok = false;
   10254           0 :                     $$ = (Node *) n;
   10255             :                 }
   10256             :             | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
   10257             :                 {
   10258           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10259             : 
   10260           0 :                     n->objectType = OBJECT_VIEW;
   10261           0 :                     n->relation = $5;
   10262           0 :                     n->newschema = $8;
   10263           0 :                     n->missing_ok = true;
   10264           0 :                     $$ = (Node *) n;
   10265             :                 }
   10266             :             | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
   10267             :                 {
   10268           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10269             : 
   10270           6 :                     n->objectType = OBJECT_MATVIEW;
   10271           6 :                     n->relation = $4;
   10272           6 :                     n->newschema = $7;
   10273           6 :                     n->missing_ok = false;
   10274           6 :                     $$ = (Node *) n;
   10275             :                 }
   10276             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
   10277             :                 {
   10278           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10279             : 
   10280           0 :                     n->objectType = OBJECT_MATVIEW;
   10281           0 :                     n->relation = $6;
   10282           0 :                     n->newschema = $9;
   10283           0 :                     n->missing_ok = true;
   10284           0 :                     $$ = (Node *) n;
   10285             :                 }
   10286             :             | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
   10287             :                 {
   10288           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10289             : 
   10290           6 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10291           6 :                     n->relation = $4;
   10292           6 :                     n->newschema = $7;
   10293           6 :                     n->missing_ok = false;
   10294           6 :                     $$ = (Node *) n;
   10295             :                 }
   10296             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10297             :                 {
   10298           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10299             : 
   10300           6 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10301           6 :                     n->relation = $6;
   10302           6 :                     n->newschema = $9;
   10303           6 :                     n->missing_ok = true;
   10304           6 :                     $$ = (Node *) n;
   10305             :                 }
   10306             :             | ALTER TYPE_P any_name SET SCHEMA name
   10307             :                 {
   10308          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10309             : 
   10310          12 :                     n->objectType = OBJECT_TYPE;
   10311          12 :                     n->object = (Node *) $3;
   10312          12 :                     n->newschema = $6;
   10313          12 :                     n->missing_ok = false;
   10314          12 :                     $$ = (Node *) n;
   10315             :                 }
   10316             :         ;
   10317             : 
   10318             : /*****************************************************************************
   10319             :  *
   10320             :  * ALTER OPERATOR name SET define
   10321             :  *
   10322             :  *****************************************************************************/
   10323             : 
   10324             : AlterOperatorStmt:
   10325             :             ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
   10326             :                 {
   10327         602 :                     AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
   10328             : 
   10329         602 :                     n->opername = $3;
   10330         602 :                     n->options = $6;
   10331         602 :                     $$ = (Node *) n;
   10332             :                 }
   10333             :         ;
   10334             : 
   10335         662 : operator_def_list:  operator_def_elem                               { $$ = list_make1($1); }
   10336         506 :             | operator_def_list ',' operator_def_elem               { $$ = lappend($1, $3); }
   10337             :         ;
   10338             : 
   10339             : operator_def_elem: ColLabel '=' NONE
   10340          30 :                         { $$ = makeDefElem($1, NULL, @1); }
   10341             :                    | ColLabel '=' operator_def_arg
   10342        1110 :                         { $$ = makeDefElem($1, (Node *) $3, @1); }
   10343             :                    | ColLabel
   10344          28 :                         { $$ = makeDefElem($1, NULL, @1); }
   10345             :         ;
   10346             : 
   10347             : /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
   10348             : operator_def_arg:
   10349        1032 :             func_type                       { $$ = (Node *) $1; }
   10350          24 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
   10351          54 :             | qual_all_Op                   { $$ = (Node *) $1; }
   10352           0 :             | NumericOnly                   { $$ = (Node *) $1; }
   10353           0 :             | Sconst                        { $$ = (Node *) makeString($1); }
   10354             :         ;
   10355             : 
   10356             : /*****************************************************************************
   10357             :  *
   10358             :  * ALTER TYPE name SET define
   10359             :  *
   10360             :  * We repurpose ALTER OPERATOR's version of "definition" here
   10361             :  *
   10362             :  *****************************************************************************/
   10363             : 
   10364             : AlterTypeStmt:
   10365             :             ALTER TYPE_P any_name SET '(' operator_def_list ')'
   10366             :                 {
   10367          60 :                     AlterTypeStmt *n = makeNode(AlterTypeStmt);
   10368             : 
   10369          60 :                     n->typeName = $3;
   10370          60 :                     n->options = $6;
   10371          60 :                     $$ = (Node *) n;
   10372             :                 }
   10373             :         ;
   10374             : 
   10375             : /*****************************************************************************
   10376             :  *
   10377             :  * ALTER THING name OWNER TO newname
   10378             :  *
   10379             :  *****************************************************************************/
   10380             : 
   10381             : AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec
   10382             :                 {
   10383         142 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10384             : 
   10385         142 :                     n->objectType = OBJECT_AGGREGATE;
   10386         142 :                     n->object = (Node *) $3;
   10387         142 :                     n->newowner = $6;
   10388         142 :                     $$ = (Node *) n;
   10389             :                 }
   10390             :             | ALTER COLLATION any_name OWNER TO RoleSpec
   10391             :                 {
   10392          16 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10393             : 
   10394          16 :                     n->objectType = OBJECT_COLLATION;
   10395          16 :                     n->object = (Node *) $3;
   10396          16 :                     n->newowner = $6;
   10397          16 :                     $$ = (Node *) n;
   10398             :                 }
   10399             :             | ALTER CONVERSION_P any_name OWNER TO RoleSpec
   10400             :                 {
   10401          24 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10402             : 
   10403          24 :                     n->objectType = OBJECT_CONVERSION;
   10404          24 :                     n->object = (Node *) $3;
   10405          24 :                     n->newowner = $6;
   10406          24 :                     $$ = (Node *) n;
   10407             :                 }
   10408             :             | ALTER DATABASE name OWNER TO RoleSpec
   10409             :                 {
   10410          44 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10411             : 
   10412          44 :                     n->objectType = OBJECT_DATABASE;
   10413          44 :                     n->object = (Node *) makeString($3);
   10414          44 :                     n->newowner = $6;
   10415          44 :                     $$ = (Node *) n;
   10416             :                 }
   10417             :             | ALTER DOMAIN_P any_name OWNER TO RoleSpec
   10418             :                 {
   10419          38 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10420             : 
   10421          38 :                     n->objectType = OBJECT_DOMAIN;
   10422          38 :                     n->object = (Node *) $3;
   10423          38 :                     n->newowner = $6;
   10424          38 :                     $$ = (Node *) n;
   10425             :                 }
   10426             :             | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
   10427             :                 {
   10428         574 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10429             : 
   10430         574 :                     n->objectType = OBJECT_FUNCTION;
   10431         574 :                     n->object = (Node *) $3;
   10432         574 :                     n->newowner = $6;
   10433         574 :                     $$ = (Node *) n;
   10434             :                 }
   10435             :             | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
   10436             :                 {
   10437         122 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10438             : 
   10439         122 :                     n->objectType = OBJECT_LANGUAGE;
   10440         122 :                     n->object = (Node *) makeString($4);
   10441         122 :                     n->newowner = $7;
   10442         122 :                     $$ = (Node *) n;
   10443             :                 }
   10444             :             | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
   10445             :                 {
   10446          12 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10447             : 
   10448          12 :                     n->objectType = OBJECT_LARGEOBJECT;
   10449          12 :                     n->object = (Node *) $4;
   10450          12 :                     n->newowner = $7;
   10451          12 :                     $$ = (Node *) n;
   10452             :                 }
   10453             :             | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
   10454             :                 {
   10455          46 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10456             : 
   10457          46 :                     n->objectType = OBJECT_OPERATOR;
   10458          46 :                     n->object = (Node *) $3;
   10459          46 :                     n->newowner = $6;
   10460          46 :                     $$ = (Node *) n;
   10461             :                 }
   10462             :             | ALTER OPERATOR CLASS any_name USING name OWNER TO RoleSpec
   10463             :                 {
   10464          54 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10465             : 
   10466          54 :                     n->objectType = OBJECT_OPCLASS;
   10467          54 :                     n->object = (Node *) lcons(makeString($6), $4);
   10468          54 :                     n->newowner = $9;
   10469          54 :                     $$ = (Node *) n;
   10470             :                 }
   10471             :             | ALTER OPERATOR FAMILY any_name USING name OWNER TO RoleSpec
   10472             :                 {
   10473          62 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10474             : 
   10475          62 :                     n->objectType = OBJECT_OPFAMILY;
   10476          62 :                     n->object = (Node *) lcons(makeString($6), $4);
   10477          62 :                     n->newowner = $9;
   10478          62 :                     $$ = (Node *) n;
   10479             :                 }
   10480             :             | ALTER PROCEDURE function_with_argtypes OWNER TO RoleSpec
   10481             :                 {
   10482          18 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10483             : 
   10484          18 :                     n->objectType = OBJECT_PROCEDURE;
   10485          18 :                     n->object = (Node *) $3;
   10486          18 :                     n->newowner = $6;
   10487          18 :                     $$ = (Node *) n;
   10488             :                 }
   10489             :             | ALTER ROUTINE function_with_argtypes OWNER TO RoleSpec
   10490             :                 {
   10491           0 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10492             : 
   10493           0 :                     n->objectType = OBJECT_ROUTINE;
   10494           0 :                     n->object = (Node *) $3;
   10495           0 :                     n->newowner = $6;
   10496           0 :                     $$ = (Node *) n;
   10497             :                 }
   10498             :             | ALTER SCHEMA name OWNER TO RoleSpec
   10499             :                 {
   10500          52 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10501             : 
   10502          52 :                     n->objectType = OBJECT_SCHEMA;
   10503          52 :                     n->object = (Node *) makeString($3);
   10504          52 :                     n->newowner = $6;
   10505          52 :                     $$ = (Node *) n;
   10506             :                 }
   10507             :             | ALTER TYPE_P any_name OWNER TO RoleSpec
   10508             :                 {
   10509          80 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10510             : 
   10511          80 :                     n->objectType = OBJECT_TYPE;
   10512          80 :                     n->object = (Node *) $3;
   10513          80 :                     n->newowner = $6;
   10514          80 :                     $$ = (Node *) n;
   10515             :                 }
   10516             :             | ALTER TABLESPACE name OWNER TO RoleSpec
   10517             :                 {
   10518           6 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10519             : 
   10520           6 :                     n->objectType = OBJECT_TABLESPACE;
   10521           6 :                     n->object = (Node *) makeString($3);
   10522           6 :                     n->newowner = $6;
   10523           6 :                     $$ = (Node *) n;
   10524             :                 }
   10525             :             | ALTER STATISTICS any_name OWNER TO RoleSpec
   10526             :                 {
   10527          32 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10528             : 
   10529          32 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10530          32 :                     n->object = (Node *) $3;
   10531          32 :                     n->newowner = $6;
   10532          32 :                     $$ = (Node *) n;
   10533             :                 }
   10534             :             | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
   10535             :                 {
   10536          42 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10537             : 
   10538          42 :                     n->objectType = OBJECT_TSDICTIONARY;
   10539          42 :                     n->object = (Node *) $5;
   10540          42 :                     n->newowner = $8;
   10541          42 :                     $$ = (Node *) n;
   10542             :                 }
   10543             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
   10544             :                 {
   10545          32 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10546             : 
   10547          32 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10548          32 :                     n->object = (Node *) $5;
   10549          32 :                     n->newowner = $8;
   10550          32 :                     $$ = (Node *) n;
   10551             :                 }
   10552             :             | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
   10553             :                 {
   10554          20 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10555             : 
   10556          20 :                     n->objectType = OBJECT_FDW;
   10557          20 :                     n->object = (Node *) makeString($5);
   10558          20 :                     n->newowner = $8;
   10559          20 :                     $$ = (Node *) n;
   10560             :                 }
   10561             :             | ALTER SERVER name OWNER TO RoleSpec
   10562             :                 {
   10563          68 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10564             : 
   10565          68 :                     n->objectType = OBJECT_FOREIGN_SERVER;
   10566          68 :                     n->object = (Node *) makeString($3);
   10567          68 :                     n->newowner = $6;
   10568          68 :                     $$ = (Node *) n;
   10569             :                 }
   10570             :             | ALTER EVENT TRIGGER name OWNER TO RoleSpec
   10571             :                 {
   10572          14 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10573             : 
   10574          14 :                     n->objectType = OBJECT_EVENT_TRIGGER;
   10575          14 :                     n->object = (Node *) makeString($4);
   10576          14 :                     n->newowner = $7;
   10577          14 :                     $$ = (Node *) n;
   10578             :                 }
   10579             :             | ALTER PUBLICATION name OWNER TO RoleSpec
   10580             :                 {
   10581          26 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10582             : 
   10583          26 :                     n->objectType = OBJECT_PUBLICATION;
   10584          26 :                     n->object = (Node *) makeString($3);
   10585          26 :                     n->newowner = $6;
   10586          26 :                     $$ = (Node *) n;
   10587             :                 }
   10588             :             | ALTER SUBSCRIPTION name OWNER TO RoleSpec
   10589             :                 {
   10590          18 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10591             : 
   10592          18 :                     n->objectType = OBJECT_SUBSCRIPTION;
   10593          18 :                     n->object = (Node *) makeString($3);
   10594          18 :                     n->newowner = $6;
   10595          18 :                     $$ = (Node *) n;
   10596             :                 }
   10597             :         ;
   10598             : 
   10599             : 
   10600             : /*****************************************************************************
   10601             :  *
   10602             :  * CREATE PUBLICATION name [WITH options]
   10603             :  *
   10604             :  * CREATE PUBLICATION FOR ALL TABLES [WITH options]
   10605             :  *
   10606             :  * CREATE PUBLICATION FOR pub_obj [, ...] [WITH options]
   10607             :  *
   10608             :  * pub_obj is one of:
   10609             :  *
   10610             :  *      TABLE table [, ...]
   10611             :  *      TABLES IN SCHEMA schema [, ...]
   10612             :  *
   10613             :  *****************************************************************************/
   10614             : 
   10615             : CreatePublicationStmt:
   10616             :             CREATE PUBLICATION name opt_definition
   10617             :                 {
   10618         108 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10619             : 
   10620         108 :                     n->pubname = $3;
   10621         108 :                     n->options = $4;
   10622         108 :                     $$ = (Node *) n;
   10623             :                 }
   10624             :             | CREATE PUBLICATION name FOR ALL TABLES opt_definition
   10625             :                 {
   10626          62 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10627             : 
   10628          62 :                     n->pubname = $3;
   10629          62 :                     n->options = $7;
   10630          62 :                     n->for_all_tables = true;
   10631          62 :                     $$ = (Node *) n;
   10632             :                 }
   10633             :             | CREATE PUBLICATION name FOR pub_obj_list opt_definition
   10634             :                 {
   10635         550 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10636             : 
   10637         550 :                     n->pubname = $3;
   10638         550 :                     n->options = $6;
   10639         550 :                     n->pubobjects = (List *) $5;
   10640         550 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10641         520 :                     $$ = (Node *) n;
   10642             :                 }
   10643             :         ;
   10644             : 
   10645             : /*
   10646             :  * FOR TABLE and FOR TABLES IN SCHEMA specifications
   10647             :  *
   10648             :  * This rule parses publication objects with and without keyword prefixes.
   10649             :  *
   10650             :  * The actual type of the object without keyword prefix depends on the previous
   10651             :  * one with keyword prefix. It will be preprocessed in preprocess_pubobj_list().
   10652             :  *
   10653             :  * For the object without keyword prefix, we cannot just use relation_expr here,
   10654             :  * because some extended expressions in relation_expr cannot be used as a
   10655             :  * schemaname and we cannot differentiate it. So, we extract the rules from
   10656             :  * relation_expr here.
   10657             :  */
   10658             : PublicationObjSpec:
   10659             :             TABLE relation_expr opt_column_list OptWhereClause
   10660             :                 {
   10661        1158 :                     $$ = makeNode(PublicationObjSpec);
   10662        1158 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLE;
   10663        1158 :                     $$->pubtable = makeNode(PublicationTable);
   10664        1158 :                     $$->pubtable->relation = $2;
   10665        1158 :                     $$->pubtable->columns = $3;
   10666        1158 :                     $$->pubtable->whereClause = $4;
   10667             :                 }
   10668             :             | TABLES IN_P SCHEMA ColId
   10669             :                 {
   10670         332 :                     $$ = makeNode(PublicationObjSpec);
   10671         332 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   10672         332 :                     $$->name = $4;
   10673         332 :                     $$->location = @4;
   10674             :                 }
   10675             :             | TABLES IN_P SCHEMA CURRENT_SCHEMA
   10676             :                 {
   10677          18 :                     $$ = makeNode(PublicationObjSpec);
   10678          18 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   10679          18 :                     $$->location = @4;
   10680             :                 }
   10681             :             | ColId opt_column_list OptWhereClause
   10682             :                 {
   10683         130 :                     $$ = makeNode(PublicationObjSpec);
   10684         130 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10685             :                     /*
   10686             :                      * If either a row filter or column list is specified, create
   10687             :                      * a PublicationTable object.
   10688             :                      */
   10689         130 :                     if ($2 || $3)
   10690             :                     {
   10691             :                         /*
   10692             :                          * The OptWhereClause must be stored here but it is
   10693             :                          * valid only for tables. For non-table objects, an
   10694             :                          * error will be thrown later via
   10695             :                          * preprocess_pubobj_list().
   10696             :                          */
   10697          42 :                         $$->pubtable = makeNode(PublicationTable);
   10698          42 :                         $$->pubtable->relation = makeRangeVar(NULL, $1, @1);
   10699          42 :                         $$->pubtable->columns = $2;
   10700          42 :                         $$->pubtable->whereClause = $3;
   10701             :                     }
   10702             :                     else
   10703             :                     {
   10704          88 :                         $$->name = $1;
   10705             :                     }
   10706         130 :                     $$->location = @1;
   10707             :                 }
   10708             :             | ColId indirection opt_column_list OptWhereClause
   10709             :                 {
   10710          32 :                     $$ = makeNode(PublicationObjSpec);
   10711          32 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10712          32 :                     $$->pubtable = makeNode(PublicationTable);
   10713          32 :                     $$->pubtable->relation = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   10714          32 :                     $$->pubtable->columns = $3;
   10715          32 :                     $$->pubtable->whereClause = $4;
   10716          32 :                     $$->location = @1;
   10717             :                 }
   10718             :             /* grammar like tablename * , ONLY tablename, ONLY ( tablename ) */
   10719             :             | extended_relation_expr opt_column_list OptWhereClause
   10720             :                 {
   10721           6 :                     $$ = makeNode(PublicationObjSpec);
   10722           6 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10723           6 :                     $$->pubtable = makeNode(PublicationTable);
   10724           6 :                     $$->pubtable->relation = $1;
   10725           6 :                     $$->pubtable->columns = $2;
   10726           6 :                     $$->pubtable->whereClause = $3;
   10727             :                 }
   10728             :             | CURRENT_SCHEMA
   10729             :                 {
   10730          18 :                     $$ = makeNode(PublicationObjSpec);
   10731          18 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10732          18 :                     $$->location = @1;
   10733             :                 }
   10734             :                 ;
   10735             : 
   10736             : pub_obj_list:   PublicationObjSpec
   10737        1470 :                     { $$ = list_make1($1); }
   10738             :             | pub_obj_list ',' PublicationObjSpec
   10739         224 :                     { $$ = lappend($1, $3); }
   10740             :     ;
   10741             : 
   10742             : /*****************************************************************************
   10743             :  *
   10744             :  * ALTER PUBLICATION name SET ( options )
   10745             :  *
   10746             :  * ALTER PUBLICATION name ADD pub_obj [, ...]
   10747             :  *
   10748             :  * ALTER PUBLICATION name DROP pub_obj [, ...]
   10749             :  *
   10750             :  * ALTER PUBLICATION name SET pub_obj [, ...]
   10751             :  *
   10752             :  * pub_obj is one of:
   10753             :  *
   10754             :  *      TABLE table_name [, ...]
   10755             :  *      TABLES IN SCHEMA schema_name [, ...]
   10756             :  *
   10757             :  *****************************************************************************/
   10758             : 
   10759             : AlterPublicationStmt:
   10760             :             ALTER PUBLICATION name SET definition
   10761             :                 {
   10762         110 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10763             : 
   10764         110 :                     n->pubname = $3;
   10765         110 :                     n->options = $5;
   10766         110 :                     $$ = (Node *) n;
   10767             :                 }
   10768             :             | ALTER PUBLICATION name ADD_P pub_obj_list
   10769             :                 {
   10770         332 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10771             : 
   10772         332 :                     n->pubname = $3;
   10773         332 :                     n->pubobjects = $5;
   10774         332 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10775         326 :                     n->action = AP_AddObjects;
   10776         326 :                     $$ = (Node *) n;
   10777             :                 }
   10778             :             | ALTER PUBLICATION name SET pub_obj_list
   10779             :                 {
   10780         440 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10781             : 
   10782         440 :                     n->pubname = $3;
   10783         440 :                     n->pubobjects = $5;
   10784         440 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10785         440 :                     n->action = AP_SetObjects;
   10786         440 :                     $$ = (Node *) n;
   10787             :                 }
   10788             :             | ALTER PUBLICATION name DROP pub_obj_list
   10789             :                 {
   10790         148 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10791             : 
   10792         148 :                     n->pubname = $3;
   10793         148 :                     n->pubobjects = $5;
   10794         148 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10795         148 :                     n->action = AP_DropObjects;
   10796         148 :                     $$ = (Node *) n;
   10797             :                 }
   10798             :         ;
   10799             : 
   10800             : /*****************************************************************************
   10801             :  *
   10802             :  * CREATE SUBSCRIPTION name ...
   10803             :  *
   10804             :  *****************************************************************************/
   10805             : 
   10806             : CreateSubscriptionStmt:
   10807             :             CREATE SUBSCRIPTION name CONNECTION Sconst PUBLICATION name_list opt_definition
   10808             :                 {
   10809             :                     CreateSubscriptionStmt *n =
   10810         416 :                         makeNode(CreateSubscriptionStmt);
   10811         416 :                     n->subname = $3;
   10812         416 :                     n->conninfo = $5;
   10813         416 :                     n->publication = $7;
   10814         416 :                     n->options = $8;
   10815         416 :                     $$ = (Node *) n;
   10816             :                 }
   10817             :         ;
   10818             : 
   10819             : /*****************************************************************************
   10820             :  *
   10821             :  * ALTER SUBSCRIPTION name ...
   10822             :  *
   10823             :  *****************************************************************************/
   10824             : 
   10825             : AlterSubscriptionStmt:
   10826             :             ALTER SUBSCRIPTION name SET definition
   10827             :                 {
   10828             :                     AlterSubscriptionStmt *n =
   10829         184 :                         makeNode(AlterSubscriptionStmt);
   10830             : 
   10831         184 :                     n->kind = ALTER_SUBSCRIPTION_OPTIONS;
   10832         184 :                     n->subname = $3;
   10833         184 :                     n->options = $5;
   10834         184 :                     $$ = (Node *) n;
   10835             :                 }
   10836             :             | ALTER SUBSCRIPTION name CONNECTION Sconst
   10837             :                 {
   10838             :                     AlterSubscriptionStmt *n =
   10839          26 :                         makeNode(AlterSubscriptionStmt);
   10840             : 
   10841          26 :                     n->kind = ALTER_SUBSCRIPTION_CONNECTION;
   10842          26 :                     n->subname = $3;
   10843          26 :                     n->conninfo = $5;
   10844          26 :                     $$ = (Node *) n;
   10845             :                 }
   10846             :             | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
   10847             :                 {
   10848             :                     AlterSubscriptionStmt *n =
   10849          54 :                         makeNode(AlterSubscriptionStmt);
   10850             : 
   10851          54 :                     n->kind = ALTER_SUBSCRIPTION_REFRESH;
   10852          54 :                     n->subname = $3;
   10853          54 :                     n->options = $6;
   10854          54 :                     $$ = (Node *) n;
   10855             :                 }
   10856             :             | ALTER SUBSCRIPTION name ADD_P PUBLICATION name_list opt_definition
   10857             :                 {
   10858             :                     AlterSubscriptionStmt *n =
   10859          28 :                         makeNode(AlterSubscriptionStmt);
   10860             : 
   10861          28 :                     n->kind = ALTER_SUBSCRIPTION_ADD_PUBLICATION;
   10862          28 :                     n->subname = $3;
   10863          28 :                     n->publication = $6;
   10864          28 :                     n->options = $7;
   10865          28 :                     $$ = (Node *) n;
   10866             :                 }
   10867             :             | ALTER SUBSCRIPTION name DROP PUBLICATION name_list opt_definition
   10868             :                 {
   10869             :                     AlterSubscriptionStmt *n =
   10870          26 :                         makeNode(AlterSubscriptionStmt);
   10871             : 
   10872          26 :                     n->kind = ALTER_SUBSCRIPTION_DROP_PUBLICATION;
   10873          26 :                     n->subname = $3;
   10874          26 :                     n->publication = $6;
   10875          26 :                     n->options = $7;
   10876          26 :                     $$ = (Node *) n;
   10877             :                 }
   10878             :             | ALTER SUBSCRIPTION name SET PUBLICATION name_list opt_definition
   10879             :                 {
   10880             :                     AlterSubscriptionStmt *n =
   10881          40 :                         makeNode(AlterSubscriptionStmt);
   10882             : 
   10883          40 :                     n->kind = ALTER_SUBSCRIPTION_SET_PUBLICATION;
   10884          40 :                     n->subname = $3;
   10885          40 :                     n->publication = $6;
   10886          40 :                     n->options = $7;
   10887          40 :                     $$ = (Node *) n;
   10888             :                 }
   10889             :             | ALTER SUBSCRIPTION name ENABLE_P
   10890             :                 {
   10891             :                     AlterSubscriptionStmt *n =
   10892          44 :                         makeNode(AlterSubscriptionStmt);
   10893             : 
   10894          44 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   10895          44 :                     n->subname = $3;
   10896          44 :                     n->options = list_make1(makeDefElem("enabled",
   10897             :                                             (Node *) makeBoolean(true), @1));
   10898          44 :                     $$ = (Node *) n;
   10899             :                 }
   10900             :             | ALTER SUBSCRIPTION name DISABLE_P
   10901             :                 {
   10902             :                     AlterSubscriptionStmt *n =
   10903          26 :                         makeNode(AlterSubscriptionStmt);
   10904             : 
   10905          26 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   10906          26 :                     n->subname = $3;
   10907          26 :                     n->options = list_make1(makeDefElem("enabled",
   10908             :                                             (Node *) makeBoolean(false), @1));
   10909          26 :                     $$ = (Node *) n;
   10910             :                 }
   10911             :             | ALTER SUBSCRIPTION name SKIP definition
   10912             :                 {
   10913             :                     AlterSubscriptionStmt *n =
   10914          24 :                         makeNode(AlterSubscriptionStmt);
   10915             : 
   10916          24 :                     n->kind = ALTER_SUBSCRIPTION_SKIP;
   10917          24 :                     n->subname = $3;
   10918          24 :                     n->options = $5;
   10919          24 :                     $$ = (Node *) n;
   10920             :                 }
   10921             :         ;
   10922             : 
   10923             : /*****************************************************************************
   10924             :  *
   10925             :  * DROP SUBSCRIPTION [ IF EXISTS ] name
   10926             :  *
   10927             :  *****************************************************************************/
   10928             : 
   10929             : DropSubscriptionStmt: DROP SUBSCRIPTION name opt_drop_behavior
   10930             :                 {
   10931         186 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   10932             : 
   10933         186 :                     n->subname = $3;
   10934         186 :                     n->missing_ok = false;
   10935         186 :                     n->behavior = $4;
   10936         186 :                     $$ = (Node *) n;
   10937             :                 }
   10938             :                 |  DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
   10939             :                 {
   10940           6 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   10941             : 
   10942           6 :                     n->subname = $5;
   10943           6 :                     n->missing_ok = true;
   10944           6 :                     n->behavior = $6;
   10945           6 :                     $$ = (Node *) n;
   10946             :                 }
   10947             :         ;
   10948             : 
   10949             : /*****************************************************************************
   10950             :  *
   10951             :  *      QUERY:  Define Rewrite Rule
   10952             :  *
   10953             :  *****************************************************************************/
   10954             : 
   10955             : RuleStmt:   CREATE opt_or_replace RULE name AS
   10956             :             ON event TO qualified_name where_clause
   10957             :             DO opt_instead RuleActionList
   10958             :                 {
   10959        1028 :                     RuleStmt   *n = makeNode(RuleStmt);
   10960             : 
   10961        1028 :                     n->replace = $2;
   10962        1028 :                     n->relation = $9;
   10963        1028 :                     n->rulename = $4;
   10964        1028 :                     n->whereClause = $10;
   10965        1028 :                     n->event = $7;
   10966        1028 :                     n->instead = $12;
   10967        1028 :                     n->actions = $13;
   10968        1028 :                     $$ = (Node *) n;
   10969             :                 }
   10970             :         ;
   10971             : 
   10972             : RuleActionList:
   10973         142 :             NOTHING                                 { $$ = NIL; }
   10974         840 :             | RuleActionStmt                        { $$ = list_make1($1); }
   10975          46 :             | '(' RuleActionMulti ')'               { $$ = $2; }
   10976             :         ;
   10977             : 
   10978             : /* the thrashing around here is to discard "empty" statements... */
   10979             : RuleActionMulti:
   10980             :             RuleActionMulti ';' RuleActionStmtOrEmpty
   10981          62 :                 { if ($3 != NULL)
   10982          46 :                     $$ = lappend($1, $3);
   10983             :                   else
   10984          16 :                     $$ = $1;
   10985             :                 }
   10986             :             | RuleActionStmtOrEmpty
   10987          46 :                 { if ($1 != NULL)
   10988          46 :                     $$ = list_make1($1);
   10989             :                   else
   10990           0 :                     $$ = NIL;
   10991             :                 }
   10992             :         ;
   10993             : 
   10994             : RuleActionStmt:
   10995             :             SelectStmt
   10996             :             | InsertStmt
   10997             :             | UpdateStmt
   10998             :             | DeleteStmt
   10999             :             | NotifyStmt
   11000             :         ;
   11001             : 
   11002             : RuleActionStmtOrEmpty:
   11003          92 :             RuleActionStmt                          { $$ = $1; }
   11004          16 :             |   /*EMPTY*/                           { $$ = NULL; }
   11005             :         ;
   11006             : 
   11007          18 : event:      SELECT                                  { $$ = CMD_SELECT; }
   11008         386 :             | UPDATE                                { $$ = CMD_UPDATE; }
   11009         152 :             | DELETE_P                              { $$ = CMD_DELETE; }
   11010         472 :             | INSERT                                { $$ = CMD_INSERT; }
   11011             :          ;
   11012             : 
   11013             : opt_instead:
   11014         708 :             INSTEAD                                 { $$ = true; }
   11015         156 :             | ALSO                                  { $$ = false; }
   11016         164 :             | /*EMPTY*/                             { $$ = false; }
   11017             :         ;
   11018             : 
   11019             : 
   11020             : /*****************************************************************************
   11021             :  *
   11022             :  *      QUERY:
   11023             :  *              NOTIFY <identifier> can appear both in rule bodies and
   11024             :  *              as a query-level command
   11025             :  *
   11026             :  *****************************************************************************/
   11027             : 
   11028             : NotifyStmt: NOTIFY ColId notify_payload
   11029             :                 {
   11030         122 :                     NotifyStmt *n = makeNode(NotifyStmt);
   11031             : 
   11032         122 :                     n->conditionname = $2;
   11033         122 :                     n->payload = $3;
   11034         122 :                     $$ = (Node *) n;
   11035             :                 }
   11036             :         ;
   11037             : 
   11038             : notify_payload:
   11039          62 :             ',' Sconst                          { $$ = $2; }
   11040          60 :             | /*EMPTY*/                         { $$ = NULL; }
   11041             :         ;
   11042             : 
   11043             : ListenStmt: LISTEN ColId
   11044             :                 {
   11045          74 :                     ListenStmt *n = makeNode(ListenStmt);
   11046             : 
   11047          74 :                     n->conditionname = $2;
   11048          74 :                     $$ = (Node *) n;
   11049             :                 }
   11050             :         ;
   11051             : 
   11052             : UnlistenStmt:
   11053             :             UNLISTEN ColId
   11054             :                 {
   11055           6 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   11056             : 
   11057           6 :                     n->conditionname = $2;
   11058           6 :                     $$ = (Node *) n;
   11059             :                 }
   11060             :             | UNLISTEN '*'
   11061             :                 {
   11062          32 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   11063             : 
   11064          32 :                     n->conditionname = NULL;
   11065          32 :                     $$ = (Node *) n;
   11066             :                 }
   11067             :         ;
   11068             : 
   11069             : 
   11070             : /*****************************************************************************
   11071             :  *
   11072             :  *      Transactions:
   11073             :  *
   11074             :  *      BEGIN / COMMIT / ROLLBACK
   11075             :  *      (also older versions END / ABORT)
   11076             :  *
   11077             :  *****************************************************************************/
   11078             : 
   11079             : TransactionStmt:
   11080             :             ABORT_P opt_transaction opt_transaction_chain
   11081             :                 {
   11082         204 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11083             : 
   11084         204 :                     n->kind = TRANS_STMT_ROLLBACK;
   11085         204 :                     n->options = NIL;
   11086         204 :                     n->chain = $3;
   11087         204 :                     n->location = -1;
   11088         204 :                     $$ = (Node *) n;
   11089             :                 }
   11090             :             | START TRANSACTION transaction_mode_list_or_empty
   11091             :                 {
   11092        1578 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11093             : 
   11094        1578 :                     n->kind = TRANS_STMT_START;
   11095        1578 :                     n->options = $3;
   11096        1578 :                     n->location = -1;
   11097        1578 :                     $$ = (Node *) n;
   11098             :                 }
   11099             :             | COMMIT opt_transaction opt_transaction_chain
   11100             :                 {
   11101       11494 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11102             : 
   11103       11494 :                     n->kind = TRANS_STMT_COMMIT;
   11104       11494 :                     n->options = NIL;
   11105       11494 :                     n->chain = $3;
   11106       11494 :                     n->location = -1;
   11107       11494 :                     $$ = (Node *) n;
   11108             :                 }
   11109             :             | ROLLBACK opt_transaction opt_transaction_chain
   11110             :                 {
   11111        2376 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11112             : 
   11113        2376 :                     n->kind = TRANS_STMT_ROLLBACK;
   11114        2376 :                     n->options = NIL;
   11115        2376 :                     n->chain = $3;
   11116        2376 :                     n->location = -1;
   11117        2376 :                     $$ = (Node *) n;
   11118             :                 }
   11119             :             | SAVEPOINT ColId
   11120             :                 {
   11121        2016 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11122             : 
   11123        2016 :                     n->kind = TRANS_STMT_SAVEPOINT;
   11124        2016 :                     n->savepoint_name = $2;
   11125        2016 :                     n->location = @2;
   11126        2016 :                     $$ = (Node *) n;
   11127             :                 }
   11128             :             | RELEASE SAVEPOINT ColId
   11129             :                 {
   11130         208 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11131             : 
   11132         208 :                     n->kind = TRANS_STMT_RELEASE;
   11133         208 :                     n->savepoint_name = $3;
   11134         208 :                     n->location = @3;
   11135         208 :                     $$ = (Node *) n;
   11136             :                 }
   11137             :             | RELEASE ColId
   11138             :                 {
   11139          86 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11140             : 
   11141          86 :                     n->kind = TRANS_STMT_RELEASE;
   11142          86 :                     n->savepoint_name = $2;
   11143          86 :                     n->location = @2;
   11144          86 :                     $$ = (Node *) n;
   11145             :                 }
   11146             :             | ROLLBACK opt_transaction TO SAVEPOINT ColId
   11147             :                 {
   11148         218 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11149             : 
   11150         218 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   11151         218 :                     n->savepoint_name = $5;
   11152         218 :                     n->location = @5;
   11153         218 :                     $$ = (Node *) n;
   11154             :                 }
   11155             :             | ROLLBACK opt_transaction TO ColId
   11156             :                 {
   11157         494 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11158             : 
   11159         494 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   11160         494 :                     n->savepoint_name = $4;
   11161         494 :                     n->location = @4;
   11162         494 :                     $$ = (Node *) n;
   11163             :                 }
   11164             :             | PREPARE TRANSACTION Sconst
   11165             :                 {
   11166         798 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11167             : 
   11168         798 :                     n->kind = TRANS_STMT_PREPARE;
   11169         798 :                     n->gid = $3;
   11170         798 :                     n->location = @3;
   11171         798 :                     $$ = (Node *) n;
   11172             :                 }
   11173             :             | COMMIT PREPARED Sconst
   11174             :                 {
   11175         644 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11176             : 
   11177         644 :                     n->kind = TRANS_STMT_COMMIT_PREPARED;
   11178         644 :                     n->gid = $3;
   11179         644 :                     n->location = @3;
   11180         644 :                     $$ = (Node *) n;
   11181             :                 }
   11182             :             | ROLLBACK PREPARED Sconst
   11183             :                 {
   11184          74 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11185             : 
   11186          74 :                     n->kind = TRANS_STMT_ROLLBACK_PREPARED;
   11187          74 :                     n->gid = $3;
   11188          74 :                     n->location = @3;
   11189          74 :                     $$ = (Node *) n;
   11190             :                 }
   11191             :         ;
   11192             : 
   11193             : TransactionStmtLegacy:
   11194             :             BEGIN_P opt_transaction transaction_mode_list_or_empty
   11195             :                 {
   11196       13938 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11197             : 
   11198       13938 :                     n->kind = TRANS_STMT_BEGIN;
   11199       13938 :                     n->options = $3;
   11200       13938 :                     n->location = -1;
   11201       13938 :                     $$ = (Node *) n;
   11202             :                 }
   11203             :             | END_P opt_transaction opt_transaction_chain
   11204             :                 {
   11205         360 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11206             : 
   11207         360 :                     n->kind = TRANS_STMT_COMMIT;
   11208         360 :                     n->options = NIL;
   11209         360 :                     n->chain = $3;
   11210         360 :                     n->location = -1;
   11211         360 :                     $$ = (Node *) n;
   11212             :                 }
   11213             :         ;
   11214             : 
   11215             : opt_transaction:    WORK
   11216             :             | TRANSACTION
   11217             :             | /*EMPTY*/
   11218             :         ;
   11219             : 
   11220             : transaction_mode_item:
   11221             :             ISOLATION LEVEL iso_level
   11222        6560 :                     { $$ = makeDefElem("transaction_isolation",
   11223        6560 :                                        makeStringConst($3, @3), @1); }
   11224             :             | READ ONLY
   11225        1288 :                     { $$ = makeDefElem("transaction_read_only",
   11226        1288 :                                        makeIntConst(true, @1), @1); }
   11227             :             | READ WRITE
   11228          88 :                     { $$ = makeDefElem("transaction_read_only",
   11229          88 :                                        makeIntConst(false, @1), @1); }
   11230             :             | DEFERRABLE
   11231          44 :                     { $$ = makeDefElem("transaction_deferrable",
   11232             :                                        makeIntConst(true, @1), @1); }
   11233             :             | NOT DEFERRABLE
   11234          10 :                     { $$ = makeDefElem("transaction_deferrable",
   11235          10 :                                        makeIntConst(false, @1), @1); }
   11236             :         ;
   11237             : 
   11238             : /* Syntax with commas is SQL-spec, without commas is Postgres historical */
   11239             : transaction_mode_list:
   11240             :             transaction_mode_item
   11241        6770 :                     { $$ = list_make1($1); }
   11242             :             | transaction_mode_list ',' transaction_mode_item
   11243         870 :                     { $$ = lappend($1, $3); }
   11244             :             | transaction_mode_list transaction_mode_item
   11245         350 :                     { $$ = lappend($1, $2); }
   11246             :         ;
   11247             : 
   11248             : transaction_mode_list_or_empty:
   11249             :             transaction_mode_list
   11250             :             | /* EMPTY */
   11251        9274 :                     { $$ = NIL; }
   11252             :         ;
   11253             : 
   11254             : opt_transaction_chain:
   11255         120 :             AND CHAIN       { $$ = true; }
   11256           2 :             | AND NO CHAIN  { $$ = false; }
   11257       14312 :             | /* EMPTY */   { $$ = false; }
   11258             :         ;
   11259             : 
   11260             : 
   11261             : /*****************************************************************************
   11262             :  *
   11263             :  *  QUERY:
   11264             :  *      CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
   11265             :  *          AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
   11266             :  *
   11267             :  *****************************************************************************/
   11268             : 
   11269             : ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11270             :                 AS SelectStmt opt_check_option
   11271             :                 {
   11272       13392 :                     ViewStmt   *n = makeNode(ViewStmt);
   11273             : 
   11274       13392 :                     n->view = $4;
   11275       13392 :                     n->view->relpersistence = $2;
   11276       13392 :                     n->aliases = $5;
   11277       13392 :                     n->query = $8;
   11278       13392 :                     n->replace = false;
   11279       13392 :                     n->options = $6;
   11280       13392 :                     n->withCheckOption = $9;
   11281       13392 :                     $$ = (Node *) n;
   11282             :                 }
   11283             :         | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11284             :                 AS SelectStmt opt_check_option
   11285             :                 {
   11286         244 :                     ViewStmt   *n = makeNode(ViewStmt);
   11287             : 
   11288         244 :                     n->view = $6;
   11289         244 :                     n->view->relpersistence = $4;
   11290         244 :                     n->aliases = $7;
   11291         244 :                     n->query = $10;
   11292         244 :                     n->replace = true;
   11293         244 :                     n->options = $8;
   11294         244 :                     n->withCheckOption = $11;
   11295         244 :                     $$ = (Node *) n;
   11296             :                 }
   11297             :         | CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11298             :                 AS SelectStmt opt_check_option
   11299             :                 {
   11300           8 :                     ViewStmt   *n = makeNode(ViewStmt);
   11301             : 
   11302           8 :                     n->view = $5;
   11303           8 :                     n->view->relpersistence = $2;
   11304           8 :                     n->aliases = $7;
   11305           8 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
   11306           8 :                     n->replace = false;
   11307           8 :                     n->options = $9;
   11308           8 :                     n->withCheckOption = $12;
   11309           8 :                     if (n->withCheckOption != NO_CHECK_OPTION)
   11310           0 :                         ereport(ERROR,
   11311             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   11312             :                                  errmsg("WITH CHECK OPTION not supported on recursive views"),
   11313             :                                  parser_errposition(@12)));
   11314           8 :                     $$ = (Node *) n;
   11315             :                 }
   11316             :         | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11317             :                 AS SelectStmt opt_check_option
   11318             :                 {
   11319           6 :                     ViewStmt   *n = makeNode(ViewStmt);
   11320             : 
   11321           6 :                     n->view = $7;
   11322           6 :                     n->view->relpersistence = $4;
   11323           6 :                     n->aliases = $9;
   11324           6 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
   11325           6 :                     n->replace = true;
   11326           6 :                     n->options = $11;
   11327           6 :                     n->withCheckOption = $14;
   11328           6 :                     if (n->withCheckOption != NO_CHECK_OPTION)
   11329           0 :                         ereport(ERROR,
   11330             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   11331             :                                  errmsg("WITH CHECK OPTION not supported on recursive views"),
   11332             :                                  parser_errposition(@14)));
   11333           6 :                     $$ = (Node *) n;
   11334             :                 }
   11335             :         ;
   11336             : 
   11337             : opt_check_option:
   11338          90 :         WITH CHECK OPTION               { $$ = CASCADED_CHECK_OPTION; }
   11339           6 :         | WITH CASCADED CHECK OPTION    { $$ = CASCADED_CHECK_OPTION; }
   11340          24 :         | WITH LOCAL CHECK OPTION       { $$ = LOCAL_CHECK_OPTION; }
   11341       13530 :         | /* EMPTY */                   { $$ = NO_CHECK_OPTION; }
   11342             :         ;
   11343             : 
   11344             : /*****************************************************************************
   11345             :  *
   11346             :  *      QUERY:
   11347             :  *              LOAD "filename"
   11348             :  *
   11349             :  *****************************************************************************/
   11350             : 
   11351             : LoadStmt:   LOAD file_name
   11352             :                 {
   11353          58 :                     LoadStmt   *n = makeNode(LoadStmt);
   11354             : 
   11355          58 :                     n->filename = $2;
   11356          58 :                     $$ = (Node *) n;
   11357             :                 }
   11358             :         ;
   11359             : 
   11360             : 
   11361             : /*****************************************************************************
   11362             :  *
   11363             :  *      CREATE DATABASE
   11364             :  *
   11365             :  *****************************************************************************/
   11366             : 
   11367             : CreatedbStmt:
   11368             :             CREATE DATABASE name opt_with createdb_opt_list
   11369             :                 {
   11370         640 :                     CreatedbStmt *n = makeNode(CreatedbStmt);
   11371             : 
   11372         640 :                     n->dbname = $3;
   11373         640 :                     n->options = $5;
   11374         640 :                     $$ = (Node *) n;
   11375             :                 }
   11376             :         ;
   11377             : 
   11378             : createdb_opt_list:
   11379         490 :             createdb_opt_items                      { $$ = $1; }
   11380         174 :             | /* EMPTY */                           { $$ = NIL; }
   11381             :         ;
   11382             : 
   11383             : createdb_opt_items:
   11384         490 :             createdb_opt_item                       { $$ = list_make1($1); }
   11385         638 :             | createdb_opt_items createdb_opt_item  { $$ = lappend($1, $2); }
   11386             :         ;
   11387             : 
   11388             : createdb_opt_item:
   11389             :             createdb_opt_name opt_equal NumericOnly
   11390             :                 {
   11391         184 :                     $$ = makeDefElem($1, $3, @1);
   11392             :                 }
   11393             :             | createdb_opt_name opt_equal opt_boolean_or_string
   11394             :                 {
   11395         944 :                     $$ = makeDefElem($1, (Node *) makeString($3), @1);
   11396             :                 }
   11397             :             | createdb_opt_name opt_equal DEFAULT
   11398             :                 {
   11399           0 :                     $$ = makeDefElem($1, NULL, @1);
   11400             :                 }
   11401             :         ;
   11402             : 
   11403             : /*
   11404             :  * Ideally we'd use ColId here, but that causes shift/reduce conflicts against
   11405             :  * the ALTER DATABASE SET/RESET syntaxes.  Instead call out specific keywords
   11406             :  * we need, and allow IDENT so that database option names don't have to be
   11407             :  * parser keywords unless they are already keywords for other reasons.
   11408             :  *
   11409             :  * XXX this coding technique is fragile since if someone makes a formerly
   11410             :  * non-keyword option name into a keyword and forgets to add it here, the
   11411             :  * option will silently break.  Best defense is to provide a regression test
   11412             :  * exercising every such option, at least at the syntax level.
   11413             :  */
   11414             : createdb_opt_name:
   11415         768 :             IDENT                           { $$ = $1; }
   11416           2 :             | CONNECTION LIMIT              { $$ = pstrdup("connection_limit"); }
   11417          60 :             | ENCODING                      { $$ = pstrdup($1); }
   11418           0 :             | LOCATION                      { $$ = pstrdup($1); }
   11419           2 :             | OWNER                         { $$ = pstrdup($1); }
   11420          16 :             | TABLESPACE                    { $$ = pstrdup($1); }
   11421         280 :             | TEMPLATE                      { $$ = pstrdup($1); }
   11422             :         ;
   11423             : 
   11424             : /*
   11425             :  *  Though the equals sign doesn't match other WITH options, pg_dump uses
   11426             :  *  equals for backward compatibility, and it doesn't seem worth removing it.
   11427             :  */
   11428             : opt_equal:  '='
   11429             :             | /*EMPTY*/
   11430             :         ;
   11431             : 
   11432             : 
   11433             : /*****************************************************************************
   11434             :  *
   11435             :  *      ALTER DATABASE
   11436             :  *
   11437             :  *****************************************************************************/
   11438             : 
   11439             : AlterDatabaseStmt:
   11440             :             ALTER DATABASE name WITH createdb_opt_list
   11441             :                  {
   11442           0 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11443             : 
   11444           0 :                     n->dbname = $3;
   11445           0 :                     n->options = $5;
   11446           0 :                     $$ = (Node *) n;
   11447             :                  }
   11448             :             | ALTER DATABASE name createdb_opt_list
   11449             :                  {
   11450          24 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11451             : 
   11452          24 :                     n->dbname = $3;
   11453          24 :                     n->options = $4;
   11454          24 :                     $$ = (Node *) n;
   11455             :                  }
   11456             :             | ALTER DATABASE name SET TABLESPACE name
   11457             :                  {
   11458          10 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11459             : 
   11460          10 :                     n->dbname = $3;
   11461          10 :                     n->options = list_make1(makeDefElem("tablespace",
   11462             :                                                         (Node *) makeString($6), @6));
   11463          10 :                     $$ = (Node *) n;
   11464             :                  }
   11465             :             | ALTER DATABASE name REFRESH COLLATION VERSION_P
   11466             :                  {
   11467           6 :                     AlterDatabaseRefreshCollStmt *n = makeNode(AlterDatabaseRefreshCollStmt);
   11468             : 
   11469           6 :                     n->dbname = $3;
   11470           6 :                     $$ = (Node *) n;
   11471             :                  }
   11472             :         ;
   11473             : 
   11474             : AlterDatabaseSetStmt:
   11475             :             ALTER DATABASE name SetResetClause
   11476             :                 {
   11477        1058 :                     AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
   11478             : 
   11479        1058 :                     n->dbname = $3;
   11480        1058 :                     n->setstmt = $4;
   11481        1058 :                     $$ = (Node *) n;
   11482             :                 }
   11483             :         ;
   11484             : 
   11485             : 
   11486             : /*****************************************************************************
   11487             :  *
   11488             :  *      DROP DATABASE [ IF EXISTS ] dbname [ [ WITH ] ( options ) ]
   11489             :  *
   11490             :  * This is implicitly CASCADE, no need for drop behavior
   11491             :  *****************************************************************************/
   11492             : 
   11493             : DropdbStmt: DROP DATABASE name
   11494             :                 {
   11495          64 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11496             : 
   11497          64 :                     n->dbname = $3;
   11498          64 :                     n->missing_ok = false;
   11499          64 :                     n->options = NULL;
   11500          64 :                     $$ = (Node *) n;
   11501             :                 }
   11502             :             | DROP DATABASE IF_P EXISTS name
   11503             :                 {
   11504           4 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11505             : 
   11506           4 :                     n->dbname = $5;
   11507           4 :                     n->missing_ok = true;
   11508           4 :                     n->options = NULL;
   11509           4 :                     $$ = (Node *) n;
   11510             :                 }
   11511             :             | DROP DATABASE name opt_with '(' drop_option_list ')'
   11512             :                 {
   11513          14 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11514             : 
   11515          14 :                     n->dbname = $3;
   11516          14 :                     n->missing_ok = false;
   11517          14 :                     n->options = $6;
   11518          14 :                     $$ = (Node *) n;
   11519             :                 }
   11520             :             | DROP DATABASE IF_P EXISTS name opt_with '(' drop_option_list ')'
   11521             :                 {
   11522          12 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11523             : 
   11524          12 :                     n->dbname = $5;
   11525          12 :                     n->missing_ok = true;
   11526          12 :                     n->options = $8;
   11527          12 :                     $$ = (Node *) n;
   11528             :                 }
   11529             :         ;
   11530             : 
   11531             : drop_option_list:
   11532             :             drop_option
   11533             :                 {
   11534          26 :                     $$ = list_make1((Node *) $1);
   11535             :                 }
   11536             :             | drop_option_list ',' drop_option
   11537             :                 {
   11538           0 :                     $$ = lappend($1, (Node *) $3);
   11539             :                 }
   11540             :         ;
   11541             : 
   11542             : /*
   11543             :  * Currently only the FORCE option is supported, but the syntax is designed
   11544             :  * to be extensible so that we can add more options in the future if required.
   11545             :  */
   11546             : drop_option:
   11547             :             FORCE
   11548             :                 {
   11549          26 :                     $$ = makeDefElem("force", NULL, @1);
   11550             :                 }
   11551             :         ;
   11552             : 
   11553             : /*****************************************************************************
   11554             :  *
   11555             :  *      ALTER COLLATION
   11556             :  *
   11557             :  *****************************************************************************/
   11558             : 
   11559             : AlterCollationStmt: ALTER COLLATION any_name REFRESH VERSION_P
   11560             :                 {
   11561           6 :                     AlterCollationStmt *n = makeNode(AlterCollationStmt);
   11562             : 
   11563           6 :                     n->collname = $3;
   11564           6 :                     $$ = (Node *) n;
   11565             :                 }
   11566             :         ;
   11567             : 
   11568             : 
   11569             : /*****************************************************************************
   11570             :  *
   11571             :  *      ALTER SYSTEM
   11572             :  *
   11573             :  * This is used to change configuration parameters persistently.
   11574             :  *****************************************************************************/
   11575             : 
   11576             : AlterSystemStmt:
   11577             :             ALTER SYSTEM_P SET generic_set
   11578             :                 {
   11579         106 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11580             : 
   11581         106 :                     n->setstmt = $4;
   11582         106 :                     $$ = (Node *) n;
   11583             :                 }
   11584             :             | ALTER SYSTEM_P RESET generic_reset
   11585             :                 {
   11586          48 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11587             : 
   11588          48 :                     n->setstmt = $4;
   11589          48 :                     $$ = (Node *) n;
   11590             :                 }
   11591             :         ;
   11592             : 
   11593             : 
   11594             : /*****************************************************************************
   11595             :  *
   11596             :  * Manipulate a domain
   11597             :  *
   11598             :  *****************************************************************************/
   11599             : 
   11600             : CreateDomainStmt:
   11601             :             CREATE DOMAIN_P any_name opt_as Typename ColQualList
   11602             :                 {
   11603        1162 :                     CreateDomainStmt *n = makeNode(CreateDomainStmt);
   11604             : 
   11605        1162 :                     n->domainname = $3;
   11606        1162 :                     n->typeName = $5;
   11607        1162 :                     SplitColQualList($6, &n->constraints, &n->collClause,
   11608             :                                      yyscanner);
   11609        1162 :                     $$ = (Node *) n;
   11610             :                 }
   11611             :         ;
   11612             : 
   11613             : AlterDomainStmt:
   11614             :             /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
   11615             :             ALTER DOMAIN_P any_name alter_column_default
   11616             :                 {
   11617          14 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11618             : 
   11619          14 :                     n->subtype = 'T';
   11620          14 :                     n->typeName = $3;
   11621          14 :                     n->def = $4;
   11622          14 :                     $$ = (Node *) n;
   11623             :                 }
   11624             :             /* ALTER DOMAIN <domain> DROP NOT NULL */
   11625             :             | ALTER DOMAIN_P any_name DROP NOT NULL_P
   11626             :                 {
   11627          12 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11628             : 
   11629          12 :                     n->subtype = 'N';
   11630          12 :                     n->typeName = $3;
   11631          12 :                     $$ = (Node *) n;
   11632             :                 }
   11633             :             /* ALTER DOMAIN <domain> SET NOT NULL */
   11634             :             | ALTER DOMAIN_P any_name SET NOT NULL_P
   11635             :                 {
   11636          24 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11637             : 
   11638          24 :                     n->subtype = 'O';
   11639          24 :                     n->typeName = $3;
   11640          24 :                     $$ = (Node *) n;
   11641             :                 }
   11642             :             /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
   11643             :             | ALTER DOMAIN_P any_name ADD_P DomainConstraint
   11644             :                 {
   11645         168 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11646             : 
   11647         168 :                     n->subtype = 'C';
   11648         168 :                     n->typeName = $3;
   11649         168 :                     n->def = $5;
   11650         168 :                     $$ = (Node *) n;
   11651             :                 }
   11652             :             /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
   11653             :             | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
   11654             :                 {
   11655          48 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11656             : 
   11657          48 :                     n->subtype = 'X';
   11658          48 :                     n->typeName = $3;
   11659          48 :                     n->name = $6;
   11660          48 :                     n->behavior = $7;
   11661          48 :                     n->missing_ok = false;
   11662          48 :                     $$ = (Node *) n;
   11663             :                 }
   11664             :             /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
   11665             :             | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
   11666             :                 {
   11667           6 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11668             : 
   11669           6 :                     n->subtype = 'X';
   11670           6 :                     n->typeName = $3;
   11671           6 :                     n->name = $8;
   11672           6 :                     n->behavior = $9;
   11673           6 :                     n->missing_ok = true;
   11674           6 :                     $$ = (Node *) n;
   11675             :                 }
   11676             :             /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
   11677             :             | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
   11678             :                 {
   11679          12 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11680             : 
   11681          12 :                     n->subtype = 'V';
   11682          12 :                     n->typeName = $3;
   11683          12 :                     n->name = $6;
   11684          12 :                     $$ = (Node *) n;
   11685             :                 }
   11686             :             ;
   11687             : 
   11688             : opt_as:     AS
   11689             :             | /* EMPTY */
   11690             :         ;
   11691             : 
   11692             : 
   11693             : /*****************************************************************************
   11694             :  *
   11695             :  * Manipulate a text search dictionary or configuration
   11696             :  *
   11697             :  *****************************************************************************/
   11698             : 
   11699             : AlterTSDictionaryStmt:
   11700             :             ALTER TEXT_P SEARCH DICTIONARY any_name definition
   11701             :                 {
   11702          40 :                     AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
   11703             : 
   11704          40 :                     n->dictname = $5;
   11705          40 :                     n->options = $6;
   11706          40 :                     $$ = (Node *) n;
   11707             :                 }
   11708             :         ;
   11709             : 
   11710             : AlterTSConfigurationStmt:
   11711             :             ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
   11712             :                 {
   11713        6550 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11714             : 
   11715        6550 :                     n->kind = ALTER_TSCONFIG_ADD_MAPPING;
   11716        6550 :                     n->cfgname = $5;
   11717        6550 :                     n->tokentype = $9;
   11718        6550 :                     n->dicts = $11;
   11719        6550 :                     n->override = false;
   11720        6550 :                     n->replace = false;
   11721        6550 :                     $$ = (Node *) n;
   11722             :                 }
   11723             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
   11724             :                 {
   11725          26 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11726             : 
   11727          26 :                     n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
   11728          26 :                     n->cfgname = $5;
   11729          26 :                     n->tokentype = $9;
   11730          26 :                     n->dicts = $11;
   11731          26 :                     n->override = true;
   11732          26 :                     n->replace = false;
   11733          26 :                     $$ = (Node *) n;
   11734             :                 }
   11735             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
   11736             :                 {
   11737          18 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11738             : 
   11739          18 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT;
   11740          18 :                     n->cfgname = $5;
   11741          18 :                     n->tokentype = NIL;
   11742          18 :                     n->dicts = list_make2($9,$11);
   11743          18 :                     n->override = false;
   11744          18 :                     n->replace = true;
   11745          18 :                     $$ = (Node *) n;
   11746             :                 }
   11747             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
   11748             :                 {
   11749           0 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11750             : 
   11751           0 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN;
   11752           0 :                     n->cfgname = $5;
   11753           0 :                     n->tokentype = $9;
   11754           0 :                     n->dicts = list_make2($11,$13);
   11755           0 :                     n->override = false;
   11756           0 :                     n->replace = true;
   11757           0 :                     $$ = (Node *) n;
   11758             :                 }
   11759             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
   11760             :                 {
   11761          18 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11762             : 
   11763          18 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   11764          18 :                     n->cfgname = $5;
   11765          18 :                     n->tokentype = $9;
   11766          18 :                     n->missing_ok = false;
   11767          18 :                     $$ = (Node *) n;
   11768             :                 }
   11769             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
   11770             :                 {
   11771          12 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11772             : 
   11773          12 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   11774          12 :                     n->cfgname = $5;
   11775          12 :                     n->tokentype = $11;
   11776          12 :                     n->missing_ok = true;
   11777          12 :                     $$ = (Node *) n;
   11778             :                 }
   11779             :         ;
   11780             : 
   11781             : /* Use this if TIME or ORDINALITY after WITH should be taken as an identifier */
   11782             : any_with:   WITH
   11783             :             | WITH_LA
   11784             :         ;
   11785             : 
   11786             : 
   11787             : /*****************************************************************************
   11788             :  *
   11789             :  * Manipulate a conversion
   11790             :  *
   11791             :  *      CREATE [DEFAULT] CONVERSION <conversion_name>
   11792             :  *      FOR <encoding_name> TO <encoding_name> FROM <func_name>
   11793             :  *
   11794             :  *****************************************************************************/
   11795             : 
   11796             : CreateConversionStmt:
   11797             :             CREATE opt_default CONVERSION_P any_name FOR Sconst
   11798             :             TO Sconst FROM any_name
   11799             :             {
   11800          64 :                 CreateConversionStmt *n = makeNode(CreateConversionStmt);
   11801             : 
   11802          64 :                 n->conversion_name = $4;
   11803          64 :                 n->for_encoding_name = $6;
   11804          64 :                 n->to_encoding_name = $8;
   11805          64 :                 n->func_name = $10;
   11806          64 :                 n->def = $2;
   11807          64 :                 $$ = (Node *) n;
   11808             :             }
   11809             :         ;
   11810             : 
   11811             : /*****************************************************************************
   11812             :  *
   11813             :  *      QUERY:
   11814             :  *              CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
   11815             :  *              CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
   11816             :  *              CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
   11817             :  *
   11818             :  *****************************************************************************/
   11819             : 
   11820             : ClusterStmt:
   11821             :             CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
   11822             :                 {
   11823           0 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11824             : 
   11825           0 :                     n->relation = $5;
   11826           0 :                     n->indexname = $6;
   11827           0 :                     n->params = $3;
   11828           0 :                     $$ = (Node *) n;
   11829             :                 }
   11830             :             | CLUSTER '(' utility_option_list ')'
   11831             :                 {
   11832           0 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11833             : 
   11834           0 :                     n->relation = NULL;
   11835           0 :                     n->indexname = NULL;
   11836           0 :                     n->params = $3;
   11837           0 :                     $$ = (Node *) n;
   11838             :                 }
   11839             :             /* unparenthesized VERBOSE kept for pre-14 compatibility */
   11840             :             | CLUSTER opt_verbose qualified_name cluster_index_specification
   11841             :                 {
   11842         190 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11843             : 
   11844         190 :                     n->relation = $3;
   11845         190 :                     n->indexname = $4;
   11846         190 :                     n->params = NIL;
   11847         190 :                     if ($2)
   11848           0 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11849         190 :                     $$ = (Node *) n;
   11850             :                 }
   11851             :             /* unparenthesized VERBOSE kept for pre-17 compatibility */
   11852             :             | CLUSTER opt_verbose
   11853             :                 {
   11854          30 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11855             : 
   11856          30 :                     n->relation = NULL;
   11857          30 :                     n->indexname = NULL;
   11858          30 :                     n->params = NIL;
   11859          30 :                     if ($2)
   11860          14 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11861          30 :                     $$ = (Node *) n;
   11862             :                 }
   11863             :             /* kept for pre-8.3 compatibility */
   11864             :             | CLUSTER opt_verbose name ON qualified_name
   11865             :                 {
   11866          18 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11867             : 
   11868          18 :                     n->relation = $5;
   11869          18 :                     n->indexname = $3;
   11870          18 :                     n->params = NIL;
   11871          18 :                     if ($2)
   11872           0 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11873          18 :                     $$ = (Node *) n;
   11874             :                 }
   11875             :         ;
   11876             : 
   11877             : cluster_index_specification:
   11878         156 :             USING name              { $$ = $2; }
   11879          34 :             | /*EMPTY*/             { $$ = NULL; }
   11880             :         ;
   11881             : 
   11882             : 
   11883             : /*****************************************************************************
   11884             :  *
   11885             :  *      QUERY:
   11886             :  *              VACUUM
   11887             :  *              ANALYZE
   11888             :  *
   11889             :  *****************************************************************************/
   11890             : 
   11891             : VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relation_list
   11892             :                 {
   11893        1052 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11894             : 
   11895        1052 :                     n->options = NIL;
   11896        1052 :                     if ($2)
   11897         116 :                         n->options = lappend(n->options,
   11898         116 :                                              makeDefElem("full", NULL, @2));
   11899        1052 :                     if ($3)
   11900         142 :                         n->options = lappend(n->options,
   11901         142 :                                              makeDefElem("freeze", NULL, @3));
   11902        1052 :                     if ($4)
   11903          18 :                         n->options = lappend(n->options,
   11904          18 :                                              makeDefElem("verbose", NULL, @4));
   11905        1052 :                     if ($5)
   11906         272 :                         n->options = lappend(n->options,
   11907         272 :                                              makeDefElem("analyze", NULL, @5));
   11908        1052 :                     n->rels = $6;
   11909        1052 :                     n->is_vacuumcmd = true;
   11910        1052 :                     $$ = (Node *) n;
   11911             :                 }
   11912             :             | VACUUM '(' utility_option_list ')' opt_vacuum_relation_list
   11913             :                 {
   11914        4954 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11915             : 
   11916        4954 :                     n->options = $3;
   11917        4954 :                     n->rels = $5;
   11918        4954 :                     n->is_vacuumcmd = true;
   11919        4954 :                     $$ = (Node *) n;
   11920             :                 }
   11921             :         ;
   11922             : 
   11923             : AnalyzeStmt: analyze_keyword opt_verbose opt_vacuum_relation_list
   11924             :                 {
   11925        4258 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11926             : 
   11927        4258 :                     n->options = NIL;
   11928        4258 :                     if ($2)
   11929           0 :                         n->options = lappend(n->options,
   11930           0 :                                              makeDefElem("verbose", NULL, @2));
   11931        4258 :                     n->rels = $3;
   11932        4258 :                     n->is_vacuumcmd = false;
   11933        4258 :                     $$ = (Node *) n;
   11934             :                 }
   11935             :             | analyze_keyword '(' utility_option_list ')' opt_vacuum_relation_list
   11936             :                 {
   11937         186 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11938             : 
   11939         186 :                     n->options = $3;
   11940         186 :                     n->rels = $5;
   11941         186 :                     n->is_vacuumcmd = false;
   11942         186 :                     $$ = (Node *) n;
   11943             :                 }
   11944             :         ;
   11945             : 
   11946             : utility_option_list:
   11947             :             utility_option_elem
   11948             :                 {
   11949       17176 :                     $$ = list_make1($1);
   11950             :                 }
   11951             :             | utility_option_list ',' utility_option_elem
   11952             :                 {
   11953        8076 :                     $$ = lappend($1, $3);
   11954             :                 }
   11955             :         ;
   11956             : 
   11957             : analyze_keyword:
   11958             :             ANALYZE
   11959             :             | ANALYSE /* British */
   11960             :         ;
   11961             : 
   11962             : utility_option_elem:
   11963             :             utility_option_name utility_option_arg
   11964             :                 {
   11965       25252 :                     $$ = makeDefElem($1, $2, @1);
   11966             :                 }
   11967             :         ;
   11968             : 
   11969             : utility_option_name:
   11970       22998 :             NonReservedWord                         { $$ = $1; }
   11971        2112 :             | analyze_keyword                       { $$ = "analyze"; }
   11972         148 :             | FORMAT_LA                             { $$ = "format"; }
   11973             :         ;
   11974             : 
   11975             : utility_option_arg:
   11976       14220 :             opt_boolean_or_string                   { $$ = (Node *) makeString($1); }
   11977         368 :             | NumericOnly                           { $$ = (Node *) $1; }
   11978       10664 :             | /* EMPTY */                           { $$ = NULL; }
   11979             :         ;
   11980             : 
   11981             : opt_analyze:
   11982         272 :             analyze_keyword                         { $$ = true; }
   11983         780 :             | /*EMPTY*/                             { $$ = false; }
   11984             :         ;
   11985             : 
   11986             : opt_verbose:
   11987          32 :             VERBOSE                                 { $$ = true; }
   11988        7808 :             | /*EMPTY*/                             { $$ = false; }
   11989             :         ;
   11990             : 
   11991         116 : opt_full:   FULL                                    { $$ = true; }
   11992         936 :             | /*EMPTY*/                             { $$ = false; }
   11993             :         ;
   11994             : 
   11995         142 : opt_freeze: FREEZE                                  { $$ = true; }
   11996         910 :             | /*EMPTY*/                             { $$ = false; }
   11997             :         ;
   11998             : 
   11999             : opt_name_list:
   12000        2444 :             '(' name_list ')'                       { $$ = $2; }
   12001       12330 :             | /*EMPTY*/                             { $$ = NIL; }
   12002             :         ;
   12003             : 
   12004             : vacuum_relation:
   12005             :             qualified_name opt_name_list
   12006             :                 {
   12007       10306 :                     $$ = (Node *) makeVacuumRelation($1, InvalidOid, $2);
   12008             :                 }
   12009             :         ;
   12010             : 
   12011             : vacuum_relation_list:
   12012             :             vacuum_relation
   12013       10158 :                     { $$ = list_make1($1); }
   12014             :             | vacuum_relation_list ',' vacuum_relation
   12015         148 :                     { $$ = lappend($1, $3); }
   12016             :         ;
   12017             : 
   12018             : opt_vacuum_relation_list:
   12019       10158 :             vacuum_relation_list                    { $$ = $1; }
   12020         292 :             | /*EMPTY*/                             { $$ = NIL; }
   12021             :         ;
   12022             : 
   12023             : 
   12024             : /*****************************************************************************
   12025             :  *
   12026             :  *      QUERY:
   12027             :  *              EXPLAIN [ANALYZE] [VERBOSE] query
   12028             :  *              EXPLAIN ( options ) query
   12029             :  *
   12030             :  *****************************************************************************/
   12031             : 
   12032             : ExplainStmt:
   12033             :         EXPLAIN ExplainableStmt
   12034             :                 {
   12035        7638 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12036             : 
   12037        7638 :                     n->query = $2;
   12038        7638 :                     n->options = NIL;
   12039        7638 :                     $$ = (Node *) n;
   12040             :                 }
   12041             :         | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
   12042             :                 {
   12043        2292 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12044             : 
   12045        2292 :                     n->query = $4;
   12046        2292 :                     n->options = list_make1(makeDefElem("analyze", NULL, @2));
   12047        2292 :                     if ($3)
   12048           0 :                         n->options = lappend(n->options,
   12049           0 :                                              makeDefElem("verbose", NULL, @3));
   12050        2292 :                     $$ = (Node *) n;
   12051             :                 }
   12052             :         | EXPLAIN VERBOSE ExplainableStmt
   12053             :                 {
   12054           0 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12055             : 
   12056           0 :                     n->query = $3;
   12057           0 :                     n->options = list_make1(makeDefElem("verbose", NULL, @2));
   12058           0 :                     $$ = (Node *) n;
   12059             :                 }
   12060             :         | EXPLAIN '(' utility_option_list ')' ExplainableStmt
   12061             :                 {
   12062       11880 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12063             : 
   12064       11880 :                     n->query = $5;
   12065       11880 :                     n->options = $3;
   12066       11880 :                     $$ = (Node *) n;
   12067             :                 }
   12068             :         ;
   12069             : 
   12070             : ExplainableStmt:
   12071             :             SelectStmt
   12072             :             | InsertStmt
   12073             :             | UpdateStmt
   12074             :             | DeleteStmt
   12075             :             | MergeStmt
   12076             :             | DeclareCursorStmt
   12077             :             | CreateAsStmt
   12078             :             | CreateMatViewStmt
   12079             :             | RefreshMatViewStmt
   12080             :             | ExecuteStmt                   /* by default all are $$=$1 */
   12081             :         ;
   12082             : 
   12083             : /*****************************************************************************
   12084             :  *
   12085             :  *      QUERY:
   12086             :  *              PREPARE <plan_name> [(args, ...)] AS <query>
   12087             :  *
   12088             :  *****************************************************************************/
   12089             : 
   12090             : PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
   12091             :                 {
   12092        1668 :                     PrepareStmt *n = makeNode(PrepareStmt);
   12093             : 
   12094        1668 :                     n->name = $2;
   12095        1668 :                     n->argtypes = $3;
   12096        1668 :                     n->query = $5;
   12097        1668 :                     $$ = (Node *) n;
   12098             :                 }
   12099             :         ;
   12100             : 
   12101        1398 : prep_type_clause: '(' type_list ')'         { $$ = $2; }
   12102         276 :                 | /* EMPTY */               { $$ = NIL; }
   12103             :         ;
   12104             : 
   12105             : PreparableStmt:
   12106             :             SelectStmt
   12107             :             | InsertStmt
   12108             :             | UpdateStmt
   12109             :             | DeleteStmt
   12110             :             | MergeStmt                     /* by default all are $$=$1 */
   12111             :         ;
   12112             : 
   12113             : /*****************************************************************************
   12114             :  *
   12115             :  * EXECUTE <plan_name> [(params, ...)]
   12116             :  * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
   12117             :  *
   12118             :  *****************************************************************************/
   12119             : 
   12120             : ExecuteStmt: EXECUTE name execute_param_clause
   12121             :                 {
   12122       11688 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12123             : 
   12124       11688 :                     n->name = $2;
   12125       11688 :                     n->params = $3;
   12126       11688 :                     $$ = (Node *) n;
   12127             :                 }
   12128             :             | CREATE OptTemp TABLE create_as_target AS
   12129             :                 EXECUTE name execute_param_clause opt_with_data
   12130             :                 {
   12131          72 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   12132          72 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12133             : 
   12134          72 :                     n->name = $7;
   12135          72 :                     n->params = $8;
   12136          72 :                     ctas->query = (Node *) n;
   12137          72 :                     ctas->into = $4;
   12138          72 :                     ctas->objtype = OBJECT_TABLE;
   12139          72 :                     ctas->is_select_into = false;
   12140          72 :                     ctas->if_not_exists = false;
   12141             :                     /* cram additional flags into the IntoClause */
   12142          72 :                     $4->rel->relpersistence = $2;
   12143          72 :                     $4->skipData = !($9);
   12144          72 :                     $$ = (Node *) ctas;
   12145             :                 }
   12146             :             | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS
   12147             :                 EXECUTE name execute_param_clause opt_with_data
   12148             :                 {
   12149          12 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   12150          12 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12151             : 
   12152          12 :                     n->name = $10;
   12153          12 :                     n->params = $11;
   12154          12 :                     ctas->query = (Node *) n;
   12155          12 :                     ctas->into = $7;
   12156          12 :                     ctas->objtype = OBJECT_TABLE;
   12157          12 :                     ctas->is_select_into = false;
   12158          12 :                     ctas->if_not_exists = true;
   12159             :                     /* cram additional flags into the IntoClause */
   12160          12 :                     $7->rel->relpersistence = $2;
   12161          12 :                     $7->skipData = !($12);
   12162          12 :                     $$ = (Node *) ctas;
   12163             :                 }
   12164             :         ;
   12165             : 
   12166       10694 : execute_param_clause: '(' expr_list ')'             { $$ = $2; }
   12167        1078 :                     | /* EMPTY */                   { $$ = NIL; }
   12168             :                     ;
   12169             : 
   12170             : /*****************************************************************************
   12171             :  *
   12172             :  *      QUERY:
   12173             :  *              DEALLOCATE [PREPARE] <plan_name>
   12174             :  *
   12175             :  *****************************************************************************/
   12176             : 
   12177             : DeallocateStmt: DEALLOCATE name
   12178             :                     {
   12179        3964 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12180             : 
   12181        3964 :                         n->name = $2;
   12182        3964 :                         n->isall = false;
   12183        3964 :                         n->location = @2;
   12184        3964 :                         $$ = (Node *) n;
   12185             :                     }
   12186             :                 | DEALLOCATE PREPARE name
   12187             :                     {
   12188          20 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12189             : 
   12190          20 :                         n->name = $3;
   12191          20 :                         n->isall = false;
   12192          20 :                         n->location = @3;
   12193          20 :                         $$ = (Node *) n;
   12194             :                     }
   12195             :                 | DEALLOCATE ALL
   12196             :                     {
   12197          48 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12198             : 
   12199          48 :                         n->name = NULL;
   12200          48 :                         n->isall = true;
   12201          48 :                         n->location = -1;
   12202          48 :                         $$ = (Node *) n;
   12203             :                     }
   12204             :                 | DEALLOCATE PREPARE ALL
   12205             :                     {
   12206           2 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12207             : 
   12208           2 :                         n->name = NULL;
   12209           2 :                         n->isall = true;
   12210           2 :                         n->location = -1;
   12211           2 :                         $$ = (Node *) n;
   12212             :                     }
   12213             :         ;
   12214             : 
   12215             : /*****************************************************************************
   12216             :  *
   12217             :  *      QUERY:
   12218             :  *              INSERT STATEMENTS
   12219             :  *
   12220             :  *****************************************************************************/
   12221             : 
   12222             : InsertStmt:
   12223             :             opt_with_clause INSERT INTO insert_target insert_rest
   12224             :             opt_on_conflict returning_clause
   12225             :                 {
   12226       72520 :                     $5->relation = $4;
   12227       72520 :                     $5->onConflictClause = $6;
   12228       72520 :                     $5->returningList = $7;
   12229       72520 :                     $5->withClause = $1;
   12230       72520 :                     $$ = (Node *) $5;
   12231             :                 }
   12232             :         ;
   12233             : 
   12234             : /*
   12235             :  * Can't easily make AS optional here, because VALUES in insert_rest would
   12236             :  * have a shift/reduce conflict with VALUES as an optional alias.  We could
   12237             :  * easily allow unreserved_keywords as optional aliases, but that'd be an odd
   12238             :  * divergence from other places.  So just require AS for now.
   12239             :  */
   12240             : insert_target:
   12241             :             qualified_name
   12242             :                 {
   12243       72394 :                     $$ = $1;
   12244             :                 }
   12245             :             | qualified_name AS ColId
   12246             :                 {
   12247         126 :                     $1->alias = makeAlias($3, NIL);
   12248         126 :                     $$ = $1;
   12249             :                 }
   12250             :         ;
   12251             : 
   12252             : insert_rest:
   12253             :             SelectStmt
   12254             :                 {
   12255       48538 :                     $$ = makeNode(InsertStmt);
   12256       48538 :                     $$->cols = NIL;
   12257       48538 :                     $$->selectStmt = $1;
   12258             :                 }
   12259             :             | OVERRIDING override_kind VALUE_P SelectStmt
   12260             :                 {
   12261          96 :                     $$ = makeNode(InsertStmt);
   12262          96 :                     $$->cols = NIL;
   12263          96 :                     $$->override = $2;
   12264          96 :                     $$->selectStmt = $4;
   12265             :                 }
   12266             :             | '(' insert_column_list ')' SelectStmt
   12267             :                 {
   12268       13120 :                     $$ = makeNode(InsertStmt);
   12269       13120 :                     $$->cols = $2;
   12270       13120 :                     $$->selectStmt = $4;
   12271             :                 }
   12272             :             | '(' insert_column_list ')' OVERRIDING override_kind VALUE_P SelectStmt
   12273             :                 {
   12274           0 :                     $$ = makeNode(InsertStmt);
   12275           0 :                     $$->cols = $2;
   12276           0 :                     $$->override = $5;
   12277           0 :                     $$->selectStmt = $7;
   12278             :                 }
   12279             :             | DEFAULT VALUES
   12280             :                 {
   12281       10766 :                     $$ = makeNode(InsertStmt);
   12282       10766 :                     $$->cols = NIL;
   12283       10766 :                     $$->selectStmt = NULL;
   12284             :                 }
   12285             :         ;
   12286             : 
   12287             : override_kind:
   12288          66 :             USER        { $$ = OVERRIDING_USER_VALUE; }
   12289          60 :             | SYSTEM_P  { $$ = OVERRIDING_SYSTEM_VALUE; }
   12290             :         ;
   12291             : 
   12292             : insert_column_list:
   12293             :             insert_column_item
   12294       13402 :                     { $$ = list_make1($1); }
   12295             :             | insert_column_list ',' insert_column_item
   12296       15088 :                     { $$ = lappend($1, $3); }
   12297             :         ;
   12298             : 
   12299             : insert_column_item:
   12300             :             ColId opt_indirection
   12301             :                 {
   12302       28490 :                     $$ = makeNode(ResTarget);
   12303       28490 :                     $$->name = $1;
   12304       28490 :                     $$->indirection = check_indirection($2, yyscanner);
   12305       28490 :                     $$->val = NULL;
   12306       28490 :                     $$->location = @1;
   12307             :                 }
   12308             :         ;
   12309             : 
   12310             : opt_on_conflict:
   12311             :             ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
   12312             :                 {
   12313        1150 :                     $$ = makeNode(OnConflictClause);
   12314        1150 :                     $$->action = ONCONFLICT_UPDATE;
   12315        1150 :                     $$->infer = $3;
   12316        1150 :                     $$->targetList = $7;
   12317        1150 :                     $$->whereClause = $8;
   12318        1150 :                     $$->location = @1;
   12319             :                 }
   12320             :             |
   12321             :             ON CONFLICT opt_conf_expr DO NOTHING
   12322             :                 {
   12323         322 :                     $$ = makeNode(OnConflictClause);
   12324         322 :                     $$->action = ONCONFLICT_NOTHING;
   12325         322 :                     $$->infer = $3;
   12326         322 :                     $$->targetList = NIL;
   12327         322 :                     $$->whereClause = NULL;
   12328         322 :                     $$->location = @1;
   12329             :                 }
   12330             :             | /*EMPTY*/
   12331             :                 {
   12332       71048 :                     $$ = NULL;
   12333             :                 }
   12334             :         ;
   12335             : 
   12336             : opt_conf_expr:
   12337             :             '(' index_params ')' where_clause
   12338             :                 {
   12339        1262 :                     $$ = makeNode(InferClause);
   12340        1262 :                     $$->indexElems = $2;
   12341        1262 :                     $$->whereClause = $4;
   12342        1262 :                     $$->conname = NULL;
   12343        1262 :                     $$->location = @1;
   12344             :                 }
   12345             :             |
   12346             :             ON CONSTRAINT name
   12347             :                 {
   12348          48 :                     $$ = makeNode(InferClause);
   12349          48 :                     $$->indexElems = NIL;
   12350          48 :                     $$->whereClause = NULL;
   12351          48 :                     $$->conname = $3;
   12352          48 :                     $$->location = @1;
   12353             :                 }
   12354             :             | /*EMPTY*/
   12355             :                 {
   12356         162 :                     $$ = NULL;
   12357             :                 }
   12358             :         ;
   12359             : 
   12360             : returning_clause:
   12361        2658 :             RETURNING target_list       { $$ = $2; }
   12362       89694 :             | /* EMPTY */               { $$ = NIL; }
   12363             :         ;
   12364             : 
   12365             : 
   12366             : /*****************************************************************************
   12367             :  *
   12368             :  *      QUERY:
   12369             :  *              DELETE STATEMENTS
   12370             :  *
   12371             :  *****************************************************************************/
   12372             : 
   12373             : DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
   12374             :             using_clause where_or_current_clause returning_clause
   12375             :                 {
   12376        4488 :                     DeleteStmt *n = makeNode(DeleteStmt);
   12377             : 
   12378        4488 :                     n->relation = $4;
   12379        4488 :                     n->usingClause = $5;
   12380        4488 :                     n->whereClause = $6;
   12381        4488 :                     n->returningList = $7;
   12382        4488 :                     n->withClause = $1;
   12383        4488 :                     $$ = (Node *) n;
   12384             :                 }
   12385             :         ;
   12386             : 
   12387             : using_clause:
   12388         108 :                 USING from_list                     { $$ = $2; }
   12389        4380 :             | /*EMPTY*/                             { $$ = NIL; }
   12390             :         ;
   12391             : 
   12392             : 
   12393             : /*****************************************************************************
   12394             :  *
   12395             :  *      QUERY:
   12396             :  *              LOCK TABLE
   12397             :  *
   12398             :  *****************************************************************************/
   12399             : 
   12400             : LockStmt:   LOCK_P opt_table relation_expr_list opt_lock opt_nowait
   12401             :                 {
   12402        1080 :                     LockStmt   *n = makeNode(LockStmt);
   12403             : 
   12404        1080 :                     n->relations = $3;
   12405        1080 :                     n->mode = $4;
   12406        1080 :                     n->nowait = $5;
   12407        1080 :                     $$ = (Node *) n;
   12408             :                 }
   12409             :         ;
   12410             : 
   12411         988 : opt_lock:   IN_P lock_type MODE             { $$ = $2; }
   12412          92 :             | /*EMPTY*/                     { $$ = AccessExclusiveLock; }
   12413             :         ;
   12414             : 
   12415         498 : lock_type:  ACCESS SHARE                    { $$ = AccessShareLock; }
   12416          14 :             | ROW SHARE                     { $$ = RowShareLock; }
   12417          88 :             | ROW EXCLUSIVE                 { $$ = RowExclusiveLock; }
   12418          66 :             | SHARE UPDATE EXCLUSIVE        { $$ = ShareUpdateExclusiveLock; }
   12419          80 :             | SHARE                         { $$ = ShareLock; }
   12420          14 :             | SHARE ROW EXCLUSIVE           { $$ = ShareRowExclusiveLock; }
   12421         102 :             | EXCLUSIVE                     { $$ = ExclusiveLock; }
   12422         126 :             | ACCESS EXCLUSIVE              { $$ = AccessExclusiveLock; }
   12423             :         ;
   12424             : 
   12425         286 : opt_nowait: NOWAIT                          { $$ = true; }
   12426         824 :             | /*EMPTY*/                     { $$ = false; }
   12427             :         ;
   12428             : 
   12429             : opt_nowait_or_skip:
   12430          50 :             NOWAIT                          { $$ = LockWaitError; }
   12431         190 :             | SKIP LOCKED                   { $$ = LockWaitSkip; }
   12432        4940 :             | /*EMPTY*/                     { $$ = LockWaitBlock; }
   12433             :         ;
   12434             : 
   12435             : 
   12436             : /*****************************************************************************
   12437             :  *
   12438             :  *      QUERY:
   12439             :  *              UpdateStmt (UPDATE)
   12440             :  *
   12441             :  *****************************************************************************/
   12442             : 
   12443             : UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
   12444             :             SET set_clause_list
   12445             :             from_clause
   12446             :             where_or_current_clause
   12447             :             returning_clause
   12448             :                 {
   12449       13418 :                     UpdateStmt *n = makeNode(UpdateStmt);
   12450             : 
   12451       13418 :                     n->relation = $3;
   12452       13418 :                     n->targetList = $5;
   12453       13418 :                     n->fromClause = $6;
   12454       13418 :                     n->whereClause = $7;
   12455       13418 :                     n->returningList = $8;
   12456       13418 :                     n->withClause = $1;
   12457       13418 :                     $$ = (Node *) n;
   12458             :                 }
   12459             :         ;
   12460             : 
   12461             : set_clause_list:
   12462       16070 :             set_clause                          { $$ = $1; }
   12463        3700 :             | set_clause_list ',' set_clause    { $$ = list_concat($1,$3); }
   12464             :         ;
   12465             : 
   12466             : set_clause:
   12467             :             set_target '=' a_expr
   12468             :                 {
   12469       19586 :                     $1->val = (Node *) $3;
   12470       19586 :                     $$ = list_make1($1);
   12471             :                 }
   12472             :             | '(' set_target_list ')' '=' a_expr
   12473             :                 {
   12474         184 :                     int         ncolumns = list_length($2);
   12475         184 :                     int         i = 1;
   12476             :                     ListCell   *col_cell;
   12477             : 
   12478             :                     /* Create a MultiAssignRef source for each target */
   12479         568 :                     foreach(col_cell, $2)
   12480             :                     {
   12481         384 :                         ResTarget  *res_col = (ResTarget *) lfirst(col_cell);
   12482         384 :                         MultiAssignRef *r = makeNode(MultiAssignRef);
   12483             : 
   12484         384 :                         r->source = (Node *) $5;
   12485         384 :                         r->colno = i;
   12486         384 :                         r->ncolumns = ncolumns;
   12487         384 :                         res_col->val = (Node *) r;
   12488         384 :                         i++;
   12489             :                     }
   12490             : 
   12491         184 :                     $$ = $2;
   12492             :                 }
   12493             :         ;
   12494             : 
   12495             : set_target:
   12496             :             ColId opt_indirection
   12497             :                 {
   12498       19976 :                     $$ = makeNode(ResTarget);
   12499       19976 :                     $$->name = $1;
   12500       19976 :                     $$->indirection = check_indirection($2, yyscanner);
   12501       19976 :                     $$->val = NULL;  /* upper production sets this */
   12502       19976 :                     $$->location = @1;
   12503             :                 }
   12504             :         ;
   12505             : 
   12506             : set_target_list:
   12507         190 :             set_target                              { $$ = list_make1($1); }
   12508         200 :             | set_target_list ',' set_target        { $$ = lappend($1,$3); }
   12509             :         ;
   12510             : 
   12511             : 
   12512             : /*****************************************************************************
   12513             :  *
   12514             :  *      QUERY:
   12515             :  *              MERGE
   12516             :  *
   12517             :  *****************************************************************************/
   12518             : 
   12519             : MergeStmt:
   12520             :             opt_with_clause MERGE INTO relation_expr_opt_alias
   12521             :             USING table_ref
   12522             :             ON a_expr
   12523             :             merge_when_list
   12524             :             returning_clause
   12525             :                 {
   12526        1926 :                     MergeStmt  *m = makeNode(MergeStmt);
   12527             : 
   12528        1926 :                     m->withClause = $1;
   12529        1926 :                     m->relation = $4;
   12530        1926 :                     m->sourceRelation = $6;
   12531        1926 :                     m->joinCondition = $8;
   12532        1926 :                     m->mergeWhenClauses = $9;
   12533        1926 :                     m->returningList = $10;
   12534             : 
   12535        1926 :                     $$ = (Node *) m;
   12536             :                 }
   12537             :         ;
   12538             : 
   12539             : merge_when_list:
   12540        1926 :             merge_when_clause                       { $$ = list_make1($1); }
   12541        1118 :             | merge_when_list merge_when_clause     { $$ = lappend($1,$2); }
   12542             :         ;
   12543             : 
   12544             : /*
   12545             :  * A WHEN clause may be WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, or WHEN NOT
   12546             :  * MATCHED [BY TARGET]. The first two cases match target tuples, and support
   12547             :  * UPDATE/DELETE/DO NOTHING actions. The third case does not match target
   12548             :  * tuples, and only supports INSERT/DO NOTHING actions.
   12549             :  */
   12550             : merge_when_clause:
   12551             :             merge_when_tgt_matched opt_merge_when_condition THEN merge_update
   12552             :                 {
   12553        1502 :                     $4->matchKind = $1;
   12554        1502 :                     $4->condition = $2;
   12555             : 
   12556        1502 :                     $$ = (Node *) $4;
   12557             :                 }
   12558             :             | merge_when_tgt_matched opt_merge_when_condition THEN merge_delete
   12559             :                 {
   12560         470 :                     $4->matchKind = $1;
   12561         470 :                     $4->condition = $2;
   12562             : 
   12563         470 :                     $$ = (Node *) $4;
   12564             :                 }
   12565             :             | merge_when_tgt_not_matched opt_merge_when_condition THEN merge_insert
   12566             :                 {
   12567        1012 :                     $4->matchKind = $1;
   12568        1012 :                     $4->condition = $2;
   12569             : 
   12570        1012 :                     $$ = (Node *) $4;
   12571             :                 }
   12572             :             | merge_when_tgt_matched opt_merge_when_condition THEN DO NOTHING
   12573             :                 {
   12574          46 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12575             : 
   12576          46 :                     m->matchKind = $1;
   12577          46 :                     m->commandType = CMD_NOTHING;
   12578          46 :                     m->condition = $2;
   12579             : 
   12580          46 :                     $$ = (Node *) m;
   12581             :                 }
   12582             :             | merge_when_tgt_not_matched opt_merge_when_condition THEN DO NOTHING
   12583             :                 {
   12584          14 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12585             : 
   12586          14 :                     m->matchKind = $1;
   12587          14 :                     m->commandType = CMD_NOTHING;
   12588          14 :                     m->condition = $2;
   12589             : 
   12590          14 :                     $$ = (Node *) m;
   12591             :                 }
   12592             :         ;
   12593             : 
   12594             : merge_when_tgt_matched:
   12595        1868 :             WHEN MATCHED                    { $$ = MERGE_WHEN_MATCHED; }
   12596         168 :             | WHEN NOT MATCHED BY SOURCE    { $$ = MERGE_WHEN_NOT_MATCHED_BY_SOURCE; }
   12597             :         ;
   12598             : 
   12599             : merge_when_tgt_not_matched:
   12600        1032 :             WHEN NOT MATCHED                { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
   12601          18 :             | WHEN NOT MATCHED BY TARGET    { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
   12602             :         ;
   12603             : 
   12604             : opt_merge_when_condition:
   12605         802 :             AND a_expr              { $$ = $2; }
   12606        2284 :             |                       { $$ = NULL; }
   12607             :         ;
   12608             : 
   12609             : merge_update:
   12610             :             UPDATE SET set_clause_list
   12611             :                 {
   12612        1502 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12613        1502 :                     n->commandType = CMD_UPDATE;
   12614        1502 :                     n->override = OVERRIDING_NOT_SET;
   12615        1502 :                     n->targetList = $3;
   12616        1502 :                     n->values = NIL;
   12617             : 
   12618        1502 :                     $$ = n;
   12619             :                 }
   12620             :         ;
   12621             : 
   12622             : merge_delete:
   12623             :             DELETE_P
   12624             :                 {
   12625         470 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12626         470 :                     n->commandType = CMD_DELETE;
   12627         470 :                     n->override = OVERRIDING_NOT_SET;
   12628         470 :                     n->targetList = NIL;
   12629         470 :                     n->values = NIL;
   12630             : 
   12631         470 :                     $$ = n;
   12632             :                 }
   12633             :         ;
   12634             : 
   12635             : merge_insert:
   12636             :             INSERT merge_values_clause
   12637             :                 {
   12638         694 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12639         694 :                     n->commandType = CMD_INSERT;
   12640         694 :                     n->override = OVERRIDING_NOT_SET;
   12641         694 :                     n->targetList = NIL;
   12642         694 :                     n->values = $2;
   12643         694 :                     $$ = n;
   12644             :                 }
   12645             :             | INSERT OVERRIDING override_kind VALUE_P merge_values_clause
   12646             :                 {
   12647           0 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12648           0 :                     n->commandType = CMD_INSERT;
   12649           0 :                     n->override = $3;
   12650           0 :                     n->targetList = NIL;
   12651           0 :                     n->values = $5;
   12652           0 :                     $$ = n;
   12653             :                 }
   12654             :             | INSERT '(' insert_column_list ')' merge_values_clause
   12655             :                 {
   12656         252 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12657         252 :                     n->commandType = CMD_INSERT;
   12658         252 :                     n->override = OVERRIDING_NOT_SET;
   12659         252 :                     n->targetList = $3;
   12660         252 :                     n->values = $5;
   12661         252 :                     $$ = n;
   12662             :                 }
   12663             :             | INSERT '(' insert_column_list ')' OVERRIDING override_kind VALUE_P merge_values_clause
   12664             :                 {
   12665          30 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12666          30 :                     n->commandType = CMD_INSERT;
   12667          30 :                     n->override = $6;
   12668          30 :                     n->targetList = $3;
   12669          30 :                     n->values = $8;
   12670          30 :                     $$ = n;
   12671             :                 }
   12672             :             | INSERT DEFAULT VALUES
   12673             :                 {
   12674          36 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12675          36 :                     n->commandType = CMD_INSERT;
   12676          36 :                     n->override = OVERRIDING_NOT_SET;
   12677          36 :                     n->targetList = NIL;
   12678          36 :                     n->values = NIL;
   12679          36 :                     $$ = n;
   12680             :                 }
   12681             :         ;
   12682             : 
   12683             : merge_values_clause:
   12684             :             VALUES '(' expr_list ')'
   12685             :                 {
   12686         976 :                     $$ = $3;
   12687             :                 }
   12688             :         ;
   12689             : 
   12690             : /*****************************************************************************
   12691             :  *
   12692             :  *      QUERY:
   12693             :  *              CURSOR STATEMENTS
   12694             :  *
   12695             :  *****************************************************************************/
   12696             : DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
   12697             :                 {
   12698        2734 :                     DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
   12699             : 
   12700        2734 :                     n->portalname = $2;
   12701             :                     /* currently we always set FAST_PLAN option */
   12702        2734 :                     n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
   12703        2734 :                     n->query = $7;
   12704        2734 :                     $$ = (Node *) n;
   12705             :                 }
   12706             :         ;
   12707             : 
   12708       10796 : cursor_name:    name                        { $$ = $1; }
   12709             :         ;
   12710             : 
   12711        2734 : cursor_options: /*EMPTY*/                   { $$ = 0; }
   12712          24 :             | cursor_options NO SCROLL      { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
   12713         240 :             | cursor_options SCROLL         { $$ = $1 | CURSOR_OPT_SCROLL; }
   12714          14 :             | cursor_options BINARY         { $$ = $1 | CURSOR_OPT_BINARY; }
   12715           0 :             | cursor_options ASENSITIVE     { $$ = $1 | CURSOR_OPT_ASENSITIVE; }
   12716           6 :             | cursor_options INSENSITIVE    { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
   12717             :         ;
   12718             : 
   12719        2636 : opt_hold: /* EMPTY */                       { $$ = 0; }
   12720          92 :             | WITH HOLD                     { $$ = CURSOR_OPT_HOLD; }
   12721           6 :             | WITHOUT HOLD                  { $$ = 0; }
   12722             :         ;
   12723             : 
   12724             : /*****************************************************************************
   12725             :  *
   12726             :  *      QUERY:
   12727             :  *              SELECT STATEMENTS
   12728             :  *
   12729             :  *****************************************************************************/
   12730             : 
   12731             : /* A complete SELECT statement looks like this.
   12732             :  *
   12733             :  * The rule returns either a single SelectStmt node or a tree of them,
   12734             :  * representing a set-operation tree.
   12735             :  *
   12736             :  * There is an ambiguity when a sub-SELECT is within an a_expr and there
   12737             :  * are excess parentheses: do the parentheses belong to the sub-SELECT or
   12738             :  * to the surrounding a_expr?  We don't really care, but bison wants to know.
   12739             :  * To resolve the ambiguity, we are careful to define the grammar so that
   12740             :  * the decision is staved off as long as possible: as long as we can keep
   12741             :  * absorbing parentheses into the sub-SELECT, we will do so, and only when
   12742             :  * it's no longer possible to do that will we decide that parens belong to
   12743             :  * the expression.  For example, in "SELECT (((SELECT 2)) + 3)" the extra
   12744             :  * parentheses are treated as part of the sub-select.  The necessity of doing
   12745             :  * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)".    Had we
   12746             :  * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
   12747             :  * SELECT viewpoint when we see the UNION.
   12748             :  *
   12749             :  * This approach is implemented by defining a nonterminal select_with_parens,
   12750             :  * which represents a SELECT with at least one outer layer of parentheses,
   12751             :  * and being careful to use select_with_parens, never '(' SelectStmt ')',
   12752             :  * in the expression grammar.  We will then have shift-reduce conflicts
   12753             :  * which we can resolve in favor of always treating '(' <select> ')' as
   12754             :  * a select_with_parens.  To resolve the conflicts, the productions that
   12755             :  * conflict with the select_with_parens productions are manually given
   12756             :  * precedences lower than the precedence of ')', thereby ensuring that we
   12757             :  * shift ')' (and then reduce to select_with_parens) rather than trying to
   12758             :  * reduce the inner <select> nonterminal to something else.  We use UMINUS
   12759             :  * precedence for this, which is a fairly arbitrary choice.
   12760             :  *
   12761             :  * To be able to define select_with_parens itself without ambiguity, we need
   12762             :  * a nonterminal select_no_parens that represents a SELECT structure with no
   12763             :  * outermost parentheses.  This is a little bit tedious, but it works.
   12764             :  *
   12765             :  * In non-expression contexts, we use SelectStmt which can represent a SELECT
   12766             :  * with or without outer parentheses.
   12767             :  */
   12768             : 
   12769             : SelectStmt: select_no_parens            %prec UMINUS
   12770             :             | select_with_parens        %prec UMINUS
   12771             :         ;
   12772             : 
   12773             : select_with_parens:
   12774       52102 :             '(' select_no_parens ')'                { $$ = $2; }
   12775         150 :             | '(' select_with_parens ')'            { $$ = $2; }
   12776             :         ;
   12777             : 
   12778             : /*
   12779             :  * This rule parses the equivalent of the standard's <query expression>.
   12780             :  * The duplicative productions are annoying, but hard to get rid of without
   12781             :  * creating shift/reduce conflicts.
   12782             :  *
   12783             :  *  The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
   12784             :  *  In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
   12785             :  *  We now support both orderings, but prefer LIMIT/OFFSET before the locking
   12786             :  * clause.
   12787             :  *  2002-08-28 bjm
   12788             :  */
   12789             : select_no_parens:
   12790      397890 :             simple_select                       { $$ = $1; }
   12791             :             | select_clause sort_clause
   12792             :                 {
   12793       55226 :                     insertSelectOptions((SelectStmt *) $1, $2, NIL,
   12794             :                                         NULL, NULL,
   12795             :                                         yyscanner);
   12796       55226 :                     $$ = $1;
   12797             :                 }
   12798             :             | select_clause opt_sort_clause for_locking_clause opt_select_limit
   12799             :                 {
   12800        4736 :                     insertSelectOptions((SelectStmt *) $1, $2, $3,
   12801        4736 :                                         $4,
   12802             :                                         NULL,
   12803             :                                         yyscanner);
   12804        4736 :                     $$ = $1;
   12805             :                 }
   12806             :             | select_clause opt_sort_clause select_limit opt_for_locking_clause
   12807             :                 {
   12808        4608 :                     insertSelectOptions((SelectStmt *) $1, $2, $4,
   12809        4608 :                                         $3,
   12810             :                                         NULL,
   12811             :                                         yyscanner);
   12812        4596 :                     $$ = $1;
   12813             :                 }
   12814             :             | with_clause select_clause
   12815             :                 {
   12816        1860 :                     insertSelectOptions((SelectStmt *) $2, NULL, NIL,
   12817             :                                         NULL,
   12818        1860 :                                         $1,
   12819             :                                         yyscanner);
   12820        1860 :                     $$ = $2;
   12821             :                 }
   12822             :             | with_clause select_clause sort_clause
   12823             :                 {
   12824         484 :                     insertSelectOptions((SelectStmt *) $2, $3, NIL,
   12825             :                                         NULL,
   12826         484 :                                         $1,
   12827             :                                         yyscanner);
   12828         484 :                     $$ = $2;
   12829             :                 }
   12830             :             | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
   12831             :                 {
   12832           6 :                     insertSelectOptions((SelectStmt *) $2, $3, $4,
   12833           6 :                                         $5,
   12834           6 :                                         $1,
   12835             :                                         yyscanner);
   12836           6 :                     $$ = $2;
   12837             :                 }
   12838             :             | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
   12839             :                 {
   12840          64 :                     insertSelectOptions((SelectStmt *) $2, $3, $5,
   12841          64 :                                         $4,
   12842          64 :                                         $1,
   12843             :                                         yyscanner);
   12844          64 :                     $$ = $2;
   12845             :                 }
   12846             :         ;
   12847             : 
   12848             : select_clause:
   12849       94812 :             simple_select                           { $$ = $1; }
   12850         472 :             | select_with_parens                    { $$ = $1; }
   12851             :         ;
   12852             : 
   12853             : /*
   12854             :  * This rule parses SELECT statements that can appear within set operations,
   12855             :  * including UNION, INTERSECT and EXCEPT.  '(' and ')' can be used to specify
   12856             :  * the ordering of the set operations.  Without '(' and ')' we want the
   12857             :  * operations to be ordered per the precedence specs at the head of this file.
   12858             :  *
   12859             :  * As with select_no_parens, simple_select cannot have outer parentheses,
   12860             :  * but can have parenthesized subclauses.
   12861             :  *
   12862             :  * It might appear that we could fold the first two alternatives into one
   12863             :  * by using opt_distinct_clause.  However, that causes a shift/reduce conflict
   12864             :  * against INSERT ... SELECT ... ON CONFLICT.  We avoid the ambiguity by
   12865             :  * requiring SELECT DISTINCT [ON] to be followed by a non-empty target_list.
   12866             :  *
   12867             :  * Note that sort clauses cannot be included at this level --- SQL requires
   12868             :  *      SELECT foo UNION SELECT bar ORDER BY baz
   12869             :  * to be parsed as
   12870             :  *      (SELECT foo UNION SELECT bar) ORDER BY baz
   12871             :  * not
   12872             :  *      SELECT foo UNION (SELECT bar ORDER BY baz)
   12873             :  * Likewise for WITH, FOR UPDATE and LIMIT.  Therefore, those clauses are
   12874             :  * described as part of the select_no_parens production, not simple_select.
   12875             :  * This does not limit functionality, because you can reintroduce these
   12876             :  * clauses inside parentheses.
   12877             :  *
   12878             :  * NOTE: only the leftmost component SelectStmt should have INTO.
   12879             :  * However, this is not checked by the grammar; parse analysis must check it.
   12880             :  */
   12881             : simple_select:
   12882             :             SELECT opt_all_clause opt_target_list
   12883             :             into_clause from_clause where_clause
   12884             :             group_clause having_clause window_clause
   12885             :                 {
   12886      414670 :                     SelectStmt *n = makeNode(SelectStmt);
   12887             : 
   12888      414670 :                     n->targetList = $3;
   12889      414670 :                     n->intoClause = $4;
   12890      414670 :                     n->fromClause = $5;
   12891      414670 :                     n->whereClause = $6;
   12892      414670 :                     n->groupClause = ($7)->list;
   12893      414670 :                     n->groupDistinct = ($7)->distinct;
   12894      414670 :                     n->havingClause = $8;
   12895      414670 :                     n->windowClause = $9;
   12896      414670 :                     $$ = (Node *) n;
   12897             :                 }
   12898             :             | SELECT distinct_clause target_list
   12899             :             into_clause from_clause where_clause
   12900             :             group_clause having_clause window_clause
   12901             :                 {
   12902        3026 :                     SelectStmt *n = makeNode(SelectStmt);
   12903             : 
   12904        3026 :                     n->distinctClause = $2;
   12905        3026 :                     n->targetList = $3;
   12906        3026 :                     n->intoClause = $4;
   12907        3026 :                     n->fromClause = $5;
   12908        3026 :                     n->whereClause = $6;
   12909        3026 :                     n->groupClause = ($7)->list;
   12910        3026 :                     n->groupDistinct = ($7)->distinct;
   12911        3026 :                     n->havingClause = $8;
   12912        3026 :                     n->windowClause = $9;
   12913        3026 :                     $$ = (Node *) n;
   12914             :                 }
   12915       60626 :             | values_clause                         { $$ = $1; }
   12916             :             | TABLE relation_expr
   12917             :                 {
   12918             :                     /* same as SELECT * FROM relation_expr */
   12919         236 :                     ColumnRef  *cr = makeNode(ColumnRef);
   12920         236 :                     ResTarget  *rt = makeNode(ResTarget);
   12921         236 :                     SelectStmt *n = makeNode(SelectStmt);
   12922             : 
   12923         236 :                     cr->fields = list_make1(makeNode(A_Star));
   12924         236 :                     cr->location = -1;
   12925             : 
   12926         236 :                     rt->name = NULL;
   12927         236 :                     rt->indirection = NIL;
   12928         236 :                     rt->val = (Node *) cr;
   12929         236 :                     rt->location = -1;
   12930             : 
   12931         236 :                     n->targetList = list_make1(rt);
   12932         236 :                     n->fromClause = list_make1($2);
   12933         236 :                     $$ = (Node *) n;
   12934             :                 }
   12935             :             | select_clause UNION set_quantifier select_clause
   12936             :                 {
   12937       13470 :                     $$ = makeSetOp(SETOP_UNION, $3 == SET_QUANTIFIER_ALL, $1, $4);
   12938             :                 }
   12939             :             | select_clause INTERSECT set_quantifier select_clause
   12940             :                 {
   12941         240 :                     $$ = makeSetOp(SETOP_INTERSECT, $3 == SET_QUANTIFIER_ALL, $1, $4);
   12942             :                 }
   12943             :             | select_clause EXCEPT set_quantifier select_clause
   12944             :                 {
   12945         434 :                     $$ = makeSetOp(SETOP_EXCEPT, $3 == SET_QUANTIFIER_ALL, $1, $4);
   12946             :                 }
   12947             :         ;
   12948             : 
   12949             : /*
   12950             :  * SQL standard WITH clause looks like:
   12951             :  *
   12952             :  * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
   12953             :  *      AS (query) [ SEARCH or CYCLE clause ]
   12954             :  *
   12955             :  * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
   12956             :  */
   12957             : with_clause:
   12958             :         WITH cte_list
   12959             :             {
   12960        1694 :                 $$ = makeNode(WithClause);
   12961        1694 :                 $$->ctes = $2;
   12962        1694 :                 $$->recursive = false;
   12963        1694 :                 $$->location = @1;
   12964             :             }
   12965             :         | WITH_LA cte_list
   12966             :             {
   12967           6 :                 $$ = makeNode(WithClause);
   12968           6 :                 $$->ctes = $2;
   12969           6 :                 $$->recursive = false;
   12970           6 :                 $$->location = @1;
   12971             :             }
   12972             :         | WITH RECURSIVE cte_list
   12973             :             {
   12974        1092 :                 $$ = makeNode(WithClause);
   12975        1092 :                 $$->ctes = $3;
   12976        1092 :                 $$->recursive = true;
   12977        1092 :                 $$->location = @1;
   12978             :             }
   12979             :         ;
   12980             : 
   12981             : cte_list:
   12982        2792 :         common_table_expr                       { $$ = list_make1($1); }
   12983        1074 :         | cte_list ',' common_table_expr        { $$ = lappend($1, $3); }
   12984             :         ;
   12985             : 
   12986             : common_table_expr:  name opt_name_list AS opt_materialized '(' PreparableStmt ')' opt_search_clause opt_cycle_clause
   12987             :             {
   12988        3866 :                 CommonTableExpr *n = makeNode(CommonTableExpr);
   12989             : 
   12990        3866 :                 n->ctename = $1;
   12991        3866 :                 n->aliascolnames = $2;
   12992        3866 :                 n->ctematerialized = $4;
   12993        3866 :                 n->ctequery = $6;
   12994        3866 :                 n->search_clause = castNode(CTESearchClause, $8);
   12995        3866 :                 n->cycle_clause = castNode(CTECycleClause, $9);
   12996        3866 :                 n->location = @1;
   12997        3866 :                 $$ = (Node *) n;
   12998             :             }
   12999             :         ;
   13000             : 
   13001             : opt_materialized:
   13002         166 :         MATERIALIZED                            { $$ = CTEMaterializeAlways; }
   13003          48 :         | NOT MATERIALIZED                      { $$ = CTEMaterializeNever; }
   13004        3652 :         | /*EMPTY*/                             { $$ = CTEMaterializeDefault; }
   13005             :         ;
   13006             : 
   13007             : opt_search_clause:
   13008             :         SEARCH DEPTH FIRST_P BY columnList SET ColId
   13009             :             {
   13010          90 :                 CTESearchClause *n = makeNode(CTESearchClause);
   13011             : 
   13012          90 :                 n->search_col_list = $5;
   13013          90 :                 n->search_breadth_first = false;
   13014          90 :                 n->search_seq_column = $7;
   13015          90 :                 n->location = @1;
   13016          90 :                 $$ = (Node *) n;
   13017             :             }
   13018             :         | SEARCH BREADTH FIRST_P BY columnList SET ColId
   13019             :             {
   13020          36 :                 CTESearchClause *n = makeNode(CTESearchClause);
   13021             : 
   13022          36 :                 n->search_col_list = $5;
   13023          36 :                 n->search_breadth_first = true;
   13024          36 :                 n->search_seq_column = $7;
   13025          36 :                 n->location = @1;
   13026          36 :                 $$ = (Node *) n;
   13027             :             }
   13028             :         | /*EMPTY*/
   13029             :             {
   13030        3740 :                 $$ = NULL;
   13031             :             }
   13032             :         ;
   13033             : 
   13034             : opt_cycle_clause:
   13035             :         CYCLE columnList SET ColId TO AexprConst DEFAULT AexprConst USING ColId
   13036             :             {
   13037          66 :                 CTECycleClause *n = makeNode(CTECycleClause);
   13038             : 
   13039          66 :                 n->cycle_col_list = $2;
   13040          66 :                 n->cycle_mark_column = $4;
   13041          66 :                 n->cycle_mark_value = $6;
   13042          66 :                 n->cycle_mark_default = $8;
   13043          66 :                 n->cycle_path_column = $10;
   13044          66 :                 n->location = @1;
   13045          66 :                 $$ = (Node *) n;
   13046             :             }
   13047             :         | CYCLE columnList SET ColId USING ColId
   13048             :             {
   13049          60 :                 CTECycleClause *n = makeNode(CTECycleClause);
   13050             : 
   13051          60 :                 n->cycle_col_list = $2;
   13052          60 :                 n->cycle_mark_column = $4;
   13053          60 :                 n->cycle_mark_value = makeBoolAConst(true, -1);
   13054          60 :                 n->cycle_mark_default = makeBoolAConst(false, -1);
   13055          60 :                 n->cycle_path_column = $6;
   13056          60 :                 n->location = @1;
   13057          60 :                 $$ = (Node *) n;
   13058             :             }
   13059             :         | /*EMPTY*/
   13060             :             {
   13061        3740 :                 $$ = NULL;
   13062             :             }
   13063             :         ;
   13064             : 
   13065             : opt_with_clause:
   13066         378 :         with_clause                             { $$ = $1; }
   13067       92084 :         | /*EMPTY*/                             { $$ = NULL; }
   13068             :         ;
   13069             : 
   13070             : into_clause:
   13071             :             INTO OptTempTableName
   13072             :                 {
   13073         132 :                     $$ = makeNode(IntoClause);
   13074         132 :                     $$->rel = $2;
   13075         132 :                     $$->colNames = NIL;
   13076         132 :                     $$->options = NIL;
   13077         132 :                     $$->onCommit = ONCOMMIT_NOOP;
   13078         132 :                     $$->tableSpaceName = NULL;
   13079         132 :                     $$->viewQuery = NULL;
   13080         132 :                     $$->skipData = false;
   13081             :                 }
   13082             :             | /*EMPTY*/
   13083      417582 :                 { $$ = NULL; }
   13084             :         ;
   13085             : 
   13086             : /*
   13087             :  * Redundancy here is needed to avoid shift/reduce conflicts,
   13088             :  * since TEMP is not a reserved word.  See also OptTemp.
   13089             :  */
   13090             : OptTempTableName:
   13091             :             TEMPORARY opt_table qualified_name
   13092             :                 {
   13093           0 :                     $$ = $3;
   13094           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13095             :                 }
   13096             :             | TEMP opt_table qualified_name
   13097             :                 {
   13098           6 :                     $$ = $3;
   13099           6 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13100             :                 }
   13101             :             | LOCAL TEMPORARY opt_table qualified_name
   13102             :                 {
   13103           0 :                     $$ = $4;
   13104           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13105             :                 }
   13106             :             | LOCAL TEMP opt_table qualified_name
   13107             :                 {
   13108           0 :                     $$ = $4;
   13109           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13110             :                 }
   13111             :             | GLOBAL TEMPORARY opt_table qualified_name
   13112             :                 {
   13113           0 :                     ereport(WARNING,
   13114             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   13115             :                              parser_errposition(@1)));
   13116           0 :                     $$ = $4;
   13117           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13118             :                 }
   13119             :             | GLOBAL TEMP opt_table qualified_name
   13120             :                 {
   13121           0 :                     ereport(WARNING,
   13122             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   13123             :                              parser_errposition(@1)));
   13124           0 :                     $$ = $4;
   13125           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13126             :                 }
   13127             :             | UNLOGGED opt_table qualified_name
   13128             :                 {
   13129           0 :                     $$ = $3;
   13130           0 :                     $$->relpersistence = RELPERSISTENCE_UNLOGGED;
   13131             :                 }
   13132             :             | TABLE qualified_name
   13133             :                 {
   13134          30 :                     $$ = $2;
   13135          30 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   13136             :                 }
   13137             :             | qualified_name
   13138             :                 {
   13139          96 :                     $$ = $1;
   13140          96 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   13141             :                 }
   13142             :         ;
   13143             : 
   13144             : opt_table:  TABLE
   13145             :             | /*EMPTY*/
   13146             :         ;
   13147             : 
   13148             : set_quantifier:
   13149        6512 :             ALL                                     { $$ = SET_QUANTIFIER_ALL; }
   13150          32 :             | DISTINCT                              { $$ = SET_QUANTIFIER_DISTINCT; }
   13151       11800 :             | /*EMPTY*/                             { $$ = SET_QUANTIFIER_DEFAULT; }
   13152             :         ;
   13153             : 
   13154             : /* We use (NIL) as a placeholder to indicate that all target expressions
   13155             :  * should be placed in the DISTINCT list during parsetree analysis.
   13156             :  */
   13157             : distinct_clause:
   13158        2854 :             DISTINCT                                { $$ = list_make1(NIL); }
   13159         178 :             | DISTINCT ON '(' expr_list ')'         { $$ = $4; }
   13160             :         ;
   13161             : 
   13162             : opt_all_clause:
   13163             :             ALL
   13164             :             | /*EMPTY*/
   13165             :         ;
   13166             : 
   13167             : opt_distinct_clause:
   13168           0 :             distinct_clause                         { $$ = $1; }
   13169       36766 :             | opt_all_clause                        { $$ = NIL; }
   13170             :         ;
   13171             : 
   13172             : opt_sort_clause:
   13173        6526 :             sort_clause                             { $$ = $1; }
   13174      325172 :             | /*EMPTY*/                             { $$ = NIL; }
   13175             :         ;
   13176             : 
   13177             : sort_clause:
   13178       62584 :             ORDER BY sortby_list                    { $$ = $3; }
   13179             :         ;
   13180             : 
   13181             : sortby_list:
   13182       62602 :             sortby                                  { $$ = list_make1($1); }
   13183       24596 :             | sortby_list ',' sortby                { $$ = lappend($1, $3); }
   13184             :         ;
   13185             : 
   13186             : sortby:     a_expr USING qual_all_Op opt_nulls_order
   13187             :                 {
   13188         220 :                     $$ = makeNode(SortBy);
   13189         220 :                     $$->node = $1;
   13190         220 :                     $$->sortby_dir = SORTBY_USING;
   13191         220 :                     $$->sortby_nulls = $4;
   13192         220 :                     $$->useOp = $3;
   13193         220 :                     $$->location = @3;
   13194             :                 }
   13195             :             | a_expr opt_asc_desc opt_nulls_order
   13196             :                 {
   13197       86978 :                     $$ = makeNode(SortBy);
   13198       86978 :                     $$->node = $1;
   13199       86978 :                     $$->sortby_dir = $2;
   13200       86978 :                     $$->sortby_nulls = $3;
   13201       86978 :                     $$->useOp = NIL;
   13202       86978 :                     $$->location = -1;       /* no operator */
   13203             :                 }
   13204             :         ;
   13205             : 
   13206             : 
   13207             : select_limit:
   13208             :             limit_clause offset_clause
   13209             :                 {
   13210         168 :                     $$ = $1;
   13211         168 :                     ($$)->limitOffset = $2;
   13212             :                 }
   13213             :             | offset_clause limit_clause
   13214             :                 {
   13215         214 :                     $$ = $2;
   13216         214 :                     ($$)->limitOffset = $1;
   13217             :                 }
   13218             :             | limit_clause
   13219             :                 {
   13220        4106 :                     $$ = $1;
   13221             :                 }
   13222             :             | offset_clause
   13223             :                 {
   13224         374 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13225             : 
   13226         374 :                     n->limitOffset = $1;
   13227         374 :                     n->limitCount = NULL;
   13228         374 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13229         374 :                     $$ = n;
   13230             :                 }
   13231             :         ;
   13232             : 
   13233             : opt_select_limit:
   13234         190 :             select_limit                        { $$ = $1; }
   13235       41318 :             | /* EMPTY */                       { $$ = NULL; }
   13236             :         ;
   13237             : 
   13238             : limit_clause:
   13239             :             LIMIT select_limit_value
   13240             :                 {
   13241        4408 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13242             : 
   13243        4408 :                     n->limitOffset = NULL;
   13244        4408 :                     n->limitCount = $2;
   13245        4408 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13246        4408 :                     $$ = n;
   13247             :                 }
   13248             :             | LIMIT select_limit_value ',' select_offset_value
   13249             :                 {
   13250             :                     /* Disabled because it was too confusing, bjm 2002-02-18 */
   13251           0 :                     ereport(ERROR,
   13252             :                             (errcode(ERRCODE_SYNTAX_ERROR),
   13253             :                              errmsg("LIMIT #,# syntax is not supported"),
   13254             :                              errhint("Use separate LIMIT and OFFSET clauses."),
   13255             :                              parser_errposition(@1)));
   13256             :                 }
   13257             :             /* SQL:2008 syntax */
   13258             :             /* to avoid shift/reduce conflicts, handle the optional value with
   13259             :              * a separate production rather than an opt_ expression.  The fact
   13260             :              * that ONLY is fully reserved means that this way, we defer any
   13261             :              * decision about what rule reduces ROW or ROWS to the point where
   13262             :              * we can see the ONLY token in the lookahead slot.
   13263             :              */
   13264             :             | FETCH first_or_next select_fetch_first_value row_or_rows ONLY
   13265             :                 {
   13266          20 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13267             : 
   13268          20 :                     n->limitOffset = NULL;
   13269          20 :                     n->limitCount = $3;
   13270          20 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13271          20 :                     $$ = n;
   13272             :                 }
   13273             :             | FETCH first_or_next select_fetch_first_value row_or_rows WITH TIES
   13274             :                 {
   13275          54 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13276             : 
   13277          54 :                     n->limitOffset = NULL;
   13278          54 :                     n->limitCount = $3;
   13279          54 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13280          54 :                     $$ = n;
   13281             :                 }
   13282             :             | FETCH first_or_next row_or_rows ONLY
   13283             :                 {
   13284           0 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13285             : 
   13286           0 :                     n->limitOffset = NULL;
   13287           0 :                     n->limitCount = makeIntConst(1, -1);
   13288           0 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13289           0 :                     $$ = n;
   13290             :                 }
   13291             :             | FETCH first_or_next row_or_rows WITH TIES
   13292             :                 {
   13293           6 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13294             : 
   13295           6 :                     n->limitOffset = NULL;
   13296           6 :                     n->limitCount = makeIntConst(1, -1);
   13297           6 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13298           6 :                     $$ = n;
   13299             :                 }
   13300             :         ;
   13301             : 
   13302             : offset_clause:
   13303             :             OFFSET select_offset_value
   13304         756 :                 { $$ = $2; }
   13305             :             /* SQL:2008 syntax */
   13306             :             | OFFSET select_fetch_first_value row_or_rows
   13307           0 :                 { $$ = $2; }
   13308             :         ;
   13309             : 
   13310             : select_limit_value:
   13311        4406 :             a_expr                                  { $$ = $1; }
   13312             :             | ALL
   13313             :                 {
   13314             :                     /* LIMIT ALL is represented as a NULL constant */
   13315           2 :                     $$ = makeNullAConst(@1);
   13316             :                 }
   13317             :         ;
   13318             : 
   13319             : select_offset_value:
   13320         756 :             a_expr                                  { $$ = $1; }
   13321             :         ;
   13322             : 
   13323             : /*
   13324             :  * Allowing full expressions without parentheses causes various parsing
   13325             :  * problems with the trailing ROW/ROWS key words.  SQL spec only calls for
   13326             :  * <simple value specification>, which is either a literal or a parameter (but
   13327             :  * an <SQL parameter reference> could be an identifier, bringing up conflicts
   13328             :  * with ROW/ROWS). We solve this by leveraging the presence of ONLY (see above)
   13329             :  * to determine whether the expression is missing rather than trying to make it
   13330             :  * optional in this rule.
   13331             :  *
   13332             :  * c_expr covers almost all the spec-required cases (and more), but it doesn't
   13333             :  * cover signed numeric literals, which are allowed by the spec. So we include
   13334             :  * those here explicitly. We need FCONST as well as ICONST because values that
   13335             :  * don't fit in the platform's "long", but do fit in bigint, should still be
   13336             :  * accepted here. (This is possible in 64-bit Windows as well as all 32-bit
   13337             :  * builds.)
   13338             :  */
   13339             : select_fetch_first_value:
   13340          74 :             c_expr                                  { $$ = $1; }
   13341             :             | '+' I_or_F_const
   13342           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   13343             :             | '-' I_or_F_const
   13344           0 :                 { $$ = doNegate($2, @1); }
   13345             :         ;
   13346             : 
   13347             : I_or_F_const:
   13348           0 :             Iconst                                  { $$ = makeIntConst($1,@1); }
   13349           0 :             | FCONST                                { $$ = makeFloatConst($1,@1); }
   13350             :         ;
   13351             : 
   13352             : /* noise words */
   13353          32 : row_or_rows: ROW                                    { $$ = 0; }
   13354          48 :             | ROWS                                  { $$ = 0; }
   13355             :         ;
   13356             : 
   13357          80 : first_or_next: FIRST_P                              { $$ = 0; }
   13358           0 :             | NEXT                                  { $$ = 0; }
   13359             :         ;
   13360             : 
   13361             : 
   13362             : /*
   13363             :  * This syntax for group_clause tries to follow the spec quite closely.
   13364             :  * However, the spec allows only column references, not expressions,
   13365             :  * which introduces an ambiguity between implicit row constructors
   13366             :  * (a,b) and lists of column references.
   13367             :  *
   13368             :  * We handle this by using the a_expr production for what the spec calls
   13369             :  * <ordinary grouping set>, which in the spec represents either one column
   13370             :  * reference or a parenthesized list of column references. Then, we check the
   13371             :  * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
   13372             :  * grab and use the list, discarding the node. (this is done in parse analysis,
   13373             :  * not here)
   13374             :  *
   13375             :  * (we abuse the row_format field of RowExpr to distinguish implicit and
   13376             :  * explicit row constructors; it's debatable if anyone sanely wants to use them
   13377             :  * in a group clause, but if they have a reason to, we make it possible.)
   13378             :  *
   13379             :  * Each item in the group_clause list is either an expression tree or a
   13380             :  * GroupingSet node of some type.
   13381             :  */
   13382             : group_clause:
   13383             :             GROUP_P BY set_quantifier group_by_list
   13384             :                 {
   13385        4188 :                     GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
   13386             : 
   13387        4188 :                     n->distinct = $3 == SET_QUANTIFIER_DISTINCT;
   13388        4188 :                     n->list = $4;
   13389        4188 :                     $$ = n;
   13390             :                 }
   13391             :             | /*EMPTY*/
   13392             :                 {
   13393      450274 :                     GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
   13394             : 
   13395      450274 :                     n->distinct = false;
   13396      450274 :                     n->list = NIL;
   13397      450274 :                     $$ = n;
   13398             :                 }
   13399             :         ;
   13400             : 
   13401             : group_by_list:
   13402        4678 :             group_by_item                           { $$ = list_make1($1); }
   13403        2730 :             | group_by_list ',' group_by_item       { $$ = lappend($1,$3); }
   13404             :         ;
   13405             : 
   13406             : group_by_item:
   13407        6262 :             a_expr                                  { $$ = $1; }
   13408         222 :             | empty_grouping_set                    { $$ = $1; }
   13409         184 :             | cube_clause                           { $$ = $1; }
   13410         250 :             | rollup_clause                         { $$ = $1; }
   13411         490 :             | grouping_sets_clause                  { $$ = $1; }
   13412             :         ;
   13413             : 
   13414             : empty_grouping_set:
   13415             :             '(' ')'
   13416             :                 {
   13417         222 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, @1);
   13418             :                 }
   13419             :         ;
   13420             : 
   13421             : /*
   13422             :  * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
   13423             :  * so that they shift in these rules rather than reducing the conflicting
   13424             :  * unreserved_keyword rule.
   13425             :  */
   13426             : 
   13427             : rollup_clause:
   13428             :             ROLLUP '(' expr_list ')'
   13429             :                 {
   13430         250 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_ROLLUP, $3, @1);
   13431             :                 }
   13432             :         ;
   13433             : 
   13434             : cube_clause:
   13435             :             CUBE '(' expr_list ')'
   13436             :                 {
   13437         184 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_CUBE, $3, @1);
   13438             :                 }
   13439             :         ;
   13440             : 
   13441             : grouping_sets_clause:
   13442             :             GROUPING SETS '(' group_by_list ')'
   13443             :                 {
   13444         490 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_SETS, $4, @1);
   13445             :                 }
   13446             :         ;
   13447             : 
   13448             : having_clause:
   13449         774 :             HAVING a_expr                           { $$ = $2; }
   13450      453688 :             | /*EMPTY*/                             { $$ = NULL; }
   13451             :         ;
   13452             : 
   13453             : for_locking_clause:
   13454        5082 :             for_locking_items                       { $$ = $1; }
   13455           0 :             | FOR READ ONLY                         { $$ = NIL; }
   13456             :         ;
   13457             : 
   13458             : opt_for_locking_clause:
   13459         340 :             for_locking_clause                      { $$ = $1; }
   13460       41098 :             | /* EMPTY */                           { $$ = NIL; }
   13461             :         ;
   13462             : 
   13463             : for_locking_items:
   13464        5082 :             for_locking_item                        { $$ = list_make1($1); }
   13465          98 :             | for_locking_items for_locking_item    { $$ = lappend($1, $2); }
   13466             :         ;
   13467             : 
   13468             : for_locking_item:
   13469             :             for_locking_strength locked_rels_list opt_nowait_or_skip
   13470             :                 {
   13471        5180 :                     LockingClause *n = makeNode(LockingClause);
   13472             : 
   13473        5180 :                     n->lockedRels = $2;
   13474        5180 :                     n->strength = $1;
   13475        5180 :                     n->waitPolicy = $3;
   13476        5180 :                     $$ = (Node *) n;
   13477             :                 }
   13478             :         ;
   13479             : 
   13480             : for_locking_strength:
   13481        1450 :             FOR UPDATE                          { $$ = LCS_FORUPDATE; }
   13482          66 :             | FOR NO KEY UPDATE                 { $$ = LCS_FORNOKEYUPDATE; }
   13483         214 :             | FOR SHARE                         { $$ = LCS_FORSHARE; }
   13484        3450 :             | FOR KEY SHARE                     { $$ = LCS_FORKEYSHARE; }
   13485             :         ;
   13486             : 
   13487             : locked_rels_list:
   13488        3456 :             OF qualified_name_list                  { $$ = $2; }
   13489        1724 :             | /* EMPTY */                           { $$ = NIL; }
   13490             :         ;
   13491             : 
   13492             : 
   13493             : /*
   13494             :  * We should allow ROW '(' expr_list ')' too, but that seems to require
   13495             :  * making VALUES a fully reserved word, which will probably break more apps
   13496             :  * than allowing the noise-word is worth.
   13497             :  */
   13498             : values_clause:
   13499             :             VALUES '(' expr_list ')'
   13500             :                 {
   13501       60626 :                     SelectStmt *n = makeNode(SelectStmt);
   13502             : 
   13503       60626 :                     n->valuesLists = list_make1($3);
   13504       60626 :                     $$ = (Node *) n;
   13505             :                 }
   13506             :             | values_clause ',' '(' expr_list ')'
   13507             :                 {
   13508       24360 :                     SelectStmt *n = (SelectStmt *) $1;
   13509             : 
   13510       24360 :                     n->valuesLists = lappend(n->valuesLists, $4);
   13511       24360 :                     $$ = (Node *) n;
   13512             :                 }
   13513             :         ;
   13514             : 
   13515             : 
   13516             : /*****************************************************************************
   13517             :  *
   13518             :  *  clauses common to all Optimizable Stmts:
   13519             :  *      from_clause     - allow list of both JOIN expressions and table names
   13520             :  *      where_clause    - qualifications for joins or restrictions
   13521             :  *
   13522             :  *****************************************************************************/
   13523             : 
   13524             : from_clause:
   13525      269548 :             FROM from_list                          { $$ = $2; }
   13526      198332 :             | /*EMPTY*/                             { $$ = NIL; }
   13527             :         ;
   13528             : 
   13529             : from_list:
   13530      270228 :             table_ref                               { $$ = list_make1($1); }
   13531       52438 :             | from_list ',' table_ref               { $$ = lappend($1, $3); }
   13532             :         ;
   13533             : 
   13534             : /*
   13535             :  * table_ref is where an alias clause can be attached.
   13536             :  */
   13537             : table_ref:  relation_expr opt_alias_clause
   13538             :                 {
   13539      344386 :                     $1->alias = $2;
   13540      344386 :                     $$ = (Node *) $1;
   13541             :                 }
   13542             :             | relation_expr opt_alias_clause tablesample_clause
   13543             :                 {
   13544         254 :                     RangeTableSample *n = (RangeTableSample *) $3;
   13545             : 
   13546         254 :                     $1->alias = $2;
   13547             :                     /* relation_expr goes inside the RangeTableSample node */
   13548         254 :                     n->relation = (Node *) $1;
   13549         254 :                     $$ = (Node *) n;
   13550             :                 }
   13551             :             | func_table func_alias_clause
   13552             :                 {
   13553       38340 :                     RangeFunction *n = (RangeFunction *) $1;
   13554             : 
   13555       38340 :                     n->alias = linitial($2);
   13556       38340 :                     n->coldeflist = lsecond($2);
   13557       38340 :                     $$ = (Node *) n;
   13558             :                 }
   13559             :             | LATERAL_P func_table func_alias_clause
   13560             :                 {
   13561         990 :                     RangeFunction *n = (RangeFunction *) $2;
   13562             : 
   13563         990 :                     n->lateral = true;
   13564         990 :                     n->alias = linitial($3);
   13565         990 :                     n->coldeflist = lsecond($3);
   13566         990 :                     $$ = (Node *) n;
   13567             :                 }
   13568             :             | xmltable opt_alias_clause
   13569             :                 {
   13570          80 :                     RangeTableFunc *n = (RangeTableFunc *) $1;
   13571             : 
   13572          80 :                     n->alias = $2;
   13573          80 :                     $$ = (Node *) n;
   13574             :                 }
   13575             :             | LATERAL_P xmltable opt_alias_clause
   13576             :                 {
   13577         140 :                     RangeTableFunc *n = (RangeTableFunc *) $2;
   13578             : 
   13579         140 :                     n->lateral = true;
   13580         140 :                     n->alias = $3;
   13581         140 :                     $$ = (Node *) n;
   13582             :                 }
   13583             :             | select_with_parens opt_alias_clause
   13584             :                 {
   13585       12470 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13586             : 
   13587       12470 :                     n->lateral = false;
   13588       12470 :                     n->subquery = $1;
   13589       12470 :                     n->alias = $2;
   13590       12470 :                     $$ = (Node *) n;
   13591             :                 }
   13592             :             | LATERAL_P select_with_parens opt_alias_clause
   13593             :                 {
   13594        1370 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13595             : 
   13596        1370 :                     n->lateral = true;
   13597        1370 :                     n->subquery = $2;
   13598        1370 :                     n->alias = $3;
   13599        1370 :                     $$ = (Node *) n;
   13600             :                 }
   13601             :             | joined_table
   13602             :                 {
   13603       73650 :                     $$ = (Node *) $1;
   13604             :                 }
   13605             :             | '(' joined_table ')' alias_clause
   13606             :                 {
   13607         174 :                     $2->alias = $4;
   13608         174 :                     $$ = (Node *) $2;
   13609             :                 }
   13610             :             | json_table opt_alias_clause
   13611             :                 {
   13612         428 :                     JsonTable  *jt = castNode(JsonTable, $1);
   13613             : 
   13614         428 :                     jt->alias = $2;
   13615         428 :                     $$ = (Node *) jt;
   13616             :                 }
   13617             :             | LATERAL_P json_table opt_alias_clause
   13618             :                 {
   13619           0 :                     JsonTable  *jt = castNode(JsonTable, $2);
   13620             : 
   13621           0 :                     jt->alias = $3;
   13622           0 :                     jt->lateral = true;
   13623           0 :                     $$ = (Node *) jt;
   13624             :                 }
   13625             :         ;
   13626             : 
   13627             : 
   13628             : /*
   13629             :  * It may seem silly to separate joined_table from table_ref, but there is
   13630             :  * method in SQL's madness: if you don't do it this way you get reduce-
   13631             :  * reduce conflicts, because it's not clear to the parser generator whether
   13632             :  * to expect alias_clause after ')' or not.  For the same reason we must
   13633             :  * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
   13634             :  * join_type to expand to empty; if we try it, the parser generator can't
   13635             :  * figure out when to reduce an empty join_type right after table_ref.
   13636             :  *
   13637             :  * Note that a CROSS JOIN is the same as an unqualified
   13638             :  * INNER JOIN, and an INNER JOIN/ON has the same shape
   13639             :  * but a qualification expression to limit membership.
   13640             :  * A NATURAL JOIN implicitly matches column names between
   13641             :  * tables and the shape is determined by which columns are
   13642             :  * in common. We'll collect columns during the later transformations.
   13643             :  */
   13644             : 
   13645             : joined_table:
   13646             :             '(' joined_table ')'
   13647             :                 {
   13648        3398 :                     $$ = $2;
   13649             :                 }
   13650             :             | table_ref CROSS JOIN table_ref
   13651             :                 {
   13652             :                     /* CROSS JOIN is same as unqualified inner join */
   13653         298 :                     JoinExpr   *n = makeNode(JoinExpr);
   13654             : 
   13655         298 :                     n->jointype = JOIN_INNER;
   13656         298 :                     n->isNatural = false;
   13657         298 :                     n->larg = $1;
   13658         298 :                     n->rarg = $4;
   13659         298 :                     n->usingClause = NIL;
   13660         298 :                     n->join_using_alias = NULL;
   13661         298 :                     n->quals = NULL;
   13662         298 :                     $$ = n;
   13663             :                 }
   13664             :             | table_ref join_type JOIN table_ref join_qual
   13665             :                 {
   13666       44500 :                     JoinExpr   *n = makeNode(JoinExpr);
   13667             : 
   13668       44500 :                     n->jointype = $2;
   13669       44500 :                     n->isNatural = false;
   13670       44500 :                     n->larg = $1;
   13671       44500 :                     n->rarg = $4;
   13672       44500 :                     if ($5 != NULL && IsA($5, List))
   13673             :                     {
   13674             :                          /* USING clause */
   13675         486 :                         n->usingClause = linitial_node(List, castNode(List, $5));
   13676         486 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $5));
   13677             :                     }
   13678             :                     else
   13679             :                     {
   13680             :                         /* ON clause */
   13681       44014 :                         n->quals = $5;
   13682             :                     }
   13683       44500 :                     $$ = n;
   13684             :                 }
   13685             :             | table_ref JOIN table_ref join_qual
   13686             :                 {
   13687             :                     /* letting join_type reduce to empty doesn't work */
   13688       28768 :                     JoinExpr   *n = makeNode(JoinExpr);
   13689             : 
   13690       28768 :                     n->jointype = JOIN_INNER;
   13691       28768 :                     n->isNatural = false;
   13692       28768 :                     n->larg = $1;
   13693       28768 :                     n->rarg = $3;
   13694       28768 :                     if ($4 != NULL && IsA($4, List))
   13695             :                     {
   13696             :                         /* USING clause */
   13697         708 :                         n->usingClause = linitial_node(List, castNode(List, $4));
   13698         708 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $4));
   13699             :                     }
   13700             :                     else
   13701             :                     {
   13702             :                         /* ON clause */
   13703       28060 :                         n->quals = $4;
   13704             :                     }
   13705       28768 :                     $$ = n;
   13706             :                 }
   13707             :             | table_ref NATURAL join_type JOIN table_ref
   13708             :                 {
   13709          78 :                     JoinExpr   *n = makeNode(JoinExpr);
   13710             : 
   13711          78 :                     n->jointype = $3;
   13712          78 :                     n->isNatural = true;
   13713          78 :                     n->larg = $1;
   13714          78 :                     n->rarg = $5;
   13715          78 :                     n->usingClause = NIL; /* figure out which columns later... */
   13716          78 :                     n->join_using_alias = NULL;
   13717          78 :                     n->quals = NULL; /* fill later */
   13718          78 :                     $$ = n;
   13719             :                 }
   13720             :             | table_ref NATURAL JOIN table_ref
   13721             :                 {
   13722             :                     /* letting join_type reduce to empty doesn't work */
   13723         180 :                     JoinExpr   *n = makeNode(JoinExpr);
   13724             : 
   13725         180 :                     n->jointype = JOIN_INNER;
   13726         180 :                     n->isNatural = true;
   13727         180 :                     n->larg = $1;
   13728         180 :                     n->rarg = $4;
   13729         180 :                     n->usingClause = NIL; /* figure out which columns later... */
   13730         180 :                     n->join_using_alias = NULL;
   13731         180 :                     n->quals = NULL; /* fill later */
   13732         180 :                     $$ = n;
   13733             :                 }
   13734             :         ;
   13735             : 
   13736             : alias_clause:
   13737             :             AS ColId '(' name_list ')'
   13738             :                 {
   13739        5424 :                     $$ = makeNode(Alias);
   13740        5424 :                     $$->aliasname = $2;
   13741        5424 :                     $$->colnames = $4;
   13742             :                 }
   13743             :             | AS ColId
   13744             :                 {
   13745       11572 :                     $$ = makeNode(Alias);
   13746       11572 :                     $$->aliasname = $2;
   13747             :                 }
   13748             :             | ColId '(' name_list ')'
   13749             :                 {
   13750        5418 :                     $$ = makeNode(Alias);
   13751        5418 :                     $$->aliasname = $1;
   13752        5418 :                     $$->colnames = $3;
   13753             :                 }
   13754             :             | ColId
   13755             :                 {
   13756      224718 :                     $$ = makeNode(Alias);
   13757      224718 :                     $$->aliasname = $1;
   13758             :                 }
   13759             :         ;
   13760             : 
   13761      221288 : opt_alias_clause: alias_clause                      { $$ = $1; }
   13762      137840 :             | /*EMPTY*/                             { $$ = NULL; }
   13763             :         ;
   13764             : 
   13765             : /*
   13766             :  * The alias clause after JOIN ... USING only accepts the AS ColId spelling,
   13767             :  * per SQL standard.  (The grammar could parse the other variants, but they
   13768             :  * don't seem to be useful, and it might lead to parser problems in the
   13769             :  * future.)
   13770             :  */
   13771             : opt_alias_clause_for_join_using:
   13772             :             AS ColId
   13773             :                 {
   13774          84 :                     $$ = makeNode(Alias);
   13775          84 :                     $$->aliasname = $2;
   13776             :                     /* the column name list will be inserted later */
   13777             :                 }
   13778        1110 :             | /*EMPTY*/                             { $$ = NULL; }
   13779             :         ;
   13780             : 
   13781             : /*
   13782             :  * func_alias_clause can include both an Alias and a coldeflist, so we make it
   13783             :  * return a 2-element list that gets disassembled by calling production.
   13784             :  */
   13785             : func_alias_clause:
   13786             :             alias_clause
   13787             :                 {
   13788       25670 :                     $$ = list_make2($1, NIL);
   13789             :                 }
   13790             :             | AS '(' TableFuncElementList ')'
   13791             :                 {
   13792         110 :                     $$ = list_make2(NULL, $3);
   13793             :                 }
   13794             :             | AS ColId '(' TableFuncElementList ')'
   13795             :                 {
   13796         586 :                     Alias      *a = makeNode(Alias);
   13797             : 
   13798         586 :                     a->aliasname = $2;
   13799         586 :                     $$ = list_make2(a, $4);
   13800             :                 }
   13801             :             | ColId '(' TableFuncElementList ')'
   13802             :                 {
   13803          50 :                     Alias      *a = makeNode(Alias);
   13804             : 
   13805          50 :                     a->aliasname = $1;
   13806          50 :                     $$ = list_make2(a, $3);
   13807             :                 }
   13808             :             | /*EMPTY*/
   13809             :                 {
   13810       12914 :                     $$ = list_make2(NULL, NIL);
   13811             :                 }
   13812             :         ;
   13813             : 
   13814        1006 : join_type:  FULL opt_outer                          { $$ = JOIN_FULL; }
   13815       39470 :             | LEFT opt_outer                        { $$ = JOIN_LEFT; }
   13816         338 :             | RIGHT opt_outer                       { $$ = JOIN_RIGHT; }
   13817        3764 :             | INNER_P                               { $$ = JOIN_INNER; }
   13818             :         ;
   13819             : 
   13820             : /* OUTER is just noise... */
   13821             : opt_outer: OUTER_P
   13822             :             | /*EMPTY*/
   13823             :         ;
   13824             : 
   13825             : /* JOIN qualification clauses
   13826             :  * Possibilities are:
   13827             :  *  USING ( column list ) [ AS alias ]
   13828             :  *                        allows only unqualified column names,
   13829             :  *                        which must match between tables.
   13830             :  *  ON expr allows more general qualifications.
   13831             :  *
   13832             :  * We return USING as a two-element List (the first item being a sub-List
   13833             :  * of the common column names, and the second either an Alias item or NULL).
   13834             :  * An ON-expr will not be a List, so it can be told apart that way.
   13835             :  */
   13836             : 
   13837             : join_qual: USING '(' name_list ')' opt_alias_clause_for_join_using
   13838             :                 {
   13839        1194 :                     $$ = (Node *) list_make2($3, $5);
   13840             :                 }
   13841             :             | ON a_expr
   13842             :                 {
   13843       72074 :                     $$ = $2;
   13844             :                 }
   13845             :         ;
   13846             : 
   13847             : 
   13848             : relation_expr:
   13849             :             qualified_name
   13850             :                 {
   13851             :                     /* inheritance query, implicitly */
   13852      403906 :                     $$ = $1;
   13853      403906 :                     $$->inh = true;
   13854      403906 :                     $$->alias = NULL;
   13855             :                 }
   13856             :             | extended_relation_expr
   13857             :                 {
   13858        7004 :                     $$ = $1;
   13859             :                 }
   13860             :         ;
   13861             : 
   13862             : extended_relation_expr:
   13863             :             qualified_name '*'
   13864             :                 {
   13865             :                     /* inheritance query, explicitly */
   13866         204 :                     $$ = $1;
   13867         204 :                     $$->inh = true;
   13868         204 :                     $$->alias = NULL;
   13869             :                 }
   13870             :             | ONLY qualified_name
   13871             :                 {
   13872             :                     /* no inheritance */
   13873        6806 :                     $$ = $2;
   13874        6806 :                     $$->inh = false;
   13875        6806 :                     $$->alias = NULL;
   13876             :                 }
   13877             :             | ONLY '(' qualified_name ')'
   13878             :                 {
   13879             :                     /* no inheritance, SQL99-style syntax */
   13880           0 :                     $$ = $3;
   13881           0 :                     $$->inh = false;
   13882           0 :                     $$->alias = NULL;
   13883             :                 }
   13884             :         ;
   13885             : 
   13886             : 
   13887             : relation_expr_list:
   13888        2548 :             relation_expr                           { $$ = list_make1($1); }
   13889        9474 :             | relation_expr_list ',' relation_expr  { $$ = lappend($1, $3); }
   13890             :         ;
   13891             : 
   13892             : 
   13893             : /*
   13894             :  * Given "UPDATE foo set set ...", we have to decide without looking any
   13895             :  * further ahead whether the first "set" is an alias or the UPDATE's SET
   13896             :  * keyword.  Since "set" is allowed as a column name both interpretations
   13897             :  * are feasible.  We resolve the shift/reduce conflict by giving the first
   13898             :  * relation_expr_opt_alias production a higher precedence than the SET token
   13899             :  * has, causing the parser to prefer to reduce, in effect assuming that the
   13900             :  * SET is not an alias.
   13901             :  */
   13902             : relation_expr_opt_alias: relation_expr                  %prec UMINUS
   13903             :                 {
   13904       17718 :                     $$ = $1;
   13905             :                 }
   13906             :             | relation_expr ColId
   13907             :                 {
   13908        2090 :                     Alias      *alias = makeNode(Alias);
   13909             : 
   13910        2090 :                     alias->aliasname = $2;
   13911        2090 :                     $1->alias = alias;
   13912        2090 :                     $$ = $1;
   13913             :                 }
   13914             :             | relation_expr AS ColId
   13915             :                 {
   13916          78 :                     Alias      *alias = makeNode(Alias);
   13917             : 
   13918          78 :                     alias->aliasname = $3;
   13919          78 :                     $1->alias = alias;
   13920          78 :                     $$ = $1;
   13921             :                 }
   13922             :         ;
   13923             : 
   13924             : /*
   13925             :  * TABLESAMPLE decoration in a FROM item
   13926             :  */
   13927             : tablesample_clause:
   13928             :             TABLESAMPLE func_name '(' expr_list ')' opt_repeatable_clause
   13929             :                 {
   13930         254 :                     RangeTableSample *n = makeNode(RangeTableSample);
   13931             : 
   13932             :                     /* n->relation will be filled in later */
   13933         254 :                     n->method = $2;
   13934         254 :                     n->args = $4;
   13935         254 :                     n->repeatable = $6;
   13936         254 :                     n->location = @2;
   13937         254 :                     $$ = (Node *) n;
   13938             :                 }
   13939             :         ;
   13940             : 
   13941             : opt_repeatable_clause:
   13942         108 :             REPEATABLE '(' a_expr ')'   { $$ = (Node *) $3; }
   13943         146 :             | /*EMPTY*/                 { $$ = NULL; }
   13944             :         ;
   13945             : 
   13946             : /*
   13947             :  * func_table represents a function invocation in a FROM list. It can be
   13948             :  * a plain function call, like "foo(...)", or a ROWS FROM expression with
   13949             :  * one or more function calls, "ROWS FROM (foo(...), bar(...))",
   13950             :  * optionally with WITH ORDINALITY attached.
   13951             :  * In the ROWS FROM syntax, a column definition list can be given for each
   13952             :  * function, for example:
   13953             :  *     ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
   13954             :  *                bar() AS (bar_res_a text, bar_res_b text))
   13955             :  * It's also possible to attach a column definition list to the RangeFunction
   13956             :  * as a whole, but that's handled by the table_ref production.
   13957             :  */
   13958             : func_table: func_expr_windowless opt_ordinality
   13959             :                 {
   13960       39204 :                     RangeFunction *n = makeNode(RangeFunction);
   13961             : 
   13962       39204 :                     n->lateral = false;
   13963       39204 :                     n->ordinality = $2;
   13964       39204 :                     n->is_rowsfrom = false;
   13965       39204 :                     n->functions = list_make1(list_make2($1, NIL));
   13966             :                     /* alias and coldeflist are set by table_ref production */
   13967       39204 :                     $$ = (Node *) n;
   13968             :                 }
   13969             :             | ROWS FROM '(' rowsfrom_list ')' opt_ordinality
   13970             :                 {
   13971         132 :                     RangeFunction *n = makeNode(RangeFunction);
   13972             : 
   13973         132 :                     n->lateral = false;
   13974         132 :                     n->ordinality = $6;
   13975         132 :                     n->is_rowsfrom = true;
   13976         132 :                     n->functions = $4;
   13977             :                     /* alias and coldeflist are set by table_ref production */
   13978         132 :                     $$ = (Node *) n;
   13979             :                 }
   13980             :         ;
   13981             : 
   13982             : rowsfrom_item: func_expr_windowless opt_col_def_list
   13983         318 :                 { $$ = list_make2($1, $2); }
   13984             :         ;
   13985             : 
   13986             : rowsfrom_list:
   13987         132 :             rowsfrom_item                       { $$ = list_make1($1); }
   13988         186 :             | rowsfrom_list ',' rowsfrom_item   { $$ = lappend($1, $3); }
   13989             :         ;
   13990             : 
   13991          54 : opt_col_def_list: AS '(' TableFuncElementList ')'   { $$ = $3; }
   13992         264 :             | /*EMPTY*/                             { $$ = NIL; }
   13993             :         ;
   13994             : 
   13995         762 : opt_ordinality: WITH_LA ORDINALITY                  { $$ = true; }
   13996       38574 :             | /*EMPTY*/                             { $$ = false; }
   13997             :         ;
   13998             : 
   13999             : 
   14000             : where_clause:
   14001      180110 :             WHERE a_expr                            { $$ = $2; }
   14002      293132 :             | /*EMPTY*/                             { $$ = NULL; }
   14003             :         ;
   14004             : 
   14005             : /* variant for UPDATE and DELETE */
   14006             : where_or_current_clause:
   14007       12870 :             WHERE a_expr                            { $$ = $2; }
   14008             :             | WHERE CURRENT_P OF cursor_name
   14009             :                 {
   14010         266 :                     CurrentOfExpr *n = makeNode(CurrentOfExpr);
   14011             : 
   14012             :                     /* cvarno is filled in by parse analysis */
   14013         266 :                     n->cursor_name = $4;
   14014         266 :                     n->cursor_param = 0;
   14015         266 :                     $$ = (Node *) n;
   14016             :                 }
   14017        4770 :             | /*EMPTY*/                             { $$ = NULL; }
   14018             :         ;
   14019             : 
   14020             : 
   14021             : OptTableFuncElementList:
   14022         684 :             TableFuncElementList                { $$ = $1; }
   14023           6 :             | /*EMPTY*/                         { $$ = NIL; }
   14024             :         ;
   14025             : 
   14026             : TableFuncElementList:
   14027             :             TableFuncElement
   14028             :                 {
   14029        1484 :                     $$ = list_make1($1);
   14030             :                 }
   14031             :             | TableFuncElementList ',' TableFuncElement
   14032             :                 {
   14033        1978 :                     $$ = lappend($1, $3);
   14034             :                 }
   14035             :         ;
   14036             : 
   14037             : TableFuncElement:   ColId Typename opt_collate_clause
   14038             :                 {
   14039        3526 :                     ColumnDef *n = makeNode(ColumnDef);
   14040             : 
   14041        3526 :                     n->colname = $1;
   14042        3526 :                     n->typeName = $2;
   14043        3526 :                     n->inhcount = 0;
   14044        3526 :                     n->is_local = true;
   14045        3526 :                     n->is_not_null = false;
   14046        3526 :                     n->is_from_type = false;
   14047        3526 :                     n->storage = 0;
   14048        3526 :                     n->raw_default = NULL;
   14049        3526 :                     n->cooked_default = NULL;
   14050        3526 :                     n->collClause = (CollateClause *) $3;
   14051        3526 :                     n->collOid = InvalidOid;
   14052        3526 :                     n->constraints = NIL;
   14053        3526 :                     n->location = @1;
   14054        3526 :                     $$ = (Node *) n;
   14055             :                 }
   14056             :         ;
   14057             : 
   14058             : /*
   14059             :  * XMLTABLE
   14060             :  */
   14061             : xmltable:
   14062             :             XMLTABLE '(' c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   14063             :                 {
   14064         200 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   14065             : 
   14066         200 :                     n->rowexpr = $3;
   14067         200 :                     n->docexpr = $4;
   14068         200 :                     n->columns = $6;
   14069         200 :                     n->namespaces = NIL;
   14070         200 :                     n->location = @1;
   14071         200 :                     $$ = (Node *) n;
   14072             :                 }
   14073             :             | XMLTABLE '(' XMLNAMESPACES '(' xml_namespace_list ')' ','
   14074             :                 c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   14075             :                 {
   14076          20 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   14077             : 
   14078          20 :                     n->rowexpr = $8;
   14079          20 :                     n->docexpr = $9;
   14080          20 :                     n->columns = $11;
   14081          20 :                     n->namespaces = $5;
   14082          20 :                     n->location = @1;
   14083          20 :                     $$ = (Node *) n;
   14084             :                 }
   14085             :         ;
   14086             : 
   14087         220 : xmltable_column_list: xmltable_column_el                    { $$ = list_make1($1); }
   14088         530 :             | xmltable_column_list ',' xmltable_column_el   { $$ = lappend($1, $3); }
   14089             :         ;
   14090             : 
   14091             : xmltable_column_el:
   14092             :             ColId Typename
   14093             :                 {
   14094         198 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14095             : 
   14096         198 :                     fc->colname = $1;
   14097         198 :                     fc->for_ordinality = false;
   14098         198 :                     fc->typeName = $2;
   14099         198 :                     fc->is_not_null = false;
   14100         198 :                     fc->colexpr = NULL;
   14101         198 :                     fc->coldefexpr = NULL;
   14102         198 :                     fc->location = @1;
   14103             : 
   14104         198 :                     $$ = (Node *) fc;
   14105             :                 }
   14106             :             | ColId Typename xmltable_column_option_list
   14107             :                 {
   14108         490 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14109             :                     ListCell   *option;
   14110         490 :                     bool        nullability_seen = false;
   14111             : 
   14112         490 :                     fc->colname = $1;
   14113         490 :                     fc->typeName = $2;
   14114         490 :                     fc->for_ordinality = false;
   14115         490 :                     fc->is_not_null = false;
   14116         490 :                     fc->colexpr = NULL;
   14117         490 :                     fc->coldefexpr = NULL;
   14118         490 :                     fc->location = @1;
   14119             : 
   14120        1092 :                     foreach(option, $3)
   14121             :                     {
   14122         602 :                         DefElem   *defel = (DefElem *) lfirst(option);
   14123             : 
   14124         602 :                         if (strcmp(defel->defname, "default") == 0)
   14125             :                         {
   14126          56 :                             if (fc->coldefexpr != NULL)
   14127           0 :                                 ereport(ERROR,
   14128             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14129             :                                          errmsg("only one DEFAULT value is allowed"),
   14130             :                                          parser_errposition(defel->location)));
   14131          56 :                             fc->coldefexpr = defel->arg;
   14132             :                         }
   14133         546 :                         else if (strcmp(defel->defname, "path") == 0)
   14134             :                         {
   14135         490 :                             if (fc->colexpr != NULL)
   14136           0 :                                 ereport(ERROR,
   14137             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14138             :                                          errmsg("only one PATH value per column is allowed"),
   14139             :                                          parser_errposition(defel->location)));
   14140         490 :                             fc->colexpr = defel->arg;
   14141             :                         }
   14142          56 :                         else if (strcmp(defel->defname, "is_not_null") == 0)
   14143             :                         {
   14144          56 :                             if (nullability_seen)
   14145           0 :                                 ereport(ERROR,
   14146             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14147             :                                          errmsg("conflicting or redundant NULL / NOT NULL declarations for column \"%s\"", fc->colname),
   14148             :                                          parser_errposition(defel->location)));
   14149          56 :                             fc->is_not_null = boolVal(defel->arg);
   14150          56 :                             nullability_seen = true;
   14151             :                         }
   14152             :                         else
   14153             :                         {
   14154           0 :                             ereport(ERROR,
   14155             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   14156             :                                      errmsg("unrecognized column option \"%s\"",
   14157             :                                             defel->defname),
   14158             :                                      parser_errposition(defel->location)));
   14159             :                         }
   14160             :                     }
   14161         490 :                     $$ = (Node *) fc;
   14162             :                 }
   14163             :             | ColId FOR ORDINALITY
   14164             :                 {
   14165          62 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14166             : 
   14167          62 :                     fc->colname = $1;
   14168          62 :                     fc->for_ordinality = true;
   14169             :                     /* other fields are ignored, initialized by makeNode */
   14170          62 :                     fc->location = @1;
   14171             : 
   14172          62 :                     $$ = (Node *) fc;
   14173             :                 }
   14174             :         ;
   14175             : 
   14176             : xmltable_column_option_list:
   14177             :             xmltable_column_option_el
   14178         490 :                 { $$ = list_make1($1); }
   14179             :             | xmltable_column_option_list xmltable_column_option_el
   14180         112 :                 { $$ = lappend($1, $2); }
   14181             :         ;
   14182             : 
   14183             : xmltable_column_option_el:
   14184             :             IDENT b_expr
   14185           0 :                 { $$ = makeDefElem($1, $2, @1); }
   14186             :             | DEFAULT b_expr
   14187          56 :                 { $$ = makeDefElem("default", $2, @1); }
   14188             :             | NOT NULL_P
   14189          56 :                 { $$ = makeDefElem("is_not_null", (Node *) makeBoolean(true), @1); }
   14190             :             | NULL_P
   14191           0 :                 { $$ = makeDefElem("is_not_null", (Node *) makeBoolean(false), @1); }
   14192             :             | PATH b_expr
   14193         490 :                 { $$ = makeDefElem("path", $2, @1); }
   14194             :         ;
   14195             : 
   14196             : xml_namespace_list:
   14197             :             xml_namespace_el
   14198          20 :                 { $$ = list_make1($1); }
   14199             :             | xml_namespace_list ',' xml_namespace_el
   14200           0 :                 { $$ = lappend($1, $3); }
   14201             :         ;
   14202             : 
   14203             : xml_namespace_el:
   14204             :             b_expr AS ColLabel
   14205             :                 {
   14206          14 :                     $$ = makeNode(ResTarget);
   14207          14 :                     $$->name = $3;
   14208          14 :                     $$->indirection = NIL;
   14209          14 :                     $$->val = $1;
   14210          14 :                     $$->location = @1;
   14211             :                 }
   14212             :             | DEFAULT b_expr
   14213             :                 {
   14214           6 :                     $$ = makeNode(ResTarget);
   14215           6 :                     $$->name = NULL;
   14216           6 :                     $$->indirection = NIL;
   14217           6 :                     $$->val = $2;
   14218           6 :                     $$->location = @1;
   14219             :                 }
   14220             :         ;
   14221             : 
   14222             : json_table:
   14223             :             JSON_TABLE '('
   14224             :                 json_value_expr ',' a_expr json_table_path_name_opt
   14225             :                 json_passing_clause_opt
   14226             :                 COLUMNS '(' json_table_column_definition_list ')'
   14227             :                 json_on_error_clause_opt
   14228             :             ')'
   14229             :                 {
   14230         434 :                     JsonTable *n = makeNode(JsonTable);
   14231             :                     char      *pathstring;
   14232             : 
   14233         434 :                     n->context_item = (JsonValueExpr *) $3;
   14234         434 :                     if (!IsA($5, A_Const) ||
   14235         428 :                         castNode(A_Const, $5)->val.node.type != T_String)
   14236           6 :                         ereport(ERROR,
   14237             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   14238             :                                 errmsg("only string constants are supported in JSON_TABLE path specification"),
   14239             :                                 parser_errposition(@5));
   14240         428 :                     pathstring = castNode(A_Const, $5)->val.sval.sval;
   14241         428 :                     n->pathspec = makeJsonTablePathSpec(pathstring, $6, @5, @6);
   14242         428 :                     n->passing = $7;
   14243         428 :                     n->columns = $10;
   14244         428 :                     n->on_error = (JsonBehavior *) $12;
   14245         428 :                     n->location = @1;
   14246         428 :                     $$ = (Node *) n;
   14247             :                 }
   14248             :         ;
   14249             : 
   14250             : json_table_path_name_opt:
   14251          62 :             AS name         { $$ = $2; }
   14252         378 :             | /* empty */   { $$ = NULL; }
   14253             :         ;
   14254             : 
   14255             : json_table_column_definition_list:
   14256             :             json_table_column_definition
   14257         724 :                 { $$ = list_make1($1); }
   14258             :             | json_table_column_definition_list ',' json_table_column_definition
   14259         528 :                 { $$ = lappend($1, $3); }
   14260             :         ;
   14261             : 
   14262             : json_table_column_definition:
   14263             :             ColId FOR ORDINALITY
   14264             :                 {
   14265          84 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14266             : 
   14267          84 :                     n->coltype = JTC_FOR_ORDINALITY;
   14268          84 :                     n->name = $1;
   14269          84 :                     n->location = @1;
   14270          84 :                     $$ = (Node *) n;
   14271             :                 }
   14272             :             | ColId Typename
   14273             :                 json_table_column_path_clause_opt
   14274             :                 json_wrapper_behavior
   14275             :                 json_quotes_clause_opt
   14276             :                 json_behavior_clause_opt
   14277             :                 {
   14278         686 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14279             : 
   14280         686 :                     n->coltype = JTC_REGULAR;
   14281         686 :                     n->name = $1;
   14282         686 :                     n->typeName = $2;
   14283         686 :                     n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   14284         686 :                     n->pathspec = (JsonTablePathSpec *) $3;
   14285         686 :                     n->wrapper = $4;
   14286         686 :                     n->quotes = $5;
   14287         686 :                     n->on_empty = (JsonBehavior *) linitial($6);
   14288         686 :                     n->on_error = (JsonBehavior *) lsecond($6);
   14289         686 :                     n->location = @1;
   14290         686 :                     $$ = (Node *) n;
   14291             :                 }
   14292             :             | ColId Typename json_format_clause
   14293             :                 json_table_column_path_clause_opt
   14294             :                 json_wrapper_behavior
   14295             :                 json_quotes_clause_opt
   14296             :                 json_behavior_clause_opt
   14297             :                 {
   14298         108 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14299             : 
   14300         108 :                     n->coltype = JTC_FORMATTED;
   14301         108 :                     n->name = $1;
   14302         108 :                     n->typeName = $2;
   14303         108 :                     n->format = (JsonFormat *) $3;
   14304         108 :                     n->pathspec = (JsonTablePathSpec *) $4;
   14305         108 :                     n->wrapper = $5;
   14306         108 :                     n->quotes = $6;
   14307         108 :                     n->on_empty = (JsonBehavior *) linitial($7);
   14308         108 :                     n->on_error = (JsonBehavior *) lsecond($7);
   14309         108 :                     n->location = @1;
   14310         108 :                     $$ = (Node *) n;
   14311             :                 }
   14312             :             | ColId Typename
   14313             :                 EXISTS json_table_column_path_clause_opt
   14314             :                 json_behavior_clause_opt
   14315             :                 {
   14316          84 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14317             : 
   14318          84 :                     n->coltype = JTC_EXISTS;
   14319          84 :                     n->name = $1;
   14320          84 :                     n->typeName = $2;
   14321          84 :                     n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   14322          84 :                     n->wrapper = JSW_NONE;
   14323          84 :                     n->quotes = JS_QUOTES_UNSPEC;
   14324          84 :                     n->pathspec = (JsonTablePathSpec *) $4;
   14325          84 :                     n->on_empty = (JsonBehavior *) linitial($5);
   14326          84 :                     n->on_error = (JsonBehavior *) lsecond($5);
   14327          84 :                     n->location = @1;
   14328          84 :                     $$ = (Node *) n;
   14329             :                 }
   14330             :             | NESTED path_opt Sconst
   14331             :                 COLUMNS '(' json_table_column_definition_list ')'
   14332             :                 {
   14333         144 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14334             : 
   14335         144 :                     n->coltype = JTC_NESTED;
   14336         288 :                     n->pathspec = (JsonTablePathSpec *)
   14337         144 :                         makeJsonTablePathSpec($3, NULL, @3, -1);
   14338         144 :                     n->columns = $6;
   14339         144 :                     n->location = @1;
   14340         144 :                     $$ = (Node *) n;
   14341             :                 }
   14342             :             | NESTED path_opt Sconst AS name
   14343             :                 COLUMNS '(' json_table_column_definition_list ')'
   14344             :                 {
   14345         146 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14346             : 
   14347         146 :                     n->coltype = JTC_NESTED;
   14348         292 :                     n->pathspec = (JsonTablePathSpec *)
   14349         146 :                         makeJsonTablePathSpec($3, $5, @3, @5);
   14350         146 :                     n->columns = $8;
   14351         146 :                     n->location = @1;
   14352         146 :                     $$ = (Node *) n;
   14353             :                 }
   14354             :         ;
   14355             : 
   14356             : path_opt:
   14357             :             PATH
   14358             :             | /* EMPTY */
   14359             :         ;
   14360             : 
   14361             : json_table_column_path_clause_opt:
   14362             :             PATH Sconst
   14363         756 :                 { $$ = (Node *) makeJsonTablePathSpec($2, NULL, @2, -1); }
   14364             :             | /* EMPTY */
   14365         122 :                 { $$ = NULL; }
   14366             :         ;
   14367             : 
   14368             : /*****************************************************************************
   14369             :  *
   14370             :  *  Type syntax
   14371             :  *      SQL introduces a large amount of type-specific syntax.
   14372             :  *      Define individual clauses to handle these cases, and use
   14373             :  *       the generic case to handle regular type-extensible Postgres syntax.
   14374             :  *      - thomas 1997-10-10
   14375             :  *
   14376             :  *****************************************************************************/
   14377             : 
   14378             : Typename:   SimpleTypename opt_array_bounds
   14379             :                 {
   14380      411172 :                     $$ = $1;
   14381      411172 :                     $$->arrayBounds = $2;
   14382             :                 }
   14383             :             | SETOF SimpleTypename opt_array_bounds
   14384             :                 {
   14385        1890 :                     $$ = $2;
   14386        1890 :                     $$->arrayBounds = $3;
   14387        1890 :                     $$->setof = true;
   14388             :                 }
   14389             :             /* SQL standard syntax, currently only one-dimensional */
   14390             :             | SimpleTypename ARRAY '[' Iconst ']'
   14391             :                 {
   14392           6 :                     $$ = $1;
   14393           6 :                     $$->arrayBounds = list_make1(makeInteger($4));
   14394             :                 }
   14395             :             | SETOF SimpleTypename ARRAY '[' Iconst ']'
   14396             :                 {
   14397           0 :                     $$ = $2;
   14398           0 :                     $$->arrayBounds = list_make1(makeInteger($5));
   14399           0 :                     $$->setof = true;
   14400             :                 }
   14401             :             | SimpleTypename ARRAY
   14402             :                 {
   14403           0 :                     $$ = $1;
   14404           0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   14405             :                 }
   14406             :             | SETOF SimpleTypename ARRAY
   14407             :                 {
   14408           0 :                     $$ = $2;
   14409           0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   14410           0 :                     $$->setof = true;
   14411             :                 }
   14412             :         ;
   14413             : 
   14414             : opt_array_bounds:
   14415             :             opt_array_bounds '[' ']'
   14416       11542 :                     {  $$ = lappend($1, makeInteger(-1)); }
   14417             :             | opt_array_bounds '[' Iconst ']'
   14418          62 :                     {  $$ = lappend($1, makeInteger($3)); }
   14419             :             | /*EMPTY*/
   14420      413062 :                     {  $$ = NIL; }
   14421             :         ;
   14422             : 
   14423             : SimpleTypename:
   14424      329696 :             GenericType                             { $$ = $1; }
   14425       69566 :             | Numeric                               { $$ = $1; }
   14426        1854 :             | Bit                                   { $$ = $1; }
   14427        3086 :             | Character                             { $$ = $1; }
   14428        4288 :             | ConstDatetime                         { $$ = $1; }
   14429             :             | ConstInterval opt_interval
   14430             :                 {
   14431        3308 :                     $$ = $1;
   14432        3308 :                     $$->typmods = $2;
   14433             :                 }
   14434             :             | ConstInterval '(' Iconst ')'
   14435             :                 {
   14436           0 :                     $$ = $1;
   14437           0 :                     $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   14438             :                                              makeIntConst($3, @3));
   14439             :                 }
   14440        1640 :             | JsonType                              { $$ = $1; }
   14441             :         ;
   14442             : 
   14443             : /* We have a separate ConstTypename to allow defaulting fixed-length
   14444             :  * types such as CHAR() and BIT() to an unspecified length.
   14445             :  * SQL9x requires that these default to a length of one, but this
   14446             :  * makes no sense for constructs like CHAR 'hi' and BIT '0101',
   14447             :  * where there is an obvious better choice to make.
   14448             :  * Note that ConstInterval is not included here since it must
   14449             :  * be pushed up higher in the rules to accommodate the postfix
   14450             :  * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
   14451             :  * the generic-type-name case in AexprConst to avoid premature
   14452             :  * reduce/reduce conflicts against function names.
   14453             :  */
   14454             : ConstTypename:
   14455          78 :             Numeric                                 { $$ = $1; }
   14456           0 :             | ConstBit                              { $$ = $1; }
   14457          34 :             | ConstCharacter                        { $$ = $1; }
   14458        2546 :             | ConstDatetime                         { $$ = $1; }
   14459         264 :             | JsonType                              { $$ = $1; }
   14460             :         ;
   14461             : 
   14462             : /*
   14463             :  * GenericType covers all type names that don't have special syntax mandated
   14464             :  * by the standard, including qualified names.  We also allow type modifiers.
   14465             :  * To avoid parsing conflicts against function invocations, the modifiers
   14466             :  * have to be shown as expr_list here, but parse analysis will only accept
   14467             :  * constants for them.
   14468             :  */
   14469             : GenericType:
   14470             :             type_function_name opt_type_modifiers
   14471             :                 {
   14472      244798 :                     $$ = makeTypeName($1);
   14473      244798 :                     $$->typmods = $2;
   14474      244798 :                     $$->location = @1;
   14475             :                 }
   14476             :             | type_function_name attrs opt_type_modifiers
   14477             :                 {
   14478       84898 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
   14479       84898 :                     $$->typmods = $3;
   14480       84898 :                     $$->location = @1;
   14481             :                 }
   14482             :         ;
   14483             : 
   14484        1342 : opt_type_modifiers: '(' expr_list ')'               { $$ = $2; }
   14485      334124 :                     | /* EMPTY */                   { $$ = NIL; }
   14486             :         ;
   14487             : 
   14488             : /*
   14489             :  * SQL numeric data types
   14490             :  */
   14491             : Numeric:    INT_P
   14492             :                 {
   14493       34650 :                     $$ = SystemTypeName("int4");
   14494       34650 :                     $$->location = @1;
   14495             :                 }
   14496             :             | INTEGER
   14497             :                 {
   14498       12898 :                     $$ = SystemTypeName("int4");
   14499       12898 :                     $$->location = @1;
   14500             :                 }
   14501             :             | SMALLINT
   14502             :                 {
   14503        1128 :                     $$ = SystemTypeName("int2");
   14504        1128 :                     $$->location = @1;
   14505             :                 }
   14506             :             | BIGINT
   14507             :                 {
   14508        4168 :                     $$ = SystemTypeName("int8");
   14509        4168 :                     $$->location = @1;
   14510             :                 }
   14511             :             | REAL
   14512             :                 {
   14513         368 :                     $$ = SystemTypeName("float4");
   14514         368 :                     $$->location = @1;
   14515             :                 }
   14516             :             | FLOAT_P opt_float
   14517             :                 {
   14518         488 :                     $$ = $2;
   14519         488 :                     $$->location = @1;
   14520             :                 }
   14521             :             | DOUBLE_P PRECISION
   14522             :                 {
   14523         488 :                     $$ = SystemTypeName("float8");
   14524         488 :                     $$->location = @1;
   14525             :                 }
   14526             :             | DECIMAL_P opt_type_modifiers
   14527             :                 {
   14528          36 :                     $$ = SystemTypeName("numeric");
   14529          36 :                     $$->typmods = $2;
   14530          36 :                     $$->location = @1;
   14531             :                 }
   14532             :             | DEC opt_type_modifiers
   14533             :                 {
   14534           0 :                     $$ = SystemTypeName("numeric");
   14535           0 :                     $$->typmods = $2;
   14536           0 :                     $$->location = @1;
   14537             :                 }
   14538             :             | NUMERIC opt_type_modifiers
   14539             :                 {
   14540        5734 :                     $$ = SystemTypeName("numeric");
   14541        5734 :                     $$->typmods = $2;
   14542        5734 :                     $$->location = @1;
   14543             :                 }
   14544             :             | BOOLEAN_P
   14545             :                 {
   14546        9686 :                     $$ = SystemTypeName("bool");
   14547        9686 :                     $$->location = @1;
   14548             :                 }
   14549             :         ;
   14550             : 
   14551             : opt_float:  '(' Iconst ')'
   14552             :                 {
   14553             :                     /*
   14554             :                      * Check FLOAT() precision limits assuming IEEE floating
   14555             :                      * types - thomas 1997-09-18
   14556             :                      */
   14557           2 :                     if ($2 < 1)
   14558           0 :                         ereport(ERROR,
   14559             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   14560             :                                  errmsg("precision for type float must be at least 1 bit"),
   14561             :                                  parser_errposition(@2)));
   14562           2 :                     else if ($2 <= 24)
   14563           2 :                         $$ = SystemTypeName("float4");
   14564           0 :                     else if ($2 <= 53)
   14565           0 :                         $$ = SystemTypeName("float8");
   14566             :                     else
   14567           0 :                         ereport(ERROR,
   14568             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   14569             :                                  errmsg("precision for type float must be less than 54 bits"),
   14570             :                                  parser_errposition(@2)));
   14571             :                 }
   14572             :             | /*EMPTY*/
   14573             :                 {
   14574         486 :                     $$ = SystemTypeName("float8");
   14575             :                 }
   14576             :         ;
   14577             : 
   14578             : /*
   14579             :  * SQL bit-field data types
   14580             :  * The following implements BIT() and BIT VARYING().
   14581             :  */
   14582             : Bit:        BitWithLength
   14583             :                 {
   14584        1666 :                     $$ = $1;
   14585             :                 }
   14586             :             | BitWithoutLength
   14587             :                 {
   14588         188 :                     $$ = $1;
   14589             :                 }
   14590             :         ;
   14591             : 
   14592             : /* ConstBit is like Bit except "BIT" defaults to unspecified length */
   14593             : /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
   14594             : ConstBit:   BitWithLength
   14595             :                 {
   14596           0 :                     $$ = $1;
   14597             :                 }
   14598             :             | BitWithoutLength
   14599             :                 {
   14600           0 :                     $$ = $1;
   14601           0 :                     $$->typmods = NIL;
   14602             :                 }
   14603             :         ;
   14604             : 
   14605             : BitWithLength:
   14606             :             BIT opt_varying '(' expr_list ')'
   14607             :                 {
   14608             :                     char *typname;
   14609             : 
   14610        1666 :                     typname = $2 ? "varbit" : "bit";
   14611        1666 :                     $$ = SystemTypeName(typname);
   14612        1666 :                     $$->typmods = $4;
   14613        1666 :                     $$->location = @1;
   14614             :                 }
   14615             :         ;
   14616             : 
   14617             : BitWithoutLength:
   14618             :             BIT opt_varying
   14619             :                 {
   14620             :                     /* bit defaults to bit(1), varbit to no limit */
   14621         188 :                     if ($2)
   14622             :                     {
   14623          20 :                         $$ = SystemTypeName("varbit");
   14624             :                     }
   14625             :                     else
   14626             :                     {
   14627         168 :                         $$ = SystemTypeName("bit");
   14628         168 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   14629             :                     }
   14630         188 :                     $$->location = @1;
   14631             :                 }
   14632             :         ;
   14633             : 
   14634             : 
   14635             : /*
   14636             :  * SQL character data types
   14637             :  * The following implements CHAR() and VARCHAR().
   14638             :  */
   14639             : Character:  CharacterWithLength
   14640             :                 {
   14641        1890 :                     $$ = $1;
   14642             :                 }
   14643             :             | CharacterWithoutLength
   14644             :                 {
   14645        1196 :                     $$ = $1;
   14646             :                 }
   14647             :         ;
   14648             : 
   14649             : ConstCharacter:  CharacterWithLength
   14650             :                 {
   14651          12 :                     $$ = $1;
   14652             :                 }
   14653             :             | CharacterWithoutLength
   14654             :                 {
   14655             :                     /* Length was not specified so allow to be unrestricted.
   14656             :                      * This handles problems with fixed-length (bpchar) strings
   14657             :                      * which in column definitions must default to a length
   14658             :                      * of one, but should not be constrained if the length
   14659             :                      * was not specified.
   14660             :                      */
   14661          22 :                     $$ = $1;
   14662          22 :                     $$->typmods = NIL;
   14663             :                 }
   14664             :         ;
   14665             : 
   14666             : CharacterWithLength:  character '(' Iconst ')'
   14667             :                 {
   14668        1902 :                     $$ = SystemTypeName($1);
   14669        1902 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14670        1902 :                     $$->location = @1;
   14671             :                 }
   14672             :         ;
   14673             : 
   14674             : CharacterWithoutLength:  character
   14675             :                 {
   14676        1218 :                     $$ = SystemTypeName($1);
   14677             :                     /* char defaults to char(1), varchar to no limit */
   14678        1218 :                     if (strcmp($1, "bpchar") == 0)
   14679         252 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   14680        1218 :                     $$->location = @1;
   14681             :                 }
   14682             :         ;
   14683             : 
   14684             : character:  CHARACTER opt_varying
   14685         500 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14686             :             | CHAR_P opt_varying
   14687        1110 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14688             :             | VARCHAR
   14689        1506 :                                         { $$ = "varchar"; }
   14690             :             | NATIONAL CHARACTER opt_varying
   14691           0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   14692             :             | NATIONAL CHAR_P opt_varying
   14693           0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   14694             :             | NCHAR opt_varying
   14695           4 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14696             :         ;
   14697             : 
   14698             : opt_varying:
   14699         398 :             VARYING                                 { $$ = true; }
   14700        3070 :             | /*EMPTY*/                             { $$ = false; }
   14701             :         ;
   14702             : 
   14703             : /*
   14704             :  * SQL date/time types
   14705             :  */
   14706             : ConstDatetime:
   14707             :             TIMESTAMP '(' Iconst ')' opt_timezone
   14708             :                 {
   14709         114 :                     if ($5)
   14710          90 :                         $$ = SystemTypeName("timestamptz");
   14711             :                     else
   14712          24 :                         $$ = SystemTypeName("timestamp");
   14713         114 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14714         114 :                     $$->location = @1;
   14715             :                 }
   14716             :             | TIMESTAMP opt_timezone
   14717             :                 {
   14718        4622 :                     if ($2)
   14719        1310 :                         $$ = SystemTypeName("timestamptz");
   14720             :                     else
   14721        3312 :                         $$ = SystemTypeName("timestamp");
   14722        4622 :                     $$->location = @1;
   14723             :                 }
   14724             :             | TIME '(' Iconst ')' opt_timezone
   14725             :                 {
   14726          22 :                     if ($5)
   14727           8 :                         $$ = SystemTypeName("timetz");
   14728             :                     else
   14729          14 :                         $$ = SystemTypeName("time");
   14730          22 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14731          22 :                     $$->location = @1;
   14732             :                 }
   14733             :             | TIME opt_timezone
   14734             :                 {
   14735        2076 :                     if ($2)
   14736         266 :                         $$ = SystemTypeName("timetz");
   14737             :                     else
   14738        1810 :                         $$ = SystemTypeName("time");
   14739        2076 :                     $$->location = @1;
   14740             :                 }
   14741             :         ;
   14742             : 
   14743             : ConstInterval:
   14744             :             INTERVAL
   14745             :                 {
   14746        6564 :                     $$ = SystemTypeName("interval");
   14747        6564 :                     $$->location = @1;
   14748             :                 }
   14749             :         ;
   14750             : 
   14751             : opt_timezone:
   14752        1674 :             WITH_LA TIME ZONE                       { $$ = true; }
   14753         514 :             | WITHOUT_LA TIME ZONE                  { $$ = false; }
   14754        4646 :             | /*EMPTY*/                             { $$ = false; }
   14755             :         ;
   14756             : 
   14757             : opt_interval:
   14758             :             YEAR_P
   14759          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
   14760             :             | MONTH_P
   14761          18 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
   14762             :             | DAY_P
   14763          18 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
   14764             :             | HOUR_P
   14765          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
   14766             :             | MINUTE_P
   14767          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
   14768             :             | interval_second
   14769          36 :                 { $$ = $1; }
   14770             :             | YEAR_P TO MONTH_P
   14771             :                 {
   14772          18 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
   14773             :                                                  INTERVAL_MASK(MONTH), @1));
   14774             :                 }
   14775             :             | DAY_P TO HOUR_P
   14776             :                 {
   14777          24 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   14778             :                                                  INTERVAL_MASK(HOUR), @1));
   14779             :                 }
   14780             :             | DAY_P TO MINUTE_P
   14781             :                 {
   14782          24 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   14783             :                                                  INTERVAL_MASK(HOUR) |
   14784             :                                                  INTERVAL_MASK(MINUTE), @1));
   14785             :                 }
   14786             :             | DAY_P TO interval_second
   14787             :                 {
   14788          48 :                     $$ = $3;
   14789          48 :                     linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
   14790             :                                                 INTERVAL_MASK(HOUR) |
   14791             :                                                 INTERVAL_MASK(MINUTE) |
   14792          48 :                                                 INTERVAL_MASK(SECOND), @1);
   14793             :                 }
   14794             :             | HOUR_P TO MINUTE_P
   14795             :                 {
   14796          18 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
   14797             :                                                  INTERVAL_MASK(MINUTE), @1));
   14798             :                 }
   14799             :             | HOUR_P TO interval_second
   14800             :                 {
   14801          36 :                     $$ = $3;
   14802          36 :                     linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
   14803             :                                                 INTERVAL_MASK(MINUTE) |
   14804          36 :                                                 INTERVAL_MASK(SECOND), @1);
   14805             :                 }
   14806             :             | MINUTE_P TO interval_second
   14807             :                 {
   14808          66 :                     $$ = $3;
   14809          66 :                     linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
   14810          66 :                                                 INTERVAL_MASK(SECOND), @1);
   14811             :                 }
   14812             :             | /*EMPTY*/
   14813        6210 :                 { $$ = NIL; }
   14814             :         ;
   14815             : 
   14816             : interval_second:
   14817             :             SECOND_P
   14818             :                 {
   14819         102 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
   14820             :                 }
   14821             :             | SECOND_P '(' Iconst ')'
   14822             :                 {
   14823          84 :                     $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
   14824             :                                     makeIntConst($3, @3));
   14825             :                 }
   14826             :         ;
   14827             : 
   14828             : JsonType:
   14829             :             JSON
   14830             :                 {
   14831        1904 :                     $$ = SystemTypeName("json");
   14832        1904 :                     $$->location = @1;
   14833             :                 }
   14834             :         ;
   14835             : 
   14836             : /*****************************************************************************
   14837             :  *
   14838             :  *  expression grammar
   14839             :  *
   14840             :  *****************************************************************************/
   14841             : 
   14842             : /*
   14843             :  * General expressions
   14844             :  * This is the heart of the expression syntax.
   14845             :  *
   14846             :  * We have two expression types: a_expr is the unrestricted kind, and
   14847             :  * b_expr is a subset that must be used in some places to avoid shift/reduce
   14848             :  * conflicts.  For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
   14849             :  * because that use of AND conflicts with AND as a boolean operator.  So,
   14850             :  * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
   14851             :  *
   14852             :  * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
   14853             :  * always be used by surrounding it with parens.
   14854             :  *
   14855             :  * c_expr is all the productions that are common to a_expr and b_expr;
   14856             :  * it's factored out just to eliminate redundant coding.
   14857             :  *
   14858             :  * Be careful of productions involving more than one terminal token.
   14859             :  * By default, bison will assign such productions the precedence of their
   14860             :  * last terminal, but in nearly all cases you want it to be the precedence
   14861             :  * of the first terminal instead; otherwise you will not get the behavior
   14862             :  * you expect!  So we use %prec annotations freely to set precedences.
   14863             :  */
   14864     3302210 : a_expr:     c_expr                                  { $$ = $1; }
   14865             :             | a_expr TYPECAST Typename
   14866      174886 :                     { $$ = makeTypeCast($1, $3, @2); }
   14867             :             | a_expr COLLATE any_name
   14868             :                 {
   14869        7772 :                     CollateClause *n = makeNode(CollateClause);
   14870             : 
   14871        7772 :                     n->arg = $1;
   14872        7772 :                     n->collname = $3;
   14873        7772 :                     n->location = @2;
   14874        7772 :                     $$ = (Node *) n;
   14875             :                 }
   14876             :             | a_expr AT TIME ZONE a_expr            %prec AT
   14877             :                 {
   14878         396 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   14879         396 :                                                list_make2($5, $1),
   14880             :                                                COERCE_SQL_SYNTAX,
   14881         396 :                                                @2);
   14882             :                 }
   14883             :             | a_expr AT LOCAL                       %prec AT
   14884             :                 {
   14885          42 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   14886          42 :                                                list_make1($1),
   14887             :                                                COERCE_SQL_SYNTAX,
   14888             :                                                -1);
   14889             :                 }
   14890             :         /*
   14891             :          * These operators must be called out explicitly in order to make use
   14892             :          * of bison's automatic operator-precedence handling.  All other
   14893             :          * operator names are handled by the generic productions using "Op",
   14894             :          * below; and all those operators will have the same precedence.
   14895             :          *
   14896             :          * If you add more explicitly-known operators, be sure to add them
   14897             :          * also to b_expr and to the MathOp list below.
   14898             :          */
   14899             :             | '+' a_expr                    %prec UMINUS
   14900          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   14901             :             | '-' a_expr                    %prec UMINUS
   14902       27160 :                 { $$ = doNegate($2, @1); }
   14903             :             | a_expr '+' a_expr
   14904       12854 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   14905             :             | a_expr '-' a_expr
   14906        4102 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   14907             :             | a_expr '*' a_expr
   14908        8414 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   14909             :             | a_expr '/' a_expr
   14910        3714 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   14911             :             | a_expr '%' a_expr
   14912        2596 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   14913             :             | a_expr '^' a_expr
   14914         456 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   14915             :             | a_expr '<' a_expr
   14916       22908 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   14917             :             | a_expr '>' a_expr
   14918       32346 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   14919             :             | a_expr '=' a_expr
   14920      337516 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   14921             :             | a_expr LESS_EQUALS a_expr
   14922        4752 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   14923             :             | a_expr GREATER_EQUALS a_expr
   14924        4860 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   14925             :             | a_expr NOT_EQUALS a_expr
   14926       36648 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   14927             : 
   14928             :             | a_expr qual_Op a_expr             %prec Op
   14929       54258 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   14930             :             | qual_Op a_expr                    %prec Op
   14931         192 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   14932             : 
   14933             :             | a_expr AND a_expr
   14934      198764 :                 { $$ = makeAndExpr($1, $3, @2); }
   14935             :             | a_expr OR a_expr
   14936       14654 :                 { $$ = makeOrExpr($1, $3, @2); }
   14937             :             | NOT a_expr
   14938       13728 :                 { $$ = makeNotExpr($2, @1); }
   14939             :             | NOT_LA a_expr                     %prec NOT
   14940           0 :                 { $$ = makeNotExpr($2, @1); }
   14941             : 
   14942             :             | a_expr LIKE a_expr
   14943             :                 {
   14944        1792 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   14945        1792 :                                                    $1, $3, @2);
   14946             :                 }
   14947             :             | a_expr LIKE a_expr ESCAPE a_expr                  %prec LIKE
   14948             :                 {
   14949          96 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   14950          96 :                                                  list_make2($3, $5),
   14951             :                                                  COERCE_EXPLICIT_CALL,
   14952          96 :                                                  @2);
   14953          96 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   14954          96 :                                                    $1, (Node *) n, @2);
   14955             :                 }
   14956             :             | a_expr NOT_LA LIKE a_expr                         %prec NOT_LA
   14957             :                 {
   14958         198 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   14959         198 :                                                    $1, $4, @2);
   14960             :                 }
   14961             :             | a_expr NOT_LA LIKE a_expr ESCAPE a_expr           %prec NOT_LA
   14962             :                 {
   14963          96 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   14964          96 :                                                  list_make2($4, $6),
   14965             :                                                  COERCE_EXPLICIT_CALL,
   14966          96 :                                                  @2);
   14967          96 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   14968          96 :                                                    $1, (Node *) n, @2);
   14969             :                 }
   14970             :             | a_expr ILIKE a_expr
   14971             :                 {
   14972         174 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   14973         174 :                                                    $1, $3, @2);
   14974             :                 }
   14975             :             | a_expr ILIKE a_expr ESCAPE a_expr                 %prec ILIKE
   14976             :                 {
   14977           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   14978           0 :                                                  list_make2($3, $5),
   14979             :                                                  COERCE_EXPLICIT_CALL,
   14980           0 :                                                  @2);
   14981           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   14982           0 :                                                    $1, (Node *) n, @2);
   14983             :                 }
   14984             :             | a_expr NOT_LA ILIKE a_expr                        %prec NOT_LA
   14985             :                 {
   14986          30 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   14987          30 :                                                    $1, $4, @2);
   14988             :                 }
   14989             :             | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr          %prec NOT_LA
   14990             :                 {
   14991           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   14992           0 :                                                  list_make2($4, $6),
   14993             :                                                  COERCE_EXPLICIT_CALL,
   14994           0 :                                                  @2);
   14995           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   14996           0 :                                                    $1, (Node *) n, @2);
   14997             :                 }
   14998             : 
   14999             :             | a_expr SIMILAR TO a_expr                          %prec SIMILAR
   15000             :                 {
   15001          40 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15002          40 :                                                  list_make1($4),
   15003             :                                                  COERCE_EXPLICIT_CALL,
   15004          40 :                                                  @2);
   15005          40 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   15006          40 :                                                    $1, (Node *) n, @2);
   15007             :                 }
   15008             :             | a_expr SIMILAR TO a_expr ESCAPE a_expr            %prec SIMILAR
   15009             :                 {
   15010          30 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15011          30 :                                                  list_make2($4, $6),
   15012             :                                                  COERCE_EXPLICIT_CALL,
   15013          30 :                                                  @2);
   15014          30 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   15015          30 :                                                    $1, (Node *) n, @2);
   15016             :                 }
   15017             :             | a_expr NOT_LA SIMILAR TO a_expr                   %prec NOT_LA
   15018             :                 {
   15019           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15020           0 :                                                  list_make1($5),
   15021             :                                                  COERCE_EXPLICIT_CALL,
   15022           0 :                                                  @2);
   15023           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   15024           0 :                                                    $1, (Node *) n, @2);
   15025             :                 }
   15026             :             | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr     %prec NOT_LA
   15027             :                 {
   15028           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15029           0 :                                                  list_make2($5, $7),
   15030             :                                                  COERCE_EXPLICIT_CALL,
   15031           0 :                                                  @2);
   15032           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   15033           0 :                                                    $1, (Node *) n, @2);
   15034             :                 }
   15035             : 
   15036             :             /* NullTest clause
   15037             :              * Define SQL-style Null test clause.
   15038             :              * Allow two forms described in the standard:
   15039             :              *  a IS NULL
   15040             :              *  a IS NOT NULL
   15041             :              * Allow two SQL extensions
   15042             :              *  a ISNULL
   15043             :              *  a NOTNULL
   15044             :              */
   15045             :             | a_expr IS NULL_P                          %prec IS
   15046             :                 {
   15047        5116 :                     NullTest   *n = makeNode(NullTest);
   15048             : 
   15049        5116 :                     n->arg = (Expr *) $1;
   15050        5116 :                     n->nulltesttype = IS_NULL;
   15051        5116 :                     n->location = @2;
   15052        5116 :                     $$ = (Node *) n;
   15053             :                 }
   15054             :             | a_expr ISNULL
   15055             :                 {
   15056          96 :                     NullTest   *n = makeNode(NullTest);
   15057             : 
   15058          96 :                     n->arg = (Expr *) $1;
   15059          96 :                     n->nulltesttype = IS_NULL;
   15060          96 :                     n->location = @2;
   15061          96 :                     $$ = (Node *) n;
   15062             :                 }
   15063             :             | a_expr IS NOT NULL_P                      %prec IS
   15064             :                 {
   15065       11634 :                     NullTest   *n = makeNode(NullTest);
   15066             : 
   15067       11634 :                     n->arg = (Expr *) $1;
   15068       11634 :                     n->nulltesttype = IS_NOT_NULL;
   15069       11634 :                     n->location = @2;
   15070       11634 :                     $$ = (Node *) n;
   15071             :                 }
   15072             :             | a_expr NOTNULL
   15073             :                 {
   15074           6 :                     NullTest   *n = makeNode(NullTest);
   15075             : 
   15076           6 :                     n->arg = (Expr *) $1;
   15077           6 :                     n->nulltesttype = IS_NOT_NULL;
   15078           6 :                     n->location = @2;
   15079           6 :                     $$ = (Node *) n;
   15080             :                 }
   15081             :             | row OVERLAPS row
   15082             :                 {
   15083         786 :                     if (list_length($1) != 2)
   15084           0 :                         ereport(ERROR,
   15085             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   15086             :                                  errmsg("wrong number of parameters on left side of OVERLAPS expression"),
   15087             :                                  parser_errposition(@1)));
   15088         786 :                     if (list_length($3) != 2)
   15089           0 :                         ereport(ERROR,
   15090             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   15091             :                                  errmsg("wrong number of parameters on right side of OVERLAPS expression"),
   15092             :                                  parser_errposition(@3)));
   15093         786 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
   15094         786 :                                                list_concat($1, $3),
   15095             :                                                COERCE_SQL_SYNTAX,
   15096         786 :                                                @2);
   15097             :                 }
   15098             :             | a_expr IS TRUE_P                          %prec IS
   15099             :                 {
   15100         368 :                     BooleanTest *b = makeNode(BooleanTest);
   15101             : 
   15102         368 :                     b->arg = (Expr *) $1;
   15103         368 :                     b->booltesttype = IS_TRUE;
   15104         368 :                     b->location = @2;
   15105         368 :                     $$ = (Node *) b;
   15106             :                 }
   15107             :             | a_expr IS NOT TRUE_P                      %prec IS
   15108             :                 {
   15109         138 :                     BooleanTest *b = makeNode(BooleanTest);
   15110             : 
   15111         138 :                     b->arg = (Expr *) $1;
   15112         138 :                     b->booltesttype = IS_NOT_TRUE;
   15113         138 :                     b->location = @2;
   15114         138 :                     $$ = (Node *) b;
   15115             :                 }
   15116             :             | a_expr IS FALSE_P                         %prec IS
   15117             :                 {
   15118         114 :                     BooleanTest *b = makeNode(BooleanTest);
   15119             : 
   15120         114 :                     b->arg = (Expr *) $1;
   15121         114 :                     b->booltesttype = IS_FALSE;
   15122         114 :                     b->location = @2;
   15123         114 :                     $$ = (Node *) b;
   15124             :                 }
   15125             :             | a_expr IS NOT FALSE_P                     %prec IS
   15126             :                 {
   15127          90 :                     BooleanTest *b = makeNode(BooleanTest);
   15128             : 
   15129          90 :                     b->arg = (Expr *) $1;
   15130          90 :                     b->booltesttype = IS_NOT_FALSE;
   15131          90 :                     b->location = @2;
   15132          90 :                     $$ = (Node *) b;
   15133             :                 }
   15134             :             | a_expr IS UNKNOWN                         %prec IS
   15135             :                 {
   15136          52 :                     BooleanTest *b = makeNode(BooleanTest);
   15137             : 
   15138          52 :                     b->arg = (Expr *) $1;
   15139          52 :                     b->booltesttype = IS_UNKNOWN;
   15140          52 :                     b->location = @2;
   15141          52 :                     $$ = (Node *) b;
   15142             :                 }
   15143             :             | a_expr IS NOT UNKNOWN                     %prec IS
   15144             :                 {
   15145          48 :                     BooleanTest *b = makeNode(BooleanTest);
   15146             : 
   15147          48 :                     b->arg = (Expr *) $1;
   15148          48 :                     b->booltesttype = IS_NOT_UNKNOWN;
   15149          48 :                     b->location = @2;
   15150          48 :                     $$ = (Node *) b;
   15151             :                 }
   15152             :             | a_expr IS DISTINCT FROM a_expr            %prec IS
   15153             :                 {
   15154         870 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   15155             :                 }
   15156             :             | a_expr IS NOT DISTINCT FROM a_expr        %prec IS
   15157             :                 {
   15158          62 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   15159             :                 }
   15160             :             | a_expr BETWEEN opt_asymmetric b_expr AND a_expr       %prec BETWEEN
   15161             :                 {
   15162         466 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN,
   15163             :                                                    "BETWEEN",
   15164         466 :                                                    $1,
   15165         466 :                                                    (Node *) list_make2($4, $6),
   15166         466 :                                                    @2);
   15167             :                 }
   15168             :             | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
   15169             :                 {
   15170          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN,
   15171             :                                                    "NOT BETWEEN",
   15172          12 :                                                    $1,
   15173          12 :                                                    (Node *) list_make2($5, $7),
   15174          12 :                                                    @2);
   15175             :                 }
   15176             :             | a_expr BETWEEN SYMMETRIC b_expr AND a_expr            %prec BETWEEN
   15177             :                 {
   15178          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN_SYM,
   15179             :                                                    "BETWEEN SYMMETRIC",
   15180          12 :                                                    $1,
   15181          12 :                                                    (Node *) list_make2($4, $6),
   15182          12 :                                                    @2);
   15183             :                 }
   15184             :             | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr     %prec NOT_LA
   15185             :                 {
   15186          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN_SYM,
   15187             :                                                    "NOT BETWEEN SYMMETRIC",
   15188          12 :                                                    $1,
   15189          12 :                                                    (Node *) list_make2($5, $7),
   15190          12 :                                                    @2);
   15191             :                 }
   15192             :             | a_expr IN_P in_expr
   15193             :                 {
   15194             :                     /* in_expr returns a SubLink or a list of a_exprs */
   15195       16922 :                     if (IsA($3, SubLink))
   15196             :                     {
   15197             :                         /* generate foo = ANY (subquery) */
   15198        2294 :                         SubLink    *n = (SubLink *) $3;
   15199             : 
   15200        2294 :                         n->subLinkType = ANY_SUBLINK;
   15201        2294 :                         n->subLinkId = 0;
   15202        2294 :                         n->testexpr = $1;
   15203        2294 :                         n->operName = NIL;       /* show it's IN not = ANY */
   15204        2294 :                         n->location = @2;
   15205        2294 :                         $$ = (Node *) n;
   15206             :                     }
   15207             :                     else
   15208             :                     {
   15209             :                         /* generate scalar IN expression */
   15210       14628 :                         $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
   15211             :                     }
   15212             :                 }
   15213             :             | a_expr NOT_LA IN_P in_expr                        %prec NOT_LA
   15214             :                 {
   15215             :                     /* in_expr returns a SubLink or a list of a_exprs */
   15216        2182 :                     if (IsA($4, SubLink))
   15217             :                     {
   15218             :                         /* generate NOT (foo = ANY (subquery)) */
   15219             :                         /* Make an = ANY node */
   15220         120 :                         SubLink    *n = (SubLink *) $4;
   15221             : 
   15222         120 :                         n->subLinkType = ANY_SUBLINK;
   15223         120 :                         n->subLinkId = 0;
   15224         120 :                         n->testexpr = $1;
   15225         120 :                         n->operName = NIL;       /* show it's IN not = ANY */
   15226         120 :                         n->location = @2;
   15227             :                         /* Stick a NOT on top; must have same parse location */
   15228         120 :                         $$ = makeNotExpr((Node *) n, @2);
   15229             :                     }
   15230             :                     else
   15231             :                     {
   15232             :                         /* generate scalar NOT IN expression */
   15233        2062 :                         $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
   15234             :                     }
   15235             :                 }
   15236             :             | a_expr subquery_Op sub_type select_with_parens    %prec Op
   15237             :                 {
   15238         166 :                     SubLink    *n = makeNode(SubLink);
   15239             : 
   15240         166 :                     n->subLinkType = $3;
   15241         166 :                     n->subLinkId = 0;
   15242         166 :                     n->testexpr = $1;
   15243         166 :                     n->operName = $2;
   15244         166 :                     n->subselect = $4;
   15245         166 :                     n->location = @2;
   15246         166 :                     $$ = (Node *) n;
   15247             :                 }
   15248             :             | a_expr subquery_Op sub_type '(' a_expr ')'        %prec Op
   15249             :                 {
   15250       14814 :                     if ($3 == ANY_SUBLINK)
   15251       14514 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
   15252             :                     else
   15253         300 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
   15254             :                 }
   15255             :             | UNIQUE opt_unique_null_treatment select_with_parens
   15256             :                 {
   15257             :                     /* Not sure how to get rid of the parentheses
   15258             :                      * but there are lots of shift/reduce errors without them.
   15259             :                      *
   15260             :                      * Should be able to implement this by plopping the entire
   15261             :                      * select into a node, then transforming the target expressions
   15262             :                      * from whatever they are into count(*), and testing the
   15263             :                      * entire result equal to one.
   15264             :                      * But, will probably implement a separate node in the executor.
   15265             :                      */
   15266           0 :                     ereport(ERROR,
   15267             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   15268             :                              errmsg("UNIQUE predicate is not yet implemented"),
   15269             :                              parser_errposition(@1)));
   15270             :                 }
   15271             :             | a_expr IS DOCUMENT_P                  %prec IS
   15272             :                 {
   15273          18 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15274          18 :                                      list_make1($1), @2);
   15275             :                 }
   15276             :             | a_expr IS NOT DOCUMENT_P              %prec IS
   15277             :                 {
   15278          18 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15279          18 :                                                  list_make1($1), @2),
   15280          18 :                                      @2);
   15281             :                 }
   15282             :             | a_expr IS NORMALIZED                              %prec IS
   15283             :                 {
   15284          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15285          12 :                                                list_make1($1),
   15286             :                                                COERCE_SQL_SYNTAX,
   15287          12 :                                                @2);
   15288             :                 }
   15289             :             | a_expr IS unicode_normal_form NORMALIZED          %prec IS
   15290             :                 {
   15291          36 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15292          36 :                                                list_make2($1, makeStringConst($3, @3)),
   15293             :                                                COERCE_SQL_SYNTAX,
   15294          36 :                                                @2);
   15295             :                 }
   15296             :             | a_expr IS NOT NORMALIZED                          %prec IS
   15297             :                 {
   15298           0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15299           0 :                                                            list_make1($1),
   15300             :                                                            COERCE_SQL_SYNTAX,
   15301           0 :                                                            @2),
   15302           0 :                                      @2);
   15303             :                 }
   15304             :             | a_expr IS NOT unicode_normal_form NORMALIZED      %prec IS
   15305             :                 {
   15306           0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15307           0 :                                                            list_make2($1, makeStringConst($4, @4)),
   15308             :                                                            COERCE_SQL_SYNTAX,
   15309           0 :                                                            @2),
   15310           0 :                                      @2);
   15311             :                 }
   15312             :             | a_expr IS json_predicate_type_constraint
   15313             :                     json_key_uniqueness_constraint_opt      %prec IS
   15314             :                 {
   15315         304 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   15316             : 
   15317         304 :                     $$ = makeJsonIsPredicate($1, format, $3, $4, @1);
   15318             :                 }
   15319             :             /*
   15320             :              * Required by SQL/JSON, but there are conflicts
   15321             :             | a_expr
   15322             :                 json_format_clause
   15323             :                 IS  json_predicate_type_constraint
   15324             :                     json_key_uniqueness_constraint_opt      %prec IS
   15325             :                 {
   15326             :                     $$ = makeJsonIsPredicate($1, $2, $4, $5, @1);
   15327             :                 }
   15328             :             */
   15329             :             | a_expr IS NOT
   15330             :                     json_predicate_type_constraint
   15331             :                     json_key_uniqueness_constraint_opt      %prec IS
   15332             :                 {
   15333          46 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   15334             : 
   15335          46 :                     $$ = makeNotExpr(makeJsonIsPredicate($1, format, $4, $5, @1), @1);
   15336             :                 }
   15337             :             /*
   15338             :              * Required by SQL/JSON, but there are conflicts
   15339             :             | a_expr
   15340             :                 json_format_clause
   15341             :                 IS NOT
   15342             :                     json_predicate_type_constraint
   15343             :                     json_key_uniqueness_constraint_opt      %prec IS
   15344             :                 {
   15345             :                     $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, @1), @1);
   15346             :                 }
   15347             :             */
   15348             :             | DEFAULT
   15349             :                 {
   15350             :                     /*
   15351             :                      * The SQL spec only allows DEFAULT in "contextually typed
   15352             :                      * expressions", but for us, it's easier to allow it in
   15353             :                      * any a_expr and then throw error during parse analysis
   15354             :                      * if it's in an inappropriate context.  This way also
   15355             :                      * lets us say something smarter than "syntax error".
   15356             :                      */
   15357        1402 :                     SetToDefault *n = makeNode(SetToDefault);
   15358             : 
   15359             :                     /* parse analysis will fill in the rest */
   15360        1402 :                     n->location = @1;
   15361        1402 :                     $$ = (Node *) n;
   15362             :                 }
   15363             :         ;
   15364             : 
   15365             : /*
   15366             :  * Restricted expressions
   15367             :  *
   15368             :  * b_expr is a subset of the complete expression syntax defined by a_expr.
   15369             :  *
   15370             :  * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
   15371             :  * cause trouble in the places where b_expr is used.  For simplicity, we
   15372             :  * just eliminate all the boolean-keyword-operator productions from b_expr.
   15373             :  */
   15374             : b_expr:     c_expr
   15375        3474 :                 { $$ = $1; }
   15376             :             | b_expr TYPECAST Typename
   15377         134 :                 { $$ = makeTypeCast($1, $3, @2); }
   15378             :             | '+' b_expr                    %prec UMINUS
   15379           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   15380             :             | '-' b_expr                    %prec UMINUS
   15381          66 :                 { $$ = doNegate($2, @1); }
   15382             :             | b_expr '+' b_expr
   15383          30 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   15384             :             | b_expr '-' b_expr
   15385          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   15386             :             | b_expr '*' b_expr
   15387          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   15388             :             | b_expr '/' b_expr
   15389           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   15390             :             | b_expr '%' b_expr
   15391           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   15392             :             | b_expr '^' b_expr
   15393           6 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   15394             :             | b_expr '<' b_expr
   15395           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   15396             :             | b_expr '>' b_expr
   15397           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   15398             :             | b_expr '=' b_expr
   15399           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   15400             :             | b_expr LESS_EQUALS b_expr
   15401           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   15402             :             | b_expr GREATER_EQUALS b_expr
   15403           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   15404             :             | b_expr NOT_EQUALS b_expr
   15405           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   15406             :             | b_expr qual_Op b_expr             %prec Op
   15407          12 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   15408             :             | qual_Op b_expr                    %prec Op
   15409           0 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   15410             :             | b_expr IS DISTINCT FROM b_expr        %prec IS
   15411             :                 {
   15412           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   15413             :                 }
   15414             :             | b_expr IS NOT DISTINCT FROM b_expr    %prec IS
   15415             :                 {
   15416           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   15417             :                 }
   15418             :             | b_expr IS DOCUMENT_P                  %prec IS
   15419             :                 {
   15420           0 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15421           0 :                                      list_make1($1), @2);
   15422             :                 }
   15423             :             | b_expr IS NOT DOCUMENT_P              %prec IS
   15424             :                 {
   15425           0 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15426           0 :                                                  list_make1($1), @2),
   15427           0 :                                      @2);
   15428             :                 }
   15429             :         ;
   15430             : 
   15431             : /*
   15432             :  * Productions that can be used in both a_expr and b_expr.
   15433             :  *
   15434             :  * Note: productions that refer recursively to a_expr or b_expr mostly
   15435             :  * cannot appear here.  However, it's OK to refer to a_exprs that occur
   15436             :  * inside parentheses, such as function arguments; that cannot introduce
   15437             :  * ambiguity to the b_expr syntax.
   15438             :  */
   15439     1510922 : c_expr:     columnref                               { $$ = $1; }
   15440     1101640 :             | AexprConst                            { $$ = $1; }
   15441             :             | PARAM opt_indirection
   15442             :                 {
   15443      142514 :                     ParamRef   *p = makeNode(ParamRef);
   15444             : 
   15445      142514 :                     p->number = $1;
   15446      142514 :                     p->location = @1;
   15447      142514 :                     if ($2)
   15448             :                     {
   15449        1138 :                         A_Indirection *n = makeNode(A_Indirection);
   15450             : 
   15451        1138 :                         n->arg = (Node *) p;
   15452        1138 :                         n->indirection = check_indirection($2, yyscanner);
   15453        1138 :                         $$ = (Node *) n;
   15454             :                     }
   15455             :                     else
   15456      141376 :                         $$ = (Node *) p;
   15457             :                 }
   15458             :             | '(' a_expr ')' opt_indirection
   15459             :                 {
   15460       85980 :                     if ($4)
   15461             :                     {
   15462        9962 :                         A_Indirection *n = makeNode(A_Indirection);
   15463             : 
   15464        9962 :                         n->arg = $2;
   15465        9962 :                         n->indirection = check_indirection($4, yyscanner);
   15466        9962 :                         $$ = (Node *) n;
   15467             :                     }
   15468             :                     else
   15469       76018 :                         $$ = $2;
   15470             :                 }
   15471             :             | case_expr
   15472       53830 :                 { $$ = $1; }
   15473             :             | func_expr
   15474      362940 :                 { $$ = $1; }
   15475             :             | select_with_parens            %prec UMINUS
   15476             :                 {
   15477       22366 :                     SubLink    *n = makeNode(SubLink);
   15478             : 
   15479       22366 :                     n->subLinkType = EXPR_SUBLINK;
   15480       22366 :                     n->subLinkId = 0;
   15481       22366 :                     n->testexpr = NULL;
   15482       22366 :                     n->operName = NIL;
   15483       22366 :                     n->subselect = $1;
   15484       22366 :                     n->location = @1;
   15485       22366 :                     $$ = (Node *) n;
   15486             :                 }
   15487             :             | select_with_parens indirection
   15488             :                 {
   15489             :                     /*
   15490             :                      * Because the select_with_parens nonterminal is designed
   15491             :                      * to "eat" as many levels of parens as possible, the
   15492             :                      * '(' a_expr ')' opt_indirection production above will
   15493             :                      * fail to match a sub-SELECT with indirection decoration;
   15494             :                      * the sub-SELECT won't be regarded as an a_expr as long
   15495             :                      * as there are parens around it.  To support applying
   15496             :                      * subscripting or field selection to a sub-SELECT result,
   15497             :                      * we need this redundant-looking production.
   15498             :                      */
   15499          18 :                     SubLink    *n = makeNode(SubLink);
   15500          18 :                     A_Indirection *a = makeNode(A_Indirection);
   15501             : 
   15502          18 :                     n->subLinkType = EXPR_SUBLINK;
   15503          18 :                     n->subLinkId = 0;
   15504          18 :                     n->testexpr = NULL;
   15505          18 :                     n->operName = NIL;
   15506          18 :                     n->subselect = $1;
   15507          18 :                     n->location = @1;
   15508          18 :                     a->arg = (Node *) n;
   15509          18 :                     a->indirection = check_indirection($2, yyscanner);
   15510          18 :                     $$ = (Node *) a;
   15511             :                 }
   15512             :             | EXISTS select_with_parens
   15513             :                 {
   15514        5096 :                     SubLink    *n = makeNode(SubLink);
   15515             : 
   15516        5096 :                     n->subLinkType = EXISTS_SUBLINK;
   15517        5096 :                     n->subLinkId = 0;
   15518        5096 :                     n->testexpr = NULL;
   15519        5096 :                     n->operName = NIL;
   15520        5096 :                     n->subselect = $2;
   15521        5096 :                     n->location = @1;
   15522        5096 :                     $$ = (Node *) n;
   15523             :                 }
   15524             :             | ARRAY select_with_parens
   15525             :                 {
   15526        7398 :                     SubLink    *n = makeNode(SubLink);
   15527             : 
   15528        7398 :                     n->subLinkType = ARRAY_SUBLINK;
   15529        7398 :                     n->subLinkId = 0;
   15530        7398 :                     n->testexpr = NULL;
   15531        7398 :                     n->operName = NIL;
   15532        7398 :                     n->subselect = $2;
   15533        7398 :                     n->location = @1;
   15534        7398 :                     $$ = (Node *) n;
   15535             :                 }
   15536             :             | ARRAY array_expr
   15537             :                 {
   15538        7380 :                     A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
   15539             : 
   15540             :                     /* point outermost A_ArrayExpr to the ARRAY keyword */
   15541        7380 :                     n->location = @1;
   15542        7380 :                     $$ = (Node *) n;
   15543             :                 }
   15544             :             | explicit_row
   15545             :                 {
   15546        3808 :                     RowExpr    *r = makeNode(RowExpr);
   15547             : 
   15548        3808 :                     r->args = $1;
   15549        3808 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15550        3808 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15551        3808 :                     r->row_format = COERCE_EXPLICIT_CALL; /* abuse */
   15552        3808 :                     r->location = @1;
   15553        3808 :                     $$ = (Node *) r;
   15554             :                 }
   15555             :             | implicit_row
   15556             :                 {
   15557        2124 :                     RowExpr    *r = makeNode(RowExpr);
   15558             : 
   15559        2124 :                     r->args = $1;
   15560        2124 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15561        2124 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15562        2124 :                     r->row_format = COERCE_IMPLICIT_CAST; /* abuse */
   15563        2124 :                     r->location = @1;
   15564        2124 :                     $$ = (Node *) r;
   15565             :                 }
   15566             :             | GROUPING '(' expr_list ')'
   15567             :               {
   15568         314 :                   GroupingFunc *g = makeNode(GroupingFunc);
   15569             : 
   15570         314 :                   g->args = $3;
   15571         314 :                   g->location = @1;
   15572         314 :                   $$ = (Node *) g;
   15573             :               }
   15574             :         ;
   15575             : 
   15576             : func_application: func_name '(' ')'
   15577             :                 {
   15578       46648 :                     $$ = (Node *) makeFuncCall($1, NIL,
   15579             :                                                COERCE_EXPLICIT_CALL,
   15580       46648 :                                                @1);
   15581             :                 }
   15582             :             | func_name '(' func_arg_list opt_sort_clause ')'
   15583             :                 {
   15584      281290 :                     FuncCall   *n = makeFuncCall($1, $3,
   15585             :                                                  COERCE_EXPLICIT_CALL,
   15586      281290 :                                                  @1);
   15587             : 
   15588      281290 :                     n->agg_order = $4;
   15589      281290 :                     $$ = (Node *) n;
   15590             :                 }
   15591             :             | func_name '(' VARIADIC func_arg_expr opt_sort_clause ')'
   15592             :                 {
   15593         576 :                     FuncCall   *n = makeFuncCall($1, list_make1($4),
   15594             :                                                  COERCE_EXPLICIT_CALL,
   15595         576 :                                                  @1);
   15596             : 
   15597         576 :                     n->func_variadic = true;
   15598         576 :                     n->agg_order = $5;
   15599         576 :                     $$ = (Node *) n;
   15600             :                 }
   15601             :             | func_name '(' func_arg_list ',' VARIADIC func_arg_expr opt_sort_clause ')'
   15602             :                 {
   15603         120 :                     FuncCall   *n = makeFuncCall($1, lappend($3, $6),
   15604             :                                                  COERCE_EXPLICIT_CALL,
   15605         120 :                                                  @1);
   15606             : 
   15607         120 :                     n->func_variadic = true;
   15608         120 :                     n->agg_order = $7;
   15609         120 :                     $$ = (Node *) n;
   15610             :                 }
   15611             :             | func_name '(' ALL func_arg_list opt_sort_clause ')'
   15612             :                 {
   15613           0 :                     FuncCall   *n = makeFuncCall($1, $4,
   15614             :                                                  COERCE_EXPLICIT_CALL,
   15615           0 :                                                  @1);
   15616             : 
   15617           0 :                     n->agg_order = $5;
   15618             :                     /* Ideally we'd mark the FuncCall node to indicate
   15619             :                      * "must be an aggregate", but there's no provision
   15620             :                      * for that in FuncCall at the moment.
   15621             :                      */
   15622           0 :                     $$ = (Node *) n;
   15623             :                 }
   15624             :             | func_name '(' DISTINCT func_arg_list opt_sort_clause ')'
   15625             :                 {
   15626         526 :                     FuncCall   *n = makeFuncCall($1, $4,
   15627             :                                                  COERCE_EXPLICIT_CALL,
   15628         526 :                                                  @1);
   15629             : 
   15630         526 :                     n->agg_order = $5;
   15631         526 :                     n->agg_distinct = true;
   15632         526 :                     $$ = (Node *) n;
   15633             :                 }
   15634             :             | func_name '(' '*' ')'
   15635             :                 {
   15636             :                     /*
   15637             :                      * We consider AGGREGATE(*) to invoke a parameterless
   15638             :                      * aggregate.  This does the right thing for COUNT(*),
   15639             :                      * and there are no other aggregates in SQL that accept
   15640             :                      * '*' as parameter.
   15641             :                      *
   15642             :                      * The FuncCall node is also marked agg_star = true,
   15643             :                      * so that later processing can detect what the argument
   15644             :                      * really was.
   15645             :                      */
   15646       11958 :                     FuncCall   *n = makeFuncCall($1, NIL,
   15647             :                                                  COERCE_EXPLICIT_CALL,
   15648       11958 :                                                  @1);
   15649             : 
   15650       11958 :                     n->agg_star = true;
   15651       11958 :                     $$ = (Node *) n;
   15652             :                 }
   15653             :         ;
   15654             : 
   15655             : 
   15656             : /*
   15657             :  * func_expr and its cousin func_expr_windowless are split out from c_expr just
   15658             :  * so that we have classifications for "everything that is a function call or
   15659             :  * looks like one".  This isn't very important, but it saves us having to
   15660             :  * document which variants are legal in places like "FROM function()" or the
   15661             :  * backwards-compatible functional-index syntax for CREATE INDEX.
   15662             :  * (Note that many of the special SQL functions wouldn't actually make any
   15663             :  * sense as functional index entries, but we ignore that consideration here.)
   15664             :  */
   15665             : func_expr: func_application within_group_clause filter_clause over_clause
   15666             :                 {
   15667      300734 :                     FuncCall   *n = (FuncCall *) $1;
   15668             : 
   15669             :                     /*
   15670             :                      * The order clause for WITHIN GROUP and the one for
   15671             :                      * plain-aggregate ORDER BY share a field, so we have to
   15672             :                      * check here that at most one is present.  We also check
   15673             :                      * for DISTINCT and VARIADIC here to give a better error
   15674             :                      * location.  Other consistency checks are deferred to
   15675             :                      * parse analysis.
   15676             :                      */
   15677      300734 :                     if ($2 != NIL)
   15678             :                     {
   15679         348 :                         if (n->agg_order != NIL)
   15680           6 :                             ereport(ERROR,
   15681             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15682             :                                      errmsg("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
   15683             :                                      parser_errposition(@2)));
   15684         342 :                         if (n->agg_distinct)
   15685           0 :                             ereport(ERROR,
   15686             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15687             :                                      errmsg("cannot use DISTINCT with WITHIN GROUP"),
   15688             :                                      parser_errposition(@2)));
   15689         342 :                         if (n->func_variadic)
   15690           0 :                             ereport(ERROR,
   15691             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15692             :                                      errmsg("cannot use VARIADIC with WITHIN GROUP"),
   15693             :                                      parser_errposition(@2)));
   15694         342 :                         n->agg_order = $2;
   15695         342 :                         n->agg_within_group = true;
   15696             :                     }
   15697      300728 :                     n->agg_filter = $3;
   15698      300728 :                     n->over = $4;
   15699      300728 :                     $$ = (Node *) n;
   15700             :                 }
   15701             :             | json_aggregate_func filter_clause over_clause
   15702             :                 {
   15703         612 :                     JsonAggConstructor *n = IsA($1, JsonObjectAgg) ?
   15704         306 :                         ((JsonObjectAgg *) $1)->constructor :
   15705         150 :                         ((JsonArrayAgg *) $1)->constructor;
   15706             : 
   15707         306 :                     n->agg_filter = $2;
   15708         306 :                     n->over = $3;
   15709         306 :                     $$ = (Node *) $1;
   15710             :                 }
   15711             :             | func_expr_common_subexpr
   15712       61906 :                 { $$ = $1; }
   15713             :         ;
   15714             : 
   15715             : /*
   15716             :  * As func_expr but does not accept WINDOW functions directly
   15717             :  * (but they can still be contained in arguments for functions etc).
   15718             :  * Use this when window expressions are not allowed, where needed to
   15719             :  * disambiguate the grammar (e.g. in CREATE INDEX).
   15720             :  */
   15721             : func_expr_windowless:
   15722       39850 :             func_application                        { $$ = $1; }
   15723         402 :             | func_expr_common_subexpr              { $$ = $1; }
   15724           0 :             | json_aggregate_func                   { $$ = $1; }
   15725             :         ;
   15726             : 
   15727             : /*
   15728             :  * Special expressions that are considered to be functions.
   15729             :  */
   15730             : func_expr_common_subexpr:
   15731             :             COLLATION FOR '(' a_expr ')'
   15732             :                 {
   15733          30 :                     $$ = (Node *) makeFuncCall(SystemFuncName("pg_collation_for"),
   15734          30 :                                                list_make1($4),
   15735             :                                                COERCE_SQL_SYNTAX,
   15736          30 :                                                @1);
   15737             :                 }
   15738             :             | CURRENT_DATE
   15739             :                 {
   15740         268 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_DATE, -1, @1);
   15741             :                 }
   15742             :             | CURRENT_TIME
   15743             :                 {
   15744          24 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME, -1, @1);
   15745             :                 }
   15746             :             | CURRENT_TIME '(' Iconst ')'
   15747             :                 {
   15748          24 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME_N, $3, @1);
   15749             :                 }
   15750             :             | CURRENT_TIMESTAMP
   15751             :                 {
   15752         288 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP, -1, @1);
   15753             :                 }
   15754             :             | CURRENT_TIMESTAMP '(' Iconst ')'
   15755             :                 {
   15756         106 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP_N, $3, @1);
   15757             :                 }
   15758             :             | LOCALTIME
   15759             :                 {
   15760          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIME, -1, @1);
   15761             :                 }
   15762             :             | LOCALTIME '(' Iconst ')'
   15763             :                 {
   15764          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIME_N, $3, @1);
   15765             :                 }
   15766             :             | LOCALTIMESTAMP
   15767             :                 {
   15768          36 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP, -1, @1);
   15769             :                 }
   15770             :             | LOCALTIMESTAMP '(' Iconst ')'
   15771             :                 {
   15772          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP_N, $3, @1);
   15773             :                 }
   15774             :             | CURRENT_ROLE
   15775             :                 {
   15776          68 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_ROLE, -1, @1);
   15777             :                 }
   15778             :             | CURRENT_USER
   15779             :                 {
   15780         850 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_USER, -1, @1);
   15781             :                 }
   15782             :             | SESSION_USER
   15783             :                 {
   15784         542 :                     $$ = makeSQLValueFunction(SVFOP_SESSION_USER, -1, @1);
   15785             :                 }
   15786             :             | SYSTEM_USER
   15787             :                 {
   15788          20 :                     $$ = (Node *) makeFuncCall(SystemFuncName("system_user"),
   15789             :                                                NIL,
   15790             :                                                COERCE_SQL_SYNTAX,
   15791             :                                                @1);
   15792             :                 }
   15793             :             | USER
   15794             :                 {
   15795          24 :                     $$ = makeSQLValueFunction(SVFOP_USER, -1, @1);
   15796             :                 }
   15797             :             | CURRENT_CATALOG
   15798             :                 {
   15799          30 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_CATALOG, -1, @1);
   15800             :                 }
   15801             :             | CURRENT_SCHEMA
   15802             :                 {
   15803          30 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_SCHEMA, -1, @1);
   15804             :                 }
   15805             :             | CAST '(' a_expr AS Typename ')'
   15806       49612 :                 { $$ = makeTypeCast($3, $5, @1); }
   15807             :             | EXTRACT '(' extract_list ')'
   15808             :                 {
   15809        1152 :                     $$ = (Node *) makeFuncCall(SystemFuncName("extract"),
   15810        1152 :                                                $3,
   15811             :                                                COERCE_SQL_SYNTAX,
   15812        1152 :                                                @1);
   15813             :                 }
   15814             :             | NORMALIZE '(' a_expr ')'
   15815             :                 {
   15816          18 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   15817          18 :                                                list_make1($3),
   15818             :                                                COERCE_SQL_SYNTAX,
   15819          18 :                                                @1);
   15820             :                 }
   15821             :             | NORMALIZE '(' a_expr ',' unicode_normal_form ')'
   15822             :                 {
   15823          36 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   15824          36 :                                                list_make2($3, makeStringConst($5, @5)),
   15825             :                                                COERCE_SQL_SYNTAX,
   15826          36 :                                                @1);
   15827             :                 }
   15828             :             | OVERLAY '(' overlay_list ')'
   15829             :                 {
   15830          82 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlay"),
   15831          82 :                                                $3,
   15832             :                                                COERCE_SQL_SYNTAX,
   15833          82 :                                                @1);
   15834             :                 }
   15835             :             | OVERLAY '(' func_arg_list_opt ')'
   15836             :                 {
   15837             :                     /*
   15838             :                      * allow functions named overlay() to be called without
   15839             :                      * special syntax
   15840             :                      */
   15841           0 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("overlay")),
   15842           0 :                                                $3,
   15843             :                                                COERCE_EXPLICIT_CALL,
   15844           0 :                                                @1);
   15845             :                 }
   15846             :             | POSITION '(' position_list ')'
   15847             :                 {
   15848             :                     /*
   15849             :                      * position(A in B) is converted to position(B, A)
   15850             :                      *
   15851             :                      * We deliberately don't offer a "plain syntax" option
   15852             :                      * for position(), because the reversal of the arguments
   15853             :                      * creates too much risk of confusion.
   15854             :                      */
   15855         350 :                     $$ = (Node *) makeFuncCall(SystemFuncName("position"),
   15856         350 :                                                $3,
   15857             :                                                COERCE_SQL_SYNTAX,
   15858         350 :                                                @1);
   15859             :                 }
   15860             :             | SUBSTRING '(' substr_list ')'
   15861             :                 {
   15862             :                     /* substring(A from B for C) is converted to
   15863             :                      * substring(A, B, C) - thomas 2000-11-28
   15864             :                      */
   15865         630 :                     $$ = (Node *) makeFuncCall(SystemFuncName("substring"),
   15866         630 :                                                $3,
   15867             :                                                COERCE_SQL_SYNTAX,
   15868         630 :                                                @1);
   15869             :                 }
   15870             :             | SUBSTRING '(' func_arg_list_opt ')'
   15871             :                 {
   15872             :                     /*
   15873             :                      * allow functions named substring() to be called without
   15874             :                      * special syntax
   15875             :                      */
   15876         188 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("substring")),
   15877         188 :                                                $3,
   15878             :                                                COERCE_EXPLICIT_CALL,
   15879         188 :                                                @1);
   15880             :                 }
   15881             :             | TREAT '(' a_expr AS Typename ')'
   15882             :                 {
   15883             :                     /* TREAT(expr AS target) converts expr of a particular type to target,
   15884             :                      * which is defined to be a subtype of the original expression.
   15885             :                      * In SQL99, this is intended for use with structured UDTs,
   15886             :                      * but let's make this a generally useful form allowing stronger
   15887             :                      * coercions than are handled by implicit casting.
   15888             :                      *
   15889             :                      * Convert SystemTypeName() to SystemFuncName() even though
   15890             :                      * at the moment they result in the same thing.
   15891             :                      */
   15892           0 :                     $$ = (Node *) makeFuncCall(SystemFuncName(strVal(llast($5->names))),
   15893           0 :                                                list_make1($3),
   15894             :                                                COERCE_EXPLICIT_CALL,
   15895           0 :                                                @1);
   15896             :                 }
   15897             :             | TRIM '(' BOTH trim_list ')'
   15898             :                 {
   15899             :                     /* various trim expressions are defined in SQL
   15900             :                      * - thomas 1997-07-19
   15901             :                      */
   15902          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   15903          12 :                                                $4,
   15904             :                                                COERCE_SQL_SYNTAX,
   15905          12 :                                                @1);
   15906             :                 }
   15907             :             | TRIM '(' LEADING trim_list ')'
   15908             :                 {
   15909          24 :                     $$ = (Node *) makeFuncCall(SystemFuncName("ltrim"),
   15910          24 :                                                $4,
   15911             :                                                COERCE_SQL_SYNTAX,
   15912          24 :                                                @1);
   15913             :                 }
   15914             :             | TRIM '(' TRAILING trim_list ')'
   15915             :                 {
   15916         536 :                     $$ = (Node *) makeFuncCall(SystemFuncName("rtrim"),
   15917         536 :                                                $4,
   15918             :                                                COERCE_SQL_SYNTAX,
   15919         536 :                                                @1);
   15920             :                 }
   15921             :             | TRIM '(' trim_list ')'
   15922             :                 {
   15923          98 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   15924          98 :                                                $3,
   15925             :                                                COERCE_SQL_SYNTAX,
   15926          98 :                                                @1);
   15927             :                 }
   15928             :             | NULLIF '(' a_expr ',' a_expr ')'
   15929             :                 {
   15930         242 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
   15931             :                 }
   15932             :             | COALESCE '(' expr_list ')'
   15933             :                 {
   15934        3030 :                     CoalesceExpr *c = makeNode(CoalesceExpr);
   15935             : 
   15936        3030 :                     c->args = $3;
   15937        3030 :                     c->location = @1;
   15938        3030 :                     $$ = (Node *) c;
   15939             :                 }
   15940             :             | GREATEST '(' expr_list ')'
   15941             :                 {
   15942         140 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   15943             : 
   15944         140 :                     v->args = $3;
   15945         140 :                     v->op = IS_GREATEST;
   15946         140 :                     v->location = @1;
   15947         140 :                     $$ = (Node *) v;
   15948             :                 }
   15949             :             | LEAST '(' expr_list ')'
   15950             :                 {
   15951         142 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   15952             : 
   15953         142 :                     v->args = $3;
   15954         142 :                     v->op = IS_LEAST;
   15955         142 :                     v->location = @1;
   15956         142 :                     $$ = (Node *) v;
   15957             :                 }
   15958             :             | XMLCONCAT '(' expr_list ')'
   15959             :                 {
   15960          62 :                     $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
   15961             :                 }
   15962             :             | XMLELEMENT '(' NAME_P ColLabel ')'
   15963             :                 {
   15964           6 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
   15965             :                 }
   15966             :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
   15967             :                 {
   15968          36 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
   15969             :                 }
   15970             :             | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
   15971             :                 {
   15972         116 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
   15973             :                 }
   15974             :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
   15975             :                 {
   15976          20 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
   15977             :                 }
   15978             :             | XMLEXISTS '(' c_expr xmlexists_argument ')'
   15979             :                 {
   15980             :                     /* xmlexists(A PASSING [BY REF] B [BY REF]) is
   15981             :                      * converted to xmlexists(A, B)*/
   15982          54 :                     $$ = (Node *) makeFuncCall(SystemFuncName("xmlexists"),
   15983          54 :                                                list_make2($3, $4),
   15984             :                                                COERCE_SQL_SYNTAX,
   15985          54 :                                                @1);
   15986             :                 }
   15987             :             | XMLFOREST '(' xml_attribute_list ')'
   15988             :                 {
   15989          32 :                     $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
   15990             :                 }
   15991             :             | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
   15992             :                 {
   15993             :                     XmlExpr *x = (XmlExpr *)
   15994         140 :                         makeXmlExpr(IS_XMLPARSE, NULL, NIL,
   15995         140 :                                     list_make2($4, makeBoolAConst($5, -1)),
   15996         140 :                                     @1);
   15997             : 
   15998         140 :                     x->xmloption = $3;
   15999         140 :                     $$ = (Node *) x;
   16000             :                 }
   16001             :             | XMLPI '(' NAME_P ColLabel ')'
   16002             :                 {
   16003          30 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
   16004             :                 }
   16005             :             | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
   16006             :                 {
   16007          50 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
   16008             :                 }
   16009             :             | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
   16010             :                 {
   16011          68 :                     $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
   16012          68 :                                      list_make3($3, $5, $6), @1);
   16013             :                 }
   16014             :             | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename xml_indent_option ')'
   16015             :                 {
   16016         190 :                     XmlSerialize *n = makeNode(XmlSerialize);
   16017             : 
   16018         190 :                     n->xmloption = $3;
   16019         190 :                     n->expr = $4;
   16020         190 :                     n->typeName = $6;
   16021         190 :                     n->indent = $7;
   16022         190 :                     n->location = @1;
   16023         190 :                     $$ = (Node *) n;
   16024             :                 }
   16025             :             | JSON_OBJECT '(' func_arg_list ')'
   16026             :                 {
   16027             :                     /* Support for legacy (non-standard) json_object() */
   16028          90 :                     $$ = (Node *) makeFuncCall(SystemFuncName("json_object"),
   16029          90 :                                                $3, COERCE_EXPLICIT_CALL, @1);
   16030             :                 }
   16031             :             | JSON_OBJECT '(' json_name_and_value_list
   16032             :                 json_object_constructor_null_clause_opt
   16033             :                 json_key_uniqueness_constraint_opt
   16034             :                 json_returning_clause_opt ')'
   16035             :                 {
   16036         288 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   16037             : 
   16038         288 :                     n->exprs = $3;
   16039         288 :                     n->absent_on_null = $4;
   16040         288 :                     n->unique = $5;
   16041         288 :                     n->output = (JsonOutput *) $6;
   16042         288 :                     n->location = @1;
   16043         288 :                     $$ = (Node *) n;
   16044             :                 }
   16045             :             | JSON_OBJECT '(' json_returning_clause_opt ')'
   16046             :                 {
   16047          92 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   16048             : 
   16049          92 :                     n->exprs = NULL;
   16050          92 :                     n->absent_on_null = false;
   16051          92 :                     n->unique = false;
   16052          92 :                     n->output = (JsonOutput *) $3;
   16053          92 :                     n->location = @1;
   16054          92 :                     $$ = (Node *) n;
   16055             :                 }
   16056             :             | JSON_ARRAY '('
   16057             :                 json_value_expr_list
   16058             :                 json_array_constructor_null_clause_opt
   16059             :                 json_returning_clause_opt
   16060             :             ')'
   16061             :                 {
   16062          96 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   16063             : 
   16064          96 :                     n->exprs = $3;
   16065          96 :                     n->absent_on_null = $4;
   16066          96 :                     n->output = (JsonOutput *) $5;
   16067          96 :                     n->location = @1;
   16068          96 :                     $$ = (Node *) n;
   16069             :                 }
   16070             :             | JSON_ARRAY '('
   16071             :                 select_no_parens
   16072             :                 json_format_clause_opt
   16073             :                 /* json_array_constructor_null_clause_opt */
   16074             :                 json_returning_clause_opt
   16075             :             ')'
   16076             :                 {
   16077          54 :                     JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
   16078             : 
   16079          54 :                     n->query = $3;
   16080          54 :                     n->format = (JsonFormat *) $4;
   16081          54 :                     n->absent_on_null = true;    /* XXX */
   16082          54 :                     n->output = (JsonOutput *) $5;
   16083          54 :                     n->location = @1;
   16084          54 :                     $$ = (Node *) n;
   16085             :                 }
   16086             :             | JSON_ARRAY '('
   16087             :                 json_returning_clause_opt
   16088             :             ')'
   16089             :                 {
   16090          86 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   16091             : 
   16092          86 :                     n->exprs = NIL;
   16093          86 :                     n->absent_on_null = true;
   16094          86 :                     n->output = (JsonOutput *) $3;
   16095          86 :                     n->location = @1;
   16096          86 :                     $$ = (Node *) n;
   16097             :                 }
   16098             :             | JSON '(' json_value_expr json_key_uniqueness_constraint_opt ')'
   16099             :                 {
   16100         164 :                     JsonParseExpr *n = makeNode(JsonParseExpr);
   16101             : 
   16102         164 :                     n->expr = (JsonValueExpr *) $3;
   16103         164 :                     n->unique_keys = $4;
   16104         164 :                     n->output = NULL;
   16105         164 :                     n->location = @1;
   16106         164 :                     $$ = (Node *) n;
   16107             :                 }
   16108             :             | JSON_SCALAR '(' a_expr ')'
   16109             :                 {
   16110         112 :                     JsonScalarExpr *n = makeNode(JsonScalarExpr);
   16111             : 
   16112         112 :                     n->expr = (Expr *) $3;
   16113         112 :                     n->output = NULL;
   16114         112 :                     n->location = @1;
   16115         112 :                     $$ = (Node *) n;
   16116             :                 }
   16117             :             | JSON_SERIALIZE '(' json_value_expr json_returning_clause_opt ')'
   16118             :                 {
   16119          90 :                     JsonSerializeExpr *n = makeNode(JsonSerializeExpr);
   16120             : 
   16121          90 :                     n->expr = (JsonValueExpr *) $3;
   16122          90 :                     n->output = (JsonOutput *) $4;
   16123          90 :                     n->location = @1;
   16124          90 :                     $$ = (Node *) n;
   16125             :                 }
   16126             :             | MERGE_ACTION '(' ')'
   16127             :                 {
   16128         168 :                     MergeSupportFunc *m = makeNode(MergeSupportFunc);
   16129             : 
   16130         168 :                     m->msftype = TEXTOID;
   16131         168 :                     m->location = @1;
   16132         168 :                     $$ = (Node *) m;
   16133             :                 }
   16134             :             | JSON_QUERY '('
   16135             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16136             :                 json_returning_clause_opt
   16137             :                 json_wrapper_behavior
   16138             :                 json_quotes_clause_opt
   16139             :                 json_behavior_clause_opt
   16140             :             ')'
   16141             :                 {
   16142         906 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16143             : 
   16144         906 :                     n->op = JSON_QUERY_OP;
   16145         906 :                     n->context_item = (JsonValueExpr *) $3;
   16146         906 :                     n->pathspec = $5;
   16147         906 :                     n->passing = $6;
   16148         906 :                     n->output = (JsonOutput *) $7;
   16149         906 :                     n->wrapper = $8;
   16150         906 :                     n->quotes = $9;
   16151         906 :                     n->on_empty = (JsonBehavior *) linitial($10);
   16152         906 :                     n->on_error = (JsonBehavior *) lsecond($10);
   16153         906 :                     n->location = @1;
   16154         906 :                     $$ = (Node *) n;
   16155             :                 }
   16156             :             | JSON_EXISTS '('
   16157             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16158             :                 json_on_error_clause_opt
   16159             :             ')'
   16160             :                 {
   16161         162 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16162             : 
   16163         162 :                     n->op = JSON_EXISTS_OP;
   16164         162 :                     n->context_item = (JsonValueExpr *) $3;
   16165         162 :                     n->pathspec = $5;
   16166         162 :                     n->passing = $6;
   16167         162 :                     n->output = NULL;
   16168         162 :                     n->on_error = (JsonBehavior *) $7;
   16169         162 :                     n->location = @1;
   16170         162 :                     $$ = (Node *) n;
   16171             :                 }
   16172             :             | JSON_VALUE '('
   16173             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16174             :                 json_returning_clause_opt
   16175             :                 json_behavior_clause_opt
   16176             :             ')'
   16177             :                 {
   16178         492 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16179             : 
   16180         492 :                     n->op = JSON_VALUE_OP;
   16181         492 :                     n->context_item = (JsonValueExpr *) $3;
   16182         492 :                     n->pathspec = $5;
   16183         492 :                     n->passing = $6;
   16184         492 :                     n->output = (JsonOutput *) $7;
   16185         492 :                     n->on_empty = (JsonBehavior *) linitial($8);
   16186         492 :                     n->on_error = (JsonBehavior *) lsecond($8);
   16187         492 :                     n->location = @1;
   16188         492 :                     $$ = (Node *) n;
   16189             :                 }
   16190             :             ;
   16191             : 
   16192             : 
   16193             : /*
   16194             :  * SQL/XML support
   16195             :  */
   16196             : xml_root_version: VERSION_P a_expr
   16197          24 :                 { $$ = $2; }
   16198             :             | VERSION_P NO VALUE_P
   16199          44 :                 { $$ = makeNullAConst(-1); }
   16200             :         ;
   16201             : 
   16202             : opt_xml_root_standalone: ',' STANDALONE_P YES_P
   16203          26 :                 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
   16204             :             | ',' STANDALONE_P NO
   16205          12 :                 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
   16206             :             | ',' STANDALONE_P NO VALUE_P
   16207          12 :                 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
   16208             :             | /*EMPTY*/
   16209          18 :                 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
   16210             :         ;
   16211             : 
   16212          56 : xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')'    { $$ = $3; }
   16213             :         ;
   16214             : 
   16215          88 : xml_attribute_list: xml_attribute_el                    { $$ = list_make1($1); }
   16216         144 :             | xml_attribute_list ',' xml_attribute_el   { $$ = lappend($1, $3); }
   16217             :         ;
   16218             : 
   16219             : xml_attribute_el: a_expr AS ColLabel
   16220             :                 {
   16221         106 :                     $$ = makeNode(ResTarget);
   16222         106 :                     $$->name = $3;
   16223         106 :                     $$->indirection = NIL;
   16224         106 :                     $$->val = (Node *) $1;
   16225         106 :                     $$->location = @1;
   16226             :                 }
   16227             :             | a_expr
   16228             :                 {
   16229         126 :                     $$ = makeNode(ResTarget);
   16230         126 :                     $$->name = NULL;
   16231         126 :                     $$->indirection = NIL;
   16232         126 :                     $$->val = (Node *) $1;
   16233         126 :                     $$->location = @1;
   16234             :                 }
   16235             :         ;
   16236             : 
   16237         162 : document_or_content: DOCUMENT_P                     { $$ = XMLOPTION_DOCUMENT; }
   16238         180 :             | CONTENT_P                             { $$ = XMLOPTION_CONTENT; }
   16239             :         ;
   16240             : 
   16241         120 : xml_indent_option: INDENT                           { $$ = true; }
   16242          24 :             | NO INDENT                             { $$ = false; }
   16243          46 :             | /*EMPTY*/                             { $$ = false; }
   16244             :         ;
   16245             : 
   16246           0 : xml_whitespace_option: PRESERVE WHITESPACE_P        { $$ = true; }
   16247           2 :             | STRIP_P WHITESPACE_P                  { $$ = false; }
   16248         138 :             | /*EMPTY*/                             { $$ = false; }
   16249             :         ;
   16250             : 
   16251             : /* We allow several variants for SQL and other compatibility. */
   16252             : xmlexists_argument:
   16253             :             PASSING c_expr
   16254             :                 {
   16255         226 :                     $$ = $2;
   16256             :                 }
   16257             :             | PASSING c_expr xml_passing_mech
   16258             :                 {
   16259           0 :                     $$ = $2;
   16260             :                 }
   16261             :             | PASSING xml_passing_mech c_expr
   16262             :                 {
   16263          42 :                     $$ = $3;
   16264             :                 }
   16265             :             | PASSING xml_passing_mech c_expr xml_passing_mech
   16266             :                 {
   16267           6 :                     $$ = $3;
   16268             :                 }
   16269             :         ;
   16270             : 
   16271             : xml_passing_mech:
   16272             :             BY REF_P
   16273             :             | BY VALUE_P
   16274             :         ;
   16275             : 
   16276             : 
   16277             : /*
   16278             :  * Aggregate decoration clauses
   16279             :  */
   16280             : within_group_clause:
   16281         348 :             WITHIN GROUP_P '(' sort_clause ')'      { $$ = $4; }
   16282      300392 :             | /*EMPTY*/                             { $$ = NIL; }
   16283             :         ;
   16284             : 
   16285             : filter_clause:
   16286         836 :             FILTER '(' WHERE a_expr ')'             { $$ = $4; }
   16287      300210 :             | /*EMPTY*/                             { $$ = NULL; }
   16288             :         ;
   16289             : 
   16290             : 
   16291             : /*
   16292             :  * Window Definitions
   16293             :  */
   16294             : window_clause:
   16295         528 :             WINDOW window_definition_list           { $$ = $2; }
   16296      453934 :             | /*EMPTY*/                             { $$ = NIL; }
   16297             :         ;
   16298             : 
   16299             : window_definition_list:
   16300         528 :             window_definition                       { $$ = list_make1($1); }
   16301             :             | window_definition_list ',' window_definition
   16302          12 :                                                     { $$ = lappend($1, $3); }
   16303             :         ;
   16304             : 
   16305             : window_definition:
   16306             :             ColId AS window_specification
   16307             :                 {
   16308         540 :                     WindowDef  *n = $3;
   16309             : 
   16310         540 :                     n->name = $1;
   16311         540 :                     $$ = n;
   16312             :                 }
   16313             :         ;
   16314             : 
   16315             : over_clause: OVER window_specification
   16316        2466 :                 { $$ = $2; }
   16317             :             | OVER ColId
   16318             :                 {
   16319         942 :                     WindowDef  *n = makeNode(WindowDef);
   16320             : 
   16321         942 :                     n->name = $2;
   16322         942 :                     n->refname = NULL;
   16323         942 :                     n->partitionClause = NIL;
   16324         942 :                     n->orderClause = NIL;
   16325         942 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   16326         942 :                     n->startOffset = NULL;
   16327         942 :                     n->endOffset = NULL;
   16328         942 :                     n->location = @2;
   16329         942 :                     $$ = n;
   16330             :                 }
   16331             :             | /*EMPTY*/
   16332      297632 :                 { $$ = NULL; }
   16333             :         ;
   16334             : 
   16335             : window_specification: '(' opt_existing_window_name opt_partition_clause
   16336             :                         opt_sort_clause opt_frame_clause ')'
   16337             :                 {
   16338        3006 :                     WindowDef  *n = makeNode(WindowDef);
   16339             : 
   16340        3006 :                     n->name = NULL;
   16341        3006 :                     n->refname = $2;
   16342        3006 :                     n->partitionClause = $3;
   16343        3006 :                     n->orderClause = $4;
   16344             :                     /* copy relevant fields of opt_frame_clause */
   16345        3006 :                     n->frameOptions = $5->frameOptions;
   16346        3006 :                     n->startOffset = $5->startOffset;
   16347        3006 :                     n->endOffset = $5->endOffset;
   16348        3006 :                     n->location = @1;
   16349        3006 :                     $$ = n;
   16350             :                 }
   16351             :         ;
   16352             : 
   16353             : /*
   16354             :  * If we see PARTITION, RANGE, ROWS or GROUPS as the first token after the '('
   16355             :  * of a window_specification, we want the assumption to be that there is
   16356             :  * no existing_window_name; but those keywords are unreserved and so could
   16357             :  * be ColIds.  We fix this by making them have the same precedence as IDENT
   16358             :  * and giving the empty production here a slightly higher precedence, so
   16359             :  * that the shift/reduce conflict is resolved in favor of reducing the rule.
   16360             :  * These keywords are thus precluded from being an existing_window_name but
   16361             :  * are not reserved for any other purpose.
   16362             :  */
   16363          30 : opt_existing_window_name: ColId                     { $$ = $1; }
   16364        2982 :             | /*EMPTY*/             %prec Op        { $$ = NULL; }
   16365             :         ;
   16366             : 
   16367         822 : opt_partition_clause: PARTITION BY expr_list        { $$ = $3; }
   16368        2184 :             | /*EMPTY*/                             { $$ = NIL; }
   16369             :         ;
   16370             : 
   16371             : /*
   16372             :  * For frame clauses, we return a WindowDef, but only some fields are used:
   16373             :  * frameOptions, startOffset, and endOffset.
   16374             :  */
   16375             : opt_frame_clause:
   16376             :             RANGE frame_extent opt_window_exclusion_clause
   16377             :                 {
   16378         796 :                     WindowDef  *n = $2;
   16379             : 
   16380         796 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
   16381         796 :                     n->frameOptions |= $3;
   16382         796 :                     $$ = n;
   16383             :                 }
   16384             :             | ROWS frame_extent opt_window_exclusion_clause
   16385             :                 {
   16386         618 :                     WindowDef  *n = $2;
   16387             : 
   16388         618 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
   16389         618 :                     n->frameOptions |= $3;
   16390         618 :                     $$ = n;
   16391             :                 }
   16392             :             | GROUPS frame_extent opt_window_exclusion_clause
   16393             :                 {
   16394         204 :                     WindowDef  *n = $2;
   16395             : 
   16396         204 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_GROUPS;
   16397         204 :                     n->frameOptions |= $3;
   16398         204 :                     $$ = n;
   16399             :                 }
   16400             :             | /*EMPTY*/
   16401             :                 {
   16402        1388 :                     WindowDef  *n = makeNode(WindowDef);
   16403             : 
   16404        1388 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   16405        1388 :                     n->startOffset = NULL;
   16406        1388 :                     n->endOffset = NULL;
   16407        1388 :                     $$ = n;
   16408             :                 }
   16409             :         ;
   16410             : 
   16411             : frame_extent: frame_bound
   16412             :                 {
   16413           6 :                     WindowDef  *n = $1;
   16414             : 
   16415             :                     /* reject invalid cases */
   16416           6 :                     if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   16417           0 :                         ereport(ERROR,
   16418             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16419             :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   16420             :                                  parser_errposition(@1)));
   16421           6 :                     if (n->frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING)
   16422           0 :                         ereport(ERROR,
   16423             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16424             :                                  errmsg("frame starting from following row cannot end with current row"),
   16425             :                                  parser_errposition(@1)));
   16426           6 :                     n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
   16427           6 :                     $$ = n;
   16428             :                 }
   16429             :             | BETWEEN frame_bound AND frame_bound
   16430             :                 {
   16431        1612 :                     WindowDef  *n1 = $2;
   16432        1612 :                     WindowDef  *n2 = $4;
   16433             : 
   16434             :                     /* form merged options */
   16435        1612 :                     int     frameOptions = n1->frameOptions;
   16436             :                     /* shift converts START_ options to END_ options */
   16437        1612 :                     frameOptions |= n2->frameOptions << 1;
   16438        1612 :                     frameOptions |= FRAMEOPTION_BETWEEN;
   16439             :                     /* reject invalid cases */
   16440        1612 :                     if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   16441           0 :                         ereport(ERROR,
   16442             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16443             :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   16444             :                                  parser_errposition(@2)));
   16445        1612 :                     if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
   16446           0 :                         ereport(ERROR,
   16447             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16448             :                                  errmsg("frame end cannot be UNBOUNDED PRECEDING"),
   16449             :                                  parser_errposition(@4)));
   16450        1612 :                     if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
   16451         460 :                         (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING))
   16452           0 :                         ereport(ERROR,
   16453             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16454             :                                  errmsg("frame starting from current row cannot have preceding rows"),
   16455             :                                  parser_errposition(@4)));
   16456        1612 :                     if ((frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING) &&
   16457         168 :                         (frameOptions & (FRAMEOPTION_END_OFFSET_PRECEDING |
   16458             :                                          FRAMEOPTION_END_CURRENT_ROW)))
   16459           0 :                         ereport(ERROR,
   16460             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16461             :                                  errmsg("frame starting from following row cannot have preceding rows"),
   16462             :                                  parser_errposition(@4)));
   16463        1612 :                     n1->frameOptions = frameOptions;
   16464        1612 :                     n1->endOffset = n2->startOffset;
   16465        1612 :                     $$ = n1;
   16466             :                 }
   16467             :         ;
   16468             : 
   16469             : /*
   16470             :  * This is used for both frame start and frame end, with output set up on
   16471             :  * the assumption it's frame start; the frame_extent productions must reject
   16472             :  * invalid cases.
   16473             :  */
   16474             : frame_bound:
   16475             :             UNBOUNDED PRECEDING
   16476             :                 {
   16477         198 :                     WindowDef  *n = makeNode(WindowDef);
   16478             : 
   16479         198 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
   16480         198 :                     n->startOffset = NULL;
   16481         198 :                     n->endOffset = NULL;
   16482         198 :                     $$ = n;
   16483             :                 }
   16484             :             | UNBOUNDED FOLLOWING
   16485             :                 {
   16486         376 :                     WindowDef  *n = makeNode(WindowDef);
   16487             : 
   16488         376 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
   16489         376 :                     n->startOffset = NULL;
   16490         376 :                     n->endOffset = NULL;
   16491         376 :                     $$ = n;
   16492             :                 }
   16493             :             | CURRENT_P ROW
   16494             :                 {
   16495         604 :                     WindowDef  *n = makeNode(WindowDef);
   16496             : 
   16497         604 :                     n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
   16498         604 :                     n->startOffset = NULL;
   16499         604 :                     n->endOffset = NULL;
   16500         604 :                     $$ = n;
   16501             :                 }
   16502             :             | a_expr PRECEDING
   16503             :                 {
   16504         900 :                     WindowDef  *n = makeNode(WindowDef);
   16505             : 
   16506         900 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_PRECEDING;
   16507         900 :                     n->startOffset = $1;
   16508         900 :                     n->endOffset = NULL;
   16509         900 :                     $$ = n;
   16510             :                 }
   16511             :             | a_expr FOLLOWING
   16512             :                 {
   16513        1152 :                     WindowDef  *n = makeNode(WindowDef);
   16514             : 
   16515        1152 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_FOLLOWING;
   16516        1152 :                     n->startOffset = $1;
   16517        1152 :                     n->endOffset = NULL;
   16518        1152 :                     $$ = n;
   16519             :                 }
   16520             :         ;
   16521             : 
   16522             : opt_window_exclusion_clause:
   16523          84 :             EXCLUDE CURRENT_P ROW   { $$ = FRAMEOPTION_EXCLUDE_CURRENT_ROW; }
   16524          96 :             | EXCLUDE GROUP_P       { $$ = FRAMEOPTION_EXCLUDE_GROUP; }
   16525         150 :             | EXCLUDE TIES          { $$ = FRAMEOPTION_EXCLUDE_TIES; }
   16526          18 :             | EXCLUDE NO OTHERS     { $$ = 0; }
   16527        1270 :             | /*EMPTY*/             { $$ = 0; }
   16528             :         ;
   16529             : 
   16530             : 
   16531             : /*
   16532             :  * Supporting nonterminals for expressions.
   16533             :  */
   16534             : 
   16535             : /* Explicit row production.
   16536             :  *
   16537             :  * SQL99 allows an optional ROW keyword, so we can now do single-element rows
   16538             :  * without conflicting with the parenthesized a_expr production.  Without the
   16539             :  * ROW keyword, there must be more than one a_expr inside the parens.
   16540             :  */
   16541           0 : row:        ROW '(' expr_list ')'                   { $$ = $3; }
   16542           0 :             | ROW '(' ')'                           { $$ = NIL; }
   16543        1572 :             | '(' expr_list ',' a_expr ')'          { $$ = lappend($2, $4); }
   16544             :         ;
   16545             : 
   16546        3778 : explicit_row:   ROW '(' expr_list ')'               { $$ = $3; }
   16547          30 :             | ROW '(' ')'                           { $$ = NIL; }
   16548             :         ;
   16549             : 
   16550        2124 : implicit_row:   '(' expr_list ',' a_expr ')'        { $$ = lappend($2, $4); }
   16551             :         ;
   16552             : 
   16553       14656 : sub_type:   ANY                                     { $$ = ANY_SUBLINK; }
   16554           0 :             | SOME                                  { $$ = ANY_SUBLINK; }
   16555         324 :             | ALL                                   { $$ = ALL_SUBLINK; }
   16556             :         ;
   16557             : 
   16558       10744 : all_Op:     Op                                      { $$ = $1; }
   16559       24602 :             | MathOp                                { $$ = $1; }
   16560             :         ;
   16561             : 
   16562          38 : MathOp:      '+'                                    { $$ = "+"; }
   16563          46 :             | '-'                                   { $$ = "-"; }
   16564          12 :             | '*'                                   { $$ = "*"; }
   16565           0 :             | '/'                                   { $$ = "/"; }
   16566           8 :             | '%'                                   { $$ = "%"; }
   16567           0 :             | '^'                                   { $$ = "^"; }
   16568         746 :             | '<'                                    { $$ = "<"; }
   16569         588 :             | '>'                                    { $$ = ">"; }
   16570       21500 :             | '='                                   { $$ = "="; }
   16571         612 :             | LESS_EQUALS                           { $$ = "<="; }
   16572         604 :             | GREATER_EQUALS                        { $$ = ">="; }
   16573         448 :             | NOT_EQUALS                            { $$ = "<>"; }
   16574             :         ;
   16575             : 
   16576             : qual_Op:    Op
   16577       40522 :                     { $$ = list_make1(makeString($1)); }
   16578             :             | OPERATOR '(' any_operator ')'
   16579       13946 :                     { $$ = $3; }
   16580             :         ;
   16581             : 
   16582             : qual_all_Op:
   16583             :             all_Op
   16584        1414 :                     { $$ = list_make1(makeString($1)); }
   16585             :             | OPERATOR '(' any_operator ')'
   16586          34 :                     { $$ = $3; }
   16587             :         ;
   16588             : 
   16589             : subquery_Op:
   16590             :             all_Op
   16591       14710 :                     { $$ = list_make1(makeString($1)); }
   16592             :             | OPERATOR '(' any_operator ')'
   16593         236 :                     { $$ = $3; }
   16594             :             | LIKE
   16595          24 :                     { $$ = list_make1(makeString("~~")); }
   16596             :             | NOT_LA LIKE
   16597          12 :                     { $$ = list_make1(makeString("!~~")); }
   16598             :             | ILIKE
   16599          12 :                     { $$ = list_make1(makeString("~~*")); }
   16600             :             | NOT_LA ILIKE
   16601           0 :                     { $$ = list_make1(makeString("!~~*")); }
   16602             : /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
   16603             :  * the regular expression is preprocessed by a function (similar_to_escape),
   16604             :  * and the ~ operator for posix regular expressions is used.
   16605             :  *        x SIMILAR TO y     ->    x ~ similar_to_escape(y)
   16606             :  * this transformation is made on the fly by the parser upwards.
   16607             :  * however the SubLink structure which handles any/some/all stuff
   16608             :  * is not ready for such a thing.
   16609             :  */
   16610             :             ;
   16611             : 
   16612             : expr_list:  a_expr
   16613             :                 {
   16614      152696 :                     $$ = list_make1($1);
   16615             :                 }
   16616             :             | expr_list ',' a_expr
   16617             :                 {
   16618      139984 :                     $$ = lappend($1, $3);
   16619             :                 }
   16620             :         ;
   16621             : 
   16622             : /* function arguments can have names */
   16623             : func_arg_list:  func_arg_expr
   16624             :                 {
   16625      282214 :                     $$ = list_make1($1);
   16626             :                 }
   16627             :             | func_arg_list ',' func_arg_expr
   16628             :                 {
   16629      206616 :                     $$ = lappend($1, $3);
   16630             :                 }
   16631             :         ;
   16632             : 
   16633             : func_arg_expr:  a_expr
   16634             :                 {
   16635      442736 :                     $$ = $1;
   16636             :                 }
   16637             :             | param_name COLON_EQUALS a_expr
   16638             :                 {
   16639       45778 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   16640             : 
   16641       45778 :                     na->name = $1;
   16642       45778 :                     na->arg = (Expr *) $3;
   16643       45778 :                     na->argnumber = -1;      /* until determined */
   16644       45778 :                     na->location = @1;
   16645       45778 :                     $$ = (Node *) na;
   16646             :                 }
   16647             :             | param_name EQUALS_GREATER a_expr
   16648             :                 {
   16649        1012 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   16650             : 
   16651        1012 :                     na->name = $1;
   16652        1012 :                     na->arg = (Expr *) $3;
   16653        1012 :                     na->argnumber = -1;      /* until determined */
   16654        1012 :                     na->location = @1;
   16655        1012 :                     $$ = (Node *) na;
   16656             :                 }
   16657             :         ;
   16658             : 
   16659         188 : func_arg_list_opt:  func_arg_list                   { $$ = $1; }
   16660           0 :             | /*EMPTY*/                             { $$ = NIL; }
   16661             :         ;
   16662             : 
   16663        1680 : type_list:  Typename                                { $$ = list_make1($1); }
   16664         392 :             | type_list ',' Typename                { $$ = lappend($1, $3); }
   16665             :         ;
   16666             : 
   16667             : array_expr: '[' expr_list ']'
   16668             :                 {
   16669        7622 :                     $$ = makeAArrayExpr($2, @1);
   16670             :                 }
   16671             :             | '[' array_expr_list ']'
   16672             :                 {
   16673         406 :                     $$ = makeAArrayExpr($2, @1);
   16674             :                 }
   16675             :             | '[' ']'
   16676             :                 {
   16677          88 :                     $$ = makeAArrayExpr(NIL, @1);
   16678             :                 }
   16679             :         ;
   16680             : 
   16681         406 : array_expr_list: array_expr                         { $$ = list_make1($1); }
   16682         330 :             | array_expr_list ',' array_expr        { $$ = lappend($1, $3); }
   16683             :         ;
   16684             : 
   16685             : 
   16686             : extract_list:
   16687             :             extract_arg FROM a_expr
   16688             :                 {
   16689        1152 :                     $$ = list_make2(makeStringConst($1, @1), $3);
   16690             :                 }
   16691             :         ;
   16692             : 
   16693             : /* Allow delimited string Sconst in extract_arg as an SQL extension.
   16694             :  * - thomas 2001-04-12
   16695             :  */
   16696             : extract_arg:
   16697         942 :             IDENT                                   { $$ = $1; }
   16698          54 :             | YEAR_P                                { $$ = "year"; }
   16699          36 :             | MONTH_P                               { $$ = "month"; }
   16700          48 :             | DAY_P                                 { $$ = "day"; }
   16701          24 :             | HOUR_P                                { $$ = "hour"; }
   16702          24 :             | MINUTE_P                              { $$ = "minute"; }
   16703          24 :             | SECOND_P                              { $$ = "second"; }
   16704           0 :             | Sconst                                { $$ = $1; }
   16705             :         ;
   16706             : 
   16707             : unicode_normal_form:
   16708          24 :             NFC                                     { $$ = "NFC"; }
   16709          12 :             | NFD                                   { $$ = "NFD"; }
   16710          18 :             | NFKC                                  { $$ = "NFKC"; }
   16711          18 :             | NFKD                                  { $$ = "NFKD"; }
   16712             :         ;
   16713             : 
   16714             : /* OVERLAY() arguments */
   16715             : overlay_list:
   16716             :             a_expr PLACING a_expr FROM a_expr FOR a_expr
   16717             :                 {
   16718             :                     /* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D) */
   16719          34 :                     $$ = list_make4($1, $3, $5, $7);
   16720             :                 }
   16721             :             | a_expr PLACING a_expr FROM a_expr
   16722             :                 {
   16723             :                     /* overlay(A PLACING B FROM C) is converted to overlay(A, B, C) */
   16724          48 :                     $$ = list_make3($1, $3, $5);
   16725             :                 }
   16726             :         ;
   16727             : 
   16728             : /* position_list uses b_expr not a_expr to avoid conflict with general IN */
   16729             : position_list:
   16730         350 :             b_expr IN_P b_expr                      { $$ = list_make2($3, $1); }
   16731             :         ;
   16732             : 
   16733             : /*
   16734             :  * SUBSTRING() arguments
   16735             :  *
   16736             :  * Note that SQL:1999 has both
   16737             :  *     text FROM int FOR int
   16738             :  * and
   16739             :  *     text FROM pattern FOR escape
   16740             :  *
   16741             :  * In the parser we map them both to a call to the substring() function and
   16742             :  * rely on type resolution to pick the right one.
   16743             :  *
   16744             :  * In SQL:2003, the second variant was changed to
   16745             :  *     text SIMILAR pattern ESCAPE escape
   16746             :  * We could in theory map that to a different function internally, but
   16747             :  * since we still support the SQL:1999 version, we don't.  However,
   16748             :  * ruleutils.c will reverse-list the call in the newer style.
   16749             :  */
   16750             : substr_list:
   16751             :             a_expr FROM a_expr FOR a_expr
   16752             :                 {
   16753         122 :                     $$ = list_make3($1, $3, $5);
   16754             :                 }
   16755             :             | a_expr FOR a_expr FROM a_expr
   16756             :                 {
   16757             :                     /* not legal per SQL, but might as well allow it */
   16758           0 :                     $$ = list_make3($1, $5, $3);
   16759             :                 }
   16760             :             | a_expr FROM a_expr
   16761             :                 {
   16762             :                     /*
   16763             :                      * Because we aren't restricting data types here, this
   16764             :                      * syntax can end up resolving to textregexsubstr().
   16765             :                      * We've historically allowed that to happen, so continue
   16766             :                      * to accept it.  However, ruleutils.c will reverse-list
   16767             :                      * such a call in regular function call syntax.
   16768             :                      */
   16769         310 :                     $$ = list_make2($1, $3);
   16770             :                 }
   16771             :             | a_expr FOR a_expr
   16772             :                 {
   16773             :                     /* not legal per SQL */
   16774             : 
   16775             :                     /*
   16776             :                      * Since there are no cases where this syntax allows
   16777             :                      * a textual FOR value, we forcibly cast the argument
   16778             :                      * to int4.  The possible matches in pg_proc are
   16779             :                      * substring(text,int4) and substring(text,text),
   16780             :                      * and we don't want the parser to choose the latter,
   16781             :                      * which it is likely to do if the second argument
   16782             :                      * is unknown or doesn't have an implicit cast to int4.
   16783             :                      */
   16784          36 :                     $$ = list_make3($1, makeIntConst(1, -1),
   16785             :                                     makeTypeCast($3,
   16786             :                                                  SystemTypeName("int4"), -1));
   16787             :                 }
   16788             :             | a_expr SIMILAR a_expr ESCAPE a_expr
   16789             :                 {
   16790         162 :                     $$ = list_make3($1, $3, $5);
   16791             :                 }
   16792             :         ;
   16793             : 
   16794         560 : trim_list:  a_expr FROM expr_list                   { $$ = lappend($3, $1); }
   16795          24 :             | FROM expr_list                        { $$ = $2; }
   16796          86 :             | expr_list                             { $$ = $1; }
   16797             :         ;
   16798             : 
   16799             : in_expr:    select_with_parens
   16800             :                 {
   16801        2414 :                     SubLink    *n = makeNode(SubLink);
   16802             : 
   16803        2414 :                     n->subselect = $1;
   16804             :                     /* other fields will be filled later */
   16805        2414 :                     $$ = (Node *) n;
   16806             :                 }
   16807       16690 :             | '(' expr_list ')'                     { $$ = (Node *) $2; }
   16808             :         ;
   16809             : 
   16810             : /*
   16811             :  * Define SQL-style CASE clause.
   16812             :  * - Full specification
   16813             :  *  CASE WHEN a = b THEN c ... ELSE d END
   16814             :  * - Implicit argument
   16815             :  *  CASE a WHEN b THEN c ... ELSE d END
   16816             :  */
   16817             : case_expr:  CASE case_arg when_clause_list case_default END_P
   16818             :                 {
   16819       53830 :                     CaseExpr   *c = makeNode(CaseExpr);
   16820             : 
   16821       53830 :                     c->casetype = InvalidOid; /* not analyzed yet */
   16822       53830 :                     c->arg = (Expr *) $2;
   16823       53830 :                     c->args = $3;
   16824       53830 :                     c->defresult = (Expr *) $4;
   16825       53830 :                     c->location = @1;
   16826       53830 :                     $$ = (Node *) c;
   16827             :                 }
   16828             :         ;
   16829             : 
   16830             : when_clause_list:
   16831             :             /* There must be at least one */
   16832       53830 :             when_clause                             { $$ = list_make1($1); }
   16833       41966 :             | when_clause_list when_clause          { $$ = lappend($1, $2); }
   16834             :         ;
   16835             : 
   16836             : when_clause:
   16837             :             WHEN a_expr THEN a_expr
   16838             :                 {
   16839       95796 :                     CaseWhen   *w = makeNode(CaseWhen);
   16840             : 
   16841       95796 :                     w->expr = (Expr *) $2;
   16842       95796 :                     w->result = (Expr *) $4;
   16843       95796 :                     w->location = @1;
   16844       95796 :                     $$ = (Node *) w;
   16845             :                 }
   16846             :         ;
   16847             : 
   16848             : case_default:
   16849       45968 :             ELSE a_expr                             { $$ = $2; }
   16850        7862 :             | /*EMPTY*/                             { $$ = NULL; }
   16851             :         ;
   16852             : 
   16853        5460 : case_arg:   a_expr                                  { $$ = $1; }
   16854       48370 :             | /*EMPTY*/                             { $$ = NULL; }
   16855             :         ;
   16856             : 
   16857             : columnref:  ColId
   16858             :                 {
   16859      581024 :                     $$ = makeColumnRef($1, NIL, @1, yyscanner);
   16860             :                 }
   16861             :             | ColId indirection
   16862             :                 {
   16863      929898 :                     $$ = makeColumnRef($1, $2, @1, yyscanner);
   16864             :                 }
   16865             :         ;
   16866             : 
   16867             : indirection_el:
   16868             :             '.' attr_name
   16869             :                 {
   16870     1255236 :                     $$ = (Node *) makeString($2);
   16871             :                 }
   16872             :             | '.' '*'
   16873             :                 {
   16874        5886 :                     $$ = (Node *) makeNode(A_Star);
   16875             :                 }
   16876             :             | '[' a_expr ']'
   16877             :                 {
   16878       11786 :                     A_Indices *ai = makeNode(A_Indices);
   16879             : 
   16880       11786 :                     ai->is_slice = false;
   16881       11786 :                     ai->lidx = NULL;
   16882       11786 :                     ai->uidx = $2;
   16883       11786 :                     $$ = (Node *) ai;
   16884             :                 }
   16885             :             | '[' opt_slice_bound ':' opt_slice_bound ']'
   16886             :                 {
   16887         558 :                     A_Indices *ai = makeNode(A_Indices);
   16888             : 
   16889         558 :                     ai->is_slice = true;
   16890         558 :                     ai->lidx = $2;
   16891         558 :                     ai->uidx = $4;
   16892         558 :                     $$ = (Node *) ai;
   16893             :                 }
   16894             :         ;
   16895             : 
   16896             : opt_slice_bound:
   16897         936 :             a_expr                                  { $$ = $1; }
   16898         180 :             | /*EMPTY*/                             { $$ = NULL; }
   16899             :         ;
   16900             : 
   16901             : indirection:
   16902     1255734 :             indirection_el                          { $$ = list_make1($1); }
   16903        2826 :             | indirection indirection_el            { $$ = lappend($1, $2); }
   16904             :         ;
   16905             : 
   16906             : opt_indirection:
   16907      283574 :             /*EMPTY*/                               { $$ = NIL; }
   16908       14906 :             | opt_indirection indirection_el        { $$ = lappend($1, $2); }
   16909             :         ;
   16910             : 
   16911             : opt_asymmetric: ASYMMETRIC
   16912             :             | /*EMPTY*/
   16913             :         ;
   16914             : 
   16915             : /* SQL/JSON support */
   16916             : json_passing_clause_opt:
   16917         300 :             PASSING json_arguments                  { $$ = $2; }
   16918        1700 :             | /*EMPTY*/                             { $$ = NIL; }
   16919             :         ;
   16920             : 
   16921             : json_arguments:
   16922         300 :             json_argument                           { $$ = list_make1($1); }
   16923         126 :             | json_arguments ',' json_argument      { $$ = lappend($1, $3); }
   16924             :         ;
   16925             : 
   16926             : json_argument:
   16927             :             json_value_expr AS ColLabel
   16928             :             {
   16929         426 :                 JsonArgument *n = makeNode(JsonArgument);
   16930             : 
   16931         426 :                 n->val = (JsonValueExpr *) $1;
   16932         426 :                 n->name = $3;
   16933         426 :                 $$ = (Node *) n;
   16934             :             }
   16935             :         ;
   16936             : 
   16937             : /* ARRAY is a noise word */
   16938             : json_wrapper_behavior:
   16939          42 :               WITHOUT WRAPPER                   { $$ = JSW_NONE; }
   16940           0 :             | WITHOUT ARRAY WRAPPER             { $$ = JSW_NONE; }
   16941          78 :             | WITH WRAPPER                      { $$ = JSW_UNCONDITIONAL; }
   16942          12 :             | WITH ARRAY WRAPPER                { $$ = JSW_UNCONDITIONAL; }
   16943           0 :             | WITH CONDITIONAL ARRAY WRAPPER    { $$ = JSW_CONDITIONAL; }
   16944          12 :             | WITH UNCONDITIONAL ARRAY WRAPPER  { $$ = JSW_UNCONDITIONAL; }
   16945          36 :             | WITH CONDITIONAL WRAPPER          { $$ = JSW_CONDITIONAL; }
   16946           6 :             | WITH UNCONDITIONAL WRAPPER        { $$ = JSW_UNCONDITIONAL; }
   16947        1514 :             | /* empty */                       { $$ = JSW_UNSPEC; }
   16948             :         ;
   16949             : 
   16950             : json_behavior:
   16951             :             DEFAULT a_expr
   16952         318 :                 { $$ = (Node *) makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); }
   16953             :             | json_behavior_type
   16954         528 :                 { $$ = (Node *) makeJsonBehavior($1, NULL, @1); }
   16955             :         ;
   16956             : 
   16957             : json_behavior_type:
   16958         384 :             ERROR_P     { $$ = JSON_BEHAVIOR_ERROR; }
   16959          24 :             | NULL_P    { $$ = JSON_BEHAVIOR_NULL; }
   16960           6 :             | TRUE_P    { $$ = JSON_BEHAVIOR_TRUE; }
   16961           6 :             | FALSE_P   { $$ = JSON_BEHAVIOR_FALSE; }
   16962          12 :             | UNKNOWN   { $$ = JSON_BEHAVIOR_UNKNOWN; }
   16963          24 :             | EMPTY_P ARRAY { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
   16964          60 :             | EMPTY_P OBJECT_P  { $$ = JSON_BEHAVIOR_EMPTY_OBJECT; }
   16965             :             /* non-standard, for Oracle compatibility only */
   16966          12 :             | EMPTY_P   { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
   16967             :         ;
   16968             : 
   16969             : json_behavior_clause_opt:
   16970             :             json_behavior ON EMPTY_P
   16971         108 :                 { $$ = list_make2($1, NULL); }
   16972             :             | json_behavior ON ERROR_P
   16973         498 :                 { $$ = list_make2(NULL, $1); }
   16974             :             | json_behavior ON EMPTY_P json_behavior ON ERROR_P
   16975          96 :                 { $$ = list_make2($1, $4); }
   16976             :             | /* EMPTY */
   16977        1574 :                 { $$ = list_make2(NULL, NULL); }
   16978             :         ;
   16979             : 
   16980             : json_on_error_clause_opt:
   16981             :             json_behavior ON ERROR_P
   16982          48 :                 { $$ = $1; }
   16983             :             | /* EMPTY */
   16984         548 :                 { $$ = NULL; }
   16985             :         ;
   16986             : 
   16987             : json_value_expr:
   16988             :             a_expr json_format_clause_opt
   16989             :             {
   16990             :                 /* formatted_expr will be set during parse-analysis. */
   16991        3728 :                 $$ = (Node *) makeJsonValueExpr((Expr *) $1, NULL,
   16992        3728 :                                                 castNode(JsonFormat, $2));
   16993             :             }
   16994             :         ;
   16995             : 
   16996             : json_format_clause:
   16997             :             FORMAT_LA JSON ENCODING name
   16998             :                 {
   16999             :                     int     encoding;
   17000             : 
   17001         100 :                     if (!pg_strcasecmp($4, "utf8"))
   17002          64 :                         encoding = JS_ENC_UTF8;
   17003          36 :                     else if (!pg_strcasecmp($4, "utf16"))
   17004          12 :                         encoding = JS_ENC_UTF16;
   17005          24 :                     else if (!pg_strcasecmp($4, "utf32"))
   17006          12 :                         encoding = JS_ENC_UTF32;
   17007             :                     else
   17008          12 :                         ereport(ERROR,
   17009             :                                 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   17010             :                                 errmsg("unrecognized JSON encoding: %s", $4));
   17011             : 
   17012          88 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
   17013             :                 }
   17014             :             | FORMAT_LA JSON
   17015             :                 {
   17016         358 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
   17017             :                 }
   17018             :         ;
   17019             : 
   17020             : json_format_clause_opt:
   17021             :             json_format_clause
   17022             :                 {
   17023         338 :                     $$ = $1;
   17024             :                 }
   17025             :             | /* EMPTY */
   17026             :                 {
   17027        4696 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   17028             :                 }
   17029             :         ;
   17030             : 
   17031             : json_quotes_clause_opt:
   17032          12 :             KEEP QUOTES ON SCALAR STRING_P      { $$ = JS_QUOTES_KEEP; }
   17033          90 :             | KEEP QUOTES                       { $$ = JS_QUOTES_KEEP; }
   17034          12 :             | OMIT QUOTES ON SCALAR STRING_P    { $$ = JS_QUOTES_OMIT; }
   17035         150 :             | OMIT QUOTES                       { $$ = JS_QUOTES_OMIT; }
   17036        1436 :             | /* EMPTY */                       { $$ = JS_QUOTES_UNSPEC; }
   17037             :         ;
   17038             : 
   17039             : json_returning_clause_opt:
   17040             :             RETURNING Typename json_format_clause_opt
   17041             :                 {
   17042        1252 :                     JsonOutput *n = makeNode(JsonOutput);
   17043             : 
   17044        1252 :                     n->typeName = $2;
   17045        1252 :                     n->returning = makeNode(JsonReturning);
   17046        1252 :                     n->returning->format = (JsonFormat *) $3;
   17047        1252 :                     $$ = (Node *) n;
   17048             :                 }
   17049        1158 :             | /* EMPTY */                           { $$ = NULL; }
   17050             :         ;
   17051             : 
   17052             : /*
   17053             :  * We must assign the only-JSON production a precedence less than IDENT in
   17054             :  * order to favor shifting over reduction when JSON is followed by VALUE_P,
   17055             :  * OBJECT_P, or SCALAR.  (ARRAY doesn't need that treatment, because it's a
   17056             :  * fully reserved word.)  Because json_predicate_type_constraint is always
   17057             :  * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
   17058             :  * production to have precedence less than WITH and WITHOUT.  UNBOUNDED isn't
   17059             :  * really related to this syntax, but it's a convenient choice because it
   17060             :  * already has a precedence less than IDENT for other reasons.
   17061             :  */
   17062             : json_predicate_type_constraint:
   17063         202 :             JSON                    %prec UNBOUNDED { $$ = JS_TYPE_ANY; }
   17064          28 :             | JSON VALUE_P                          { $$ = JS_TYPE_ANY; }
   17065          40 :             | JSON ARRAY                            { $$ = JS_TYPE_ARRAY; }
   17066          40 :             | JSON OBJECT_P                         { $$ = JS_TYPE_OBJECT; }
   17067          40 :             | JSON SCALAR                           { $$ = JS_TYPE_SCALAR; }
   17068             :         ;
   17069             : 
   17070             : /*
   17071             :  * KEYS is a noise word here.  To avoid shift/reduce conflicts, assign the
   17072             :  * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
   17073             :  * This prevents reducing them when the next token is KEYS.
   17074             :  */
   17075             : json_key_uniqueness_constraint_opt:
   17076         108 :             WITH UNIQUE KEYS                            { $$ = true; }
   17077          82 :             | WITH UNIQUE               %prec UNBOUNDED { $$ = true; }
   17078          44 :             | WITHOUT UNIQUE KEYS                       { $$ = false; }
   17079          16 :             | WITHOUT UNIQUE            %prec UNBOUNDED { $$ = false; }
   17080         708 :             | /* EMPTY */               %prec UNBOUNDED { $$ = false; }
   17081             :         ;
   17082             : 
   17083             : json_name_and_value_list:
   17084             :             json_name_and_value
   17085         288 :                 { $$ = list_make1($1); }
   17086             :             | json_name_and_value_list ',' json_name_and_value
   17087         232 :                 { $$ = lappend($1, $3); }
   17088             :         ;
   17089             : 
   17090             : json_name_and_value:
   17091             : /* Supporting this syntax seems to require major surgery
   17092             :             KEY c_expr VALUE_P json_value_expr
   17093             :                 { $$ = makeJsonKeyValue($2, $4); }
   17094             :             |
   17095             : */
   17096             :             c_expr VALUE_P json_value_expr
   17097          24 :                 { $$ = makeJsonKeyValue($1, $3); }
   17098             :             |
   17099             :             a_expr ':' json_value_expr
   17100         652 :                 { $$ = makeJsonKeyValue($1, $3); }
   17101             :         ;
   17102             : 
   17103             : /* empty means false for objects, true for arrays */
   17104             : json_object_constructor_null_clause_opt:
   17105          30 :             NULL_P ON NULL_P                    { $$ = false; }
   17106         110 :             | ABSENT ON NULL_P                  { $$ = true; }
   17107         304 :             | /* EMPTY */                       { $$ = false; }
   17108             :         ;
   17109             : 
   17110             : json_array_constructor_null_clause_opt:
   17111          54 :             NULL_P ON NULL_P                        { $$ = false; }
   17112          36 :             | ABSENT ON NULL_P                      { $$ = true; }
   17113         156 :             | /* EMPTY */                           { $$ = true; }
   17114             :         ;
   17115             : 
   17116             : json_value_expr_list:
   17117          96 :             json_value_expr                             { $$ = list_make1($1); }
   17118         126 :             | json_value_expr_list ',' json_value_expr  { $$ = lappend($1, $3);}
   17119             :         ;
   17120             : 
   17121             : json_aggregate_func:
   17122             :             JSON_OBJECTAGG '('
   17123             :                 json_name_and_value
   17124             :                 json_object_constructor_null_clause_opt
   17125             :                 json_key_uniqueness_constraint_opt
   17126             :                 json_returning_clause_opt
   17127             :             ')'
   17128             :                 {
   17129         156 :                     JsonObjectAgg *n = makeNode(JsonObjectAgg);
   17130             : 
   17131         156 :                     n->arg = (JsonKeyValue *) $3;
   17132         156 :                     n->absent_on_null = $4;
   17133         156 :                     n->unique = $5;
   17134         156 :                     n->constructor = makeNode(JsonAggConstructor);
   17135         156 :                     n->constructor->output = (JsonOutput *) $6;
   17136         156 :                     n->constructor->agg_order = NULL;
   17137         156 :                     n->constructor->location = @1;
   17138         156 :                     $$ = (Node *) n;
   17139             :                 }
   17140             :             | JSON_ARRAYAGG '('
   17141             :                 json_value_expr
   17142             :                 json_array_aggregate_order_by_clause_opt
   17143             :                 json_array_constructor_null_clause_opt
   17144             :                 json_returning_clause_opt
   17145             :             ')'
   17146             :                 {
   17147         150 :                     JsonArrayAgg *n = makeNode(JsonArrayAgg);
   17148             : 
   17149         150 :                     n->arg = (JsonValueExpr *) $3;
   17150         150 :                     n->absent_on_null = $5;
   17151         150 :                     n->constructor = makeNode(JsonAggConstructor);
   17152         150 :                     n->constructor->agg_order = $4;
   17153         150 :                     n->constructor->output = (JsonOutput *) $6;
   17154         150 :                     n->constructor->location = @1;
   17155         150 :                     $$ = (Node *) n;
   17156             :                 }
   17157             :         ;
   17158             : 
   17159             : json_array_aggregate_order_by_clause_opt:
   17160          18 :             ORDER BY sortby_list                    { $$ = $3; }
   17161         132 :             | /* EMPTY */                           { $$ = NIL; }
   17162             :         ;
   17163             : 
   17164             : /*****************************************************************************
   17165             :  *
   17166             :  *  target list for SELECT
   17167             :  *
   17168             :  *****************************************************************************/
   17169             : 
   17170      451148 : opt_target_list: target_list                        { $$ = $1; }
   17171         306 :             | /* EMPTY */                           { $$ = NIL; }
   17172             :         ;
   17173             : 
   17174             : target_list:
   17175      456838 :             target_el                               { $$ = list_make1($1); }
   17176      545118 :             | target_list ',' target_el             { $$ = lappend($1, $3); }
   17177             :         ;
   17178             : 
   17179             : target_el:  a_expr AS ColLabel
   17180             :                 {
   17181      184320 :                     $$ = makeNode(ResTarget);
   17182      184320 :                     $$->name = $3;
   17183      184320 :                     $$->indirection = NIL;
   17184      184320 :                     $$->val = (Node *) $1;
   17185      184320 :                     $$->location = @1;
   17186             :                 }
   17187             :             | a_expr BareColLabel
   17188             :                 {
   17189        3134 :                     $$ = makeNode(ResTarget);
   17190        3134 :                     $$->name = $2;
   17191        3134 :                     $$->indirection = NIL;
   17192        3134 :                     $$->val = (Node *) $1;
   17193        3134 :                     $$->location = @1;
   17194             :                 }
   17195             :             | a_expr
   17196             :                 {
   17197      765276 :                     $$ = makeNode(ResTarget);
   17198      765276 :                     $$->name = NULL;
   17199      765276 :                     $$->indirection = NIL;
   17200      765276 :                     $$->val = (Node *) $1;
   17201      765276 :                     $$->location = @1;
   17202             :                 }
   17203             :             | '*'
   17204             :                 {
   17205       49226 :                     ColumnRef  *n = makeNode(ColumnRef);
   17206             : 
   17207       49226 :                     n->fields = list_make1(makeNode(A_Star));
   17208       49226 :                     n->location = @1;
   17209             : 
   17210       49226 :                     $$ = makeNode(ResTarget);
   17211       49226 :                     $$->name = NULL;
   17212       49226 :                     $$->indirection = NIL;
   17213       49226 :                     $$->val = (Node *) n;
   17214       49226 :                     $$->location = @1;
   17215             :                 }
   17216             :         ;
   17217             : 
   17218             : 
   17219             : /*****************************************************************************
   17220             :  *
   17221             :  *  Names and constants
   17222             :  *
   17223             :  *****************************************************************************/
   17224             : 
   17225             : qualified_name_list:
   17226       13290 :             qualified_name                          { $$ = list_make1($1); }
   17227         608 :             | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
   17228             :         ;
   17229             : 
   17230             : /*
   17231             :  * The production for a qualified relation name has to exactly match the
   17232             :  * production for a qualified func_name, because in a FROM clause we cannot
   17233             :  * tell which we are parsing until we see what comes after it ('(' for a
   17234             :  * func_name, something else for a relation). Therefore we allow 'indirection'
   17235             :  * which may contain subscripts, and reject that case in the C code.
   17236             :  */
   17237             : qualified_name:
   17238             :             ColId
   17239             :                 {
   17240      376974 :                     $$ = makeRangeVar(NULL, $1, @1);
   17241             :                 }
   17242             :             | ColId indirection
   17243             :                 {
   17244      216090 :                     $$ = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   17245             :                 }
   17246             :         ;
   17247             : 
   17248             : name_list:  name
   17249       23792 :                     { $$ = list_make1(makeString($1)); }
   17250             :             | name_list ',' name
   17251       48330 :                     { $$ = lappend($1, makeString($3)); }
   17252             :         ;
   17253             : 
   17254             : 
   17255      142898 : name:       ColId                                   { $$ = $1; };
   17256             : 
   17257     1348586 : attr_name:  ColLabel                                { $$ = $1; };
   17258             : 
   17259          58 : file_name:  Sconst                                  { $$ = $1; };
   17260             : 
   17261             : /*
   17262             :  * The production for a qualified func_name has to exactly match the
   17263             :  * production for a qualified columnref, because we cannot tell which we
   17264             :  * are parsing until we see what comes after it ('(' or Sconst for a func_name,
   17265             :  * anything else for a columnref).  Therefore we allow 'indirection' which
   17266             :  * may contain subscripts, and reject that case in the C code.  (If we
   17267             :  * ever implement SQL99-like methods, such syntax may actually become legal!)
   17268             :  */
   17269             : func_name:  type_function_name
   17270      279302 :                     { $$ = list_make1(makeString($1)); }
   17271             :             | ColId indirection
   17272             :                     {
   17273      109668 :                         $$ = check_func_name(lcons(makeString($1), $2),
   17274             :                                              yyscanner);
   17275             :                     }
   17276             :         ;
   17277             : 
   17278             : 
   17279             : /*
   17280             :  * Constants
   17281             :  */
   17282             : AexprConst: Iconst
   17283             :                 {
   17284      410986 :                     $$ = makeIntConst($1, @1);
   17285             :                 }
   17286             :             | FCONST
   17287             :                 {
   17288       10636 :                     $$ = makeFloatConst($1, @1);
   17289             :                 }
   17290             :             | Sconst
   17291             :                 {
   17292      548208 :                     $$ = makeStringConst($1, @1);
   17293             :                 }
   17294             :             | BCONST
   17295             :                 {
   17296         754 :                     $$ = makeBitStringConst($1, @1);
   17297             :                 }
   17298             :             | XCONST
   17299             :                 {
   17300             :                     /* This is a bit constant per SQL99:
   17301             :                      * Without Feature F511, "BIT data type",
   17302             :                      * a <general literal> shall not be a
   17303             :                      * <bit string literal> or a <hex string literal>.
   17304             :                      */
   17305        3302 :                     $$ = makeBitStringConst($1, @1);
   17306             :                 }
   17307             :             | func_name Sconst
   17308             :                 {
   17309             :                     /* generic type 'literal' syntax */
   17310        9402 :                     TypeName   *t = makeTypeNameFromNameList($1);
   17311             : 
   17312        9402 :                     t->location = @1;
   17313        9402 :                     $$ = makeStringConstCast($2, @2, t);
   17314             :                 }
   17315             :             | func_name '(' func_arg_list opt_sort_clause ')' Sconst
   17316             :                 {
   17317             :                     /* generic syntax with a type modifier */
   17318           0 :                     TypeName   *t = makeTypeNameFromNameList($1);
   17319             :                     ListCell   *lc;
   17320             : 
   17321             :                     /*
   17322             :                      * We must use func_arg_list and opt_sort_clause in the
   17323             :                      * production to avoid reduce/reduce conflicts, but we
   17324             :                      * don't actually wish to allow NamedArgExpr in this
   17325             :                      * context, nor ORDER BY.
   17326             :                      */
   17327           0 :                     foreach(lc, $3)
   17328             :                     {
   17329           0 :                         NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
   17330             : 
   17331           0 :                         if (IsA(arg, NamedArgExpr))
   17332           0 :                             ereport(ERROR,
   17333             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17334             :                                      errmsg("type modifier cannot have parameter name"),
   17335             :                                      parser_errposition(arg->location)));
   17336             :                     }
   17337           0 :                     if ($4 != NIL)
   17338           0 :                             ereport(ERROR,
   17339             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17340             :                                      errmsg("type modifier cannot have ORDER BY"),
   17341             :                                      parser_errposition(@4)));
   17342             : 
   17343           0 :                     t->typmods = $3;
   17344           0 :                     t->location = @1;
   17345           0 :                     $$ = makeStringConstCast($6, @6, t);
   17346             :                 }
   17347             :             | ConstTypename Sconst
   17348             :                 {
   17349        2922 :                     $$ = makeStringConstCast($2, @2, $1);
   17350             :                 }
   17351             :             | ConstInterval Sconst opt_interval
   17352             :                 {
   17353        3244 :                     TypeName   *t = $1;
   17354             : 
   17355        3244 :                     t->typmods = $3;
   17356        3244 :                     $$ = makeStringConstCast($2, @2, t);
   17357             :                 }
   17358             :             | ConstInterval '(' Iconst ')' Sconst
   17359             :                 {
   17360          12 :                     TypeName   *t = $1;
   17361             : 
   17362          12 :                     t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   17363             :                                             makeIntConst($3, @3));
   17364          12 :                     $$ = makeStringConstCast($5, @5, t);
   17365             :                 }
   17366             :             | TRUE_P
   17367             :                 {
   17368       22490 :                     $$ = makeBoolAConst(true, @1);
   17369             :                 }
   17370             :             | FALSE_P
   17371             :                 {
   17372       31934 :                     $$ = makeBoolAConst(false, @1);
   17373             :                 }
   17374             :             | NULL_P
   17375             :                 {
   17376       57882 :                     $$ = makeNullAConst(@1);
   17377             :                 }
   17378             :         ;
   17379             : 
   17380      433786 : Iconst:     ICONST                                  { $$ = $1; };
   17381      613242 : Sconst:     SCONST                                  { $$ = $1; };
   17382             : 
   17383       14804 : SignedIconst: Iconst                                { $$ = $1; }
   17384           0 :             | '+' Iconst                            { $$ = + $2; }
   17385         266 :             | '-' Iconst                            { $$ = - $2; }
   17386             :         ;
   17387             : 
   17388             : /* Role specifications */
   17389             : RoleId:     RoleSpec
   17390             :                 {
   17391        1756 :                     RoleSpec   *spc = (RoleSpec *) $1;
   17392             : 
   17393        1756 :                     switch (spc->roletype)
   17394             :                     {
   17395        1746 :                         case ROLESPEC_CSTRING:
   17396        1746 :                             $$ = spc->rolename;
   17397        1746 :                             break;
   17398           4 :                         case ROLESPEC_PUBLIC:
   17399           4 :                             ereport(ERROR,
   17400             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17401             :                                      errmsg("role name \"%s\" is reserved",
   17402             :                                             "public"),
   17403             :                                      parser_errposition(@1)));
   17404             :                             break;
   17405           2 :                         case ROLESPEC_SESSION_USER:
   17406           2 :                             ereport(ERROR,
   17407             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17408             :                                      errmsg("%s cannot be used as a role name here",
   17409             :                                             "SESSION_USER"),
   17410             :                                      parser_errposition(@1)));
   17411             :                             break;
   17412           2 :                         case ROLESPEC_CURRENT_USER:
   17413           2 :                             ereport(ERROR,
   17414             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17415             :                                      errmsg("%s cannot be used as a role name here",
   17416             :                                             "CURRENT_USER"),
   17417             :                                      parser_errposition(@1)));
   17418             :                             break;
   17419           2 :                         case ROLESPEC_CURRENT_ROLE:
   17420           2 :                             ereport(ERROR,
   17421             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17422             :                                      errmsg("%s cannot be used as a role name here",
   17423             :                                             "CURRENT_ROLE"),
   17424             :                                      parser_errposition(@1)));
   17425             :                             break;
   17426             :                     }
   17427        1746 :                 }
   17428             :             ;
   17429             : 
   17430             : RoleSpec:   NonReservedWord
   17431             :                 {
   17432             :                     /*
   17433             :                      * "public" and "none" are not keywords, but they must
   17434             :                      * be treated specially here.
   17435             :                      */
   17436             :                     RoleSpec   *n;
   17437             : 
   17438       25012 :                     if (strcmp($1, "public") == 0)
   17439             :                     {
   17440       12124 :                         n = (RoleSpec *) makeRoleSpec(ROLESPEC_PUBLIC, @1);
   17441       12124 :                         n->roletype = ROLESPEC_PUBLIC;
   17442             :                     }
   17443       12888 :                     else if (strcmp($1, "none") == 0)
   17444             :                     {
   17445          26 :                         ereport(ERROR,
   17446             :                                 (errcode(ERRCODE_RESERVED_NAME),
   17447             :                                  errmsg("role name \"%s\" is reserved",
   17448             :                                         "none"),
   17449             :                                  parser_errposition(@1)));
   17450             :                     }
   17451             :                     else
   17452             :                     {
   17453       12862 :                         n = makeRoleSpec(ROLESPEC_CSTRING, @1);
   17454       12862 :                         n->rolename = pstrdup($1);
   17455             :                     }
   17456       24986 :                     $$ = n;
   17457             :                 }
   17458             :             | CURRENT_ROLE
   17459             :                 {
   17460         128 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_ROLE, @1);
   17461             :                 }
   17462             :             | CURRENT_USER
   17463             :                 {
   17464         228 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
   17465             :                 }
   17466             :             | SESSION_USER
   17467             :                 {
   17468          36 :                     $$ = makeRoleSpec(ROLESPEC_SESSION_USER, @1);
   17469             :                 }
   17470             :         ;
   17471             : 
   17472             : role_list:  RoleSpec
   17473        3098 :                 { $$ = list_make1($1); }
   17474             :             | role_list ',' RoleSpec
   17475         258 :                 { $$ = lappend($1, $3); }
   17476             :         ;
   17477             : 
   17478             : 
   17479             : /*****************************************************************************
   17480             :  *
   17481             :  * PL/pgSQL extensions
   17482             :  *
   17483             :  * You'd think a PL/pgSQL "expression" should be just an a_expr, but
   17484             :  * historically it can include just about anything that can follow SELECT.
   17485             :  * Therefore the returned struct is a SelectStmt.
   17486             :  *****************************************************************************/
   17487             : 
   17488             : PLpgSQL_Expr: opt_distinct_clause opt_target_list
   17489             :             from_clause where_clause
   17490             :             group_clause having_clause window_clause
   17491             :             opt_sort_clause opt_select_limit opt_for_locking_clause
   17492             :                 {
   17493       36766 :                     SelectStmt *n = makeNode(SelectStmt);
   17494             : 
   17495       36766 :                     n->distinctClause = $1;
   17496       36766 :                     n->targetList = $2;
   17497       36766 :                     n->fromClause = $3;
   17498       36766 :                     n->whereClause = $4;
   17499       36766 :                     n->groupClause = ($5)->list;
   17500       36766 :                     n->groupDistinct = ($5)->distinct;
   17501       36766 :                     n->havingClause = $6;
   17502       36766 :                     n->windowClause = $7;
   17503       36766 :                     n->sortClause = $8;
   17504       36766 :                     if ($9)
   17505             :                     {
   17506           4 :                         n->limitOffset = $9->limitOffset;
   17507           4 :                         n->limitCount = $9->limitCount;
   17508           4 :                         if (!n->sortClause &&
   17509           4 :                             $9->limitOption == LIMIT_OPTION_WITH_TIES)
   17510           0 :                             ereport(ERROR,
   17511             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17512             :                                      errmsg("WITH TIES cannot be specified without ORDER BY clause")));
   17513           4 :                         n->limitOption = $9->limitOption;
   17514             :                     }
   17515       36766 :                     n->lockingClause = $10;
   17516       36766 :                     $$ = (Node *) n;
   17517             :                 }
   17518             :         ;
   17519             : 
   17520             : /*
   17521             :  * PL/pgSQL Assignment statement: name opt_indirection := PLpgSQL_Expr
   17522             :  */
   17523             : 
   17524             : PLAssignStmt: plassign_target opt_indirection plassign_equals PLpgSQL_Expr
   17525             :                 {
   17526        6614 :                     PLAssignStmt *n = makeNode(PLAssignStmt);
   17527             : 
   17528        6614 :                     n->name = $1;
   17529        6614 :                     n->indirection = check_indirection($2, yyscanner);
   17530             :                     /* nnames will be filled by calling production */
   17531        6614 :                     n->val = (SelectStmt *) $4;
   17532        6614 :                     n->location = @1;
   17533        6614 :                     $$ = (Node *) n;
   17534             :                 }
   17535             :         ;
   17536             : 
   17537        6590 : plassign_target: ColId                          { $$ = $1; }
   17538          24 :             | PARAM                             { $$ = psprintf("$%d", $1); }
   17539             :         ;
   17540             : 
   17541             : plassign_equals: COLON_EQUALS
   17542             :             | '='
   17543             :         ;
   17544             : 
   17545             : 
   17546             : /*
   17547             :  * Name classification hierarchy.
   17548             :  *
   17549             :  * IDENT is the lexeme returned by the lexer for identifiers that match
   17550             :  * no known keyword.  In most cases, we can accept certain keywords as
   17551             :  * names, not only IDENTs.  We prefer to accept as many such keywords
   17552             :  * as possible to minimize the impact of "reserved words" on programmers.
   17553             :  * So, we divide names into several possible classes.  The classification
   17554             :  * is chosen in part to make keywords acceptable as names wherever possible.
   17555             :  */
   17556             : 
   17557             : /* Column identifier --- names that can be column, table, etc names.
   17558             :  */
   17559     2864680 : ColId:      IDENT                                   { $$ = $1; }
   17560       54918 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17561        4826 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17562             :         ;
   17563             : 
   17564             : /* Type/function identifier --- names that can be type or function names.
   17565             :  */
   17566      615136 : type_function_name: IDENT                           { $$ = $1; }
   17567       66232 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17568          54 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17569             :         ;
   17570             : 
   17571             : /* Any not-fully-reserved word --- these names can be, eg, role names.
   17572             :  */
   17573       65316 : NonReservedWord:    IDENT                           { $$ = $1; }
   17574       24822 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17575         176 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17576        3502 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17577             :         ;
   17578             : 
   17579             : /* Column label --- allowed labels in "AS" clauses.
   17580             :  * This presently includes *all* Postgres keywords.
   17581             :  */
   17582     1519254 : ColLabel:   IDENT                                   { $$ = $1; }
   17583       34290 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17584         272 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17585        1756 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17586        7072 :             | reserved_keyword                      { $$ = pstrdup($1); }
   17587             :         ;
   17588             : 
   17589             : /* Bare column label --- names that can be column labels without writing "AS".
   17590             :  * This classification is orthogonal to the other keyword categories.
   17591             :  */
   17592        3128 : BareColLabel:   IDENT                               { $$ = $1; }
   17593           6 :             | bare_label_keyword                    { $$ = pstrdup($1); }
   17594             :         ;
   17595             : 
   17596             : 
   17597             : /*
   17598             :  * Keyword category lists.  Generally, every keyword present in
   17599             :  * the Postgres grammar should appear in exactly one of these lists.
   17600             :  *
   17601             :  * Put a new keyword into the first list that it can go into without causing
   17602             :  * shift or reduce conflicts.  The earlier lists define "less reserved"
   17603             :  * categories of keywords.
   17604             :  *
   17605             :  * Make sure that each keyword's category in kwlist.h matches where
   17606             :  * it is listed here.  (Someday we may be able to generate these lists and
   17607             :  * kwlist.h's table from one source of truth.)
   17608             :  */
   17609             : 
   17610             : /* "Unreserved" keywords --- available for use as any kind of name.
   17611             :  */
   17612             : unreserved_keyword:
   17613             :               ABORT_P
   17614             :             | ABSENT
   17615             :             | ABSOLUTE_P
   17616             :             | ACCESS
   17617             :             | ACTION
   17618             :             | ADD_P
   17619             :             | ADMIN
   17620             :             | AFTER
   17621             :             | AGGREGATE
   17622             :             | ALSO
   17623             :             | ALTER
   17624             :             | ALWAYS
   17625             :             | ASENSITIVE
   17626             :             | ASSERTION
   17627             :             | ASSIGNMENT
   17628             :             | AT
   17629             :             | ATOMIC
   17630             :             | ATTACH
   17631             :             | ATTRIBUTE
   17632             :             | BACKWARD
   17633             :             | BEFORE
   17634             :             | BEGIN_P
   17635             :             | BREADTH
   17636             :             | BY
   17637             :             | CACHE
   17638             :             | CALL
   17639             :             | CALLED
   17640             :             | CASCADE
   17641             :             | CASCADED
   17642             :             | CATALOG_P
   17643             :             | CHAIN
   17644             :             | CHARACTERISTICS
   17645             :             | CHECKPOINT
   17646             :             | CLASS
   17647             :             | CLOSE
   17648             :             | CLUSTER
   17649             :             | COLUMNS
   17650             :             | COMMENT
   17651             :             | COMMENTS
   17652             :             | COMMIT
   17653             :             | COMMITTED
   17654             :             | COMPRESSION
   17655             :             | CONDITIONAL
   17656             :             | CONFIGURATION
   17657             :             | CONFLICT
   17658             :             | CONNECTION
   17659             :             | CONSTRAINTS
   17660             :             | CONTENT_P
   17661             :             | CONTINUE_P
   17662             :             | CONVERSION_P
   17663             :             | COPY
   17664             :             | COST
   17665             :             | CSV
   17666             :             | CUBE
   17667             :             | CURRENT_P
   17668             :             | CURSOR
   17669             :             | CYCLE
   17670             :             | DATA_P
   17671             :             | DATABASE
   17672             :             | DAY_P
   17673             :             | DEALLOCATE
   17674             :             | DECLARE
   17675             :             | DEFAULTS
   17676             :             | DEFERRED
   17677             :             | DEFINER
   17678             :             | DELETE_P
   17679             :             | DELIMITER
   17680             :             | DELIMITERS
   17681             :             | DEPENDS
   17682             :             | DEPTH
   17683             :             | DETACH
   17684             :             | DICTIONARY
   17685             :             | DISABLE_P
   17686             :             | DISCARD
   17687             :             | DOCUMENT_P
   17688             :             | DOMAIN_P
   17689             :             | DOUBLE_P
   17690             :             | DROP
   17691             :             | EACH
   17692             :             | EMPTY_P
   17693             :             | ENABLE_P
   17694             :             | ENCODING
   17695             :             | ENCRYPTED
   17696             :             | ENUM_P
   17697             :             | ERROR_P
   17698             :             | ESCAPE
   17699             :             | EVENT
   17700             :             | EXCLUDE
   17701             :             | EXCLUDING
   17702             :             | EXCLUSIVE
   17703             :             | EXECUTE
   17704             :             | EXPLAIN
   17705             :             | EXPRESSION
   17706             :             | EXTENSION
   17707             :             | EXTERNAL
   17708             :             | FAMILY
   17709             :             | FILTER
   17710             :             | FINALIZE
   17711             :             | FIRST_P
   17712             :             | FOLLOWING
   17713             :             | FORCE
   17714             :             | FORMAT
   17715             :             | FORWARD
   17716             :             | FUNCTION
   17717             :             | FUNCTIONS
   17718             :             | GENERATED
   17719             :             | GLOBAL
   17720             :             | GRANTED
   17721             :             | GROUPS
   17722             :             | HANDLER
   17723             :             | HEADER_P
   17724             :             | HOLD
   17725             :             | HOUR_P
   17726             :             | IDENTITY_P
   17727             :             | IF_P
   17728             :             | IMMEDIATE
   17729             :             | IMMUTABLE
   17730             :             | IMPLICIT_P
   17731             :             | IMPORT_P
   17732             :             | INCLUDE
   17733             :             | INCLUDING
   17734             :             | INCREMENT
   17735             :             | INDENT
   17736             :             | INDEX
   17737             :             | INDEXES
   17738             :             | INHERIT
   17739             :             | INHERITS
   17740             :             | INLINE_P
   17741             :             | INPUT_P
   17742             :             | INSENSITIVE
   17743             :             | INSERT
   17744             :             | INSTEAD
   17745             :             | INVOKER
   17746             :             | ISOLATION
   17747             :             | KEEP
   17748             :             | KEY
   17749             :             | KEYS
   17750             :             | LABEL
   17751             :             | LANGUAGE
   17752             :             | LARGE_P
   17753             :             | LAST_P
   17754             :             | LEAKPROOF
   17755             :             | LEVEL
   17756             :             | LISTEN
   17757             :             | LOAD
   17758             :             | LOCAL
   17759             :             | LOCATION
   17760             :             | LOCK_P
   17761             :             | LOCKED
   17762             :             | LOGGED
   17763             :             | MAPPING
   17764             :             | MATCH
   17765             :             | MATCHED
   17766             :             | MATERIALIZED
   17767             :             | MAXVALUE
   17768             :             | MERGE
   17769             :             | METHOD
   17770             :             | MINUTE_P
   17771             :             | MINVALUE
   17772             :             | MODE
   17773             :             | MONTH_P
   17774             :             | MOVE
   17775             :             | NAME_P
   17776             :             | NAMES
   17777             :             | NESTED
   17778             :             | NEW
   17779             :             | NEXT
   17780             :             | NFC
   17781             :             | NFD
   17782             :             | NFKC
   17783             :             | NFKD
   17784             :             | NO
   17785             :             | NORMALIZED
   17786             :             | NOTHING
   17787             :             | NOTIFY
   17788             :             | NOWAIT
   17789             :             | NULLS_P
   17790             :             | OBJECT_P
   17791             :             | OF
   17792             :             | OFF
   17793             :             | OIDS
   17794             :             | OLD
   17795             :             | OMIT
   17796             :             | OPERATOR
   17797             :             | OPTION
   17798             :             | OPTIONS
   17799             :             | ORDINALITY
   17800             :             | OTHERS
   17801             :             | OVER
   17802             :             | OVERRIDING
   17803             :             | OWNED
   17804             :             | OWNER
   17805             :             | PARALLEL
   17806             :             | PARAMETER
   17807             :             | PARSER
   17808             :             | PARTIAL
   17809             :             | PARTITION
   17810             :             | PARTITIONS
   17811             :             | PASSING
   17812             :             | PASSWORD
   17813             :             | PATH
   17814             :             | PERIOD
   17815             :             | PLAN
   17816             :             | PLANS
   17817             :             | POLICY
   17818             :             | PRECEDING
   17819             :             | PREPARE
   17820             :             | PREPARED
   17821             :             | PRESERVE
   17822             :             | PRIOR
   17823             :             | PRIVILEGES
   17824             :             | PROCEDURAL
   17825             :             | PROCEDURE
   17826             :             | PROCEDURES
   17827             :             | PROGRAM
   17828             :             | PUBLICATION
   17829             :             | QUOTE
   17830             :             | QUOTES
   17831             :             | RANGE
   17832             :             | READ
   17833             :             | REASSIGN
   17834             :             | RECHECK
   17835             :             | RECURSIVE
   17836             :             | REF_P
   17837             :             | REFERENCING
   17838             :             | REFRESH
   17839             :             | REINDEX
   17840             :             | RELATIVE_P
   17841             :             | RELEASE
   17842             :             | RENAME
   17843             :             | REPEATABLE
   17844             :             | REPLACE
   17845             :             | REPLICA
   17846             :             | RESET
   17847             :             | RESTART
   17848             :             | RESTRICT
   17849             :             | RETURN
   17850             :             | RETURNS
   17851             :             | REVOKE
   17852             :             | ROLE
   17853             :             | ROLLBACK
   17854             :             | ROLLUP
   17855             :             | ROUTINE
   17856             :             | ROUTINES
   17857             :             | ROWS
   17858             :             | RULE
   17859             :             | SAVEPOINT
   17860             :             | SCALAR
   17861             :             | SCHEMA
   17862             :             | SCHEMAS
   17863             :             | SCROLL
   17864             :             | SEARCH
   17865             :             | SECOND_P
   17866             :             | SECURITY
   17867             :             | SEQUENCE
   17868             :             | SEQUENCES
   17869             :             | SERIALIZABLE
   17870             :             | SERVER
   17871             :             | SESSION
   17872             :             | SET
   17873             :             | SETS
   17874             :             | SHARE
   17875             :             | SHOW
   17876             :             | SIMPLE
   17877             :             | SKIP
   17878             :             | SNAPSHOT
   17879             :             | SOURCE
   17880             :             | SPLIT
   17881             :             | SQL_P
   17882             :             | STABLE
   17883             :             | STANDALONE_P
   17884             :             | START
   17885             :             | STATEMENT
   17886             :             | STATISTICS
   17887             :             | STDIN
   17888             :             | STDOUT
   17889             :             | STORAGE
   17890             :             | STORED
   17891             :             | STRICT_P
   17892             :             | STRING_P
   17893             :             | STRIP_P
   17894             :             | SUBSCRIPTION
   17895             :             | SUPPORT
   17896             :             | SYSID
   17897             :             | SYSTEM_P
   17898             :             | TABLES
   17899             :             | TABLESPACE
   17900             :             | TARGET
   17901             :             | TEMP
   17902             :             | TEMPLATE
   17903             :             | TEMPORARY
   17904             :             | TEXT_P
   17905             :             | TIES
   17906             :             | TRANSACTION
   17907             :             | TRANSFORM
   17908             :             | TRIGGER
   17909             :             | TRUNCATE
   17910             :             | TRUSTED
   17911             :             | TYPE_P
   17912             :             | TYPES_P
   17913             :             | UESCAPE
   17914             :             | UNBOUNDED
   17915             :             | UNCOMMITTED
   17916             :             | UNCONDITIONAL
   17917             :             | UNENCRYPTED
   17918             :             | UNKNOWN
   17919             :             | UNLISTEN
   17920             :             | UNLOGGED
   17921             :             | UNTIL
   17922             :             | UPDATE
   17923             :             | VACUUM
   17924             :             | VALID
   17925             :             | VALIDATE
   17926             :             | VALIDATOR
   17927             :             | VALUE_P
   17928             :             | VARYING
   17929             :             | VERSION_P
   17930             :             | VIEW
   17931             :             | VIEWS
   17932             :             | VOLATILE
   17933             :             | WHITESPACE_P
   17934             :             | WITHIN
   17935             :             | WITHOUT
   17936             :             | WORK
   17937             :             | WRAPPER
   17938             :             | WRITE
   17939             :             | XML_P
   17940             :             | YEAR_P
   17941             :             | YES_P
   17942             :             | ZONE
   17943             :         ;
   17944             : 
   17945             : /* Column identifier --- keywords that can be column, table, etc names.
   17946             :  *
   17947             :  * Many of these keywords will in fact be recognized as type or function
   17948             :  * names too; but they have special productions for the purpose, and so
   17949             :  * can't be treated as "generic" type or function names.
   17950             :  *
   17951             :  * The type names appearing here are not usable as function names
   17952             :  * because they can be followed by '(' in typename productions, which
   17953             :  * looks too much like a function call for an LR(1) parser.
   17954             :  */
   17955             : col_name_keyword:
   17956             :               BETWEEN
   17957             :             | BIGINT
   17958             :             | BIT
   17959             :             | BOOLEAN_P
   17960             :             | CHAR_P
   17961             :             | CHARACTER
   17962             :             | COALESCE
   17963             :             | DEC
   17964             :             | DECIMAL_P
   17965             :             | EXISTS
   17966             :             | EXTRACT
   17967             :             | FLOAT_P
   17968             :             | GREATEST
   17969             :             | GROUPING
   17970             :             | INOUT
   17971             :             | INT_P
   17972             :             | INTEGER
   17973             :             | INTERVAL
   17974             :             | JSON
   17975             :             | JSON_ARRAY
   17976             :             | JSON_ARRAYAGG
   17977             :             | JSON_EXISTS
   17978             :             | JSON_OBJECT
   17979             :             | JSON_OBJECTAGG
   17980             :             | JSON_QUERY
   17981             :             | JSON_SCALAR
   17982             :             | JSON_SERIALIZE
   17983             :             | JSON_TABLE
   17984             :             | JSON_VALUE
   17985             :             | LEAST
   17986             :             | MERGE_ACTION
   17987             :             | NATIONAL
   17988             :             | NCHAR
   17989             :             | NONE
   17990             :             | NORMALIZE
   17991             :             | NULLIF
   17992             :             | NUMERIC
   17993             :             | OUT_P
   17994             :             | OVERLAY
   17995             :             | POSITION
   17996             :             | PRECISION
   17997             :             | REAL
   17998             :             | ROW
   17999             :             | SETOF
   18000             :             | SMALLINT
   18001             :             | SUBSTRING
   18002             :             | TIME
   18003             :             | TIMESTAMP
   18004             :             | TREAT
   18005             :             | TRIM
   18006             :             | VALUES
   18007             :             | VARCHAR
   18008             :             | XMLATTRIBUTES
   18009             :             | XMLCONCAT
   18010             :             | XMLELEMENT
   18011             :             | XMLEXISTS
   18012             :             | XMLFOREST
   18013             :             | XMLNAMESPACES
   18014             :             | XMLPARSE
   18015             :             | XMLPI
   18016             :             | XMLROOT
   18017             :             | XMLSERIALIZE
   18018             :             | XMLTABLE
   18019             :         ;
   18020             : 
   18021             : /* Type/function identifier --- keywords that can be type or function names.
   18022             :  *
   18023             :  * Most of these are keywords that are used as operators in expressions;
   18024             :  * in general such keywords can't be column names because they would be
   18025             :  * ambiguous with variables, but they are unambiguous as function identifiers.
   18026             :  *
   18027             :  * Do not include POSITION, SUBSTRING, etc here since they have explicit
   18028             :  * productions in a_expr to support the goofy SQL9x argument syntax.
   18029             :  * - thomas 2000-11-28
   18030             :  */
   18031             : type_func_name_keyword:
   18032             :               AUTHORIZATION
   18033             :             | BINARY
   18034             :             | COLLATION
   18035             :             | CONCURRENTLY
   18036             :             | CROSS
   18037             :             | CURRENT_SCHEMA
   18038             :             | FREEZE
   18039             :             | FULL
   18040             :             | ILIKE
   18041             :             | INNER_P
   18042             :             | IS
   18043             :             | ISNULL
   18044             :             | JOIN
   18045             :             | LEFT
   18046             :             | LIKE
   18047             :             | NATURAL
   18048             :             | NOTNULL
   18049             :             | OUTER_P
   18050             :             | OVERLAPS
   18051             :             | RIGHT
   18052             :             | SIMILAR
   18053             :             | TABLESAMPLE
   18054             :             | VERBOSE
   18055             :         ;
   18056             : 
   18057             : /* Reserved keyword --- these keywords are usable only as a ColLabel.
   18058             :  *
   18059             :  * Keywords appear here if they could not be distinguished from variable,
   18060             :  * type, or function names in some contexts.  Don't put things here unless
   18061             :  * forced to.
   18062             :  */
   18063             : reserved_keyword:
   18064             :               ALL
   18065             :             | ANALYSE
   18066             :             | ANALYZE
   18067             :             | AND
   18068             :             | ANY
   18069             :             | ARRAY
   18070             :             | AS
   18071             :             | ASC
   18072             :             | ASYMMETRIC
   18073             :             | BOTH
   18074             :             | CASE
   18075             :             | CAST
   18076             :             | CHECK
   18077             :             | COLLATE
   18078             :             | COLUMN
   18079             :             | CONSTRAINT
   18080             :             | CREATE
   18081             :             | CURRENT_CATALOG
   18082             :             | CURRENT_DATE
   18083             :             | CURRENT_ROLE
   18084             :             | CURRENT_TIME
   18085             :             | CURRENT_TIMESTAMP
   18086             :             | CURRENT_USER
   18087             :             | DEFAULT
   18088             :             | DEFERRABLE
   18089             :             | DESC
   18090             :             | DISTINCT
   18091             :             | DO
   18092             :             | ELSE
   18093             :             | END_P
   18094             :             | EXCEPT
   18095             :             | FALSE_P
   18096             :             | FETCH
   18097             :             | FOR
   18098             :             | FOREIGN
   18099             :             | FROM
   18100             :             | GRANT
   18101             :             | GROUP_P
   18102             :             | HAVING
   18103             :             | IN_P
   18104             :             | INITIALLY
   18105             :             | INTERSECT
   18106             :             | INTO
   18107             :             | LATERAL_P
   18108             :             | LEADING
   18109             :             | LIMIT
   18110             :             | LOCALTIME
   18111             :             | LOCALTIMESTAMP
   18112             :             | NOT
   18113             :             | NULL_P
   18114             :             | OFFSET
   18115             :             | ON
   18116             :             | ONLY
   18117             :             | OR
   18118             :             | ORDER
   18119             :             | PLACING
   18120             :             | PRIMARY
   18121             :             | REFERENCES
   18122             :             | RETURNING
   18123             :             | SELECT
   18124             :             | SESSION_USER
   18125             :             | SOME
   18126             :             | SYMMETRIC
   18127             :             | SYSTEM_USER
   18128             :             | TABLE
   18129             :             | THEN
   18130             :             | TO
   18131             :             | TRAILING
   18132             :             | TRUE_P
   18133             :             | UNION
   18134             :             | UNIQUE
   18135             :             | USER
   18136             :             | USING
   18137             :             | VARIADIC
   18138             :             | WHEN
   18139             :             | WHERE
   18140             :             | WINDOW
   18141             :             | WITH
   18142             :         ;
   18143             : 
   18144             : /*
   18145             :  * While all keywords can be used as column labels when preceded by AS,
   18146             :  * not all of them can be used as a "bare" column label without AS.
   18147             :  * Those that can be used as a bare label must be listed here,
   18148             :  * in addition to appearing in one of the category lists above.
   18149             :  *
   18150             :  * Always add a new keyword to this list if possible.  Mark it BARE_LABEL
   18151             :  * in kwlist.h if it is included here, or AS_LABEL if it is not.
   18152             :  */
   18153             : bare_label_keyword:
   18154             :               ABORT_P
   18155             :             | ABSENT
   18156             :             | ABSOLUTE_P
   18157             :             | ACCESS
   18158             :             | ACTION
   18159             :             | ADD_P
   18160             :             | ADMIN
   18161             :             | AFTER
   18162             :             | AGGREGATE
   18163             :             | ALL
   18164             :             | ALSO
   18165             :             | ALTER
   18166             :             | ALWAYS
   18167             :             | ANALYSE
   18168             :             | ANALYZE
   18169             :             | AND
   18170             :             | ANY
   18171             :             | ASC
   18172             :             | ASENSITIVE
   18173             :             | ASSERTION
   18174             :             | ASSIGNMENT
   18175             :             | ASYMMETRIC
   18176             :             | AT
   18177             :             | ATOMIC
   18178             :             | ATTACH
   18179             :             | ATTRIBUTE
   18180             :             | AUTHORIZATION
   18181             :             | BACKWARD
   18182             :             | BEFORE
   18183             :             | BEGIN_P
   18184             :             | BETWEEN
   18185             :             | BIGINT
   18186             :             | BINARY
   18187             :             | BIT
   18188             :             | BOOLEAN_P
   18189             :             | BOTH
   18190             :             | BREADTH
   18191             :             | BY
   18192             :             | CACHE
   18193             :             | CALL
   18194             :             | CALLED
   18195             :             | CASCADE
   18196             :             | CASCADED
   18197             :             | CASE
   18198             :             | CAST
   18199             :             | CATALOG_P
   18200             :             | CHAIN
   18201             :             | CHARACTERISTICS
   18202             :             | CHECK
   18203             :             | CHECKPOINT
   18204             :             | CLASS
   18205             :             | CLOSE
   18206             :             | CLUSTER
   18207             :             | COALESCE
   18208             :             | COLLATE
   18209             :             | COLLATION
   18210             :             | COLUMN
   18211             :             | COLUMNS
   18212             :             | COMMENT
   18213             :             | COMMENTS
   18214             :             | COMMIT
   18215             :             | COMMITTED
   18216             :             | COMPRESSION
   18217             :             | CONCURRENTLY
   18218             :             | CONDITIONAL
   18219             :             | CONFIGURATION
   18220             :             | CONFLICT
   18221             :             | CONNECTION
   18222             :             | CONSTRAINT
   18223             :             | CONSTRAINTS
   18224             :             | CONTENT_P
   18225             :             | CONTINUE_P
   18226             :             | CONVERSION_P
   18227             :             | COPY
   18228             :             | COST
   18229             :             | CROSS
   18230             :             | CSV
   18231             :             | CUBE
   18232             :             | CURRENT_P
   18233             :             | CURRENT_CATALOG
   18234             :             | CURRENT_DATE
   18235             :             | CURRENT_ROLE
   18236             :             | CURRENT_SCHEMA
   18237             :             | CURRENT_TIME
   18238             :             | CURRENT_TIMESTAMP
   18239             :             | CURRENT_USER
   18240             :             | CURSOR
   18241             :             | CYCLE
   18242             :             | DATA_P
   18243             :             | DATABASE
   18244             :             | DEALLOCATE
   18245             :             | DEC
   18246             :             | DECIMAL_P
   18247             :             | DECLARE
   18248             :             | DEFAULT
   18249             :             | DEFAULTS
   18250             :             | DEFERRABLE
   18251             :             | DEFERRED
   18252             :             | DEFINER
   18253             :             | DELETE_P
   18254             :             | DELIMITER
   18255             :             | DELIMITERS
   18256             :             | DEPENDS
   18257             :             | DEPTH
   18258             :             | DESC
   18259             :             | DETACH
   18260             :             | DICTIONARY
   18261             :             | DISABLE_P
   18262             :             | DISCARD
   18263             :             | DISTINCT
   18264             :             | DO
   18265             :             | DOCUMENT_P
   18266             :             | DOMAIN_P
   18267             :             | DOUBLE_P
   18268             :             | DROP
   18269             :             | EACH
   18270             :             | ELSE
   18271             :             | EMPTY_P
   18272             :             | ENABLE_P
   18273             :             | ENCODING
   18274             :             | ENCRYPTED
   18275             :             | END_P
   18276             :             | ENUM_P
   18277             :             | ERROR_P
   18278             :             | ESCAPE
   18279             :             | EVENT
   18280             :             | EXCLUDE
   18281             :             | EXCLUDING
   18282             :             | EXCLUSIVE
   18283             :             | EXECUTE
   18284             :             | EXISTS
   18285             :             | EXPLAIN
   18286             :             | EXPRESSION
   18287             :             | EXTENSION
   18288             :             | EXTERNAL
   18289             :             | EXTRACT
   18290             :             | FALSE_P
   18291             :             | FAMILY
   18292             :             | FINALIZE
   18293             :             | FIRST_P
   18294             :             | FLOAT_P
   18295             :             | FOLLOWING
   18296             :             | FORCE
   18297             :             | FOREIGN
   18298             :             | FORMAT
   18299             :             | FORWARD
   18300             :             | FREEZE
   18301             :             | FULL
   18302             :             | FUNCTION
   18303             :             | FUNCTIONS
   18304             :             | GENERATED
   18305             :             | GLOBAL
   18306             :             | GRANTED
   18307             :             | GREATEST
   18308             :             | GROUPING
   18309             :             | GROUPS
   18310             :             | HANDLER
   18311             :             | HEADER_P
   18312             :             | HOLD
   18313             :             | IDENTITY_P
   18314             :             | IF_P
   18315             :             | ILIKE
   18316             :             | IMMEDIATE
   18317             :             | IMMUTABLE
   18318             :             | IMPLICIT_P
   18319             :             | IMPORT_P
   18320             :             | IN_P
   18321             :             | INCLUDE
   18322             :             | INCLUDING
   18323             :             | INCREMENT
   18324             :             | INDENT
   18325             :             | INDEX
   18326             :             | INDEXES
   18327             :             | INHERIT
   18328             :             | INHERITS
   18329             :             | INITIALLY
   18330             :             | INLINE_P
   18331             :             | INNER_P
   18332             :             | INOUT
   18333             :             | INPUT_P
   18334             :             | INSENSITIVE
   18335             :             | INSERT
   18336             :             | INSTEAD
   18337             :             | INT_P
   18338             :             | INTEGER
   18339             :             | INTERVAL
   18340             :             | INVOKER
   18341             :             | IS
   18342             :             | ISOLATION
   18343             :             | JOIN
   18344             :             | JSON
   18345             :             | JSON_ARRAY
   18346             :             | JSON_ARRAYAGG
   18347             :             | JSON_EXISTS
   18348             :             | JSON_OBJECT
   18349             :             | JSON_OBJECTAGG
   18350             :             | JSON_QUERY
   18351             :             | JSON_SCALAR
   18352             :             | JSON_SERIALIZE
   18353             :             | JSON_TABLE
   18354             :             | JSON_VALUE
   18355             :             | KEEP
   18356             :             | KEY
   18357             :             | KEYS
   18358             :             | LABEL
   18359             :             | LANGUAGE
   18360             :             | LARGE_P
   18361             :             | LAST_P
   18362             :             | LATERAL_P
   18363             :             | LEADING
   18364             :             | LEAKPROOF
   18365             :             | LEAST
   18366             :             | LEFT
   18367             :             | LEVEL
   18368             :             | LIKE
   18369             :             | LISTEN
   18370             :             | LOAD
   18371             :             | LOCAL
   18372             :             | LOCALTIME
   18373             :             | LOCALTIMESTAMP
   18374             :             | LOCATION
   18375             :             | LOCK_P
   18376             :             | LOCKED
   18377             :             | LOGGED
   18378             :             | MAPPING
   18379             :             | MATCH
   18380             :             | MATCHED
   18381             :             | MATERIALIZED
   18382             :             | MAXVALUE
   18383             :             | MERGE
   18384             :             | MERGE_ACTION
   18385             :             | METHOD
   18386             :             | MINVALUE
   18387             :             | MODE
   18388             :             | MOVE
   18389             :             | NAME_P
   18390             :             | NAMES
   18391             :             | NATIONAL
   18392             :             | NATURAL
   18393             :             | NCHAR
   18394             :             | NESTED
   18395             :             | NEW
   18396             :             | NEXT
   18397             :             | NFC
   18398             :             | NFD
   18399             :             | NFKC
   18400             :             | NFKD
   18401             :             | NO
   18402             :             | NONE
   18403             :             | NORMALIZE
   18404             :             | NORMALIZED
   18405             :             | NOT
   18406             :             | NOTHING
   18407             :             | NOTIFY
   18408             :             | NOWAIT
   18409             :             | NULL_P
   18410             :             | NULLIF
   18411             :             | NULLS_P
   18412             :             | NUMERIC
   18413             :             | OBJECT_P
   18414             :             | OF
   18415             :             | OFF
   18416             :             | OIDS
   18417             :             | OLD
   18418             :             | OMIT
   18419             :             | ONLY
   18420             :             | OPERATOR
   18421             :             | OPTION
   18422             :             | OPTIONS
   18423             :             | OR
   18424             :             | ORDINALITY
   18425             :             | OTHERS
   18426             :             | OUT_P
   18427             :             | OUTER_P
   18428             :             | OVERLAY
   18429             :             | OVERRIDING
   18430             :             | OWNED
   18431             :             | OWNER
   18432             :             | PARALLEL
   18433             :             | PARAMETER
   18434             :             | PARSER
   18435             :             | PARTIAL
   18436             :             | PARTITION
   18437             :             | PARTITIONS
   18438             :             | PASSING
   18439             :             | PASSWORD
   18440             :             | PATH
   18441             :             | PERIOD
   18442             :             | PLACING
   18443             :             | PLAN
   18444             :             | PLANS
   18445             :             | POLICY
   18446             :             | POSITION
   18447             :             | PRECEDING
   18448             :             | PREPARE
   18449             :             | PREPARED
   18450             :             | PRESERVE
   18451             :             | PRIMARY
   18452             :             | PRIOR
   18453             :             | PRIVILEGES
   18454             :             | PROCEDURAL
   18455             :             | PROCEDURE
   18456             :             | PROCEDURES
   18457             :             | PROGRAM
   18458             :             | PUBLICATION
   18459             :             | QUOTE
   18460             :             | QUOTES
   18461             :             | RANGE
   18462             :             | READ
   18463             :             | REAL
   18464             :             | REASSIGN
   18465             :             | RECHECK
   18466             :             | RECURSIVE
   18467             :             | REF_P
   18468             :             | REFERENCES
   18469             :             | REFERENCING
   18470             :             | REFRESH
   18471             :             | REINDEX
   18472             :             | RELATIVE_P
   18473             :             | RELEASE
   18474             :             | RENAME
   18475             :             | REPEATABLE
   18476             :             | REPLACE
   18477             :             | REPLICA
   18478             :             | RESET
   18479             :             | RESTART
   18480             :             | RESTRICT
   18481             :             | RETURN
   18482             :             | RETURNS
   18483             :             | REVOKE
   18484             :             | RIGHT
   18485             :             | ROLE
   18486             :             | ROLLBACK
   18487             :             | ROLLUP
   18488             :             | ROUTINE
   18489             :             | ROUTINES
   18490             :             | ROW
   18491             :             | ROWS
   18492             :             | RULE
   18493             :             | SAVEPOINT
   18494             :             | SCALAR
   18495             :             | SCHEMA
   18496             :             | SCHEMAS
   18497             :             | SCROLL
   18498             :             | SEARCH
   18499             :             | SECURITY
   18500             :             | SELECT
   18501             :             | SEQUENCE
   18502             :             | SEQUENCES
   18503             :             | SERIALIZABLE
   18504             :             | SERVER
   18505             :             | SESSION
   18506             :             | SESSION_USER
   18507             :             | SET
   18508             :             | SETOF
   18509             :             | SETS
   18510             :             | SHARE
   18511             :             | SHOW
   18512             :             | SIMILAR
   18513             :             | SIMPLE
   18514             :             | SKIP
   18515             :             | SMALLINT
   18516             :             | SNAPSHOT
   18517             :             | SOME
   18518             :             | SOURCE
   18519             :             | SPLIT
   18520             :             | SQL_P
   18521             :             | STABLE
   18522             :             | STANDALONE_P
   18523             :             | START
   18524             :             | STATEMENT
   18525             :             | STATISTICS
   18526             :             | STDIN
   18527             :             | STDOUT
   18528             :             | STORAGE
   18529             :             | STORED
   18530             :             | STRICT_P
   18531             :             | STRING_P
   18532             :             | STRIP_P
   18533             :             | SUBSCRIPTION
   18534             :             | SUBSTRING
   18535             :             | SUPPORT
   18536             :             | SYMMETRIC
   18537             :             | SYSID
   18538             :             | SYSTEM_P
   18539             :             | SYSTEM_USER
   18540             :             | TABLE
   18541             :             | TABLES
   18542             :             | TABLESAMPLE
   18543             :             | TABLESPACE
   18544             :             | TARGET
   18545             :             | TEMP
   18546             :             | TEMPLATE
   18547             :             | TEMPORARY
   18548             :             | TEXT_P
   18549             :             | THEN
   18550             :             | TIES
   18551             :             | TIME
   18552             :             | TIMESTAMP
   18553             :             | TRAILING
   18554             :             | TRANSACTION
   18555             :             | TRANSFORM
   18556             :             | TREAT
   18557             :             | TRIGGER
   18558             :             | TRIM
   18559             :             | TRUE_P
   18560             :             | TRUNCATE
   18561             :             | TRUSTED
   18562             :             | TYPE_P
   18563             :             | TYPES_P
   18564             :             | UESCAPE
   18565             :             | UNBOUNDED
   18566             :             | UNCOMMITTED
   18567             :             | UNCONDITIONAL
   18568             :             | UNENCRYPTED
   18569             :             | UNIQUE
   18570             :             | UNKNOWN
   18571             :             | UNLISTEN
   18572             :             | UNLOGGED
   18573             :             | UNTIL
   18574             :             | UPDATE
   18575             :             | USER
   18576             :             | USING
   18577             :             | VACUUM
   18578             :             | VALID
   18579             :             | VALIDATE
   18580             :             | VALIDATOR
   18581             :             | VALUE_P
   18582             :             | VALUES
   18583             :             | VARCHAR
   18584             :             | VARIADIC
   18585             :             | VERBOSE
   18586             :             | VERSION_P
   18587             :             | VIEW
   18588             :             | VIEWS
   18589             :             | VOLATILE
   18590             :             | WHEN
   18591             :             | WHITESPACE_P
   18592             :             | WORK
   18593             :             | WRAPPER
   18594             :             | WRITE
   18595             :             | XML_P
   18596             :             | XMLATTRIBUTES
   18597             :             | XMLCONCAT
   18598             :             | XMLELEMENT
   18599             :             | XMLEXISTS
   18600             :             | XMLFOREST
   18601             :             | XMLNAMESPACES
   18602             :             | XMLPARSE
   18603             :             | XMLPI
   18604             :             | XMLROOT
   18605             :             | XMLSERIALIZE
   18606             :             | XMLTABLE
   18607             :             | YES_P
   18608             :             | ZONE
   18609             :         ;
   18610             : 
   18611             : %%
   18612             : 
   18613             : /*
   18614             :  * The signature of this function is required by bison.  However, we
   18615             :  * ignore the passed yylloc and instead use the last token position
   18616             :  * available from the scanner.
   18617             :  */
   18618             : static void
   18619         680 : base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
   18620             : {
   18621         680 :     parser_yyerror(msg);
   18622             : }
   18623             : 
   18624             : static RawStmt *
   18625      761168 : makeRawStmt(Node *stmt, int stmt_location)
   18626             : {
   18627      761168 :     RawStmt    *rs = makeNode(RawStmt);
   18628             : 
   18629      761168 :     rs->stmt = stmt;
   18630      761168 :     rs->stmt_location = stmt_location;
   18631      761168 :     rs->stmt_len = 0;            /* might get changed later */
   18632      761168 :     return rs;
   18633             : }
   18634             : 
   18635             : /* Adjust a RawStmt to reflect that it doesn't run to the end of the string */
   18636             : static void
   18637      549066 : updateRawStmtEnd(RawStmt *rs, int end_location)
   18638             : {
   18639             :     /*
   18640             :      * If we already set the length, don't change it.  This is for situations
   18641             :      * like "select foo ;; select bar" where the same statement will be last
   18642             :      * in the string for more than one semicolon.
   18643             :      */
   18644      549066 :     if (rs->stmt_len > 0)
   18645          10 :         return;
   18646             : 
   18647             :     /* OK, update length of RawStmt */
   18648      549056 :     rs->stmt_len = end_location - rs->stmt_location;
   18649             : }
   18650             : 
   18651             : static Node *
   18652     1510936 : makeColumnRef(char *colname, List *indirection,
   18653             :               int location, core_yyscan_t yyscanner)
   18654             : {
   18655             :     /*
   18656             :      * Generate a ColumnRef node, with an A_Indirection node added if there
   18657             :      * is any subscripting in the specified indirection list.  However,
   18658             :      * any field selection at the start of the indirection list must be
   18659             :      * transposed into the "fields" part of the ColumnRef node.
   18660             :      */
   18661     1510936 :     ColumnRef  *c = makeNode(ColumnRef);
   18662     1510936 :     int         nfields = 0;
   18663             :     ListCell   *l;
   18664             : 
   18665     1510936 :     c->location = location;
   18666     2434522 :     foreach(l, indirection)
   18667             :     {
   18668      932450 :         if (IsA(lfirst(l), A_Indices))
   18669             :         {
   18670        8864 :             A_Indirection *i = makeNode(A_Indirection);
   18671             : 
   18672        8864 :             if (nfields == 0)
   18673             :             {
   18674             :                 /* easy case - all indirection goes to A_Indirection */
   18675        6392 :                 c->fields = list_make1(makeString(colname));
   18676        6392 :                 i->indirection = check_indirection(indirection, yyscanner);
   18677             :             }
   18678             :             else
   18679             :             {
   18680             :                 /* got to split the list in two */
   18681        2472 :                 i->indirection = check_indirection(list_copy_tail(indirection,
   18682             :                                                                   nfields),
   18683             :                                                    yyscanner);
   18684        2472 :                 indirection = list_truncate(indirection, nfields);
   18685        2472 :                 c->fields = lcons(makeString(colname), indirection);
   18686             :             }
   18687        8864 :             i->arg = (Node *) c;
   18688        8864 :             return (Node *) i;
   18689             :         }
   18690      923586 :         else if (IsA(lfirst(l), A_Star))
   18691             :         {
   18692             :             /* We only allow '*' at the end of a ColumnRef */
   18693        4652 :             if (lnext(indirection, l) != NULL)
   18694           0 :                 parser_yyerror("improper use of \"*\"");
   18695             :         }
   18696      923586 :         nfields++;
   18697             :     }
   18698             :     /* No subscripting, so all indirection gets added to field list */
   18699     1502072 :     c->fields = lcons(makeString(colname), indirection);
   18700     1502072 :     return (Node *) c;
   18701             : }
   18702             : 
   18703             : static Node *
   18704      240248 : makeTypeCast(Node *arg, TypeName *typename, int location)
   18705             : {
   18706      240248 :     TypeCast   *n = makeNode(TypeCast);
   18707             : 
   18708      240248 :     n->arg = arg;
   18709      240248 :     n->typeName = typename;
   18710      240248 :     n->location = location;
   18711      240248 :     return (Node *) n;
   18712             : }
   18713             : 
   18714             : static Node *
   18715       15580 : makeStringConstCast(char *str, int location, TypeName *typename)
   18716             : {
   18717       15580 :     Node       *s = makeStringConst(str, location);
   18718             : 
   18719       15580 :     return makeTypeCast(s, typename, -1);
   18720             : }
   18721             : 
   18722             : static Node *
   18723      419626 : makeIntConst(int val, int location)
   18724             : {
   18725      419626 :     A_Const    *n = makeNode(A_Const);
   18726             : 
   18727      419626 :     n->val.ival.type = T_Integer;
   18728      419626 :     n->val.ival.ival = val;
   18729      419626 :     n->location = location;
   18730             : 
   18731      419626 :    return (Node *) n;
   18732             : }
   18733             : 
   18734             : static Node *
   18735       10854 : makeFloatConst(char *str, int location)
   18736             : {
   18737       10854 :     A_Const    *n = makeNode(A_Const);
   18738             : 
   18739       10854 :     n->val.fval.type = T_Float;
   18740       10854 :     n->val.fval.fval = str;
   18741       10854 :     n->location = location;
   18742             : 
   18743       10854 :    return (Node *) n;
   18744             : }
   18745             : 
   18746             : static Node *
   18747       54684 : makeBoolAConst(bool state, int location)
   18748             : {
   18749       54684 :     A_Const    *n = makeNode(A_Const);
   18750             : 
   18751       54684 :     n->val.boolval.type = T_Boolean;
   18752       54684 :     n->val.boolval.boolval = state;
   18753       54684 :     n->location = location;
   18754             : 
   18755       54684 :    return (Node *) n;
   18756             : }
   18757             : 
   18758             : static Node *
   18759        4056 : makeBitStringConst(char *str, int location)
   18760             : {
   18761        4056 :     A_Const    *n = makeNode(A_Const);
   18762             : 
   18763        4056 :     n->val.bsval.type = T_BitString;
   18764        4056 :     n->val.bsval.bsval = str;
   18765        4056 :     n->location = location;
   18766             : 
   18767        4056 :    return (Node *) n;
   18768             : }
   18769             : 
   18770             : static Node *
   18771       57928 : makeNullAConst(int location)
   18772             : {
   18773       57928 :     A_Const    *n = makeNode(A_Const);
   18774             : 
   18775       57928 :     n->isnull = true;
   18776       57928 :     n->location = location;
   18777             : 
   18778       57928 :     return (Node *) n;
   18779             : }
   18780             : 
   18781             : static Node *
   18782        4260 : makeAConst(Node *v, int location)
   18783             : {
   18784             :     Node       *n;
   18785             : 
   18786        4260 :     switch (v->type)
   18787             :     {
   18788         218 :         case T_Float:
   18789         218 :             n = makeFloatConst(castNode(Float, v)->fval, location);
   18790         218 :             break;
   18791             : 
   18792        4042 :         case T_Integer:
   18793        4042 :             n = makeIntConst(castNode(Integer, v)->ival, location);
   18794        4042 :             break;
   18795             : 
   18796           0 :         default:
   18797             :             /* currently not used */
   18798             :             Assert(false);
   18799           0 :             n = NULL;
   18800             :     }
   18801             : 
   18802        4260 :     return n;
   18803             : }
   18804             : 
   18805             : /* makeRoleSpec
   18806             :  * Create a RoleSpec with the given type
   18807             :  */
   18808             : static RoleSpec *
   18809       25958 : makeRoleSpec(RoleSpecType type, int location)
   18810             : {
   18811       25958 :     RoleSpec   *spec = makeNode(RoleSpec);
   18812             : 
   18813       25958 :     spec->roletype = type;
   18814       25958 :     spec->location = location;
   18815             : 
   18816       25958 :     return spec;
   18817             : }
   18818             : 
   18819             : /* check_qualified_name --- check the result of qualified_name production
   18820             :  *
   18821             :  * It's easiest to let the grammar production for qualified_name allow
   18822             :  * subscripts and '*', which we then must reject here.
   18823             :  */
   18824             : static void
   18825      216122 : check_qualified_name(List *names, core_yyscan_t yyscanner)
   18826             : {
   18827             :     ListCell   *i;
   18828             : 
   18829      432244 :     foreach(i, names)
   18830             :     {
   18831      216122 :         if (!IsA(lfirst(i), String))
   18832           0 :             parser_yyerror("syntax error");
   18833             :     }
   18834      216122 : }
   18835             : 
   18836             : /* check_func_name --- check the result of func_name production
   18837             :  *
   18838             :  * It's easiest to let the grammar production for func_name allow subscripts
   18839             :  * and '*', which we then must reject here.
   18840             :  */
   18841             : static List *
   18842      109696 : check_func_name(List *names, core_yyscan_t yyscanner)
   18843             : {
   18844             :     ListCell   *i;
   18845             : 
   18846      329088 :     foreach(i, names)
   18847             :     {
   18848      219392 :         if (!IsA(lfirst(i), String))
   18849           0 :             parser_yyerror("syntax error");
   18850             :     }
   18851      109696 :     return names;
   18852             : }
   18853             : 
   18854             : /* check_indirection --- check the result of indirection production
   18855             :  *
   18856             :  * We only allow '*' at the end of the list, but it's hard to enforce that
   18857             :  * in the grammar, so do it here.
   18858             :  */
   18859             : static List *
   18860       75062 : check_indirection(List *indirection, core_yyscan_t yyscanner)
   18861             : {
   18862             :     ListCell *l;
   18863             : 
   18864       99124 :     foreach(l, indirection)
   18865             :     {
   18866       24062 :         if (IsA(lfirst(l), A_Star))
   18867             :         {
   18868        1234 :             if (lnext(indirection, l) != NULL)
   18869           0 :                 parser_yyerror("improper use of \"*\"");
   18870             :         }
   18871             :     }
   18872       75062 :     return indirection;
   18873             : }
   18874             : 
   18875             : /* extractArgTypes()
   18876             :  * Given a list of FunctionParameter nodes, extract a list of just the
   18877             :  * argument types (TypeNames) for input parameters only.  This is what
   18878             :  * is needed to look up an existing function, which is what is wanted by
   18879             :  * the productions that use this call.
   18880             :  */
   18881             : static List *
   18882       13472 : extractArgTypes(List *parameters)
   18883             : {
   18884       13472 :     List       *result = NIL;
   18885             :     ListCell   *i;
   18886             : 
   18887       30032 :     foreach(i, parameters)
   18888             :     {
   18889       16560 :         FunctionParameter *p = (FunctionParameter *) lfirst(i);
   18890             : 
   18891       16560 :         if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
   18892       16410 :             result = lappend(result, p->argType);
   18893             :     }
   18894       13472 :     return result;
   18895             : }
   18896             : 
   18897             : /* extractAggrArgTypes()
   18898             :  * As above, but work from the output of the aggr_args production.
   18899             :  */
   18900             : static List *
   18901         362 : extractAggrArgTypes(List *aggrargs)
   18902             : {
   18903             :     Assert(list_length(aggrargs) == 2);
   18904         362 :     return extractArgTypes((List *) linitial(aggrargs));
   18905             : }
   18906             : 
   18907             : /* makeOrderedSetArgs()
   18908             :  * Build the result of the aggr_args production (which see the comments for).
   18909             :  * This handles only the case where both given lists are nonempty, so that
   18910             :  * we have to deal with multiple VARIADIC arguments.
   18911             :  */
   18912             : static List *
   18913          32 : makeOrderedSetArgs(List *directargs, List *orderedargs,
   18914             :                    core_yyscan_t yyscanner)
   18915             : {
   18916          32 :     FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
   18917             :     Integer    *ndirectargs;
   18918             : 
   18919             :     /* No restriction unless last direct arg is VARIADIC */
   18920          32 :     if (lastd->mode == FUNC_PARAM_VARIADIC)
   18921             :     {
   18922          16 :         FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
   18923             : 
   18924             :         /*
   18925             :          * We ignore the names, though the aggr_arg production allows them;
   18926             :          * it doesn't allow default values, so those need not be checked.
   18927             :          */
   18928          16 :         if (list_length(orderedargs) != 1 ||
   18929          16 :             firsto->mode != FUNC_PARAM_VARIADIC ||
   18930          16 :             !equal(lastd->argType, firsto->argType))
   18931           0 :             ereport(ERROR,
   18932             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   18933             :                      errmsg("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
   18934             :                      parser_errposition(exprLocation((Node *) firsto))));
   18935             : 
   18936             :         /* OK, drop the duplicate VARIADIC argument from the internal form */
   18937          16 :         orderedargs = NIL;
   18938             :     }
   18939             : 
   18940             :     /* don't merge into the next line, as list_concat changes directargs */
   18941          32 :     ndirectargs = makeInteger(list_length(directargs));
   18942             : 
   18943          32 :     return list_make2(list_concat(directargs, orderedargs),
   18944             :                       ndirectargs);
   18945             : }
   18946             : 
   18947             : /* insertSelectOptions()
   18948             :  * Insert ORDER BY, etc into an already-constructed SelectStmt.
   18949             :  *
   18950             :  * This routine is just to avoid duplicating code in SelectStmt productions.
   18951             :  */
   18952             : static void
   18953       66984 : insertSelectOptions(SelectStmt *stmt,
   18954             :                     List *sortClause, List *lockingClause,
   18955             :                     SelectLimit *limitClause,
   18956             :                     WithClause *withClause,
   18957             :                     core_yyscan_t yyscanner)
   18958             : {
   18959             :     Assert(IsA(stmt, SelectStmt));
   18960             : 
   18961             :     /*
   18962             :      * Tests here are to reject constructs like
   18963             :      *  (SELECT foo ORDER BY bar) ORDER BY baz
   18964             :      */
   18965       66984 :     if (sortClause)
   18966             :     {
   18967       58108 :         if (stmt->sortClause)
   18968           0 :             ereport(ERROR,
   18969             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   18970             :                      errmsg("multiple ORDER BY clauses not allowed"),
   18971             :                      parser_errposition(exprLocation((Node *) sortClause))));
   18972       58108 :         stmt->sortClause = sortClause;
   18973             :     }
   18974             :     /* We can handle multiple locking clauses, though */
   18975       66984 :     stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
   18976       66984 :     if (limitClause && limitClause->limitOffset)
   18977             :     {
   18978         756 :         if (stmt->limitOffset)
   18979           0 :             ereport(ERROR,
   18980             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   18981             :                      errmsg("multiple OFFSET clauses not allowed"),
   18982             :                      parser_errposition(exprLocation(limitClause->limitOffset))));
   18983         756 :         stmt->limitOffset = limitClause->limitOffset;
   18984             :     }
   18985       66984 :     if (limitClause && limitClause->limitCount)
   18986             :     {
   18987        4484 :         if (stmt->limitCount)
   18988           0 :             ereport(ERROR,
   18989             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   18990             :                      errmsg("multiple LIMIT clauses not allowed"),
   18991             :                      parser_errposition(exprLocation(limitClause->limitCount))));
   18992        4484 :         stmt->limitCount = limitClause->limitCount;
   18993             :     }
   18994       66984 :     if (limitClause)
   18995             :     {
   18996        4858 :         if (stmt->limitOption)
   18997           0 :             ereport(ERROR,
   18998             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   18999             :                      errmsg("multiple limit options not allowed")));
   19000        4858 :         if (!stmt->sortClause && limitClause->limitOption == LIMIT_OPTION_WITH_TIES)
   19001           6 :             ereport(ERROR,
   19002             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19003             :                      errmsg("WITH TIES cannot be specified without ORDER BY clause")));
   19004        4852 :         if (limitClause->limitOption == LIMIT_OPTION_WITH_TIES && stmt->lockingClause)
   19005             :         {
   19006             :             ListCell   *lc;
   19007             : 
   19008           6 :             foreach(lc, stmt->lockingClause)
   19009             :             {
   19010           6 :                 LockingClause *lock = lfirst_node(LockingClause, lc);
   19011             : 
   19012           6 :                 if (lock->waitPolicy == LockWaitSkip)
   19013           6 :                     ereport(ERROR,
   19014             :                             (errcode(ERRCODE_SYNTAX_ERROR),
   19015             :                              errmsg("%s and %s options cannot be used together",
   19016             :                                     "SKIP LOCKED", "WITH TIES")));
   19017             :             }
   19018             :         }
   19019        4846 :         stmt->limitOption = limitClause->limitOption;
   19020             :     }
   19021       66972 :     if (withClause)
   19022             :     {
   19023        2414 :         if (stmt->withClause)
   19024           0 :             ereport(ERROR,
   19025             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19026             :                      errmsg("multiple WITH clauses not allowed"),
   19027             :                      parser_errposition(exprLocation((Node *) withClause))));
   19028        2414 :         stmt->withClause = withClause;
   19029             :     }
   19030       66972 : }
   19031             : 
   19032             : static Node *
   19033       14144 : makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
   19034             : {
   19035       14144 :     SelectStmt *n = makeNode(SelectStmt);
   19036             : 
   19037       14144 :     n->op = op;
   19038       14144 :     n->all = all;
   19039       14144 :     n->larg = (SelectStmt *) larg;
   19040       14144 :     n->rarg = (SelectStmt *) rarg;
   19041       14144 :     return (Node *) n;
   19042             : }
   19043             : 
   19044             : /* SystemFuncName()
   19045             :  * Build a properly-qualified reference to a built-in function.
   19046             :  */
   19047             : List *
   19048       16740 : SystemFuncName(char *name)
   19049             : {
   19050       16740 :     return list_make2(makeString("pg_catalog"), makeString(name));
   19051             : }
   19052             : 
   19053             : /* SystemTypeName()
   19054             :  * Build a properly-qualified reference to a built-in type.
   19055             :  *
   19056             :  * typmod is defaulted, but may be changed afterwards by caller.
   19057             :  * Likewise for the location.
   19058             :  */
   19059             : TypeName *
   19060       90828 : SystemTypeName(char *name)
   19061             : {
   19062       90828 :     return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
   19063             :                                                makeString(name)));
   19064             : }
   19065             : 
   19066             : /* doNegate()
   19067             :  * Handle negation of a numeric constant.
   19068             :  *
   19069             :  * Formerly, we did this here because the optimizer couldn't cope with
   19070             :  * indexquals that looked like "var = -4" --- it wants "var = const"
   19071             :  * and a unary minus operator applied to a constant didn't qualify.
   19072             :  * As of Postgres 7.0, that problem doesn't exist anymore because there
   19073             :  * is a constant-subexpression simplifier in the optimizer.  However,
   19074             :  * there's still a good reason for doing this here, which is that we can
   19075             :  * postpone committing to a particular internal representation for simple
   19076             :  * negative constants.  It's better to leave "-123.456" in string form
   19077             :  * until we know what the desired type is.
   19078             :  */
   19079             : static Node *
   19080       27226 : doNegate(Node *n, int location)
   19081             : {
   19082       27226 :     if (IsA(n, A_Const))
   19083             :     {
   19084       26296 :         A_Const    *con = (A_Const *) n;
   19085             : 
   19086             :         /* report the constant's location as that of the '-' sign */
   19087       26296 :         con->location = location;
   19088             : 
   19089       26296 :         if (IsA(&con->val, Integer))
   19090             :         {
   19091       25374 :             con->val.ival.ival = -con->val.ival.ival;
   19092       25374 :             return n;
   19093             :         }
   19094         922 :         if (IsA(&con->val, Float))
   19095             :         {
   19096         922 :             doNegateFloat(&con->val.fval);
   19097         922 :             return n;
   19098             :         }
   19099             :     }
   19100             : 
   19101         930 :     return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
   19102             : }
   19103             : 
   19104             : static void
   19105         942 : doNegateFloat(Float *v)
   19106             : {
   19107         942 :     char       *oldval = v->fval;
   19108             : 
   19109         942 :     if (*oldval == '+')
   19110           0 :         oldval++;
   19111         942 :     if (*oldval == '-')
   19112           0 :         v->fval = oldval+1;  /* just strip the '-' */
   19113             :     else
   19114         942 :         v->fval = psprintf("-%s", oldval);
   19115         942 : }
   19116             : 
   19117             : static Node *
   19118      198764 : makeAndExpr(Node *lexpr, Node *rexpr, int location)
   19119             : {
   19120             :     /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
   19121      198764 :     if (IsA(lexpr, BoolExpr))
   19122             :     {
   19123       92422 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   19124             : 
   19125       92422 :         if (blexpr->boolop == AND_EXPR)
   19126             :         {
   19127       90144 :             blexpr->args = lappend(blexpr->args, rexpr);
   19128       90144 :             return (Node *) blexpr;
   19129             :         }
   19130             :     }
   19131      108620 :     return (Node *) makeBoolExpr(AND_EXPR, list_make2(lexpr, rexpr), location);
   19132             : }
   19133             : 
   19134             : static Node *
   19135       14654 : makeOrExpr(Node *lexpr, Node *rexpr, int location)
   19136             : {
   19137             :     /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
   19138       14654 :     if (IsA(lexpr, BoolExpr))
   19139             :     {
   19140        6142 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   19141             : 
   19142        6142 :         if (blexpr->boolop == OR_EXPR)
   19143             :         {
   19144        3360 :             blexpr->args = lappend(blexpr->args, rexpr);
   19145        3360 :             return (Node *) blexpr;
   19146             :         }
   19147             :     }
   19148       11294 :     return (Node *) makeBoolExpr(OR_EXPR, list_make2(lexpr, rexpr), location);
   19149             : }
   19150             : 
   19151             : static Node *
   19152       13912 : makeNotExpr(Node *expr, int location)
   19153             : {
   19154       13912 :     return (Node *) makeBoolExpr(NOT_EXPR, list_make1(expr), location);
   19155             : }
   19156             : 
   19157             : static Node *
   19158        8116 : makeAArrayExpr(List *elements, int location)
   19159             : {
   19160        8116 :     A_ArrayExpr *n = makeNode(A_ArrayExpr);
   19161             : 
   19162        8116 :     n->elements = elements;
   19163        8116 :     n->location = location;
   19164        8116 :     return (Node *) n;
   19165             : }
   19166             : 
   19167             : static Node *
   19168        2362 : makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod, int location)
   19169             : {
   19170        2362 :     SQLValueFunction *svf = makeNode(SQLValueFunction);
   19171             : 
   19172        2362 :     svf->op = op;
   19173             :     /* svf->type will be filled during parse analysis */
   19174        2362 :     svf->typmod = typmod;
   19175        2362 :     svf->location = location;
   19176        2362 :     return (Node *) svf;
   19177             : }
   19178             : 
   19179             : static Node *
   19180         596 : makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
   19181             :             int location)
   19182             : {
   19183         596 :     XmlExpr     *x = makeNode(XmlExpr);
   19184             : 
   19185         596 :     x->op = op;
   19186         596 :     x->name = name;
   19187             :     /*
   19188             :      * named_args is a list of ResTarget; it'll be split apart into separate
   19189             :      * expression and name lists in transformXmlExpr().
   19190             :      */
   19191         596 :     x->named_args = named_args;
   19192         596 :     x->arg_names = NIL;
   19193         596 :     x->args = args;
   19194             :     /* xmloption, if relevant, must be filled in by caller */
   19195             :     /* type and typmod will be filled in during parse analysis */
   19196         596 :     x->type = InvalidOid;            /* marks the node as not analyzed */
   19197         596 :     x->location = location;
   19198         596 :     return (Node *) x;
   19199             : }
   19200             : 
   19201             : /*
   19202             :  * Merge the input and output parameters of a table function.
   19203             :  */
   19204             : static List *
   19205         188 : mergeTableFuncParameters(List *func_args, List *columns)
   19206             : {
   19207             :     ListCell   *lc;
   19208             : 
   19209             :     /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
   19210         382 :     foreach(lc, func_args)
   19211             :     {
   19212         194 :         FunctionParameter *p = (FunctionParameter *) lfirst(lc);
   19213             : 
   19214         194 :         if (p->mode != FUNC_PARAM_DEFAULT &&
   19215           0 :             p->mode != FUNC_PARAM_IN &&
   19216           0 :             p->mode != FUNC_PARAM_VARIADIC)
   19217           0 :             ereport(ERROR,
   19218             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19219             :                      errmsg("OUT and INOUT arguments aren't allowed in TABLE functions")));
   19220             :     }
   19221             : 
   19222         188 :     return list_concat(func_args, columns);
   19223             : }
   19224             : 
   19225             : /*
   19226             :  * Determine return type of a TABLE function.  A single result column
   19227             :  * returns setof that column's type; otherwise return setof record.
   19228             :  */
   19229             : static TypeName *
   19230         188 : TableFuncTypeName(List *columns)
   19231             : {
   19232             :     TypeName   *result;
   19233             : 
   19234         188 :     if (list_length(columns) == 1)
   19235             :     {
   19236          62 :         FunctionParameter *p = (FunctionParameter *) linitial(columns);
   19237             : 
   19238          62 :         result = copyObject(p->argType);
   19239             :     }
   19240             :     else
   19241         126 :         result = SystemTypeName("record");
   19242             : 
   19243         188 :     result->setof = true;
   19244             : 
   19245         188 :     return result;
   19246             : }
   19247             : 
   19248             : /*
   19249             :  * Convert a list of (dotted) names to a RangeVar (like
   19250             :  * makeRangeVarFromNameList, but with position support).  The
   19251             :  * "AnyName" refers to the any_name production in the grammar.
   19252             :  */
   19253             : static RangeVar *
   19254         922 : makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
   19255             : {
   19256         922 :     RangeVar   *r = makeNode(RangeVar);
   19257             : 
   19258         922 :     switch (list_length(names))
   19259             :     {
   19260         840 :         case 1:
   19261         840 :             r->catalogname = NULL;
   19262         840 :             r->schemaname = NULL;
   19263         840 :             r->relname = strVal(linitial(names));
   19264         840 :             break;
   19265          82 :         case 2:
   19266          82 :             r->catalogname = NULL;
   19267          82 :             r->schemaname = strVal(linitial(names));
   19268          82 :             r->relname = strVal(lsecond(names));
   19269          82 :             break;
   19270           0 :         case 3:
   19271           0 :             r->catalogname = strVal(linitial(names));
   19272           0 :             r->schemaname = strVal(lsecond(names));
   19273           0 :             r->relname = strVal(lthird(names));
   19274           0 :             break;
   19275           0 :         default:
   19276           0 :             ereport(ERROR,
   19277             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19278             :                      errmsg("improper qualified name (too many dotted names): %s",
   19279             :                             NameListToString(names)),
   19280             :                      parser_errposition(position)));
   19281             :             break;
   19282             :     }
   19283             : 
   19284         922 :     r->relpersistence = RELPERSISTENCE_PERMANENT;
   19285         922 :     r->location = position;
   19286             : 
   19287         922 :     return r;
   19288             : }
   19289             : 
   19290             : /*
   19291             :  * Convert a relation_name with name and namelist to a RangeVar using
   19292             :  * makeRangeVar.
   19293             :  */
   19294             : static RangeVar *
   19295      216122 : makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
   19296             :                               core_yyscan_t yyscanner)
   19297             : {
   19298             :     RangeVar   *r;
   19299             : 
   19300      216122 :     check_qualified_name(namelist, yyscanner);
   19301      216122 :     r = makeRangeVar(NULL, NULL, location);
   19302             : 
   19303      216122 :     switch (list_length(namelist))
   19304             :     {
   19305      216122 :         case 1:
   19306      216122 :             r->catalogname = NULL;
   19307      216122 :             r->schemaname = name;
   19308      216122 :             r->relname = strVal(linitial(namelist));
   19309      216122 :             break;
   19310           0 :         case 2:
   19311           0 :             r->catalogname = name;
   19312           0 :             r->schemaname = strVal(linitial(namelist));
   19313           0 :             r->relname = strVal(lsecond(namelist));
   19314           0 :             break;
   19315           0 :         default:
   19316           0 :             ereport(ERROR,
   19317             :                     errcode(ERRCODE_SYNTAX_ERROR),
   19318             :                     errmsg("improper qualified name (too many dotted names): %s",
   19319             :                            NameListToString(lcons(makeString(name), namelist))),
   19320             :                            parser_errposition(location));
   19321             :             break;
   19322             :     }
   19323             : 
   19324      216122 :     return r;
   19325             : }
   19326             : 
   19327             : /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
   19328             : static void
   19329       64324 : SplitColQualList(List *qualList,
   19330             :                  List **constraintList, CollateClause **collClause,
   19331             :                  core_yyscan_t yyscanner)
   19332             : {
   19333             :     ListCell   *cell;
   19334             : 
   19335       64324 :     *collClause = NULL;
   19336       81306 :     foreach(cell, qualList)
   19337             :     {
   19338       16982 :         Node       *n = (Node *) lfirst(cell);
   19339             : 
   19340       16982 :         if (IsA(n, Constraint))
   19341             :         {
   19342             :             /* keep it in list */
   19343       16368 :             continue;
   19344             :         }
   19345         614 :         if (IsA(n, CollateClause))
   19346             :         {
   19347         614 :             CollateClause *c = (CollateClause *) n;
   19348             : 
   19349         614 :             if (*collClause)
   19350           0 :                 ereport(ERROR,
   19351             :                         (errcode(ERRCODE_SYNTAX_ERROR),
   19352             :                          errmsg("multiple COLLATE clauses not allowed"),
   19353             :                          parser_errposition(c->location)));
   19354         614 :             *collClause = c;
   19355             :         }
   19356             :         else
   19357           0 :             elog(ERROR, "unexpected node type %d", (int) n->type);
   19358             :         /* remove non-Constraint nodes from qualList */
   19359         614 :         qualList = foreach_delete_current(qualList, cell);
   19360             :     }
   19361       64324 :     *constraintList = qualList;
   19362       64324 : }
   19363             : 
   19364             : /*
   19365             :  * Process result of ConstraintAttributeSpec, and set appropriate bool flags
   19366             :  * in the output command node.  Pass NULL for any flags the particular
   19367             :  * command doesn't support.
   19368             :  */
   19369             : static void
   19370       14456 : processCASbits(int cas_bits, int location, const char *constrType,
   19371             :                bool *deferrable, bool *initdeferred, bool *not_valid,
   19372             :                bool *no_inherit, core_yyscan_t yyscanner)
   19373             : {
   19374             :     /* defaults */
   19375       14456 :     if (deferrable)
   19376       13044 :         *deferrable = false;
   19377       14456 :     if (initdeferred)
   19378       13044 :         *initdeferred = false;
   19379       14456 :     if (not_valid)
   19380        2902 :         *not_valid = false;
   19381             : 
   19382       14456 :     if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
   19383             :     {
   19384         246 :         if (deferrable)
   19385         246 :             *deferrable = true;
   19386             :         else
   19387           0 :             ereport(ERROR,
   19388             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19389             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19390             :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   19391             :                             constrType),
   19392             :                      parser_errposition(location)));
   19393             :     }
   19394             : 
   19395       14456 :     if (cas_bits & CAS_INITIALLY_DEFERRED)
   19396             :     {
   19397         156 :         if (initdeferred)
   19398         156 :             *initdeferred = true;
   19399             :         else
   19400           0 :             ereport(ERROR,
   19401             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19402             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19403             :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   19404             :                             constrType),
   19405             :                      parser_errposition(location)));
   19406             :     }
   19407             : 
   19408       14456 :     if (cas_bits & CAS_NOT_VALID)
   19409             :     {
   19410         516 :         if (not_valid)
   19411         516 :             *not_valid = true;
   19412             :         else
   19413           0 :             ereport(ERROR,
   19414             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19415             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19416             :                      errmsg("%s constraints cannot be marked NOT VALID",
   19417             :                             constrType),
   19418             :                      parser_errposition(location)));
   19419             :     }
   19420             : 
   19421       14456 :     if (cas_bits & CAS_NO_INHERIT)
   19422             :     {
   19423         172 :         if (no_inherit)
   19424         172 :             *no_inherit = true;
   19425             :         else
   19426           0 :             ereport(ERROR,
   19427             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19428             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19429             :                      errmsg("%s constraints cannot be marked NO INHERIT",
   19430             :                             constrType),
   19431             :                      parser_errposition(location)));
   19432             :     }
   19433       14456 : }
   19434             : 
   19435             : /*
   19436             :  * Parse a user-supplied partition strategy string into parse node
   19437             :  * PartitionStrategy representation, or die trying.
   19438             :  */
   19439             : static PartitionStrategy
   19440        4948 : parsePartitionStrategy(char *strategy)
   19441             : {
   19442        4948 :     if (pg_strcasecmp(strategy, "list") == 0)
   19443        2378 :         return PARTITION_STRATEGY_LIST;
   19444        2570 :     else if (pg_strcasecmp(strategy, "range") == 0)
   19445        2336 :         return PARTITION_STRATEGY_RANGE;
   19446         234 :     else if (pg_strcasecmp(strategy, "hash") == 0)
   19447         228 :         return PARTITION_STRATEGY_HASH;
   19448             : 
   19449           6 :     ereport(ERROR,
   19450             :             (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   19451             :              errmsg("unrecognized partitioning strategy \"%s\"",
   19452             :                     strategy)));
   19453             :     return PARTITION_STRATEGY_LIST;     /* keep compiler quiet */
   19454             : 
   19455             : }
   19456             : 
   19457             : /*
   19458             :  * Process pubobjspec_list to check for errors in any of the objects and
   19459             :  * convert PUBLICATIONOBJ_CONTINUATION into appropriate PublicationObjSpecType.
   19460             :  */
   19461             : static void
   19462        1470 : preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
   19463             : {
   19464             :     ListCell   *cell;
   19465             :     PublicationObjSpec *pubobj;
   19466        1470 :     PublicationObjSpecType prevobjtype = PUBLICATIONOBJ_CONTINUATION;
   19467             : 
   19468        1470 :     if (!pubobjspec_list)
   19469           0 :         return;
   19470             : 
   19471        1470 :     pubobj = (PublicationObjSpec *) linitial(pubobjspec_list);
   19472        1470 :     if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   19473          12 :         ereport(ERROR,
   19474             :                 errcode(ERRCODE_SYNTAX_ERROR),
   19475             :                 errmsg("invalid publication object list"),
   19476             :                 errdetail("One of TABLE or TABLES IN SCHEMA must be specified before a standalone table or schema name."),
   19477             :                 parser_errposition(pubobj->location));
   19478             : 
   19479        3116 :     foreach(cell, pubobjspec_list)
   19480             :     {
   19481        1682 :         pubobj = (PublicationObjSpec *) lfirst(cell);
   19482             : 
   19483        1682 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   19484         174 :             pubobj->pubobjtype = prevobjtype;
   19485             : 
   19486        1682 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE)
   19487             :         {
   19488             :             /* relation name or pubtable must be set for this type of object */
   19489        1278 :             if (!pubobj->name && !pubobj->pubtable)
   19490           6 :                 ereport(ERROR,
   19491             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19492             :                         errmsg("invalid table name"),
   19493             :                         parser_errposition(pubobj->location));
   19494             : 
   19495        1272 :             if (pubobj->name)
   19496             :             {
   19497             :                 /* convert it to PublicationTable */
   19498          58 :                 PublicationTable *pubtable = makeNode(PublicationTable);
   19499             : 
   19500          58 :                 pubtable->relation =
   19501          58 :                     makeRangeVar(NULL, pubobj->name, pubobj->location);
   19502          58 :                 pubobj->pubtable = pubtable;
   19503          58 :                 pubobj->name = NULL;
   19504             :             }
   19505             :         }
   19506         404 :         else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
   19507          24 :                  pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA)
   19508             :         {
   19509             :             /* WHERE clause is not allowed on a schema object */
   19510         404 :             if (pubobj->pubtable && pubobj->pubtable->whereClause)
   19511           6 :                 ereport(ERROR,
   19512             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19513             :                         errmsg("WHERE clause not allowed for schema"),
   19514             :                         parser_errposition(pubobj->location));
   19515             : 
   19516             :             /* Column list is not allowed on a schema object */
   19517         398 :             if (pubobj->pubtable && pubobj->pubtable->columns)
   19518           6 :                 ereport(ERROR,
   19519             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19520             :                         errmsg("column specification not allowed for schema"),
   19521             :                         parser_errposition(pubobj->location));
   19522             : 
   19523             :             /*
   19524             :              * We can distinguish between the different type of schema
   19525             :              * objects based on whether name and pubtable is set.
   19526             :              */
   19527         392 :             if (pubobj->name)
   19528         362 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   19529          30 :             else if (!pubobj->name && !pubobj->pubtable)
   19530          24 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   19531             :             else
   19532           6 :                 ereport(ERROR,
   19533             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19534             :                         errmsg("invalid schema name"),
   19535             :                         parser_errposition(pubobj->location));
   19536             :         }
   19537             : 
   19538        1658 :         prevobjtype = pubobj->pubobjtype;
   19539             :     }
   19540             : }
   19541             : 
   19542             : /*----------
   19543             :  * Recursive view transformation
   19544             :  *
   19545             :  * Convert
   19546             :  *
   19547             :  *     CREATE RECURSIVE VIEW relname (aliases) AS query
   19548             :  *
   19549             :  * to
   19550             :  *
   19551             :  *     CREATE VIEW relname (aliases) AS
   19552             :  *         WITH RECURSIVE relname (aliases) AS (query)
   19553             :  *         SELECT aliases FROM relname
   19554             :  *
   19555             :  * Actually, just the WITH ... part, which is then inserted into the original
   19556             :  * view definition as the query.
   19557             :  * ----------
   19558             :  */
   19559             : static Node *
   19560          14 : makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
   19561             : {
   19562          14 :     SelectStmt *s = makeNode(SelectStmt);
   19563          14 :     WithClause *w = makeNode(WithClause);
   19564          14 :     CommonTableExpr *cte = makeNode(CommonTableExpr);
   19565          14 :     List       *tl = NIL;
   19566             :     ListCell   *lc;
   19567             : 
   19568             :     /* create common table expression */
   19569          14 :     cte->ctename = relname;
   19570          14 :     cte->aliascolnames = aliases;
   19571          14 :     cte->ctematerialized = CTEMaterializeDefault;
   19572          14 :     cte->ctequery = query;
   19573          14 :     cte->location = -1;
   19574             : 
   19575             :     /* create WITH clause and attach CTE */
   19576          14 :     w->recursive = true;
   19577          14 :     w->ctes = list_make1(cte);
   19578          14 :     w->location = -1;
   19579             : 
   19580             :     /* create target list for the new SELECT from the alias list of the
   19581             :      * recursive view specification */
   19582          28 :     foreach (lc, aliases)
   19583             :     {
   19584          14 :         ResTarget *rt = makeNode(ResTarget);
   19585             : 
   19586          14 :         rt->name = NULL;
   19587          14 :         rt->indirection = NIL;
   19588          14 :         rt->val = makeColumnRef(strVal(lfirst(lc)), NIL, -1, 0);
   19589          14 :         rt->location = -1;
   19590             : 
   19591          14 :         tl = lappend(tl, rt);
   19592             :     }
   19593             : 
   19594             :     /* create new SELECT combining WITH clause, target list, and fake FROM
   19595             :      * clause */
   19596          14 :     s->withClause = w;
   19597          14 :     s->targetList = tl;
   19598          14 :     s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));
   19599             : 
   19600          14 :     return (Node *) s;
   19601             : }
   19602             : 
   19603             : /* parser_init()
   19604             :  * Initialize to parse one query string
   19605             :  */
   19606             : void
   19607      723448 : parser_init(base_yy_extra_type *yyext)
   19608             : {
   19609      723448 :     yyext->parsetree = NIL;      /* in case grammar forgets to set it */
   19610      723448 : }

Generated by: LCOV version 1.14