LCOV - code coverage report
Current view: top level - src/backend/parser - gram.y (source / functions) Hit Total Coverage
Test: PostgreSQL 17devel Lines: 6514 7248 89.9 %
Date: 2024-03-29 09:11:05 Functions: 42 42 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 *makeStringConst(char *str, int location);
     174             : static Node *makeStringConstCast(char *str, int location, TypeName *typename);
     175             : static Node *makeIntConst(int val, int location);
     176             : static Node *makeFloatConst(char *str, int location);
     177             : static Node *makeBoolAConst(bool state, int location);
     178             : static Node *makeBitStringConst(char *str, int location);
     179             : static Node *makeNullAConst(int location);
     180             : static Node *makeAConst(Node *v, int location);
     181             : static RoleSpec *makeRoleSpec(RoleSpecType type, int location);
     182             : static void check_qualified_name(List *names, core_yyscan_t yyscanner);
     183             : static List *check_func_name(List *names, core_yyscan_t yyscanner);
     184             : static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
     185             : static List *extractArgTypes(List *parameters);
     186             : static List *extractAggrArgTypes(List *aggrargs);
     187             : static List *makeOrderedSetArgs(List *directargs, List *orderedargs,
     188             :                                 core_yyscan_t yyscanner);
     189             : static void insertSelectOptions(SelectStmt *stmt,
     190             :                                 List *sortClause, List *lockingClause,
     191             :                                 SelectLimit *limitClause,
     192             :                                 WithClause *withClause,
     193             :                                 core_yyscan_t yyscanner);
     194             : static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
     195             : static Node *doNegate(Node *n, int location);
     196             : static void doNegateFloat(Float *v);
     197             : static Node *makeAndExpr(Node *lexpr, Node *rexpr, int location);
     198             : static Node *makeOrExpr(Node *lexpr, Node *rexpr, int location);
     199             : static Node *makeNotExpr(Node *expr, int location);
     200             : static Node *makeAArrayExpr(List *elements, int location);
     201             : static Node *makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod,
     202             :                                   int location);
     203             : static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
     204             :                          List *args, int location);
     205             : static List *mergeTableFuncParameters(List *func_args, List *columns);
     206             : static TypeName *TableFuncTypeName(List *columns);
     207             : static RangeVar *makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner);
     208             : static RangeVar *makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
     209             :                                                core_yyscan_t yyscanner);
     210             : static void SplitColQualList(List *qualList,
     211             :                              List **constraintList, CollateClause **collClause,
     212             :                              core_yyscan_t yyscanner);
     213             : static void processCASbits(int cas_bits, int location, const char *constrType,
     214             :                bool *deferrable, bool *initdeferred, bool *not_valid,
     215             :                bool *no_inherit, core_yyscan_t yyscanner);
     216             : static PartitionStrategy parsePartitionStrategy(char *strategy);
     217             : static void preprocess_pubobj_list(List *pubobjspec_list,
     218             :                                    core_yyscan_t yyscanner);
     219             : static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
     220             : 
     221             : %}
     222             : 
     223             : %pure-parser
     224             : %expect 0
     225             : %name-prefix="base_yy"
     226             : %locations
     227             : 
     228             : %parse-param {core_yyscan_t yyscanner}
     229             : %lex-param   {core_yyscan_t yyscanner}
     230             : 
     231             : %union
     232             : {
     233             :     core_YYSTYPE core_yystype;
     234             :     /* these fields must match core_YYSTYPE: */
     235             :     int         ival;
     236             :     char       *str;
     237             :     const char *keyword;
     238             : 
     239             :     char        chr;
     240             :     bool        boolean;
     241             :     JoinType    jtype;
     242             :     DropBehavior dbehavior;
     243             :     OnCommitAction oncommit;
     244             :     List       *list;
     245             :     Node       *node;
     246             :     ObjectType  objtype;
     247             :     TypeName   *typnam;
     248             :     FunctionParameter *fun_param;
     249             :     FunctionParameterMode fun_param_mode;
     250             :     ObjectWithArgs *objwithargs;
     251             :     DefElem    *defelt;
     252             :     SortBy     *sortby;
     253             :     WindowDef  *windef;
     254             :     JoinExpr   *jexpr;
     255             :     IndexElem  *ielem;
     256             :     StatsElem  *selem;
     257             :     Alias      *alias;
     258             :     RangeVar   *range;
     259             :     IntoClause *into;
     260             :     WithClause *with;
     261             :     InferClause *infer;
     262             :     OnConflictClause *onconflict;
     263             :     A_Indices  *aind;
     264             :     ResTarget  *target;
     265             :     struct PrivTarget *privtarget;
     266             :     AccessPriv *accesspriv;
     267             :     struct ImportQual *importqual;
     268             :     InsertStmt *istmt;
     269             :     VariableSetStmt *vsetstmt;
     270             :     PartitionElem *partelem;
     271             :     PartitionSpec *partspec;
     272             :     PartitionBoundSpec *partboundspec;
     273             :     RoleSpec   *rolespec;
     274             :     PublicationObjSpec *publicationobjectspec;
     275             :     struct SelectLimit *selectlimit;
     276             :     SetQuantifier setquantifier;
     277             :     struct GroupClause *groupclause;
     278             :     MergeWhenClause *mergewhen;
     279             :     struct KeyActions *keyactions;
     280             :     struct KeyAction *keyaction;
     281             : }
     282             : 
     283             : %type <node>  stmt toplevel_stmt schema_stmt routine_body_stmt
     284             :         AlterEventTrigStmt AlterCollationStmt
     285             :         AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt
     286             :         AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
     287             :         AlterObjectDependsStmt AlterObjectSchemaStmt AlterOwnerStmt
     288             :         AlterOperatorStmt AlterTypeStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
     289             :         AlterTblSpcStmt AlterExtensionStmt AlterExtensionContentsStmt
     290             :         AlterCompositeTypeStmt AlterUserMappingStmt
     291             :         AlterRoleStmt AlterRoleSetStmt AlterPolicyStmt AlterStatsStmt
     292             :         AlterDefaultPrivilegesStmt DefACLAction
     293             :         AnalyzeStmt CallStmt ClosePortalStmt ClusterStmt CommentStmt
     294             :         ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
     295             :         CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt
     296             :         CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
     297             :         CreateSchemaStmt CreateSeqStmt CreateStmt CreateStatsStmt CreateTableSpaceStmt
     298             :         CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt
     299             :         CreateAssertionStmt CreateTransformStmt CreateTrigStmt CreateEventTrigStmt
     300             :         CreateUserStmt CreateUserMappingStmt CreateRoleStmt CreatePolicyStmt
     301             :         CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
     302             :         DropOpClassStmt DropOpFamilyStmt DropStmt
     303             :         DropCastStmt DropRoleStmt
     304             :         DropdbStmt DropTableSpaceStmt
     305             :         DropTransformStmt
     306             :         DropUserMappingStmt ExplainStmt FetchStmt
     307             :         GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
     308             :         ListenStmt LoadStmt LockStmt MergeStmt NotifyStmt ExplainableStmt PreparableStmt
     309             :         CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
     310             :         RemoveFuncStmt RemoveOperStmt RenameStmt ReturnStmt RevokeStmt RevokeRoleStmt
     311             :         RuleActionStmt RuleActionStmtOrEmpty RuleStmt
     312             :         SecLabelStmt SelectStmt TransactionStmt TransactionStmtLegacy TruncateStmt
     313             :         UnlistenStmt UpdateStmt VacuumStmt
     314             :         VariableResetStmt VariableSetStmt VariableShowStmt
     315             :         ViewStmt CheckPointStmt CreateConversionStmt
     316             :         DeallocateStmt PrepareStmt ExecuteStmt
     317             :         DropOwnedStmt ReassignOwnedStmt
     318             :         AlterTSConfigurationStmt AlterTSDictionaryStmt
     319             :         CreateMatViewStmt RefreshMatViewStmt CreateAmStmt
     320             :         CreatePublicationStmt AlterPublicationStmt
     321             :         CreateSubscriptionStmt AlterSubscriptionStmt DropSubscriptionStmt
     322             : 
     323             : %type <node>  select_no_parens select_with_parens select_clause
     324             :                 simple_select values_clause
     325             :                 PLpgSQL_Expr PLAssignStmt
     326             : 
     327             : %type <str>           opt_single_name
     328             : %type <list>      opt_qualified_name
     329             : %type <boolean>       opt_concurrently
     330             : %type <dbehavior> opt_drop_behavior
     331             : 
     332             : %type <node>  alter_column_default opclass_item opclass_drop alter_using
     333             : %type <ival>  add_drop opt_asc_desc opt_nulls_order
     334             : 
     335             : %type <node>  alter_table_cmd alter_type_cmd opt_collate_clause
     336             :        replica_identity partition_cmd index_partition_cmd
     337             : %type <list>  alter_table_cmds alter_type_cmds
     338             : %type <list>    alter_identity_column_option_list
     339             : %type <defelt>  alter_identity_column_option
     340             : %type <node>  set_statistics_value
     341             : %type <str>       set_access_method_name
     342             : 
     343             : %type <list>  createdb_opt_list createdb_opt_items copy_opt_list
     344             :                 transaction_mode_list
     345             :                 create_extension_opt_list alter_extension_opt_list
     346             : %type <defelt>    createdb_opt_item copy_opt_item
     347             :                 transaction_mode_item
     348             :                 create_extension_opt_item alter_extension_opt_item
     349             : 
     350             : %type <ival>  opt_lock lock_type cast_context
     351             : %type <str>       utility_option_name
     352             : %type <defelt>    utility_option_elem
     353             : %type <list>  utility_option_list
     354             : %type <node>  utility_option_arg
     355             : %type <defelt>    drop_option
     356             : %type <boolean>   opt_or_replace opt_no
     357             :                 opt_grant_grant_option
     358             :                 opt_nowait opt_if_exists opt_with_data
     359             :                 opt_transaction_chain
     360             : %type <list>  grant_role_opt_list
     361             : %type <defelt>    grant_role_opt
     362             : %type <node>  grant_role_opt_value
     363             : %type <ival>  opt_nowait_or_skip
     364             : 
     365             : %type <list>  OptRoleList AlterOptRoleList
     366             : %type <defelt>    CreateOptRoleElem AlterOptRoleElem
     367             : 
     368             : %type <str>       opt_type
     369             : %type <str>       foreign_server_version opt_foreign_server_version
     370             : %type <str>       opt_in_database
     371             : 
     372             : %type <str>       parameter_name
     373             : %type <list>  OptSchemaEltList parameter_name_list
     374             : 
     375             : %type <chr>       am_type
     376             : 
     377             : %type <boolean> TriggerForSpec TriggerForType
     378             : %type <ival>  TriggerActionTime
     379             : %type <list>  TriggerEvents TriggerOneEvent
     380             : %type <node>  TriggerFuncArg
     381             : %type <node>  TriggerWhen
     382             : %type <str>       TransitionRelName
     383             : %type <boolean>   TransitionRowOrTable TransitionOldOrNew
     384             : %type <node>  TriggerTransition
     385             : 
     386             : %type <list>  event_trigger_when_list event_trigger_value_list
     387             : %type <defelt>    event_trigger_when_item
     388             : %type <chr>       enable_trigger
     389             : 
     390             : %type <str>       copy_file_name
     391             :                 access_method_clause attr_name
     392             :                 table_access_method_clause name cursor_name file_name
     393             :                 cluster_index_specification
     394             : 
     395             : %type <list>  func_name handler_name qual_Op qual_all_Op subquery_Op
     396             :                 opt_inline_handler opt_validator validator_clause
     397             :                 opt_collate
     398             : 
     399             : %type <range> qualified_name insert_target OptConstrFromTable
     400             : 
     401             : %type <str>       all_Op MathOp
     402             : 
     403             : %type <str>       row_security_cmd RowSecurityDefaultForCmd
     404             : %type <boolean> RowSecurityDefaultPermissive
     405             : %type <node>  RowSecurityOptionalWithCheck RowSecurityOptionalExpr
     406             : %type <list>  RowSecurityDefaultToRole RowSecurityOptionalToRole
     407             : 
     408             : %type <str>       iso_level opt_encoding
     409             : %type <rolespec> grantee
     410             : %type <list>  grantee_list
     411             : %type <accesspriv> privilege
     412             : %type <list>  privileges privilege_list
     413             : %type <privtarget> privilege_target
     414             : %type <objwithargs> function_with_argtypes aggregate_with_argtypes operator_with_argtypes
     415             : %type <list>  function_with_argtypes_list aggregate_with_argtypes_list operator_with_argtypes_list
     416             : %type <ival>  defacl_privilege_target
     417             : %type <defelt>    DefACLOption
     418             : %type <list>  DefACLOptionList
     419             : %type <ival>  import_qualification_type
     420             : %type <importqual> import_qualification
     421             : %type <node>  vacuum_relation
     422             : %type <selectlimit> opt_select_limit select_limit limit_clause
     423             : 
     424             : %type <list>  parse_toplevel stmtmulti routine_body_stmt_list
     425             :                 OptTableElementList TableElementList OptInherit definition
     426             :                 OptTypedTableElementList TypedTableElementList
     427             :                 reloptions opt_reloptions
     428             :                 OptWith opt_definition func_args func_args_list
     429             :                 func_args_with_defaults func_args_with_defaults_list
     430             :                 aggr_args aggr_args_list
     431             :                 func_as createfunc_opt_list opt_createfunc_opt_list alterfunc_opt_list
     432             :                 old_aggr_definition old_aggr_list
     433             :                 oper_argtypes RuleActionList RuleActionMulti
     434             :                 opt_column_list columnList opt_name_list
     435             :                 sort_clause opt_sort_clause sortby_list index_params
     436             :                 stats_params
     437             :                 opt_include opt_c_include index_including_params
     438             :                 name_list role_list from_clause from_list opt_array_bounds
     439             :                 qualified_name_list any_name any_name_list type_name_list
     440             :                 any_operator expr_list attrs
     441             :                 distinct_clause opt_distinct_clause
     442             :                 target_list opt_target_list insert_column_list set_target_list
     443             :                 merge_values_clause
     444             :                 set_clause_list set_clause
     445             :                 def_list operator_def_list indirection opt_indirection
     446             :                 reloption_list TriggerFuncArgs opclass_item_list opclass_drop_list
     447             :                 opclass_purpose opt_opfamily transaction_mode_list_or_empty
     448             :                 OptTableFuncElementList TableFuncElementList opt_type_modifiers
     449             :                 prep_type_clause
     450             :                 execute_param_clause using_clause returning_clause
     451             :                 opt_enum_val_list enum_val_list table_func_column_list
     452             :                 create_generic_options alter_generic_options
     453             :                 relation_expr_list dostmt_opt_list
     454             :                 transform_element_list transform_type_list
     455             :                 TriggerTransitions TriggerReferencing
     456             :                 vacuum_relation_list opt_vacuum_relation_list
     457             :                 drop_option_list pub_obj_list
     458             : 
     459             : %type <node>  opt_routine_body
     460             : %type <groupclause> group_clause
     461             : %type <list>  group_by_list
     462             : %type <node>  group_by_item empty_grouping_set rollup_clause cube_clause
     463             : %type <node>  grouping_sets_clause
     464             : 
     465             : %type <list>  opt_fdw_options fdw_options
     466             : %type <defelt>    fdw_option
     467             : 
     468             : %type <range> OptTempTableName
     469             : %type <into>  into_clause create_as_target create_mv_target
     470             : 
     471             : %type <defelt>    createfunc_opt_item common_func_opt_item dostmt_opt_item
     472             : %type <fun_param> func_arg func_arg_with_default table_func_column aggr_arg
     473             : %type <fun_param_mode> arg_class
     474             : %type <typnam>    func_return func_type
     475             : 
     476             : %type <boolean>  opt_trusted opt_restart_seqs
     477             : %type <ival>   OptTemp
     478             : %type <ival>   OptNoLog
     479             : %type <oncommit> OnCommitOption
     480             : 
     481             : %type <ival>  for_locking_strength
     482             : %type <node>  for_locking_item
     483             : %type <list>  for_locking_clause opt_for_locking_clause for_locking_items
     484             : %type <list>  locked_rels_list
     485             : %type <setquantifier> set_quantifier
     486             : 
     487             : %type <node>  join_qual
     488             : %type <jtype> join_type
     489             : 
     490             : %type <list>  extract_list overlay_list position_list
     491             : %type <list>  substr_list trim_list
     492             : %type <list>  opt_interval interval_second
     493             : %type <str>       unicode_normal_form
     494             : 
     495             : %type <boolean> opt_instead
     496             : %type <boolean> opt_unique opt_verbose opt_full
     497             : %type <boolean> opt_freeze opt_analyze opt_default opt_recheck
     498             : %type <defelt>    opt_binary copy_delimiter
     499             : 
     500             : %type <boolean> copy_from opt_program
     501             : 
     502             : %type <ival>  event cursor_options opt_hold opt_set_data
     503             : %type <objtype>   object_type_any_name object_type_name object_type_name_on_any_name
     504             :                 drop_type_name
     505             : 
     506             : %type <node>  fetch_args select_limit_value
     507             :                 offset_clause select_offset_value
     508             :                 select_fetch_first_value I_or_F_const
     509             : %type <ival>  row_or_rows first_or_next
     510             : 
     511             : %type <list>  OptSeqOptList SeqOptList OptParenthesizedSeqOptList
     512             : %type <defelt>    SeqOptElem
     513             : 
     514             : %type <istmt> insert_rest
     515             : %type <infer> opt_conf_expr
     516             : %type <onconflict> opt_on_conflict
     517             : %type <mergewhen> merge_insert merge_update merge_delete
     518             : 
     519             : %type <node>  merge_when_clause opt_merge_when_condition
     520             : %type <list>  merge_when_list
     521             : 
     522             : %type <vsetstmt> generic_set set_rest set_rest_more generic_reset reset_rest
     523             :                  SetResetClause FunctionSetResetClause
     524             : 
     525             : %type <node>  TableElement TypedTableElement ConstraintElem TableFuncElement
     526             : %type <node>  columnDef columnOptions optionalPeriodName
     527             : %type <defelt>    def_elem reloption_elem old_aggr_elem operator_def_elem
     528             : %type <node>  def_arg columnElem where_clause where_or_current_clause
     529             :                 a_expr b_expr c_expr AexprConst indirection_el opt_slice_bound
     530             :                 columnref in_expr having_clause func_table xmltable array_expr
     531             :                 OptWhereClause operator_def_arg
     532             : %type <list>  opt_column_and_period_list
     533             : %type <list>  rowsfrom_item rowsfrom_list opt_col_def_list
     534             : %type <boolean> opt_ordinality opt_without_overlaps
     535             : %type <list>  ExclusionConstraintList ExclusionConstraintElem
     536             : %type <list>  func_arg_list func_arg_list_opt
     537             : %type <node>  func_arg_expr
     538             : %type <list>  row explicit_row implicit_row type_list array_expr_list
     539             : %type <node>  case_expr case_arg when_clause case_default
     540             : %type <list>  when_clause_list
     541             : %type <node>  opt_search_clause opt_cycle_clause
     542             : %type <ival>  sub_type opt_materialized
     543             : %type <node>  NumericOnly
     544             : %type <list>  NumericOnly_list
     545             : %type <alias> alias_clause opt_alias_clause opt_alias_clause_for_join_using
     546             : %type <list>  func_alias_clause
     547             : %type <sortby>    sortby
     548             : %type <ielem> index_elem index_elem_options
     549             : %type <selem> stats_param
     550             : %type <node>  table_ref
     551             : %type <jexpr> joined_table
     552             : %type <range> relation_expr
     553             : %type <range> extended_relation_expr
     554             : %type <range> relation_expr_opt_alias
     555             : %type <node>  tablesample_clause opt_repeatable_clause
     556             : %type <target>    target_el set_target insert_column_item
     557             : 
     558             : %type <str>       generic_option_name
     559             : %type <node>  generic_option_arg
     560             : %type <defelt>    generic_option_elem alter_generic_option_elem
     561             : %type <list>  generic_option_list alter_generic_option_list
     562             : 
     563             : %type <ival>  reindex_target_relation reindex_target_all
     564             : %type <list>  opt_reindex_option_list
     565             : 
     566             : %type <node>  copy_generic_opt_arg copy_generic_opt_arg_list_item
     567             : %type <defelt>    copy_generic_opt_elem
     568             : %type <list>  copy_generic_opt_list copy_generic_opt_arg_list
     569             : %type <list>  copy_options
     570             : 
     571             : %type <typnam>    Typename SimpleTypename ConstTypename
     572             :                 GenericType Numeric opt_float JsonType
     573             :                 Character ConstCharacter
     574             :                 CharacterWithLength CharacterWithoutLength
     575             :                 ConstDatetime ConstInterval
     576             :                 Bit ConstBit BitWithLength BitWithoutLength
     577             : %type <str>       character
     578             : %type <str>       extract_arg
     579             : %type <boolean> opt_varying opt_timezone opt_no_inherit
     580             : 
     581             : %type <ival>  Iconst SignedIconst
     582             : %type <str>       Sconst comment_text notify_payload
     583             : %type <str>       RoleId opt_boolean_or_string
     584             : %type <list>  var_list
     585             : %type <str>       ColId ColLabel BareColLabel
     586             : %type <str>       NonReservedWord NonReservedWord_or_Sconst
     587             : %type <str>       var_name type_function_name param_name
     588             : %type <str>       createdb_opt_name plassign_target
     589             : %type <node>  var_value zone_value
     590             : %type <rolespec> auth_ident RoleSpec opt_granted_by
     591             : %type <publicationobjectspec> PublicationObjSpec
     592             : 
     593             : %type <keyword> unreserved_keyword type_func_name_keyword
     594             : %type <keyword> col_name_keyword reserved_keyword
     595             : %type <keyword> bare_label_keyword
     596             : 
     597             : %type <node>  TableConstraint TableLikeClause
     598             : %type <ival>  TableLikeOptionList TableLikeOption
     599             : %type <str>       column_compression opt_column_compression column_storage opt_column_storage
     600             : %type <list>  ColQualList
     601             : %type <node>  ColConstraint ColConstraintElem ConstraintAttr
     602             : %type <ival>  key_match
     603             : %type <keyaction> key_delete key_update key_action
     604             : %type <keyactions> key_actions
     605             : %type <ival>  ConstraintAttributeSpec ConstraintAttributeElem
     606             : %type <str>       ExistingIndex
     607             : 
     608             : %type <list>  constraints_set_list
     609             : %type <boolean> constraints_set_mode
     610             : %type <str>       OptTableSpace OptConsTableSpace
     611             : %type <rolespec> OptTableSpaceOwner
     612             : %type <ival>  opt_check_option
     613             : 
     614             : %type <str>       opt_provider security_label
     615             : 
     616             : %type <target>    xml_attribute_el
     617             : %type <list>  xml_attribute_list xml_attributes
     618             : %type <node>  xml_root_version opt_xml_root_standalone
     619             : %type <node>  xmlexists_argument
     620             : %type <ival>  document_or_content
     621             : %type <boolean>   xml_indent_option xml_whitespace_option
     622             : %type <list>  xmltable_column_list xmltable_column_option_list
     623             : %type <node>  xmltable_column_el
     624             : %type <defelt>    xmltable_column_option_el
     625             : %type <list>  xml_namespace_list
     626             : %type <target>    xml_namespace_el
     627             : 
     628             : %type <node>  func_application func_expr_common_subexpr
     629             : %type <node>  func_expr func_expr_windowless
     630             : %type <node>  common_table_expr
     631             : %type <with>  with_clause opt_with_clause
     632             : %type <list>  cte_list
     633             : 
     634             : %type <list>  within_group_clause
     635             : %type <node>  filter_clause
     636             : %type <list>  window_clause window_definition_list opt_partition_clause
     637             : %type <windef>    window_definition over_clause window_specification
     638             :                 opt_frame_clause frame_extent frame_bound
     639             : %type <ival>  opt_window_exclusion_clause
     640             : %type <str>       opt_existing_window_name
     641             : %type <boolean> opt_if_not_exists
     642             : %type <boolean> opt_unique_null_treatment
     643             : %type <ival>  generated_when override_kind
     644             : %type <partspec>  PartitionSpec OptPartitionSpec
     645             : %type <partelem>  part_elem
     646             : %type <list>      part_params
     647             : %type <partboundspec> PartitionBoundSpec
     648             : %type <list>      hash_partbound
     649             : %type <defelt>        hash_partbound_elem
     650             : 
     651             : %type <node>  json_format_clause
     652             :                 json_format_clause_opt
     653             :                 json_value_expr
     654             :                 json_returning_clause_opt
     655             :                 json_name_and_value
     656             :                 json_aggregate_func
     657             :                 json_argument
     658             :                 json_behavior
     659             :                 json_on_error_clause_opt
     660             : %type <list>  json_name_and_value_list
     661             :                 json_value_expr_list
     662             :                 json_array_aggregate_order_by_clause_opt
     663             :                 json_arguments
     664             :                 json_behavior_clause_opt
     665             :                 json_passing_clause_opt
     666             : %type <ival>  json_behavior_type
     667             :                 json_predicate_type_constraint
     668             :                 json_quotes_clause_opt
     669             :                 json_wrapper_behavior
     670             : %type <boolean>   json_key_uniqueness_constraint_opt
     671             :                 json_object_constructor_null_clause_opt
     672             :                 json_array_constructor_null_clause_opt
     673             : 
     674             : 
     675             : /*
     676             :  * Non-keyword token types.  These are hard-wired into the "flex" lexer.
     677             :  * They must be listed first so that their numeric codes do not depend on
     678             :  * the set of keywords.  PL/pgSQL depends on this so that it can share the
     679             :  * same lexer.  If you add/change tokens here, fix PL/pgSQL to match!
     680             :  *
     681             :  * UIDENT and USCONST are reduced to IDENT and SCONST in parser.c, so that
     682             :  * they need no productions here; but we must assign token codes to them.
     683             :  *
     684             :  * DOT_DOT is unused in the core SQL grammar, and so will always provoke
     685             :  * parse errors.  It is needed by PL/pgSQL.
     686             :  */
     687             : %token <str>  IDENT UIDENT FCONST SCONST USCONST BCONST XCONST Op
     688             : %token <ival> ICONST PARAM
     689             : %token          TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
     690             : %token          LESS_EQUALS GREATER_EQUALS NOT_EQUALS
     691             : 
     692             : /*
     693             :  * If you want to make any keyword changes, update the keyword table in
     694             :  * src/include/parser/kwlist.h and add new keywords to the appropriate one
     695             :  * of the reserved-or-not-so-reserved keyword lists, below; search
     696             :  * this file for "Keyword category lists".
     697             :  */
     698             : 
     699             : /* ordinary key words in alphabetical order */
     700             : %token <keyword> ABORT_P ABSENT ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
     701             :     AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
     702             :     ASENSITIVE ASSERTION ASSIGNMENT ASYMMETRIC ATOMIC AT ATTACH ATTRIBUTE AUTHORIZATION
     703             : 
     704             :     BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
     705             :     BOOLEAN_P BOTH BREADTH BY
     706             : 
     707             :     CACHE CALL CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
     708             :     CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
     709             :     CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
     710             :     COMMITTED COMPRESSION CONCURRENTLY CONDITIONAL CONFIGURATION CONFLICT
     711             :     CONNECTION CONSTRAINT CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY
     712             :     COST CREATE CROSS CSV CUBE CURRENT_P
     713             :     CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
     714             :     CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
     715             : 
     716             :     DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
     717             :     DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DEPENDS DEPTH DESC
     718             :     DETACH DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P
     719             :     DOUBLE_P DROP
     720             : 
     721             :     EACH ELSE EMPTY_P ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ERROR_P ESCAPE
     722             :     EVENT EXCEPT EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN EXPRESSION
     723             :     EXTENSION EXTERNAL EXTRACT
     724             : 
     725             :     FALSE_P FAMILY FETCH FILTER FINALIZE FIRST_P FLOAT_P FOLLOWING FOR
     726             :     FORCE FOREIGN FORMAT FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
     727             : 
     728             :     GENERATED GLOBAL GRANT GRANTED GREATEST GROUP_P GROUPING GROUPS
     729             : 
     730             :     HANDLER HAVING HEADER_P HOLD HOUR_P
     731             : 
     732             :     IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P INCLUDE
     733             :     INCLUDING INCREMENT INDENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
     734             :     INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
     735             :     INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
     736             : 
     737             :     JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_EXISTS JSON_OBJECT JSON_OBJECTAGG
     738             :     JSON_QUERY JSON_SCALAR JSON_SERIALIZE JSON_VALUE
     739             : 
     740             :     KEEP KEY KEYS
     741             : 
     742             :     LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
     743             :     LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
     744             :     LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED
     745             : 
     746             :     MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE MERGE_ACTION METHOD
     747             :     MINUTE_P MINVALUE MODE MONTH_P MOVE
     748             : 
     749             :     NAME_P NAMES NATIONAL NATURAL NCHAR NEW NEXT NFC NFD NFKC NFKD NO NONE
     750             :     NORMALIZE NORMALIZED
     751             :     NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
     752             :     NULLS_P NUMERIC
     753             : 
     754             :     OBJECT_P OF OFF OFFSET OIDS OLD OMIT ON ONLY OPERATOR OPTION OPTIONS OR
     755             :     ORDER ORDINALITY OTHERS OUT_P OUTER_P
     756             :     OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
     757             : 
     758             :     PARALLEL PARAMETER PARSER PARTIAL PARTITION PASSING PASSWORD
     759             :     PERIOD PLACING PLANS POLICY
     760             :     POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
     761             :     PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PUBLICATION
     762             : 
     763             :     QUOTE QUOTES
     764             : 
     765             :     RANGE READ REAL REASSIGN RECHECK RECURSIVE REF_P REFERENCES REFERENCING
     766             :     REFRESH REINDEX RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
     767             :     RESET RESTART RESTRICT RETURN RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
     768             :     ROUTINE ROUTINES ROW ROWS RULE
     769             : 
     770             :     SAVEPOINT SCALAR SCHEMA SCHEMAS SCROLL SEARCH SECOND_P SECURITY SELECT
     771             :     SEQUENCE SEQUENCES
     772             :     SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
     773             :     SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SQL_P STABLE STANDALONE_P
     774             :     START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRING_P STRIP_P
     775             :     SUBSCRIPTION SUBSTRING SUPPORT SYMMETRIC SYSID SYSTEM_P SYSTEM_USER
     776             : 
     777             :     TABLE TABLES TABLESAMPLE TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN
     778             :     TIES TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM
     779             :     TREAT TRIGGER TRIM TRUE_P
     780             :     TRUNCATE TRUSTED TYPE_P TYPES_P
     781             : 
     782             :     UESCAPE UNBOUNDED UNCONDITIONAL UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
     783             :     UNLISTEN UNLOGGED UNTIL UPDATE USER USING
     784             : 
     785             :     VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
     786             :     VERBOSE VERSION_P VIEW VIEWS VOLATILE
     787             : 
     788             :     WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
     789             : 
     790             :     XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLNAMESPACES
     791             :     XMLPARSE XMLPI XMLROOT XMLSERIALIZE XMLTABLE
     792             : 
     793             :     YEAR_P YES_P
     794             : 
     795             :     ZONE
     796             : 
     797             : /*
     798             :  * The grammar thinks these are keywords, but they are not in the kwlist.h
     799             :  * list and so can never be entered directly.  The filter in parser.c
     800             :  * creates these tokens when required (based on looking one token ahead).
     801             :  *
     802             :  * NOT_LA exists so that productions such as NOT LIKE can be given the same
     803             :  * precedence as LIKE; otherwise they'd effectively have the same precedence
     804             :  * as NOT, at least with respect to their left-hand subexpression.
     805             :  * FORMAT_LA, NULLS_LA, WITH_LA, and WITHOUT_LA are needed to make the grammar
     806             :  * LALR(1).
     807             :  */
     808             : %token      FORMAT_LA NOT_LA NULLS_LA WITH_LA WITHOUT_LA
     809             : 
     810             : /*
     811             :  * The grammar likewise thinks these tokens are keywords, but they are never
     812             :  * generated by the scanner.  Rather, they can be injected by parser.c as
     813             :  * the initial token of the string (using the lookahead-token mechanism
     814             :  * implemented there).  This provides a way to tell the grammar to parse
     815             :  * something other than the usual list of SQL commands.
     816             :  */
     817             : %token      MODE_TYPE_NAME
     818             : %token      MODE_PLPGSQL_EXPR
     819             : %token      MODE_PLPGSQL_ASSIGN1
     820             : %token      MODE_PLPGSQL_ASSIGN2
     821             : %token      MODE_PLPGSQL_ASSIGN3
     822             : 
     823             : 
     824             : /* Precedence: lowest to highest */
     825             : %left       UNION EXCEPT
     826             : %left       INTERSECT
     827             : %left       OR
     828             : %left       AND
     829             : %right      NOT
     830             : %nonassoc   IS ISNULL NOTNULL   /* IS sets precedence for IS NULL, etc */
     831             : %nonassoc   '<' '>' '=' LESS_EQUALS GREATER_EQUALS NOT_EQUALS
     832             : %nonassoc   BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
     833             : %nonassoc   ESCAPE          /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
     834             : 
     835             : /*
     836             :  * Sometimes it is necessary to assign precedence to keywords that are not
     837             :  * really part of the operator hierarchy, in order to resolve grammar
     838             :  * ambiguities.  It's best to avoid doing so whenever possible, because such
     839             :  * assignments have global effect and may hide ambiguities besides the one
     840             :  * you intended to solve.  (Attaching a precedence to a single rule with
     841             :  * %prec is far safer and should be preferred.)  If you must give precedence
     842             :  * to a new keyword, try very hard to give it the same precedence as IDENT.
     843             :  * If the keyword has IDENT's precedence then it clearly acts the same as
     844             :  * non-keywords and other similar keywords, thus reducing the risk of
     845             :  * unexpected precedence effects.
     846             :  *
     847             :  * We used to need to assign IDENT an explicit precedence just less than Op,
     848             :  * to support target_el without AS.  While that's not really necessary since
     849             :  * we removed postfix operators, we continue to do so because it provides a
     850             :  * reference point for a precedence level that we can assign to other
     851             :  * keywords that lack a natural precedence level.
     852             :  *
     853             :  * We need to do this for PARTITION, RANGE, ROWS, and GROUPS to support
     854             :  * opt_existing_window_name (see comment there).
     855             :  *
     856             :  * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
     857             :  * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
     858             :  * there is no principled way to distinguish these from the productions
     859             :  * a_expr PRECEDING/FOLLOWING.  We hack this up by giving UNBOUNDED slightly
     860             :  * lower precedence than PRECEDING and FOLLOWING.  At present this doesn't
     861             :  * appear to cause UNBOUNDED to be treated differently from other unreserved
     862             :  * keywords anywhere else in the grammar, but it's definitely risky.  We can
     863             :  * blame any funny behavior of UNBOUNDED on the SQL standard, though.
     864             :  *
     865             :  * To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
     866             :  * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
     867             :  * rather than reducing a conflicting rule that takes CUBE as a function name.
     868             :  * Using the same precedence as IDENT seems right for the reasons given above.
     869             :  *
     870             :  * SET is likewise assigned the same precedence as IDENT, to support the
     871             :  * relation_expr_opt_alias production (see comment there).
     872             :  *
     873             :  * KEYS, OBJECT_P, SCALAR, VALUE_P, WITH, and WITHOUT are similarly assigned
     874             :  * the same precedence as IDENT.  This allows resolving conflicts in the
     875             :  * json_predicate_type_constraint and json_key_uniqueness_constraint_opt
     876             :  * productions (see comments there).
     877             :  */
     878             : %nonassoc   UNBOUNDED       /* ideally would have same precedence as IDENT */
     879             : %nonassoc   IDENT PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
     880             :             SET KEYS OBJECT_P SCALAR VALUE_P WITH WITHOUT
     881             : %left       Op OPERATOR     /* multi-character ops and user-defined operators */
     882             : %left       '+' '-'
     883             : %left       '*' '/' '%'
     884             : %left       '^'
     885             : /* Unary Operators */
     886             : %left       AT              /* sets precedence for AT TIME ZONE, AT LOCAL */
     887             : %left       COLLATE
     888             : %right      UMINUS
     889             : %left       '[' ']'
     890             : %left       '(' ')'
     891             : %left       TYPECAST
     892             : %left       '.'
     893             : /*
     894             :  * These might seem to be low-precedence, but actually they are not part
     895             :  * of the arithmetic hierarchy at all in their use as JOIN operators.
     896             :  * We make them high-precedence to support their use as function names.
     897             :  * They wouldn't be given a precedence at all, were it not that we need
     898             :  * left-associativity among the JOIN rules themselves.
     899             :  */
     900             : %left       JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
     901             : 
     902             : %%
     903             : 
     904             : /*
     905             :  *  The target production for the whole parse.
     906             :  *
     907             :  * Ordinarily we parse a list of statements, but if we see one of the
     908             :  * special MODE_XXX symbols as first token, we parse something else.
     909             :  * The options here correspond to enum RawParseMode, which see for details.
     910             :  */
     911             : parse_toplevel:
     912             :             stmtmulti
     913             :             {
     914      669932 :                 pg_yyget_extra(yyscanner)->parsetree = $1;
     915             :                 (void) yynerrs;     /* suppress compiler warning */
     916             :             }
     917             :             | MODE_TYPE_NAME Typename
     918             :             {
     919        9322 :                 pg_yyget_extra(yyscanner)->parsetree = list_make1($2);
     920             :             }
     921             :             | MODE_PLPGSQL_EXPR PLpgSQL_Expr
     922             :             {
     923       29860 :                 pg_yyget_extra(yyscanner)->parsetree =
     924       29860 :                     list_make1(makeRawStmt($2, 0));
     925             :             }
     926             :             | MODE_PLPGSQL_ASSIGN1 PLAssignStmt
     927             :             {
     928        5966 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     929             : 
     930        5966 :                 n->nnames = 1;
     931        5966 :                 pg_yyget_extra(yyscanner)->parsetree =
     932        5966 :                     list_make1(makeRawStmt((Node *) n, 0));
     933             :             }
     934             :             | MODE_PLPGSQL_ASSIGN2 PLAssignStmt
     935             :             {
     936         620 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     937             : 
     938         620 :                 n->nnames = 2;
     939         620 :                 pg_yyget_extra(yyscanner)->parsetree =
     940         620 :                     list_make1(makeRawStmt((Node *) n, 0));
     941             :             }
     942             :             | MODE_PLPGSQL_ASSIGN3 PLAssignStmt
     943             :             {
     944          28 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     945             : 
     946          28 :                 n->nnames = 3;
     947          28 :                 pg_yyget_extra(yyscanner)->parsetree =
     948          28 :                     list_make1(makeRawStmt((Node *) n, 0));
     949             :             }
     950             :         ;
     951             : 
     952             : /*
     953             :  * At top level, we wrap each stmt with a RawStmt node carrying start location
     954             :  * and length of the stmt's text.  Notice that the start loc/len are driven
     955             :  * entirely from semicolon locations (@2).  It would seem natural to use
     956             :  * @1 or @3 to get the true start location of a stmt, but that doesn't work
     957             :  * for statements that can start with empty nonterminals (opt_with_clause is
     958             :  * the main offender here); as noted in the comments for YYLLOC_DEFAULT,
     959             :  * we'd get -1 for the location in such cases.
     960             :  * We also take care to discard empty statements entirely.
     961             :  */
     962             : stmtmulti:  stmtmulti ';' toplevel_stmt
     963             :                 {
     964      542318 :                     if ($1 != NIL)
     965             :                     {
     966             :                         /* update length of previous stmt */
     967      542228 :                         updateRawStmtEnd(llast_node(RawStmt, $1), @2);
     968             :                     }
     969      542318 :                     if ($3 != NULL)
     970       48346 :                         $$ = lappend($1, makeRawStmt($3, @2 + 1));
     971             :                     else
     972      493972 :                         $$ = $1;
     973             :                 }
     974             :             | toplevel_stmt
     975             :                 {
     976      669938 :                     if ($1 != NULL)
     977      669464 :                         $$ = list_make1(makeRawStmt($1, 0));
     978             :                     else
     979         474 :                         $$ = NIL;
     980             :                 }
     981             :         ;
     982             : 
     983             : /*
     984             :  * toplevel_stmt includes BEGIN and END.  stmt does not include them, because
     985             :  * those words have different meanings in function bodies.
     986             :  */
     987             : toplevel_stmt:
     988             :             stmt
     989             :             | TransactionStmtLegacy
     990             :         ;
     991             : 
     992             : stmt:
     993             :             AlterEventTrigStmt
     994             :             | AlterCollationStmt
     995             :             | AlterDatabaseStmt
     996             :             | AlterDatabaseSetStmt
     997             :             | AlterDefaultPrivilegesStmt
     998             :             | AlterDomainStmt
     999             :             | AlterEnumStmt
    1000             :             | AlterExtensionStmt
    1001             :             | AlterExtensionContentsStmt
    1002             :             | AlterFdwStmt
    1003             :             | AlterForeignServerStmt
    1004             :             | AlterFunctionStmt
    1005             :             | AlterGroupStmt
    1006             :             | AlterObjectDependsStmt
    1007             :             | AlterObjectSchemaStmt
    1008             :             | AlterOwnerStmt
    1009             :             | AlterOperatorStmt
    1010             :             | AlterTypeStmt
    1011             :             | AlterPolicyStmt
    1012             :             | AlterSeqStmt
    1013             :             | AlterSystemStmt
    1014             :             | AlterTableStmt
    1015             :             | AlterTblSpcStmt
    1016             :             | AlterCompositeTypeStmt
    1017             :             | AlterPublicationStmt
    1018             :             | AlterRoleSetStmt
    1019             :             | AlterRoleStmt
    1020             :             | AlterSubscriptionStmt
    1021             :             | AlterStatsStmt
    1022             :             | AlterTSConfigurationStmt
    1023             :             | AlterTSDictionaryStmt
    1024             :             | AlterUserMappingStmt
    1025             :             | AnalyzeStmt
    1026             :             | CallStmt
    1027             :             | CheckPointStmt
    1028             :             | ClosePortalStmt
    1029             :             | ClusterStmt
    1030             :             | CommentStmt
    1031             :             | ConstraintsSetStmt
    1032             :             | CopyStmt
    1033             :             | CreateAmStmt
    1034             :             | CreateAsStmt
    1035             :             | CreateAssertionStmt
    1036             :             | CreateCastStmt
    1037             :             | CreateConversionStmt
    1038             :             | CreateDomainStmt
    1039             :             | CreateExtensionStmt
    1040             :             | CreateFdwStmt
    1041             :             | CreateForeignServerStmt
    1042             :             | CreateForeignTableStmt
    1043             :             | CreateFunctionStmt
    1044             :             | CreateGroupStmt
    1045             :             | CreateMatViewStmt
    1046             :             | CreateOpClassStmt
    1047             :             | CreateOpFamilyStmt
    1048             :             | CreatePublicationStmt
    1049             :             | AlterOpFamilyStmt
    1050             :             | CreatePolicyStmt
    1051             :             | CreatePLangStmt
    1052             :             | CreateSchemaStmt
    1053             :             | CreateSeqStmt
    1054             :             | CreateStmt
    1055             :             | CreateSubscriptionStmt
    1056             :             | CreateStatsStmt
    1057             :             | CreateTableSpaceStmt
    1058             :             | CreateTransformStmt
    1059             :             | CreateTrigStmt
    1060             :             | CreateEventTrigStmt
    1061             :             | CreateRoleStmt
    1062             :             | CreateUserStmt
    1063             :             | CreateUserMappingStmt
    1064             :             | CreatedbStmt
    1065             :             | DeallocateStmt
    1066             :             | DeclareCursorStmt
    1067             :             | DefineStmt
    1068             :             | DeleteStmt
    1069             :             | DiscardStmt
    1070             :             | DoStmt
    1071             :             | DropCastStmt
    1072             :             | DropOpClassStmt
    1073             :             | DropOpFamilyStmt
    1074             :             | DropOwnedStmt
    1075             :             | DropStmt
    1076             :             | DropSubscriptionStmt
    1077             :             | DropTableSpaceStmt
    1078             :             | DropTransformStmt
    1079             :             | DropRoleStmt
    1080             :             | DropUserMappingStmt
    1081             :             | DropdbStmt
    1082             :             | ExecuteStmt
    1083             :             | ExplainStmt
    1084             :             | FetchStmt
    1085             :             | GrantStmt
    1086             :             | GrantRoleStmt
    1087             :             | ImportForeignSchemaStmt
    1088             :             | IndexStmt
    1089             :             | InsertStmt
    1090             :             | ListenStmt
    1091             :             | RefreshMatViewStmt
    1092             :             | LoadStmt
    1093             :             | LockStmt
    1094             :             | MergeStmt
    1095             :             | NotifyStmt
    1096             :             | PrepareStmt
    1097             :             | ReassignOwnedStmt
    1098             :             | ReindexStmt
    1099             :             | RemoveAggrStmt
    1100             :             | RemoveFuncStmt
    1101             :             | RemoveOperStmt
    1102             :             | RenameStmt
    1103             :             | RevokeStmt
    1104             :             | RevokeRoleStmt
    1105             :             | RuleStmt
    1106             :             | SecLabelStmt
    1107             :             | SelectStmt
    1108             :             | TransactionStmt
    1109             :             | TruncateStmt
    1110             :             | UnlistenStmt
    1111             :             | UpdateStmt
    1112             :             | VacuumStmt
    1113             :             | VariableResetStmt
    1114             :             | VariableSetStmt
    1115             :             | VariableShowStmt
    1116             :             | ViewStmt
    1117             :             | /*EMPTY*/
    1118      494464 :                 { $$ = NULL; }
    1119             :         ;
    1120             : 
    1121             : /*
    1122             :  * Generic supporting productions for DDL
    1123             :  */
    1124             : opt_single_name:
    1125        5056 :             ColId                           { $$ = $1; }
    1126        1466 :             | /* EMPTY */                   { $$ = NULL; }
    1127             :         ;
    1128             : 
    1129             : opt_qualified_name:
    1130        1666 :             any_name                        { $$ = $1; }
    1131       14034 :             | /*EMPTY*/                     { $$ = NIL; }
    1132             :         ;
    1133             : 
    1134             : opt_concurrently:
    1135         974 :             CONCURRENTLY                    { $$ = true; }
    1136        7166 :             | /*EMPTY*/                     { $$ = false; }
    1137             :         ;
    1138             : 
    1139             : opt_drop_behavior:
    1140        1834 :             CASCADE                         { $$ = DROP_CASCADE; }
    1141         166 :             | RESTRICT                      { $$ = DROP_RESTRICT; }
    1142       33506 :             | /* EMPTY */                   { $$ = DROP_RESTRICT; /* default */ }
    1143             :         ;
    1144             : 
    1145             : /*****************************************************************************
    1146             :  *
    1147             :  * CALL statement
    1148             :  *
    1149             :  *****************************************************************************/
    1150             : 
    1151             : CallStmt:   CALL func_application
    1152             :                 {
    1153         528 :                     CallStmt   *n = makeNode(CallStmt);
    1154             : 
    1155         528 :                     n->funccall = castNode(FuncCall, $2);
    1156         528 :                     $$ = (Node *) n;
    1157             :                 }
    1158             :         ;
    1159             : 
    1160             : /*****************************************************************************
    1161             :  *
    1162             :  * Create a new Postgres DBMS role
    1163             :  *
    1164             :  *****************************************************************************/
    1165             : 
    1166             : CreateRoleStmt:
    1167             :             CREATE ROLE RoleId opt_with OptRoleList
    1168             :                 {
    1169        1238 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1170             : 
    1171        1238 :                     n->stmt_type = ROLESTMT_ROLE;
    1172        1238 :                     n->role = $3;
    1173        1238 :                     n->options = $5;
    1174        1238 :                     $$ = (Node *) n;
    1175             :                 }
    1176             :         ;
    1177             : 
    1178             : 
    1179             : opt_with:   WITH
    1180             :             | WITH_LA
    1181             :             | /*EMPTY*/
    1182             :         ;
    1183             : 
    1184             : /*
    1185             :  * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
    1186             :  * for backwards compatibility).  Note: the only option required by SQL99
    1187             :  * is "WITH ADMIN name".
    1188             :  */
    1189             : OptRoleList:
    1190        1146 :             OptRoleList CreateOptRoleElem           { $$ = lappend($1, $2); }
    1191        1686 :             | /* EMPTY */                           { $$ = NIL; }
    1192             :         ;
    1193             : 
    1194             : AlterOptRoleList:
    1195         572 :             AlterOptRoleList AlterOptRoleElem       { $$ = lappend($1, $2); }
    1196         392 :             | /* EMPTY */                           { $$ = NIL; }
    1197             :         ;
    1198             : 
    1199             : AlterOptRoleElem:
    1200             :             PASSWORD Sconst
    1201             :                 {
    1202         162 :                     $$ = makeDefElem("password",
    1203         162 :                                      (Node *) makeString($2), @1);
    1204             :                 }
    1205             :             | PASSWORD NULL_P
    1206             :                 {
    1207          12 :                     $$ = makeDefElem("password", NULL, @1);
    1208             :                 }
    1209             :             | ENCRYPTED PASSWORD Sconst
    1210             :                 {
    1211             :                     /*
    1212             :                      * These days, passwords are always stored in encrypted
    1213             :                      * form, so there is no difference between PASSWORD and
    1214             :                      * ENCRYPTED PASSWORD.
    1215             :                      */
    1216          16 :                     $$ = makeDefElem("password",
    1217          16 :                                      (Node *) makeString($3), @1);
    1218             :                 }
    1219             :             | UNENCRYPTED PASSWORD Sconst
    1220             :                 {
    1221           0 :                     ereport(ERROR,
    1222             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1223             :                              errmsg("UNENCRYPTED PASSWORD is no longer supported"),
    1224             :                              errhint("Remove UNENCRYPTED to store the password in encrypted form instead."),
    1225             :                              parser_errposition(@1)));
    1226             :                 }
    1227             :             | INHERIT
    1228             :                 {
    1229          86 :                     $$ = makeDefElem("inherit", (Node *) makeBoolean(true), @1);
    1230             :                 }
    1231             :             | CONNECTION LIMIT SignedIconst
    1232             :                 {
    1233          24 :                     $$ = makeDefElem("connectionlimit", (Node *) makeInteger($3), @1);
    1234             :                 }
    1235             :             | VALID UNTIL Sconst
    1236             :                 {
    1237           2 :                     $$ = makeDefElem("validUntil", (Node *) makeString($3), @1);
    1238             :                 }
    1239             :         /*  Supported but not documented for roles, for use by ALTER GROUP. */
    1240             :             | USER role_list
    1241             :                 {
    1242           6 :                     $$ = makeDefElem("rolemembers", (Node *) $2, @1);
    1243             :                 }
    1244             :             | IDENT
    1245             :                 {
    1246             :                     /*
    1247             :                      * We handle identifiers that aren't parser keywords with
    1248             :                      * the following special-case codes, to avoid bloating the
    1249             :                      * size of the main parser.
    1250             :                      */
    1251        1266 :                     if (strcmp($1, "superuser") == 0)
    1252         172 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(true), @1);
    1253        1094 :                     else if (strcmp($1, "nosuperuser") == 0)
    1254         100 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(false), @1);
    1255         994 :                     else if (strcmp($1, "createrole") == 0)
    1256          92 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(true), @1);
    1257         902 :                     else if (strcmp($1, "nocreaterole") == 0)
    1258          38 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(false), @1);
    1259         864 :                     else if (strcmp($1, "replication") == 0)
    1260         120 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(true), @1);
    1261         744 :                     else if (strcmp($1, "noreplication") == 0)
    1262          96 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(false), @1);
    1263         648 :                     else if (strcmp($1, "createdb") == 0)
    1264          82 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(true), @1);
    1265         566 :                     else if (strcmp($1, "nocreatedb") == 0)
    1266          46 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(false), @1);
    1267         520 :                     else if (strcmp($1, "login") == 0)
    1268         258 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(true), @1);
    1269         262 :                     else if (strcmp($1, "nologin") == 0)
    1270          86 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(false), @1);
    1271         176 :                     else if (strcmp($1, "bypassrls") == 0)
    1272          72 :                         $$ = makeDefElem("bypassrls", (Node *) makeBoolean(true), @1);
    1273         104 :                     else if (strcmp($1, "nobypassrls") == 0)
    1274          68 :                         $$ = makeDefElem("bypassrls", (Node *) makeBoolean(false), @1);
    1275          36 :                     else if (strcmp($1, "noinherit") == 0)
    1276             :                     {
    1277             :                         /*
    1278             :                          * Note that INHERIT is a keyword, so it's handled by main parser, but
    1279             :                          * NOINHERIT is handled here.
    1280             :                          */
    1281          36 :                         $$ = makeDefElem("inherit", (Node *) makeBoolean(false), @1);
    1282             :                     }
    1283             :                     else
    1284           0 :                         ereport(ERROR,
    1285             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    1286             :                                  errmsg("unrecognized role option \"%s\"", $1),
    1287             :                                      parser_errposition(@1)));
    1288             :                 }
    1289             :         ;
    1290             : 
    1291             : CreateOptRoleElem:
    1292        1002 :             AlterOptRoleElem            { $$ = $1; }
    1293             :             /* The following are not supported by ALTER ROLE/USER/GROUP */
    1294             :             | SYSID Iconst
    1295             :                 {
    1296           6 :                     $$ = makeDefElem("sysid", (Node *) makeInteger($2), @1);
    1297             :                 }
    1298             :             | ADMIN role_list
    1299             :                 {
    1300          22 :                     $$ = makeDefElem("adminmembers", (Node *) $2, @1);
    1301             :                 }
    1302             :             | ROLE role_list
    1303             :                 {
    1304          16 :                     $$ = makeDefElem("rolemembers", (Node *) $2, @1);
    1305             :                 }
    1306             :             | IN_P ROLE role_list
    1307             :                 {
    1308         100 :                     $$ = makeDefElem("addroleto", (Node *) $3, @1);
    1309             :                 }
    1310             :             | IN_P GROUP_P role_list
    1311             :                 {
    1312           0 :                     $$ = makeDefElem("addroleto", (Node *) $3, @1);
    1313             :                 }
    1314             :         ;
    1315             : 
    1316             : 
    1317             : /*****************************************************************************
    1318             :  *
    1319             :  * Create a new Postgres DBMS user (role with implied login ability)
    1320             :  *
    1321             :  *****************************************************************************/
    1322             : 
    1323             : CreateUserStmt:
    1324             :             CREATE USER RoleId opt_with OptRoleList
    1325             :                 {
    1326         424 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1327             : 
    1328         424 :                     n->stmt_type = ROLESTMT_USER;
    1329         424 :                     n->role = $3;
    1330         424 :                     n->options = $5;
    1331         424 :                     $$ = (Node *) n;
    1332             :                 }
    1333             :         ;
    1334             : 
    1335             : 
    1336             : /*****************************************************************************
    1337             :  *
    1338             :  * Alter a postgresql DBMS role
    1339             :  *
    1340             :  *****************************************************************************/
    1341             : 
    1342             : AlterRoleStmt:
    1343             :             ALTER ROLE RoleSpec opt_with AlterOptRoleList
    1344             :                  {
    1345         306 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1346             : 
    1347         306 :                     n->role = $3;
    1348         306 :                     n->action = +1;  /* add, if there are members */
    1349         306 :                     n->options = $5;
    1350         306 :                     $$ = (Node *) n;
    1351             :                  }
    1352             :             | ALTER USER RoleSpec opt_with AlterOptRoleList
    1353             :                  {
    1354          86 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1355             : 
    1356          86 :                     n->role = $3;
    1357          86 :                     n->action = +1;  /* add, if there are members */
    1358          86 :                     n->options = $5;
    1359          86 :                     $$ = (Node *) n;
    1360             :                  }
    1361             :         ;
    1362             : 
    1363             : opt_in_database:
    1364          82 :                /* EMPTY */                  { $$ = NULL; }
    1365           0 :             | IN_P DATABASE name    { $$ = $3; }
    1366             :         ;
    1367             : 
    1368             : AlterRoleSetStmt:
    1369             :             ALTER ROLE RoleSpec opt_in_database SetResetClause
    1370             :                 {
    1371          44 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1372             : 
    1373          44 :                     n->role = $3;
    1374          44 :                     n->database = $4;
    1375          44 :                     n->setstmt = $5;
    1376          44 :                     $$ = (Node *) n;
    1377             :                 }
    1378             :             | ALTER ROLE ALL opt_in_database SetResetClause
    1379             :                 {
    1380           4 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1381             : 
    1382           4 :                     n->role = NULL;
    1383           4 :                     n->database = $4;
    1384           4 :                     n->setstmt = $5;
    1385           4 :                     $$ = (Node *) n;
    1386             :                 }
    1387             :             | ALTER USER RoleSpec opt_in_database SetResetClause
    1388             :                 {
    1389          26 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1390             : 
    1391          26 :                     n->role = $3;
    1392          26 :                     n->database = $4;
    1393          26 :                     n->setstmt = $5;
    1394          26 :                     $$ = (Node *) n;
    1395             :                 }
    1396             :             | ALTER USER ALL opt_in_database SetResetClause
    1397             :                 {
    1398           4 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1399             : 
    1400           4 :                     n->role = NULL;
    1401           4 :                     n->database = $4;
    1402           4 :                     n->setstmt = $5;
    1403           4 :                     $$ = (Node *) n;
    1404             :                 }
    1405             :         ;
    1406             : 
    1407             : 
    1408             : /*****************************************************************************
    1409             :  *
    1410             :  * Drop a postgresql DBMS role
    1411             :  *
    1412             :  * XXX Ideally this would have CASCADE/RESTRICT options, but a role
    1413             :  * might own objects in multiple databases, and there is presently no way to
    1414             :  * implement cascading to other databases.  So we always behave as RESTRICT.
    1415             :  *****************************************************************************/
    1416             : 
    1417             : DropRoleStmt:
    1418             :             DROP ROLE role_list
    1419             :                 {
    1420        1038 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1421             : 
    1422        1038 :                     n->missing_ok = false;
    1423        1038 :                     n->roles = $3;
    1424        1038 :                     $$ = (Node *) n;
    1425             :                 }
    1426             :             | DROP ROLE IF_P EXISTS role_list
    1427             :                 {
    1428         134 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1429             : 
    1430         134 :                     n->missing_ok = true;
    1431         134 :                     n->roles = $5;
    1432         134 :                     $$ = (Node *) n;
    1433             :                 }
    1434             :             | DROP USER role_list
    1435             :                 {
    1436         394 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1437             : 
    1438         394 :                     n->missing_ok = false;
    1439         394 :                     n->roles = $3;
    1440         394 :                     $$ = (Node *) n;
    1441             :                 }
    1442             :             | DROP USER IF_P EXISTS role_list
    1443             :                 {
    1444          36 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1445             : 
    1446          36 :                     n->roles = $5;
    1447          36 :                     n->missing_ok = true;
    1448          36 :                     $$ = (Node *) n;
    1449             :                 }
    1450             :             | DROP GROUP_P role_list
    1451             :                 {
    1452          36 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1453             : 
    1454          36 :                     n->missing_ok = false;
    1455          36 :                     n->roles = $3;
    1456          36 :                     $$ = (Node *) n;
    1457             :                 }
    1458             :             | DROP GROUP_P IF_P EXISTS role_list
    1459             :                 {
    1460           6 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1461             : 
    1462           6 :                     n->missing_ok = true;
    1463           6 :                     n->roles = $5;
    1464           6 :                     $$ = (Node *) n;
    1465             :                 }
    1466             :             ;
    1467             : 
    1468             : 
    1469             : /*****************************************************************************
    1470             :  *
    1471             :  * Create a postgresql group (role without login ability)
    1472             :  *
    1473             :  *****************************************************************************/
    1474             : 
    1475             : CreateGroupStmt:
    1476             :             CREATE GROUP_P RoleId opt_with OptRoleList
    1477             :                 {
    1478          24 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1479             : 
    1480          24 :                     n->stmt_type = ROLESTMT_GROUP;
    1481          24 :                     n->role = $3;
    1482          24 :                     n->options = $5;
    1483          24 :                     $$ = (Node *) n;
    1484             :                 }
    1485             :         ;
    1486             : 
    1487             : 
    1488             : /*****************************************************************************
    1489             :  *
    1490             :  * Alter a postgresql group
    1491             :  *
    1492             :  *****************************************************************************/
    1493             : 
    1494             : AlterGroupStmt:
    1495             :             ALTER GROUP_P RoleSpec add_drop USER role_list
    1496             :                 {
    1497          30 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1498             : 
    1499          30 :                     n->role = $3;
    1500          30 :                     n->action = $4;
    1501          30 :                     n->options = list_make1(makeDefElem("rolemembers",
    1502             :                                                         (Node *) $6, @6));
    1503          30 :                     $$ = (Node *) n;
    1504             :                 }
    1505             :         ;
    1506             : 
    1507          80 : add_drop:   ADD_P                                   { $$ = +1; }
    1508         150 :             | DROP                                  { $$ = -1; }
    1509             :         ;
    1510             : 
    1511             : 
    1512             : /*****************************************************************************
    1513             :  *
    1514             :  * Manipulate a schema
    1515             :  *
    1516             :  *****************************************************************************/
    1517             : 
    1518             : CreateSchemaStmt:
    1519             :             CREATE SCHEMA opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
    1520             :                 {
    1521         158 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1522             : 
    1523             :                     /* One can omit the schema name or the authorization id. */
    1524         158 :                     n->schemaname = $3;
    1525         158 :                     n->authrole = $5;
    1526         158 :                     n->schemaElts = $6;
    1527         158 :                     n->if_not_exists = false;
    1528         158 :                     $$ = (Node *) n;
    1529             :                 }
    1530             :             | CREATE SCHEMA ColId OptSchemaEltList
    1531             :                 {
    1532         758 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1533             : 
    1534             :                     /* ...but not both */
    1535         758 :                     n->schemaname = $3;
    1536         758 :                     n->authrole = NULL;
    1537         758 :                     n->schemaElts = $4;
    1538         758 :                     n->if_not_exists = false;
    1539         758 :                     $$ = (Node *) n;
    1540             :                 }
    1541             :             | CREATE SCHEMA IF_P NOT EXISTS opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
    1542             :                 {
    1543          18 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1544             : 
    1545             :                     /* schema name can be omitted here, too */
    1546          18 :                     n->schemaname = $6;
    1547          18 :                     n->authrole = $8;
    1548          18 :                     if ($9 != NIL)
    1549           0 :                         ereport(ERROR,
    1550             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1551             :                                  errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
    1552             :                                  parser_errposition(@9)));
    1553          18 :                     n->schemaElts = $9;
    1554          18 :                     n->if_not_exists = true;
    1555          18 :                     $$ = (Node *) n;
    1556             :                 }
    1557             :             | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
    1558             :                 {
    1559          34 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1560             : 
    1561             :                     /* ...but not here */
    1562          34 :                     n->schemaname = $6;
    1563          34 :                     n->authrole = NULL;
    1564          34 :                     if ($7 != NIL)
    1565           6 :                         ereport(ERROR,
    1566             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1567             :                                  errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
    1568             :                                  parser_errposition(@7)));
    1569          28 :                     n->schemaElts = $7;
    1570          28 :                     n->if_not_exists = true;
    1571          28 :                     $$ = (Node *) n;
    1572             :                 }
    1573             :         ;
    1574             : 
    1575             : OptSchemaEltList:
    1576             :             OptSchemaEltList schema_stmt
    1577             :                 {
    1578         480 :                     if (@$ < 0)          /* see comments for YYLLOC_DEFAULT */
    1579         222 :                         @$ = @2;
    1580         480 :                     $$ = lappend($1, $2);
    1581             :                 }
    1582             :             | /* EMPTY */
    1583         968 :                 { $$ = NIL; }
    1584             :         ;
    1585             : 
    1586             : /*
    1587             :  *  schema_stmt are the ones that can show up inside a CREATE SCHEMA
    1588             :  *  statement (in addition to by themselves).
    1589             :  */
    1590             : schema_stmt:
    1591             :             CreateStmt
    1592             :             | IndexStmt
    1593             :             | CreateSeqStmt
    1594             :             | CreateTrigStmt
    1595             :             | GrantStmt
    1596             :             | ViewStmt
    1597             :         ;
    1598             : 
    1599             : 
    1600             : /*****************************************************************************
    1601             :  *
    1602             :  * Set PG internal variable
    1603             :  *    SET name TO 'var_value'
    1604             :  * Include SQL syntax (thomas 1997-10-22):
    1605             :  *    SET TIME ZONE 'var_value'
    1606             :  *
    1607             :  *****************************************************************************/
    1608             : 
    1609             : VariableSetStmt:
    1610             :             SET set_rest
    1611             :                 {
    1612       18424 :                     VariableSetStmt *n = $2;
    1613             : 
    1614       18424 :                     n->is_local = false;
    1615       18424 :                     $$ = (Node *) n;
    1616             :                 }
    1617             :             | SET LOCAL set_rest
    1618             :                 {
    1619        1106 :                     VariableSetStmt *n = $3;
    1620             : 
    1621        1106 :                     n->is_local = true;
    1622        1106 :                     $$ = (Node *) n;
    1623             :                 }
    1624             :             | SET SESSION set_rest
    1625             :                 {
    1626          80 :                     VariableSetStmt *n = $3;
    1627             : 
    1628          80 :                     n->is_local = false;
    1629          80 :                     $$ = (Node *) n;
    1630             :                 }
    1631             :         ;
    1632             : 
    1633             : set_rest:
    1634             :             TRANSACTION transaction_mode_list
    1635             :                 {
    1636         518 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1637             : 
    1638         518 :                     n->kind = VAR_SET_MULTI;
    1639         518 :                     n->name = "TRANSACTION";
    1640         518 :                     n->args = $2;
    1641         518 :                     $$ = n;
    1642             :                 }
    1643             :             | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
    1644             :                 {
    1645          12 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1646             : 
    1647          12 :                     n->kind = VAR_SET_MULTI;
    1648          12 :                     n->name = "SESSION CHARACTERISTICS";
    1649          12 :                     n->args = $5;
    1650          12 :                     $$ = n;
    1651             :                 }
    1652             :             | set_rest_more
    1653             :             ;
    1654             : 
    1655             : generic_set:
    1656             :             var_name TO var_list
    1657             :                 {
    1658        4374 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1659             : 
    1660        4374 :                     n->kind = VAR_SET_VALUE;
    1661        4374 :                     n->name = $1;
    1662        4374 :                     n->args = $3;
    1663        4374 :                     $$ = n;
    1664             :                 }
    1665             :             | var_name '=' var_list
    1666             :                 {
    1667       12418 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1668             : 
    1669       12418 :                     n->kind = VAR_SET_VALUE;
    1670       12418 :                     n->name = $1;
    1671       12418 :                     n->args = $3;
    1672       12418 :                     $$ = n;
    1673             :                 }
    1674             :             | var_name TO DEFAULT
    1675             :                 {
    1676         126 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1677             : 
    1678         126 :                     n->kind = VAR_SET_DEFAULT;
    1679         126 :                     n->name = $1;
    1680         126 :                     $$ = n;
    1681             :                 }
    1682             :             | var_name '=' DEFAULT
    1683             :                 {
    1684           6 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1685             : 
    1686           6 :                     n->kind = VAR_SET_DEFAULT;
    1687           6 :                     n->name = $1;
    1688           6 :                     $$ = n;
    1689             :                 }
    1690             :         ;
    1691             : 
    1692             : set_rest_more:  /* Generic SET syntaxes: */
    1693       16818 :             generic_set                         {$$ = $1;}
    1694             :             | var_name FROM CURRENT_P
    1695             :                 {
    1696           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1697             : 
    1698           0 :                     n->kind = VAR_SET_CURRENT;
    1699           0 :                     n->name = $1;
    1700           0 :                     $$ = n;
    1701             :                 }
    1702             :             /* Special syntaxes mandated by SQL standard: */
    1703             :             | TIME ZONE zone_value
    1704             :                 {
    1705          94 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1706             : 
    1707          94 :                     n->kind = VAR_SET_VALUE;
    1708          94 :                     n->name = "timezone";
    1709          94 :                     if ($3 != NULL)
    1710          82 :                         n->args = list_make1($3);
    1711             :                     else
    1712          12 :                         n->kind = VAR_SET_DEFAULT;
    1713          94 :                     $$ = n;
    1714             :                 }
    1715             :             | CATALOG_P Sconst
    1716             :                 {
    1717           0 :                     ereport(ERROR,
    1718             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1719             :                              errmsg("current database cannot be changed"),
    1720             :                              parser_errposition(@2)));
    1721             :                     $$ = NULL; /*not reached*/
    1722             :                 }
    1723             :             | SCHEMA Sconst
    1724             :                 {
    1725           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1726             : 
    1727           0 :                     n->kind = VAR_SET_VALUE;
    1728           0 :                     n->name = "search_path";
    1729           0 :                     n->args = list_make1(makeStringConst($2, @2));
    1730           0 :                     $$ = n;
    1731             :                 }
    1732             :             | NAMES opt_encoding
    1733             :                 {
    1734           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1735             : 
    1736           0 :                     n->kind = VAR_SET_VALUE;
    1737           0 :                     n->name = "client_encoding";
    1738           0 :                     if ($2 != NULL)
    1739           0 :                         n->args = list_make1(makeStringConst($2, @2));
    1740             :                     else
    1741           0 :                         n->kind = VAR_SET_DEFAULT;
    1742           0 :                     $$ = n;
    1743             :                 }
    1744             :             | ROLE NonReservedWord_or_Sconst
    1745             :                 {
    1746         822 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1747             : 
    1748         822 :                     n->kind = VAR_SET_VALUE;
    1749         822 :                     n->name = "role";
    1750         822 :                     n->args = list_make1(makeStringConst($2, @2));
    1751         822 :                     $$ = n;
    1752             :                 }
    1753             :             | SESSION AUTHORIZATION NonReservedWord_or_Sconst
    1754             :                 {
    1755        2494 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1756             : 
    1757        2494 :                     n->kind = VAR_SET_VALUE;
    1758        2494 :                     n->name = "session_authorization";
    1759        2494 :                     n->args = list_make1(makeStringConst($3, @3));
    1760        2494 :                     $$ = n;
    1761             :                 }
    1762             :             | SESSION AUTHORIZATION DEFAULT
    1763             :                 {
    1764           4 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1765             : 
    1766           4 :                     n->kind = VAR_SET_DEFAULT;
    1767           4 :                     n->name = "session_authorization";
    1768           4 :                     $$ = n;
    1769             :                 }
    1770             :             | XML_P OPTION document_or_content
    1771             :                 {
    1772          12 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1773             : 
    1774          12 :                     n->kind = VAR_SET_VALUE;
    1775          12 :                     n->name = "xmloption";
    1776          12 :                     n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
    1777          12 :                     $$ = n;
    1778             :                 }
    1779             :             /* Special syntaxes invented by PostgreSQL: */
    1780             :             | TRANSACTION SNAPSHOT Sconst
    1781             :                 {
    1782          44 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1783             : 
    1784          44 :                     n->kind = VAR_SET_MULTI;
    1785          44 :                     n->name = "TRANSACTION SNAPSHOT";
    1786          44 :                     n->args = list_make1(makeStringConst($3, @3));
    1787          44 :                     $$ = n;
    1788             :                 }
    1789             :         ;
    1790             : 
    1791       20978 : var_name:   ColId                               { $$ = $1; }
    1792             :             | var_name '.' ColId
    1793         386 :                 { $$ = psprintf("%s.%s", $1, $3); }
    1794             :         ;
    1795             : 
    1796       16792 : var_list:   var_value                               { $$ = list_make1($1); }
    1797         166 :             | var_list ',' var_value                { $$ = lappend($1, $3); }
    1798             :         ;
    1799             : 
    1800             : var_value:  opt_boolean_or_string
    1801       12718 :                 { $$ = makeStringConst($1, @1); }
    1802             :             | NumericOnly
    1803        4240 :                 { $$ = makeAConst($1, @1); }
    1804             :         ;
    1805             : 
    1806           0 : iso_level:  READ UNCOMMITTED                        { $$ = "read uncommitted"; }
    1807         886 :             | READ COMMITTED                        { $$ = "read committed"; }
    1808        2432 :             | REPEATABLE READ                       { $$ = "repeatable read"; }
    1809        3196 :             | SERIALIZABLE                          { $$ = "serializable"; }
    1810             :         ;
    1811             : 
    1812             : opt_boolean_or_string:
    1813         550 :             TRUE_P                                  { $$ = "true"; }
    1814        1260 :             | FALSE_P                               { $$ = "false"; }
    1815        1896 :             | ON                                    { $$ = "on"; }
    1816             :             /*
    1817             :              * OFF is also accepted as a boolean value, but is handled by
    1818             :              * the NonReservedWord rule.  The action for booleans and strings
    1819             :              * is the same, so we don't need to distinguish them here.
    1820             :              */
    1821       25080 :             | NonReservedWord_or_Sconst             { $$ = $1; }
    1822             :         ;
    1823             : 
    1824             : /* Timezone values can be:
    1825             :  * - a string such as 'pst8pdt'
    1826             :  * - an identifier such as "pst8pdt"
    1827             :  * - an integer or floating point number
    1828             :  * - a time interval per SQL99
    1829             :  * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
    1830             :  * so use IDENT (meaning we reject anything that is a key word).
    1831             :  */
    1832             : zone_value:
    1833             :             Sconst
    1834             :                 {
    1835          54 :                     $$ = makeStringConst($1, @1);
    1836             :                 }
    1837             :             | IDENT
    1838             :                 {
    1839           4 :                     $$ = makeStringConst($1, @1);
    1840             :                 }
    1841             :             | ConstInterval Sconst opt_interval
    1842             :                 {
    1843           0 :                     TypeName   *t = $1;
    1844             : 
    1845           0 :                     if ($3 != NIL)
    1846             :                     {
    1847           0 :                         A_Const    *n = (A_Const *) linitial($3);
    1848             : 
    1849           0 :                         if ((n->val.ival.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
    1850           0 :                             ereport(ERROR,
    1851             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    1852             :                                      errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
    1853             :                                      parser_errposition(@3)));
    1854             :                     }
    1855           0 :                     t->typmods = $3;
    1856           0 :                     $$ = makeStringConstCast($2, @2, t);
    1857             :                 }
    1858             :             | ConstInterval '(' Iconst ')' Sconst
    1859             :                 {
    1860           0 :                     TypeName   *t = $1;
    1861             : 
    1862           0 :                     t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
    1863             :                                             makeIntConst($3, @3));
    1864           0 :                     $$ = makeStringConstCast($5, @5, t);
    1865             :                 }
    1866          24 :             | NumericOnly                           { $$ = makeAConst($1, @1); }
    1867          12 :             | DEFAULT                               { $$ = NULL; }
    1868           0 :             | LOCAL                                 { $$ = NULL; }
    1869             :         ;
    1870             : 
    1871             : opt_encoding:
    1872           0 :             Sconst                                  { $$ = $1; }
    1873           0 :             | DEFAULT                               { $$ = NULL; }
    1874           0 :             | /*EMPTY*/                             { $$ = NULL; }
    1875             :         ;
    1876             : 
    1877             : NonReservedWord_or_Sconst:
    1878       44338 :             NonReservedWord                         { $$ = $1; }
    1879        4714 :             | Sconst                                { $$ = $1; }
    1880             :         ;
    1881             : 
    1882             : VariableResetStmt:
    1883        3976 :             RESET reset_rest                        { $$ = (Node *) $2; }
    1884             :         ;
    1885             : 
    1886             : reset_rest:
    1887        3220 :             generic_reset                           { $$ = $1; }
    1888             :             | TIME ZONE
    1889             :                 {
    1890          12 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1891             : 
    1892          12 :                     n->kind = VAR_RESET;
    1893          12 :                     n->name = "timezone";
    1894          12 :                     $$ = n;
    1895             :                 }
    1896             :             | TRANSACTION ISOLATION LEVEL
    1897             :                 {
    1898           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1899             : 
    1900           0 :                     n->kind = VAR_RESET;
    1901           0 :                     n->name = "transaction_isolation";
    1902           0 :                     $$ = n;
    1903             :                 }
    1904             :             | SESSION AUTHORIZATION
    1905             :                 {
    1906         744 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1907             : 
    1908         744 :                     n->kind = VAR_RESET;
    1909         744 :                     n->name = "session_authorization";
    1910         744 :                     $$ = n;
    1911             :                 }
    1912             :         ;
    1913             : 
    1914             : generic_reset:
    1915             :             var_name
    1916             :                 {
    1917        3252 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1918             : 
    1919        3252 :                     n->kind = VAR_RESET;
    1920        3252 :                     n->name = $1;
    1921        3252 :                     $$ = n;
    1922             :                 }
    1923             :             | ALL
    1924             :                 {
    1925          16 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1926             : 
    1927          16 :                     n->kind = VAR_RESET_ALL;
    1928          16 :                     $$ = n;
    1929             :                 }
    1930             :         ;
    1931             : 
    1932             : /* SetResetClause allows SET or RESET without LOCAL */
    1933             : SetResetClause:
    1934        1108 :             SET set_rest                    { $$ = $2; }
    1935          28 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    1936             :         ;
    1937             : 
    1938             : /* SetResetClause allows SET or RESET without LOCAL */
    1939             : FunctionSetResetClause:
    1940         100 :             SET set_rest_more               { $$ = $2; }
    1941          12 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    1942             :         ;
    1943             : 
    1944             : 
    1945             : VariableShowStmt:
    1946             :             SHOW var_name
    1947             :                 {
    1948         802 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1949             : 
    1950         802 :                     n->name = $2;
    1951         802 :                     $$ = (Node *) n;
    1952             :                 }
    1953             :             | SHOW TIME ZONE
    1954             :                 {
    1955          10 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1956             : 
    1957          10 :                     n->name = "timezone";
    1958          10 :                     $$ = (Node *) n;
    1959             :                 }
    1960             :             | SHOW TRANSACTION ISOLATION LEVEL
    1961             :                 {
    1962           4 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1963             : 
    1964           4 :                     n->name = "transaction_isolation";
    1965           4 :                     $$ = (Node *) n;
    1966             :                 }
    1967             :             | SHOW SESSION AUTHORIZATION
    1968             :                 {
    1969           0 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1970             : 
    1971           0 :                     n->name = "session_authorization";
    1972           0 :                     $$ = (Node *) n;
    1973             :                 }
    1974             :             | SHOW ALL
    1975             :                 {
    1976           0 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1977             : 
    1978           0 :                     n->name = "all";
    1979           0 :                     $$ = (Node *) n;
    1980             :                 }
    1981             :         ;
    1982             : 
    1983             : 
    1984             : ConstraintsSetStmt:
    1985             :             SET CONSTRAINTS constraints_set_list constraints_set_mode
    1986             :                 {
    1987         104 :                     ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
    1988             : 
    1989         104 :                     n->constraints = $3;
    1990         104 :                     n->deferred = $4;
    1991         104 :                     $$ = (Node *) n;
    1992             :                 }
    1993             :         ;
    1994             : 
    1995             : constraints_set_list:
    1996          56 :             ALL                                     { $$ = NIL; }
    1997          48 :             | qualified_name_list                   { $$ = $1; }
    1998             :         ;
    1999             : 
    2000             : constraints_set_mode:
    2001          68 :             DEFERRED                                { $$ = true; }
    2002          36 :             | IMMEDIATE                             { $$ = false; }
    2003             :         ;
    2004             : 
    2005             : 
    2006             : /*
    2007             :  * Checkpoint statement
    2008             :  */
    2009             : CheckPointStmt:
    2010             :             CHECKPOINT
    2011             :                 {
    2012         188 :                     CheckPointStmt *n = makeNode(CheckPointStmt);
    2013             : 
    2014         188 :                     $$ = (Node *) n;
    2015             :                 }
    2016             :         ;
    2017             : 
    2018             : 
    2019             : /*****************************************************************************
    2020             :  *
    2021             :  * DISCARD { ALL | TEMP | PLANS | SEQUENCES }
    2022             :  *
    2023             :  *****************************************************************************/
    2024             : 
    2025             : DiscardStmt:
    2026             :             DISCARD ALL
    2027             :                 {
    2028           6 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2029             : 
    2030           6 :                     n->target = DISCARD_ALL;
    2031           6 :                     $$ = (Node *) n;
    2032             :                 }
    2033             :             | DISCARD TEMP
    2034             :                 {
    2035           8 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2036             : 
    2037           8 :                     n->target = DISCARD_TEMP;
    2038           8 :                     $$ = (Node *) n;
    2039             :                 }
    2040             :             | DISCARD TEMPORARY
    2041             :                 {
    2042           0 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2043             : 
    2044           0 :                     n->target = DISCARD_TEMP;
    2045           0 :                     $$ = (Node *) n;
    2046             :                 }
    2047             :             | DISCARD PLANS
    2048             :                 {
    2049           4 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2050             : 
    2051           4 :                     n->target = DISCARD_PLANS;
    2052           4 :                     $$ = (Node *) n;
    2053             :                 }
    2054             :             | DISCARD SEQUENCES
    2055             :                 {
    2056          12 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2057             : 
    2058          12 :                     n->target = DISCARD_SEQUENCES;
    2059          12 :                     $$ = (Node *) n;
    2060             :                 }
    2061             : 
    2062             :         ;
    2063             : 
    2064             : 
    2065             : /*****************************************************************************
    2066             :  *
    2067             :  *  ALTER [ TABLE | INDEX | SEQUENCE | VIEW | MATERIALIZED VIEW | FOREIGN TABLE ] variations
    2068             :  *
    2069             :  * Note: we accept all subcommands for each of the variants, and sort
    2070             :  * out what's really legal at execution time.
    2071             :  *****************************************************************************/
    2072             : 
    2073             : AlterTableStmt:
    2074             :             ALTER TABLE relation_expr alter_table_cmds
    2075             :                 {
    2076       22034 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2077             : 
    2078       22034 :                     n->relation = $3;
    2079       22034 :                     n->cmds = $4;
    2080       22034 :                     n->objtype = OBJECT_TABLE;
    2081       22034 :                     n->missing_ok = false;
    2082       22034 :                     $$ = (Node *) n;
    2083             :                 }
    2084             :         |   ALTER TABLE IF_P EXISTS relation_expr alter_table_cmds
    2085             :                 {
    2086          54 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2087             : 
    2088          54 :                     n->relation = $5;
    2089          54 :                     n->cmds = $6;
    2090          54 :                     n->objtype = OBJECT_TABLE;
    2091          54 :                     n->missing_ok = true;
    2092          54 :                     $$ = (Node *) n;
    2093             :                 }
    2094             :         |   ALTER TABLE relation_expr partition_cmd
    2095             :                 {
    2096        2706 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2097             : 
    2098        2706 :                     n->relation = $3;
    2099        2706 :                     n->cmds = list_make1($4);
    2100        2706 :                     n->objtype = OBJECT_TABLE;
    2101        2706 :                     n->missing_ok = false;
    2102        2706 :                     $$ = (Node *) n;
    2103             :                 }
    2104             :         |   ALTER TABLE IF_P EXISTS relation_expr partition_cmd
    2105             :                 {
    2106           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2107             : 
    2108           0 :                     n->relation = $5;
    2109           0 :                     n->cmds = list_make1($6);
    2110           0 :                     n->objtype = OBJECT_TABLE;
    2111           0 :                     n->missing_ok = true;
    2112           0 :                     $$ = (Node *) n;
    2113             :                 }
    2114             :         |   ALTER TABLE ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2115             :                 {
    2116             :                     AlterTableMoveAllStmt *n =
    2117          12 :                         makeNode(AlterTableMoveAllStmt);
    2118             : 
    2119          12 :                     n->orig_tablespacename = $6;
    2120          12 :                     n->objtype = OBJECT_TABLE;
    2121          12 :                     n->roles = NIL;
    2122          12 :                     n->new_tablespacename = $9;
    2123          12 :                     n->nowait = $10;
    2124          12 :                     $$ = (Node *) n;
    2125             :                 }
    2126             :         |   ALTER TABLE ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2127             :                 {
    2128             :                     AlterTableMoveAllStmt *n =
    2129           0 :                         makeNode(AlterTableMoveAllStmt);
    2130             : 
    2131           0 :                     n->orig_tablespacename = $6;
    2132           0 :                     n->objtype = OBJECT_TABLE;
    2133           0 :                     n->roles = $9;
    2134           0 :                     n->new_tablespacename = $12;
    2135           0 :                     n->nowait = $13;
    2136           0 :                     $$ = (Node *) n;
    2137             :                 }
    2138             :         |   ALTER INDEX qualified_name alter_table_cmds
    2139             :                 {
    2140         226 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2141             : 
    2142         226 :                     n->relation = $3;
    2143         226 :                     n->cmds = $4;
    2144         226 :                     n->objtype = OBJECT_INDEX;
    2145         226 :                     n->missing_ok = false;
    2146         226 :                     $$ = (Node *) n;
    2147             :                 }
    2148             :         |   ALTER INDEX IF_P EXISTS qualified_name alter_table_cmds
    2149             :                 {
    2150           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2151             : 
    2152           0 :                     n->relation = $5;
    2153           0 :                     n->cmds = $6;
    2154           0 :                     n->objtype = OBJECT_INDEX;
    2155           0 :                     n->missing_ok = true;
    2156           0 :                     $$ = (Node *) n;
    2157             :                 }
    2158             :         |   ALTER INDEX qualified_name index_partition_cmd
    2159             :                 {
    2160         390 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2161             : 
    2162         390 :                     n->relation = $3;
    2163         390 :                     n->cmds = list_make1($4);
    2164         390 :                     n->objtype = OBJECT_INDEX;
    2165         390 :                     n->missing_ok = false;
    2166         390 :                     $$ = (Node *) n;
    2167             :                 }
    2168             :         |   ALTER INDEX ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2169             :                 {
    2170             :                     AlterTableMoveAllStmt *n =
    2171           6 :                         makeNode(AlterTableMoveAllStmt);
    2172             : 
    2173           6 :                     n->orig_tablespacename = $6;
    2174           6 :                     n->objtype = OBJECT_INDEX;
    2175           6 :                     n->roles = NIL;
    2176           6 :                     n->new_tablespacename = $9;
    2177           6 :                     n->nowait = $10;
    2178           6 :                     $$ = (Node *) n;
    2179             :                 }
    2180             :         |   ALTER INDEX ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2181             :                 {
    2182             :                     AlterTableMoveAllStmt *n =
    2183           0 :                         makeNode(AlterTableMoveAllStmt);
    2184             : 
    2185           0 :                     n->orig_tablespacename = $6;
    2186           0 :                     n->objtype = OBJECT_INDEX;
    2187           0 :                     n->roles = $9;
    2188           0 :                     n->new_tablespacename = $12;
    2189           0 :                     n->nowait = $13;
    2190           0 :                     $$ = (Node *) n;
    2191             :                 }
    2192             :         |   ALTER SEQUENCE qualified_name alter_table_cmds
    2193             :                 {
    2194          74 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2195             : 
    2196          74 :                     n->relation = $3;
    2197          74 :                     n->cmds = $4;
    2198          74 :                     n->objtype = OBJECT_SEQUENCE;
    2199          74 :                     n->missing_ok = false;
    2200          74 :                     $$ = (Node *) n;
    2201             :                 }
    2202             :         |   ALTER SEQUENCE IF_P EXISTS qualified_name alter_table_cmds
    2203             :                 {
    2204           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2205             : 
    2206           0 :                     n->relation = $5;
    2207           0 :                     n->cmds = $6;
    2208           0 :                     n->objtype = OBJECT_SEQUENCE;
    2209           0 :                     n->missing_ok = true;
    2210           0 :                     $$ = (Node *) n;
    2211             :                 }
    2212             :         |   ALTER VIEW qualified_name alter_table_cmds
    2213             :                 {
    2214         240 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2215             : 
    2216         240 :                     n->relation = $3;
    2217         240 :                     n->cmds = $4;
    2218         240 :                     n->objtype = OBJECT_VIEW;
    2219         240 :                     n->missing_ok = false;
    2220         240 :                     $$ = (Node *) n;
    2221             :                 }
    2222             :         |   ALTER VIEW IF_P EXISTS qualified_name alter_table_cmds
    2223             :                 {
    2224           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2225             : 
    2226           0 :                     n->relation = $5;
    2227           0 :                     n->cmds = $6;
    2228           0 :                     n->objtype = OBJECT_VIEW;
    2229           0 :                     n->missing_ok = true;
    2230           0 :                     $$ = (Node *) n;
    2231             :                 }
    2232             :         |   ALTER MATERIALIZED VIEW qualified_name alter_table_cmds
    2233             :                 {
    2234          48 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2235             : 
    2236          48 :                     n->relation = $4;
    2237          48 :                     n->cmds = $5;
    2238          48 :                     n->objtype = OBJECT_MATVIEW;
    2239          48 :                     n->missing_ok = false;
    2240          48 :                     $$ = (Node *) n;
    2241             :                 }
    2242             :         |   ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name alter_table_cmds
    2243             :                 {
    2244           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2245             : 
    2246           0 :                     n->relation = $6;
    2247           0 :                     n->cmds = $7;
    2248           0 :                     n->objtype = OBJECT_MATVIEW;
    2249           0 :                     n->missing_ok = true;
    2250           0 :                     $$ = (Node *) n;
    2251             :                 }
    2252             :         |   ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2253             :                 {
    2254             :                     AlterTableMoveAllStmt *n =
    2255          12 :                         makeNode(AlterTableMoveAllStmt);
    2256             : 
    2257          12 :                     n->orig_tablespacename = $7;
    2258          12 :                     n->objtype = OBJECT_MATVIEW;
    2259          12 :                     n->roles = NIL;
    2260          12 :                     n->new_tablespacename = $10;
    2261          12 :                     n->nowait = $11;
    2262          12 :                     $$ = (Node *) n;
    2263             :                 }
    2264             :         |   ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2265             :                 {
    2266             :                     AlterTableMoveAllStmt *n =
    2267           0 :                         makeNode(AlterTableMoveAllStmt);
    2268             : 
    2269           0 :                     n->orig_tablespacename = $7;
    2270           0 :                     n->objtype = OBJECT_MATVIEW;
    2271           0 :                     n->roles = $10;
    2272           0 :                     n->new_tablespacename = $13;
    2273           0 :                     n->nowait = $14;
    2274           0 :                     $$ = (Node *) n;
    2275             :                 }
    2276             :         |   ALTER FOREIGN TABLE relation_expr alter_table_cmds
    2277             :                 {
    2278         366 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2279             : 
    2280         366 :                     n->relation = $4;
    2281         366 :                     n->cmds = $5;
    2282         366 :                     n->objtype = OBJECT_FOREIGN_TABLE;
    2283         366 :                     n->missing_ok = false;
    2284         366 :                     $$ = (Node *) n;
    2285             :                 }
    2286             :         |   ALTER FOREIGN TABLE IF_P EXISTS relation_expr alter_table_cmds
    2287             :                 {
    2288         108 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2289             : 
    2290         108 :                     n->relation = $6;
    2291         108 :                     n->cmds = $7;
    2292         108 :                     n->objtype = OBJECT_FOREIGN_TABLE;
    2293         108 :                     n->missing_ok = true;
    2294         108 :                     $$ = (Node *) n;
    2295             :                 }
    2296             :         ;
    2297             : 
    2298             : alter_table_cmds:
    2299       23150 :             alter_table_cmd                         { $$ = list_make1($1); }
    2300         918 :             | alter_table_cmds ',' alter_table_cmd  { $$ = lappend($1, $3); }
    2301             :         ;
    2302             : 
    2303             : partition_cmd:
    2304             :             /* ALTER TABLE <name> ATTACH PARTITION <table_name> FOR VALUES */
    2305             :             ATTACH PARTITION qualified_name PartitionBoundSpec
    2306             :                 {
    2307        2164 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2308        2164 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2309             : 
    2310        2164 :                     n->subtype = AT_AttachPartition;
    2311        2164 :                     cmd->name = $3;
    2312        2164 :                     cmd->bound = $4;
    2313        2164 :                     cmd->concurrent = false;
    2314        2164 :                     n->def = (Node *) cmd;
    2315             : 
    2316        2164 :                     $$ = (Node *) n;
    2317             :                 }
    2318             :             /* ALTER TABLE <name> DETACH PARTITION <partition_name> [CONCURRENTLY] */
    2319             :             | DETACH PARTITION qualified_name opt_concurrently
    2320             :                 {
    2321         528 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2322         528 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2323             : 
    2324         528 :                     n->subtype = AT_DetachPartition;
    2325         528 :                     cmd->name = $3;
    2326         528 :                     cmd->bound = NULL;
    2327         528 :                     cmd->concurrent = $4;
    2328         528 :                     n->def = (Node *) cmd;
    2329             : 
    2330         528 :                     $$ = (Node *) n;
    2331             :                 }
    2332             :             | DETACH PARTITION qualified_name FINALIZE
    2333             :                 {
    2334          14 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2335          14 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2336             : 
    2337          14 :                     n->subtype = AT_DetachPartitionFinalize;
    2338          14 :                     cmd->name = $3;
    2339          14 :                     cmd->bound = NULL;
    2340          14 :                     cmd->concurrent = false;
    2341          14 :                     n->def = (Node *) cmd;
    2342          14 :                     $$ = (Node *) n;
    2343             :                 }
    2344             :         ;
    2345             : 
    2346             : index_partition_cmd:
    2347             :             /* ALTER INDEX <name> ATTACH PARTITION <index_name> */
    2348             :             ATTACH PARTITION qualified_name
    2349             :                 {
    2350         390 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2351         390 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2352             : 
    2353         390 :                     n->subtype = AT_AttachPartition;
    2354         390 :                     cmd->name = $3;
    2355         390 :                     cmd->bound = NULL;
    2356         390 :                     cmd->concurrent = false;
    2357         390 :                     n->def = (Node *) cmd;
    2358             : 
    2359         390 :                     $$ = (Node *) n;
    2360             :                 }
    2361             :         ;
    2362             : 
    2363             : alter_table_cmd:
    2364             :             /* ALTER TABLE <name> ADD <coldef> */
    2365             :             ADD_P columnDef
    2366             :                 {
    2367         164 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2368             : 
    2369         164 :                     n->subtype = AT_AddColumn;
    2370         164 :                     n->def = $2;
    2371         164 :                     n->missing_ok = false;
    2372         164 :                     $$ = (Node *) n;
    2373             :                 }
    2374             :             /* ALTER TABLE <name> ADD IF NOT EXISTS <coldef> */
    2375             :             | ADD_P IF_P NOT EXISTS columnDef
    2376             :                 {
    2377           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2378             : 
    2379           0 :                     n->subtype = AT_AddColumn;
    2380           0 :                     n->def = $5;
    2381           0 :                     n->missing_ok = true;
    2382           0 :                     $$ = (Node *) n;
    2383             :                 }
    2384             :             /* ALTER TABLE <name> ADD COLUMN <coldef> */
    2385             :             | ADD_P COLUMN columnDef
    2386             :                 {
    2387        1716 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2388             : 
    2389        1716 :                     n->subtype = AT_AddColumn;
    2390        1716 :                     n->def = $3;
    2391        1716 :                     n->missing_ok = false;
    2392        1716 :                     $$ = (Node *) n;
    2393             :                 }
    2394             :             /* ALTER TABLE <name> ADD COLUMN IF NOT EXISTS <coldef> */
    2395             :             | ADD_P COLUMN IF_P NOT EXISTS columnDef
    2396             :                 {
    2397          60 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2398             : 
    2399          60 :                     n->subtype = AT_AddColumn;
    2400          60 :                     n->def = $6;
    2401          60 :                     n->missing_ok = true;
    2402          60 :                     $$ = (Node *) n;
    2403             :                 }
    2404             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
    2405             :             | ALTER opt_column ColId alter_column_default
    2406             :                 {
    2407         532 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2408             : 
    2409         532 :                     n->subtype = AT_ColumnDefault;
    2410         532 :                     n->name = $3;
    2411         532 :                     n->def = $4;
    2412         532 :                     $$ = (Node *) n;
    2413             :                 }
    2414             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
    2415             :             | ALTER opt_column ColId DROP NOT NULL_P
    2416             :                 {
    2417         258 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2418             : 
    2419         258 :                     n->subtype = AT_DropNotNull;
    2420         258 :                     n->name = $3;
    2421         258 :                     $$ = (Node *) n;
    2422             :                 }
    2423             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
    2424             :             | ALTER opt_column ColId SET NOT NULL_P
    2425             :                 {
    2426         374 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2427             : 
    2428         374 :                     n->subtype = AT_SetNotNull;
    2429         374 :                     n->name = $3;
    2430         374 :                     $$ = (Node *) n;
    2431             :                 }
    2432             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET EXPRESSION AS <expr> */
    2433             :             | ALTER opt_column ColId SET EXPRESSION AS '(' a_expr ')'
    2434             :                 {
    2435          66 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2436             : 
    2437          66 :                     n->subtype = AT_SetExpression;
    2438          66 :                     n->name = $3;
    2439          66 :                     n->def = $8;
    2440          66 :                     $$ = (Node *) n;
    2441             :                 }
    2442             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
    2443             :             | ALTER opt_column ColId DROP EXPRESSION
    2444             :                 {
    2445          32 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2446             : 
    2447          32 :                     n->subtype = AT_DropExpression;
    2448          32 :                     n->name = $3;
    2449          32 :                     $$ = (Node *) n;
    2450             :                 }
    2451             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION IF EXISTS */
    2452             :             | ALTER opt_column ColId DROP EXPRESSION IF_P EXISTS
    2453             :                 {
    2454           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2455             : 
    2456           6 :                     n->subtype = AT_DropExpression;
    2457           6 :                     n->name = $3;
    2458           6 :                     n->missing_ok = true;
    2459           6 :                     $$ = (Node *) n;
    2460             :                 }
    2461             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS */
    2462             :             | ALTER opt_column ColId SET STATISTICS set_statistics_value
    2463             :                 {
    2464          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2465             : 
    2466          62 :                     n->subtype = AT_SetStatistics;
    2467          62 :                     n->name = $3;
    2468          62 :                     n->def = $6;
    2469          62 :                     $$ = (Node *) n;
    2470             :                 }
    2471             :             /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS */
    2472             :             | ALTER opt_column Iconst SET STATISTICS set_statistics_value
    2473             :                 {
    2474          70 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2475             : 
    2476          70 :                     if ($3 <= 0 || $3 > PG_INT16_MAX)
    2477           6 :                         ereport(ERROR,
    2478             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
    2479             :                                  errmsg("column number must be in range from 1 to %d", PG_INT16_MAX),
    2480             :                                  parser_errposition(@3)));
    2481             : 
    2482          64 :                     n->subtype = AT_SetStatistics;
    2483          64 :                     n->num = (int16) $3;
    2484          64 :                     n->def = $6;
    2485          64 :                     $$ = (Node *) n;
    2486             :                 }
    2487             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
    2488             :             | ALTER opt_column ColId SET reloptions
    2489             :                 {
    2490          38 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2491             : 
    2492          38 :                     n->subtype = AT_SetOptions;
    2493          38 :                     n->name = $3;
    2494          38 :                     n->def = (Node *) $5;
    2495          38 :                     $$ = (Node *) n;
    2496             :                 }
    2497             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> RESET ( column_parameter [, ... ] ) */
    2498             :             | ALTER opt_column ColId RESET reloptions
    2499             :                 {
    2500           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2501             : 
    2502           6 :                     n->subtype = AT_ResetOptions;
    2503           6 :                     n->name = $3;
    2504           6 :                     n->def = (Node *) $5;
    2505           6 :                     $$ = (Node *) n;
    2506             :                 }
    2507             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
    2508             :             | ALTER opt_column ColId SET column_storage
    2509             :                 {
    2510         212 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2511             : 
    2512         212 :                     n->subtype = AT_SetStorage;
    2513         212 :                     n->name = $3;
    2514         212 :                     n->def = (Node *) makeString($5);
    2515         212 :                     $$ = (Node *) n;
    2516             :                 }
    2517             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET COMPRESSION <cm> */
    2518             :             | ALTER opt_column ColId SET column_compression
    2519             :                 {
    2520          66 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2521             : 
    2522          66 :                     n->subtype = AT_SetCompression;
    2523          66 :                     n->name = $3;
    2524          66 :                     n->def = (Node *) makeString($5);
    2525          66 :                     $$ = (Node *) n;
    2526             :                 }
    2527             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> ADD GENERATED ... AS IDENTITY ... */
    2528             :             | ALTER opt_column ColId ADD_P GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    2529             :                 {
    2530         154 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2531         154 :                     Constraint *c = makeNode(Constraint);
    2532             : 
    2533         154 :                     c->contype = CONSTR_IDENTITY;
    2534         154 :                     c->generated_when = $6;
    2535         154 :                     c->options = $9;
    2536         154 :                     c->location = @5;
    2537             : 
    2538         154 :                     n->subtype = AT_AddIdentity;
    2539         154 :                     n->name = $3;
    2540         154 :                     n->def = (Node *) c;
    2541             : 
    2542         154 :                     $$ = (Node *) n;
    2543             :                 }
    2544             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET <sequence options>/RESET */
    2545             :             | ALTER opt_column ColId alter_identity_column_option_list
    2546             :                 {
    2547          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2548             : 
    2549          62 :                     n->subtype = AT_SetIdentity;
    2550          62 :                     n->name = $3;
    2551          62 :                     n->def = (Node *) $4;
    2552          62 :                     $$ = (Node *) n;
    2553             :                 }
    2554             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY */
    2555             :             | ALTER opt_column ColId DROP IDENTITY_P
    2556             :                 {
    2557          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2558             : 
    2559          50 :                     n->subtype = AT_DropIdentity;
    2560          50 :                     n->name = $3;
    2561          50 :                     n->missing_ok = false;
    2562          50 :                     $$ = (Node *) n;
    2563             :                 }
    2564             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY IF EXISTS */
    2565             :             | ALTER opt_column ColId DROP IDENTITY_P IF_P EXISTS
    2566             :                 {
    2567           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2568             : 
    2569           6 :                     n->subtype = AT_DropIdentity;
    2570           6 :                     n->name = $3;
    2571           6 :                     n->missing_ok = true;
    2572           6 :                     $$ = (Node *) n;
    2573             :                 }
    2574             :             /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
    2575             :             | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
    2576             :                 {
    2577          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2578             : 
    2579          18 :                     n->subtype = AT_DropColumn;
    2580          18 :                     n->name = $5;
    2581          18 :                     n->behavior = $6;
    2582          18 :                     n->missing_ok = true;
    2583          18 :                     $$ = (Node *) n;
    2584             :                 }
    2585             :             /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
    2586             :             | DROP opt_column ColId opt_drop_behavior
    2587             :                 {
    2588        1498 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2589             : 
    2590        1498 :                     n->subtype = AT_DropColumn;
    2591        1498 :                     n->name = $3;
    2592        1498 :                     n->behavior = $4;
    2593        1498 :                     n->missing_ok = false;
    2594        1498 :                     $$ = (Node *) n;
    2595             :                 }
    2596             :             /*
    2597             :              * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
    2598             :              *      [ USING <expression> ]
    2599             :              */
    2600             :             | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using
    2601             :                 {
    2602         846 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2603         846 :                     ColumnDef *def = makeNode(ColumnDef);
    2604             : 
    2605         846 :                     n->subtype = AT_AlterColumnType;
    2606         846 :                     n->name = $3;
    2607         846 :                     n->def = (Node *) def;
    2608             :                     /* We only use these fields of the ColumnDef node */
    2609         846 :                     def->typeName = $6;
    2610         846 :                     def->collClause = (CollateClause *) $7;
    2611         846 :                     def->raw_default = $8;
    2612         846 :                     def->location = @3;
    2613         846 :                     $$ = (Node *) n;
    2614             :                 }
    2615             :             /* ALTER FOREIGN TABLE <name> ALTER [COLUMN] <colname> OPTIONS */
    2616             :             | ALTER opt_column ColId alter_generic_options
    2617             :                 {
    2618          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2619             : 
    2620          50 :                     n->subtype = AT_AlterColumnGenericOptions;
    2621          50 :                     n->name = $3;
    2622          50 :                     n->def = (Node *) $4;
    2623          50 :                     $$ = (Node *) n;
    2624             :                 }
    2625             :             /* ALTER TABLE <name> ADD CONSTRAINT ... */
    2626             :             | ADD_P TableConstraint
    2627             :                 {
    2628       11578 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2629             : 
    2630       11578 :                     n->subtype = AT_AddConstraint;
    2631       11578 :                     n->def = $2;
    2632       11578 :                     $$ = (Node *) n;
    2633             :                 }
    2634             :             /* ALTER TABLE <name> ALTER CONSTRAINT ... */
    2635             :             | ALTER CONSTRAINT name ConstraintAttributeSpec
    2636             :                 {
    2637         132 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2638         132 :                     Constraint *c = makeNode(Constraint);
    2639             : 
    2640         132 :                     n->subtype = AT_AlterConstraint;
    2641         132 :                     n->def = (Node *) c;
    2642         132 :                     c->contype = CONSTR_FOREIGN; /* others not supported, yet */
    2643         132 :                     c->conname = $3;
    2644         132 :                     processCASbits($4, @4, "ALTER CONSTRAINT statement",
    2645             :                                     &c->deferrable,
    2646             :                                     &c->initdeferred,
    2647             :                                     NULL, NULL, yyscanner);
    2648         132 :                     $$ = (Node *) n;
    2649             :                 }
    2650             :             /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
    2651             :             | VALIDATE CONSTRAINT name
    2652             :                 {
    2653         388 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2654             : 
    2655         388 :                     n->subtype = AT_ValidateConstraint;
    2656         388 :                     n->name = $3;
    2657         388 :                     $$ = (Node *) n;
    2658             :                 }
    2659             :             /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
    2660             :             | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
    2661             :                 {
    2662          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2663             : 
    2664          18 :                     n->subtype = AT_DropConstraint;
    2665          18 :                     n->name = $5;
    2666          18 :                     n->behavior = $6;
    2667          18 :                     n->missing_ok = true;
    2668          18 :                     $$ = (Node *) n;
    2669             :                 }
    2670             :             /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
    2671             :             | DROP CONSTRAINT name opt_drop_behavior
    2672             :                 {
    2673         946 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2674             : 
    2675         946 :                     n->subtype = AT_DropConstraint;
    2676         946 :                     n->name = $3;
    2677         946 :                     n->behavior = $4;
    2678         946 :                     n->missing_ok = false;
    2679         946 :                     $$ = (Node *) n;
    2680             :                 }
    2681             :             /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat */
    2682             :             | SET WITHOUT OIDS
    2683             :                 {
    2684           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2685             : 
    2686           6 :                     n->subtype = AT_DropOids;
    2687           6 :                     $$ = (Node *) n;
    2688             :                 }
    2689             :             /* ALTER TABLE <name> CLUSTER ON <indexname> */
    2690             :             | CLUSTER ON name
    2691             :                 {
    2692          46 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2693             : 
    2694          46 :                     n->subtype = AT_ClusterOn;
    2695          46 :                     n->name = $3;
    2696          46 :                     $$ = (Node *) n;
    2697             :                 }
    2698             :             /* ALTER TABLE <name> SET WITHOUT CLUSTER */
    2699             :             | SET WITHOUT CLUSTER
    2700             :                 {
    2701          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2702             : 
    2703          18 :                     n->subtype = AT_DropCluster;
    2704          18 :                     n->name = NULL;
    2705          18 :                     $$ = (Node *) n;
    2706             :                 }
    2707             :             /* ALTER TABLE <name> SET LOGGED */
    2708             :             | SET LOGGED
    2709             :                 {
    2710          38 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2711             : 
    2712          38 :                     n->subtype = AT_SetLogged;
    2713          38 :                     $$ = (Node *) n;
    2714             :                 }
    2715             :             /* ALTER TABLE <name> SET UNLOGGED */
    2716             :             | SET UNLOGGED
    2717             :                 {
    2718          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2719             : 
    2720          50 :                     n->subtype = AT_SetUnLogged;
    2721          50 :                     $$ = (Node *) n;
    2722             :                 }
    2723             :             /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
    2724             :             | ENABLE_P TRIGGER name
    2725             :                 {
    2726         122 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2727             : 
    2728         122 :                     n->subtype = AT_EnableTrig;
    2729         122 :                     n->name = $3;
    2730         122 :                     $$ = (Node *) n;
    2731             :                 }
    2732             :             /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
    2733             :             | ENABLE_P ALWAYS TRIGGER name
    2734             :                 {
    2735          40 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2736             : 
    2737          40 :                     n->subtype = AT_EnableAlwaysTrig;
    2738          40 :                     n->name = $4;
    2739          40 :                     $$ = (Node *) n;
    2740             :                 }
    2741             :             /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
    2742             :             | ENABLE_P REPLICA TRIGGER name
    2743             :                 {
    2744          16 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2745             : 
    2746          16 :                     n->subtype = AT_EnableReplicaTrig;
    2747          16 :                     n->name = $4;
    2748          16 :                     $$ = (Node *) n;
    2749             :                 }
    2750             :             /* ALTER TABLE <name> ENABLE TRIGGER ALL */
    2751             :             | ENABLE_P TRIGGER ALL
    2752             :                 {
    2753           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2754             : 
    2755           0 :                     n->subtype = AT_EnableTrigAll;
    2756           0 :                     $$ = (Node *) n;
    2757             :                 }
    2758             :             /* ALTER TABLE <name> ENABLE TRIGGER USER */
    2759             :             | ENABLE_P TRIGGER USER
    2760             :                 {
    2761           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2762             : 
    2763           0 :                     n->subtype = AT_EnableTrigUser;
    2764           0 :                     $$ = (Node *) n;
    2765             :                 }
    2766             :             /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
    2767             :             | DISABLE_P TRIGGER name
    2768             :                 {
    2769         138 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2770             : 
    2771         138 :                     n->subtype = AT_DisableTrig;
    2772         138 :                     n->name = $3;
    2773         138 :                     $$ = (Node *) n;
    2774             :                 }
    2775             :             /* ALTER TABLE <name> DISABLE TRIGGER ALL */
    2776             :             | DISABLE_P TRIGGER ALL
    2777             :                 {
    2778          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2779             : 
    2780          12 :                     n->subtype = AT_DisableTrigAll;
    2781          12 :                     $$ = (Node *) n;
    2782             :                 }
    2783             :             /* ALTER TABLE <name> DISABLE TRIGGER USER */
    2784             :             | DISABLE_P TRIGGER USER
    2785             :                 {
    2786          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2787             : 
    2788          12 :                     n->subtype = AT_DisableTrigUser;
    2789          12 :                     $$ = (Node *) n;
    2790             :                 }
    2791             :             /* ALTER TABLE <name> ENABLE RULE <rule> */
    2792             :             | ENABLE_P RULE name
    2793             :                 {
    2794           8 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2795             : 
    2796           8 :                     n->subtype = AT_EnableRule;
    2797           8 :                     n->name = $3;
    2798           8 :                     $$ = (Node *) n;
    2799             :                 }
    2800             :             /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
    2801             :             | ENABLE_P ALWAYS RULE name
    2802             :                 {
    2803           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2804             : 
    2805           0 :                     n->subtype = AT_EnableAlwaysRule;
    2806           0 :                     n->name = $4;
    2807           0 :                     $$ = (Node *) n;
    2808             :                 }
    2809             :             /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
    2810             :             | ENABLE_P REPLICA RULE name
    2811             :                 {
    2812           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2813             : 
    2814           6 :                     n->subtype = AT_EnableReplicaRule;
    2815           6 :                     n->name = $4;
    2816           6 :                     $$ = (Node *) n;
    2817             :                 }
    2818             :             /* ALTER TABLE <name> DISABLE RULE <rule> */
    2819             :             | DISABLE_P RULE name
    2820             :                 {
    2821          32 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2822             : 
    2823          32 :                     n->subtype = AT_DisableRule;
    2824          32 :                     n->name = $3;
    2825          32 :                     $$ = (Node *) n;
    2826             :                 }
    2827             :             /* ALTER TABLE <name> INHERIT <parent> */
    2828             :             | INHERIT qualified_name
    2829             :                 {
    2830         326 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2831             : 
    2832         326 :                     n->subtype = AT_AddInherit;
    2833         326 :                     n->def = (Node *) $2;
    2834         326 :                     $$ = (Node *) n;
    2835             :                 }
    2836             :             /* ALTER TABLE <name> NO INHERIT <parent> */
    2837             :             | NO INHERIT qualified_name
    2838             :                 {
    2839          44 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2840             : 
    2841          44 :                     n->subtype = AT_DropInherit;
    2842          44 :                     n->def = (Node *) $3;
    2843          44 :                     $$ = (Node *) n;
    2844             :                 }
    2845             :             /* ALTER TABLE <name> OF <type_name> */
    2846             :             | OF any_name
    2847             :                 {
    2848          66 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2849          66 :                     TypeName   *def = makeTypeNameFromNameList($2);
    2850             : 
    2851          66 :                     def->location = @2;
    2852          66 :                     n->subtype = AT_AddOf;
    2853          66 :                     n->def = (Node *) def;
    2854          66 :                     $$ = (Node *) n;
    2855             :                 }
    2856             :             /* ALTER TABLE <name> NOT OF */
    2857             :             | NOT OF
    2858             :                 {
    2859           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2860             : 
    2861           6 :                     n->subtype = AT_DropOf;
    2862           6 :                     $$ = (Node *) n;
    2863             :                 }
    2864             :             /* ALTER TABLE <name> OWNER TO RoleSpec */
    2865             :             | OWNER TO RoleSpec
    2866             :                 {
    2867        1820 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2868             : 
    2869        1820 :                     n->subtype = AT_ChangeOwner;
    2870        1820 :                     n->newowner = $3;
    2871        1820 :                     $$ = (Node *) n;
    2872             :                 }
    2873             :             /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
    2874             :             | SET ACCESS METHOD set_access_method_name
    2875             :                 {
    2876         128 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2877             : 
    2878         128 :                     n->subtype = AT_SetAccessMethod;
    2879         128 :                     n->name = $4;
    2880         128 :                     $$ = (Node *) n;
    2881             :                 }
    2882             :             /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
    2883             :             | SET TABLESPACE name
    2884             :                 {
    2885         104 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2886             : 
    2887         104 :                     n->subtype = AT_SetTableSpace;
    2888         104 :                     n->name = $3;
    2889         104 :                     $$ = (Node *) n;
    2890             :                 }
    2891             :             /* ALTER TABLE <name> SET (...) */
    2892             :             | SET reloptions
    2893             :                 {
    2894         582 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2895             : 
    2896         582 :                     n->subtype = AT_SetRelOptions;
    2897         582 :                     n->def = (Node *) $2;
    2898         582 :                     $$ = (Node *) n;
    2899             :                 }
    2900             :             /* ALTER TABLE <name> RESET (...) */
    2901             :             | RESET reloptions
    2902             :                 {
    2903         158 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2904             : 
    2905         158 :                     n->subtype = AT_ResetRelOptions;
    2906         158 :                     n->def = (Node *) $2;
    2907         158 :                     $$ = (Node *) n;
    2908             :                 }
    2909             :             /* ALTER TABLE <name> REPLICA IDENTITY */
    2910             :             | REPLICA IDENTITY_P replica_identity
    2911             :                 {
    2912         430 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2913             : 
    2914         430 :                     n->subtype = AT_ReplicaIdentity;
    2915         430 :                     n->def = $3;
    2916         430 :                     $$ = (Node *) n;
    2917             :                 }
    2918             :             /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
    2919             :             | ENABLE_P ROW LEVEL SECURITY
    2920             :                 {
    2921         278 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2922             : 
    2923         278 :                     n->subtype = AT_EnableRowSecurity;
    2924         278 :                     $$ = (Node *) n;
    2925             :                 }
    2926             :             /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
    2927             :             | DISABLE_P ROW LEVEL SECURITY
    2928             :                 {
    2929          10 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2930             : 
    2931          10 :                     n->subtype = AT_DisableRowSecurity;
    2932          10 :                     $$ = (Node *) n;
    2933             :                 }
    2934             :             /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
    2935             :             | FORCE ROW LEVEL SECURITY
    2936             :                 {
    2937          82 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2938             : 
    2939          82 :                     n->subtype = AT_ForceRowSecurity;
    2940          82 :                     $$ = (Node *) n;
    2941             :                 }
    2942             :             /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
    2943             :             | NO FORCE ROW LEVEL SECURITY
    2944             :                 {
    2945          32 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2946             : 
    2947          32 :                     n->subtype = AT_NoForceRowSecurity;
    2948          32 :                     $$ = (Node *) n;
    2949             :                 }
    2950             :             | alter_generic_options
    2951             :                 {
    2952          56 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2953             : 
    2954          56 :                     n->subtype = AT_GenericOptions;
    2955          56 :                     n->def = (Node *) $1;
    2956          56 :                     $$ = (Node *) n;
    2957             :                 }
    2958             :         ;
    2959             : 
    2960             : alter_column_default:
    2961         366 :             SET DEFAULT a_expr          { $$ = $3; }
    2962         180 :             | DROP DEFAULT              { $$ = NULL; }
    2963             :         ;
    2964             : 
    2965             : opt_collate_clause:
    2966             :             COLLATE any_name
    2967             :                 {
    2968          12 :                     CollateClause *n = makeNode(CollateClause);
    2969             : 
    2970          12 :                     n->arg = NULL;
    2971          12 :                     n->collname = $2;
    2972          12 :                     n->location = @1;
    2973          12 :                     $$ = (Node *) n;
    2974             :                 }
    2975        4410 :             | /* EMPTY */               { $$ = NULL; }
    2976             :         ;
    2977             : 
    2978             : alter_using:
    2979         168 :             USING a_expr                { $$ = $2; }
    2980         678 :             | /* EMPTY */               { $$ = NULL; }
    2981             :         ;
    2982             : 
    2983             : replica_identity:
    2984             :             NOTHING
    2985             :                 {
    2986          36 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    2987             : 
    2988          36 :                     n->identity_type = REPLICA_IDENTITY_NOTHING;
    2989          36 :                     n->name = NULL;
    2990          36 :                     $$ = (Node *) n;
    2991             :                 }
    2992             :             | FULL
    2993             :                 {
    2994         138 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    2995             : 
    2996         138 :                     n->identity_type = REPLICA_IDENTITY_FULL;
    2997         138 :                     n->name = NULL;
    2998         138 :                     $$ = (Node *) n;
    2999             :                 }
    3000             :             | DEFAULT
    3001             :                 {
    3002           6 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3003             : 
    3004           6 :                     n->identity_type = REPLICA_IDENTITY_DEFAULT;
    3005           6 :                     n->name = NULL;
    3006           6 :                     $$ = (Node *) n;
    3007             :                 }
    3008             :             | USING INDEX name
    3009             :                 {
    3010         250 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3011             : 
    3012         250 :                     n->identity_type = REPLICA_IDENTITY_INDEX;
    3013         250 :                     n->name = $3;
    3014         250 :                     $$ = (Node *) n;
    3015             :                 }
    3016             : ;
    3017             : 
    3018             : reloptions:
    3019        2452 :             '(' reloption_list ')'                  { $$ = $2; }
    3020             :         ;
    3021             : 
    3022         890 : opt_reloptions:     WITH reloptions                 { $$ = $2; }
    3023       19678 :              |      /* EMPTY */                     { $$ = NIL; }
    3024             :         ;
    3025             : 
    3026             : reloption_list:
    3027        2452 :             reloption_elem                          { $$ = list_make1($1); }
    3028         220 :             | reloption_list ',' reloption_elem     { $$ = lappend($1, $3); }
    3029             :         ;
    3030             : 
    3031             : /* This should match def_elem and also allow qualified names */
    3032             : reloption_elem:
    3033             :             ColLabel '=' def_arg
    3034             :                 {
    3035        2098 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    3036             :                 }
    3037             :             | ColLabel
    3038             :                 {
    3039         506 :                     $$ = makeDefElem($1, NULL, @1);
    3040             :                 }
    3041             :             | ColLabel '.' ColLabel '=' def_arg
    3042             :                 {
    3043          62 :                     $$ = makeDefElemExtended($1, $3, (Node *) $5,
    3044          62 :                                              DEFELEM_UNSPEC, @1);
    3045             :                 }
    3046             :             | ColLabel '.' ColLabel
    3047             :                 {
    3048           6 :                     $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC, @1);
    3049             :                 }
    3050             :         ;
    3051             : 
    3052             : alter_identity_column_option_list:
    3053             :             alter_identity_column_option
    3054          62 :                 { $$ = list_make1($1); }
    3055             :             | alter_identity_column_option_list alter_identity_column_option
    3056          60 :                 { $$ = lappend($1, $2); }
    3057             :         ;
    3058             : 
    3059             : alter_identity_column_option:
    3060             :             RESTART
    3061             :                 {
    3062          24 :                     $$ = makeDefElem("restart", NULL, @1);
    3063             :                 }
    3064             :             | RESTART opt_with NumericOnly
    3065             :                 {
    3066           0 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    3067             :                 }
    3068             :             | SET SeqOptElem
    3069             :                 {
    3070          54 :                     if (strcmp($2->defname, "as") == 0 ||
    3071          54 :                         strcmp($2->defname, "restart") == 0 ||
    3072          54 :                         strcmp($2->defname, "owned_by") == 0)
    3073           0 :                         ereport(ERROR,
    3074             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3075             :                                  errmsg("sequence option \"%s\" not supported here", $2->defname),
    3076             :                                  parser_errposition(@2)));
    3077          54 :                     $$ = $2;
    3078             :                 }
    3079             :             | SET GENERATED generated_when
    3080             :                 {
    3081          44 :                     $$ = makeDefElem("generated", (Node *) makeInteger($3), @1);
    3082             :                 }
    3083             :         ;
    3084             : 
    3085             : set_statistics_value:
    3086         158 :             SignedIconst                    { $$ = (Node *) makeInteger($1); }
    3087           0 :             | DEFAULT                       { $$ = NULL; }
    3088             :         ;
    3089             : 
    3090             : set_access_method_name:
    3091          92 :             ColId                           { $$ = $1; }
    3092          36 :             | DEFAULT                       { $$ = NULL; }
    3093             :         ;
    3094             : 
    3095             : PartitionBoundSpec:
    3096             :             /* a HASH partition */
    3097             :             FOR VALUES WITH '(' hash_partbound ')'
    3098             :                 {
    3099             :                     ListCell   *lc;
    3100         698 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3101             : 
    3102         698 :                     n->strategy = PARTITION_STRATEGY_HASH;
    3103         698 :                     n->modulus = n->remainder = -1;
    3104             : 
    3105        2094 :                     foreach (lc, $5)
    3106             :                     {
    3107        1396 :                         DefElem    *opt = lfirst_node(DefElem, lc);
    3108             : 
    3109        1396 :                         if (strcmp(opt->defname, "modulus") == 0)
    3110             :                         {
    3111         698 :                             if (n->modulus != -1)
    3112           0 :                                 ereport(ERROR,
    3113             :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    3114             :                                          errmsg("modulus for hash partition provided more than once"),
    3115             :                                          parser_errposition(opt->location)));
    3116         698 :                             n->modulus = defGetInt32(opt);
    3117             :                         }
    3118         698 :                         else if (strcmp(opt->defname, "remainder") == 0)
    3119             :                         {
    3120         698 :                             if (n->remainder != -1)
    3121           0 :                                 ereport(ERROR,
    3122             :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    3123             :                                          errmsg("remainder for hash partition provided more than once"),
    3124             :                                          parser_errposition(opt->location)));
    3125         698 :                             n->remainder = defGetInt32(opt);
    3126             :                         }
    3127             :                         else
    3128           0 :                             ereport(ERROR,
    3129             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    3130             :                                      errmsg("unrecognized hash partition bound specification \"%s\"",
    3131             :                                             opt->defname),
    3132             :                                      parser_errposition(opt->location)));
    3133             :                     }
    3134             : 
    3135         698 :                     if (n->modulus == -1)
    3136           0 :                         ereport(ERROR,
    3137             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3138             :                                  errmsg("modulus for hash partition must be specified")));
    3139         698 :                     if (n->remainder == -1)
    3140           0 :                         ereport(ERROR,
    3141             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3142             :                                  errmsg("remainder for hash partition must be specified")));
    3143             : 
    3144         698 :                     n->location = @3;
    3145             : 
    3146         698 :                     $$ = n;
    3147             :                 }
    3148             : 
    3149             :             /* a LIST partition */
    3150             :             | FOR VALUES IN_P '(' expr_list ')'
    3151             :                 {
    3152        4550 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3153             : 
    3154        4550 :                     n->strategy = PARTITION_STRATEGY_LIST;
    3155        4550 :                     n->is_default = false;
    3156        4550 :                     n->listdatums = $5;
    3157        4550 :                     n->location = @3;
    3158             : 
    3159        4550 :                     $$ = n;
    3160             :                 }
    3161             : 
    3162             :             /* a RANGE partition */
    3163             :             | FOR VALUES FROM '(' expr_list ')' TO '(' expr_list ')'
    3164             :                 {
    3165        3928 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3166             : 
    3167        3928 :                     n->strategy = PARTITION_STRATEGY_RANGE;
    3168        3928 :                     n->is_default = false;
    3169        3928 :                     n->lowerdatums = $5;
    3170        3928 :                     n->upperdatums = $9;
    3171        3928 :                     n->location = @3;
    3172             : 
    3173        3928 :                     $$ = n;
    3174             :                 }
    3175             : 
    3176             :             /* a DEFAULT partition */
    3177             :             | DEFAULT
    3178             :                 {
    3179         590 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3180             : 
    3181         590 :                     n->is_default = true;
    3182         590 :                     n->location = @1;
    3183             : 
    3184         590 :                     $$ = n;
    3185             :                 }
    3186             :         ;
    3187             : 
    3188             : hash_partbound_elem:
    3189             :         NonReservedWord Iconst
    3190             :             {
    3191        1396 :                 $$ = makeDefElem($1, (Node *) makeInteger($2), @1);
    3192             :             }
    3193             :         ;
    3194             : 
    3195             : hash_partbound:
    3196             :         hash_partbound_elem
    3197             :             {
    3198         698 :                 $$ = list_make1($1);
    3199             :             }
    3200             :         | hash_partbound ',' hash_partbound_elem
    3201             :             {
    3202         698 :                 $$ = lappend($1, $3);
    3203             :             }
    3204             :         ;
    3205             : 
    3206             : /*****************************************************************************
    3207             :  *
    3208             :  *  ALTER TYPE
    3209             :  *
    3210             :  * really variants of the ALTER TABLE subcommands with different spellings
    3211             :  *****************************************************************************/
    3212             : 
    3213             : AlterCompositeTypeStmt:
    3214             :             ALTER TYPE_P any_name alter_type_cmds
    3215             :                 {
    3216         208 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    3217             : 
    3218             :                     /* can't use qualified_name, sigh */
    3219         208 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
    3220         208 :                     n->cmds = $4;
    3221         208 :                     n->objtype = OBJECT_TYPE;
    3222         208 :                     $$ = (Node *) n;
    3223             :                 }
    3224             :             ;
    3225             : 
    3226             : alter_type_cmds:
    3227         208 :             alter_type_cmd                          { $$ = list_make1($1); }
    3228          12 :             | alter_type_cmds ',' alter_type_cmd    { $$ = lappend($1, $3); }
    3229             :         ;
    3230             : 
    3231             : alter_type_cmd:
    3232             :             /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
    3233             :             ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
    3234             :                 {
    3235          64 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3236             : 
    3237          64 :                     n->subtype = AT_AddColumn;
    3238          64 :                     n->def = $3;
    3239          64 :                     n->behavior = $4;
    3240          64 :                     $$ = (Node *) n;
    3241             :                 }
    3242             :             /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
    3243             :             | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
    3244             :                 {
    3245           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3246             : 
    3247           6 :                     n->subtype = AT_DropColumn;
    3248           6 :                     n->name = $5;
    3249           6 :                     n->behavior = $6;
    3250           6 :                     n->missing_ok = true;
    3251           6 :                     $$ = (Node *) n;
    3252             :                 }
    3253             :             /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
    3254             :             | DROP ATTRIBUTE ColId opt_drop_behavior
    3255             :                 {
    3256          76 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3257             : 
    3258          76 :                     n->subtype = AT_DropColumn;
    3259          76 :                     n->name = $3;
    3260          76 :                     n->behavior = $4;
    3261          76 :                     n->missing_ok = false;
    3262          76 :                     $$ = (Node *) n;
    3263             :                 }
    3264             :             /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
    3265             :             | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
    3266             :                 {
    3267          74 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3268          74 :                     ColumnDef *def = makeNode(ColumnDef);
    3269             : 
    3270          74 :                     n->subtype = AT_AlterColumnType;
    3271          74 :                     n->name = $3;
    3272          74 :                     n->def = (Node *) def;
    3273          74 :                     n->behavior = $8;
    3274             :                     /* We only use these fields of the ColumnDef node */
    3275          74 :                     def->typeName = $6;
    3276          74 :                     def->collClause = (CollateClause *) $7;
    3277          74 :                     def->raw_default = NULL;
    3278          74 :                     def->location = @3;
    3279          74 :                     $$ = (Node *) n;
    3280             :                 }
    3281             :         ;
    3282             : 
    3283             : 
    3284             : /*****************************************************************************
    3285             :  *
    3286             :  *      QUERY :
    3287             :  *              close <portalname>
    3288             :  *
    3289             :  *****************************************************************************/
    3290             : 
    3291             : ClosePortalStmt:
    3292             :             CLOSE cursor_name
    3293             :                 {
    3294        2198 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3295             : 
    3296        2198 :                     n->portalname = $2;
    3297        2198 :                     $$ = (Node *) n;
    3298             :                 }
    3299             :             | CLOSE ALL
    3300             :                 {
    3301          12 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3302             : 
    3303          12 :                     n->portalname = NULL;
    3304          12 :                     $$ = (Node *) n;
    3305             :                 }
    3306             :         ;
    3307             : 
    3308             : 
    3309             : /*****************************************************************************
    3310             :  *
    3311             :  *      QUERY :
    3312             :  *              COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
    3313             :  *              COPY ( query ) TO file  [WITH] [(options)]
    3314             :  *
    3315             :  *              where 'query' can be one of:
    3316             :  *              { SELECT | UPDATE | INSERT | DELETE }
    3317             :  *
    3318             :  *              and 'file' can be one of:
    3319             :  *              { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
    3320             :  *
    3321             :  *              In the preferred syntax the options are comma-separated
    3322             :  *              and use generic identifiers instead of keywords.  The pre-9.0
    3323             :  *              syntax had a hard-wired, space-separated set of options.
    3324             :  *
    3325             :  *              Really old syntax, from versions 7.2 and prior:
    3326             :  *              COPY [ BINARY ] table FROM/TO file
    3327             :  *                  [ [ USING ] DELIMITERS 'delimiter' ] ]
    3328             :  *                  [ WITH NULL AS 'null string' ]
    3329             :  *              This option placement is not supported with COPY (query...).
    3330             :  *
    3331             :  *****************************************************************************/
    3332             : 
    3333             : CopyStmt:   COPY opt_binary qualified_name opt_column_list
    3334             :             copy_from opt_program copy_file_name copy_delimiter opt_with
    3335             :             copy_options where_clause
    3336             :                 {
    3337        9066 :                     CopyStmt *n = makeNode(CopyStmt);
    3338             : 
    3339        9066 :                     n->relation = $3;
    3340        9066 :                     n->query = NULL;
    3341        9066 :                     n->attlist = $4;
    3342        9066 :                     n->is_from = $5;
    3343        9066 :                     n->is_program = $6;
    3344        9066 :                     n->filename = $7;
    3345        9066 :                     n->whereClause = $11;
    3346             : 
    3347        9066 :                     if (n->is_program && n->filename == NULL)
    3348           0 :                         ereport(ERROR,
    3349             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3350             :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3351             :                                  parser_errposition(@8)));
    3352             : 
    3353        9066 :                     if (!n->is_from && n->whereClause != NULL)
    3354           6 :                         ereport(ERROR,
    3355             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3356             :                                  errmsg("WHERE clause not allowed with COPY TO"),
    3357             :                                  parser_errposition(@11)));
    3358             : 
    3359        9060 :                     n->options = NIL;
    3360             :                     /* Concatenate user-supplied flags */
    3361        9060 :                     if ($2)
    3362          12 :                         n->options = lappend(n->options, $2);
    3363        9060 :                     if ($8)
    3364           0 :                         n->options = lappend(n->options, $8);
    3365        9060 :                     if ($10)
    3366         788 :                         n->options = list_concat(n->options, $10);
    3367        9060 :                     $$ = (Node *) n;
    3368             :                 }
    3369             :             | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
    3370             :                 {
    3371         400 :                     CopyStmt *n = makeNode(CopyStmt);
    3372             : 
    3373         400 :                     n->relation = NULL;
    3374         400 :                     n->query = $3;
    3375         400 :                     n->attlist = NIL;
    3376         400 :                     n->is_from = false;
    3377         400 :                     n->is_program = $6;
    3378         400 :                     n->filename = $7;
    3379         400 :                     n->options = $9;
    3380             : 
    3381         400 :                     if (n->is_program && n->filename == NULL)
    3382           0 :                         ereport(ERROR,
    3383             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3384             :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3385             :                                  parser_errposition(@5)));
    3386             : 
    3387         400 :                     $$ = (Node *) n;
    3388             :                 }
    3389             :         ;
    3390             : 
    3391             : copy_from:
    3392        1506 :             FROM                                    { $$ = true; }
    3393        7560 :             | TO                                    { $$ = false; }
    3394             :         ;
    3395             : 
    3396             : opt_program:
    3397           0 :             PROGRAM                                 { $$ = true; }
    3398        9466 :             | /* EMPTY */                           { $$ = false; }
    3399             :         ;
    3400             : 
    3401             : /*
    3402             :  * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
    3403             :  * used depends on the direction. (It really doesn't make sense to copy from
    3404             :  * stdout. We silently correct the "typo".)        - AY 9/94
    3405             :  */
    3406             : copy_file_name:
    3407         378 :             Sconst                                  { $$ = $1; }
    3408        1204 :             | STDIN                                 { $$ = NULL; }
    3409        7884 :             | STDOUT                                { $$ = NULL; }
    3410             :         ;
    3411             : 
    3412        8966 : copy_options: copy_opt_list                         { $$ = $1; }
    3413         500 :             | '(' copy_generic_opt_list ')'         { $$ = $2; }
    3414             :         ;
    3415             : 
    3416             : /* old COPY option syntax */
    3417             : copy_opt_list:
    3418         498 :             copy_opt_list copy_opt_item             { $$ = lappend($1, $2); }
    3419        8966 :             | /* EMPTY */                           { $$ = NIL; }
    3420             :         ;
    3421             : 
    3422             : copy_opt_item:
    3423             :             BINARY
    3424             :                 {
    3425           0 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3426             :                 }
    3427             :             | FREEZE
    3428             :                 {
    3429          50 :                     $$ = makeDefElem("freeze", (Node *) makeBoolean(true), @1);
    3430             :                 }
    3431             :             | DELIMITER opt_as Sconst
    3432             :                 {
    3433         172 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @1);
    3434             :                 }
    3435             :             | NULL_P opt_as Sconst
    3436             :                 {
    3437          48 :                     $$ = makeDefElem("null", (Node *) makeString($3), @1);
    3438             :                 }
    3439             :             | CSV
    3440             :                 {
    3441         144 :                     $$ = makeDefElem("format", (Node *) makeString("csv"), @1);
    3442             :                 }
    3443             :             | HEADER_P
    3444             :                 {
    3445          18 :                     $$ = makeDefElem("header", (Node *) makeBoolean(true), @1);
    3446             :                 }
    3447             :             | QUOTE opt_as Sconst
    3448             :                 {
    3449          18 :                     $$ = makeDefElem("quote", (Node *) makeString($3), @1);
    3450             :                 }
    3451             :             | ESCAPE opt_as Sconst
    3452             :                 {
    3453          18 :                     $$ = makeDefElem("escape", (Node *) makeString($3), @1);
    3454             :                 }
    3455             :             | FORCE QUOTE columnList
    3456             :                 {
    3457          12 :                     $$ = makeDefElem("force_quote", (Node *) $3, @1);
    3458             :                 }
    3459             :             | FORCE QUOTE '*'
    3460             :                 {
    3461           6 :                     $$ = makeDefElem("force_quote", (Node *) makeNode(A_Star), @1);
    3462             :                 }
    3463             :             | FORCE NOT NULL_P columnList
    3464             :                 {
    3465           0 :                     $$ = makeDefElem("force_not_null", (Node *) $4, @1);
    3466             :                 }
    3467             :             | FORCE NOT NULL_P '*'
    3468             :                 {
    3469           0 :                     $$ = makeDefElem("force_not_null", (Node *) makeNode(A_Star), @1);
    3470             :                 }
    3471             :             | FORCE NULL_P columnList
    3472             :                 {
    3473           0 :                     $$ = makeDefElem("force_null", (Node *) $3, @1);
    3474             :                 }
    3475             :             | FORCE NULL_P '*'
    3476             :                 {
    3477           0 :                     $$ = makeDefElem("force_null", (Node *) makeNode(A_Star), @1);
    3478             :                 }
    3479             :             | ENCODING Sconst
    3480             :                 {
    3481          12 :                     $$ = makeDefElem("encoding", (Node *) makeString($2), @1);
    3482             :                 }
    3483             :         ;
    3484             : 
    3485             : /* The following exist for backward compatibility with very old versions */
    3486             : 
    3487             : opt_binary:
    3488             :             BINARY
    3489             :                 {
    3490          12 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3491             :                 }
    3492        9054 :             | /*EMPTY*/                             { $$ = NULL; }
    3493             :         ;
    3494             : 
    3495             : copy_delimiter:
    3496             :             opt_using DELIMITERS Sconst
    3497             :                 {
    3498           0 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @2);
    3499             :                 }
    3500        9066 :             | /*EMPTY*/                             { $$ = NULL; }
    3501             :         ;
    3502             : 
    3503             : opt_using:
    3504             :             USING
    3505             :             | /*EMPTY*/
    3506             :         ;
    3507             : 
    3508             : /* new COPY option syntax */
    3509             : copy_generic_opt_list:
    3510             :             copy_generic_opt_elem
    3511             :                 {
    3512         500 :                     $$ = list_make1($1);
    3513             :                 }
    3514             :             | copy_generic_opt_list ',' copy_generic_opt_elem
    3515             :                 {
    3516         348 :                     $$ = lappend($1, $3);
    3517             :                 }
    3518             :         ;
    3519             : 
    3520             : copy_generic_opt_elem:
    3521             :             ColLabel copy_generic_opt_arg
    3522             :                 {
    3523         848 :                     $$ = makeDefElem($1, $2, @1);
    3524             :                 }
    3525             :         ;
    3526             : 
    3527             : copy_generic_opt_arg:
    3528         626 :             opt_boolean_or_string           { $$ = (Node *) makeString($1); }
    3529           0 :             | NumericOnly                   { $$ = (Node *) $1; }
    3530          54 :             | '*'                           { $$ = (Node *) makeNode(A_Star); }
    3531         150 :             | '(' copy_generic_opt_arg_list ')'     { $$ = (Node *) $2; }
    3532          18 :             | /* EMPTY */                   { $$ = NULL; }
    3533             :         ;
    3534             : 
    3535             : copy_generic_opt_arg_list:
    3536             :               copy_generic_opt_arg_list_item
    3537             :                 {
    3538         150 :                     $$ = list_make1($1);
    3539             :                 }
    3540             :             | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
    3541             :                 {
    3542          12 :                     $$ = lappend($1, $3);
    3543             :                 }
    3544             :         ;
    3545             : 
    3546             : /* beware of emitting non-string list elements here; see commands/define.c */
    3547             : copy_generic_opt_arg_list_item:
    3548         162 :             opt_boolean_or_string   { $$ = (Node *) makeString($1); }
    3549             :         ;
    3550             : 
    3551             : 
    3552             : /*****************************************************************************
    3553             :  *
    3554             :  *      QUERY :
    3555             :  *              CREATE TABLE relname
    3556             :  *
    3557             :  *****************************************************************************/
    3558             : 
    3559             : CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
    3560             :             OptInherit OptPartitionSpec table_access_method_clause OptWith
    3561             :             OnCommitOption OptTableSpace
    3562             :                 {
    3563       26466 :                     CreateStmt *n = makeNode(CreateStmt);
    3564             : 
    3565       26466 :                     $4->relpersistence = $2;
    3566       26466 :                     n->relation = $4;
    3567       26466 :                     n->tableElts = $6;
    3568       26466 :                     n->inhRelations = $8;
    3569       26466 :                     n->partspec = $9;
    3570       26466 :                     n->ofTypename = NULL;
    3571       26466 :                     n->constraints = NIL;
    3572       26466 :                     n->accessMethod = $10;
    3573       26466 :                     n->options = $11;
    3574       26466 :                     n->oncommit = $12;
    3575       26466 :                     n->tablespacename = $13;
    3576       26466 :                     n->if_not_exists = false;
    3577       26466 :                     $$ = (Node *) n;
    3578             :                 }
    3579             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
    3580             :             OptTableElementList ')' OptInherit OptPartitionSpec table_access_method_clause
    3581             :             OptWith OnCommitOption OptTableSpace
    3582             :                 {
    3583          30 :                     CreateStmt *n = makeNode(CreateStmt);
    3584             : 
    3585          30 :                     $7->relpersistence = $2;
    3586          30 :                     n->relation = $7;
    3587          30 :                     n->tableElts = $9;
    3588          30 :                     n->inhRelations = $11;
    3589          30 :                     n->partspec = $12;
    3590          30 :                     n->ofTypename = NULL;
    3591          30 :                     n->constraints = NIL;
    3592          30 :                     n->accessMethod = $13;
    3593          30 :                     n->options = $14;
    3594          30 :                     n->oncommit = $15;
    3595          30 :                     n->tablespacename = $16;
    3596          30 :                     n->if_not_exists = true;
    3597          30 :                     $$ = (Node *) n;
    3598             :                 }
    3599             :         | CREATE OptTemp TABLE qualified_name OF any_name
    3600             :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3601             :             OptWith OnCommitOption OptTableSpace
    3602             :                 {
    3603         110 :                     CreateStmt *n = makeNode(CreateStmt);
    3604             : 
    3605         110 :                     $4->relpersistence = $2;
    3606         110 :                     n->relation = $4;
    3607         110 :                     n->tableElts = $7;
    3608         110 :                     n->inhRelations = NIL;
    3609         110 :                     n->partspec = $8;
    3610         110 :                     n->ofTypename = makeTypeNameFromNameList($6);
    3611         110 :                     n->ofTypename->location = @6;
    3612         110 :                     n->constraints = NIL;
    3613         110 :                     n->accessMethod = $9;
    3614         110 :                     n->options = $10;
    3615         110 :                     n->oncommit = $11;
    3616         110 :                     n->tablespacename = $12;
    3617         110 :                     n->if_not_exists = false;
    3618         110 :                     $$ = (Node *) n;
    3619             :                 }
    3620             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
    3621             :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3622             :             OptWith OnCommitOption OptTableSpace
    3623             :                 {
    3624           6 :                     CreateStmt *n = makeNode(CreateStmt);
    3625             : 
    3626           6 :                     $7->relpersistence = $2;
    3627           6 :                     n->relation = $7;
    3628           6 :                     n->tableElts = $10;
    3629           6 :                     n->inhRelations = NIL;
    3630           6 :                     n->partspec = $11;
    3631           6 :                     n->ofTypename = makeTypeNameFromNameList($9);
    3632           6 :                     n->ofTypename->location = @9;
    3633           6 :                     n->constraints = NIL;
    3634           6 :                     n->accessMethod = $12;
    3635           6 :                     n->options = $13;
    3636           6 :                     n->oncommit = $14;
    3637           6 :                     n->tablespacename = $15;
    3638           6 :                     n->if_not_exists = true;
    3639           6 :                     $$ = (Node *) n;
    3640             :                 }
    3641             :         | CREATE OptTemp TABLE qualified_name PARTITION OF qualified_name
    3642             :             OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3643             :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3644             :                 {
    3645        7512 :                     CreateStmt *n = makeNode(CreateStmt);
    3646             : 
    3647        7512 :                     $4->relpersistence = $2;
    3648        7512 :                     n->relation = $4;
    3649        7512 :                     n->tableElts = $8;
    3650        7512 :                     n->inhRelations = list_make1($7);
    3651        7512 :                     n->partbound = $9;
    3652        7512 :                     n->partspec = $10;
    3653        7512 :                     n->ofTypename = NULL;
    3654        7512 :                     n->constraints = NIL;
    3655        7512 :                     n->accessMethod = $11;
    3656        7512 :                     n->options = $12;
    3657        7512 :                     n->oncommit = $13;
    3658        7512 :                     n->tablespacename = $14;
    3659        7512 :                     n->if_not_exists = false;
    3660        7512 :                     $$ = (Node *) n;
    3661             :                 }
    3662             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name PARTITION OF
    3663             :             qualified_name OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3664             :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3665             :                 {
    3666           0 :                     CreateStmt *n = makeNode(CreateStmt);
    3667             : 
    3668           0 :                     $7->relpersistence = $2;
    3669           0 :                     n->relation = $7;
    3670           0 :                     n->tableElts = $11;
    3671           0 :                     n->inhRelations = list_make1($10);
    3672           0 :                     n->partbound = $12;
    3673           0 :                     n->partspec = $13;
    3674           0 :                     n->ofTypename = NULL;
    3675           0 :                     n->constraints = NIL;
    3676           0 :                     n->accessMethod = $14;
    3677           0 :                     n->options = $15;
    3678           0 :                     n->oncommit = $16;
    3679           0 :                     n->tablespacename = $17;
    3680           0 :                     n->if_not_exists = true;
    3681           0 :                     $$ = (Node *) n;
    3682             :                 }
    3683             :         ;
    3684             : 
    3685             : /*
    3686             :  * Redundancy here is needed to avoid shift/reduce conflicts,
    3687             :  * since TEMP is not a reserved word.  See also OptTempTableName.
    3688             :  *
    3689             :  * NOTE: we accept both GLOBAL and LOCAL options.  They currently do nothing,
    3690             :  * but future versions might consider GLOBAL to request SQL-spec-compliant
    3691             :  * temp table behavior, so warn about that.  Since we have no modules the
    3692             :  * LOCAL keyword is really meaningless; furthermore, some other products
    3693             :  * implement LOCAL as meaning the same as our default temp table behavior,
    3694             :  * so we'll probably continue to treat LOCAL as a noise word.
    3695             :  */
    3696         294 : OptTemp:    TEMPORARY                   { $$ = RELPERSISTENCE_TEMP; }
    3697        2568 :             | TEMP                      { $$ = RELPERSISTENCE_TEMP; }
    3698           0 :             | LOCAL TEMPORARY           { $$ = RELPERSISTENCE_TEMP; }
    3699           0 :             | LOCAL TEMP                { $$ = RELPERSISTENCE_TEMP; }
    3700             :             | GLOBAL TEMPORARY
    3701             :                 {
    3702           0 :                     ereport(WARNING,
    3703             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3704             :                              parser_errposition(@1)));
    3705           0 :                     $$ = RELPERSISTENCE_TEMP;
    3706             :                 }
    3707             :             | GLOBAL TEMP
    3708             :                 {
    3709           0 :                     ereport(WARNING,
    3710             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3711             :                              parser_errposition(@1)));
    3712           0 :                     $$ = RELPERSISTENCE_TEMP;
    3713             :                 }
    3714         152 :             | UNLOGGED                  { $$ = RELPERSISTENCE_UNLOGGED; }
    3715       46736 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    3716             :         ;
    3717             : 
    3718             : OptTableElementList:
    3719       25534 :             TableElementList                    { $$ = $1; }
    3720        1360 :             | /*EMPTY*/                         { $$ = NIL; }
    3721             :         ;
    3722             : 
    3723             : OptTypedTableElementList:
    3724         302 :             '(' TypedTableElementList ')'       { $$ = $2; }
    3725        7422 :             | /*EMPTY*/                         { $$ = NIL; }
    3726             :         ;
    3727             : 
    3728             : TableElementList:
    3729             :             TableElement
    3730             :                 {
    3731       25582 :                     $$ = list_make1($1);
    3732             :                 }
    3733             :             | TableElementList ',' TableElement
    3734             :                 {
    3735       37238 :                     $$ = lappend($1, $3);
    3736             :                 }
    3737             :         ;
    3738             : 
    3739             : TypedTableElementList:
    3740             :             TypedTableElement
    3741             :                 {
    3742         302 :                     $$ = list_make1($1);
    3743             :                 }
    3744             :             | TypedTableElementList ',' TypedTableElement
    3745             :                 {
    3746          68 :                     $$ = lappend($1, $3);
    3747             :                 }
    3748             :         ;
    3749             : 
    3750             : TableElement:
    3751       59754 :             columnDef                           { $$ = $1; }
    3752         714 :             | TableLikeClause                   { $$ = $1; }
    3753        2352 :             | TableConstraint                   { $$ = $1; }
    3754             :         ;
    3755             : 
    3756             : TypedTableElement:
    3757         300 :             columnOptions                       { $$ = $1; }
    3758          70 :             | TableConstraint                   { $$ = $1; }
    3759             :         ;
    3760             : 
    3761             : columnDef:  ColId Typename opt_column_storage opt_column_compression create_generic_options ColQualList
    3762             :                 {
    3763       61694 :                     ColumnDef *n = makeNode(ColumnDef);
    3764             : 
    3765       61694 :                     n->colname = $1;
    3766       61694 :                     n->typeName = $2;
    3767       61694 :                     n->storage_name = $3;
    3768       61694 :                     n->compression = $4;
    3769       61694 :                     n->inhcount = 0;
    3770       61694 :                     n->is_local = true;
    3771       61694 :                     n->is_not_null = false;
    3772       61694 :                     n->is_from_type = false;
    3773       61694 :                     n->storage = 0;
    3774       61694 :                     n->raw_default = NULL;
    3775       61694 :                     n->cooked_default = NULL;
    3776       61694 :                     n->collOid = InvalidOid;
    3777       61694 :                     n->fdwoptions = $5;
    3778       61694 :                     SplitColQualList($6, &n->constraints, &n->collClause,
    3779             :                                      yyscanner);
    3780       61694 :                     n->location = @1;
    3781       61694 :                     $$ = (Node *) n;
    3782             :                 }
    3783             :         ;
    3784             : 
    3785             : columnOptions:  ColId ColQualList
    3786             :                 {
    3787         120 :                     ColumnDef *n = makeNode(ColumnDef);
    3788             : 
    3789         120 :                     n->colname = $1;
    3790         120 :                     n->typeName = NULL;
    3791         120 :                     n->inhcount = 0;
    3792         120 :                     n->is_local = true;
    3793         120 :                     n->is_not_null = false;
    3794         120 :                     n->is_from_type = false;
    3795         120 :                     n->storage = 0;
    3796         120 :                     n->raw_default = NULL;
    3797         120 :                     n->cooked_default = NULL;
    3798         120 :                     n->collOid = InvalidOid;
    3799         120 :                     SplitColQualList($2, &n->constraints, &n->collClause,
    3800             :                                      yyscanner);
    3801         120 :                     n->location = @1;
    3802         120 :                     $$ = (Node *) n;
    3803             :                 }
    3804             :                 | ColId WITH OPTIONS ColQualList
    3805             :                 {
    3806         180 :                     ColumnDef *n = makeNode(ColumnDef);
    3807             : 
    3808         180 :                     n->colname = $1;
    3809         180 :                     n->typeName = NULL;
    3810         180 :                     n->inhcount = 0;
    3811         180 :                     n->is_local = true;
    3812         180 :                     n->is_not_null = false;
    3813         180 :                     n->is_from_type = false;
    3814         180 :                     n->storage = 0;
    3815         180 :                     n->raw_default = NULL;
    3816         180 :                     n->cooked_default = NULL;
    3817         180 :                     n->collOid = InvalidOid;
    3818         180 :                     SplitColQualList($4, &n->constraints, &n->collClause,
    3819             :                                      yyscanner);
    3820         180 :                     n->location = @1;
    3821         180 :                     $$ = (Node *) n;
    3822             :                 }
    3823             :         ;
    3824             : 
    3825             : column_compression:
    3826         136 :             COMPRESSION ColId                       { $$ = $2; }
    3827           6 :             | COMPRESSION DEFAULT                   { $$ = pstrdup("default"); }
    3828             :         ;
    3829             : 
    3830             : opt_column_compression:
    3831          76 :             column_compression                      { $$ = $1; }
    3832       61678 :             | /*EMPTY*/                             { $$ = NULL; }
    3833             :         ;
    3834             : 
    3835             : column_storage:
    3836         226 :             STORAGE ColId                           { $$ = $2; }
    3837           6 :             | STORAGE DEFAULT                       { $$ = pstrdup("default"); }
    3838             :         ;
    3839             : 
    3840             : opt_column_storage:
    3841          20 :             column_storage                          { $$ = $1; }
    3842       61734 :             | /*EMPTY*/                             { $$ = NULL; }
    3843             :         ;
    3844             : 
    3845             : ColQualList:
    3846       16832 :             ColQualList ColConstraint               { $$ = lappend($1, $2); }
    3847       63168 :             | /*EMPTY*/                             { $$ = NIL; }
    3848             :         ;
    3849             : 
    3850             : ColConstraint:
    3851             :             CONSTRAINT name ColConstraintElem
    3852             :                 {
    3853         684 :                     Constraint *n = castNode(Constraint, $3);
    3854             : 
    3855         684 :                     n->conname = $2;
    3856         684 :                     n->location = @1;
    3857         684 :                     $$ = (Node *) n;
    3858             :                 }
    3859       15360 :             | ColConstraintElem                     { $$ = $1; }
    3860         174 :             | ConstraintAttr                        { $$ = $1; }
    3861             :             | COLLATE any_name
    3862             :                 {
    3863             :                     /*
    3864             :                      * Note: the CollateClause is momentarily included in
    3865             :                      * the list built by ColQualList, but we split it out
    3866             :                      * again in SplitColQualList.
    3867             :                      */
    3868         614 :                     CollateClause *n = makeNode(CollateClause);
    3869             : 
    3870         614 :                     n->arg = NULL;
    3871         614 :                     n->collname = $2;
    3872         614 :                     n->location = @1;
    3873         614 :                     $$ = (Node *) n;
    3874             :                 }
    3875             :         ;
    3876             : 
    3877             : /* DEFAULT NULL is already the default for Postgres.
    3878             :  * But define it here and carry it forward into the system
    3879             :  * to make it explicit.
    3880             :  * - thomas 1998-09-13
    3881             :  *
    3882             :  * WITH NULL and NULL are not SQL-standard syntax elements,
    3883             :  * so leave them out. Use DEFAULT NULL to explicitly indicate
    3884             :  * that a column may have that value. WITH NULL leads to
    3885             :  * shift/reduce conflicts with WITH TIME ZONE anyway.
    3886             :  * - thomas 1999-01-08
    3887             :  *
    3888             :  * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
    3889             :  * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
    3890             :  * or be part of a_expr NOT LIKE or similar constructs).
    3891             :  */
    3892             : ColConstraintElem:
    3893             :             NOT NULL_P opt_no_inherit
    3894             :                 {
    3895        5986 :                     Constraint *n = makeNode(Constraint);
    3896             : 
    3897        5986 :                     n->contype = CONSTR_NOTNULL;
    3898        5986 :                     n->location = @1;
    3899        5986 :                     n->is_no_inherit = $3;
    3900        5986 :                     n->skip_validation = false;
    3901        5986 :                     n->initially_valid = true;
    3902        5986 :                     $$ = (Node *) n;
    3903             :                 }
    3904             :             | NULL_P
    3905             :                 {
    3906          24 :                     Constraint *n = makeNode(Constraint);
    3907             : 
    3908          24 :                     n->contype = CONSTR_NULL;
    3909          24 :                     n->location = @1;
    3910          24 :                     $$ = (Node *) n;
    3911             :                 }
    3912             :             | UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace
    3913             :                 {
    3914         398 :                     Constraint *n = makeNode(Constraint);
    3915             : 
    3916         398 :                     n->contype = CONSTR_UNIQUE;
    3917         398 :                     n->location = @1;
    3918         398 :                     n->nulls_not_distinct = !$2;
    3919         398 :                     n->keys = NULL;
    3920         398 :                     n->options = $3;
    3921         398 :                     n->indexname = NULL;
    3922         398 :                     n->indexspace = $4;
    3923         398 :                     $$ = (Node *) n;
    3924             :                 }
    3925             :             | PRIMARY KEY opt_definition OptConsTableSpace
    3926             :                 {
    3927        5304 :                     Constraint *n = makeNode(Constraint);
    3928             : 
    3929        5304 :                     n->contype = CONSTR_PRIMARY;
    3930        5304 :                     n->location = @1;
    3931        5304 :                     n->keys = NULL;
    3932        5304 :                     n->options = $3;
    3933        5304 :                     n->indexname = NULL;
    3934        5304 :                     n->indexspace = $4;
    3935        5304 :                     $$ = (Node *) n;
    3936             :                 }
    3937             :             | CHECK '(' a_expr ')' opt_no_inherit
    3938             :                 {
    3939         852 :                     Constraint *n = makeNode(Constraint);
    3940             : 
    3941         852 :                     n->contype = CONSTR_CHECK;
    3942         852 :                     n->location = @1;
    3943         852 :                     n->is_no_inherit = $5;
    3944         852 :                     n->raw_expr = $3;
    3945         852 :                     n->cooked_expr = NULL;
    3946         852 :                     n->skip_validation = false;
    3947         852 :                     n->initially_valid = true;
    3948         852 :                     $$ = (Node *) n;
    3949             :                 }
    3950             :             | DEFAULT b_expr
    3951             :                 {
    3952        1622 :                     Constraint *n = makeNode(Constraint);
    3953             : 
    3954        1622 :                     n->contype = CONSTR_DEFAULT;
    3955        1622 :                     n->location = @1;
    3956        1622 :                     n->raw_expr = $2;
    3957        1622 :                     n->cooked_expr = NULL;
    3958        1622 :                     $$ = (Node *) n;
    3959             :                 }
    3960             :             | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    3961             :                 {
    3962         260 :                     Constraint *n = makeNode(Constraint);
    3963             : 
    3964         260 :                     n->contype = CONSTR_IDENTITY;
    3965         260 :                     n->generated_when = $2;
    3966         260 :                     n->options = $5;
    3967         260 :                     n->location = @1;
    3968         260 :                     $$ = (Node *) n;
    3969             :                 }
    3970             :             | GENERATED generated_when AS '(' a_expr ')' STORED
    3971             :                 {
    3972         860 :                     Constraint *n = makeNode(Constraint);
    3973             : 
    3974         860 :                     n->contype = CONSTR_GENERATED;
    3975         860 :                     n->generated_when = $2;
    3976         860 :                     n->raw_expr = $5;
    3977         860 :                     n->cooked_expr = NULL;
    3978         860 :                     n->location = @1;
    3979             : 
    3980             :                     /*
    3981             :                      * Can't do this in the grammar because of shift/reduce
    3982             :                      * conflicts.  (IDENTITY allows both ALWAYS and BY
    3983             :                      * DEFAULT, but generated columns only allow ALWAYS.)  We
    3984             :                      * can also give a more useful error message and location.
    3985             :                      */
    3986         860 :                     if ($2 != ATTRIBUTE_IDENTITY_ALWAYS)
    3987           6 :                         ereport(ERROR,
    3988             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3989             :                                  errmsg("for a generated column, GENERATED ALWAYS must be specified"),
    3990             :                                  parser_errposition(@2)));
    3991             : 
    3992         854 :                     $$ = (Node *) n;
    3993             :                 }
    3994             :             | REFERENCES qualified_name opt_column_list key_match key_actions
    3995             :                 {
    3996         744 :                     Constraint *n = makeNode(Constraint);
    3997             : 
    3998         744 :                     n->contype = CONSTR_FOREIGN;
    3999         744 :                     n->location = @1;
    4000         744 :                     n->pktable = $2;
    4001         744 :                     n->fk_attrs = NIL;
    4002         744 :                     n->pk_attrs = $3;
    4003         744 :                     n->fk_matchtype = $4;
    4004         744 :                     n->fk_upd_action = ($5)->updateAction->action;
    4005         744 :                     n->fk_del_action = ($5)->deleteAction->action;
    4006         744 :                     n->fk_del_set_cols = ($5)->deleteAction->cols;
    4007         744 :                     n->skip_validation = false;
    4008         744 :                     n->initially_valid = true;
    4009         744 :                     $$ = (Node *) n;
    4010             :                 }
    4011             :         ;
    4012             : 
    4013             : opt_unique_null_treatment:
    4014          12 :             NULLS_P DISTINCT        { $$ = true; }
    4015          30 :             | NULLS_P NOT DISTINCT  { $$ = false; }
    4016        7156 :             | /*EMPTY*/             { $$ = true; }
    4017             :         ;
    4018             : 
    4019             : generated_when:
    4020        1172 :             ALWAYS          { $$ = ATTRIBUTE_IDENTITY_ALWAYS; }
    4021         146 :             | BY DEFAULT    { $$ = ATTRIBUTE_IDENTITY_BY_DEFAULT; }
    4022             :         ;
    4023             : 
    4024             : /*
    4025             :  * ConstraintAttr represents constraint attributes, which we parse as if
    4026             :  * they were independent constraint clauses, in order to avoid shift/reduce
    4027             :  * conflicts (since NOT might start either an independent NOT NULL clause
    4028             :  * or an attribute).  parse_utilcmd.c is responsible for attaching the
    4029             :  * attribute information to the preceding "real" constraint node, and for
    4030             :  * complaining if attribute clauses appear in the wrong place or wrong
    4031             :  * combinations.
    4032             :  *
    4033             :  * See also ConstraintAttributeSpec, which can be used in places where
    4034             :  * there is no parsing conflict.  (Note: currently, NOT VALID and NO INHERIT
    4035             :  * are allowed clauses in ConstraintAttributeSpec, but not here.  Someday we
    4036             :  * might need to allow them here too, but for the moment it doesn't seem
    4037             :  * useful in the statements that use ConstraintAttr.)
    4038             :  */
    4039             : ConstraintAttr:
    4040             :             DEFERRABLE
    4041             :                 {
    4042          96 :                     Constraint *n = makeNode(Constraint);
    4043             : 
    4044          96 :                     n->contype = CONSTR_ATTR_DEFERRABLE;
    4045          96 :                     n->location = @1;
    4046          96 :                     $$ = (Node *) n;
    4047             :                 }
    4048             :             | NOT DEFERRABLE
    4049             :                 {
    4050           0 :                     Constraint *n = makeNode(Constraint);
    4051             : 
    4052           0 :                     n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
    4053           0 :                     n->location = @1;
    4054           0 :                     $$ = (Node *) n;
    4055             :                 }
    4056             :             | INITIALLY DEFERRED
    4057             :                 {
    4058          72 :                     Constraint *n = makeNode(Constraint);
    4059             : 
    4060          72 :                     n->contype = CONSTR_ATTR_DEFERRED;
    4061          72 :                     n->location = @1;
    4062          72 :                     $$ = (Node *) n;
    4063             :                 }
    4064             :             | INITIALLY IMMEDIATE
    4065             :                 {
    4066           6 :                     Constraint *n = makeNode(Constraint);
    4067             : 
    4068           6 :                     n->contype = CONSTR_ATTR_IMMEDIATE;
    4069           6 :                     n->location = @1;
    4070           6 :                     $$ = (Node *) n;
    4071             :                 }
    4072             :         ;
    4073             : 
    4074             : 
    4075             : TableLikeClause:
    4076             :             LIKE qualified_name TableLikeOptionList
    4077             :                 {
    4078         714 :                     TableLikeClause *n = makeNode(TableLikeClause);
    4079             : 
    4080         714 :                     n->relation = $2;
    4081         714 :                     n->options = $3;
    4082         714 :                     n->relationOid = InvalidOid;
    4083         714 :                     $$ = (Node *) n;
    4084             :                 }
    4085             :         ;
    4086             : 
    4087             : TableLikeOptionList:
    4088         252 :                 TableLikeOptionList INCLUDING TableLikeOption   { $$ = $1 | $3; }
    4089           2 :                 | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
    4090         714 :                 | /* EMPTY */                       { $$ = 0; }
    4091             :         ;
    4092             : 
    4093             : TableLikeOption:
    4094          24 :                 COMMENTS            { $$ = CREATE_TABLE_LIKE_COMMENTS; }
    4095           6 :                 | COMPRESSION       { $$ = CREATE_TABLE_LIKE_COMPRESSION; }
    4096          54 :                 | CONSTRAINTS       { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
    4097          20 :                 | DEFAULTS          { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
    4098           6 :                 | IDENTITY_P        { $$ = CREATE_TABLE_LIKE_IDENTITY; }
    4099          24 :                 | GENERATED         { $$ = CREATE_TABLE_LIKE_GENERATED; }
    4100          50 :                 | INDEXES           { $$ = CREATE_TABLE_LIKE_INDEXES; }
    4101           0 :                 | STATISTICS        { $$ = CREATE_TABLE_LIKE_STATISTICS; }
    4102          26 :                 | STORAGE           { $$ = CREATE_TABLE_LIKE_STORAGE; }
    4103          44 :                 | ALL               { $$ = CREATE_TABLE_LIKE_ALL; }
    4104             :         ;
    4105             : 
    4106             : 
    4107             : /* ConstraintElem specifies constraint syntax which is not embedded into
    4108             :  *  a column definition. ColConstraintElem specifies the embedded form.
    4109             :  * - thomas 1997-12-03
    4110             :  */
    4111             : TableConstraint:
    4112             :             CONSTRAINT name ConstraintElem
    4113             :                 {
    4114        3416 :                     Constraint *n = castNode(Constraint, $3);
    4115             : 
    4116        3416 :                     n->conname = $2;
    4117        3416 :                     n->location = @1;
    4118        3416 :                     $$ = (Node *) n;
    4119             :                 }
    4120       10752 :             | ConstraintElem                        { $$ = $1; }
    4121             :         ;
    4122             : 
    4123             : ConstraintElem:
    4124             :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    4125             :                 {
    4126        1182 :                     Constraint *n = makeNode(Constraint);
    4127             : 
    4128        1182 :                     n->contype = CONSTR_CHECK;
    4129        1182 :                     n->location = @1;
    4130        1182 :                     n->raw_expr = $3;
    4131        1182 :                     n->cooked_expr = NULL;
    4132        1182 :                     processCASbits($5, @5, "CHECK",
    4133             :                                    NULL, NULL, &n->skip_validation,
    4134             :                                    &n->is_no_inherit, yyscanner);
    4135        1182 :                     n->initially_valid = !n->skip_validation;
    4136        1182 :                     $$ = (Node *) n;
    4137             :                 }
    4138             :             | NOT NULL_P ColId ConstraintAttributeSpec
    4139             :                 {
    4140         170 :                     Constraint *n = makeNode(Constraint);
    4141             : 
    4142         170 :                     n->contype = CONSTR_NOTNULL;
    4143         170 :                     n->location = @1;
    4144         170 :                     n->keys = list_make1(makeString($3));
    4145             :                     /* no NOT VALID support yet */
    4146         170 :                     processCASbits($4, @4, "NOT NULL",
    4147             :                                    NULL, NULL, NULL,
    4148             :                                    &n->is_no_inherit, yyscanner);
    4149         170 :                     n->initially_valid = true;
    4150         170 :                     $$ = (Node *) n;
    4151             :                 }
    4152             :             | UNIQUE opt_unique_null_treatment '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
    4153             :                 ConstraintAttributeSpec
    4154             :                 {
    4155         512 :                     Constraint *n = makeNode(Constraint);
    4156             : 
    4157         512 :                     n->contype = CONSTR_UNIQUE;
    4158         512 :                     n->location = @1;
    4159         512 :                     n->nulls_not_distinct = !$2;
    4160         512 :                     n->keys = $4;
    4161         512 :                     n->without_overlaps = $5;
    4162         512 :                     n->including = $7;
    4163         512 :                     n->options = $8;
    4164         512 :                     n->indexname = NULL;
    4165         512 :                     n->indexspace = $9;
    4166         512 :                     processCASbits($10, @10, "UNIQUE",
    4167             :                                    &n->deferrable, &n->initdeferred, NULL,
    4168             :                                    NULL, yyscanner);
    4169         512 :                     $$ = (Node *) n;
    4170             :                 }
    4171             :             | UNIQUE ExistingIndex ConstraintAttributeSpec
    4172             :                 {
    4173        3682 :                     Constraint *n = makeNode(Constraint);
    4174             : 
    4175        3682 :                     n->contype = CONSTR_UNIQUE;
    4176        3682 :                     n->location = @1;
    4177        3682 :                     n->keys = NIL;
    4178        3682 :                     n->including = NIL;
    4179        3682 :                     n->options = NIL;
    4180        3682 :                     n->indexname = $2;
    4181        3682 :                     n->indexspace = NULL;
    4182        3682 :                     processCASbits($3, @3, "UNIQUE",
    4183             :                                    &n->deferrable, &n->initdeferred, NULL,
    4184             :                                    NULL, yyscanner);
    4185        3682 :                     $$ = (Node *) n;
    4186             :                 }
    4187             :             | PRIMARY KEY '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
    4188             :                 ConstraintAttributeSpec
    4189             :                 {
    4190        1890 :                     Constraint *n = makeNode(Constraint);
    4191             : 
    4192        1890 :                     n->contype = CONSTR_PRIMARY;
    4193        1890 :                     n->location = @1;
    4194        1890 :                     n->keys = $4;
    4195        1890 :                     n->without_overlaps = $5;
    4196        1890 :                     n->including = $7;
    4197        1890 :                     n->options = $8;
    4198        1890 :                     n->indexname = NULL;
    4199        1890 :                     n->indexspace = $9;
    4200        1890 :                     processCASbits($10, @10, "PRIMARY KEY",
    4201             :                                    &n->deferrable, &n->initdeferred, NULL,
    4202             :                                    NULL, yyscanner);
    4203        1890 :                     $$ = (Node *) n;
    4204             :                 }
    4205             :             | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
    4206             :                 {
    4207        4778 :                     Constraint *n = makeNode(Constraint);
    4208             : 
    4209        4778 :                     n->contype = CONSTR_PRIMARY;
    4210        4778 :                     n->location = @1;
    4211        4778 :                     n->keys = NIL;
    4212        4778 :                     n->including = NIL;
    4213        4778 :                     n->options = NIL;
    4214        4778 :                     n->indexname = $3;
    4215        4778 :                     n->indexspace = NULL;
    4216        4778 :                     processCASbits($4, @4, "PRIMARY KEY",
    4217             :                                    &n->deferrable, &n->initdeferred, NULL,
    4218             :                                    NULL, yyscanner);
    4219        4778 :                     $$ = (Node *) n;
    4220             :                 }
    4221             :             | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
    4222             :                 opt_c_include opt_definition OptConsTableSpace OptWhereClause
    4223             :                 ConstraintAttributeSpec
    4224             :                 {
    4225         234 :                     Constraint *n = makeNode(Constraint);
    4226             : 
    4227         234 :                     n->contype = CONSTR_EXCLUSION;
    4228         234 :                     n->location = @1;
    4229         234 :                     n->access_method = $2;
    4230         234 :                     n->exclusions = $4;
    4231         234 :                     n->including = $6;
    4232         234 :                     n->options = $7;
    4233         234 :                     n->indexname = NULL;
    4234         234 :                     n->indexspace = $8;
    4235         234 :                     n->where_clause = $9;
    4236         234 :                     processCASbits($10, @10, "EXCLUDE",
    4237             :                                    &n->deferrable, &n->initdeferred, NULL,
    4238             :                                    NULL, yyscanner);
    4239         234 :                     $$ = (Node *) n;
    4240             :                 }
    4241             :             | FOREIGN KEY '(' columnList optionalPeriodName ')' REFERENCES qualified_name
    4242             :                 opt_column_and_period_list key_match key_actions ConstraintAttributeSpec
    4243             :                 {
    4244        1720 :                     Constraint *n = makeNode(Constraint);
    4245             : 
    4246        1720 :                     n->contype = CONSTR_FOREIGN;
    4247        1720 :                     n->location = @1;
    4248        1720 :                     n->pktable = $8;
    4249        1720 :                     n->fk_attrs = $4;
    4250        1720 :                     if ($5)
    4251             :                     {
    4252         286 :                         n->fk_attrs = lappend(n->fk_attrs, $5);
    4253         286 :                         n->fk_with_period = true;
    4254             :                     }
    4255        1720 :                     n->pk_attrs = linitial($9);
    4256        1720 :                     if (lsecond($9))
    4257             :                     {
    4258         178 :                         n->pk_attrs = lappend(n->pk_attrs, lsecond($9));
    4259         178 :                         n->pk_with_period = true;
    4260             :                     }
    4261        1720 :                     n->fk_matchtype = $10;
    4262        1720 :                     n->fk_upd_action = ($11)->updateAction->action;
    4263        1720 :                     n->fk_del_action = ($11)->deleteAction->action;
    4264        1720 :                     n->fk_del_set_cols = ($11)->deleteAction->cols;
    4265        1720 :                     processCASbits($12, @12, "FOREIGN KEY",
    4266             :                                    &n->deferrable, &n->initdeferred,
    4267             :                                    &n->skip_validation, NULL,
    4268             :                                    yyscanner);
    4269        1720 :                     n->initially_valid = !n->skip_validation;
    4270        1720 :                     $$ = (Node *) n;
    4271             :                 }
    4272             :         ;
    4273             : 
    4274         228 : opt_no_inherit: NO INHERIT                          {  $$ = true; }
    4275        6610 :             | /* EMPTY */                           {  $$ = false; }
    4276             :         ;
    4277             : 
    4278             : opt_without_overlaps:
    4279         392 :             WITHOUT OVERLAPS                        { $$ = true; }
    4280        2010 :             | /*EMPTY*/                             { $$ = false; }
    4281             :     ;
    4282             : 
    4283             : opt_column_list:
    4284        8672 :             '(' columnList ')'                      { $$ = $2; }
    4285       32862 :             | /*EMPTY*/                             { $$ = NIL; }
    4286             :         ;
    4287             : 
    4288             : columnList:
    4289       14484 :             columnElem                              { $$ = list_make1($1); }
    4290       24462 :             | columnList ',' columnElem             { $$ = lappend($1, $3); }
    4291             :         ;
    4292             : 
    4293             : optionalPeriodName:
    4294         464 :             ',' PERIOD columnElem { $$ = $3; }
    4295        2388 :             | /*EMPTY*/               { $$ = NULL; }
    4296             :     ;
    4297             : 
    4298             : opt_column_and_period_list:
    4299        1126 :             '(' columnList optionalPeriodName ')'           { $$ = list_make2($2, $3); }
    4300         600 :             | /*EMPTY*/                             { $$ = list_make2(NIL, NULL); }
    4301             :         ;
    4302             : 
    4303             : columnElem: ColId
    4304             :                 {
    4305       39410 :                     $$ = (Node *) makeString($1);
    4306             :                 }
    4307             :         ;
    4308             : 
    4309         168 : opt_c_include:  INCLUDE '(' columnList ')'          { $$ = $3; }
    4310        2468 :              |      /* EMPTY */                     { $$ = NIL; }
    4311             :         ;
    4312             : 
    4313             : key_match:  MATCH FULL
    4314             :             {
    4315          98 :                 $$ = FKCONSTR_MATCH_FULL;
    4316             :             }
    4317             :         | MATCH PARTIAL
    4318             :             {
    4319           0 :                 ereport(ERROR,
    4320             :                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4321             :                          errmsg("MATCH PARTIAL not yet implemented"),
    4322             :                          parser_errposition(@1)));
    4323             :                 $$ = FKCONSTR_MATCH_PARTIAL;
    4324             :             }
    4325             :         | MATCH SIMPLE
    4326             :             {
    4327           6 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4328             :             }
    4329             :         | /*EMPTY*/
    4330             :             {
    4331        2366 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4332             :             }
    4333             :         ;
    4334             : 
    4335             : ExclusionConstraintList:
    4336         234 :             ExclusionConstraintElem                 { $$ = list_make1($1); }
    4337             :             | ExclusionConstraintList ',' ExclusionConstraintElem
    4338         106 :                                                     { $$ = lappend($1, $3); }
    4339             :         ;
    4340             : 
    4341             : ExclusionConstraintElem: index_elem WITH any_operator
    4342             :             {
    4343         340 :                 $$ = list_make2($1, $3);
    4344             :             }
    4345             :             /* allow OPERATOR() decoration for the benefit of ruleutils.c */
    4346             :             | index_elem WITH OPERATOR '(' any_operator ')'
    4347             :             {
    4348           0 :                 $$ = list_make2($1, $5);
    4349             :             }
    4350             :         ;
    4351             : 
    4352             : OptWhereClause:
    4353         426 :             WHERE '(' a_expr ')'                    { $$ = $3; }
    4354        1134 :             | /*EMPTY*/                             { $$ = NULL; }
    4355             :         ;
    4356             : 
    4357             : key_actions:
    4358             :             key_update
    4359             :                 {
    4360          50 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4361             : 
    4362          50 :                     n->updateAction = $1;
    4363          50 :                     n->deleteAction = palloc(sizeof(KeyAction));
    4364          50 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4365          50 :                     n->deleteAction->cols = NIL;
    4366          50 :                     $$ = n;
    4367             :                 }
    4368             :             | key_delete
    4369             :                 {
    4370         160 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4371             : 
    4372         160 :                     n->updateAction = palloc(sizeof(KeyAction));
    4373         160 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4374         160 :                     n->updateAction->cols = NIL;
    4375         160 :                     n->deleteAction = $1;
    4376         160 :                     $$ = n;
    4377             :                 }
    4378             :             | key_update key_delete
    4379             :                 {
    4380         150 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4381             : 
    4382         150 :                     n->updateAction = $1;
    4383         150 :                     n->deleteAction = $2;
    4384         150 :                     $$ = n;
    4385             :                 }
    4386             :             | key_delete key_update
    4387             :                 {
    4388         132 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4389             : 
    4390         132 :                     n->updateAction = $2;
    4391         132 :                     n->deleteAction = $1;
    4392         132 :                     $$ = n;
    4393             :                 }
    4394             :             | /*EMPTY*/
    4395             :                 {
    4396        1972 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4397             : 
    4398        1972 :                     n->updateAction = palloc(sizeof(KeyAction));
    4399        1972 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4400        1972 :                     n->updateAction->cols = NIL;
    4401        1972 :                     n->deleteAction = palloc(sizeof(KeyAction));
    4402        1972 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4403        1972 :                     n->deleteAction->cols = NIL;
    4404        1972 :                     $$ = n;
    4405             :                 }
    4406             :         ;
    4407             : 
    4408             : key_update: ON UPDATE key_action
    4409             :                 {
    4410         338 :                     if (($3)->cols)
    4411           6 :                         ereport(ERROR,
    4412             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4413             :                                  errmsg("a column list with %s is only supported for ON DELETE actions",
    4414             :                                         ($3)->action == FKCONSTR_ACTION_SETNULL ? "SET NULL" : "SET DEFAULT"),
    4415             :                                  parser_errposition(@1)));
    4416         332 :                     $$ = $3;
    4417             :                 }
    4418             :         ;
    4419             : 
    4420             : key_delete: ON DELETE_P key_action
    4421             :                 {
    4422         442 :                     $$ = $3;
    4423             :                 }
    4424             :         ;
    4425             : 
    4426             : key_action:
    4427             :             NO ACTION
    4428             :                 {
    4429          74 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4430             : 
    4431          74 :                     n->action = FKCONSTR_ACTION_NOACTION;
    4432          74 :                     n->cols = NIL;
    4433          74 :                     $$ = n;
    4434             :                 }
    4435             :             | RESTRICT
    4436             :                 {
    4437          58 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4438             : 
    4439          58 :                     n->action = FKCONSTR_ACTION_RESTRICT;
    4440          58 :                     n->cols = NIL;
    4441          58 :                     $$ = n;
    4442             :                 }
    4443             :             | CASCADE
    4444             :                 {
    4445         386 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4446             : 
    4447         386 :                     n->action = FKCONSTR_ACTION_CASCADE;
    4448         386 :                     n->cols = NIL;
    4449         386 :                     $$ = n;
    4450             :                 }
    4451             :             | SET NULL_P opt_column_list
    4452             :                 {
    4453         172 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4454             : 
    4455         172 :                     n->action = FKCONSTR_ACTION_SETNULL;
    4456         172 :                     n->cols = $3;
    4457         172 :                     $$ = n;
    4458             :                 }
    4459             :             | SET DEFAULT opt_column_list
    4460             :                 {
    4461          90 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4462             : 
    4463          90 :                     n->action = FKCONSTR_ACTION_SETDEFAULT;
    4464          90 :                     n->cols = $3;
    4465          90 :                     $$ = n;
    4466             :                 }
    4467             :         ;
    4468             : 
    4469        1758 : OptInherit: INHERITS '(' qualified_name_list ')'    { $$ = $3; }
    4470       25118 :             | /*EMPTY*/                             { $$ = NIL; }
    4471             :         ;
    4472             : 
    4473             : /* Optional partition key specification */
    4474        4624 : OptPartitionSpec: PartitionSpec { $$ = $1; }
    4475       29512 :             | /*EMPTY*/         { $$ = NULL; }
    4476             :         ;
    4477             : 
    4478             : PartitionSpec: PARTITION BY ColId '(' part_params ')'
    4479             :                 {
    4480        4630 :                     PartitionSpec *n = makeNode(PartitionSpec);
    4481             : 
    4482        4630 :                     n->strategy = parsePartitionStrategy($3);
    4483        4624 :                     n->partParams = $5;
    4484        4624 :                     n->location = @1;
    4485             : 
    4486        4624 :                     $$ = n;
    4487             :                 }
    4488             :         ;
    4489             : 
    4490        4630 : part_params:    part_elem                       { $$ = list_make1($1); }
    4491         432 :             | part_params ',' part_elem         { $$ = lappend($1, $3); }
    4492             :         ;
    4493             : 
    4494             : part_elem: ColId opt_collate opt_qualified_name
    4495             :                 {
    4496        4764 :                     PartitionElem *n = makeNode(PartitionElem);
    4497             : 
    4498        4764 :                     n->name = $1;
    4499        4764 :                     n->expr = NULL;
    4500        4764 :                     n->collation = $2;
    4501        4764 :                     n->opclass = $3;
    4502        4764 :                     n->location = @1;
    4503        4764 :                     $$ = n;
    4504             :                 }
    4505             :             | func_expr_windowless opt_collate opt_qualified_name
    4506             :                 {
    4507         130 :                     PartitionElem *n = makeNode(PartitionElem);
    4508             : 
    4509         130 :                     n->name = NULL;
    4510         130 :                     n->expr = $1;
    4511         130 :                     n->collation = $2;
    4512         130 :                     n->opclass = $3;
    4513         130 :                     n->location = @1;
    4514         130 :                     $$ = n;
    4515             :                 }
    4516             :             | '(' a_expr ')' opt_collate opt_qualified_name
    4517             :                 {
    4518         168 :                     PartitionElem *n = makeNode(PartitionElem);
    4519             : 
    4520         168 :                     n->name = NULL;
    4521         168 :                     n->expr = $2;
    4522         168 :                     n->collation = $4;
    4523         168 :                     n->opclass = $5;
    4524         168 :                     n->location = @1;
    4525         168 :                     $$ = n;
    4526             :                 }
    4527             :         ;
    4528             : 
    4529             : table_access_method_clause:
    4530         116 :             USING name                          { $$ = $2; }
    4531       35818 :             | /*EMPTY*/                         { $$ = NULL; }
    4532             :         ;
    4533             : 
    4534             : /* WITHOUT OIDS is legacy only */
    4535             : OptWith:
    4536         616 :             WITH reloptions             { $$ = $2; }
    4537          24 :             | WITHOUT OIDS              { $$ = NIL; }
    4538       34730 :             | /*EMPTY*/                 { $$ = NIL; }
    4539             :         ;
    4540             : 
    4541          56 : OnCommitOption:  ON COMMIT DROP             { $$ = ONCOMMIT_DROP; }
    4542          98 :             | ON COMMIT DELETE_P ROWS       { $$ = ONCOMMIT_DELETE_ROWS; }
    4543          24 :             | ON COMMIT PRESERVE ROWS       { $$ = ONCOMMIT_PRESERVE_ROWS; }
    4544       35192 :             | /*EMPTY*/                     { $$ = ONCOMMIT_NOOP; }
    4545             :         ;
    4546             : 
    4547         198 : OptTableSpace:   TABLESPACE name                    { $$ = $2; }
    4548       42018 :             | /*EMPTY*/                             { $$ = NULL; }
    4549             :         ;
    4550             : 
    4551          66 : OptConsTableSpace:   USING INDEX TABLESPACE name    { $$ = $4; }
    4552        8272 :             | /*EMPTY*/                             { $$ = NULL; }
    4553             :         ;
    4554             : 
    4555        8460 : ExistingIndex:   USING INDEX name                   { $$ = $3; }
    4556             :         ;
    4557             : 
    4558             : /*****************************************************************************
    4559             :  *
    4560             :  *      QUERY :
    4561             :  *              CREATE STATISTICS [[IF NOT EXISTS] stats_name] [(stat types)]
    4562             :  *                  ON expression-list FROM from_list
    4563             :  *
    4564             :  * Note: the expectation here is that the clauses after ON are a subset of
    4565             :  * SELECT syntax, allowing for expressions and joined tables, and probably
    4566             :  * someday a WHERE clause.  Much less than that is currently implemented,
    4567             :  * but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
    4568             :  * errors as necessary at execution.
    4569             :  *
    4570             :  * Statistics name is optional unless IF NOT EXISTS is specified.
    4571             :  *
    4572             :  *****************************************************************************/
    4573             : 
    4574             : CreateStatsStmt:
    4575             :             CREATE STATISTICS opt_qualified_name
    4576             :             opt_name_list ON stats_params FROM from_list
    4577             :                 {
    4578         548 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4579             : 
    4580         548 :                     n->defnames = $3;
    4581         548 :                     n->stat_types = $4;
    4582         548 :                     n->exprs = $6;
    4583         548 :                     n->relations = $8;
    4584         548 :                     n->stxcomment = NULL;
    4585         548 :                     n->if_not_exists = false;
    4586         548 :                     $$ = (Node *) n;
    4587             :                 }
    4588             :             | CREATE STATISTICS IF_P NOT EXISTS any_name
    4589             :             opt_name_list ON stats_params FROM from_list
    4590             :                 {
    4591          12 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4592             : 
    4593          12 :                     n->defnames = $6;
    4594          12 :                     n->stat_types = $7;
    4595          12 :                     n->exprs = $9;
    4596          12 :                     n->relations = $11;
    4597          12 :                     n->stxcomment = NULL;
    4598          12 :                     n->if_not_exists = true;
    4599          12 :                     $$ = (Node *) n;
    4600             :                 }
    4601             :             ;
    4602             : 
    4603             : /*
    4604             :  * Statistics attributes can be either simple column references, or arbitrary
    4605             :  * expressions in parens.  For compatibility with index attributes permitted
    4606             :  * in CREATE INDEX, we allow an expression that's just a function call to be
    4607             :  * written without parens.
    4608             :  */
    4609             : 
    4610         572 : stats_params:   stats_param                         { $$ = list_make1($1); }
    4611         922 :             | stats_params ',' stats_param          { $$ = lappend($1, $3); }
    4612             :         ;
    4613             : 
    4614             : stats_param:    ColId
    4615             :                 {
    4616        1062 :                     $$ = makeNode(StatsElem);
    4617        1062 :                     $$->name = $1;
    4618        1062 :                     $$->expr = NULL;
    4619             :                 }
    4620             :             | func_expr_windowless
    4621             :                 {
    4622          20 :                     $$ = makeNode(StatsElem);
    4623          20 :                     $$->name = NULL;
    4624          20 :                     $$->expr = $1;
    4625             :                 }
    4626             :             | '(' a_expr ')'
    4627             :                 {
    4628         412 :                     $$ = makeNode(StatsElem);
    4629         412 :                     $$->name = NULL;
    4630         412 :                     $$->expr = $2;
    4631             :                 }
    4632             :         ;
    4633             : 
    4634             : /*****************************************************************************
    4635             :  *
    4636             :  *      QUERY :
    4637             :  *              ALTER STATISTICS [IF EXISTS] stats_name
    4638             :  *                  SET STATISTICS  <SignedIconst>
    4639             :  *
    4640             :  *****************************************************************************/
    4641             : 
    4642             : AlterStatsStmt:
    4643             :             ALTER STATISTICS any_name SET STATISTICS set_statistics_value
    4644             :                 {
    4645          20 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4646             : 
    4647          20 :                     n->defnames = $3;
    4648          20 :                     n->missing_ok = false;
    4649          20 :                     n->stxstattarget = $6;
    4650          20 :                     $$ = (Node *) n;
    4651             :                 }
    4652             :             | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
    4653             :                 {
    4654           6 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4655             : 
    4656           6 :                     n->defnames = $5;
    4657           6 :                     n->missing_ok = true;
    4658           6 :                     n->stxstattarget = $8;
    4659           6 :                     $$ = (Node *) n;
    4660             :                 }
    4661             :             ;
    4662             : 
    4663             : /*****************************************************************************
    4664             :  *
    4665             :  *      QUERY :
    4666             :  *              CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
    4667             :  *
    4668             :  *
    4669             :  * Note: SELECT ... INTO is a now-deprecated alternative for this.
    4670             :  *
    4671             :  *****************************************************************************/
    4672             : 
    4673             : CreateAsStmt:
    4674             :         CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
    4675             :                 {
    4676        1110 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4677             : 
    4678        1110 :                     ctas->query = $6;
    4679        1110 :                     ctas->into = $4;
    4680        1110 :                     ctas->objtype = OBJECT_TABLE;
    4681        1110 :                     ctas->is_select_into = false;
    4682        1110 :                     ctas->if_not_exists = false;
    4683             :                     /* cram additional flags into the IntoClause */
    4684        1110 :                     $4->rel->relpersistence = $2;
    4685        1110 :                     $4->skipData = !($7);
    4686        1110 :                     $$ = (Node *) ctas;
    4687             :                 }
    4688             :         | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
    4689             :                 {
    4690          52 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4691             : 
    4692          52 :                     ctas->query = $9;
    4693          52 :                     ctas->into = $7;
    4694          52 :                     ctas->objtype = OBJECT_TABLE;
    4695          52 :                     ctas->is_select_into = false;
    4696          52 :                     ctas->if_not_exists = true;
    4697             :                     /* cram additional flags into the IntoClause */
    4698          52 :                     $7->rel->relpersistence = $2;
    4699          52 :                     $7->skipData = !($10);
    4700          52 :                     $$ = (Node *) ctas;
    4701             :                 }
    4702             :         ;
    4703             : 
    4704             : create_as_target:
    4705             :             qualified_name opt_column_list table_access_method_clause
    4706             :             OptWith OnCommitOption OptTableSpace
    4707             :                 {
    4708        1246 :                     $$ = makeNode(IntoClause);
    4709        1246 :                     $$->rel = $1;
    4710        1246 :                     $$->colNames = $2;
    4711        1246 :                     $$->accessMethod = $3;
    4712        1246 :                     $$->options = $4;
    4713        1246 :                     $$->onCommit = $5;
    4714        1246 :                     $$->tableSpaceName = $6;
    4715        1246 :                     $$->viewQuery = NULL;
    4716        1246 :                     $$->skipData = false;        /* might get changed later */
    4717             :                 }
    4718             :         ;
    4719             : 
    4720             : opt_with_data:
    4721          36 :             WITH DATA_P                             { $$ = true; }
    4722         212 :             | WITH NO DATA_P                        { $$ = false; }
    4723        1814 :             | /*EMPTY*/                             { $$ = true; }
    4724             :         ;
    4725             : 
    4726             : 
    4727             : /*****************************************************************************
    4728             :  *
    4729             :  *      QUERY :
    4730             :  *              CREATE MATERIALIZED VIEW relname AS SelectStmt
    4731             :  *
    4732             :  *****************************************************************************/
    4733             : 
    4734             : CreateMatViewStmt:
    4735             :         CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
    4736             :                 {
    4737         510 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4738             : 
    4739         510 :                     ctas->query = $7;
    4740         510 :                     ctas->into = $5;
    4741         510 :                     ctas->objtype = OBJECT_MATVIEW;
    4742         510 :                     ctas->is_select_into = false;
    4743         510 :                     ctas->if_not_exists = false;
    4744             :                     /* cram additional flags into the IntoClause */
    4745         510 :                     $5->rel->relpersistence = $2;
    4746         510 :                     $5->skipData = !($8);
    4747         510 :                     $$ = (Node *) ctas;
    4748             :                 }
    4749             :         | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
    4750             :                 {
    4751          48 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4752             : 
    4753          48 :                     ctas->query = $10;
    4754          48 :                     ctas->into = $8;
    4755          48 :                     ctas->objtype = OBJECT_MATVIEW;
    4756          48 :                     ctas->is_select_into = false;
    4757          48 :                     ctas->if_not_exists = true;
    4758             :                     /* cram additional flags into the IntoClause */
    4759          48 :                     $8->rel->relpersistence = $2;
    4760          48 :                     $8->skipData = !($11);
    4761          48 :                     $$ = (Node *) ctas;
    4762             :                 }
    4763             :         ;
    4764             : 
    4765             : create_mv_target:
    4766             :             qualified_name opt_column_list table_access_method_clause opt_reloptions OptTableSpace
    4767             :                 {
    4768         558 :                     $$ = makeNode(IntoClause);
    4769         558 :                     $$->rel = $1;
    4770         558 :                     $$->colNames = $2;
    4771         558 :                     $$->accessMethod = $3;
    4772         558 :                     $$->options = $4;
    4773         558 :                     $$->onCommit = ONCOMMIT_NOOP;
    4774         558 :                     $$->tableSpaceName = $5;
    4775         558 :                     $$->viewQuery = NULL;        /* filled at analysis time */
    4776         558 :                     $$->skipData = false;        /* might get changed later */
    4777             :                 }
    4778             :         ;
    4779             : 
    4780           0 : OptNoLog:   UNLOGGED                    { $$ = RELPERSISTENCE_UNLOGGED; }
    4781         558 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    4782             :         ;
    4783             : 
    4784             : 
    4785             : /*****************************************************************************
    4786             :  *
    4787             :  *      QUERY :
    4788             :  *              REFRESH MATERIALIZED VIEW qualified_name
    4789             :  *
    4790             :  *****************************************************************************/
    4791             : 
    4792             : RefreshMatViewStmt:
    4793             :             REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
    4794             :                 {
    4795         258 :                     RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
    4796             : 
    4797         258 :                     n->concurrent = $4;
    4798         258 :                     n->relation = $5;
    4799         258 :                     n->skipData = !($6);
    4800         258 :                     $$ = (Node *) n;
    4801             :                 }
    4802             :         ;
    4803             : 
    4804             : 
    4805             : /*****************************************************************************
    4806             :  *
    4807             :  *      QUERY :
    4808             :  *              CREATE SEQUENCE seqname
    4809             :  *              ALTER SEQUENCE seqname
    4810             :  *
    4811             :  *****************************************************************************/
    4812             : 
    4813             : CreateSeqStmt:
    4814             :             CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
    4815             :                 {
    4816         622 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    4817             : 
    4818         622 :                     $4->relpersistence = $2;
    4819         622 :                     n->sequence = $4;
    4820         622 :                     n->options = $5;
    4821         622 :                     n->ownerId = InvalidOid;
    4822         622 :                     n->if_not_exists = false;
    4823         622 :                     $$ = (Node *) n;
    4824             :                 }
    4825             :             | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
    4826             :                 {
    4827          24 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    4828             : 
    4829          24 :                     $7->relpersistence = $2;
    4830          24 :                     n->sequence = $7;
    4831          24 :                     n->options = $8;
    4832          24 :                     n->ownerId = InvalidOid;
    4833          24 :                     n->if_not_exists = true;
    4834          24 :                     $$ = (Node *) n;
    4835             :                 }
    4836             :         ;
    4837             : 
    4838             : AlterSeqStmt:
    4839             :             ALTER SEQUENCE qualified_name SeqOptList
    4840             :                 {
    4841         184 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    4842             : 
    4843         184 :                     n->sequence = $3;
    4844         184 :                     n->options = $4;
    4845         184 :                     n->missing_ok = false;
    4846         184 :                     $$ = (Node *) n;
    4847             :                 }
    4848             :             | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
    4849             :                 {
    4850          12 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    4851             : 
    4852          12 :                     n->sequence = $5;
    4853          12 :                     n->options = $6;
    4854          12 :                     n->missing_ok = true;
    4855          12 :                     $$ = (Node *) n;
    4856             :                 }
    4857             : 
    4858             :         ;
    4859             : 
    4860         246 : OptSeqOptList: SeqOptList                           { $$ = $1; }
    4861         400 :             | /*EMPTY*/                             { $$ = NIL; }
    4862             :         ;
    4863             : 
    4864          68 : OptParenthesizedSeqOptList: '(' SeqOptList ')'      { $$ = $2; }
    4865         346 :             | /*EMPTY*/                             { $$ = NIL; }
    4866             :         ;
    4867             : 
    4868         510 : SeqOptList: SeqOptElem                              { $$ = list_make1($1); }
    4869         744 :             | SeqOptList SeqOptElem                 { $$ = lappend($1, $2); }
    4870             :         ;
    4871             : 
    4872             : SeqOptElem: AS SimpleTypename
    4873             :                 {
    4874         190 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    4875             :                 }
    4876             :             | CACHE NumericOnly
    4877             :                 {
    4878         116 :                     $$ = makeDefElem("cache", (Node *) $2, @1);
    4879             :                 }
    4880             :             | CYCLE
    4881             :                 {
    4882          34 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(true), @1);
    4883             :                 }
    4884             :             | NO CYCLE
    4885             :                 {
    4886          14 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(false), @1);
    4887             :                 }
    4888             :             | INCREMENT opt_by NumericOnly
    4889             :                 {
    4890         236 :                     $$ = makeDefElem("increment", (Node *) $3, @1);
    4891             :                 }
    4892             :             | MAXVALUE NumericOnly
    4893             :                 {
    4894          68 :                     $$ = makeDefElem("maxvalue", (Node *) $2, @1);
    4895             :                 }
    4896             :             | MINVALUE NumericOnly
    4897             :                 {
    4898          72 :                     $$ = makeDefElem("minvalue", (Node *) $2, @1);
    4899             :                 }
    4900             :             | NO MAXVALUE
    4901             :                 {
    4902          94 :                     $$ = makeDefElem("maxvalue", NULL, @1);
    4903             :                 }
    4904             :             | NO MINVALUE
    4905             :                 {
    4906          94 :                     $$ = makeDefElem("minvalue", NULL, @1);
    4907             :                 }
    4908             :             | OWNED BY any_name
    4909             :                 {
    4910          72 :                     $$ = makeDefElem("owned_by", (Node *) $3, @1);
    4911             :                 }
    4912             :             | SEQUENCE NAME_P any_name
    4913             :                 {
    4914             :                     /* not documented, only used by pg_dump */
    4915          38 :                     $$ = makeDefElem("sequence_name", (Node *) $3, @1);
    4916             :                 }
    4917             :             | START opt_with NumericOnly
    4918             :                 {
    4919         214 :                     $$ = makeDefElem("start", (Node *) $3, @1);
    4920             :                 }
    4921             :             | RESTART
    4922             :                 {
    4923           6 :                     $$ = makeDefElem("restart", NULL, @1);
    4924             :                 }
    4925             :             | RESTART opt_with NumericOnly
    4926             :                 {
    4927          60 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    4928             :                 }
    4929             :         ;
    4930             : 
    4931             : opt_by:     BY
    4932             :             | /* EMPTY */
    4933             :       ;
    4934             : 
    4935             : NumericOnly:
    4936         316 :             FCONST                              { $$ = (Node *) makeFloat($1); }
    4937           0 :             | '+' FCONST                        { $$ = (Node *) makeFloat($2); }
    4938             :             | '-' FCONST
    4939             :                 {
    4940          20 :                     Float      *f = makeFloat($2);
    4941             : 
    4942          20 :                     doNegateFloat(f);
    4943          20 :                     $$ = (Node *) f;
    4944             :                 }
    4945       10552 :             | SignedIconst                      { $$ = (Node *) makeInteger($1); }
    4946             :         ;
    4947             : 
    4948          80 : NumericOnly_list:   NumericOnly                     { $$ = list_make1($1); }
    4949           6 :                 | NumericOnly_list ',' NumericOnly  { $$ = lappend($1, $3); }
    4950             :         ;
    4951             : 
    4952             : /*****************************************************************************
    4953             :  *
    4954             :  *      QUERIES :
    4955             :  *              CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
    4956             :  *              DROP [PROCEDURAL] LANGUAGE ...
    4957             :  *
    4958             :  *****************************************************************************/
    4959             : 
    4960             : CreatePLangStmt:
    4961             :             CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
    4962             :             {
    4963             :                 /*
    4964             :                  * We now interpret parameterless CREATE LANGUAGE as
    4965             :                  * CREATE EXTENSION.  "OR REPLACE" is silently translated
    4966             :                  * to "IF NOT EXISTS", which isn't quite the same, but
    4967             :                  * seems more useful than throwing an error.  We just
    4968             :                  * ignore TRUSTED, as the previous code would have too.
    4969             :                  */
    4970           0 :                 CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    4971             : 
    4972           0 :                 n->if_not_exists = $2;
    4973           0 :                 n->extname = $6;
    4974           0 :                 n->options = NIL;
    4975           0 :                 $$ = (Node *) n;
    4976             :             }
    4977             :             | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
    4978             :               HANDLER handler_name opt_inline_handler opt_validator
    4979             :             {
    4980         122 :                 CreatePLangStmt *n = makeNode(CreatePLangStmt);
    4981             : 
    4982         122 :                 n->replace = $2;
    4983         122 :                 n->plname = $6;
    4984         122 :                 n->plhandler = $8;
    4985         122 :                 n->plinline = $9;
    4986         122 :                 n->plvalidator = $10;
    4987         122 :                 n->pltrusted = $3;
    4988         122 :                 $$ = (Node *) n;
    4989             :             }
    4990             :         ;
    4991             : 
    4992             : opt_trusted:
    4993          92 :             TRUSTED                                 { $$ = true; }
    4994          36 :             | /*EMPTY*/                             { $$ = false; }
    4995             :         ;
    4996             : 
    4997             : /* This ought to be just func_name, but that causes reduce/reduce conflicts
    4998             :  * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
    4999             :  * Work around by using simple names, instead.
    5000             :  */
    5001             : handler_name:
    5002         486 :             name                        { $$ = list_make1(makeString($1)); }
    5003           2 :             | name attrs                { $$ = lcons(makeString($1), $2); }
    5004             :         ;
    5005             : 
    5006             : opt_inline_handler:
    5007         104 :             INLINE_P handler_name                   { $$ = $2; }
    5008          18 :             | /*EMPTY*/                             { $$ = NIL; }
    5009             :         ;
    5010             : 
    5011             : validator_clause:
    5012         104 :             VALIDATOR handler_name                  { $$ = $2; }
    5013           0 :             | NO VALIDATOR                          { $$ = NIL; }
    5014             :         ;
    5015             : 
    5016             : opt_validator:
    5017         104 :             validator_clause                        { $$ = $1; }
    5018          18 :             | /*EMPTY*/                             { $$ = NIL; }
    5019             :         ;
    5020             : 
    5021             : opt_procedural:
    5022             :             PROCEDURAL
    5023             :             | /*EMPTY*/
    5024             :         ;
    5025             : 
    5026             : /*****************************************************************************
    5027             :  *
    5028             :  *      QUERY:
    5029             :  *             CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
    5030             :  *
    5031             :  *****************************************************************************/
    5032             : 
    5033             : CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
    5034             :                 {
    5035         108 :                     CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
    5036             : 
    5037         108 :                     n->tablespacename = $3;
    5038         108 :                     n->owner = $4;
    5039         108 :                     n->location = $6;
    5040         108 :                     n->options = $7;
    5041         108 :                     $$ = (Node *) n;
    5042             :                 }
    5043             :         ;
    5044             : 
    5045           2 : OptTableSpaceOwner: OWNER RoleSpec      { $$ = $2; }
    5046         106 :             | /*EMPTY */                { $$ = NULL; }
    5047             :         ;
    5048             : 
    5049             : /*****************************************************************************
    5050             :  *
    5051             :  *      QUERY :
    5052             :  *              DROP TABLESPACE <tablespace>
    5053             :  *
    5054             :  *      No need for drop behaviour as we cannot implement dependencies for
    5055             :  *      objects in other databases; we can only support RESTRICT.
    5056             :  *
    5057             :  ****************************************************************************/
    5058             : 
    5059             : DropTableSpaceStmt: DROP TABLESPACE name
    5060             :                 {
    5061          64 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    5062             : 
    5063          64 :                     n->tablespacename = $3;
    5064          64 :                     n->missing_ok = false;
    5065          64 :                     $$ = (Node *) n;
    5066             :                 }
    5067             :                 |  DROP TABLESPACE IF_P EXISTS name
    5068             :                 {
    5069           0 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    5070             : 
    5071           0 :                     n->tablespacename = $5;
    5072           0 :                     n->missing_ok = true;
    5073           0 :                     $$ = (Node *) n;
    5074             :                 }
    5075             :         ;
    5076             : 
    5077             : /*****************************************************************************
    5078             :  *
    5079             :  *      QUERY:
    5080             :  *             CREATE EXTENSION extension
    5081             :  *             [ WITH ] [ SCHEMA schema ] [ VERSION version ]
    5082             :  *
    5083             :  *****************************************************************************/
    5084             : 
    5085             : CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
    5086             :                 {
    5087         394 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5088             : 
    5089         394 :                     n->extname = $3;
    5090         394 :                     n->if_not_exists = false;
    5091         394 :                     n->options = $5;
    5092         394 :                     $$ = (Node *) n;
    5093             :                 }
    5094             :                 | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
    5095             :                 {
    5096          14 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5097             : 
    5098          14 :                     n->extname = $6;
    5099          14 :                     n->if_not_exists = true;
    5100          14 :                     n->options = $8;
    5101          14 :                     $$ = (Node *) n;
    5102             :                 }
    5103             :         ;
    5104             : 
    5105             : create_extension_opt_list:
    5106             :             create_extension_opt_list create_extension_opt_item
    5107          96 :                 { $$ = lappend($1, $2); }
    5108             :             | /* EMPTY */
    5109         408 :                 { $$ = NIL; }
    5110             :         ;
    5111             : 
    5112             : create_extension_opt_item:
    5113             :             SCHEMA name
    5114             :                 {
    5115          44 :                     $$ = makeDefElem("schema", (Node *) makeString($2), @1);
    5116             :                 }
    5117             :             | VERSION_P NonReservedWord_or_Sconst
    5118             :                 {
    5119          12 :                     $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
    5120             :                 }
    5121             :             | FROM NonReservedWord_or_Sconst
    5122             :                 {
    5123           0 :                     ereport(ERROR,
    5124             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    5125             :                              errmsg("CREATE EXTENSION ... FROM is no longer supported"),
    5126             :                              parser_errposition(@1)));
    5127             :                 }
    5128             :             | CASCADE
    5129             :                 {
    5130          40 :                     $$ = makeDefElem("cascade", (Node *) makeBoolean(true), @1);
    5131             :                 }
    5132             :         ;
    5133             : 
    5134             : /*****************************************************************************
    5135             :  *
    5136             :  * ALTER EXTENSION name UPDATE [ TO version ]
    5137             :  *
    5138             :  *****************************************************************************/
    5139             : 
    5140             : AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
    5141             :                 {
    5142          28 :                     AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
    5143             : 
    5144          28 :                     n->extname = $3;
    5145          28 :                     n->options = $5;
    5146          28 :                     $$ = (Node *) n;
    5147             :                 }
    5148             :         ;
    5149             : 
    5150             : alter_extension_opt_list:
    5151             :             alter_extension_opt_list alter_extension_opt_item
    5152          28 :                 { $$ = lappend($1, $2); }
    5153             :             | /* EMPTY */
    5154          28 :                 { $$ = NIL; }
    5155             :         ;
    5156             : 
    5157             : alter_extension_opt_item:
    5158             :             TO NonReservedWord_or_Sconst
    5159             :                 {
    5160          28 :                     $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
    5161             :                 }
    5162             :         ;
    5163             : 
    5164             : /*****************************************************************************
    5165             :  *
    5166             :  * ALTER EXTENSION name ADD/DROP object-identifier
    5167             :  *
    5168             :  *****************************************************************************/
    5169             : 
    5170             : AlterExtensionContentsStmt:
    5171             :             ALTER EXTENSION name add_drop object_type_name name
    5172             :                 {
    5173          18 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5174             : 
    5175          18 :                     n->extname = $3;
    5176          18 :                     n->action = $4;
    5177          18 :                     n->objtype = $5;
    5178          18 :                     n->object = (Node *) makeString($6);
    5179          18 :                     $$ = (Node *) n;
    5180             :                 }
    5181             :             | ALTER EXTENSION name add_drop object_type_any_name any_name
    5182             :                 {
    5183          58 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5184             : 
    5185          58 :                     n->extname = $3;
    5186          58 :                     n->action = $4;
    5187          58 :                     n->objtype = $5;
    5188          58 :                     n->object = (Node *) $6;
    5189          58 :                     $$ = (Node *) n;
    5190             :                 }
    5191             :             | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
    5192             :                 {
    5193           8 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5194             : 
    5195           8 :                     n->extname = $3;
    5196           8 :                     n->action = $4;
    5197           8 :                     n->objtype = OBJECT_AGGREGATE;
    5198           8 :                     n->object = (Node *) $6;
    5199           8 :                     $$ = (Node *) n;
    5200             :                 }
    5201             :             | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
    5202             :                 {
    5203           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5204             : 
    5205           4 :                     n->extname = $3;
    5206           4 :                     n->action = $4;
    5207           4 :                     n->objtype = OBJECT_CAST;
    5208           4 :                     n->object = (Node *) list_make2($7, $9);
    5209           4 :                     $$ = (Node *) n;
    5210             :                 }
    5211             :             | ALTER EXTENSION name add_drop DOMAIN_P Typename
    5212             :                 {
    5213           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5214             : 
    5215           0 :                     n->extname = $3;
    5216           0 :                     n->action = $4;
    5217           0 :                     n->objtype = OBJECT_DOMAIN;
    5218           0 :                     n->object = (Node *) $6;
    5219           0 :                     $$ = (Node *) n;
    5220             :                 }
    5221             :             | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
    5222             :                 {
    5223          74 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5224             : 
    5225          74 :                     n->extname = $3;
    5226          74 :                     n->action = $4;
    5227          74 :                     n->objtype = OBJECT_FUNCTION;
    5228          74 :                     n->object = (Node *) $6;
    5229          74 :                     $$ = (Node *) n;
    5230             :                 }
    5231             :             | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
    5232             :                 {
    5233          18 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5234             : 
    5235          18 :                     n->extname = $3;
    5236          18 :                     n->action = $4;
    5237          18 :                     n->objtype = OBJECT_OPERATOR;
    5238          18 :                     n->object = (Node *) $6;
    5239          18 :                     $$ = (Node *) n;
    5240             :                 }
    5241             :             | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING name
    5242             :                 {
    5243           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5244             : 
    5245           4 :                     n->extname = $3;
    5246           4 :                     n->action = $4;
    5247           4 :                     n->objtype = OBJECT_OPCLASS;
    5248           4 :                     n->object = (Node *) lcons(makeString($9), $7);
    5249           4 :                     $$ = (Node *) n;
    5250             :                 }
    5251             :             | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING name
    5252             :                 {
    5253           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5254             : 
    5255           4 :                     n->extname = $3;
    5256           4 :                     n->action = $4;
    5257           4 :                     n->objtype = OBJECT_OPFAMILY;
    5258           4 :                     n->object = (Node *) lcons(makeString($9), $7);
    5259           4 :                     $$ = (Node *) n;
    5260             :                 }
    5261             :             | ALTER EXTENSION name add_drop PROCEDURE function_with_argtypes
    5262             :                 {
    5263           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5264             : 
    5265           0 :                     n->extname = $3;
    5266           0 :                     n->action = $4;
    5267           0 :                     n->objtype = OBJECT_PROCEDURE;
    5268           0 :                     n->object = (Node *) $6;
    5269           0 :                     $$ = (Node *) n;
    5270             :                 }
    5271             :             | ALTER EXTENSION name add_drop ROUTINE function_with_argtypes
    5272             :                 {
    5273           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5274             : 
    5275           0 :                     n->extname = $3;
    5276           0 :                     n->action = $4;
    5277           0 :                     n->objtype = OBJECT_ROUTINE;
    5278           0 :                     n->object = (Node *) $6;
    5279           0 :                     $$ = (Node *) n;
    5280             :                 }
    5281             :             | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
    5282             :                 {
    5283           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5284             : 
    5285           4 :                     n->extname = $3;
    5286           4 :                     n->action = $4;
    5287           4 :                     n->objtype = OBJECT_TRANSFORM;
    5288           4 :                     n->object = (Node *) list_make2($7, makeString($9));
    5289           4 :                     $$ = (Node *) n;
    5290             :                 }
    5291             :             | ALTER EXTENSION name add_drop TYPE_P Typename
    5292             :                 {
    5293           8 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5294             : 
    5295           8 :                     n->extname = $3;
    5296           8 :                     n->action = $4;
    5297           8 :                     n->objtype = OBJECT_TYPE;
    5298           8 :                     n->object = (Node *) $6;
    5299           8 :                     $$ = (Node *) n;
    5300             :                 }
    5301             :         ;
    5302             : 
    5303             : /*****************************************************************************
    5304             :  *
    5305             :  *      QUERY:
    5306             :  *             CREATE FOREIGN DATA WRAPPER name options
    5307             :  *
    5308             :  *****************************************************************************/
    5309             : 
    5310             : CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
    5311             :                 {
    5312         190 :                     CreateFdwStmt *n = makeNode(CreateFdwStmt);
    5313             : 
    5314         190 :                     n->fdwname = $5;
    5315         190 :                     n->func_options = $6;
    5316         190 :                     n->options = $7;
    5317         190 :                     $$ = (Node *) n;
    5318             :                 }
    5319             :         ;
    5320             : 
    5321             : fdw_option:
    5322          54 :             HANDLER handler_name                { $$ = makeDefElem("handler", (Node *) $2, @1); }
    5323           0 :             | NO HANDLER                        { $$ = makeDefElem("handler", NULL, @1); }
    5324          44 :             | VALIDATOR handler_name            { $$ = makeDefElem("validator", (Node *) $2, @1); }
    5325           6 :             | NO VALIDATOR                      { $$ = makeDefElem("validator", NULL, @1); }
    5326             :         ;
    5327             : 
    5328             : fdw_options:
    5329          86 :             fdw_option                          { $$ = list_make1($1); }
    5330          18 :             | fdw_options fdw_option            { $$ = lappend($1, $2); }
    5331             :         ;
    5332             : 
    5333             : opt_fdw_options:
    5334          50 :             fdw_options                         { $$ = $1; }
    5335         232 :             | /*EMPTY*/                         { $$ = NIL; }
    5336             :         ;
    5337             : 
    5338             : /*****************************************************************************
    5339             :  *
    5340             :  *      QUERY :
    5341             :  *              ALTER FOREIGN DATA WRAPPER name options
    5342             :  *
    5343             :  ****************************************************************************/
    5344             : 
    5345             : AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
    5346             :                 {
    5347          86 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5348             : 
    5349          86 :                     n->fdwname = $5;
    5350          86 :                     n->func_options = $6;
    5351          86 :                     n->options = $7;
    5352          86 :                     $$ = (Node *) n;
    5353             :                 }
    5354             :             | ALTER FOREIGN DATA_P WRAPPER name fdw_options
    5355             :                 {
    5356          36 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5357             : 
    5358          36 :                     n->fdwname = $5;
    5359          36 :                     n->func_options = $6;
    5360          36 :                     n->options = NIL;
    5361          36 :                     $$ = (Node *) n;
    5362             :                 }
    5363             :         ;
    5364             : 
    5365             : /* Options definition for CREATE FDW, SERVER and USER MAPPING */
    5366             : create_generic_options:
    5367         684 :             OPTIONS '(' generic_option_list ')'         { $$ = $3; }
    5368       62260 :             | /*EMPTY*/                                 { $$ = NIL; }
    5369             :         ;
    5370             : 
    5371             : generic_option_list:
    5372             :             generic_option_elem
    5373             :                 {
    5374         684 :                     $$ = list_make1($1);
    5375             :                 }
    5376             :             | generic_option_list ',' generic_option_elem
    5377             :                 {
    5378         430 :                     $$ = lappend($1, $3);
    5379             :                 }
    5380             :         ;
    5381             : 
    5382             : /* Options definition for ALTER FDW, SERVER and USER MAPPING */
    5383             : alter_generic_options:
    5384         478 :             OPTIONS '(' alter_generic_option_list ')'       { $$ = $3; }
    5385             :         ;
    5386             : 
    5387             : alter_generic_option_list:
    5388             :             alter_generic_option_elem
    5389             :                 {
    5390         478 :                     $$ = list_make1($1);
    5391             :                 }
    5392             :             | alter_generic_option_list ',' alter_generic_option_elem
    5393             :                 {
    5394         168 :                     $$ = lappend($1, $3);
    5395             :                 }
    5396             :         ;
    5397             : 
    5398             : alter_generic_option_elem:
    5399             :             generic_option_elem
    5400             :                 {
    5401         200 :                     $$ = $1;
    5402             :                 }
    5403             :             | SET generic_option_elem
    5404             :                 {
    5405         124 :                     $$ = $2;
    5406         124 :                     $$->defaction = DEFELEM_SET;
    5407             :                 }
    5408             :             | ADD_P generic_option_elem
    5409             :                 {
    5410         196 :                     $$ = $2;
    5411         196 :                     $$->defaction = DEFELEM_ADD;
    5412             :                 }
    5413             :             | DROP generic_option_name
    5414             :                 {
    5415         126 :                     $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP, @2);
    5416             :                 }
    5417             :         ;
    5418             : 
    5419             : generic_option_elem:
    5420             :             generic_option_name generic_option_arg
    5421             :                 {
    5422        1634 :                     $$ = makeDefElem($1, $2, @1);
    5423             :                 }
    5424             :         ;
    5425             : 
    5426             : generic_option_name:
    5427        1760 :                 ColLabel            { $$ = $1; }
    5428             :         ;
    5429             : 
    5430             : /* We could use def_arg here, but the spec only requires string literals */
    5431             : generic_option_arg:
    5432        1634 :                 Sconst              { $$ = (Node *) makeString($1); }
    5433             :         ;
    5434             : 
    5435             : /*****************************************************************************
    5436             :  *
    5437             :  *      QUERY:
    5438             :  *             CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
    5439             :  *
    5440             :  *****************************************************************************/
    5441             : 
    5442             : CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
    5443             :                          FOREIGN DATA_P WRAPPER name create_generic_options
    5444             :                 {
    5445         248 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5446             : 
    5447         248 :                     n->servername = $3;
    5448         248 :                     n->servertype = $4;
    5449         248 :                     n->version = $5;
    5450         248 :                     n->fdwname = $9;
    5451         248 :                     n->options = $10;
    5452         248 :                     n->if_not_exists = false;
    5453         248 :                     $$ = (Node *) n;
    5454             :                 }
    5455             :                 | CREATE SERVER IF_P NOT EXISTS name opt_type opt_foreign_server_version
    5456             :                          FOREIGN DATA_P WRAPPER name create_generic_options
    5457             :                 {
    5458          24 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5459             : 
    5460          24 :                     n->servername = $6;
    5461          24 :                     n->servertype = $7;
    5462          24 :                     n->version = $8;
    5463          24 :                     n->fdwname = $12;
    5464          24 :                     n->options = $13;
    5465          24 :                     n->if_not_exists = true;
    5466          24 :                     $$ = (Node *) n;
    5467             :                 }
    5468             :         ;
    5469             : 
    5470             : opt_type:
    5471          18 :             TYPE_P Sconst           { $$ = $2; }
    5472         254 :             | /*EMPTY*/             { $$ = NULL; }
    5473             :         ;
    5474             : 
    5475             : 
    5476             : foreign_server_version:
    5477          66 :             VERSION_P Sconst        { $$ = $2; }
    5478           0 :         |   VERSION_P NULL_P        { $$ = NULL; }
    5479             :         ;
    5480             : 
    5481             : opt_foreign_server_version:
    5482          18 :             foreign_server_version  { $$ = $1; }
    5483         254 :             | /*EMPTY*/             { $$ = NULL; }
    5484             :         ;
    5485             : 
    5486             : /*****************************************************************************
    5487             :  *
    5488             :  *      QUERY :
    5489             :  *              ALTER SERVER name [VERSION] [OPTIONS]
    5490             :  *
    5491             :  ****************************************************************************/
    5492             : 
    5493             : AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
    5494             :                 {
    5495           6 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5496             : 
    5497           6 :                     n->servername = $3;
    5498           6 :                     n->version = $4;
    5499           6 :                     n->options = $5;
    5500           6 :                     n->has_version = true;
    5501           6 :                     $$ = (Node *) n;
    5502             :                 }
    5503             :             | ALTER SERVER name foreign_server_version
    5504             :                 {
    5505          42 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5506             : 
    5507          42 :                     n->servername = $3;
    5508          42 :                     n->version = $4;
    5509          42 :                     n->has_version = true;
    5510          42 :                     $$ = (Node *) n;
    5511             :                 }
    5512             :             | ALTER SERVER name alter_generic_options
    5513             :                 {
    5514         170 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5515             : 
    5516         170 :                     n->servername = $3;
    5517         170 :                     n->options = $4;
    5518         170 :                     $$ = (Node *) n;
    5519             :                 }
    5520             :         ;
    5521             : 
    5522             : /*****************************************************************************
    5523             :  *
    5524             :  *      QUERY:
    5525             :  *             CREATE FOREIGN TABLE relname (...) SERVER name (...)
    5526             :  *
    5527             :  *****************************************************************************/
    5528             : 
    5529             : CreateForeignTableStmt:
    5530             :         CREATE FOREIGN TABLE qualified_name
    5531             :             '(' OptTableElementList ')'
    5532             :             OptInherit SERVER name create_generic_options
    5533             :                 {
    5534         356 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5535             : 
    5536         356 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5537         356 :                     n->base.relation = $4;
    5538         356 :                     n->base.tableElts = $6;
    5539         356 :                     n->base.inhRelations = $8;
    5540         356 :                     n->base.ofTypename = NULL;
    5541         356 :                     n->base.constraints = NIL;
    5542         356 :                     n->base.options = NIL;
    5543         356 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5544         356 :                     n->base.tablespacename = NULL;
    5545         356 :                     n->base.if_not_exists = false;
    5546             :                     /* FDW-specific data */
    5547         356 :                     n->servername = $10;
    5548         356 :                     n->options = $11;
    5549         356 :                     $$ = (Node *) n;
    5550             :                 }
    5551             :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5552             :             '(' OptTableElementList ')'
    5553             :             OptInherit SERVER name create_generic_options
    5554             :                 {
    5555           0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5556             : 
    5557           0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5558           0 :                     n->base.relation = $7;
    5559           0 :                     n->base.tableElts = $9;
    5560           0 :                     n->base.inhRelations = $11;
    5561           0 :                     n->base.ofTypename = NULL;
    5562           0 :                     n->base.constraints = NIL;
    5563           0 :                     n->base.options = NIL;
    5564           0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5565           0 :                     n->base.tablespacename = NULL;
    5566           0 :                     n->base.if_not_exists = true;
    5567             :                     /* FDW-specific data */
    5568           0 :                     n->servername = $13;
    5569           0 :                     n->options = $14;
    5570           0 :                     $$ = (Node *) n;
    5571             :                 }
    5572             :         | CREATE FOREIGN TABLE qualified_name
    5573             :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5574             :             SERVER name create_generic_options
    5575             :                 {
    5576          90 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5577             : 
    5578          90 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5579          90 :                     n->base.relation = $4;
    5580          90 :                     n->base.inhRelations = list_make1($7);
    5581          90 :                     n->base.tableElts = $8;
    5582          90 :                     n->base.partbound = $9;
    5583          90 :                     n->base.ofTypename = NULL;
    5584          90 :                     n->base.constraints = NIL;
    5585          90 :                     n->base.options = NIL;
    5586          90 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5587          90 :                     n->base.tablespacename = NULL;
    5588          90 :                     n->base.if_not_exists = false;
    5589             :                     /* FDW-specific data */
    5590          90 :                     n->servername = $11;
    5591          90 :                     n->options = $12;
    5592          90 :                     $$ = (Node *) n;
    5593             :                 }
    5594             :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5595             :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5596             :             SERVER name create_generic_options
    5597             :                 {
    5598           0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5599             : 
    5600           0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5601           0 :                     n->base.relation = $7;
    5602           0 :                     n->base.inhRelations = list_make1($10);
    5603           0 :                     n->base.tableElts = $11;
    5604           0 :                     n->base.partbound = $12;
    5605           0 :                     n->base.ofTypename = NULL;
    5606           0 :                     n->base.constraints = NIL;
    5607           0 :                     n->base.options = NIL;
    5608           0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5609           0 :                     n->base.tablespacename = NULL;
    5610           0 :                     n->base.if_not_exists = true;
    5611             :                     /* FDW-specific data */
    5612           0 :                     n->servername = $14;
    5613           0 :                     n->options = $15;
    5614           0 :                     $$ = (Node *) n;
    5615             :                 }
    5616             :         ;
    5617             : 
    5618             : /*****************************************************************************
    5619             :  *
    5620             :  *      QUERY:
    5621             :  *              IMPORT FOREIGN SCHEMA remote_schema
    5622             :  *              [ { LIMIT TO | EXCEPT } ( table_list ) ]
    5623             :  *              FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
    5624             :  *
    5625             :  ****************************************************************************/
    5626             : 
    5627             : ImportForeignSchemaStmt:
    5628             :         IMPORT_P FOREIGN SCHEMA name import_qualification
    5629             :           FROM SERVER name INTO name create_generic_options
    5630             :             {
    5631          44 :                 ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
    5632             : 
    5633          44 :                 n->server_name = $8;
    5634          44 :                 n->remote_schema = $4;
    5635          44 :                 n->local_schema = $10;
    5636          44 :                 n->list_type = $5->type;
    5637          44 :                 n->table_list = $5->table_names;
    5638          44 :                 n->options = $11;
    5639          44 :                 $$ = (Node *) n;
    5640             :             }
    5641             :         ;
    5642             : 
    5643             : import_qualification_type:
    5644          10 :         LIMIT TO                { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
    5645          14 :         | EXCEPT                { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
    5646             :         ;
    5647             : 
    5648             : import_qualification:
    5649             :         import_qualification_type '(' relation_expr_list ')'
    5650             :             {
    5651          24 :                 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
    5652             : 
    5653          24 :                 n->type = $1;
    5654          24 :                 n->table_names = $3;
    5655          24 :                 $$ = n;
    5656             :             }
    5657             :         | /*EMPTY*/
    5658             :             {
    5659          20 :                 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
    5660          20 :                 n->type = FDW_IMPORT_SCHEMA_ALL;
    5661          20 :                 n->table_names = NIL;
    5662          20 :                 $$ = n;
    5663             :             }
    5664             :         ;
    5665             : 
    5666             : /*****************************************************************************
    5667             :  *
    5668             :  *      QUERY:
    5669             :  *             CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
    5670             :  *
    5671             :  *****************************************************************************/
    5672             : 
    5673             : CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
    5674             :                 {
    5675         232 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5676             : 
    5677         232 :                     n->user = $5;
    5678         232 :                     n->servername = $7;
    5679         232 :                     n->options = $8;
    5680         232 :                     n->if_not_exists = false;
    5681         232 :                     $$ = (Node *) n;
    5682             :                 }
    5683             :                 | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
    5684             :                 {
    5685           6 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5686             : 
    5687           6 :                     n->user = $8;
    5688           6 :                     n->servername = $10;
    5689           6 :                     n->options = $11;
    5690           6 :                     n->if_not_exists = true;
    5691           6 :                     $$ = (Node *) n;
    5692             :                 }
    5693             :         ;
    5694             : 
    5695             : /* User mapping authorization identifier */
    5696         428 : auth_ident: RoleSpec            { $$ = $1; }
    5697          46 :             | USER              { $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1); }
    5698             :         ;
    5699             : 
    5700             : /*****************************************************************************
    5701             :  *
    5702             :  *      QUERY :
    5703             :  *              DROP USER MAPPING FOR auth_ident SERVER name
    5704             :  *
    5705             :  * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
    5706             :  * only pro forma; but the SQL standard doesn't show one.
    5707             :  ****************************************************************************/
    5708             : 
    5709             : DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
    5710             :                 {
    5711          88 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5712             : 
    5713          88 :                     n->user = $5;
    5714          88 :                     n->servername = $7;
    5715          88 :                     n->missing_ok = false;
    5716          88 :                     $$ = (Node *) n;
    5717             :                 }
    5718             :                 |  DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
    5719             :                 {
    5720          38 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5721             : 
    5722          38 :                     n->user = $7;
    5723          38 :                     n->servername = $9;
    5724          38 :                     n->missing_ok = true;
    5725          38 :                     $$ = (Node *) n;
    5726             :                 }
    5727             :         ;
    5728             : 
    5729             : /*****************************************************************************
    5730             :  *
    5731             :  *      QUERY :
    5732             :  *              ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
    5733             :  *
    5734             :  ****************************************************************************/
    5735             : 
    5736             : AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
    5737             :                 {
    5738         110 :                     AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
    5739             : 
    5740         110 :                     n->user = $5;
    5741         110 :                     n->servername = $7;
    5742         110 :                     n->options = $8;
    5743         110 :                     $$ = (Node *) n;
    5744             :                 }
    5745             :         ;
    5746             : 
    5747             : /*****************************************************************************
    5748             :  *
    5749             :  *      QUERIES:
    5750             :  *              CREATE POLICY name ON table
    5751             :  *                  [AS { PERMISSIVE | RESTRICTIVE } ]
    5752             :  *                  [FOR { SELECT | INSERT | UPDATE | DELETE } ]
    5753             :  *                  [TO role, ...]
    5754             :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    5755             :  *              ALTER POLICY name ON table [TO role, ...]
    5756             :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    5757             :  *
    5758             :  *****************************************************************************/
    5759             : 
    5760             : CreatePolicyStmt:
    5761             :             CREATE POLICY name ON qualified_name RowSecurityDefaultPermissive
    5762             :                 RowSecurityDefaultForCmd RowSecurityDefaultToRole
    5763             :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    5764             :                 {
    5765         652 :                     CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
    5766             : 
    5767         652 :                     n->policy_name = $3;
    5768         652 :                     n->table = $5;
    5769         652 :                     n->permissive = $6;
    5770         652 :                     n->cmd_name = $7;
    5771         652 :                     n->roles = $8;
    5772         652 :                     n->qual = $9;
    5773         652 :                     n->with_check = $10;
    5774         652 :                     $$ = (Node *) n;
    5775             :                 }
    5776             :         ;
    5777             : 
    5778             : AlterPolicyStmt:
    5779             :             ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
    5780             :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    5781             :                 {
    5782          84 :                     AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
    5783             : 
    5784          84 :                     n->policy_name = $3;
    5785          84 :                     n->table = $5;
    5786          84 :                     n->roles = $6;
    5787          84 :                     n->qual = $7;
    5788          84 :                     n->with_check = $8;
    5789          84 :                     $$ = (Node *) n;
    5790             :                 }
    5791             :         ;
    5792             : 
    5793             : RowSecurityOptionalExpr:
    5794         678 :             USING '(' a_expr ')'    { $$ = $3; }
    5795          58 :             | /* EMPTY */           { $$ = NULL; }
    5796             :         ;
    5797             : 
    5798             : RowSecurityOptionalWithCheck:
    5799         122 :             WITH CHECK '(' a_expr ')'       { $$ = $4; }
    5800         614 :             | /* EMPTY */                   { $$ = NULL; }
    5801             :         ;
    5802             : 
    5803             : RowSecurityDefaultToRole:
    5804         124 :             TO role_list            { $$ = $2; }
    5805         528 :             | /* EMPTY */           { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
    5806             :         ;
    5807             : 
    5808             : RowSecurityOptionalToRole:
    5809          12 :             TO role_list            { $$ = $2; }
    5810          72 :             | /* EMPTY */           { $$ = NULL; }
    5811             :         ;
    5812             : 
    5813             : RowSecurityDefaultPermissive:
    5814             :             AS IDENT
    5815             :                 {
    5816          80 :                     if (strcmp($2, "permissive") == 0)
    5817          18 :                         $$ = true;
    5818          62 :                     else if (strcmp($2, "restrictive") == 0)
    5819          56 :                         $$ = false;
    5820             :                     else
    5821           6 :                         ereport(ERROR,
    5822             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    5823             :                                  errmsg("unrecognized row security option \"%s\"", $2),
    5824             :                                  errhint("Only PERMISSIVE or RESTRICTIVE policies are supported currently."),
    5825             :                                  parser_errposition(@2)));
    5826             : 
    5827             :                 }
    5828         578 :             | /* EMPTY */           { $$ = true; }
    5829             :         ;
    5830             : 
    5831             : RowSecurityDefaultForCmd:
    5832         314 :             FOR row_security_cmd    { $$ = $2; }
    5833         338 :             | /* EMPTY */           { $$ = "all"; }
    5834             :         ;
    5835             : 
    5836             : row_security_cmd:
    5837          44 :             ALL             { $$ = "all"; }
    5838         106 :         |   SELECT          { $$ = "select"; }
    5839          44 :         |   INSERT          { $$ = "insert"; }
    5840          78 :         |   UPDATE          { $$ = "update"; }
    5841          42 :         |   DELETE_P        { $$ = "delete"; }
    5842             :         ;
    5843             : 
    5844             : /*****************************************************************************
    5845             :  *
    5846             :  *      QUERY:
    5847             :  *             CREATE ACCESS METHOD name HANDLER handler_name
    5848             :  *
    5849             :  *****************************************************************************/
    5850             : 
    5851             : CreateAmStmt: CREATE ACCESS METHOD name TYPE_P am_type HANDLER handler_name
    5852             :                 {
    5853          60 :                     CreateAmStmt *n = makeNode(CreateAmStmt);
    5854             : 
    5855          60 :                     n->amname = $4;
    5856          60 :                     n->handler_name = $8;
    5857          60 :                     n->amtype = $6;
    5858          60 :                     $$ = (Node *) n;
    5859             :                 }
    5860             :         ;
    5861             : 
    5862             : am_type:
    5863          32 :             INDEX           { $$ = AMTYPE_INDEX; }
    5864          28 :         |   TABLE           { $$ = AMTYPE_TABLE; }
    5865             :         ;
    5866             : 
    5867             : /*****************************************************************************
    5868             :  *
    5869             :  *      QUERIES :
    5870             :  *              CREATE TRIGGER ...
    5871             :  *
    5872             :  *****************************************************************************/
    5873             : 
    5874             : CreateTrigStmt:
    5875             :             CREATE opt_or_replace TRIGGER name TriggerActionTime TriggerEvents ON
    5876             :             qualified_name TriggerReferencing TriggerForSpec TriggerWhen
    5877             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    5878             :                 {
    5879        3050 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    5880             : 
    5881        3050 :                     n->replace = $2;
    5882        3050 :                     n->isconstraint = false;
    5883        3050 :                     n->trigname = $4;
    5884        3050 :                     n->relation = $8;
    5885        3050 :                     n->funcname = $14;
    5886        3050 :                     n->args = $16;
    5887        3050 :                     n->row = $10;
    5888        3050 :                     n->timing = $5;
    5889        3050 :                     n->events = intVal(linitial($6));
    5890        3050 :                     n->columns = (List *) lsecond($6);
    5891        3050 :                     n->whenClause = $11;
    5892        3050 :                     n->transitionRels = $9;
    5893        3050 :                     n->deferrable = false;
    5894        3050 :                     n->initdeferred = false;
    5895        3050 :                     n->constrrel = NULL;
    5896        3050 :                     $$ = (Node *) n;
    5897             :                 }
    5898             :           | CREATE opt_or_replace CONSTRAINT TRIGGER name AFTER TriggerEvents ON
    5899             :             qualified_name OptConstrFromTable ConstraintAttributeSpec
    5900             :             FOR EACH ROW TriggerWhen
    5901             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    5902             :                 {
    5903          54 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    5904             : 
    5905          54 :                     n->replace = $2;
    5906          54 :                     if (n->replace) /* not supported, see CreateTrigger */
    5907           0 :                         ereport(ERROR,
    5908             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    5909             :                                  errmsg("CREATE OR REPLACE CONSTRAINT TRIGGER is not supported")));
    5910          54 :                     n->isconstraint = true;
    5911          54 :                     n->trigname = $5;
    5912          54 :                     n->relation = $9;
    5913          54 :                     n->funcname = $18;
    5914          54 :                     n->args = $20;
    5915          54 :                     n->row = true;
    5916          54 :                     n->timing = TRIGGER_TYPE_AFTER;
    5917          54 :                     n->events = intVal(linitial($7));
    5918          54 :                     n->columns = (List *) lsecond($7);
    5919          54 :                     n->whenClause = $15;
    5920          54 :                     n->transitionRels = NIL;
    5921          54 :                     processCASbits($11, @11, "TRIGGER",
    5922             :                                    &n->deferrable, &n->initdeferred, NULL,
    5923             :                                    NULL, yyscanner);
    5924          54 :                     n->constrrel = $10;
    5925          54 :                     $$ = (Node *) n;
    5926             :                 }
    5927             :         ;
    5928             : 
    5929             : TriggerActionTime:
    5930        1392 :             BEFORE                              { $$ = TRIGGER_TYPE_BEFORE; }
    5931        1532 :             | AFTER                             { $$ = TRIGGER_TYPE_AFTER; }
    5932         138 :             | INSTEAD OF                        { $$ = TRIGGER_TYPE_INSTEAD; }
    5933             :         ;
    5934             : 
    5935             : TriggerEvents:
    5936             :             TriggerOneEvent
    5937        3116 :                 { $$ = $1; }
    5938             :             | TriggerEvents OR TriggerOneEvent
    5939             :                 {
    5940        1076 :                     int         events1 = intVal(linitial($1));
    5941        1076 :                     int         events2 = intVal(linitial($3));
    5942        1076 :                     List       *columns1 = (List *) lsecond($1);
    5943        1076 :                     List       *columns2 = (List *) lsecond($3);
    5944             : 
    5945        1076 :                     if (events1 & events2)
    5946           6 :                         parser_yyerror("duplicate trigger events specified");
    5947             :                     /*
    5948             :                      * concat'ing the columns lists loses information about
    5949             :                      * which columns went with which event, but so long as
    5950             :                      * only UPDATE carries columns and we disallow multiple
    5951             :                      * UPDATE items, it doesn't matter.  Command execution
    5952             :                      * should just ignore the columns for non-UPDATE events.
    5953             :                      */
    5954        1070 :                     $$ = list_make2(makeInteger(events1 | events2),
    5955             :                                     list_concat(columns1, columns2));
    5956             :                 }
    5957             :         ;
    5958             : 
    5959             : TriggerOneEvent:
    5960             :             INSERT
    5961        1550 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
    5962             :             | DELETE_P
    5963         864 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
    5964             :             | UPDATE
    5965        1646 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
    5966             :             | UPDATE OF columnList
    5967          94 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
    5968             :             | TRUNCATE
    5969          38 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
    5970             :         ;
    5971             : 
    5972             : TriggerReferencing:
    5973         424 :             REFERENCING TriggerTransitions          { $$ = $2; }
    5974        2626 :             | /*EMPTY*/                             { $$ = NIL; }
    5975             :         ;
    5976             : 
    5977             : TriggerTransitions:
    5978         424 :             TriggerTransition                       { $$ = list_make1($1); }
    5979         138 :             | TriggerTransitions TriggerTransition  { $$ = lappend($1, $2); }
    5980             :         ;
    5981             : 
    5982             : TriggerTransition:
    5983             :             TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
    5984             :                 {
    5985         562 :                     TriggerTransition *n = makeNode(TriggerTransition);
    5986             : 
    5987         562 :                     n->name = $4;
    5988         562 :                     n->isNew = $1;
    5989         562 :                     n->isTable = $2;
    5990         562 :                     $$ = (Node *) n;
    5991             :                 }
    5992             :         ;
    5993             : 
    5994             : TransitionOldOrNew:
    5995         306 :             NEW                                     { $$ = true; }
    5996         256 :             | OLD                                   { $$ = false; }
    5997             :         ;
    5998             : 
    5999             : TransitionRowOrTable:
    6000         562 :             TABLE                                   { $$ = true; }
    6001             :             /*
    6002             :              * According to the standard, lack of a keyword here implies ROW.
    6003             :              * Support for that would require prohibiting ROW entirely here,
    6004             :              * reserving the keyword ROW, and/or requiring AS (instead of
    6005             :              * allowing it to be optional, as the standard specifies) as the
    6006             :              * next token.  Requiring ROW seems cleanest and easiest to
    6007             :              * explain.
    6008             :              */
    6009           0 :             | ROW                                   { $$ = false; }
    6010             :         ;
    6011             : 
    6012             : TransitionRelName:
    6013         562 :             ColId                                   { $$ = $1; }
    6014             :         ;
    6015             : 
    6016             : TriggerForSpec:
    6017             :             FOR TriggerForOptEach TriggerForType
    6018             :                 {
    6019        2822 :                     $$ = $3;
    6020             :                 }
    6021             :             | /* EMPTY */
    6022             :                 {
    6023             :                     /*
    6024             :                      * If ROW/STATEMENT not specified, default to
    6025             :                      * STATEMENT, per SQL
    6026             :                      */
    6027         228 :                     $$ = false;
    6028             :                 }
    6029             :         ;
    6030             : 
    6031             : TriggerForOptEach:
    6032             :             EACH
    6033             :             | /*EMPTY*/
    6034             :         ;
    6035             : 
    6036             : TriggerForType:
    6037        2042 :             ROW                                     { $$ = true; }
    6038         780 :             | STATEMENT                             { $$ = false; }
    6039             :         ;
    6040             : 
    6041             : TriggerWhen:
    6042         152 :             WHEN '(' a_expr ')'                     { $$ = $3; }
    6043        2952 :             | /*EMPTY*/                             { $$ = NULL; }
    6044             :         ;
    6045             : 
    6046             : FUNCTION_or_PROCEDURE:
    6047             :             FUNCTION
    6048             :         |   PROCEDURE
    6049             :         ;
    6050             : 
    6051             : TriggerFuncArgs:
    6052         574 :             TriggerFuncArg                          { $$ = list_make1($1); }
    6053         264 :             | TriggerFuncArgs ',' TriggerFuncArg    { $$ = lappend($1, $3); }
    6054        2530 :             | /*EMPTY*/                             { $$ = NIL; }
    6055             :         ;
    6056             : 
    6057             : TriggerFuncArg:
    6058             :             Iconst
    6059             :                 {
    6060         102 :                     $$ = (Node *) makeString(psprintf("%d", $1));
    6061             :                 }
    6062           0 :             | FCONST                                { $$ = (Node *) makeString($1); }
    6063         696 :             | Sconst                                { $$ = (Node *) makeString($1); }
    6064          40 :             | ColLabel                              { $$ = (Node *) makeString($1); }
    6065             :         ;
    6066             : 
    6067             : OptConstrFromTable:
    6068          12 :             FROM qualified_name                     { $$ = $2; }
    6069          42 :             | /*EMPTY*/                             { $$ = NULL; }
    6070             :         ;
    6071             : 
    6072             : ConstraintAttributeSpec:
    6073             :             /*EMPTY*/
    6074       14360 :                 { $$ = 0; }
    6075             :             | ConstraintAttributeSpec ConstraintAttributeElem
    6076             :                 {
    6077             :                     /*
    6078             :                      * We must complain about conflicting options.
    6079             :                      * We could, but choose not to, complain about redundant
    6080             :                      * options (ie, where $2's bit is already set in $1).
    6081             :                      */
    6082        1102 :                     int     newspec = $1 | $2;
    6083             : 
    6084             :                     /* special message for this case */
    6085        1102 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
    6086           6 :                         ereport(ERROR,
    6087             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6088             :                                  errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
    6089             :                                  parser_errposition(@2)));
    6090             :                     /* generic message for other conflicts */
    6091        1096 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
    6092        1096 :                         (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED))
    6093           0 :                         ereport(ERROR,
    6094             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6095             :                                  errmsg("conflicting constraint properties"),
    6096             :                                  parser_errposition(@2)));
    6097        1096 :                     $$ = newspec;
    6098             :                 }
    6099             :         ;
    6100             : 
    6101             : ConstraintAttributeElem:
    6102          36 :             NOT DEFERRABLE                  { $$ = CAS_NOT_DEFERRABLE; }
    6103         216 :             | DEFERRABLE                    { $$ = CAS_DEFERRABLE; }
    6104          30 :             | INITIALLY IMMEDIATE           { $$ = CAS_INITIALLY_IMMEDIATE; }
    6105         162 :             | INITIALLY DEFERRED            { $$ = CAS_INITIALLY_DEFERRED; }
    6106         516 :             | NOT VALID                     { $$ = CAS_NOT_VALID; }
    6107         142 :             | NO INHERIT                    { $$ = CAS_NO_INHERIT; }
    6108             :         ;
    6109             : 
    6110             : 
    6111             : /*****************************************************************************
    6112             :  *
    6113             :  *      QUERIES :
    6114             :  *              CREATE EVENT TRIGGER ...
    6115             :  *              ALTER EVENT TRIGGER ...
    6116             :  *
    6117             :  *****************************************************************************/
    6118             : 
    6119             : CreateEventTrigStmt:
    6120             :             CREATE EVENT TRIGGER name ON ColLabel
    6121             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    6122             :                 {
    6123          98 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6124             : 
    6125          98 :                     n->trigname = $4;
    6126          98 :                     n->eventname = $6;
    6127          98 :                     n->whenclause = NULL;
    6128          98 :                     n->funcname = $9;
    6129          98 :                     $$ = (Node *) n;
    6130             :                 }
    6131             :           | CREATE EVENT TRIGGER name ON ColLabel
    6132             :             WHEN event_trigger_when_list
    6133             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    6134             :                 {
    6135          98 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6136             : 
    6137          98 :                     n->trigname = $4;
    6138          98 :                     n->eventname = $6;
    6139          98 :                     n->whenclause = $8;
    6140          98 :                     n->funcname = $11;
    6141          98 :                     $$ = (Node *) n;
    6142             :                 }
    6143             :         ;
    6144             : 
    6145             : event_trigger_when_list:
    6146             :           event_trigger_when_item
    6147          98 :             { $$ = list_make1($1); }
    6148             :         | event_trigger_when_list AND event_trigger_when_item
    6149           6 :             { $$ = lappend($1, $3); }
    6150             :         ;
    6151             : 
    6152             : event_trigger_when_item:
    6153             :         ColId IN_P '(' event_trigger_value_list ')'
    6154         104 :             { $$ = makeDefElem($1, (Node *) $4, @1); }
    6155             :         ;
    6156             : 
    6157             : event_trigger_value_list:
    6158             :           SCONST
    6159         104 :             { $$ = list_make1(makeString($1)); }
    6160             :         | event_trigger_value_list ',' SCONST
    6161          66 :             { $$ = lappend($1, makeString($3)); }
    6162             :         ;
    6163             : 
    6164             : AlterEventTrigStmt:
    6165             :             ALTER EVENT TRIGGER name enable_trigger
    6166             :                 {
    6167          48 :                     AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
    6168             : 
    6169          48 :                     n->trigname = $4;
    6170          48 :                     n->tgenabled = $5;
    6171          48 :                     $$ = (Node *) n;
    6172             :                 }
    6173             :         ;
    6174             : 
    6175             : enable_trigger:
    6176           6 :             ENABLE_P                    { $$ = TRIGGER_FIRES_ON_ORIGIN; }
    6177           6 :             | ENABLE_P REPLICA          { $$ = TRIGGER_FIRES_ON_REPLICA; }
    6178          16 :             | ENABLE_P ALWAYS           { $$ = TRIGGER_FIRES_ALWAYS; }
    6179          20 :             | DISABLE_P                 { $$ = TRIGGER_DISABLED; }
    6180             :         ;
    6181             : 
    6182             : /*****************************************************************************
    6183             :  *
    6184             :  *      QUERY :
    6185             :  *              CREATE ASSERTION ...
    6186             :  *
    6187             :  *****************************************************************************/
    6188             : 
    6189             : CreateAssertionStmt:
    6190             :             CREATE ASSERTION any_name CHECK '(' a_expr ')' ConstraintAttributeSpec
    6191             :                 {
    6192           0 :                     ereport(ERROR,
    6193             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6194             :                              errmsg("CREATE ASSERTION is not yet implemented")));
    6195             : 
    6196             :                     $$ = NULL;
    6197             :                 }
    6198             :         ;
    6199             : 
    6200             : 
    6201             : /*****************************************************************************
    6202             :  *
    6203             :  *      QUERY :
    6204             :  *              define (aggregate,operator,type)
    6205             :  *
    6206             :  *****************************************************************************/
    6207             : 
    6208             : DefineStmt:
    6209             :             CREATE opt_or_replace AGGREGATE func_name aggr_args definition
    6210             :                 {
    6211         542 :                     DefineStmt *n = makeNode(DefineStmt);
    6212             : 
    6213         542 :                     n->kind = OBJECT_AGGREGATE;
    6214         542 :                     n->oldstyle = false;
    6215         542 :                     n->replace = $2;
    6216         542 :                     n->defnames = $4;
    6217         542 :                     n->args = $5;
    6218         542 :                     n->definition = $6;
    6219         542 :                     $$ = (Node *) n;
    6220             :                 }
    6221             :             | CREATE opt_or_replace AGGREGATE func_name old_aggr_definition
    6222             :                 {
    6223             :                     /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
    6224         362 :                     DefineStmt *n = makeNode(DefineStmt);
    6225             : 
    6226         362 :                     n->kind = OBJECT_AGGREGATE;
    6227         362 :                     n->oldstyle = true;
    6228         362 :                     n->replace = $2;
    6229         362 :                     n->defnames = $4;
    6230         362 :                     n->args = NIL;
    6231         362 :                     n->definition = $5;
    6232         362 :                     $$ = (Node *) n;
    6233             :                 }
    6234             :             | CREATE OPERATOR any_operator definition
    6235             :                 {
    6236        1586 :                     DefineStmt *n = makeNode(DefineStmt);
    6237             : 
    6238        1586 :                     n->kind = OBJECT_OPERATOR;
    6239        1586 :                     n->oldstyle = false;
    6240        1586 :                     n->defnames = $3;
    6241        1586 :                     n->args = NIL;
    6242        1586 :                     n->definition = $4;
    6243        1586 :                     $$ = (Node *) n;
    6244             :                 }
    6245             :             | CREATE TYPE_P any_name definition
    6246             :                 {
    6247         208 :                     DefineStmt *n = makeNode(DefineStmt);
    6248             : 
    6249         208 :                     n->kind = OBJECT_TYPE;
    6250         208 :                     n->oldstyle = false;
    6251         208 :                     n->defnames = $3;
    6252         208 :                     n->args = NIL;
    6253         208 :                     n->definition = $4;
    6254         208 :                     $$ = (Node *) n;
    6255             :                 }
    6256             :             | CREATE TYPE_P any_name
    6257             :                 {
    6258             :                     /* Shell type (identified by lack of definition) */
    6259         154 :                     DefineStmt *n = makeNode(DefineStmt);
    6260             : 
    6261         154 :                     n->kind = OBJECT_TYPE;
    6262         154 :                     n->oldstyle = false;
    6263         154 :                     n->defnames = $3;
    6264         154 :                     n->args = NIL;
    6265         154 :                     n->definition = NIL;
    6266         154 :                     $$ = (Node *) n;
    6267             :                 }
    6268             :             | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
    6269             :                 {
    6270         684 :                     CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
    6271             : 
    6272             :                     /* can't use qualified_name, sigh */
    6273         684 :                     n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
    6274         684 :                     n->coldeflist = $6;
    6275         684 :                     $$ = (Node *) n;
    6276             :                 }
    6277             :             | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
    6278             :                 {
    6279         188 :                     CreateEnumStmt *n = makeNode(CreateEnumStmt);
    6280             : 
    6281         188 :                     n->typeName = $3;
    6282         188 :                     n->vals = $7;
    6283         188 :                     $$ = (Node *) n;
    6284             :                 }
    6285             :             | CREATE TYPE_P any_name AS RANGE definition
    6286             :                 {
    6287         166 :                     CreateRangeStmt *n = makeNode(CreateRangeStmt);
    6288             : 
    6289         166 :                     n->typeName = $3;
    6290         166 :                     n->params = $6;
    6291         166 :                     $$ = (Node *) n;
    6292             :                 }
    6293             :             | CREATE TEXT_P SEARCH PARSER any_name definition
    6294             :                 {
    6295          40 :                     DefineStmt *n = makeNode(DefineStmt);
    6296             : 
    6297          40 :                     n->kind = OBJECT_TSPARSER;
    6298          40 :                     n->args = NIL;
    6299          40 :                     n->defnames = $5;
    6300          40 :                     n->definition = $6;
    6301          40 :                     $$ = (Node *) n;
    6302             :                 }
    6303             :             | CREATE TEXT_P SEARCH DICTIONARY any_name definition
    6304             :                 {
    6305        2274 :                     DefineStmt *n = makeNode(DefineStmt);
    6306             : 
    6307        2274 :                     n->kind = OBJECT_TSDICTIONARY;
    6308        2274 :                     n->args = NIL;
    6309        2274 :                     n->defnames = $5;
    6310        2274 :                     n->definition = $6;
    6311        2274 :                     $$ = (Node *) n;
    6312             :                 }
    6313             :             | CREATE TEXT_P SEARCH TEMPLATE any_name definition
    6314             :                 {
    6315         120 :                     DefineStmt *n = makeNode(DefineStmt);
    6316             : 
    6317         120 :                     n->kind = OBJECT_TSTEMPLATE;
    6318         120 :                     n->args = NIL;
    6319         120 :                     n->defnames = $5;
    6320         120 :                     n->definition = $6;
    6321         120 :                     $$ = (Node *) n;
    6322             :                 }
    6323             :             | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
    6324             :                 {
    6325        2216 :                     DefineStmt *n = makeNode(DefineStmt);
    6326             : 
    6327        2216 :                     n->kind = OBJECT_TSCONFIGURATION;
    6328        2216 :                     n->args = NIL;
    6329        2216 :                     n->defnames = $5;
    6330        2216 :                     n->definition = $6;
    6331        2216 :                     $$ = (Node *) n;
    6332             :                 }
    6333             :             | CREATE COLLATION any_name definition
    6334             :                 {
    6335         272 :                     DefineStmt *n = makeNode(DefineStmt);
    6336             : 
    6337         272 :                     n->kind = OBJECT_COLLATION;
    6338         272 :                     n->args = NIL;
    6339         272 :                     n->defnames = $3;
    6340         272 :                     n->definition = $4;
    6341         272 :                     $$ = (Node *) n;
    6342             :                 }
    6343             :             | CREATE COLLATION IF_P NOT EXISTS any_name definition
    6344             :                 {
    6345          18 :                     DefineStmt *n = makeNode(DefineStmt);
    6346             : 
    6347          18 :                     n->kind = OBJECT_COLLATION;
    6348          18 :                     n->args = NIL;
    6349          18 :                     n->defnames = $6;
    6350          18 :                     n->definition = $7;
    6351          18 :                     n->if_not_exists = true;
    6352          18 :                     $$ = (Node *) n;
    6353             :                 }
    6354             :             | CREATE COLLATION any_name FROM any_name
    6355             :                 {
    6356          52 :                     DefineStmt *n = makeNode(DefineStmt);
    6357             : 
    6358          52 :                     n->kind = OBJECT_COLLATION;
    6359          52 :                     n->args = NIL;
    6360          52 :                     n->defnames = $3;
    6361          52 :                     n->definition = list_make1(makeDefElem("from", (Node *) $5, @5));
    6362          52 :                     $$ = (Node *) n;
    6363             :                 }
    6364             :             | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
    6365             :                 {
    6366           0 :                     DefineStmt *n = makeNode(DefineStmt);
    6367             : 
    6368           0 :                     n->kind = OBJECT_COLLATION;
    6369           0 :                     n->args = NIL;
    6370           0 :                     n->defnames = $6;
    6371           0 :                     n->definition = list_make1(makeDefElem("from", (Node *) $8, @8));
    6372           0 :                     n->if_not_exists = true;
    6373           0 :                     $$ = (Node *) n;
    6374             :                 }
    6375             :         ;
    6376             : 
    6377        8328 : definition: '(' def_list ')'                        { $$ = $2; }
    6378             :         ;
    6379             : 
    6380        8328 : def_list:   def_elem                                { $$ = list_make1($1); }
    6381       13512 :             | def_list ',' def_elem                 { $$ = lappend($1, $3); }
    6382             :         ;
    6383             : 
    6384             : def_elem:   ColLabel '=' def_arg
    6385             :                 {
    6386       21516 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6387             :                 }
    6388             :             | ColLabel
    6389             :                 {
    6390         324 :                     $$ = makeDefElem($1, NULL, @1);
    6391             :                 }
    6392             :         ;
    6393             : 
    6394             : /* Note: any simple identifier will be returned as a type name! */
    6395       17668 : def_arg:    func_type                       { $$ = (Node *) $1; }
    6396        3294 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
    6397        1174 :             | qual_all_Op                   { $$ = (Node *) $1; }
    6398        1262 :             | NumericOnly                   { $$ = (Node *) $1; }
    6399        1802 :             | Sconst                        { $$ = (Node *) makeString($1); }
    6400         130 :             | NONE                          { $$ = (Node *) makeString(pstrdup($1)); }
    6401             :         ;
    6402             : 
    6403         362 : old_aggr_definition: '(' old_aggr_list ')'          { $$ = $2; }
    6404             :         ;
    6405             : 
    6406         362 : old_aggr_list: old_aggr_elem                        { $$ = list_make1($1); }
    6407        1292 :             | old_aggr_list ',' old_aggr_elem       { $$ = lappend($1, $3); }
    6408             :         ;
    6409             : 
    6410             : /*
    6411             :  * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
    6412             :  * the item names needed in old aggregate definitions are likely to become
    6413             :  * SQL keywords.
    6414             :  */
    6415             : old_aggr_elem:  IDENT '=' def_arg
    6416             :                 {
    6417        1654 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6418             :                 }
    6419             :         ;
    6420             : 
    6421             : opt_enum_val_list:
    6422         180 :         enum_val_list                           { $$ = $1; }
    6423           8 :         | /*EMPTY*/                             { $$ = NIL; }
    6424             :         ;
    6425             : 
    6426             : enum_val_list:  Sconst
    6427         180 :                 { $$ = list_make1(makeString($1)); }
    6428             :             | enum_val_list ',' Sconst
    6429       10394 :                 { $$ = lappend($1, makeString($3)); }
    6430             :         ;
    6431             : 
    6432             : /*****************************************************************************
    6433             :  *
    6434             :  *  ALTER TYPE enumtype ADD ...
    6435             :  *
    6436             :  *****************************************************************************/
    6437             : 
    6438             : AlterEnumStmt:
    6439             :         ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
    6440             :             {
    6441         154 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6442             : 
    6443         154 :                 n->typeName = $3;
    6444         154 :                 n->oldVal = NULL;
    6445         154 :                 n->newVal = $7;
    6446         154 :                 n->newValNeighbor = NULL;
    6447         154 :                 n->newValIsAfter = true;
    6448         154 :                 n->skipIfNewValExists = $6;
    6449         154 :                 $$ = (Node *) n;
    6450             :             }
    6451             :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
    6452             :             {
    6453         194 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6454             : 
    6455         194 :                 n->typeName = $3;
    6456         194 :                 n->oldVal = NULL;
    6457         194 :                 n->newVal = $7;
    6458         194 :                 n->newValNeighbor = $9;
    6459         194 :                 n->newValIsAfter = false;
    6460         194 :                 n->skipIfNewValExists = $6;
    6461         194 :                 $$ = (Node *) n;
    6462             :             }
    6463             :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
    6464             :             {
    6465          22 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6466             : 
    6467          22 :                 n->typeName = $3;
    6468          22 :                 n->oldVal = NULL;
    6469          22 :                 n->newVal = $7;
    6470          22 :                 n->newValNeighbor = $9;
    6471          22 :                 n->newValIsAfter = true;
    6472          22 :                 n->skipIfNewValExists = $6;
    6473          22 :                 $$ = (Node *) n;
    6474             :             }
    6475             :          | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
    6476             :             {
    6477          24 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6478             : 
    6479          24 :                 n->typeName = $3;
    6480          24 :                 n->oldVal = $6;
    6481          24 :                 n->newVal = $8;
    6482          24 :                 n->newValNeighbor = NULL;
    6483          24 :                 n->newValIsAfter = false;
    6484          24 :                 n->skipIfNewValExists = false;
    6485          24 :                 $$ = (Node *) n;
    6486             :             }
    6487             :          | ALTER TYPE_P any_name DROP VALUE_P Sconst
    6488             :             {
    6489             :                 /*
    6490             :                  * The following problems must be solved before this can be
    6491             :                  * implemented:
    6492             :                  *
    6493             :                  * - There must be no instance of the target value in
    6494             :                  *   any table.
    6495             :                  *
    6496             :                  * - The value must not appear in any catalog metadata,
    6497             :                  *   such as stored view expressions or column defaults.
    6498             :                  *
    6499             :                  * - The value must not appear in any non-leaf page of a
    6500             :                  *   btree (and similar issues with other index types).
    6501             :                  *   This is problematic because a value could persist
    6502             :                  *   there long after it's gone from user-visible data.
    6503             :                  *
    6504             :                  * - Concurrent sessions must not be able to insert the
    6505             :                  *   value while the preceding conditions are being checked.
    6506             :                  *
    6507             :                  * - Possibly more...
    6508             :                  */
    6509           0 :                 ereport(ERROR,
    6510             :                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6511             :                          errmsg("dropping an enum value is not implemented"),
    6512             :                          parser_errposition(@4)));
    6513             :             }
    6514             :          ;
    6515             : 
    6516          12 : opt_if_not_exists: IF_P NOT EXISTS              { $$ = true; }
    6517         358 :         | /* EMPTY */                          { $$ = false; }
    6518             :         ;
    6519             : 
    6520             : 
    6521             : /*****************************************************************************
    6522             :  *
    6523             :  *      QUERIES :
    6524             :  *              CREATE OPERATOR CLASS ...
    6525             :  *              CREATE OPERATOR FAMILY ...
    6526             :  *              ALTER OPERATOR FAMILY ...
    6527             :  *              DROP OPERATOR CLASS ...
    6528             :  *              DROP OPERATOR FAMILY ...
    6529             :  *
    6530             :  *****************************************************************************/
    6531             : 
    6532             : CreateOpClassStmt:
    6533             :             CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
    6534             :             USING name opt_opfamily AS opclass_item_list
    6535             :                 {
    6536         382 :                     CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
    6537             : 
    6538         382 :                     n->opclassname = $4;
    6539         382 :                     n->isDefault = $5;
    6540         382 :                     n->datatype = $8;
    6541         382 :                     n->amname = $10;
    6542         382 :                     n->opfamilyname = $11;
    6543         382 :                     n->items = $13;
    6544         382 :                     $$ = (Node *) n;
    6545             :                 }
    6546             :         ;
    6547             : 
    6548             : opclass_item_list:
    6549         820 :             opclass_item                            { $$ = list_make1($1); }
    6550        3058 :             | opclass_item_list ',' opclass_item    { $$ = lappend($1, $3); }
    6551             :         ;
    6552             : 
    6553             : opclass_item:
    6554             :             OPERATOR Iconst any_operator opclass_purpose opt_recheck
    6555             :                 {
    6556        1092 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6557        1092 :                     ObjectWithArgs *owa = makeNode(ObjectWithArgs);
    6558             : 
    6559        1092 :                     owa->objname = $3;
    6560        1092 :                     owa->objargs = NIL;
    6561        1092 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6562        1092 :                     n->name = owa;
    6563        1092 :                     n->number = $2;
    6564        1092 :                     n->order_family = $4;
    6565        1092 :                     $$ = (Node *) n;
    6566             :                 }
    6567             :             | OPERATOR Iconst operator_with_argtypes opclass_purpose
    6568             :               opt_recheck
    6569             :                 {
    6570        1026 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6571             : 
    6572        1026 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6573        1026 :                     n->name = $3;
    6574        1026 :                     n->number = $2;
    6575        1026 :                     n->order_family = $4;
    6576        1026 :                     $$ = (Node *) n;
    6577             :                 }
    6578             :             | FUNCTION Iconst function_with_argtypes
    6579             :                 {
    6580        1374 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6581             : 
    6582        1374 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6583        1374 :                     n->name = $3;
    6584        1374 :                     n->number = $2;
    6585        1374 :                     $$ = (Node *) n;
    6586             :                 }
    6587             :             | FUNCTION Iconst '(' type_list ')' function_with_argtypes
    6588             :                 {
    6589         188 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6590             : 
    6591         188 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6592         188 :                     n->name = $6;
    6593         188 :                     n->number = $2;
    6594         188 :                     n->class_args = $4;
    6595         188 :                     $$ = (Node *) n;
    6596             :                 }
    6597             :             | STORAGE Typename
    6598             :                 {
    6599         198 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6600             : 
    6601         198 :                     n->itemtype = OPCLASS_ITEM_STORAGETYPE;
    6602         198 :                     n->storedtype = $2;
    6603         198 :                     $$ = (Node *) n;
    6604             :                 }
    6605             :         ;
    6606             : 
    6607         290 : opt_default:    DEFAULT                     { $$ = true; }
    6608         156 :             | /*EMPTY*/                     { $$ = false; }
    6609             :         ;
    6610             : 
    6611          44 : opt_opfamily:   FAMILY any_name             { $$ = $2; }
    6612         338 :             | /*EMPTY*/                     { $$ = NIL; }
    6613             :         ;
    6614             : 
    6615           0 : opclass_purpose: FOR SEARCH                 { $$ = NIL; }
    6616          72 :             | FOR ORDER BY any_name         { $$ = $4; }
    6617        2046 :             | /*EMPTY*/                     { $$ = NIL; }
    6618             :         ;
    6619             : 
    6620             : opt_recheck:    RECHECK
    6621             :                 {
    6622             :                     /*
    6623             :                      * RECHECK no longer does anything in opclass definitions,
    6624             :                      * but we still accept it to ease porting of old database
    6625             :                      * dumps.
    6626             :                      */
    6627           0 :                     ereport(NOTICE,
    6628             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6629             :                              errmsg("RECHECK is no longer required"),
    6630             :                              errhint("Update your data type."),
    6631             :                              parser_errposition(@1)));
    6632           0 :                     $$ = true;
    6633             :                 }
    6634        2118 :             | /*EMPTY*/                     { $$ = false; }
    6635             :         ;
    6636             : 
    6637             : 
    6638             : CreateOpFamilyStmt:
    6639             :             CREATE OPERATOR FAMILY any_name USING name
    6640             :                 {
    6641         148 :                     CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
    6642             : 
    6643         148 :                     n->opfamilyname = $4;
    6644         148 :                     n->amname = $6;
    6645         148 :                     $$ = (Node *) n;
    6646             :                 }
    6647             :         ;
    6648             : 
    6649             : AlterOpFamilyStmt:
    6650             :             ALTER OPERATOR FAMILY any_name USING name ADD_P opclass_item_list
    6651             :                 {
    6652         438 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6653             : 
    6654         438 :                     n->opfamilyname = $4;
    6655         438 :                     n->amname = $6;
    6656         438 :                     n->isDrop = false;
    6657         438 :                     n->items = $8;
    6658         438 :                     $$ = (Node *) n;
    6659             :                 }
    6660             :             | ALTER OPERATOR FAMILY any_name USING name DROP opclass_drop_list
    6661             :                 {
    6662          64 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6663             : 
    6664          64 :                     n->opfamilyname = $4;
    6665          64 :                     n->amname = $6;
    6666          64 :                     n->isDrop = true;
    6667          64 :                     n->items = $8;
    6668          64 :                     $$ = (Node *) n;
    6669             :                 }
    6670             :         ;
    6671             : 
    6672             : opclass_drop_list:
    6673          64 :             opclass_drop                            { $$ = list_make1($1); }
    6674          30 :             | opclass_drop_list ',' opclass_drop    { $$ = lappend($1, $3); }
    6675             :         ;
    6676             : 
    6677             : opclass_drop:
    6678             :             OPERATOR Iconst '(' type_list ')'
    6679             :                 {
    6680          56 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6681             : 
    6682          56 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6683          56 :                     n->number = $2;
    6684          56 :                     n->class_args = $4;
    6685          56 :                     $$ = (Node *) n;
    6686             :                 }
    6687             :             | FUNCTION Iconst '(' type_list ')'
    6688             :                 {
    6689          38 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6690             : 
    6691          38 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6692          38 :                     n->number = $2;
    6693          38 :                     n->class_args = $4;
    6694          38 :                     $$ = (Node *) n;
    6695             :                 }
    6696             :         ;
    6697             : 
    6698             : 
    6699             : DropOpClassStmt:
    6700             :             DROP OPERATOR CLASS any_name USING name opt_drop_behavior
    6701             :                 {
    6702          38 :                     DropStmt *n = makeNode(DropStmt);
    6703             : 
    6704          38 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6705          38 :                     n->removeType = OBJECT_OPCLASS;
    6706          38 :                     n->behavior = $7;
    6707          38 :                     n->missing_ok = false;
    6708          38 :                     n->concurrent = false;
    6709          38 :                     $$ = (Node *) n;
    6710             :                 }
    6711             :             | DROP OPERATOR CLASS IF_P EXISTS any_name USING name opt_drop_behavior
    6712             :                 {
    6713          18 :                     DropStmt *n = makeNode(DropStmt);
    6714             : 
    6715          18 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6716          18 :                     n->removeType = OBJECT_OPCLASS;
    6717          18 :                     n->behavior = $9;
    6718          18 :                     n->missing_ok = true;
    6719          18 :                     n->concurrent = false;
    6720          18 :                     $$ = (Node *) n;
    6721             :                 }
    6722             :         ;
    6723             : 
    6724             : DropOpFamilyStmt:
    6725             :             DROP OPERATOR FAMILY any_name USING name opt_drop_behavior
    6726             :                 {
    6727         110 :                     DropStmt *n = makeNode(DropStmt);
    6728             : 
    6729         110 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6730         110 :                     n->removeType = OBJECT_OPFAMILY;
    6731         110 :                     n->behavior = $7;
    6732         110 :                     n->missing_ok = false;
    6733         110 :                     n->concurrent = false;
    6734         110 :                     $$ = (Node *) n;
    6735             :                 }
    6736             :             | DROP OPERATOR FAMILY IF_P EXISTS any_name USING name opt_drop_behavior
    6737             :                 {
    6738          18 :                     DropStmt *n = makeNode(DropStmt);
    6739             : 
    6740          18 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6741          18 :                     n->removeType = OBJECT_OPFAMILY;
    6742          18 :                     n->behavior = $9;
    6743          18 :                     n->missing_ok = true;
    6744          18 :                     n->concurrent = false;
    6745          18 :                     $$ = (Node *) n;
    6746             :                 }
    6747             :         ;
    6748             : 
    6749             : 
    6750             : /*****************************************************************************
    6751             :  *
    6752             :  *      QUERY:
    6753             :  *
    6754             :  *      DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
    6755             :  *      REASSIGN OWNED BY username [, username ...] TO username
    6756             :  *
    6757             :  *****************************************************************************/
    6758             : DropOwnedStmt:
    6759             :             DROP OWNED BY role_list opt_drop_behavior
    6760             :                 {
    6761         144 :                     DropOwnedStmt *n = makeNode(DropOwnedStmt);
    6762             : 
    6763         144 :                     n->roles = $4;
    6764         144 :                     n->behavior = $5;
    6765         144 :                     $$ = (Node *) n;
    6766             :                 }
    6767             :         ;
    6768             : 
    6769             : ReassignOwnedStmt:
    6770             :             REASSIGN OWNED BY role_list TO RoleSpec
    6771             :                 {
    6772          38 :                     ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
    6773             : 
    6774          38 :                     n->roles = $4;
    6775          38 :                     n->newrole = $6;
    6776          38 :                     $$ = (Node *) n;
    6777             :                 }
    6778             :         ;
    6779             : 
    6780             : /*****************************************************************************
    6781             :  *
    6782             :  *      QUERY:
    6783             :  *
    6784             :  *      DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
    6785             :  *           [ RESTRICT | CASCADE ]
    6786             :  *
    6787             :  *****************************************************************************/
    6788             : 
    6789             : DropStmt:   DROP object_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
    6790             :                 {
    6791        1232 :                     DropStmt *n = makeNode(DropStmt);
    6792             : 
    6793        1232 :                     n->removeType = $2;
    6794        1232 :                     n->missing_ok = true;
    6795        1232 :                     n->objects = $5;
    6796        1232 :                     n->behavior = $6;
    6797        1232 :                     n->concurrent = false;
    6798        1232 :                     $$ = (Node *) n;
    6799             :                 }
    6800             :             | DROP object_type_any_name any_name_list opt_drop_behavior
    6801             :                 {
    6802       14796 :                     DropStmt *n = makeNode(DropStmt);
    6803             : 
    6804       14796 :                     n->removeType = $2;
    6805       14796 :                     n->missing_ok = false;
    6806       14796 :                     n->objects = $3;
    6807       14796 :                     n->behavior = $4;
    6808       14796 :                     n->concurrent = false;
    6809       14796 :                     $$ = (Node *) n;
    6810             :                 }
    6811             :             | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
    6812             :                 {
    6813          78 :                     DropStmt *n = makeNode(DropStmt);
    6814             : 
    6815          78 :                     n->removeType = $2;
    6816          78 :                     n->missing_ok = true;
    6817          78 :                     n->objects = $5;
    6818          78 :                     n->behavior = $6;
    6819          78 :                     n->concurrent = false;
    6820          78 :                     $$ = (Node *) n;
    6821             :                 }
    6822             :             | DROP drop_type_name name_list opt_drop_behavior
    6823             :                 {
    6824        1228 :                     DropStmt *n = makeNode(DropStmt);
    6825             : 
    6826        1228 :                     n->removeType = $2;
    6827        1228 :                     n->missing_ok = false;
    6828        1228 :                     n->objects = $3;
    6829        1228 :                     n->behavior = $4;
    6830        1228 :                     n->concurrent = false;
    6831        1228 :                     $$ = (Node *) n;
    6832             :                 }
    6833             :             | DROP object_type_name_on_any_name name ON any_name opt_drop_behavior
    6834             :                 {
    6835        1074 :                     DropStmt *n = makeNode(DropStmt);
    6836             : 
    6837        1074 :                     n->removeType = $2;
    6838        1074 :                     n->objects = list_make1(lappend($5, makeString($3)));
    6839        1074 :                     n->behavior = $6;
    6840        1074 :                     n->missing_ok = false;
    6841        1074 :                     n->concurrent = false;
    6842        1074 :                     $$ = (Node *) n;
    6843             :                 }
    6844             :             | DROP object_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
    6845             :                 {
    6846          48 :                     DropStmt *n = makeNode(DropStmt);
    6847             : 
    6848          48 :                     n->removeType = $2;
    6849          48 :                     n->objects = list_make1(lappend($7, makeString($5)));
    6850          48 :                     n->behavior = $8;
    6851          48 :                     n->missing_ok = true;
    6852          48 :                     n->concurrent = false;
    6853          48 :                     $$ = (Node *) n;
    6854             :                 }
    6855             :             | DROP TYPE_P type_name_list opt_drop_behavior
    6856             :                 {
    6857         524 :                     DropStmt *n = makeNode(DropStmt);
    6858             : 
    6859         524 :                     n->removeType = OBJECT_TYPE;
    6860         524 :                     n->missing_ok = false;
    6861         524 :                     n->objects = $3;
    6862         524 :                     n->behavior = $4;
    6863         524 :                     n->concurrent = false;
    6864         524 :                     $$ = (Node *) n;
    6865             :                 }
    6866             :             | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
    6867             :                 {
    6868          22 :                     DropStmt *n = makeNode(DropStmt);
    6869             : 
    6870          22 :                     n->removeType = OBJECT_TYPE;
    6871          22 :                     n->missing_ok = true;
    6872          22 :                     n->objects = $5;
    6873          22 :                     n->behavior = $6;
    6874          22 :                     n->concurrent = false;
    6875          22 :                     $$ = (Node *) n;
    6876             :                 }
    6877             :             | DROP DOMAIN_P type_name_list opt_drop_behavior
    6878             :                 {
    6879         386 :                     DropStmt *n = makeNode(DropStmt);
    6880             : 
    6881         386 :                     n->removeType = OBJECT_DOMAIN;
    6882         386 :                     n->missing_ok = false;
    6883         386 :                     n->objects = $3;
    6884         386 :                     n->behavior = $4;
    6885         386 :                     n->concurrent = false;
    6886         386 :                     $$ = (Node *) n;
    6887             :                 }
    6888             :             | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
    6889             :                 {
    6890          18 :                     DropStmt *n = makeNode(DropStmt);
    6891             : 
    6892          18 :                     n->removeType = OBJECT_DOMAIN;
    6893          18 :                     n->missing_ok = true;
    6894          18 :                     n->objects = $5;
    6895          18 :                     n->behavior = $6;
    6896          18 :                     n->concurrent = false;
    6897          18 :                     $$ = (Node *) n;
    6898             :                 }
    6899             :             | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
    6900             :                 {
    6901         124 :                     DropStmt *n = makeNode(DropStmt);
    6902             : 
    6903         124 :                     n->removeType = OBJECT_INDEX;
    6904         124 :                     n->missing_ok = false;
    6905         124 :                     n->objects = $4;
    6906         124 :                     n->behavior = $5;
    6907         124 :                     n->concurrent = true;
    6908         124 :                     $$ = (Node *) n;
    6909             :                 }
    6910             :             | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
    6911             :                 {
    6912          12 :                     DropStmt *n = makeNode(DropStmt);
    6913             : 
    6914          12 :                     n->removeType = OBJECT_INDEX;
    6915          12 :                     n->missing_ok = true;
    6916          12 :                     n->objects = $6;
    6917          12 :                     n->behavior = $7;
    6918          12 :                     n->concurrent = true;
    6919          12 :                     $$ = (Node *) n;
    6920             :                 }
    6921             :         ;
    6922             : 
    6923             : /* object types taking any_name/any_name_list */
    6924             : object_type_any_name:
    6925       13822 :             TABLE                                   { $$ = OBJECT_TABLE; }
    6926         194 :             | SEQUENCE                              { $$ = OBJECT_SEQUENCE; }
    6927         894 :             | VIEW                                  { $$ = OBJECT_VIEW; }
    6928         124 :             | MATERIALIZED VIEW                     { $$ = OBJECT_MATVIEW; }
    6929         740 :             | INDEX                                 { $$ = OBJECT_INDEX; }
    6930         170 :             | FOREIGN TABLE                         { $$ = OBJECT_FOREIGN_TABLE; }
    6931          90 :             | COLLATION                             { $$ = OBJECT_COLLATION; }
    6932          56 :             | CONVERSION_P                          { $$ = OBJECT_CONVERSION; }
    6933         192 :             | STATISTICS                            { $$ = OBJECT_STATISTIC_EXT; }
    6934          20 :             | TEXT_P SEARCH PARSER                  { $$ = OBJECT_TSPARSER; }
    6935        2158 :             | TEXT_P SEARCH DICTIONARY              { $$ = OBJECT_TSDICTIONARY; }
    6936          96 :             | TEXT_P SEARCH TEMPLATE                { $$ = OBJECT_TSTEMPLATE; }
    6937        2162 :             | TEXT_P SEARCH CONFIGURATION           { $$ = OBJECT_TSCONFIGURATION; }
    6938             :         ;
    6939             : 
    6940             : /*
    6941             :  * object types taking name/name_list
    6942             :  *
    6943             :  * DROP handles some of them separately
    6944             :  */
    6945             : 
    6946             : object_type_name:
    6947         184 :             drop_type_name                          { $$ = $1; }
    6948         178 :             | DATABASE                              { $$ = OBJECT_DATABASE; }
    6949          52 :             | ROLE                                  { $$ = OBJECT_ROLE; }
    6950          10 :             | SUBSCRIPTION                          { $$ = OBJECT_SUBSCRIPTION; }
    6951           0 :             | TABLESPACE                            { $$ = OBJECT_TABLESPACE; }
    6952             :         ;
    6953             : 
    6954             : drop_type_name:
    6955          46 :             ACCESS METHOD                           { $$ = OBJECT_ACCESS_METHOD; }
    6956         126 :             | EVENT TRIGGER                         { $$ = OBJECT_EVENT_TRIGGER; }
    6957         108 :             | EXTENSION                             { $$ = OBJECT_EXTENSION; }
    6958         148 :             | FOREIGN DATA_P WRAPPER                { $$ = OBJECT_FDW; }
    6959         134 :             | opt_procedural LANGUAGE               { $$ = OBJECT_LANGUAGE; }
    6960         282 :             | PUBLICATION                           { $$ = OBJECT_PUBLICATION; }
    6961         516 :             | SCHEMA                                { $$ = OBJECT_SCHEMA; }
    6962         130 :             | SERVER                                { $$ = OBJECT_FOREIGN_SERVER; }
    6963             :         ;
    6964             : 
    6965             : /* object types attached to a table */
    6966             : object_type_name_on_any_name:
    6967         164 :             POLICY                                  { $$ = OBJECT_POLICY; }
    6968         250 :             | RULE                                  { $$ = OBJECT_RULE; }
    6969         760 :             | TRIGGER                               { $$ = OBJECT_TRIGGER; }
    6970             :         ;
    6971             : 
    6972             : any_name_list:
    6973       22876 :             any_name                                { $$ = list_make1($1); }
    6974        3730 :             | any_name_list ',' any_name            { $$ = lappend($1, $3); }
    6975             :         ;
    6976             : 
    6977       52604 : any_name:   ColId                       { $$ = list_make1(makeString($1)); }
    6978        8302 :             | ColId attrs               { $$ = lcons(makeString($1), $2); }
    6979             :         ;
    6980             : 
    6981             : attrs:      '.' attr_name
    6982       91720 :                     { $$ = list_make1(makeString($2)); }
    6983             :             | attrs '.' attr_name
    6984          64 :                     { $$ = lappend($1, makeString($3)); }
    6985             :         ;
    6986             : 
    6987             : type_name_list:
    6988         950 :             Typename                                { $$ = list_make1($1); }
    6989          78 :             | type_name_list ',' Typename           { $$ = lappend($1, $3); }
    6990             :         ;
    6991             : 
    6992             : /*****************************************************************************
    6993             :  *
    6994             :  *      QUERY:
    6995             :  *              truncate table relname1, relname2, ...
    6996             :  *
    6997             :  *****************************************************************************/
    6998             : 
    6999             : TruncateStmt:
    7000             :             TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
    7001             :                 {
    7002        1450 :                     TruncateStmt *n = makeNode(TruncateStmt);
    7003             : 
    7004        1450 :                     n->relations = $3;
    7005        1450 :                     n->restart_seqs = $4;
    7006        1450 :                     n->behavior = $5;
    7007        1450 :                     $$ = (Node *) n;
    7008             :                 }
    7009             :         ;
    7010             : 
    7011             : opt_restart_seqs:
    7012          24 :             CONTINUE_P IDENTITY_P       { $$ = false; }
    7013          24 :             | RESTART IDENTITY_P        { $$ = true; }
    7014        1402 :             | /* EMPTY */               { $$ = false; }
    7015             :         ;
    7016             : 
    7017             : /*****************************************************************************
    7018             :  *
    7019             :  * COMMENT ON <object> IS <text>
    7020             :  *
    7021             :  *****************************************************************************/
    7022             : 
    7023             : CommentStmt:
    7024             :             COMMENT ON object_type_any_name any_name IS comment_text
    7025             :                 {
    7026        4566 :                     CommentStmt *n = makeNode(CommentStmt);
    7027             : 
    7028        4566 :                     n->objtype = $3;
    7029        4566 :                     n->object = (Node *) $4;
    7030        4566 :                     n->comment = $6;
    7031        4566 :                     $$ = (Node *) n;
    7032             :                 }
    7033             :             | COMMENT ON COLUMN any_name IS comment_text
    7034             :                 {
    7035         108 :                     CommentStmt *n = makeNode(CommentStmt);
    7036             : 
    7037         108 :                     n->objtype = OBJECT_COLUMN;
    7038         108 :                     n->object = (Node *) $4;
    7039         108 :                     n->comment = $6;
    7040         108 :                     $$ = (Node *) n;
    7041             :                 }
    7042             :             | COMMENT ON object_type_name name IS comment_text
    7043             :                 {
    7044         362 :                     CommentStmt *n = makeNode(CommentStmt);
    7045             : 
    7046         362 :                     n->objtype = $3;
    7047         362 :                     n->object = (Node *) makeString($4);
    7048         362 :                     n->comment = $6;
    7049         362 :                     $$ = (Node *) n;
    7050             :                 }
    7051             :             | COMMENT ON TYPE_P Typename IS comment_text
    7052             :                 {
    7053          56 :                     CommentStmt *n = makeNode(CommentStmt);
    7054             : 
    7055          56 :                     n->objtype = OBJECT_TYPE;
    7056          56 :                     n->object = (Node *) $4;
    7057          56 :                     n->comment = $6;
    7058          56 :                     $$ = (Node *) n;
    7059             :                 }
    7060             :             | COMMENT ON DOMAIN_P Typename IS comment_text
    7061             :                 {
    7062           8 :                     CommentStmt *n = makeNode(CommentStmt);
    7063             : 
    7064           8 :                     n->objtype = OBJECT_DOMAIN;
    7065           8 :                     n->object = (Node *) $4;
    7066           8 :                     n->comment = $6;
    7067           8 :                     $$ = (Node *) n;
    7068             :                 }
    7069             :             | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
    7070             :                 {
    7071          40 :                     CommentStmt *n = makeNode(CommentStmt);
    7072             : 
    7073          40 :                     n->objtype = OBJECT_AGGREGATE;
    7074          40 :                     n->object = (Node *) $4;
    7075          40 :                     n->comment = $6;
    7076          40 :                     $$ = (Node *) n;
    7077             :                 }
    7078             :             | COMMENT ON FUNCTION function_with_argtypes IS comment_text
    7079             :                 {
    7080         170 :                     CommentStmt *n = makeNode(CommentStmt);
    7081             : 
    7082         170 :                     n->objtype = OBJECT_FUNCTION;
    7083         170 :                     n->object = (Node *) $4;
    7084         170 :                     n->comment = $6;
    7085         170 :                     $$ = (Node *) n;
    7086             :                 }
    7087             :             | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
    7088             :                 {
    7089          18 :                     CommentStmt *n = makeNode(CommentStmt);
    7090             : 
    7091          18 :                     n->objtype = OBJECT_OPERATOR;
    7092          18 :                     n->object = (Node *) $4;
    7093          18 :                     n->comment = $6;
    7094          18 :                     $$ = (Node *) n;
    7095             :                 }
    7096             :             | COMMENT ON CONSTRAINT name ON any_name IS comment_text
    7097             :                 {
    7098         104 :                     CommentStmt *n = makeNode(CommentStmt);
    7099             : 
    7100         104 :                     n->objtype = OBJECT_TABCONSTRAINT;
    7101         104 :                     n->object = (Node *) lappend($6, makeString($4));
    7102         104 :                     n->comment = $8;
    7103         104 :                     $$ = (Node *) n;
    7104             :                 }
    7105             :             | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
    7106             :                 {
    7107          38 :                     CommentStmt *n = makeNode(CommentStmt);
    7108             : 
    7109          38 :                     n->objtype = OBJECT_DOMCONSTRAINT;
    7110             :                     /*
    7111             :                      * should use Typename not any_name in the production, but
    7112             :                      * there's a shift/reduce conflict if we do that, so fix it
    7113             :                      * up here.
    7114             :                      */
    7115          38 :                     n->object = (Node *) list_make2(makeTypeNameFromNameList($7), makeString($4));
    7116          38 :                     n->comment = $9;
    7117          38 :                     $$ = (Node *) n;
    7118             :                 }
    7119             :             | COMMENT ON object_type_name_on_any_name name ON any_name IS comment_text
    7120             :                 {
    7121          40 :                     CommentStmt *n = makeNode(CommentStmt);
    7122             : 
    7123          40 :                     n->objtype = $3;
    7124          40 :                     n->object = (Node *) lappend($6, makeString($4));
    7125          40 :                     n->comment = $8;
    7126          40 :                     $$ = (Node *) n;
    7127             :                 }
    7128             :             | COMMENT ON PROCEDURE function_with_argtypes IS comment_text
    7129             :                 {
    7130           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7131             : 
    7132           0 :                     n->objtype = OBJECT_PROCEDURE;
    7133           0 :                     n->object = (Node *) $4;
    7134           0 :                     n->comment = $6;
    7135           0 :                     $$ = (Node *) n;
    7136             :                 }
    7137             :             | COMMENT ON ROUTINE function_with_argtypes IS comment_text
    7138             :                 {
    7139           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7140             : 
    7141           0 :                     n->objtype = OBJECT_ROUTINE;
    7142           0 :                     n->object = (Node *) $4;
    7143           0 :                     n->comment = $6;
    7144           0 :                     $$ = (Node *) n;
    7145             :                 }
    7146             :             | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
    7147             :                 {
    7148          14 :                     CommentStmt *n = makeNode(CommentStmt);
    7149             : 
    7150          14 :                     n->objtype = OBJECT_TRANSFORM;
    7151          14 :                     n->object = (Node *) list_make2($5, makeString($7));
    7152          14 :                     n->comment = $9;
    7153          14 :                     $$ = (Node *) n;
    7154             :                 }
    7155             :             | COMMENT ON OPERATOR CLASS any_name USING name IS comment_text
    7156             :                 {
    7157           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7158             : 
    7159           0 :                     n->objtype = OBJECT_OPCLASS;
    7160           0 :                     n->object = (Node *) lcons(makeString($7), $5);
    7161           0 :                     n->comment = $9;
    7162           0 :                     $$ = (Node *) n;
    7163             :                 }
    7164             :             | COMMENT ON OPERATOR FAMILY any_name USING name IS comment_text
    7165             :                 {
    7166           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7167             : 
    7168           0 :                     n->objtype = OBJECT_OPFAMILY;
    7169           0 :                     n->object = (Node *) lcons(makeString($7), $5);
    7170           0 :                     n->comment = $9;
    7171           0 :                     $$ = (Node *) n;
    7172             :                 }
    7173             :             | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
    7174             :                 {
    7175          24 :                     CommentStmt *n = makeNode(CommentStmt);
    7176             : 
    7177          24 :                     n->objtype = OBJECT_LARGEOBJECT;
    7178          24 :                     n->object = (Node *) $5;
    7179          24 :                     n->comment = $7;
    7180          24 :                     $$ = (Node *) n;
    7181             :                 }
    7182             :             | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
    7183             :                 {
    7184           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7185             : 
    7186           0 :                     n->objtype = OBJECT_CAST;
    7187           0 :                     n->object = (Node *) list_make2($5, $7);
    7188           0 :                     n->comment = $10;
    7189           0 :                     $$ = (Node *) n;
    7190             :                 }
    7191             :         ;
    7192             : 
    7193             : comment_text:
    7194        5444 :             Sconst                              { $$ = $1; }
    7195         104 :             | NULL_P                            { $$ = NULL; }
    7196             :         ;
    7197             : 
    7198             : 
    7199             : /*****************************************************************************
    7200             :  *
    7201             :  *  SECURITY LABEL [FOR <provider>] ON <object> IS <label>
    7202             :  *
    7203             :  *  As with COMMENT ON, <object> can refer to various types of database
    7204             :  *  objects (e.g. TABLE, COLUMN, etc.).
    7205             :  *
    7206             :  *****************************************************************************/
    7207             : 
    7208             : SecLabelStmt:
    7209             :             SECURITY LABEL opt_provider ON object_type_any_name any_name
    7210             :             IS security_label
    7211             :                 {
    7212          48 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7213             : 
    7214          48 :                     n->provider = $3;
    7215          48 :                     n->objtype = $5;
    7216          48 :                     n->object = (Node *) $6;
    7217          48 :                     n->label = $8;
    7218          48 :                     $$ = (Node *) n;
    7219             :                 }
    7220             :             | SECURITY LABEL opt_provider ON COLUMN any_name
    7221             :               IS security_label
    7222             :                 {
    7223           4 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7224             : 
    7225           4 :                     n->provider = $3;
    7226           4 :                     n->objtype = OBJECT_COLUMN;
    7227           4 :                     n->object = (Node *) $6;
    7228           4 :                     n->label = $8;
    7229           4 :                     $$ = (Node *) n;
    7230             :                 }
    7231             :             | SECURITY LABEL opt_provider ON object_type_name name
    7232             :               IS security_label
    7233             :                 {
    7234          44 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7235             : 
    7236          44 :                     n->provider = $3;
    7237          44 :                     n->objtype = $5;
    7238          44 :                     n->object = (Node *) makeString($6);
    7239          44 :                     n->label = $8;
    7240          44 :                     $$ = (Node *) n;
    7241             :                 }
    7242             :             | SECURITY LABEL opt_provider ON TYPE_P Typename
    7243             :               IS security_label
    7244             :                 {
    7245           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7246             : 
    7247           0 :                     n->provider = $3;
    7248           0 :                     n->objtype = OBJECT_TYPE;
    7249           0 :                     n->object = (Node *) $6;
    7250           0 :                     n->label = $8;
    7251           0 :                     $$ = (Node *) n;
    7252             :                 }
    7253             :             | SECURITY LABEL opt_provider ON DOMAIN_P Typename
    7254             :               IS security_label
    7255             :                 {
    7256           2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7257             : 
    7258           2 :                     n->provider = $3;
    7259           2 :                     n->objtype = OBJECT_DOMAIN;
    7260           2 :                     n->object = (Node *) $6;
    7261           2 :                     n->label = $8;
    7262           2 :                     $$ = (Node *) n;
    7263             :                 }
    7264             :             | SECURITY LABEL opt_provider ON AGGREGATE aggregate_with_argtypes
    7265             :               IS security_label
    7266             :                 {
    7267           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7268             : 
    7269           0 :                     n->provider = $3;
    7270           0 :                     n->objtype = OBJECT_AGGREGATE;
    7271           0 :                     n->object = (Node *) $6;
    7272           0 :                     n->label = $8;
    7273           0 :                     $$ = (Node *) n;
    7274             :                 }
    7275             :             | SECURITY LABEL opt_provider ON FUNCTION function_with_argtypes
    7276             :               IS security_label
    7277             :                 {
    7278           2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7279             : 
    7280           2 :                     n->provider = $3;
    7281           2 :                     n->objtype = OBJECT_FUNCTION;
    7282           2 :                     n->object = (Node *) $6;
    7283           2 :                     n->label = $8;
    7284           2 :                     $$ = (Node *) n;
    7285             :                 }
    7286             :             | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
    7287             :               IS security_label
    7288             :                 {
    7289           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7290             : 
    7291           0 :                     n->provider = $3;
    7292           0 :                     n->objtype = OBJECT_LARGEOBJECT;
    7293           0 :                     n->object = (Node *) $7;
    7294           0 :                     n->label = $9;
    7295           0 :                     $$ = (Node *) n;
    7296             :                 }
    7297             :             | SECURITY LABEL opt_provider ON PROCEDURE function_with_argtypes
    7298             :               IS security_label
    7299             :                 {
    7300           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7301             : 
    7302           0 :                     n->provider = $3;
    7303           0 :                     n->objtype = OBJECT_PROCEDURE;
    7304           0 :                     n->object = (Node *) $6;
    7305           0 :                     n->label = $8;
    7306           0 :                     $$ = (Node *) n;
    7307             :                 }
    7308             :             | SECURITY LABEL opt_provider ON ROUTINE function_with_argtypes
    7309             :               IS security_label
    7310             :                 {
    7311           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7312             : 
    7313           0 :                     n->provider = $3;
    7314           0 :                     n->objtype = OBJECT_ROUTINE;
    7315           0 :                     n->object = (Node *) $6;
    7316           0 :                     n->label = $8;
    7317           0 :                     $$ = (Node *) n;
    7318             :                 }
    7319             :         ;
    7320             : 
    7321          20 : opt_provider:   FOR NonReservedWord_or_Sconst   { $$ = $2; }
    7322          80 :                 | /* EMPTY */                   { $$ = NULL; }
    7323             :         ;
    7324             : 
    7325         100 : security_label: Sconst              { $$ = $1; }
    7326           0 :                 | NULL_P            { $$ = NULL; }
    7327             :         ;
    7328             : 
    7329             : /*****************************************************************************
    7330             :  *
    7331             :  *      QUERY:
    7332             :  *          fetch/move
    7333             :  *
    7334             :  *****************************************************************************/
    7335             : 
    7336             : FetchStmt:  FETCH fetch_args
    7337             :                 {
    7338        5850 :                     FetchStmt *n = (FetchStmt *) $2;
    7339             : 
    7340        5850 :                     n->ismove = false;
    7341        5850 :                     $$ = (Node *) n;
    7342             :                 }
    7343             :             | MOVE fetch_args
    7344             :                 {
    7345         104 :                     FetchStmt *n = (FetchStmt *) $2;
    7346             : 
    7347         104 :                     n->ismove = true;
    7348         104 :                     $$ = (Node *) n;
    7349             :                 }
    7350             :         ;
    7351             : 
    7352             : fetch_args: cursor_name
    7353             :                 {
    7354         266 :                     FetchStmt *n = makeNode(FetchStmt);
    7355             : 
    7356         266 :                     n->portalname = $1;
    7357         266 :                     n->direction = FETCH_FORWARD;
    7358         266 :                     n->howMany = 1;
    7359         266 :                     $$ = (Node *) n;
    7360             :                 }
    7361             :             | from_in cursor_name
    7362             :                 {
    7363         210 :                     FetchStmt *n = makeNode(FetchStmt);
    7364             : 
    7365         210 :                     n->portalname = $2;
    7366         210 :                     n->direction = FETCH_FORWARD;
    7367         210 :                     n->howMany = 1;
    7368         210 :                     $$ = (Node *) n;
    7369             :                 }
    7370             :             | NEXT opt_from_in cursor_name
    7371             :                 {
    7372         262 :                     FetchStmt *n = makeNode(FetchStmt);
    7373             : 
    7374         262 :                     n->portalname = $3;
    7375         262 :                     n->direction = FETCH_FORWARD;
    7376         262 :                     n->howMany = 1;
    7377         262 :                     $$ = (Node *) n;
    7378             :                 }
    7379             :             | PRIOR opt_from_in cursor_name
    7380             :                 {
    7381          30 :                     FetchStmt *n = makeNode(FetchStmt);
    7382             : 
    7383          30 :                     n->portalname = $3;
    7384          30 :                     n->direction = FETCH_BACKWARD;
    7385          30 :                     n->howMany = 1;
    7386          30 :                     $$ = (Node *) n;
    7387             :                 }
    7388             :             | FIRST_P opt_from_in cursor_name
    7389             :                 {
    7390          24 :                     FetchStmt *n = makeNode(FetchStmt);
    7391             : 
    7392          24 :                     n->portalname = $3;
    7393          24 :                     n->direction = FETCH_ABSOLUTE;
    7394          24 :                     n->howMany = 1;
    7395          24 :                     $$ = (Node *) n;
    7396             :                 }
    7397             :             | LAST_P opt_from_in cursor_name
    7398             :                 {
    7399          18 :                     FetchStmt *n = makeNode(FetchStmt);
    7400             : 
    7401          18 :                     n->portalname = $3;
    7402          18 :                     n->direction = FETCH_ABSOLUTE;
    7403          18 :                     n->howMany = -1;
    7404          18 :                     $$ = (Node *) n;
    7405             :                 }
    7406             :             | ABSOLUTE_P SignedIconst opt_from_in cursor_name
    7407             :                 {
    7408          88 :                     FetchStmt *n = makeNode(FetchStmt);
    7409             : 
    7410          88 :                     n->portalname = $4;
    7411          88 :                     n->direction = FETCH_ABSOLUTE;
    7412          88 :                     n->howMany = $2;
    7413          88 :                     $$ = (Node *) n;
    7414             :                 }
    7415             :             | RELATIVE_P SignedIconst opt_from_in cursor_name
    7416             :                 {
    7417          30 :                     FetchStmt *n = makeNode(FetchStmt);
    7418             : 
    7419          30 :                     n->portalname = $4;
    7420          30 :                     n->direction = FETCH_RELATIVE;
    7421          30 :                     n->howMany = $2;
    7422          30 :                     $$ = (Node *) n;
    7423             :                 }
    7424             :             | SignedIconst opt_from_in cursor_name
    7425             :                 {
    7426        4142 :                     FetchStmt *n = makeNode(FetchStmt);
    7427             : 
    7428        4142 :                     n->portalname = $3;
    7429        4142 :                     n->direction = FETCH_FORWARD;
    7430        4142 :                     n->howMany = $1;
    7431        4142 :                     $$ = (Node *) n;
    7432             :                 }
    7433             :             | ALL opt_from_in cursor_name
    7434             :                 {
    7435         266 :                     FetchStmt *n = makeNode(FetchStmt);
    7436             : 
    7437         266 :                     n->portalname = $3;
    7438         266 :                     n->direction = FETCH_FORWARD;
    7439         266 :                     n->howMany = FETCH_ALL;
    7440         266 :                     $$ = (Node *) n;
    7441             :                 }
    7442             :             | FORWARD opt_from_in cursor_name
    7443             :                 {
    7444          28 :                     FetchStmt *n = makeNode(FetchStmt);
    7445             : 
    7446          28 :                     n->portalname = $3;
    7447          28 :                     n->direction = FETCH_FORWARD;
    7448          28 :                     n->howMany = 1;
    7449          28 :                     $$ = (Node *) n;
    7450             :                 }
    7451             :             | FORWARD SignedIconst opt_from_in cursor_name
    7452             :                 {
    7453         152 :                     FetchStmt *n = makeNode(FetchStmt);
    7454             : 
    7455         152 :                     n->portalname = $4;
    7456         152 :                     n->direction = FETCH_FORWARD;
    7457         152 :                     n->howMany = $2;
    7458         152 :                     $$ = (Node *) n;
    7459             :                 }
    7460             :             | FORWARD ALL opt_from_in cursor_name
    7461             :                 {
    7462          14 :                     FetchStmt *n = makeNode(FetchStmt);
    7463             : 
    7464          14 :                     n->portalname = $4;
    7465          14 :                     n->direction = FETCH_FORWARD;
    7466          14 :                     n->howMany = FETCH_ALL;
    7467          14 :                     $$ = (Node *) n;
    7468             :                 }
    7469             :             | BACKWARD opt_from_in cursor_name
    7470             :                 {
    7471          78 :                     FetchStmt *n = makeNode(FetchStmt);
    7472             : 
    7473          78 :                     n->portalname = $3;
    7474          78 :                     n->direction = FETCH_BACKWARD;
    7475          78 :                     n->howMany = 1;
    7476          78 :                     $$ = (Node *) n;
    7477             :                 }
    7478             :             | BACKWARD SignedIconst opt_from_in cursor_name
    7479             :                 {
    7480         220 :                     FetchStmt *n = makeNode(FetchStmt);
    7481             : 
    7482         220 :                     n->portalname = $4;
    7483         220 :                     n->direction = FETCH_BACKWARD;
    7484         220 :                     n->howMany = $2;
    7485         220 :                     $$ = (Node *) n;
    7486             :                 }
    7487             :             | BACKWARD ALL opt_from_in cursor_name
    7488             :                 {
    7489         126 :                     FetchStmt *n = makeNode(FetchStmt);
    7490             : 
    7491         126 :                     n->portalname = $4;
    7492         126 :                     n->direction = FETCH_BACKWARD;
    7493         126 :                     n->howMany = FETCH_ALL;
    7494         126 :                     $$ = (Node *) n;
    7495             :                 }
    7496             :         ;
    7497             : 
    7498             : from_in:    FROM
    7499             :             | IN_P
    7500             :         ;
    7501             : 
    7502             : opt_from_in:    from_in
    7503             :             | /* EMPTY */
    7504             :         ;
    7505             : 
    7506             : 
    7507             : /*****************************************************************************
    7508             :  *
    7509             :  * GRANT and REVOKE statements
    7510             :  *
    7511             :  *****************************************************************************/
    7512             : 
    7513             : GrantStmt:  GRANT privileges ON privilege_target TO grantee_list
    7514             :             opt_grant_grant_option opt_granted_by
    7515             :                 {
    7516        8294 :                     GrantStmt *n = makeNode(GrantStmt);
    7517             : 
    7518        8294 :                     n->is_grant = true;
    7519        8294 :                     n->privileges = $2;
    7520        8294 :                     n->targtype = ($4)->targtype;
    7521        8294 :                     n->objtype = ($4)->objtype;
    7522        8294 :                     n->objects = ($4)->objs;
    7523        8294 :                     n->grantees = $6;
    7524        8294 :                     n->grant_option = $7;
    7525        8294 :                     n->grantor = $8;
    7526        8294 :                     $$ = (Node *) n;
    7527             :                 }
    7528             :         ;
    7529             : 
    7530             : RevokeStmt:
    7531             :             REVOKE privileges ON privilege_target
    7532             :             FROM grantee_list opt_granted_by opt_drop_behavior
    7533             :                 {
    7534        7074 :                     GrantStmt *n = makeNode(GrantStmt);
    7535             : 
    7536        7074 :                     n->is_grant = false;
    7537        7074 :                     n->grant_option = false;
    7538        7074 :                     n->privileges = $2;
    7539        7074 :                     n->targtype = ($4)->targtype;
    7540        7074 :                     n->objtype = ($4)->objtype;
    7541        7074 :                     n->objects = ($4)->objs;
    7542        7074 :                     n->grantees = $6;
    7543        7074 :                     n->grantor = $7;
    7544        7074 :                     n->behavior = $8;
    7545        7074 :                     $$ = (Node *) n;
    7546             :                 }
    7547             :             | REVOKE GRANT OPTION FOR privileges ON privilege_target
    7548             :             FROM grantee_list opt_granted_by opt_drop_behavior
    7549             :                 {
    7550          14 :                     GrantStmt *n = makeNode(GrantStmt);
    7551             : 
    7552          14 :                     n->is_grant = false;
    7553          14 :                     n->grant_option = true;
    7554          14 :                     n->privileges = $5;
    7555          14 :                     n->targtype = ($7)->targtype;
    7556          14 :                     n->objtype = ($7)->objtype;
    7557          14 :                     n->objects = ($7)->objs;
    7558          14 :                     n->grantees = $9;
    7559          14 :                     n->grantor = $10;
    7560          14 :                     n->behavior = $11;
    7561          14 :                     $$ = (Node *) n;
    7562             :                 }
    7563             :         ;
    7564             : 
    7565             : 
    7566             : /*
    7567             :  * Privilege names are represented as strings; the validity of the privilege
    7568             :  * names gets checked at execution.  This is a bit annoying but we have little
    7569             :  * choice because of the syntactic conflict with lists of role names in
    7570             :  * GRANT/REVOKE.  What's more, we have to call out in the "privilege"
    7571             :  * production any reserved keywords that need to be usable as privilege names.
    7572             :  */
    7573             : 
    7574             : /* either ALL [PRIVILEGES] or a list of individual privileges */
    7575             : privileges: privilege_list
    7576       13422 :                 { $$ = $1; }
    7577             :             | ALL
    7578        1994 :                 { $$ = NIL; }
    7579             :             | ALL PRIVILEGES
    7580         120 :                 { $$ = NIL; }
    7581             :             | ALL '(' columnList ')'
    7582             :                 {
    7583          18 :                     AccessPriv *n = makeNode(AccessPriv);
    7584             : 
    7585          18 :                     n->priv_name = NULL;
    7586          18 :                     n->cols = $3;
    7587          18 :                     $$ = list_make1(n);
    7588             :                 }
    7589             :             | ALL PRIVILEGES '(' columnList ')'
    7590             :                 {
    7591           0 :                     AccessPriv *n = makeNode(AccessPriv);
    7592             : 
    7593           0 :                     n->priv_name = NULL;
    7594           0 :                     n->cols = $4;
    7595           0 :                     $$ = list_make1(n);
    7596             :                 }
    7597             :         ;
    7598             : 
    7599       14312 : privilege_list: privilege                           { $$ = list_make1($1); }
    7600         444 :             | privilege_list ',' privilege          { $$ = lappend($1, $3); }
    7601             :         ;
    7602             : 
    7603             : privilege:  SELECT opt_column_list
    7604             :             {
    7605        5926 :                 AccessPriv *n = makeNode(AccessPriv);
    7606             : 
    7607        5926 :                 n->priv_name = pstrdup($1);
    7608        5926 :                 n->cols = $2;
    7609        5926 :                 $$ = n;
    7610             :             }
    7611             :         | REFERENCES opt_column_list
    7612             :             {
    7613          14 :                 AccessPriv *n = makeNode(AccessPriv);
    7614             : 
    7615          14 :                 n->priv_name = pstrdup($1);
    7616          14 :                 n->cols = $2;
    7617          14 :                 $$ = n;
    7618             :             }
    7619             :         | CREATE opt_column_list
    7620             :             {
    7621         250 :                 AccessPriv *n = makeNode(AccessPriv);
    7622             : 
    7623         250 :                 n->priv_name = pstrdup($1);
    7624         250 :                 n->cols = $2;
    7625         250 :                 $$ = n;
    7626             :             }
    7627             :         | ALTER SYSTEM_P
    7628             :             {
    7629          24 :                 AccessPriv *n = makeNode(AccessPriv);
    7630          24 :                 n->priv_name = pstrdup("alter system");
    7631          24 :                 n->cols = NIL;
    7632          24 :                 $$ = n;
    7633             :             }
    7634             :         | ColId opt_column_list
    7635             :             {
    7636        8542 :                 AccessPriv *n = makeNode(AccessPriv);
    7637             : 
    7638        8542 :                 n->priv_name = $1;
    7639        8542 :                 n->cols = $2;
    7640        8542 :                 $$ = n;
    7641             :             }
    7642             :         ;
    7643             : 
    7644             : parameter_name_list:
    7645             :         parameter_name
    7646             :             {
    7647          74 :                 $$ = list_make1(makeString($1));
    7648             :             }
    7649             :         | parameter_name_list ',' parameter_name
    7650             :             {
    7651          50 :                 $$ = lappend($1, makeString($3));
    7652             :             }
    7653             :         ;
    7654             : 
    7655             : parameter_name:
    7656             :         ColId
    7657             :             {
    7658         124 :                 $$ = $1;
    7659             :             }
    7660             :         | parameter_name '.' ColId
    7661             :             {
    7662          30 :                 $$ = psprintf("%s.%s", $1, $3);
    7663             :             }
    7664             :         ;
    7665             : 
    7666             : 
    7667             : /* Don't bother trying to fold the first two rules into one using
    7668             :  * opt_table.  You're going to get conflicts.
    7669             :  */
    7670             : privilege_target:
    7671             :             qualified_name_list
    7672             :                 {
    7673        7460 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7674             : 
    7675        7460 :                     n->targtype = ACL_TARGET_OBJECT;
    7676        7460 :                     n->objtype = OBJECT_TABLE;
    7677        7460 :                     n->objs = $1;
    7678        7460 :                     $$ = n;
    7679             :                 }
    7680             :             | TABLE qualified_name_list
    7681             :                 {
    7682         324 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7683             : 
    7684         324 :                     n->targtype = ACL_TARGET_OBJECT;
    7685         324 :                     n->objtype = OBJECT_TABLE;
    7686         324 :                     n->objs = $2;
    7687         324 :                     $$ = n;
    7688             :                 }
    7689             :             | SEQUENCE qualified_name_list
    7690             :                 {
    7691          16 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7692             : 
    7693          16 :                     n->targtype = ACL_TARGET_OBJECT;
    7694          16 :                     n->objtype = OBJECT_SEQUENCE;
    7695          16 :                     n->objs = $2;
    7696          16 :                     $$ = n;
    7697             :                 }
    7698             :             | FOREIGN DATA_P WRAPPER name_list
    7699             :                 {
    7700          92 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7701             : 
    7702          92 :                     n->targtype = ACL_TARGET_OBJECT;
    7703          92 :                     n->objtype = OBJECT_FDW;
    7704          92 :                     n->objs = $4;
    7705          92 :                     $$ = n;
    7706             :                 }
    7707             :             | FOREIGN SERVER name_list
    7708             :                 {
    7709          76 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7710             : 
    7711          76 :                     n->targtype = ACL_TARGET_OBJECT;
    7712          76 :                     n->objtype = OBJECT_FOREIGN_SERVER;
    7713          76 :                     n->objs = $3;
    7714          76 :                     $$ = n;
    7715             :                 }
    7716             :             | FUNCTION function_with_argtypes_list
    7717             :                 {
    7718        6462 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7719             : 
    7720        6462 :                     n->targtype = ACL_TARGET_OBJECT;
    7721        6462 :                     n->objtype = OBJECT_FUNCTION;
    7722        6462 :                     n->objs = $2;
    7723        6462 :                     $$ = n;
    7724             :                 }
    7725             :             | PROCEDURE function_with_argtypes_list
    7726             :                 {
    7727          42 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7728             : 
    7729          42 :                     n->targtype = ACL_TARGET_OBJECT;
    7730          42 :                     n->objtype = OBJECT_PROCEDURE;
    7731          42 :                     n->objs = $2;
    7732          42 :                     $$ = n;
    7733             :                 }
    7734             :             | ROUTINE function_with_argtypes_list
    7735             :                 {
    7736           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7737             : 
    7738           0 :                     n->targtype = ACL_TARGET_OBJECT;
    7739           0 :                     n->objtype = OBJECT_ROUTINE;
    7740           0 :                     n->objs = $2;
    7741           0 :                     $$ = n;
    7742             :                 }
    7743             :             | DATABASE name_list
    7744             :                 {
    7745         274 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7746             : 
    7747         274 :                     n->targtype = ACL_TARGET_OBJECT;
    7748         274 :                     n->objtype = OBJECT_DATABASE;
    7749         274 :                     n->objs = $2;
    7750         274 :                     $$ = n;
    7751             :                 }
    7752             :             | DOMAIN_P any_name_list
    7753             :                 {
    7754          26 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7755             : 
    7756          26 :                     n->targtype = ACL_TARGET_OBJECT;
    7757          26 :                     n->objtype = OBJECT_DOMAIN;
    7758          26 :                     n->objs = $2;
    7759          26 :                     $$ = n;
    7760             :                 }
    7761             :             | LANGUAGE name_list
    7762             :                 {
    7763          42 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7764             : 
    7765          42 :                     n->targtype = ACL_TARGET_OBJECT;
    7766          42 :                     n->objtype = OBJECT_LANGUAGE;
    7767          42 :                     n->objs = $2;
    7768          42 :                     $$ = n;
    7769             :                 }
    7770             :             | LARGE_P OBJECT_P NumericOnly_list
    7771             :                 {
    7772          80 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7773             : 
    7774          80 :                     n->targtype = ACL_TARGET_OBJECT;
    7775          80 :                     n->objtype = OBJECT_LARGEOBJECT;
    7776          80 :                     n->objs = $3;
    7777          80 :                     $$ = n;
    7778             :                 }
    7779             :             | PARAMETER parameter_name_list
    7780             :                 {
    7781          74 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7782          74 :                     n->targtype = ACL_TARGET_OBJECT;
    7783          74 :                     n->objtype = OBJECT_PARAMETER_ACL;
    7784          74 :                     n->objs = $2;
    7785          74 :                     $$ = n;
    7786             :                 }
    7787             :             | SCHEMA name_list
    7788             :                 {
    7789         286 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7790             : 
    7791         286 :                     n->targtype = ACL_TARGET_OBJECT;
    7792         286 :                     n->objtype = OBJECT_SCHEMA;
    7793         286 :                     n->objs = $2;
    7794         286 :                     $$ = n;
    7795             :                 }
    7796             :             | TABLESPACE name_list
    7797             :                 {
    7798           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7799             : 
    7800           0 :                     n->targtype = ACL_TARGET_OBJECT;
    7801           0 :                     n->objtype = OBJECT_TABLESPACE;
    7802           0 :                     n->objs = $2;
    7803           0 :                     $$ = n;
    7804             :                 }
    7805             :             | TYPE_P any_name_list
    7806             :                 {
    7807         110 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7808             : 
    7809         110 :                     n->targtype = ACL_TARGET_OBJECT;
    7810         110 :                     n->objtype = OBJECT_TYPE;
    7811         110 :                     n->objs = $2;
    7812         110 :                     $$ = n;
    7813             :                 }
    7814             :             | ALL TABLES IN_P SCHEMA name_list
    7815             :                 {
    7816          12 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7817             : 
    7818          12 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7819          12 :                     n->objtype = OBJECT_TABLE;
    7820          12 :                     n->objs = $5;
    7821          12 :                     $$ = n;
    7822             :                 }
    7823             :             | ALL SEQUENCES IN_P SCHEMA name_list
    7824             :                 {
    7825           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7826             : 
    7827           0 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7828           0 :                     n->objtype = OBJECT_SEQUENCE;
    7829           0 :                     n->objs = $5;
    7830           0 :                     $$ = n;
    7831             :                 }
    7832             :             | ALL FUNCTIONS IN_P SCHEMA name_list
    7833             :                 {
    7834           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7835             : 
    7836           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7837           6 :                     n->objtype = OBJECT_FUNCTION;
    7838           6 :                     n->objs = $5;
    7839           6 :                     $$ = n;
    7840             :                 }
    7841             :             | ALL PROCEDURES IN_P SCHEMA name_list
    7842             :                 {
    7843           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7844             : 
    7845           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7846           6 :                     n->objtype = OBJECT_PROCEDURE;
    7847           6 :                     n->objs = $5;
    7848           6 :                     $$ = n;
    7849             :                 }
    7850             :             | ALL ROUTINES IN_P SCHEMA name_list
    7851             :                 {
    7852           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7853             : 
    7854           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7855           6 :                     n->objtype = OBJECT_ROUTINE;
    7856           6 :                     n->objs = $5;
    7857           6 :                     $$ = n;
    7858             :                 }
    7859             :         ;
    7860             : 
    7861             : 
    7862             : grantee_list:
    7863       15542 :             grantee                                 { $$ = list_make1($1); }
    7864         102 :             | grantee_list ',' grantee              { $$ = lappend($1, $3); }
    7865             :         ;
    7866             : 
    7867             : grantee:
    7868       15620 :             RoleSpec                                { $$ = $1; }
    7869          24 :             | GROUP_P RoleSpec                      { $$ = $2; }
    7870             :         ;
    7871             : 
    7872             : 
    7873             : opt_grant_grant_option:
    7874          86 :             WITH GRANT OPTION { $$ = true; }
    7875        8308 :             | /*EMPTY*/ { $$ = false; }
    7876             :         ;
    7877             : 
    7878             : /*****************************************************************************
    7879             :  *
    7880             :  * GRANT and REVOKE ROLE statements
    7881             :  *
    7882             :  *****************************************************************************/
    7883             : 
    7884             : GrantRoleStmt:
    7885             :             GRANT privilege_list TO role_list opt_granted_by
    7886             :                 {
    7887         556 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    7888             : 
    7889         556 :                     n->is_grant = true;
    7890         556 :                     n->granted_roles = $2;
    7891         556 :                     n->grantee_roles = $4;
    7892         556 :                     n->opt = NIL;
    7893         556 :                     n->grantor = $5;
    7894         556 :                     $$ = (Node *) n;
    7895             :                 }
    7896             :           | GRANT privilege_list TO role_list WITH grant_role_opt_list opt_granted_by
    7897             :                 {
    7898         178 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    7899             : 
    7900         178 :                     n->is_grant = true;
    7901         178 :                     n->granted_roles = $2;
    7902         178 :                     n->grantee_roles = $4;
    7903         178 :                     n->opt = $6;
    7904         178 :                     n->grantor = $7;
    7905         178 :                     $$ = (Node *) n;
    7906             :                 }
    7907             :         ;
    7908             : 
    7909             : RevokeRoleStmt:
    7910             :             REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
    7911             :                 {
    7912          90 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    7913             : 
    7914          90 :                     n->is_grant = false;
    7915          90 :                     n->opt = NIL;
    7916          90 :                     n->granted_roles = $2;
    7917          90 :                     n->grantee_roles = $4;
    7918          90 :                     n->grantor = $5;
    7919          90 :                     n->behavior = $6;
    7920          90 :                     $$ = (Node *) n;
    7921             :                 }
    7922             :             | REVOKE ColId OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
    7923             :                 {
    7924          66 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    7925             :                     DefElem *opt;
    7926             : 
    7927          66 :                     opt = makeDefElem(pstrdup($2),
    7928          66 :                                       (Node *) makeBoolean(false), @2);
    7929          66 :                     n->is_grant = false;
    7930          66 :                     n->opt = list_make1(opt);
    7931          66 :                     n->granted_roles = $5;
    7932          66 :                     n->grantee_roles = $7;
    7933          66 :                     n->grantor = $8;
    7934          66 :                     n->behavior = $9;
    7935          66 :                     $$ = (Node *) n;
    7936             :                 }
    7937             :         ;
    7938             : 
    7939             : grant_role_opt_list:
    7940         120 :             grant_role_opt_list ',' grant_role_opt  { $$ = lappend($1, $3); }
    7941         178 :             | grant_role_opt                        { $$ = list_make1($1); }
    7942             :         ;
    7943             : 
    7944             : grant_role_opt:
    7945             :         ColLabel grant_role_opt_value
    7946             :             {
    7947         298 :                 $$ = makeDefElem(pstrdup($1), $2, @1);
    7948             :             }
    7949             :         ;
    7950             : 
    7951             : grant_role_opt_value:
    7952          72 :         OPTION          { $$ = (Node *) makeBoolean(true); }
    7953         112 :         | TRUE_P        { $$ = (Node *) makeBoolean(true); }
    7954         114 :         | FALSE_P       { $$ = (Node *) makeBoolean(false); }
    7955             :         ;
    7956             : 
    7957         138 : opt_granted_by: GRANTED BY RoleSpec                     { $$ = $3; }
    7958       16134 :             | /*EMPTY*/                                 { $$ = NULL; }
    7959             :         ;
    7960             : 
    7961             : /*****************************************************************************
    7962             :  *
    7963             :  * ALTER DEFAULT PRIVILEGES statement
    7964             :  *
    7965             :  *****************************************************************************/
    7966             : 
    7967             : AlterDefaultPrivilegesStmt:
    7968             :             ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
    7969             :                 {
    7970         160 :                     AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
    7971             : 
    7972         160 :                     n->options = $4;
    7973         160 :                     n->action = (GrantStmt *) $5;
    7974         160 :                     $$ = (Node *) n;
    7975             :                 }
    7976             :         ;
    7977             : 
    7978             : DefACLOptionList:
    7979         122 :             DefACLOptionList DefACLOption           { $$ = lappend($1, $2); }
    7980         160 :             | /* EMPTY */                           { $$ = NIL; }
    7981             :         ;
    7982             : 
    7983             : DefACLOption:
    7984             :             IN_P SCHEMA name_list
    7985             :                 {
    7986          54 :                     $$ = makeDefElem("schemas", (Node *) $3, @1);
    7987             :                 }
    7988             :             | FOR ROLE role_list
    7989             :                 {
    7990          68 :                     $$ = makeDefElem("roles", (Node *) $3, @1);
    7991             :                 }
    7992             :             | FOR USER role_list
    7993             :                 {
    7994           0 :                     $$ = makeDefElem("roles", (Node *) $3, @1);
    7995             :                 }
    7996             :         ;
    7997             : 
    7998             : /*
    7999             :  * This should match GRANT/REVOKE, except that individual target objects
    8000             :  * are not mentioned and we only allow a subset of object types.
    8001             :  */
    8002             : DefACLAction:
    8003             :             GRANT privileges ON defacl_privilege_target TO grantee_list
    8004             :             opt_grant_grant_option
    8005             :                 {
    8006         100 :                     GrantStmt *n = makeNode(GrantStmt);
    8007             : 
    8008         100 :                     n->is_grant = true;
    8009         100 :                     n->privileges = $2;
    8010         100 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8011         100 :                     n->objtype = $4;
    8012         100 :                     n->objects = NIL;
    8013         100 :                     n->grantees = $6;
    8014         100 :                     n->grant_option = $7;
    8015         100 :                     $$ = (Node *) n;
    8016             :                 }
    8017             :             | REVOKE privileges ON defacl_privilege_target
    8018             :             FROM grantee_list opt_drop_behavior
    8019             :                 {
    8020          60 :                     GrantStmt *n = makeNode(GrantStmt);
    8021             : 
    8022          60 :                     n->is_grant = false;
    8023          60 :                     n->grant_option = false;
    8024          60 :                     n->privileges = $2;
    8025          60 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8026          60 :                     n->objtype = $4;
    8027          60 :                     n->objects = NIL;
    8028          60 :                     n->grantees = $6;
    8029          60 :                     n->behavior = $7;
    8030          60 :                     $$ = (Node *) n;
    8031             :                 }
    8032             :             | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
    8033             :             FROM grantee_list opt_drop_behavior
    8034             :                 {
    8035           0 :                     GrantStmt *n = makeNode(GrantStmt);
    8036             : 
    8037           0 :                     n->is_grant = false;
    8038           0 :                     n->grant_option = true;
    8039           0 :                     n->privileges = $5;
    8040           0 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8041           0 :                     n->objtype = $7;
    8042           0 :                     n->objects = NIL;
    8043           0 :                     n->grantees = $9;
    8044           0 :                     n->behavior = $10;
    8045           0 :                     $$ = (Node *) n;
    8046             :                 }
    8047             :         ;
    8048             : 
    8049             : defacl_privilege_target:
    8050          78 :             TABLES          { $$ = OBJECT_TABLE; }
    8051          16 :             | FUNCTIONS     { $$ = OBJECT_FUNCTION; }
    8052           6 :             | ROUTINES      { $$ = OBJECT_FUNCTION; }
    8053           6 :             | SEQUENCES     { $$ = OBJECT_SEQUENCE; }
    8054          18 :             | TYPES_P       { $$ = OBJECT_TYPE; }
    8055          36 :             | SCHEMAS       { $$ = OBJECT_SCHEMA; }
    8056             :         ;
    8057             : 
    8058             : 
    8059             : /*****************************************************************************
    8060             :  *
    8061             :  *      QUERY: CREATE INDEX
    8062             :  *
    8063             :  * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
    8064             :  * willing to make TABLESPACE a fully reserved word.
    8065             :  *****************************************************************************/
    8066             : 
    8067             : IndexStmt:  CREATE opt_unique INDEX opt_concurrently opt_single_name
    8068             :             ON relation_expr access_method_clause '(' index_params ')'
    8069             :             opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
    8070             :                 {
    8071        6270 :                     IndexStmt *n = makeNode(IndexStmt);
    8072             : 
    8073        6270 :                     n->unique = $2;
    8074        6270 :                     n->concurrent = $4;
    8075        6270 :                     n->idxname = $5;
    8076        6270 :                     n->relation = $7;
    8077        6270 :                     n->accessMethod = $8;
    8078        6270 :                     n->indexParams = $10;
    8079        6270 :                     n->indexIncludingParams = $12;
    8080        6270 :                     n->nulls_not_distinct = !$13;
    8081        6270 :                     n->options = $14;
    8082        6270 :                     n->tableSpace = $15;
    8083        6270 :                     n->whereClause = $16;
    8084        6270 :                     n->excludeOpNames = NIL;
    8085        6270 :                     n->idxcomment = NULL;
    8086        6270 :                     n->indexOid = InvalidOid;
    8087        6270 :                     n->oldNumber = InvalidRelFileNumber;
    8088        6270 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8089        6270 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8090        6270 :                     n->primary = false;
    8091        6270 :                     n->isconstraint = false;
    8092        6270 :                     n->deferrable = false;
    8093        6270 :                     n->initdeferred = false;
    8094        6270 :                     n->transformed = false;
    8095        6270 :                     n->if_not_exists = false;
    8096        6270 :                     n->reset_default_tblspc = false;
    8097        6270 :                     $$ = (Node *) n;
    8098             :                 }
    8099             :             | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS name
    8100             :             ON relation_expr access_method_clause '(' index_params ')'
    8101             :             opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
    8102             :                 {
    8103          18 :                     IndexStmt *n = makeNode(IndexStmt);
    8104             : 
    8105          18 :                     n->unique = $2;
    8106          18 :                     n->concurrent = $4;
    8107          18 :                     n->idxname = $8;
    8108          18 :                     n->relation = $10;
    8109          18 :                     n->accessMethod = $11;
    8110          18 :                     n->indexParams = $13;
    8111          18 :                     n->indexIncludingParams = $15;
    8112          18 :                     n->nulls_not_distinct = !$16;
    8113          18 :                     n->options = $17;
    8114          18 :                     n->tableSpace = $18;
    8115          18 :                     n->whereClause = $19;
    8116          18 :                     n->excludeOpNames = NIL;
    8117          18 :                     n->idxcomment = NULL;
    8118          18 :                     n->indexOid = InvalidOid;
    8119          18 :                     n->oldNumber = InvalidRelFileNumber;
    8120          18 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8121          18 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8122          18 :                     n->primary = false;
    8123          18 :                     n->isconstraint = false;
    8124          18 :                     n->deferrable = false;
    8125          18 :                     n->initdeferred = false;
    8126          18 :                     n->transformed = false;
    8127          18 :                     n->if_not_exists = true;
    8128          18 :                     n->reset_default_tblspc = false;
    8129          18 :                     $$ = (Node *) n;
    8130             :                 }
    8131             :         ;
    8132             : 
    8133             : opt_unique:
    8134        1222 :             UNIQUE                                  { $$ = true; }
    8135        5072 :             | /*EMPTY*/                             { $$ = false; }
    8136             :         ;
    8137             : 
    8138             : access_method_clause:
    8139        2894 :             USING name                              { $$ = $2; }
    8140        3628 :             | /*EMPTY*/                             { $$ = DEFAULT_INDEX_TYPE; }
    8141             :         ;
    8142             : 
    8143        7550 : index_params:   index_elem                          { $$ = list_make1($1); }
    8144        1930 :             | index_params ',' index_elem           { $$ = lappend($1, $3); }
    8145             :         ;
    8146             : 
    8147             : 
    8148             : index_elem_options:
    8149             :     opt_collate opt_qualified_name opt_asc_desc opt_nulls_order
    8150             :         {
    8151       10060 :             $$ = makeNode(IndexElem);
    8152       10060 :             $$->name = NULL;
    8153       10060 :             $$->expr = NULL;
    8154       10060 :             $$->indexcolname = NULL;
    8155       10060 :             $$->collation = $1;
    8156       10060 :             $$->opclass = $2;
    8157       10060 :             $$->opclassopts = NIL;
    8158       10060 :             $$->ordering = $3;
    8159       10060 :             $$->nulls_ordering = $4;
    8160             :         }
    8161             :     | opt_collate any_name reloptions opt_asc_desc opt_nulls_order
    8162             :         {
    8163         138 :             $$ = makeNode(IndexElem);
    8164         138 :             $$->name = NULL;
    8165         138 :             $$->expr = NULL;
    8166         138 :             $$->indexcolname = NULL;
    8167         138 :             $$->collation = $1;
    8168         138 :             $$->opclass = $2;
    8169         138 :             $$->opclassopts = $3;
    8170         138 :             $$->ordering = $4;
    8171         138 :             $$->nulls_ordering = $5;
    8172             :         }
    8173             :     ;
    8174             : 
    8175             : /*
    8176             :  * Index attributes can be either simple column references, or arbitrary
    8177             :  * expressions in parens.  For backwards-compatibility reasons, we allow
    8178             :  * an expression that's just a function call to be written without parens.
    8179             :  */
    8180             : index_elem: ColId index_elem_options
    8181             :                 {
    8182        9166 :                     $$ = $2;
    8183        9166 :                     $$->name = $1;
    8184             :                 }
    8185             :             | func_expr_windowless index_elem_options
    8186             :                 {
    8187         568 :                     $$ = $2;
    8188         568 :                     $$->expr = $1;
    8189             :                 }
    8190             :             | '(' a_expr ')' index_elem_options
    8191             :                 {
    8192         464 :                     $$ = $4;
    8193         464 :                     $$->expr = $2;
    8194             :                 }
    8195             :         ;
    8196             : 
    8197         212 : opt_include:        INCLUDE '(' index_including_params ')'          { $$ = $3; }
    8198        6076 :              |      /* EMPTY */                     { $$ = NIL; }
    8199             :         ;
    8200             : 
    8201         212 : index_including_params: index_elem                      { $$ = list_make1($1); }
    8202         166 :             | index_including_params ',' index_elem     { $$ = lappend($1, $3); }
    8203             :         ;
    8204             : 
    8205         166 : opt_collate: COLLATE any_name                       { $$ = $2; }
    8206       15094 :             | /*EMPTY*/                             { $$ = NIL; }
    8207             :         ;
    8208             : 
    8209             : 
    8210        1736 : opt_asc_desc: ASC                           { $$ = SORTBY_ASC; }
    8211        2654 :             | DESC                          { $$ = SORTBY_DESC; }
    8212       90694 :             | /*EMPTY*/                     { $$ = SORTBY_DEFAULT; }
    8213             :         ;
    8214             : 
    8215         286 : opt_nulls_order: NULLS_LA FIRST_P           { $$ = SORTBY_NULLS_FIRST; }
    8216        1686 :             | NULLS_LA LAST_P               { $$ = SORTBY_NULLS_LAST; }
    8217       93332 :             | /*EMPTY*/                     { $$ = SORTBY_NULLS_DEFAULT; }
    8218             :         ;
    8219             : 
    8220             : 
    8221             : /*****************************************************************************
    8222             :  *
    8223             :  *      QUERY:
    8224             :  *              create [or replace] function <fname>
    8225             :  *                      [(<type-1> { , <type-n>})]
    8226             :  *                      returns <type-r>
    8227             :  *                      as <filename or code in language as appropriate>
    8228             :  *                      language <lang> [with parameters]
    8229             :  *
    8230             :  *****************************************************************************/
    8231             : 
    8232             : CreateFunctionStmt:
    8233             :             CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8234             :             RETURNS func_return opt_createfunc_opt_list opt_routine_body
    8235             :                 {
    8236       19474 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8237             : 
    8238       19474 :                     n->is_procedure = false;
    8239       19474 :                     n->replace = $2;
    8240       19474 :                     n->funcname = $4;
    8241       19474 :                     n->parameters = $5;
    8242       19474 :                     n->returnType = $7;
    8243       19474 :                     n->options = $8;
    8244       19474 :                     n->sql_body = $9;
    8245       19474 :                     $$ = (Node *) n;
    8246             :                 }
    8247             :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8248             :               RETURNS TABLE '(' table_func_column_list ')' opt_createfunc_opt_list opt_routine_body
    8249             :                 {
    8250         188 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8251             : 
    8252         188 :                     n->is_procedure = false;
    8253         188 :                     n->replace = $2;
    8254         188 :                     n->funcname = $4;
    8255         188 :                     n->parameters = mergeTableFuncParameters($5, $9);
    8256         188 :                     n->returnType = TableFuncTypeName($9);
    8257         188 :                     n->returnType->location = @7;
    8258         188 :                     n->options = $11;
    8259         188 :                     n->sql_body = $12;
    8260         188 :                     $$ = (Node *) n;
    8261             :                 }
    8262             :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8263             :               opt_createfunc_opt_list opt_routine_body
    8264             :                 {
    8265         472 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8266             : 
    8267         472 :                     n->is_procedure = false;
    8268         472 :                     n->replace = $2;
    8269         472 :                     n->funcname = $4;
    8270         472 :                     n->parameters = $5;
    8271         472 :                     n->returnType = NULL;
    8272         472 :                     n->options = $6;
    8273         472 :                     n->sql_body = $7;
    8274         472 :                     $$ = (Node *) n;
    8275             :                 }
    8276             :             | CREATE opt_or_replace PROCEDURE func_name func_args_with_defaults
    8277             :               opt_createfunc_opt_list opt_routine_body
    8278             :                 {
    8279         330 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8280             : 
    8281         330 :                     n->is_procedure = true;
    8282         330 :                     n->replace = $2;
    8283         330 :                     n->funcname = $4;
    8284         330 :                     n->parameters = $5;
    8285         330 :                     n->returnType = NULL;
    8286         330 :                     n->options = $6;
    8287         330 :                     n->sql_body = $7;
    8288         330 :                     $$ = (Node *) n;
    8289             :                 }
    8290             :         ;
    8291             : 
    8292             : opt_or_replace:
    8293        7946 :             OR REPLACE                              { $$ = true; }
    8294       17750 :             | /*EMPTY*/                             { $$ = false; }
    8295             :         ;
    8296             : 
    8297        8738 : func_args:  '(' func_args_list ')'                  { $$ = $2; }
    8298        4360 :             | '(' ')'                               { $$ = NIL; }
    8299             :         ;
    8300             : 
    8301             : func_args_list:
    8302        8738 :             func_arg                                { $$ = list_make1($1); }
    8303        7478 :             | func_args_list ',' func_arg           { $$ = lappend($1, $3); }
    8304             :         ;
    8305             : 
    8306             : function_with_argtypes_list:
    8307       10020 :             function_with_argtypes                  { $$ = list_make1($1); }
    8308             :             | function_with_argtypes_list ',' function_with_argtypes
    8309          72 :                                                     { $$ = lappend($1, $3); }
    8310             :         ;
    8311             : 
    8312             : function_with_argtypes:
    8313             :             func_name func_args
    8314             :                 {
    8315       13098 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8316             : 
    8317       13098 :                     n->objname = $1;
    8318       13098 :                     n->objargs = extractArgTypes($2);
    8319       13098 :                     n->objfuncargs = $2;
    8320       13098 :                     $$ = n;
    8321             :                 }
    8322             :             /*
    8323             :              * Because of reduce/reduce conflicts, we can't use func_name
    8324             :              * below, but we can write it out the long way, which actually
    8325             :              * allows more cases.
    8326             :              */
    8327             :             | type_func_name_keyword
    8328             :                 {
    8329           0 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8330             : 
    8331           0 :                     n->objname = list_make1(makeString(pstrdup($1)));
    8332           0 :                     n->args_unspecified = true;
    8333           0 :                     $$ = n;
    8334             :                 }
    8335             :             | ColId
    8336             :                 {
    8337         296 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8338             : 
    8339         296 :                     n->objname = list_make1(makeString($1));
    8340         296 :                     n->args_unspecified = true;
    8341         296 :                     $$ = n;
    8342             :                 }
    8343             :             | ColId indirection
    8344             :                 {
    8345          28 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8346             : 
    8347          28 :                     n->objname = check_func_name(lcons(makeString($1), $2),
    8348             :                                                   yyscanner);
    8349          28 :                     n->args_unspecified = true;
    8350          28 :                     $$ = n;
    8351             :                 }
    8352             :         ;
    8353             : 
    8354             : /*
    8355             :  * func_args_with_defaults is separate because we only want to accept
    8356             :  * defaults in CREATE FUNCTION, not in ALTER etc.
    8357             :  */
    8358             : func_args_with_defaults:
    8359       16418 :         '(' func_args_with_defaults_list ')'        { $$ = $2; }
    8360        4046 :         | '(' ')'                                   { $$ = NIL; }
    8361             :         ;
    8362             : 
    8363             : func_args_with_defaults_list:
    8364       16418 :         func_arg_with_default                       { $$ = list_make1($1); }
    8365             :         | func_args_with_defaults_list ',' func_arg_with_default
    8366       27068 :                                                     { $$ = lappend($1, $3); }
    8367             :         ;
    8368             : 
    8369             : /*
    8370             :  * The style with arg_class first is SQL99 standard, but Oracle puts
    8371             :  * param_name first; accept both since it's likely people will try both
    8372             :  * anyway.  Don't bother trying to save productions by letting arg_class
    8373             :  * have an empty alternative ... you'll get shift/reduce conflicts.
    8374             :  *
    8375             :  * We can catch over-specified arguments here if we want to,
    8376             :  * but for now better to silently swallow typmod, etc.
    8377             :  * - thomas 2000-03-22
    8378             :  */
    8379             : func_arg:
    8380             :             arg_class param_name func_type
    8381             :                 {
    8382       12376 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8383             : 
    8384       12376 :                     n->name = $2;
    8385       12376 :                     n->argType = $3;
    8386       12376 :                     n->mode = $1;
    8387       12376 :                     n->defexpr = NULL;
    8388       12376 :                     $$ = n;
    8389             :                 }
    8390             :             | param_name arg_class func_type
    8391             :                 {
    8392         380 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8393             : 
    8394         380 :                     n->name = $1;
    8395         380 :                     n->argType = $3;
    8396         380 :                     n->mode = $2;
    8397         380 :                     n->defexpr = NULL;
    8398         380 :                     $$ = n;
    8399             :                 }
    8400             :             | param_name func_type
    8401             :                 {
    8402       12448 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8403             : 
    8404       12448 :                     n->name = $1;
    8405       12448 :                     n->argType = $2;
    8406       12448 :                     n->mode = FUNC_PARAM_DEFAULT;
    8407       12448 :                     n->defexpr = NULL;
    8408       12448 :                     $$ = n;
    8409             :                 }
    8410             :             | arg_class func_type
    8411             :                 {
    8412         302 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8413             : 
    8414         302 :                     n->name = NULL;
    8415         302 :                     n->argType = $2;
    8416         302 :                     n->mode = $1;
    8417         302 :                     n->defexpr = NULL;
    8418         302 :                     $$ = n;
    8419             :                 }
    8420             :             | func_type
    8421             :                 {
    8422       35094 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8423             : 
    8424       35094 :                     n->name = NULL;
    8425       35094 :                     n->argType = $1;
    8426       35094 :                     n->mode = FUNC_PARAM_DEFAULT;
    8427       35094 :                     n->defexpr = NULL;
    8428       35094 :                     $$ = n;
    8429             :                 }
    8430             :         ;
    8431             : 
    8432             : /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
    8433        2840 : arg_class:  IN_P                                { $$ = FUNC_PARAM_IN; }
    8434        9566 :             | OUT_P                             { $$ = FUNC_PARAM_OUT; }
    8435         166 :             | INOUT                             { $$ = FUNC_PARAM_INOUT; }
    8436           0 :             | IN_P OUT_P                        { $$ = FUNC_PARAM_INOUT; }
    8437         486 :             | VARIADIC                          { $$ = FUNC_PARAM_VARIADIC; }
    8438             :         ;
    8439             : 
    8440             : /*
    8441             :  * Ideally param_name should be ColId, but that causes too many conflicts.
    8442             :  */
    8443             : param_name: type_function_name
    8444             :         ;
    8445             : 
    8446             : func_return:
    8447             :             func_type
    8448             :                 {
    8449             :                     /* We can catch over-specified results here if we want to,
    8450             :                      * but for now better to silently swallow typmod, etc.
    8451             :                      * - thomas 2000-03-22
    8452             :                      */
    8453       19474 :                     $$ = $1;
    8454             :                 }
    8455             :         ;
    8456             : 
    8457             : /*
    8458             :  * We would like to make the %TYPE productions here be ColId attrs etc,
    8459             :  * but that causes reduce/reduce conflicts.  type_function_name
    8460             :  * is next best choice.
    8461             :  */
    8462       99156 : func_type:  Typename                                { $$ = $1; }
    8463             :             | type_function_name attrs '%' TYPE_P
    8464             :                 {
    8465          18 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
    8466          18 :                     $$->pct_type = true;
    8467          18 :                     $$->location = @1;
    8468             :                 }
    8469             :             | SETOF type_function_name attrs '%' TYPE_P
    8470             :                 {
    8471           6 :                     $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
    8472           6 :                     $$->pct_type = true;
    8473           6 :                     $$->setof = true;
    8474           6 :                     $$->location = @2;
    8475             :                 }
    8476             :         ;
    8477             : 
    8478             : func_arg_with_default:
    8479             :         func_arg
    8480             :                 {
    8481       38600 :                     $$ = $1;
    8482             :                 }
    8483             :         | func_arg DEFAULT a_expr
    8484             :                 {
    8485        4690 :                     $$ = $1;
    8486        4690 :                     $$->defexpr = $3;
    8487             :                 }
    8488             :         | func_arg '=' a_expr
    8489             :                 {
    8490         196 :                     $$ = $1;
    8491         196 :                     $$->defexpr = $3;
    8492             :                 }
    8493             :         ;
    8494             : 
    8495             : /* Aggregate args can be most things that function args can be */
    8496             : aggr_arg:   func_arg
    8497             :                 {
    8498         898 :                     if (!($1->mode == FUNC_PARAM_DEFAULT ||
    8499          60 :                           $1->mode == FUNC_PARAM_IN ||
    8500          60 :                           $1->mode == FUNC_PARAM_VARIADIC))
    8501           0 :                         ereport(ERROR,
    8502             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    8503             :                                  errmsg("aggregates cannot have output arguments"),
    8504             :                                  parser_errposition(@1)));
    8505         898 :                     $$ = $1;
    8506             :                 }
    8507             :         ;
    8508             : 
    8509             : /*
    8510             :  * The SQL standard offers no guidance on how to declare aggregate argument
    8511             :  * lists, since it doesn't have CREATE AGGREGATE etc.  We accept these cases:
    8512             :  *
    8513             :  * (*)                                  - normal agg with no args
    8514             :  * (aggr_arg,...)                       - normal agg with args
    8515             :  * (ORDER BY aggr_arg,...)              - ordered-set agg with no direct args
    8516             :  * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
    8517             :  *
    8518             :  * The zero-argument case is spelled with '*' for consistency with COUNT(*).
    8519             :  *
    8520             :  * An additional restriction is that if the direct-args list ends in a
    8521             :  * VARIADIC item, the ordered-args list must contain exactly one item that
    8522             :  * is also VARIADIC with the same type.  This allows us to collapse the two
    8523             :  * VARIADIC items into one, which is necessary to represent the aggregate in
    8524             :  * pg_proc.  We check this at the grammar stage so that we can return a list
    8525             :  * in which the second VARIADIC item is already discarded, avoiding extra work
    8526             :  * in cases such as DROP AGGREGATE.
    8527             :  *
    8528             :  * The return value of this production is a two-element list, in which the
    8529             :  * first item is a sublist of FunctionParameter nodes (with any duplicate
    8530             :  * VARIADIC item already dropped, as per above) and the second is an Integer
    8531             :  * node, containing -1 if there was no ORDER BY and otherwise the number
    8532             :  * of argument declarations before the ORDER BY.  (If this number is equal
    8533             :  * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
    8534             :  * This representation is passed as-is to CREATE AGGREGATE; for operations
    8535             :  * on existing aggregates, we can just apply extractArgTypes to the first
    8536             :  * sublist.
    8537             :  */
    8538             : aggr_args:  '(' '*' ')'
    8539             :                 {
    8540         136 :                     $$ = list_make2(NIL, makeInteger(-1));
    8541             :                 }
    8542             :             | '(' aggr_args_list ')'
    8543             :                 {
    8544         730 :                     $$ = list_make2($2, makeInteger(-1));
    8545             :                 }
    8546             :             | '(' ORDER BY aggr_args_list ')'
    8547             :                 {
    8548           6 :                     $$ = list_make2($4, makeInteger(0));
    8549             :                 }
    8550             :             | '(' aggr_args_list ORDER BY aggr_args_list ')'
    8551             :                 {
    8552             :                     /* this is the only case requiring consistency checking */
    8553          32 :                     $$ = makeOrderedSetArgs($2, $5, yyscanner);
    8554             :                 }
    8555             :         ;
    8556             : 
    8557             : aggr_args_list:
    8558         800 :             aggr_arg                                { $$ = list_make1($1); }
    8559          98 :             | aggr_args_list ',' aggr_arg           { $$ = lappend($1, $3); }
    8560             :         ;
    8561             : 
    8562             : aggregate_with_argtypes:
    8563             :             func_name aggr_args
    8564             :                 {
    8565         362 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8566             : 
    8567         362 :                     n->objname = $1;
    8568         362 :                     n->objargs = extractAggrArgTypes($2);
    8569         362 :                     n->objfuncargs = (List *) linitial($2);
    8570         362 :                     $$ = n;
    8571             :                 }
    8572             :         ;
    8573             : 
    8574             : aggregate_with_argtypes_list:
    8575         104 :             aggregate_with_argtypes                 { $$ = list_make1($1); }
    8576             :             | aggregate_with_argtypes_list ',' aggregate_with_argtypes
    8577           0 :                                                     { $$ = lappend($1, $3); }
    8578             :         ;
    8579             : 
    8580             : opt_createfunc_opt_list:
    8581             :             createfunc_opt_list
    8582          46 :             | /*EMPTY*/ { $$ = NIL; }
    8583             :     ;
    8584             : 
    8585             : createfunc_opt_list:
    8586             :             /* Must be at least one to prevent conflict */
    8587       20418 :             createfunc_opt_item                     { $$ = list_make1($1); }
    8588       52416 :             | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
    8589             :     ;
    8590             : 
    8591             : /*
    8592             :  * Options common to both CREATE FUNCTION and ALTER FUNCTION
    8593             :  */
    8594             : common_func_opt_item:
    8595             :             CALLED ON NULL_P INPUT_P
    8596             :                 {
    8597         258 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(false), @1);
    8598             :                 }
    8599             :             | RETURNS NULL_P ON NULL_P INPUT_P
    8600             :                 {
    8601         702 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8602             :                 }
    8603             :             | STRICT_P
    8604             :                 {
    8605       10058 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8606             :                 }
    8607             :             | IMMUTABLE
    8608             :                 {
    8609        7906 :                     $$ = makeDefElem("volatility", (Node *) makeString("immutable"), @1);
    8610             :                 }
    8611             :             | STABLE
    8612             :                 {
    8613        1852 :                     $$ = makeDefElem("volatility", (Node *) makeString("stable"), @1);
    8614             :                 }
    8615             :             | VOLATILE
    8616             :                 {
    8617        1320 :                     $$ = makeDefElem("volatility", (Node *) makeString("volatile"), @1);
    8618             :                 }
    8619             :             | EXTERNAL SECURITY DEFINER
    8620             :                 {
    8621           0 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8622             :                 }
    8623             :             | EXTERNAL SECURITY INVOKER
    8624             :                 {
    8625           0 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8626             :                 }
    8627             :             | SECURITY DEFINER
    8628             :                 {
    8629          48 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8630             :                 }
    8631             :             | SECURITY INVOKER
    8632             :                 {
    8633          12 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8634             :                 }
    8635             :             | LEAKPROOF
    8636             :                 {
    8637          46 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(true), @1);
    8638             :                 }
    8639             :             | NOT LEAKPROOF
    8640             :                 {
    8641          12 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(false), @1);
    8642             :                 }
    8643             :             | COST NumericOnly
    8644             :                 {
    8645        3458 :                     $$ = makeDefElem("cost", (Node *) $2, @1);
    8646             :                 }
    8647             :             | ROWS NumericOnly
    8648             :                 {
    8649         464 :                     $$ = makeDefElem("rows", (Node *) $2, @1);
    8650             :                 }
    8651             :             | SUPPORT any_name
    8652             :                 {
    8653          94 :                     $$ = makeDefElem("support", (Node *) $2, @1);
    8654             :                 }
    8655             :             | FunctionSetResetClause
    8656             :                 {
    8657             :                     /* we abuse the normal content of a DefElem here */
    8658         112 :                     $$ = makeDefElem("set", (Node *) $1, @1);
    8659             :                 }
    8660             :             | PARALLEL ColId
    8661             :                 {
    8662       10540 :                     $$ = makeDefElem("parallel", (Node *) makeString($2), @1);
    8663             :                 }
    8664             :         ;
    8665             : 
    8666             : createfunc_opt_item:
    8667             :             AS func_as
    8668             :                 {
    8669       16046 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    8670             :                 }
    8671             :             | LANGUAGE NonReservedWord_or_Sconst
    8672             :                 {
    8673       20400 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    8674             :                 }
    8675             :             | TRANSFORM transform_type_list
    8676             :                 {
    8677         118 :                     $$ = makeDefElem("transform", (Node *) $2, @1);
    8678             :                 }
    8679             :             | WINDOW
    8680             :                 {
    8681          20 :                     $$ = makeDefElem("window", (Node *) makeBoolean(true), @1);
    8682             :                 }
    8683             :             | common_func_opt_item
    8684             :                 {
    8685       36250 :                     $$ = $1;
    8686             :                 }
    8687             :         ;
    8688             : 
    8689       13776 : func_as:    Sconst                      { $$ = list_make1(makeString($1)); }
    8690             :             | Sconst ',' Sconst
    8691             :                 {
    8692        2270 :                     $$ = list_make2(makeString($1), makeString($3));
    8693             :                 }
    8694             :         ;
    8695             : 
    8696             : ReturnStmt: RETURN a_expr
    8697             :                 {
    8698        3806 :                     ReturnStmt *r = makeNode(ReturnStmt);
    8699             : 
    8700        3806 :                     r->returnval = (Node *) $2;
    8701        3806 :                     $$ = (Node *) r;
    8702             :                 }
    8703             :         ;
    8704             : 
    8705             : opt_routine_body:
    8706             :             ReturnStmt
    8707             :                 {
    8708        3800 :                     $$ = $1;
    8709             :                 }
    8710             :             | BEGIN_P ATOMIC routine_body_stmt_list END_P
    8711             :                 {
    8712             :                     /*
    8713             :                      * A compound statement is stored as a single-item list
    8714             :                      * containing the list of statements as its member.  That
    8715             :                      * way, the parse analysis code can tell apart an empty
    8716             :                      * body from no body at all.
    8717             :                      */
    8718         624 :                     $$ = (Node *) list_make1($3);
    8719             :                 }
    8720             :             | /*EMPTY*/
    8721             :                 {
    8722       16040 :                     $$ = NULL;
    8723             :                 }
    8724             :         ;
    8725             : 
    8726             : routine_body_stmt_list:
    8727             :             routine_body_stmt_list routine_body_stmt ';'
    8728             :                 {
    8729             :                     /* As in stmtmulti, discard empty statements */
    8730         640 :                     if ($2 != NULL)
    8731         622 :                         $$ = lappend($1, $2);
    8732             :                     else
    8733          18 :                         $$ = $1;
    8734             :                 }
    8735             :             | /*EMPTY*/
    8736             :                 {
    8737         624 :                     $$ = NIL;
    8738             :                 }
    8739             :         ;
    8740             : 
    8741             : routine_body_stmt:
    8742             :             stmt
    8743             :             | ReturnStmt
    8744             :         ;
    8745             : 
    8746             : transform_type_list:
    8747         118 :             FOR TYPE_P Typename { $$ = list_make1($3); }
    8748           4 :             | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
    8749             :         ;
    8750             : 
    8751             : opt_definition:
    8752         532 :             WITH definition                         { $$ = $2; }
    8753        9098 :             | /*EMPTY*/                             { $$ = NIL; }
    8754             :         ;
    8755             : 
    8756             : table_func_column:  param_name func_type
    8757             :                 {
    8758         406 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8759             : 
    8760         406 :                     n->name = $1;
    8761         406 :                     n->argType = $2;
    8762         406 :                     n->mode = FUNC_PARAM_TABLE;
    8763         406 :                     n->defexpr = NULL;
    8764         406 :                     $$ = n;
    8765             :                 }
    8766             :         ;
    8767             : 
    8768             : table_func_column_list:
    8769             :             table_func_column
    8770             :                 {
    8771         188 :                     $$ = list_make1($1);
    8772             :                 }
    8773             :             | table_func_column_list ',' table_func_column
    8774             :                 {
    8775         218 :                     $$ = lappend($1, $3);
    8776             :                 }
    8777             :         ;
    8778             : 
    8779             : /*****************************************************************************
    8780             :  * ALTER FUNCTION / ALTER PROCEDURE / ALTER ROUTINE
    8781             :  *
    8782             :  * RENAME and OWNER subcommands are already provided by the generic
    8783             :  * ALTER infrastructure, here we just specify alterations that can
    8784             :  * only be applied to functions.
    8785             :  *
    8786             :  *****************************************************************************/
    8787             : AlterFunctionStmt:
    8788             :             ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
    8789             :                 {
    8790         614 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8791             : 
    8792         614 :                     n->objtype = OBJECT_FUNCTION;
    8793         614 :                     n->func = $3;
    8794         614 :                     n->actions = $4;
    8795         614 :                     $$ = (Node *) n;
    8796             :                 }
    8797             :             | ALTER PROCEDURE function_with_argtypes alterfunc_opt_list opt_restrict
    8798             :                 {
    8799          18 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8800             : 
    8801          18 :                     n->objtype = OBJECT_PROCEDURE;
    8802          18 :                     n->func = $3;
    8803          18 :                     n->actions = $4;
    8804          18 :                     $$ = (Node *) n;
    8805             :                 }
    8806             :             | ALTER ROUTINE function_with_argtypes alterfunc_opt_list opt_restrict
    8807             :                 {
    8808           0 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8809             : 
    8810           0 :                     n->objtype = OBJECT_ROUTINE;
    8811           0 :                     n->func = $3;
    8812           0 :                     n->actions = $4;
    8813           0 :                     $$ = (Node *) n;
    8814             :                 }
    8815             :         ;
    8816             : 
    8817             : alterfunc_opt_list:
    8818             :             /* At least one option must be specified */
    8819         632 :             common_func_opt_item                    { $$ = list_make1($1); }
    8820           0 :             | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
    8821             :         ;
    8822             : 
    8823             : /* Ignored, merely for SQL compliance */
    8824             : opt_restrict:
    8825             :             RESTRICT
    8826             :             | /* EMPTY */
    8827             :         ;
    8828             : 
    8829             : 
    8830             : /*****************************************************************************
    8831             :  *
    8832             :  *      QUERY:
    8833             :  *
    8834             :  *      DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    8835             :  *      DROP PROCEDURE procname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    8836             :  *      DROP ROUTINE routname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    8837             :  *      DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
    8838             :  *      DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
    8839             :  *
    8840             :  *****************************************************************************/
    8841             : 
    8842             : RemoveFuncStmt:
    8843             :             DROP FUNCTION function_with_argtypes_list opt_drop_behavior
    8844             :                 {
    8845        3094 :                     DropStmt *n = makeNode(DropStmt);
    8846             : 
    8847        3094 :                     n->removeType = OBJECT_FUNCTION;
    8848        3094 :                     n->objects = $3;
    8849        3094 :                     n->behavior = $4;
    8850        3094 :                     n->missing_ok = false;
    8851        3094 :                     n->concurrent = false;
    8852        3094 :                     $$ = (Node *) n;
    8853             :                 }
    8854             :             | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    8855             :                 {
    8856         260 :                     DropStmt *n = makeNode(DropStmt);
    8857             : 
    8858         260 :                     n->removeType = OBJECT_FUNCTION;
    8859         260 :                     n->objects = $5;
    8860         260 :                     n->behavior = $6;
    8861         260 :                     n->missing_ok = true;
    8862         260 :                     n->concurrent = false;
    8863         260 :                     $$ = (Node *) n;
    8864             :                 }
    8865             :             | DROP PROCEDURE function_with_argtypes_list opt_drop_behavior
    8866             :                 {
    8867         138 :                     DropStmt *n = makeNode(DropStmt);
    8868             : 
    8869         138 :                     n->removeType = OBJECT_PROCEDURE;
    8870         138 :                     n->objects = $3;
    8871         138 :                     n->behavior = $4;
    8872         138 :                     n->missing_ok = false;
    8873         138 :                     n->concurrent = false;
    8874         138 :                     $$ = (Node *) n;
    8875             :                 }
    8876             :             | DROP PROCEDURE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    8877             :                 {
    8878           6 :                     DropStmt *n = makeNode(DropStmt);
    8879             : 
    8880           6 :                     n->removeType = OBJECT_PROCEDURE;
    8881           6 :                     n->objects = $5;
    8882           6 :                     n->behavior = $6;
    8883           6 :                     n->missing_ok = true;
    8884           6 :                     n->concurrent = false;
    8885           6 :                     $$ = (Node *) n;
    8886             :                 }
    8887             :             | DROP ROUTINE function_with_argtypes_list opt_drop_behavior
    8888             :                 {
    8889          12 :                     DropStmt *n = makeNode(DropStmt);
    8890             : 
    8891          12 :                     n->removeType = OBJECT_ROUTINE;
    8892          12 :                     n->objects = $3;
    8893          12 :                     n->behavior = $4;
    8894          12 :                     n->missing_ok = false;
    8895          12 :                     n->concurrent = false;
    8896          12 :                     $$ = (Node *) n;
    8897             :                 }
    8898             :             | DROP ROUTINE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    8899             :                 {
    8900           6 :                     DropStmt *n = makeNode(DropStmt);
    8901             : 
    8902           6 :                     n->removeType = OBJECT_ROUTINE;
    8903           6 :                     n->objects = $5;
    8904           6 :                     n->behavior = $6;
    8905           6 :                     n->missing_ok = true;
    8906           6 :                     n->concurrent = false;
    8907           6 :                     $$ = (Node *) n;
    8908             :                 }
    8909             :         ;
    8910             : 
    8911             : RemoveAggrStmt:
    8912             :             DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
    8913             :                 {
    8914          74 :                     DropStmt *n = makeNode(DropStmt);
    8915             : 
    8916          74 :                     n->removeType = OBJECT_AGGREGATE;
    8917          74 :                     n->objects = $3;
    8918          74 :                     n->behavior = $4;
    8919          74 :                     n->missing_ok = false;
    8920          74 :                     n->concurrent = false;
    8921          74 :                     $$ = (Node *) n;
    8922             :                 }
    8923             :             | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
    8924             :                 {
    8925          30 :                     DropStmt *n = makeNode(DropStmt);
    8926             : 
    8927          30 :                     n->removeType = OBJECT_AGGREGATE;
    8928          30 :                     n->objects = $5;
    8929          30 :                     n->behavior = $6;
    8930          30 :                     n->missing_ok = true;
    8931          30 :                     n->concurrent = false;
    8932          30 :                     $$ = (Node *) n;
    8933             :                 }
    8934             :         ;
    8935             : 
    8936             : RemoveOperStmt:
    8937             :             DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
    8938             :                 {
    8939         194 :                     DropStmt *n = makeNode(DropStmt);
    8940             : 
    8941         194 :                     n->removeType = OBJECT_OPERATOR;
    8942         194 :                     n->objects = $3;
    8943         194 :                     n->behavior = $4;
    8944         194 :                     n->missing_ok = false;
    8945         194 :                     n->concurrent = false;
    8946         194 :                     $$ = (Node *) n;
    8947             :                 }
    8948             :             | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
    8949             :                 {
    8950          30 :                     DropStmt *n = makeNode(DropStmt);
    8951             : 
    8952          30 :                     n->removeType = OBJECT_OPERATOR;
    8953          30 :                     n->objects = $5;
    8954          30 :                     n->behavior = $6;
    8955          30 :                     n->missing_ok = true;
    8956          30 :                     n->concurrent = false;
    8957          30 :                     $$ = (Node *) n;
    8958             :                 }
    8959             :         ;
    8960             : 
    8961             : oper_argtypes:
    8962             :             '(' Typename ')'
    8963             :                 {
    8964          12 :                    ereport(ERROR,
    8965             :                            (errcode(ERRCODE_SYNTAX_ERROR),
    8966             :                             errmsg("missing argument"),
    8967             :                             errhint("Use NONE to denote the missing argument of a unary operator."),
    8968             :                             parser_errposition(@3)));
    8969             :                 }
    8970             :             | '(' Typename ',' Typename ')'
    8971        1908 :                     { $$ = list_make2($2, $4); }
    8972             :             | '(' NONE ',' Typename ')'                 /* left unary */
    8973          32 :                     { $$ = list_make2(NULL, $4); }
    8974             :             | '(' Typename ',' NONE ')'                 /* right unary */
    8975          12 :                     { $$ = list_make2($2, NULL); }
    8976             :         ;
    8977             : 
    8978             : any_operator:
    8979             :             all_Op
    8980       19108 :                     { $$ = list_make1(makeString($1)); }
    8981             :             | ColId '.' any_operator
    8982       14244 :                     { $$ = lcons(makeString($1), $3); }
    8983             :         ;
    8984             : 
    8985             : operator_with_argtypes_list:
    8986         224 :             operator_with_argtypes                  { $$ = list_make1($1); }
    8987             :             | operator_with_argtypes_list ',' operator_with_argtypes
    8988           0 :                                                     { $$ = lappend($1, $3); }
    8989             :         ;
    8990             : 
    8991             : operator_with_argtypes:
    8992             :             any_operator oper_argtypes
    8993             :                 {
    8994        1952 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8995             : 
    8996        1952 :                     n->objname = $1;
    8997        1952 :                     n->objargs = $2;
    8998        1952 :                     $$ = n;
    8999             :                 }
    9000             :         ;
    9001             : 
    9002             : /*****************************************************************************
    9003             :  *
    9004             :  *      DO <anonymous code block> [ LANGUAGE language ]
    9005             :  *
    9006             :  * We use a DefElem list for future extensibility, and to allow flexibility
    9007             :  * in the clause order.
    9008             :  *
    9009             :  *****************************************************************************/
    9010             : 
    9011             : DoStmt: DO dostmt_opt_list
    9012             :                 {
    9013        1086 :                     DoStmt *n = makeNode(DoStmt);
    9014             : 
    9015        1086 :                     n->args = $2;
    9016        1086 :                     $$ = (Node *) n;
    9017             :                 }
    9018             :         ;
    9019             : 
    9020             : dostmt_opt_list:
    9021        1086 :             dostmt_opt_item                     { $$ = list_make1($1); }
    9022         196 :             | dostmt_opt_list dostmt_opt_item   { $$ = lappend($1, $2); }
    9023             :         ;
    9024             : 
    9025             : dostmt_opt_item:
    9026             :             Sconst
    9027             :                 {
    9028        1086 :                     $$ = makeDefElem("as", (Node *) makeString($1), @1);
    9029             :                 }
    9030             :             | LANGUAGE NonReservedWord_or_Sconst
    9031             :                 {
    9032         196 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    9033             :                 }
    9034             :         ;
    9035             : 
    9036             : /*****************************************************************************
    9037             :  *
    9038             :  *      CREATE CAST / DROP CAST
    9039             :  *
    9040             :  *****************************************************************************/
    9041             : 
    9042             : CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
    9043             :                     WITH FUNCTION function_with_argtypes cast_context
    9044             :                 {
    9045         102 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9046             : 
    9047         102 :                     n->sourcetype = $4;
    9048         102 :                     n->targettype = $6;
    9049         102 :                     n->func = $10;
    9050         102 :                     n->context = (CoercionContext) $11;
    9051         102 :                     n->inout = false;
    9052         102 :                     $$ = (Node *) n;
    9053             :                 }
    9054             :             | CREATE CAST '(' Typename AS Typename ')'
    9055             :                     WITHOUT FUNCTION cast_context
    9056             :                 {
    9057         162 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9058             : 
    9059         162 :                     n->sourcetype = $4;
    9060         162 :                     n->targettype = $6;
    9061         162 :                     n->func = NULL;
    9062         162 :                     n->context = (CoercionContext) $10;
    9063         162 :                     n->inout = false;
    9064         162 :                     $$ = (Node *) n;
    9065             :                 }
    9066             :             | CREATE CAST '(' Typename AS Typename ')'
    9067             :                     WITH INOUT cast_context
    9068             :                 {
    9069           6 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9070             : 
    9071           6 :                     n->sourcetype = $4;
    9072           6 :                     n->targettype = $6;
    9073           6 :                     n->func = NULL;
    9074           6 :                     n->context = (CoercionContext) $10;
    9075           6 :                     n->inout = true;
    9076           6 :                     $$ = (Node *) n;
    9077             :                 }
    9078             :         ;
    9079             : 
    9080          30 : cast_context:  AS IMPLICIT_P                    { $$ = COERCION_IMPLICIT; }
    9081          58 :         | AS ASSIGNMENT                         { $$ = COERCION_ASSIGNMENT; }
    9082         182 :         | /*EMPTY*/                             { $$ = COERCION_EXPLICIT; }
    9083             :         ;
    9084             : 
    9085             : 
    9086             : DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
    9087             :                 {
    9088          54 :                     DropStmt *n = makeNode(DropStmt);
    9089             : 
    9090          54 :                     n->removeType = OBJECT_CAST;
    9091          54 :                     n->objects = list_make1(list_make2($5, $7));
    9092          54 :                     n->behavior = $9;
    9093          54 :                     n->missing_ok = $3;
    9094          54 :                     n->concurrent = false;
    9095          54 :                     $$ = (Node *) n;
    9096             :                 }
    9097             :         ;
    9098             : 
    9099          36 : opt_if_exists: IF_P EXISTS                      { $$ = true; }
    9100          32 :         | /*EMPTY*/                             { $$ = false; }
    9101             :         ;
    9102             : 
    9103             : 
    9104             : /*****************************************************************************
    9105             :  *
    9106             :  *      CREATE TRANSFORM / DROP TRANSFORM
    9107             :  *
    9108             :  *****************************************************************************/
    9109             : 
    9110             : CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name '(' transform_element_list ')'
    9111             :                 {
    9112          50 :                     CreateTransformStmt *n = makeNode(CreateTransformStmt);
    9113             : 
    9114          50 :                     n->replace = $2;
    9115          50 :                     n->type_name = $5;
    9116          50 :                     n->lang = $7;
    9117          50 :                     n->fromsql = linitial($9);
    9118          50 :                     n->tosql = lsecond($9);
    9119          50 :                     $$ = (Node *) n;
    9120             :                 }
    9121             :         ;
    9122             : 
    9123             : transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes ',' TO SQL_P WITH FUNCTION function_with_argtypes
    9124             :                 {
    9125          44 :                     $$ = list_make2($5, $11);
    9126             :                 }
    9127             :                 | TO SQL_P WITH FUNCTION function_with_argtypes ',' FROM SQL_P WITH FUNCTION function_with_argtypes
    9128             :                 {
    9129           0 :                     $$ = list_make2($11, $5);
    9130             :                 }
    9131             :                 | FROM SQL_P WITH FUNCTION function_with_argtypes
    9132             :                 {
    9133           4 :                     $$ = list_make2($5, NULL);
    9134             :                 }
    9135             :                 | TO SQL_P WITH FUNCTION function_with_argtypes
    9136             :                 {
    9137           2 :                     $$ = list_make2(NULL, $5);
    9138             :                 }
    9139             :         ;
    9140             : 
    9141             : 
    9142             : DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
    9143             :                 {
    9144          14 :                     DropStmt *n = makeNode(DropStmt);
    9145             : 
    9146          14 :                     n->removeType = OBJECT_TRANSFORM;
    9147          14 :                     n->objects = list_make1(list_make2($5, makeString($7)));
    9148          14 :                     n->behavior = $8;
    9149          14 :                     n->missing_ok = $3;
    9150          14 :                     $$ = (Node *) n;
    9151             :                 }
    9152             :         ;
    9153             : 
    9154             : 
    9155             : /*****************************************************************************
    9156             :  *
    9157             :  *      QUERY:
    9158             :  *
    9159             :  *      REINDEX [ (options) ] {INDEX | TABLE | SCHEMA} [CONCURRENTLY] <name>
    9160             :  *      REINDEX [ (options) ] {DATABASE | SYSTEM} [CONCURRENTLY] [<name>]
    9161             :  *****************************************************************************/
    9162             : 
    9163             : ReindexStmt:
    9164             :             REINDEX opt_reindex_option_list reindex_target_relation opt_concurrently qualified_name
    9165             :                 {
    9166         876 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9167             : 
    9168         876 :                     n->kind = $3;
    9169         876 :                     n->relation = $5;
    9170         876 :                     n->name = NULL;
    9171         876 :                     n->params = $2;
    9172         876 :                     if ($4)
    9173         496 :                         n->params = lappend(n->params,
    9174         496 :                                             makeDefElem("concurrently", NULL, @4));
    9175         876 :                     $$ = (Node *) n;
    9176             :                 }
    9177             :             | REINDEX opt_reindex_option_list SCHEMA opt_concurrently name
    9178             :                 {
    9179         116 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9180             : 
    9181         116 :                     n->kind = REINDEX_OBJECT_SCHEMA;
    9182         116 :                     n->relation = NULL;
    9183         116 :                     n->name = $5;
    9184         116 :                     n->params = $2;
    9185         116 :                     if ($4)
    9186          40 :                         n->params = lappend(n->params,
    9187          40 :                                             makeDefElem("concurrently", NULL, @4));
    9188         116 :                     $$ = (Node *) n;
    9189             :                 }
    9190             :             | REINDEX opt_reindex_option_list reindex_target_all opt_concurrently opt_single_name
    9191             :                 {
    9192          68 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9193             : 
    9194          68 :                     n->kind = $3;
    9195          68 :                     n->relation = NULL;
    9196          68 :                     n->name = $5;
    9197          68 :                     n->params = $2;
    9198          68 :                     if ($4)
    9199          10 :                         n->params = lappend(n->params,
    9200          10 :                                             makeDefElem("concurrently", NULL, @4));
    9201          68 :                     $$ = (Node *) n;
    9202             :                 }
    9203             :         ;
    9204             : reindex_target_relation:
    9205         378 :             INDEX                   { $$ = REINDEX_OBJECT_INDEX; }
    9206         498 :             | TABLE                 { $$ = REINDEX_OBJECT_TABLE; }
    9207             :         ;
    9208             : reindex_target_all:
    9209          34 :             SYSTEM_P                { $$ = REINDEX_OBJECT_SYSTEM; }
    9210          34 :             | DATABASE              { $$ = REINDEX_OBJECT_DATABASE; }
    9211             :         ;
    9212             : opt_reindex_option_list:
    9213         156 :             '(' utility_option_list ')'             { $$ = $2; }
    9214         904 :             | /* EMPTY */                           { $$ = NULL; }
    9215             :         ;
    9216             : 
    9217             : /*****************************************************************************
    9218             :  *
    9219             :  * ALTER TABLESPACE
    9220             :  *
    9221             :  *****************************************************************************/
    9222             : 
    9223             : AlterTblSpcStmt:
    9224             :             ALTER TABLESPACE name SET reloptions
    9225             :                 {
    9226             :                     AlterTableSpaceOptionsStmt *n =
    9227          12 :                         makeNode(AlterTableSpaceOptionsStmt);
    9228             : 
    9229          12 :                     n->tablespacename = $3;
    9230          12 :                     n->options = $5;
    9231          12 :                     n->isReset = false;
    9232          12 :                     $$ = (Node *) n;
    9233             :                 }
    9234             :             | ALTER TABLESPACE name RESET reloptions
    9235             :                 {
    9236             :                     AlterTableSpaceOptionsStmt *n =
    9237          12 :                         makeNode(AlterTableSpaceOptionsStmt);
    9238             : 
    9239          12 :                     n->tablespacename = $3;
    9240          12 :                     n->options = $5;
    9241          12 :                     n->isReset = true;
    9242          12 :                     $$ = (Node *) n;
    9243             :                 }
    9244             :         ;
    9245             : 
    9246             : /*****************************************************************************
    9247             :  *
    9248             :  * ALTER THING name RENAME TO newname
    9249             :  *
    9250             :  *****************************************************************************/
    9251             : 
    9252             : RenameStmt: ALTER AGGREGATE aggregate_with_argtypes RENAME TO name
    9253             :                 {
    9254          42 :                     RenameStmt *n = makeNode(RenameStmt);
    9255             : 
    9256          42 :                     n->renameType = OBJECT_AGGREGATE;
    9257          42 :                     n->object = (Node *) $3;
    9258          42 :                     n->newname = $6;
    9259          42 :                     n->missing_ok = false;
    9260          42 :                     $$ = (Node *) n;
    9261             :                 }
    9262             :             | ALTER COLLATION any_name RENAME TO name
    9263             :                 {
    9264          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9265             : 
    9266          18 :                     n->renameType = OBJECT_COLLATION;
    9267          18 :                     n->object = (Node *) $3;
    9268          18 :                     n->newname = $6;
    9269          18 :                     n->missing_ok = false;
    9270          18 :                     $$ = (Node *) n;
    9271             :                 }
    9272             :             | ALTER CONVERSION_P any_name RENAME TO name
    9273             :                 {
    9274          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9275             : 
    9276          24 :                     n->renameType = OBJECT_CONVERSION;
    9277          24 :                     n->object = (Node *) $3;
    9278          24 :                     n->newname = $6;
    9279          24 :                     n->missing_ok = false;
    9280          24 :                     $$ = (Node *) n;
    9281             :                 }
    9282             :             | ALTER DATABASE name RENAME TO name
    9283             :                 {
    9284           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9285             : 
    9286           0 :                     n->renameType = OBJECT_DATABASE;
    9287           0 :                     n->subname = $3;
    9288           0 :                     n->newname = $6;
    9289           0 :                     n->missing_ok = false;
    9290           0 :                     $$ = (Node *) n;
    9291             :                 }
    9292             :             | ALTER DOMAIN_P any_name RENAME TO name
    9293             :                 {
    9294           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9295             : 
    9296           6 :                     n->renameType = OBJECT_DOMAIN;
    9297           6 :                     n->object = (Node *) $3;
    9298           6 :                     n->newname = $6;
    9299           6 :                     n->missing_ok = false;
    9300           6 :                     $$ = (Node *) n;
    9301             :                 }
    9302             :             | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
    9303             :                 {
    9304           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9305             : 
    9306           6 :                     n->renameType = OBJECT_DOMCONSTRAINT;
    9307           6 :                     n->object = (Node *) $3;
    9308           6 :                     n->subname = $6;
    9309           6 :                     n->newname = $8;
    9310           6 :                     $$ = (Node *) n;
    9311             :                 }
    9312             :             | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
    9313             :                 {
    9314          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9315             : 
    9316          24 :                     n->renameType = OBJECT_FDW;
    9317          24 :                     n->object = (Node *) makeString($5);
    9318          24 :                     n->newname = $8;
    9319          24 :                     n->missing_ok = false;
    9320          24 :                     $$ = (Node *) n;
    9321             :                 }
    9322             :             | ALTER FUNCTION function_with_argtypes RENAME TO name
    9323             :                 {
    9324          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9325             : 
    9326          24 :                     n->renameType = OBJECT_FUNCTION;
    9327          24 :                     n->object = (Node *) $3;
    9328          24 :                     n->newname = $6;
    9329          24 :                     n->missing_ok = false;
    9330          24 :                     $$ = (Node *) n;
    9331             :                 }
    9332             :             | ALTER GROUP_P RoleId RENAME TO RoleId
    9333             :                 {
    9334           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9335             : 
    9336           0 :                     n->renameType = OBJECT_ROLE;
    9337           0 :                     n->subname = $3;
    9338           0 :                     n->newname = $6;
    9339           0 :                     n->missing_ok = false;
    9340           0 :                     $$ = (Node *) n;
    9341             :                 }
    9342             :             | ALTER opt_procedural LANGUAGE name RENAME TO name
    9343             :                 {
    9344          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9345             : 
    9346          18 :                     n->renameType = OBJECT_LANGUAGE;
    9347          18 :                     n->object = (Node *) makeString($4);
    9348          18 :                     n->newname = $7;
    9349          18 :                     n->missing_ok = false;
    9350          18 :                     $$ = (Node *) n;
    9351             :                 }
    9352             :             | ALTER OPERATOR CLASS any_name USING name RENAME TO name
    9353             :                 {
    9354          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9355             : 
    9356          24 :                     n->renameType = OBJECT_OPCLASS;
    9357          24 :                     n->object = (Node *) lcons(makeString($6), $4);
    9358          24 :                     n->newname = $9;
    9359          24 :                     n->missing_ok = false;
    9360          24 :                     $$ = (Node *) n;
    9361             :                 }
    9362             :             | ALTER OPERATOR FAMILY any_name USING name RENAME TO name
    9363             :                 {
    9364          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9365             : 
    9366          24 :                     n->renameType = OBJECT_OPFAMILY;
    9367          24 :                     n->object = (Node *) lcons(makeString($6), $4);
    9368          24 :                     n->newname = $9;
    9369          24 :                     n->missing_ok = false;
    9370          24 :                     $$ = (Node *) n;
    9371             :                 }
    9372             :             | ALTER POLICY name ON qualified_name RENAME TO name
    9373             :                 {
    9374          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9375             : 
    9376          18 :                     n->renameType = OBJECT_POLICY;
    9377          18 :                     n->relation = $5;
    9378          18 :                     n->subname = $3;
    9379          18 :                     n->newname = $8;
    9380          18 :                     n->missing_ok = false;
    9381          18 :                     $$ = (Node *) n;
    9382             :                 }
    9383             :             | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
    9384             :                 {
    9385           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9386             : 
    9387           0 :                     n->renameType = OBJECT_POLICY;
    9388           0 :                     n->relation = $7;
    9389           0 :                     n->subname = $5;
    9390           0 :                     n->newname = $10;
    9391           0 :                     n->missing_ok = true;
    9392           0 :                     $$ = (Node *) n;
    9393             :                 }
    9394             :             | ALTER PROCEDURE function_with_argtypes RENAME TO name
    9395             :                 {
    9396           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9397             : 
    9398           0 :                     n->renameType = OBJECT_PROCEDURE;
    9399           0 :                     n->object = (Node *) $3;
    9400           0 :                     n->newname = $6;
    9401           0 :                     n->missing_ok = false;
    9402           0 :                     $$ = (Node *) n;
    9403             :                 }
    9404             :             | ALTER PUBLICATION name RENAME TO name
    9405             :                 {
    9406          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9407             : 
    9408          18 :                     n->renameType = OBJECT_PUBLICATION;
    9409          18 :                     n->object = (Node *) makeString($3);
    9410          18 :                     n->newname = $6;
    9411          18 :                     n->missing_ok = false;
    9412          18 :                     $$ = (Node *) n;
    9413             :                 }
    9414             :             | ALTER ROUTINE function_with_argtypes RENAME TO name
    9415             :                 {
    9416          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9417             : 
    9418          24 :                     n->renameType = OBJECT_ROUTINE;
    9419          24 :                     n->object = (Node *) $3;
    9420          24 :                     n->newname = $6;
    9421          24 :                     n->missing_ok = false;
    9422          24 :                     $$ = (Node *) n;
    9423             :                 }
    9424             :             | ALTER SCHEMA name RENAME TO name
    9425             :                 {
    9426          20 :                     RenameStmt *n = makeNode(RenameStmt);
    9427             : 
    9428          20 :                     n->renameType = OBJECT_SCHEMA;
    9429          20 :                     n->subname = $3;
    9430          20 :                     n->newname = $6;
    9431          20 :                     n->missing_ok = false;
    9432          20 :                     $$ = (Node *) n;
    9433             :                 }
    9434             :             | ALTER SERVER name RENAME TO name
    9435             :                 {
    9436          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9437             : 
    9438          24 :                     n->renameType = OBJECT_FOREIGN_SERVER;
    9439          24 :                     n->object = (Node *) makeString($3);
    9440          24 :                     n->newname = $6;
    9441          24 :                     n->missing_ok = false;
    9442          24 :                     $$ = (Node *) n;
    9443             :                 }
    9444             :             | ALTER SUBSCRIPTION name RENAME TO name
    9445             :                 {
    9446          38 :                     RenameStmt *n = makeNode(RenameStmt);
    9447             : 
    9448          38 :                     n->renameType = OBJECT_SUBSCRIPTION;
    9449          38 :                     n->object = (Node *) makeString($3);
    9450          38 :                     n->newname = $6;
    9451          38 :                     n->missing_ok = false;
    9452          38 :                     $$ = (Node *) n;
    9453             :                 }
    9454             :             | ALTER TABLE relation_expr RENAME TO name
    9455             :                 {
    9456         286 :                     RenameStmt *n = makeNode(RenameStmt);
    9457             : 
    9458         286 :                     n->renameType = OBJECT_TABLE;
    9459         286 :                     n->relation = $3;
    9460         286 :                     n->subname = NULL;
    9461         286 :                     n->newname = $6;
    9462         286 :                     n->missing_ok = false;
    9463         286 :                     $$ = (Node *) n;
    9464             :                 }
    9465             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
    9466             :                 {
    9467           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9468             : 
    9469           0 :                     n->renameType = OBJECT_TABLE;
    9470           0 :                     n->relation = $5;
    9471           0 :                     n->subname = NULL;
    9472           0 :                     n->newname = $8;
    9473           0 :                     n->missing_ok = true;
    9474           0 :                     $$ = (Node *) n;
    9475             :                 }
    9476             :             | ALTER SEQUENCE qualified_name RENAME TO name
    9477             :                 {
    9478           2 :                     RenameStmt *n = makeNode(RenameStmt);
    9479             : 
    9480           2 :                     n->renameType = OBJECT_SEQUENCE;
    9481           2 :                     n->relation = $3;
    9482           2 :                     n->subname = NULL;
    9483           2 :                     n->newname = $6;
    9484           2 :                     n->missing_ok = false;
    9485           2 :                     $$ = (Node *) n;
    9486             :                 }
    9487             :             | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
    9488             :                 {
    9489           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9490             : 
    9491           0 :                     n->renameType = OBJECT_SEQUENCE;
    9492           0 :                     n->relation = $5;
    9493           0 :                     n->subname = NULL;
    9494           0 :                     n->newname = $8;
    9495           0 :                     n->missing_ok = true;
    9496           0 :                     $$ = (Node *) n;
    9497             :                 }
    9498             :             | ALTER VIEW qualified_name RENAME TO name
    9499             :                 {
    9500           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9501             : 
    9502           6 :                     n->renameType = OBJECT_VIEW;
    9503           6 :                     n->relation = $3;
    9504           6 :                     n->subname = NULL;
    9505           6 :                     n->newname = $6;
    9506           6 :                     n->missing_ok = false;
    9507           6 :                     $$ = (Node *) n;
    9508             :                 }
    9509             :             | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
    9510             :                 {
    9511           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9512             : 
    9513           0 :                     n->renameType = OBJECT_VIEW;
    9514           0 :                     n->relation = $5;
    9515           0 :                     n->subname = NULL;
    9516           0 :                     n->newname = $8;
    9517           0 :                     n->missing_ok = true;
    9518           0 :                     $$ = (Node *) n;
    9519             :                 }
    9520             :             | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
    9521             :                 {
    9522           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9523             : 
    9524           0 :                     n->renameType = OBJECT_MATVIEW;
    9525           0 :                     n->relation = $4;
    9526           0 :                     n->subname = NULL;
    9527           0 :                     n->newname = $7;
    9528           0 :                     n->missing_ok = false;
    9529           0 :                     $$ = (Node *) n;
    9530             :                 }
    9531             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
    9532             :                 {
    9533           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9534             : 
    9535           0 :                     n->renameType = OBJECT_MATVIEW;
    9536           0 :                     n->relation = $6;
    9537           0 :                     n->subname = NULL;
    9538           0 :                     n->newname = $9;
    9539           0 :                     n->missing_ok = true;
    9540           0 :                     $$ = (Node *) n;
    9541             :                 }
    9542             :             | ALTER INDEX qualified_name RENAME TO name
    9543             :                 {
    9544         192 :                     RenameStmt *n = makeNode(RenameStmt);
    9545             : 
    9546         192 :                     n->renameType = OBJECT_INDEX;
    9547         192 :                     n->relation = $3;
    9548         192 :                     n->subname = NULL;
    9549         192 :                     n->newname = $6;
    9550         192 :                     n->missing_ok = false;
    9551         192 :                     $$ = (Node *) n;
    9552             :                 }
    9553             :             | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
    9554             :                 {
    9555          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9556             : 
    9557          12 :                     n->renameType = OBJECT_INDEX;
    9558          12 :                     n->relation = $5;
    9559          12 :                     n->subname = NULL;
    9560          12 :                     n->newname = $8;
    9561          12 :                     n->missing_ok = true;
    9562          12 :                     $$ = (Node *) n;
    9563             :                 }
    9564             :             | ALTER FOREIGN TABLE relation_expr RENAME TO name
    9565             :                 {
    9566           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9567             : 
    9568           6 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9569           6 :                     n->relation = $4;
    9570           6 :                     n->subname = NULL;
    9571           6 :                     n->newname = $7;
    9572           6 :                     n->missing_ok = false;
    9573           6 :                     $$ = (Node *) n;
    9574             :                 }
    9575             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
    9576             :                 {
    9577           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9578             : 
    9579           6 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9580           6 :                     n->relation = $6;
    9581           6 :                     n->subname = NULL;
    9582           6 :                     n->newname = $9;
    9583           6 :                     n->missing_ok = true;
    9584           6 :                     $$ = (Node *) n;
    9585             :                 }
    9586             :             | ALTER TABLE relation_expr RENAME opt_column name TO name
    9587             :                 {
    9588         238 :                     RenameStmt *n = makeNode(RenameStmt);
    9589             : 
    9590         238 :                     n->renameType = OBJECT_COLUMN;
    9591         238 :                     n->relationType = OBJECT_TABLE;
    9592         238 :                     n->relation = $3;
    9593         238 :                     n->subname = $6;
    9594         238 :                     n->newname = $8;
    9595         238 :                     n->missing_ok = false;
    9596         238 :                     $$ = (Node *) n;
    9597             :                 }
    9598             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9599             :                 {
    9600          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9601             : 
    9602          24 :                     n->renameType = OBJECT_COLUMN;
    9603          24 :                     n->relationType = OBJECT_TABLE;
    9604          24 :                     n->relation = $5;
    9605          24 :                     n->subname = $8;
    9606          24 :                     n->newname = $10;
    9607          24 :                     n->missing_ok = true;
    9608          24 :                     $$ = (Node *) n;
    9609             :                 }
    9610             :             | ALTER VIEW qualified_name RENAME opt_column name TO name
    9611             :                 {
    9612           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9613             : 
    9614           6 :                     n->renameType = OBJECT_COLUMN;
    9615           6 :                     n->relationType = OBJECT_VIEW;
    9616           6 :                     n->relation = $3;
    9617           6 :                     n->subname = $6;
    9618           6 :                     n->newname = $8;
    9619           6 :                     n->missing_ok = false;
    9620           6 :                     $$ = (Node *) n;
    9621             :                 }
    9622             :             | ALTER VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    9623             :                 {
    9624           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9625             : 
    9626           0 :                     n->renameType = OBJECT_COLUMN;
    9627           0 :                     n->relationType = OBJECT_VIEW;
    9628           0 :                     n->relation = $5;
    9629           0 :                     n->subname = $8;
    9630           0 :                     n->newname = $10;
    9631           0 :                     n->missing_ok = true;
    9632           0 :                     $$ = (Node *) n;
    9633             :                 }
    9634             :             | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
    9635             :                 {
    9636           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9637             : 
    9638           0 :                     n->renameType = OBJECT_COLUMN;
    9639           0 :                     n->relationType = OBJECT_MATVIEW;
    9640           0 :                     n->relation = $4;
    9641           0 :                     n->subname = $7;
    9642           0 :                     n->newname = $9;
    9643           0 :                     n->missing_ok = false;
    9644           0 :                     $$ = (Node *) n;
    9645             :                 }
    9646             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    9647             :                 {
    9648           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9649             : 
    9650           0 :                     n->renameType = OBJECT_COLUMN;
    9651           0 :                     n->relationType = OBJECT_MATVIEW;
    9652           0 :                     n->relation = $6;
    9653           0 :                     n->subname = $9;
    9654           0 :                     n->newname = $11;
    9655           0 :                     n->missing_ok = true;
    9656           0 :                     $$ = (Node *) n;
    9657             :                 }
    9658             :             | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
    9659             :                 {
    9660          66 :                     RenameStmt *n = makeNode(RenameStmt);
    9661             : 
    9662          66 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9663          66 :                     n->relation = $3;
    9664          66 :                     n->subname = $6;
    9665          66 :                     n->newname = $8;
    9666          66 :                     n->missing_ok = false;
    9667          66 :                     $$ = (Node *) n;
    9668             :                 }
    9669             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
    9670             :                 {
    9671           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9672             : 
    9673           6 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9674           6 :                     n->relation = $5;
    9675           6 :                     n->subname = $8;
    9676           6 :                     n->newname = $10;
    9677           6 :                     n->missing_ok = true;
    9678           6 :                     $$ = (Node *) n;
    9679             :                 }
    9680             :             | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
    9681             :                 {
    9682           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9683             : 
    9684           6 :                     n->renameType = OBJECT_COLUMN;
    9685           6 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    9686           6 :                     n->relation = $4;
    9687           6 :                     n->subname = $7;
    9688           6 :                     n->newname = $9;
    9689           6 :                     n->missing_ok = false;
    9690           6 :                     $$ = (Node *) n;
    9691             :                 }
    9692             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9693             :                 {
    9694           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9695             : 
    9696           6 :                     n->renameType = OBJECT_COLUMN;
    9697           6 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    9698           6 :                     n->relation = $6;
    9699           6 :                     n->subname = $9;
    9700           6 :                     n->newname = $11;
    9701           6 :                     n->missing_ok = true;
    9702           6 :                     $$ = (Node *) n;
    9703             :                 }
    9704             :             | ALTER RULE name ON qualified_name RENAME TO name
    9705             :                 {
    9706          34 :                     RenameStmt *n = makeNode(RenameStmt);
    9707             : 
    9708          34 :                     n->renameType = OBJECT_RULE;
    9709          34 :                     n->relation = $5;
    9710          34 :                     n->subname = $3;
    9711          34 :                     n->newname = $8;
    9712          34 :                     n->missing_ok = false;
    9713          34 :                     $$ = (Node *) n;
    9714             :                 }
    9715             :             | ALTER TRIGGER name ON qualified_name RENAME TO name
    9716             :                 {
    9717          40 :                     RenameStmt *n = makeNode(RenameStmt);
    9718             : 
    9719          40 :                     n->renameType = OBJECT_TRIGGER;
    9720          40 :                     n->relation = $5;
    9721          40 :                     n->subname = $3;
    9722          40 :                     n->newname = $8;
    9723          40 :                     n->missing_ok = false;
    9724          40 :                     $$ = (Node *) n;
    9725             :                 }
    9726             :             | ALTER EVENT TRIGGER name RENAME TO name
    9727             :                 {
    9728          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9729             : 
    9730          12 :                     n->renameType = OBJECT_EVENT_TRIGGER;
    9731          12 :                     n->object = (Node *) makeString($4);
    9732          12 :                     n->newname = $7;
    9733          12 :                     $$ = (Node *) n;
    9734             :                 }
    9735             :             | ALTER ROLE RoleId RENAME TO RoleId
    9736             :                 {
    9737          30 :                     RenameStmt *n = makeNode(RenameStmt);
    9738             : 
    9739          30 :                     n->renameType = OBJECT_ROLE;
    9740          30 :                     n->subname = $3;
    9741          30 :                     n->newname = $6;
    9742          30 :                     n->missing_ok = false;
    9743          30 :                     $$ = (Node *) n;
    9744             :                 }
    9745             :             | ALTER USER RoleId RENAME TO RoleId
    9746             :                 {
    9747           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9748             : 
    9749           0 :                     n->renameType = OBJECT_ROLE;
    9750           0 :                     n->subname = $3;
    9751           0 :                     n->newname = $6;
    9752           0 :                     n->missing_ok = false;
    9753           0 :                     $$ = (Node *) n;
    9754             :                 }
    9755             :             | ALTER TABLESPACE name RENAME TO name
    9756             :                 {
    9757           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9758             : 
    9759           6 :                     n->renameType = OBJECT_TABLESPACE;
    9760           6 :                     n->subname = $3;
    9761           6 :                     n->newname = $6;
    9762           6 :                     n->missing_ok = false;
    9763           6 :                     $$ = (Node *) n;
    9764             :                 }
    9765             :             | ALTER STATISTICS any_name RENAME TO name
    9766             :                 {
    9767          30 :                     RenameStmt *n = makeNode(RenameStmt);
    9768             : 
    9769          30 :                     n->renameType = OBJECT_STATISTIC_EXT;
    9770          30 :                     n->object = (Node *) $3;
    9771          30 :                     n->newname = $6;
    9772          30 :                     n->missing_ok = false;
    9773          30 :                     $$ = (Node *) n;
    9774             :                 }
    9775             :             | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
    9776             :                 {
    9777          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9778             : 
    9779          12 :                     n->renameType = OBJECT_TSPARSER;
    9780          12 :                     n->object = (Node *) $5;
    9781          12 :                     n->newname = $8;
    9782          12 :                     n->missing_ok = false;
    9783          12 :                     $$ = (Node *) n;
    9784             :                 }
    9785             :             | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
    9786             :                 {
    9787          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9788             : 
    9789          24 :                     n->renameType = OBJECT_TSDICTIONARY;
    9790          24 :                     n->object = (Node *) $5;
    9791          24 :                     n->newname = $8;
    9792          24 :                     n->missing_ok = false;
    9793          24 :                     $$ = (Node *) n;
    9794             :                 }
    9795             :             | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
    9796             :                 {
    9797          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9798             : 
    9799          12 :                     n->renameType = OBJECT_TSTEMPLATE;
    9800          12 :                     n->object = (Node *) $5;
    9801          12 :                     n->newname = $8;
    9802          12 :                     n->missing_ok = false;
    9803          12 :                     $$ = (Node *) n;
    9804             :                 }
    9805             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
    9806             :                 {
    9807          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9808             : 
    9809          24 :                     n->renameType = OBJECT_TSCONFIGURATION;
    9810          24 :                     n->object = (Node *) $5;
    9811          24 :                     n->newname = $8;
    9812          24 :                     n->missing_ok = false;
    9813          24 :                     $$ = (Node *) n;
    9814             :                 }
    9815             :             | ALTER TYPE_P any_name RENAME TO name
    9816             :                 {
    9817          26 :                     RenameStmt *n = makeNode(RenameStmt);
    9818             : 
    9819          26 :                     n->renameType = OBJECT_TYPE;
    9820          26 :                     n->object = (Node *) $3;
    9821          26 :                     n->newname = $6;
    9822          26 :                     n->missing_ok = false;
    9823          26 :                     $$ = (Node *) n;
    9824             :                 }
    9825             :             | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
    9826             :                 {
    9827          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9828             : 
    9829          24 :                     n->renameType = OBJECT_ATTRIBUTE;
    9830          24 :                     n->relationType = OBJECT_TYPE;
    9831          24 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
    9832          24 :                     n->subname = $6;
    9833          24 :                     n->newname = $8;
    9834          24 :                     n->behavior = $9;
    9835          24 :                     n->missing_ok = false;
    9836          24 :                     $$ = (Node *) n;
    9837             :                 }
    9838             :         ;
    9839             : 
    9840             : opt_column: COLUMN
    9841             :             | /*EMPTY*/
    9842             :         ;
    9843             : 
    9844         148 : opt_set_data: SET DATA_P                            { $$ = 1; }
    9845         772 :             | /*EMPTY*/                             { $$ = 0; }
    9846             :         ;
    9847             : 
    9848             : /*****************************************************************************
    9849             :  *
    9850             :  * ALTER THING name DEPENDS ON EXTENSION name
    9851             :  *
    9852             :  *****************************************************************************/
    9853             : 
    9854             : AlterObjectDependsStmt:
    9855             :             ALTER FUNCTION function_with_argtypes opt_no DEPENDS ON EXTENSION name
    9856             :                 {
    9857          12 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9858             : 
    9859          12 :                     n->objectType = OBJECT_FUNCTION;
    9860          12 :                     n->object = (Node *) $3;
    9861          12 :                     n->extname = makeString($8);
    9862          12 :                     n->remove = $4;
    9863          12 :                     $$ = (Node *) n;
    9864             :                 }
    9865             :             | ALTER PROCEDURE function_with_argtypes opt_no DEPENDS ON EXTENSION name
    9866             :                 {
    9867           0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9868             : 
    9869           0 :                     n->objectType = OBJECT_PROCEDURE;
    9870           0 :                     n->object = (Node *) $3;
    9871           0 :                     n->extname = makeString($8);
    9872           0 :                     n->remove = $4;
    9873           0 :                     $$ = (Node *) n;
    9874             :                 }
    9875             :             | ALTER ROUTINE function_with_argtypes opt_no DEPENDS ON EXTENSION name
    9876             :                 {
    9877           0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9878             : 
    9879           0 :                     n->objectType = OBJECT_ROUTINE;
    9880           0 :                     n->object = (Node *) $3;
    9881           0 :                     n->extname = makeString($8);
    9882           0 :                     n->remove = $4;
    9883           0 :                     $$ = (Node *) n;
    9884             :                 }
    9885             :             | ALTER TRIGGER name ON qualified_name opt_no DEPENDS ON EXTENSION name
    9886             :                 {
    9887          10 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9888             : 
    9889          10 :                     n->objectType = OBJECT_TRIGGER;
    9890          10 :                     n->relation = $5;
    9891          10 :                     n->object = (Node *) list_make1(makeString($3));
    9892          10 :                     n->extname = makeString($10);
    9893          10 :                     n->remove = $6;
    9894          10 :                     $$ = (Node *) n;
    9895             :                 }
    9896             :             | ALTER MATERIALIZED VIEW qualified_name opt_no DEPENDS ON EXTENSION name
    9897             :                 {
    9898          10 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9899             : 
    9900          10 :                     n->objectType = OBJECT_MATVIEW;
    9901          10 :                     n->relation = $4;
    9902          10 :                     n->extname = makeString($9);
    9903          10 :                     n->remove = $5;
    9904          10 :                     $$ = (Node *) n;
    9905             :                 }
    9906             :             | ALTER INDEX qualified_name opt_no DEPENDS ON EXTENSION name
    9907             :                 {
    9908          14 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9909             : 
    9910          14 :                     n->objectType = OBJECT_INDEX;
    9911          14 :                     n->relation = $3;
    9912          14 :                     n->extname = makeString($8);
    9913          14 :                     n->remove = $4;
    9914          14 :                     $$ = (Node *) n;
    9915             :                 }
    9916             :         ;
    9917             : 
    9918           8 : opt_no:     NO              { $$ = true; }
    9919          38 :             | /* EMPTY */   { $$ = false;   }
    9920             :         ;
    9921             : 
    9922             : /*****************************************************************************
    9923             :  *
    9924             :  * ALTER THING name SET SCHEMA name
    9925             :  *
    9926             :  *****************************************************************************/
    9927             : 
    9928             : AlterObjectSchemaStmt:
    9929             :             ALTER AGGREGATE aggregate_with_argtypes SET SCHEMA name
    9930             :                 {
    9931          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9932             : 
    9933          24 :                     n->objectType = OBJECT_AGGREGATE;
    9934          24 :                     n->object = (Node *) $3;
    9935          24 :                     n->newschema = $6;
    9936          24 :                     n->missing_ok = false;
    9937          24 :                     $$ = (Node *) n;
    9938             :                 }
    9939             :             | ALTER COLLATION any_name SET SCHEMA name
    9940             :                 {
    9941           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9942             : 
    9943           6 :                     n->objectType = OBJECT_COLLATION;
    9944           6 :                     n->object = (Node *) $3;
    9945           6 :                     n->newschema = $6;
    9946           6 :                     n->missing_ok = false;
    9947           6 :                     $$ = (Node *) n;
    9948             :                 }
    9949             :             | ALTER CONVERSION_P any_name SET SCHEMA name
    9950             :                 {
    9951          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9952             : 
    9953          24 :                     n->objectType = OBJECT_CONVERSION;
    9954          24 :                     n->object = (Node *) $3;
    9955          24 :                     n->newschema = $6;
    9956          24 :                     n->missing_ok = false;
    9957          24 :                     $$ = (Node *) n;
    9958             :                 }
    9959             :             | ALTER DOMAIN_P any_name SET SCHEMA name
    9960             :                 {
    9961           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9962             : 
    9963           6 :                     n->objectType = OBJECT_DOMAIN;
    9964           6 :                     n->object = (Node *) $3;
    9965           6 :                     n->newschema = $6;
    9966           6 :                     n->missing_ok = false;
    9967           6 :                     $$ = (Node *) n;
    9968             :                 }
    9969             :             | ALTER EXTENSION name SET SCHEMA name
    9970             :                 {
    9971          10 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9972             : 
    9973          10 :                     n->objectType = OBJECT_EXTENSION;
    9974          10 :                     n->object = (Node *) makeString($3);
    9975          10 :                     n->newschema = $6;
    9976          10 :                     n->missing_ok = false;
    9977          10 :                     $$ = (Node *) n;
    9978             :                 }
    9979             :             | ALTER FUNCTION function_with_argtypes SET SCHEMA name
    9980             :                 {
    9981          42 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9982             : 
    9983          42 :                     n->objectType = OBJECT_FUNCTION;
    9984          42 :                     n->object = (Node *) $3;
    9985          42 :                     n->newschema = $6;
    9986          42 :                     n->missing_ok = false;
    9987          42 :                     $$ = (Node *) n;
    9988             :                 }
    9989             :             | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
    9990             :                 {
    9991          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9992             : 
    9993          18 :                     n->objectType = OBJECT_OPERATOR;
    9994          18 :                     n->object = (Node *) $3;
    9995          18 :                     n->newschema = $6;
    9996          18 :                     n->missing_ok = false;
    9997          18 :                     $$ = (Node *) n;
    9998             :                 }
    9999             :             | ALTER OPERATOR CLASS any_name USING name SET SCHEMA name
   10000             :                 {
   10001          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10002             : 
   10003          24 :                     n->objectType = OBJECT_OPCLASS;
   10004          24 :                     n->object = (Node *) lcons(makeString($6), $4);
   10005          24 :                     n->newschema = $9;
   10006          24 :                     n->missing_ok = false;
   10007          24 :                     $$ = (Node *) n;
   10008             :                 }
   10009             :             | ALTER OPERATOR FAMILY any_name USING name SET SCHEMA name
   10010             :                 {
   10011          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10012             : 
   10013          24 :                     n->objectType = OBJECT_OPFAMILY;
   10014          24 :                     n->object = (Node *) lcons(makeString($6), $4);
   10015          24 :                     n->newschema = $9;
   10016          24 :                     n->missing_ok = false;
   10017          24 :                     $$ = (Node *) n;
   10018             :                 }
   10019             :             | ALTER PROCEDURE function_with_argtypes SET SCHEMA name
   10020             :                 {
   10021           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10022             : 
   10023           0 :                     n->objectType = OBJECT_PROCEDURE;
   10024           0 :                     n->object = (Node *) $3;
   10025           0 :                     n->newschema = $6;
   10026           0 :                     n->missing_ok = false;
   10027           0 :                     $$ = (Node *) n;
   10028             :                 }
   10029             :             | ALTER ROUTINE function_with_argtypes SET SCHEMA name
   10030             :                 {
   10031           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10032             : 
   10033           0 :                     n->objectType = OBJECT_ROUTINE;
   10034           0 :                     n->object = (Node *) $3;
   10035           0 :                     n->newschema = $6;
   10036           0 :                     n->missing_ok = false;
   10037           0 :                     $$ = (Node *) n;
   10038             :                 }
   10039             :             | ALTER TABLE relation_expr SET SCHEMA name
   10040             :                 {
   10041          66 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10042             : 
   10043          66 :                     n->objectType = OBJECT_TABLE;
   10044          66 :                     n->relation = $3;
   10045          66 :                     n->newschema = $6;
   10046          66 :                     n->missing_ok = false;
   10047          66 :                     $$ = (Node *) n;
   10048             :                 }
   10049             :             | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10050             :                 {
   10051          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10052             : 
   10053          12 :                     n->objectType = OBJECT_TABLE;
   10054          12 :                     n->relation = $5;
   10055          12 :                     n->newschema = $8;
   10056          12 :                     n->missing_ok = true;
   10057          12 :                     $$ = (Node *) n;
   10058             :                 }
   10059             :             | ALTER STATISTICS any_name SET SCHEMA name
   10060             :                 {
   10061          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10062             : 
   10063          18 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10064          18 :                     n->object = (Node *) $3;
   10065          18 :                     n->newschema = $6;
   10066          18 :                     n->missing_ok = false;
   10067          18 :                     $$ = (Node *) n;
   10068             :                 }
   10069             :             | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
   10070             :                 {
   10071          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10072             : 
   10073          18 :                     n->objectType = OBJECT_TSPARSER;
   10074          18 :                     n->object = (Node *) $5;
   10075          18 :                     n->newschema = $8;
   10076          18 :                     n->missing_ok = false;
   10077          18 :                     $$ = (Node *) n;
   10078             :                 }
   10079             :             | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
   10080             :                 {
   10081          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10082             : 
   10083          24 :                     n->objectType = OBJECT_TSDICTIONARY;
   10084          24 :                     n->object = (Node *) $5;
   10085          24 :                     n->newschema = $8;
   10086          24 :                     n->missing_ok = false;
   10087          24 :                     $$ = (Node *) n;
   10088             :                 }
   10089             :             | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
   10090             :                 {
   10091          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10092             : 
   10093          18 :                     n->objectType = OBJECT_TSTEMPLATE;
   10094          18 :                     n->object = (Node *) $5;
   10095          18 :                     n->newschema = $8;
   10096          18 :                     n->missing_ok = false;
   10097          18 :                     $$ = (Node *) n;
   10098             :                 }
   10099             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
   10100             :                 {
   10101          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10102             : 
   10103          24 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10104          24 :                     n->object = (Node *) $5;
   10105          24 :                     n->newschema = $8;
   10106          24 :                     n->missing_ok = false;
   10107          24 :                     $$ = (Node *) n;
   10108             :                 }
   10109             :             | ALTER SEQUENCE qualified_name SET SCHEMA name
   10110             :                 {
   10111           8 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10112             : 
   10113           8 :                     n->objectType = OBJECT_SEQUENCE;
   10114           8 :                     n->relation = $3;
   10115           8 :                     n->newschema = $6;
   10116           8 :                     n->missing_ok = false;
   10117           8 :                     $$ = (Node *) n;
   10118             :                 }
   10119             :             | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
   10120             :                 {
   10121           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10122             : 
   10123           0 :                     n->objectType = OBJECT_SEQUENCE;
   10124           0 :                     n->relation = $5;
   10125           0 :                     n->newschema = $8;
   10126           0 :                     n->missing_ok = true;
   10127           0 :                     $$ = (Node *) n;
   10128             :                 }
   10129             :             | ALTER VIEW qualified_name SET SCHEMA name
   10130             :                 {
   10131           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10132             : 
   10133           0 :                     n->objectType = OBJECT_VIEW;
   10134           0 :                     n->relation = $3;
   10135           0 :                     n->newschema = $6;
   10136           0 :                     n->missing_ok = false;
   10137           0 :                     $$ = (Node *) n;
   10138             :                 }
   10139             :             | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
   10140             :                 {
   10141           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10142             : 
   10143           0 :                     n->objectType = OBJECT_VIEW;
   10144           0 :                     n->relation = $5;
   10145           0 :                     n->newschema = $8;
   10146           0 :                     n->missing_ok = true;
   10147           0 :                     $$ = (Node *) n;
   10148             :                 }
   10149             :             | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
   10150             :                 {
   10151           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10152             : 
   10153           6 :                     n->objectType = OBJECT_MATVIEW;
   10154           6 :                     n->relation = $4;
   10155           6 :                     n->newschema = $7;
   10156           6 :                     n->missing_ok = false;
   10157           6 :                     $$ = (Node *) n;
   10158             :                 }
   10159             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
   10160             :                 {
   10161           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10162             : 
   10163           0 :                     n->objectType = OBJECT_MATVIEW;
   10164           0 :                     n->relation = $6;
   10165           0 :                     n->newschema = $9;
   10166           0 :                     n->missing_ok = true;
   10167           0 :                     $$ = (Node *) n;
   10168             :                 }
   10169             :             | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
   10170             :                 {
   10171           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10172             : 
   10173           6 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10174           6 :                     n->relation = $4;
   10175           6 :                     n->newschema = $7;
   10176           6 :                     n->missing_ok = false;
   10177           6 :                     $$ = (Node *) n;
   10178             :                 }
   10179             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10180             :                 {
   10181           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10182             : 
   10183           6 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10184           6 :                     n->relation = $6;
   10185           6 :                     n->newschema = $9;
   10186           6 :                     n->missing_ok = true;
   10187           6 :                     $$ = (Node *) n;
   10188             :                 }
   10189             :             | ALTER TYPE_P any_name SET SCHEMA name
   10190             :                 {
   10191          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10192             : 
   10193          12 :                     n->objectType = OBJECT_TYPE;
   10194          12 :                     n->object = (Node *) $3;
   10195          12 :                     n->newschema = $6;
   10196          12 :                     n->missing_ok = false;
   10197          12 :                     $$ = (Node *) n;
   10198             :                 }
   10199             :         ;
   10200             : 
   10201             : /*****************************************************************************
   10202             :  *
   10203             :  * ALTER OPERATOR name SET define
   10204             :  *
   10205             :  *****************************************************************************/
   10206             : 
   10207             : AlterOperatorStmt:
   10208             :             ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
   10209             :                 {
   10210         602 :                     AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
   10211             : 
   10212         602 :                     n->opername = $3;
   10213         602 :                     n->options = $6;
   10214         602 :                     $$ = (Node *) n;
   10215             :                 }
   10216             :         ;
   10217             : 
   10218         662 : operator_def_list:  operator_def_elem                               { $$ = list_make1($1); }
   10219         506 :             | operator_def_list ',' operator_def_elem               { $$ = lappend($1, $3); }
   10220             :         ;
   10221             : 
   10222             : operator_def_elem: ColLabel '=' NONE
   10223          30 :                         { $$ = makeDefElem($1, NULL, @1); }
   10224             :                    | ColLabel '=' operator_def_arg
   10225        1110 :                         { $$ = makeDefElem($1, (Node *) $3, @1); }
   10226             :                    | ColLabel
   10227          28 :                         { $$ = makeDefElem($1, NULL, @1); }
   10228             :         ;
   10229             : 
   10230             : /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
   10231             : operator_def_arg:
   10232        1032 :             func_type                       { $$ = (Node *) $1; }
   10233          24 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
   10234          54 :             | qual_all_Op                   { $$ = (Node *) $1; }
   10235           0 :             | NumericOnly                   { $$ = (Node *) $1; }
   10236           0 :             | Sconst                        { $$ = (Node *) makeString($1); }
   10237             :         ;
   10238             : 
   10239             : /*****************************************************************************
   10240             :  *
   10241             :  * ALTER TYPE name SET define
   10242             :  *
   10243             :  * We repurpose ALTER OPERATOR's version of "definition" here
   10244             :  *
   10245             :  *****************************************************************************/
   10246             : 
   10247             : AlterTypeStmt:
   10248             :             ALTER TYPE_P any_name SET '(' operator_def_list ')'
   10249             :                 {
   10250          60 :                     AlterTypeStmt *n = makeNode(AlterTypeStmt);
   10251             : 
   10252          60 :                     n->typeName = $3;
   10253          60 :                     n->options = $6;
   10254          60 :                     $$ = (Node *) n;
   10255             :                 }
   10256             :         ;
   10257             : 
   10258             : /*****************************************************************************
   10259             :  *
   10260             :  * ALTER THING name OWNER TO newname
   10261             :  *
   10262             :  *****************************************************************************/
   10263             : 
   10264             : AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec
   10265             :                 {
   10266         142 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10267             : 
   10268         142 :                     n->objectType = OBJECT_AGGREGATE;
   10269         142 :                     n->object = (Node *) $3;
   10270         142 :                     n->newowner = $6;
   10271         142 :                     $$ = (Node *) n;
   10272             :                 }
   10273             :             | ALTER COLLATION any_name OWNER TO RoleSpec
   10274             :                 {
   10275          16 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10276             : 
   10277          16 :                     n->objectType = OBJECT_COLLATION;
   10278          16 :                     n->object = (Node *) $3;
   10279          16 :                     n->newowner = $6;
   10280          16 :                     $$ = (Node *) n;
   10281             :                 }
   10282             :             | ALTER CONVERSION_P any_name OWNER TO RoleSpec
   10283             :                 {
   10284          24 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10285             : 
   10286          24 :                     n->objectType = OBJECT_CONVERSION;
   10287          24 :                     n->object = (Node *) $3;
   10288          24 :                     n->newowner = $6;
   10289          24 :                     $$ = (Node *) n;
   10290             :                 }
   10291             :             | ALTER DATABASE name OWNER TO RoleSpec
   10292             :                 {
   10293          44 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10294             : 
   10295          44 :                     n->objectType = OBJECT_DATABASE;
   10296          44 :                     n->object = (Node *) makeString($3);
   10297          44 :                     n->newowner = $6;
   10298          44 :                     $$ = (Node *) n;
   10299             :                 }
   10300             :             | ALTER DOMAIN_P any_name OWNER TO RoleSpec
   10301             :                 {
   10302          38 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10303             : 
   10304          38 :                     n->objectType = OBJECT_DOMAIN;
   10305          38 :                     n->object = (Node *) $3;
   10306          38 :                     n->newowner = $6;
   10307          38 :                     $$ = (Node *) n;
   10308             :                 }
   10309             :             | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
   10310             :                 {
   10311         574 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10312             : 
   10313         574 :                     n->objectType = OBJECT_FUNCTION;
   10314         574 :                     n->object = (Node *) $3;
   10315         574 :                     n->newowner = $6;
   10316         574 :                     $$ = (Node *) n;
   10317             :                 }
   10318             :             | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
   10319             :                 {
   10320         122 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10321             : 
   10322         122 :                     n->objectType = OBJECT_LANGUAGE;
   10323         122 :                     n->object = (Node *) makeString($4);
   10324         122 :                     n->newowner = $7;
   10325         122 :                     $$ = (Node *) n;
   10326             :                 }
   10327             :             | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
   10328             :                 {
   10329          12 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10330             : 
   10331          12 :                     n->objectType = OBJECT_LARGEOBJECT;
   10332          12 :                     n->object = (Node *) $4;
   10333          12 :                     n->newowner = $7;
   10334          12 :                     $$ = (Node *) n;
   10335             :                 }
   10336             :             | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
   10337             :                 {
   10338          46 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10339             : 
   10340          46 :                     n->objectType = OBJECT_OPERATOR;
   10341          46 :                     n->object = (Node *) $3;
   10342          46 :                     n->newowner = $6;
   10343          46 :                     $$ = (Node *) n;
   10344             :                 }
   10345             :             | ALTER OPERATOR CLASS any_name USING name OWNER TO RoleSpec
   10346             :                 {
   10347          54 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10348             : 
   10349          54 :                     n->objectType = OBJECT_OPCLASS;
   10350          54 :                     n->object = (Node *) lcons(makeString($6), $4);
   10351          54 :                     n->newowner = $9;
   10352          54 :                     $$ = (Node *) n;
   10353             :                 }
   10354             :             | ALTER OPERATOR FAMILY any_name USING name OWNER TO RoleSpec
   10355             :                 {
   10356          62 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10357             : 
   10358          62 :                     n->objectType = OBJECT_OPFAMILY;
   10359          62 :                     n->object = (Node *) lcons(makeString($6), $4);
   10360          62 :                     n->newowner = $9;
   10361          62 :                     $$ = (Node *) n;
   10362             :                 }
   10363             :             | ALTER PROCEDURE function_with_argtypes OWNER TO RoleSpec
   10364             :                 {
   10365          18 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10366             : 
   10367          18 :                     n->objectType = OBJECT_PROCEDURE;
   10368          18 :                     n->object = (Node *) $3;
   10369          18 :                     n->newowner = $6;
   10370          18 :                     $$ = (Node *) n;
   10371             :                 }
   10372             :             | ALTER ROUTINE function_with_argtypes OWNER TO RoleSpec
   10373             :                 {
   10374           0 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10375             : 
   10376           0 :                     n->objectType = OBJECT_ROUTINE;
   10377           0 :                     n->object = (Node *) $3;
   10378           0 :                     n->newowner = $6;
   10379           0 :                     $$ = (Node *) n;
   10380             :                 }
   10381             :             | ALTER SCHEMA name OWNER TO RoleSpec
   10382             :                 {
   10383          52 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10384             : 
   10385          52 :                     n->objectType = OBJECT_SCHEMA;
   10386          52 :                     n->object = (Node *) makeString($3);
   10387          52 :                     n->newowner = $6;
   10388          52 :                     $$ = (Node *) n;
   10389             :                 }
   10390             :             | ALTER TYPE_P any_name OWNER TO RoleSpec
   10391             :                 {
   10392          80 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10393             : 
   10394          80 :                     n->objectType = OBJECT_TYPE;
   10395          80 :                     n->object = (Node *) $3;
   10396          80 :                     n->newowner = $6;
   10397          80 :                     $$ = (Node *) n;
   10398             :                 }
   10399             :             | ALTER TABLESPACE name OWNER TO RoleSpec
   10400             :                 {
   10401           6 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10402             : 
   10403           6 :                     n->objectType = OBJECT_TABLESPACE;
   10404           6 :                     n->object = (Node *) makeString($3);
   10405           6 :                     n->newowner = $6;
   10406           6 :                     $$ = (Node *) n;
   10407             :                 }
   10408             :             | ALTER STATISTICS any_name OWNER TO RoleSpec
   10409             :                 {
   10410          32 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10411             : 
   10412          32 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10413          32 :                     n->object = (Node *) $3;
   10414          32 :                     n->newowner = $6;
   10415          32 :                     $$ = (Node *) n;
   10416             :                 }
   10417             :             | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
   10418             :                 {
   10419          42 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10420             : 
   10421          42 :                     n->objectType = OBJECT_TSDICTIONARY;
   10422          42 :                     n->object = (Node *) $5;
   10423          42 :                     n->newowner = $8;
   10424          42 :                     $$ = (Node *) n;
   10425             :                 }
   10426             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
   10427             :                 {
   10428          32 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10429             : 
   10430          32 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10431          32 :                     n->object = (Node *) $5;
   10432          32 :                     n->newowner = $8;
   10433          32 :                     $$ = (Node *) n;
   10434             :                 }
   10435             :             | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
   10436             :                 {
   10437          20 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10438             : 
   10439          20 :                     n->objectType = OBJECT_FDW;
   10440          20 :                     n->object = (Node *) makeString($5);
   10441          20 :                     n->newowner = $8;
   10442          20 :                     $$ = (Node *) n;
   10443             :                 }
   10444             :             | ALTER SERVER name OWNER TO RoleSpec
   10445             :                 {
   10446          68 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10447             : 
   10448          68 :                     n->objectType = OBJECT_FOREIGN_SERVER;
   10449          68 :                     n->object = (Node *) makeString($3);
   10450          68 :                     n->newowner = $6;
   10451          68 :                     $$ = (Node *) n;
   10452             :                 }
   10453             :             | ALTER EVENT TRIGGER name OWNER TO RoleSpec
   10454             :                 {
   10455          14 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10456             : 
   10457          14 :                     n->objectType = OBJECT_EVENT_TRIGGER;
   10458          14 :                     n->object = (Node *) makeString($4);
   10459          14 :                     n->newowner = $7;
   10460          14 :                     $$ = (Node *) n;
   10461             :                 }
   10462             :             | ALTER PUBLICATION name OWNER TO RoleSpec
   10463             :                 {
   10464          26 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10465             : 
   10466          26 :                     n->objectType = OBJECT_PUBLICATION;
   10467          26 :                     n->object = (Node *) makeString($3);
   10468          26 :                     n->newowner = $6;
   10469          26 :                     $$ = (Node *) n;
   10470             :                 }
   10471             :             | ALTER SUBSCRIPTION name OWNER TO RoleSpec
   10472             :                 {
   10473          18 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10474             : 
   10475          18 :                     n->objectType = OBJECT_SUBSCRIPTION;
   10476          18 :                     n->object = (Node *) makeString($3);
   10477          18 :                     n->newowner = $6;
   10478          18 :                     $$ = (Node *) n;
   10479             :                 }
   10480             :         ;
   10481             : 
   10482             : 
   10483             : /*****************************************************************************
   10484             :  *
   10485             :  * CREATE PUBLICATION name [WITH options]
   10486             :  *
   10487             :  * CREATE PUBLICATION FOR ALL TABLES [WITH options]
   10488             :  *
   10489             :  * CREATE PUBLICATION FOR pub_obj [, ...] [WITH options]
   10490             :  *
   10491             :  * pub_obj is one of:
   10492             :  *
   10493             :  *      TABLE table [, ...]
   10494             :  *      TABLES IN SCHEMA schema [, ...]
   10495             :  *
   10496             :  *****************************************************************************/
   10497             : 
   10498             : CreatePublicationStmt:
   10499             :             CREATE PUBLICATION name opt_definition
   10500             :                 {
   10501         108 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10502             : 
   10503         108 :                     n->pubname = $3;
   10504         108 :                     n->options = $4;
   10505         108 :                     $$ = (Node *) n;
   10506             :                 }
   10507             :             | CREATE PUBLICATION name FOR ALL TABLES opt_definition
   10508             :                 {
   10509          62 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10510             : 
   10511          62 :                     n->pubname = $3;
   10512          62 :                     n->options = $7;
   10513          62 :                     n->for_all_tables = true;
   10514          62 :                     $$ = (Node *) n;
   10515             :                 }
   10516             :             | CREATE PUBLICATION name FOR pub_obj_list opt_definition
   10517             :                 {
   10518         550 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10519             : 
   10520         550 :                     n->pubname = $3;
   10521         550 :                     n->options = $6;
   10522         550 :                     n->pubobjects = (List *) $5;
   10523         550 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10524         520 :                     $$ = (Node *) n;
   10525             :                 }
   10526             :         ;
   10527             : 
   10528             : /*
   10529             :  * FOR TABLE and FOR TABLES IN SCHEMA specifications
   10530             :  *
   10531             :  * This rule parses publication objects with and without keyword prefixes.
   10532             :  *
   10533             :  * The actual type of the object without keyword prefix depends on the previous
   10534             :  * one with keyword prefix. It will be preprocessed in preprocess_pubobj_list().
   10535             :  *
   10536             :  * For the object without keyword prefix, we cannot just use relation_expr here,
   10537             :  * because some extended expressions in relation_expr cannot be used as a
   10538             :  * schemaname and we cannot differentiate it. So, we extract the rules from
   10539             :  * relation_expr here.
   10540             :  */
   10541             : PublicationObjSpec:
   10542             :             TABLE relation_expr opt_column_list OptWhereClause
   10543             :                 {
   10544        1158 :                     $$ = makeNode(PublicationObjSpec);
   10545        1158 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLE;
   10546        1158 :                     $$->pubtable = makeNode(PublicationTable);
   10547        1158 :                     $$->pubtable->relation = $2;
   10548        1158 :                     $$->pubtable->columns = $3;
   10549        1158 :                     $$->pubtable->whereClause = $4;
   10550             :                 }
   10551             :             | TABLES IN_P SCHEMA ColId
   10552             :                 {
   10553         332 :                     $$ = makeNode(PublicationObjSpec);
   10554         332 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   10555         332 :                     $$->name = $4;
   10556         332 :                     $$->location = @4;
   10557             :                 }
   10558             :             | TABLES IN_P SCHEMA CURRENT_SCHEMA
   10559             :                 {
   10560          18 :                     $$ = makeNode(PublicationObjSpec);
   10561          18 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   10562          18 :                     $$->location = @4;
   10563             :                 }
   10564             :             | ColId opt_column_list OptWhereClause
   10565             :                 {
   10566         130 :                     $$ = makeNode(PublicationObjSpec);
   10567         130 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10568             :                     /*
   10569             :                      * If either a row filter or column list is specified, create
   10570             :                      * a PublicationTable object.
   10571             :                      */
   10572         130 :                     if ($2 || $3)
   10573             :                     {
   10574             :                         /*
   10575             :                          * The OptWhereClause must be stored here but it is
   10576             :                          * valid only for tables. For non-table objects, an
   10577             :                          * error will be thrown later via
   10578             :                          * preprocess_pubobj_list().
   10579             :                          */
   10580          42 :                         $$->pubtable = makeNode(PublicationTable);
   10581          42 :                         $$->pubtable->relation = makeRangeVar(NULL, $1, @1);
   10582          42 :                         $$->pubtable->columns = $2;
   10583          42 :                         $$->pubtable->whereClause = $3;
   10584             :                     }
   10585             :                     else
   10586             :                     {
   10587          88 :                         $$->name = $1;
   10588             :                     }
   10589         130 :                     $$->location = @1;
   10590             :                 }
   10591             :             | ColId indirection opt_column_list OptWhereClause
   10592             :                 {
   10593          32 :                     $$ = makeNode(PublicationObjSpec);
   10594          32 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10595          32 :                     $$->pubtable = makeNode(PublicationTable);
   10596          32 :                     $$->pubtable->relation = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   10597          32 :                     $$->pubtable->columns = $3;
   10598          32 :                     $$->pubtable->whereClause = $4;
   10599          32 :                     $$->location = @1;
   10600             :                 }
   10601             :             /* grammar like tablename * , ONLY tablename, ONLY ( tablename ) */
   10602             :             | extended_relation_expr opt_column_list OptWhereClause
   10603             :                 {
   10604           6 :                     $$ = makeNode(PublicationObjSpec);
   10605           6 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10606           6 :                     $$->pubtable = makeNode(PublicationTable);
   10607           6 :                     $$->pubtable->relation = $1;
   10608           6 :                     $$->pubtable->columns = $2;
   10609           6 :                     $$->pubtable->whereClause = $3;
   10610             :                 }
   10611             :             | CURRENT_SCHEMA
   10612             :                 {
   10613          18 :                     $$ = makeNode(PublicationObjSpec);
   10614          18 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10615          18 :                     $$->location = @1;
   10616             :                 }
   10617             :                 ;
   10618             : 
   10619             : pub_obj_list:   PublicationObjSpec
   10620        1470 :                     { $$ = list_make1($1); }
   10621             :             | pub_obj_list ',' PublicationObjSpec
   10622         224 :                     { $$ = lappend($1, $3); }
   10623             :     ;
   10624             : 
   10625             : /*****************************************************************************
   10626             :  *
   10627             :  * ALTER PUBLICATION name SET ( options )
   10628             :  *
   10629             :  * ALTER PUBLICATION name ADD pub_obj [, ...]
   10630             :  *
   10631             :  * ALTER PUBLICATION name DROP pub_obj [, ...]
   10632             :  *
   10633             :  * ALTER PUBLICATION name SET pub_obj [, ...]
   10634             :  *
   10635             :  * pub_obj is one of:
   10636             :  *
   10637             :  *      TABLE table_name [, ...]
   10638             :  *      TABLES IN SCHEMA schema_name [, ...]
   10639             :  *
   10640             :  *****************************************************************************/
   10641             : 
   10642             : AlterPublicationStmt:
   10643             :             ALTER PUBLICATION name SET definition
   10644             :                 {
   10645         110 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10646             : 
   10647         110 :                     n->pubname = $3;
   10648         110 :                     n->options = $5;
   10649         110 :                     $$ = (Node *) n;
   10650             :                 }
   10651             :             | ALTER PUBLICATION name ADD_P pub_obj_list
   10652             :                 {
   10653         332 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10654             : 
   10655         332 :                     n->pubname = $3;
   10656         332 :                     n->pubobjects = $5;
   10657         332 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10658         326 :                     n->action = AP_AddObjects;
   10659         326 :                     $$ = (Node *) n;
   10660             :                 }
   10661             :             | ALTER PUBLICATION name SET pub_obj_list
   10662             :                 {
   10663         440 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10664             : 
   10665         440 :                     n->pubname = $3;
   10666         440 :                     n->pubobjects = $5;
   10667         440 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10668         440 :                     n->action = AP_SetObjects;
   10669         440 :                     $$ = (Node *) n;
   10670             :                 }
   10671             :             | ALTER PUBLICATION name DROP pub_obj_list
   10672             :                 {
   10673         148 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10674             : 
   10675         148 :                     n->pubname = $3;
   10676         148 :                     n->pubobjects = $5;
   10677         148 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10678         148 :                     n->action = AP_DropObjects;
   10679         148 :                     $$ = (Node *) n;
   10680             :                 }
   10681             :         ;
   10682             : 
   10683             : /*****************************************************************************
   10684             :  *
   10685             :  * CREATE SUBSCRIPTION name ...
   10686             :  *
   10687             :  *****************************************************************************/
   10688             : 
   10689             : CreateSubscriptionStmt:
   10690             :             CREATE SUBSCRIPTION name CONNECTION Sconst PUBLICATION name_list opt_definition
   10691             :                 {
   10692             :                     CreateSubscriptionStmt *n =
   10693         422 :                         makeNode(CreateSubscriptionStmt);
   10694         422 :                     n->subname = $3;
   10695         422 :                     n->conninfo = $5;
   10696         422 :                     n->publication = $7;
   10697         422 :                     n->options = $8;
   10698         422 :                     $$ = (Node *) n;
   10699             :                 }
   10700             :         ;
   10701             : 
   10702             : /*****************************************************************************
   10703             :  *
   10704             :  * ALTER SUBSCRIPTION name ...
   10705             :  *
   10706             :  *****************************************************************************/
   10707             : 
   10708             : AlterSubscriptionStmt:
   10709             :             ALTER SUBSCRIPTION name SET definition
   10710             :                 {
   10711             :                     AlterSubscriptionStmt *n =
   10712         180 :                         makeNode(AlterSubscriptionStmt);
   10713             : 
   10714         180 :                     n->kind = ALTER_SUBSCRIPTION_OPTIONS;
   10715         180 :                     n->subname = $3;
   10716         180 :                     n->options = $5;
   10717         180 :                     $$ = (Node *) n;
   10718             :                 }
   10719             :             | ALTER SUBSCRIPTION name CONNECTION Sconst
   10720             :                 {
   10721             :                     AlterSubscriptionStmt *n =
   10722          26 :                         makeNode(AlterSubscriptionStmt);
   10723             : 
   10724          26 :                     n->kind = ALTER_SUBSCRIPTION_CONNECTION;
   10725          26 :                     n->subname = $3;
   10726          26 :                     n->conninfo = $5;
   10727          26 :                     $$ = (Node *) n;
   10728             :                 }
   10729             :             | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
   10730             :                 {
   10731             :                     AlterSubscriptionStmt *n =
   10732          56 :                         makeNode(AlterSubscriptionStmt);
   10733             : 
   10734          56 :                     n->kind = ALTER_SUBSCRIPTION_REFRESH;
   10735          56 :                     n->subname = $3;
   10736          56 :                     n->options = $6;
   10737          56 :                     $$ = (Node *) n;
   10738             :                 }
   10739             :             | ALTER SUBSCRIPTION name ADD_P PUBLICATION name_list opt_definition
   10740             :                 {
   10741             :                     AlterSubscriptionStmt *n =
   10742          28 :                         makeNode(AlterSubscriptionStmt);
   10743             : 
   10744          28 :                     n->kind = ALTER_SUBSCRIPTION_ADD_PUBLICATION;
   10745          28 :                     n->subname = $3;
   10746          28 :                     n->publication = $6;
   10747          28 :                     n->options = $7;
   10748          28 :                     $$ = (Node *) n;
   10749             :                 }
   10750             :             | ALTER SUBSCRIPTION name DROP PUBLICATION name_list opt_definition
   10751             :                 {
   10752             :                     AlterSubscriptionStmt *n =
   10753          26 :                         makeNode(AlterSubscriptionStmt);
   10754             : 
   10755          26 :                     n->kind = ALTER_SUBSCRIPTION_DROP_PUBLICATION;
   10756          26 :                     n->subname = $3;
   10757          26 :                     n->publication = $6;
   10758          26 :                     n->options = $7;
   10759          26 :                     $$ = (Node *) n;
   10760             :                 }
   10761             :             | ALTER SUBSCRIPTION name SET PUBLICATION name_list opt_definition
   10762             :                 {
   10763             :                     AlterSubscriptionStmt *n =
   10764          40 :                         makeNode(AlterSubscriptionStmt);
   10765             : 
   10766          40 :                     n->kind = ALTER_SUBSCRIPTION_SET_PUBLICATION;
   10767          40 :                     n->subname = $3;
   10768          40 :                     n->publication = $6;
   10769          40 :                     n->options = $7;
   10770          40 :                     $$ = (Node *) n;
   10771             :                 }
   10772             :             | ALTER SUBSCRIPTION name ENABLE_P
   10773             :                 {
   10774             :                     AlterSubscriptionStmt *n =
   10775          46 :                         makeNode(AlterSubscriptionStmt);
   10776             : 
   10777          46 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   10778          46 :                     n->subname = $3;
   10779          46 :                     n->options = list_make1(makeDefElem("enabled",
   10780             :                                             (Node *) makeBoolean(true), @1));
   10781          46 :                     $$ = (Node *) n;
   10782             :                 }
   10783             :             | ALTER SUBSCRIPTION name DISABLE_P
   10784             :                 {
   10785             :                     AlterSubscriptionStmt *n =
   10786          30 :                         makeNode(AlterSubscriptionStmt);
   10787             : 
   10788          30 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   10789          30 :                     n->subname = $3;
   10790          30 :                     n->options = list_make1(makeDefElem("enabled",
   10791             :                                             (Node *) makeBoolean(false), @1));
   10792          30 :                     $$ = (Node *) n;
   10793             :                 }
   10794             :             | ALTER SUBSCRIPTION name SKIP definition
   10795             :                 {
   10796             :                     AlterSubscriptionStmt *n =
   10797          24 :                         makeNode(AlterSubscriptionStmt);
   10798             : 
   10799          24 :                     n->kind = ALTER_SUBSCRIPTION_SKIP;
   10800          24 :                     n->subname = $3;
   10801          24 :                     n->options = $5;
   10802          24 :                     $$ = (Node *) n;
   10803             :                 }
   10804             :         ;
   10805             : 
   10806             : /*****************************************************************************
   10807             :  *
   10808             :  * DROP SUBSCRIPTION [ IF EXISTS ] name
   10809             :  *
   10810             :  *****************************************************************************/
   10811             : 
   10812             : DropSubscriptionStmt: DROP SUBSCRIPTION name opt_drop_behavior
   10813             :                 {
   10814         186 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   10815             : 
   10816         186 :                     n->subname = $3;
   10817         186 :                     n->missing_ok = false;
   10818         186 :                     n->behavior = $4;
   10819         186 :                     $$ = (Node *) n;
   10820             :                 }
   10821             :                 |  DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
   10822             :                 {
   10823           6 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   10824             : 
   10825           6 :                     n->subname = $5;
   10826           6 :                     n->missing_ok = true;
   10827           6 :                     n->behavior = $6;
   10828           6 :                     $$ = (Node *) n;
   10829             :                 }
   10830             :         ;
   10831             : 
   10832             : /*****************************************************************************
   10833             :  *
   10834             :  *      QUERY:  Define Rewrite Rule
   10835             :  *
   10836             :  *****************************************************************************/
   10837             : 
   10838             : RuleStmt:   CREATE opt_or_replace RULE name AS
   10839             :             ON event TO qualified_name where_clause
   10840             :             DO opt_instead RuleActionList
   10841             :                 {
   10842        1034 :                     RuleStmt   *n = makeNode(RuleStmt);
   10843             : 
   10844        1034 :                     n->replace = $2;
   10845        1034 :                     n->relation = $9;
   10846        1034 :                     n->rulename = $4;
   10847        1034 :                     n->whereClause = $10;
   10848        1034 :                     n->event = $7;
   10849        1034 :                     n->instead = $12;
   10850        1034 :                     n->actions = $13;
   10851        1034 :                     $$ = (Node *) n;
   10852             :                 }
   10853             :         ;
   10854             : 
   10855             : RuleActionList:
   10856         142 :             NOTHING                                 { $$ = NIL; }
   10857         846 :             | RuleActionStmt                        { $$ = list_make1($1); }
   10858          46 :             | '(' RuleActionMulti ')'               { $$ = $2; }
   10859             :         ;
   10860             : 
   10861             : /* the thrashing around here is to discard "empty" statements... */
   10862             : RuleActionMulti:
   10863             :             RuleActionMulti ';' RuleActionStmtOrEmpty
   10864          62 :                 { if ($3 != NULL)
   10865          46 :                     $$ = lappend($1, $3);
   10866             :                   else
   10867          16 :                     $$ = $1;
   10868             :                 }
   10869             :             | RuleActionStmtOrEmpty
   10870          46 :                 { if ($1 != NULL)
   10871          46 :                     $$ = list_make1($1);
   10872             :                   else
   10873           0 :                     $$ = NIL;
   10874             :                 }
   10875             :         ;
   10876             : 
   10877             : RuleActionStmt:
   10878             :             SelectStmt
   10879             :             | InsertStmt
   10880             :             | UpdateStmt
   10881             :             | DeleteStmt
   10882             :             | NotifyStmt
   10883             :         ;
   10884             : 
   10885             : RuleActionStmtOrEmpty:
   10886          92 :             RuleActionStmt                          { $$ = $1; }
   10887          16 :             |   /*EMPTY*/                           { $$ = NULL; }
   10888             :         ;
   10889             : 
   10890          18 : event:      SELECT                                  { $$ = CMD_SELECT; }
   10891         386 :             | UPDATE                                { $$ = CMD_UPDATE; }
   10892         158 :             | DELETE_P                              { $$ = CMD_DELETE; }
   10893         472 :             | INSERT                                { $$ = CMD_INSERT; }
   10894             :          ;
   10895             : 
   10896             : opt_instead:
   10897         714 :             INSTEAD                                 { $$ = true; }
   10898         156 :             | ALSO                                  { $$ = false; }
   10899         164 :             | /*EMPTY*/                             { $$ = false; }
   10900             :         ;
   10901             : 
   10902             : 
   10903             : /*****************************************************************************
   10904             :  *
   10905             :  *      QUERY:
   10906             :  *              NOTIFY <identifier> can appear both in rule bodies and
   10907             :  *              as a query-level command
   10908             :  *
   10909             :  *****************************************************************************/
   10910             : 
   10911             : NotifyStmt: NOTIFY ColId notify_payload
   10912             :                 {
   10913         122 :                     NotifyStmt *n = makeNode(NotifyStmt);
   10914             : 
   10915         122 :                     n->conditionname = $2;
   10916         122 :                     n->payload = $3;
   10917         122 :                     $$ = (Node *) n;
   10918             :                 }
   10919             :         ;
   10920             : 
   10921             : notify_payload:
   10922          62 :             ',' Sconst                          { $$ = $2; }
   10923          60 :             | /*EMPTY*/                         { $$ = NULL; }
   10924             :         ;
   10925             : 
   10926             : ListenStmt: LISTEN ColId
   10927             :                 {
   10928          74 :                     ListenStmt *n = makeNode(ListenStmt);
   10929             : 
   10930          74 :                     n->conditionname = $2;
   10931          74 :                     $$ = (Node *) n;
   10932             :                 }
   10933             :         ;
   10934             : 
   10935             : UnlistenStmt:
   10936             :             UNLISTEN ColId
   10937             :                 {
   10938           6 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   10939             : 
   10940           6 :                     n->conditionname = $2;
   10941           6 :                     $$ = (Node *) n;
   10942             :                 }
   10943             :             | UNLISTEN '*'
   10944             :                 {
   10945          32 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   10946             : 
   10947          32 :                     n->conditionname = NULL;
   10948          32 :                     $$ = (Node *) n;
   10949             :                 }
   10950             :         ;
   10951             : 
   10952             : 
   10953             : /*****************************************************************************
   10954             :  *
   10955             :  *      Transactions:
   10956             :  *
   10957             :  *      BEGIN / COMMIT / ROLLBACK
   10958             :  *      (also older versions END / ABORT)
   10959             :  *
   10960             :  *****************************************************************************/
   10961             : 
   10962             : TransactionStmt:
   10963             :             ABORT_P opt_transaction opt_transaction_chain
   10964             :                 {
   10965         204 :                     TransactionStmt *n = makeNode(TransactionStmt);
   10966             : 
   10967         204 :                     n->kind = TRANS_STMT_ROLLBACK;
   10968         204 :                     n->options = NIL;
   10969         204 :                     n->chain = $3;
   10970         204 :                     n->location = -1;
   10971         204 :                     $$ = (Node *) n;
   10972             :                 }
   10973             :             | START TRANSACTION transaction_mode_list_or_empty
   10974             :                 {
   10975        1578 :                     TransactionStmt *n = makeNode(TransactionStmt);
   10976             : 
   10977        1578 :                     n->kind = TRANS_STMT_START;
   10978        1578 :                     n->options = $3;
   10979        1578 :                     n->location = -1;
   10980        1578 :                     $$ = (Node *) n;
   10981             :                 }
   10982             :             | COMMIT opt_transaction opt_transaction_chain
   10983             :                 {
   10984       11312 :                     TransactionStmt *n = makeNode(TransactionStmt);
   10985             : 
   10986       11312 :                     n->kind = TRANS_STMT_COMMIT;
   10987       11312 :                     n->options = NIL;
   10988       11312 :                     n->chain = $3;
   10989       11312 :                     n->location = -1;
   10990       11312 :                     $$ = (Node *) n;
   10991             :                 }
   10992             :             | ROLLBACK opt_transaction opt_transaction_chain
   10993             :                 {
   10994        2360 :                     TransactionStmt *n = makeNode(TransactionStmt);
   10995             : 
   10996        2360 :                     n->kind = TRANS_STMT_ROLLBACK;
   10997        2360 :                     n->options = NIL;
   10998        2360 :                     n->chain = $3;
   10999        2360 :                     n->location = -1;
   11000        2360 :                     $$ = (Node *) n;
   11001             :                 }
   11002             :             | SAVEPOINT ColId
   11003             :                 {
   11004        1994 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11005             : 
   11006        1994 :                     n->kind = TRANS_STMT_SAVEPOINT;
   11007        1994 :                     n->savepoint_name = $2;
   11008        1994 :                     n->location = @2;
   11009        1994 :                     $$ = (Node *) n;
   11010             :                 }
   11011             :             | RELEASE SAVEPOINT ColId
   11012             :                 {
   11013         208 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11014             : 
   11015         208 :                     n->kind = TRANS_STMT_RELEASE;
   11016         208 :                     n->savepoint_name = $3;
   11017         208 :                     n->location = @3;
   11018         208 :                     $$ = (Node *) n;
   11019             :                 }
   11020             :             | RELEASE ColId
   11021             :                 {
   11022          86 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11023             : 
   11024          86 :                     n->kind = TRANS_STMT_RELEASE;
   11025          86 :                     n->savepoint_name = $2;
   11026          86 :                     n->location = @2;
   11027          86 :                     $$ = (Node *) n;
   11028             :                 }
   11029             :             | ROLLBACK opt_transaction TO SAVEPOINT ColId
   11030             :                 {
   11031         218 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11032             : 
   11033         218 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   11034         218 :                     n->savepoint_name = $5;
   11035         218 :                     n->location = @5;
   11036         218 :                     $$ = (Node *) n;
   11037             :                 }
   11038             :             | ROLLBACK opt_transaction TO ColId
   11039             :                 {
   11040         494 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11041             : 
   11042         494 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   11043         494 :                     n->savepoint_name = $4;
   11044         494 :                     n->location = @4;
   11045         494 :                     $$ = (Node *) n;
   11046             :                 }
   11047             :             | PREPARE TRANSACTION Sconst
   11048             :                 {
   11049         834 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11050             : 
   11051         834 :                     n->kind = TRANS_STMT_PREPARE;
   11052         834 :                     n->gid = $3;
   11053         834 :                     n->location = @3;
   11054         834 :                     $$ = (Node *) n;
   11055             :                 }
   11056             :             | COMMIT PREPARED Sconst
   11057             :                 {
   11058         674 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11059             : 
   11060         674 :                     n->kind = TRANS_STMT_COMMIT_PREPARED;
   11061         674 :                     n->gid = $3;
   11062         674 :                     n->location = @3;
   11063         674 :                     $$ = (Node *) n;
   11064             :                 }
   11065             :             | ROLLBACK PREPARED Sconst
   11066             :                 {
   11067          74 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11068             : 
   11069          74 :                     n->kind = TRANS_STMT_ROLLBACK_PREPARED;
   11070          74 :                     n->gid = $3;
   11071          74 :                     n->location = @3;
   11072          74 :                     $$ = (Node *) n;
   11073             :                 }
   11074             :         ;
   11075             : 
   11076             : TransactionStmtLegacy:
   11077             :             BEGIN_P opt_transaction transaction_mode_list_or_empty
   11078             :                 {
   11079       13778 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11080             : 
   11081       13778 :                     n->kind = TRANS_STMT_BEGIN;
   11082       13778 :                     n->options = $3;
   11083       13778 :                     n->location = -1;
   11084       13778 :                     $$ = (Node *) n;
   11085             :                 }
   11086             :             | END_P opt_transaction opt_transaction_chain
   11087             :                 {
   11088         360 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11089             : 
   11090         360 :                     n->kind = TRANS_STMT_COMMIT;
   11091         360 :                     n->options = NIL;
   11092         360 :                     n->chain = $3;
   11093         360 :                     n->location = -1;
   11094         360 :                     $$ = (Node *) n;
   11095             :                 }
   11096             :         ;
   11097             : 
   11098             : opt_transaction:    WORK
   11099             :             | TRANSACTION
   11100             :             | /*EMPTY*/
   11101             :         ;
   11102             : 
   11103             : transaction_mode_item:
   11104             :             ISOLATION LEVEL iso_level
   11105        6514 :                     { $$ = makeDefElem("transaction_isolation",
   11106        6514 :                                        makeStringConst($3, @3), @1); }
   11107             :             | READ ONLY
   11108        1290 :                     { $$ = makeDefElem("transaction_read_only",
   11109        1290 :                                        makeIntConst(true, @1), @1); }
   11110             :             | READ WRITE
   11111          88 :                     { $$ = makeDefElem("transaction_read_only",
   11112          88 :                                        makeIntConst(false, @1), @1); }
   11113             :             | DEFERRABLE
   11114          44 :                     { $$ = makeDefElem("transaction_deferrable",
   11115             :                                        makeIntConst(true, @1), @1); }
   11116             :             | NOT DEFERRABLE
   11117          10 :                     { $$ = makeDefElem("transaction_deferrable",
   11118          10 :                                        makeIntConst(false, @1), @1); }
   11119             :         ;
   11120             : 
   11121             : /* Syntax with commas is SQL-spec, without commas is Postgres historical */
   11122             : transaction_mode_list:
   11123             :             transaction_mode_item
   11124        6724 :                     { $$ = list_make1($1); }
   11125             :             | transaction_mode_list ',' transaction_mode_item
   11126         872 :                     { $$ = lappend($1, $3); }
   11127             :             | transaction_mode_list transaction_mode_item
   11128         350 :                     { $$ = lappend($1, $2); }
   11129             :         ;
   11130             : 
   11131             : transaction_mode_list_or_empty:
   11132             :             transaction_mode_list
   11133             :             | /* EMPTY */
   11134        9162 :                     { $$ = NIL; }
   11135             :         ;
   11136             : 
   11137             : opt_transaction_chain:
   11138         120 :             AND CHAIN       { $$ = true; }
   11139           2 :             | AND NO CHAIN  { $$ = false; }
   11140       14114 :             | /* EMPTY */   { $$ = false; }
   11141             :         ;
   11142             : 
   11143             : 
   11144             : /*****************************************************************************
   11145             :  *
   11146             :  *  QUERY:
   11147             :  *      CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
   11148             :  *          AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
   11149             :  *
   11150             :  *****************************************************************************/
   11151             : 
   11152             : ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11153             :                 AS SelectStmt opt_check_option
   11154             :                 {
   11155       13356 :                     ViewStmt   *n = makeNode(ViewStmt);
   11156             : 
   11157       13356 :                     n->view = $4;
   11158       13356 :                     n->view->relpersistence = $2;
   11159       13356 :                     n->aliases = $5;
   11160       13356 :                     n->query = $8;
   11161       13356 :                     n->replace = false;
   11162       13356 :                     n->options = $6;
   11163       13356 :                     n->withCheckOption = $9;
   11164       13356 :                     $$ = (Node *) n;
   11165             :                 }
   11166             :         | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11167             :                 AS SelectStmt opt_check_option
   11168             :                 {
   11169         238 :                     ViewStmt   *n = makeNode(ViewStmt);
   11170             : 
   11171         238 :                     n->view = $6;
   11172         238 :                     n->view->relpersistence = $4;
   11173         238 :                     n->aliases = $7;
   11174         238 :                     n->query = $10;
   11175         238 :                     n->replace = true;
   11176         238 :                     n->options = $8;
   11177         238 :                     n->withCheckOption = $11;
   11178         238 :                     $$ = (Node *) n;
   11179             :                 }
   11180             :         | CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11181             :                 AS SelectStmt opt_check_option
   11182             :                 {
   11183           8 :                     ViewStmt   *n = makeNode(ViewStmt);
   11184             : 
   11185           8 :                     n->view = $5;
   11186           8 :                     n->view->relpersistence = $2;
   11187           8 :                     n->aliases = $7;
   11188           8 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
   11189           8 :                     n->replace = false;
   11190           8 :                     n->options = $9;
   11191           8 :                     n->withCheckOption = $12;
   11192           8 :                     if (n->withCheckOption != NO_CHECK_OPTION)
   11193           0 :                         ereport(ERROR,
   11194             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   11195             :                                  errmsg("WITH CHECK OPTION not supported on recursive views"),
   11196             :                                  parser_errposition(@12)));
   11197           8 :                     $$ = (Node *) n;
   11198             :                 }
   11199             :         | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11200             :                 AS SelectStmt opt_check_option
   11201             :                 {
   11202           6 :                     ViewStmt   *n = makeNode(ViewStmt);
   11203             : 
   11204           6 :                     n->view = $7;
   11205           6 :                     n->view->relpersistence = $4;
   11206           6 :                     n->aliases = $9;
   11207           6 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
   11208           6 :                     n->replace = true;
   11209           6 :                     n->options = $11;
   11210           6 :                     n->withCheckOption = $14;
   11211           6 :                     if (n->withCheckOption != NO_CHECK_OPTION)
   11212           0 :                         ereport(ERROR,
   11213             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   11214             :                                  errmsg("WITH CHECK OPTION not supported on recursive views"),
   11215             :                                  parser_errposition(@14)));
   11216           6 :                     $$ = (Node *) n;
   11217             :                 }
   11218             :         ;
   11219             : 
   11220             : opt_check_option:
   11221          90 :         WITH CHECK OPTION               { $$ = CASCADED_CHECK_OPTION; }
   11222           6 :         | WITH CASCADED CHECK OPTION    { $$ = CASCADED_CHECK_OPTION; }
   11223          24 :         | WITH LOCAL CHECK OPTION       { $$ = LOCAL_CHECK_OPTION; }
   11224       13488 :         | /* EMPTY */                   { $$ = NO_CHECK_OPTION; }
   11225             :         ;
   11226             : 
   11227             : /*****************************************************************************
   11228             :  *
   11229             :  *      QUERY:
   11230             :  *              LOAD "filename"
   11231             :  *
   11232             :  *****************************************************************************/
   11233             : 
   11234             : LoadStmt:   LOAD file_name
   11235             :                 {
   11236          58 :                     LoadStmt   *n = makeNode(LoadStmt);
   11237             : 
   11238          58 :                     n->filename = $2;
   11239          58 :                     $$ = (Node *) n;
   11240             :                 }
   11241             :         ;
   11242             : 
   11243             : 
   11244             : /*****************************************************************************
   11245             :  *
   11246             :  *      CREATE DATABASE
   11247             :  *
   11248             :  *****************************************************************************/
   11249             : 
   11250             : CreatedbStmt:
   11251             :             CREATE DATABASE name opt_with createdb_opt_list
   11252             :                 {
   11253         636 :                     CreatedbStmt *n = makeNode(CreatedbStmt);
   11254             : 
   11255         636 :                     n->dbname = $3;
   11256         636 :                     n->options = $5;
   11257         636 :                     $$ = (Node *) n;
   11258             :                 }
   11259             :         ;
   11260             : 
   11261             : createdb_opt_list:
   11262         486 :             createdb_opt_items                      { $$ = $1; }
   11263         174 :             | /* EMPTY */                           { $$ = NIL; }
   11264             :         ;
   11265             : 
   11266             : createdb_opt_items:
   11267         486 :             createdb_opt_item                       { $$ = list_make1($1); }
   11268         614 :             | createdb_opt_items createdb_opt_item  { $$ = lappend($1, $2); }
   11269             :         ;
   11270             : 
   11271             : createdb_opt_item:
   11272             :             createdb_opt_name opt_equal NumericOnly
   11273             :                 {
   11274         184 :                     $$ = makeDefElem($1, $3, @1);
   11275             :                 }
   11276             :             | createdb_opt_name opt_equal opt_boolean_or_string
   11277             :                 {
   11278         916 :                     $$ = makeDefElem($1, (Node *) makeString($3), @1);
   11279             :                 }
   11280             :             | createdb_opt_name opt_equal DEFAULT
   11281             :                 {
   11282           0 :                     $$ = makeDefElem($1, NULL, @1);
   11283             :                 }
   11284             :         ;
   11285             : 
   11286             : /*
   11287             :  * Ideally we'd use ColId here, but that causes shift/reduce conflicts against
   11288             :  * the ALTER DATABASE SET/RESET syntaxes.  Instead call out specific keywords
   11289             :  * we need, and allow IDENT so that database option names don't have to be
   11290             :  * parser keywords unless they are already keywords for other reasons.
   11291             :  *
   11292             :  * XXX this coding technique is fragile since if someone makes a formerly
   11293             :  * non-keyword option name into a keyword and forgets to add it here, the
   11294             :  * option will silently break.  Best defense is to provide a regression test
   11295             :  * exercising every such option, at least at the syntax level.
   11296             :  */
   11297             : createdb_opt_name:
   11298         744 :             IDENT                           { $$ = $1; }
   11299           2 :             | CONNECTION LIMIT              { $$ = pstrdup("connection_limit"); }
   11300          60 :             | ENCODING                      { $$ = pstrdup($1); }
   11301           0 :             | LOCATION                      { $$ = pstrdup($1); }
   11302           2 :             | OWNER                         { $$ = pstrdup($1); }
   11303          16 :             | TABLESPACE                    { $$ = pstrdup($1); }
   11304         276 :             | TEMPLATE                      { $$ = pstrdup($1); }
   11305             :         ;
   11306             : 
   11307             : /*
   11308             :  *  Though the equals sign doesn't match other WITH options, pg_dump uses
   11309             :  *  equals for backward compatibility, and it doesn't seem worth removing it.
   11310             :  */
   11311             : opt_equal:  '='
   11312             :             | /*EMPTY*/
   11313             :         ;
   11314             : 
   11315             : 
   11316             : /*****************************************************************************
   11317             :  *
   11318             :  *      ALTER DATABASE
   11319             :  *
   11320             :  *****************************************************************************/
   11321             : 
   11322             : AlterDatabaseStmt:
   11323             :             ALTER DATABASE name WITH createdb_opt_list
   11324             :                  {
   11325           0 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11326             : 
   11327           0 :                     n->dbname = $3;
   11328           0 :                     n->options = $5;
   11329           0 :                     $$ = (Node *) n;
   11330             :                  }
   11331             :             | ALTER DATABASE name createdb_opt_list
   11332             :                  {
   11333          24 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11334             : 
   11335          24 :                     n->dbname = $3;
   11336          24 :                     n->options = $4;
   11337          24 :                     $$ = (Node *) n;
   11338             :                  }
   11339             :             | ALTER DATABASE name SET TABLESPACE name
   11340             :                  {
   11341          10 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11342             : 
   11343          10 :                     n->dbname = $3;
   11344          10 :                     n->options = list_make1(makeDefElem("tablespace",
   11345             :                                                         (Node *) makeString($6), @6));
   11346          10 :                     $$ = (Node *) n;
   11347             :                  }
   11348             :             | ALTER DATABASE name REFRESH COLLATION VERSION_P
   11349             :                  {
   11350           6 :                     AlterDatabaseRefreshCollStmt *n = makeNode(AlterDatabaseRefreshCollStmt);
   11351             : 
   11352           6 :                     n->dbname = $3;
   11353           6 :                     $$ = (Node *) n;
   11354             :                  }
   11355             :         ;
   11356             : 
   11357             : AlterDatabaseSetStmt:
   11358             :             ALTER DATABASE name SetResetClause
   11359             :                 {
   11360        1058 :                     AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
   11361             : 
   11362        1058 :                     n->dbname = $3;
   11363        1058 :                     n->setstmt = $4;
   11364        1058 :                     $$ = (Node *) n;
   11365             :                 }
   11366             :         ;
   11367             : 
   11368             : 
   11369             : /*****************************************************************************
   11370             :  *
   11371             :  *      DROP DATABASE [ IF EXISTS ] dbname [ [ WITH ] ( options ) ]
   11372             :  *
   11373             :  * This is implicitly CASCADE, no need for drop behavior
   11374             :  *****************************************************************************/
   11375             : 
   11376             : DropdbStmt: DROP DATABASE name
   11377             :                 {
   11378          66 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11379             : 
   11380          66 :                     n->dbname = $3;
   11381          66 :                     n->missing_ok = false;
   11382          66 :                     n->options = NULL;
   11383          66 :                     $$ = (Node *) n;
   11384             :                 }
   11385             :             | DROP DATABASE IF_P EXISTS name
   11386             :                 {
   11387           4 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11388             : 
   11389           4 :                     n->dbname = $5;
   11390           4 :                     n->missing_ok = true;
   11391           4 :                     n->options = NULL;
   11392           4 :                     $$ = (Node *) n;
   11393             :                 }
   11394             :             | DROP DATABASE name opt_with '(' drop_option_list ')'
   11395             :                 {
   11396          14 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11397             : 
   11398          14 :                     n->dbname = $3;
   11399          14 :                     n->missing_ok = false;
   11400          14 :                     n->options = $6;
   11401          14 :                     $$ = (Node *) n;
   11402             :                 }
   11403             :             | DROP DATABASE IF_P EXISTS name opt_with '(' drop_option_list ')'
   11404             :                 {
   11405          12 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11406             : 
   11407          12 :                     n->dbname = $5;
   11408          12 :                     n->missing_ok = true;
   11409          12 :                     n->options = $8;
   11410          12 :                     $$ = (Node *) n;
   11411             :                 }
   11412             :         ;
   11413             : 
   11414             : drop_option_list:
   11415             :             drop_option
   11416             :                 {
   11417          26 :                     $$ = list_make1((Node *) $1);
   11418             :                 }
   11419             :             | drop_option_list ',' drop_option
   11420             :                 {
   11421           0 :                     $$ = lappend($1, (Node *) $3);
   11422             :                 }
   11423             :         ;
   11424             : 
   11425             : /*
   11426             :  * Currently only the FORCE option is supported, but the syntax is designed
   11427             :  * to be extensible so that we can add more options in the future if required.
   11428             :  */
   11429             : drop_option:
   11430             :             FORCE
   11431             :                 {
   11432          26 :                     $$ = makeDefElem("force", NULL, @1);
   11433             :                 }
   11434             :         ;
   11435             : 
   11436             : /*****************************************************************************
   11437             :  *
   11438             :  *      ALTER COLLATION
   11439             :  *
   11440             :  *****************************************************************************/
   11441             : 
   11442             : AlterCollationStmt: ALTER COLLATION any_name REFRESH VERSION_P
   11443             :                 {
   11444           6 :                     AlterCollationStmt *n = makeNode(AlterCollationStmt);
   11445             : 
   11446           6 :                     n->collname = $3;
   11447           6 :                     $$ = (Node *) n;
   11448             :                 }
   11449             :         ;
   11450             : 
   11451             : 
   11452             : /*****************************************************************************
   11453             :  *
   11454             :  *      ALTER SYSTEM
   11455             :  *
   11456             :  * This is used to change configuration parameters persistently.
   11457             :  *****************************************************************************/
   11458             : 
   11459             : AlterSystemStmt:
   11460             :             ALTER SYSTEM_P SET generic_set
   11461             :                 {
   11462         106 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11463             : 
   11464         106 :                     n->setstmt = $4;
   11465         106 :                     $$ = (Node *) n;
   11466             :                 }
   11467             :             | ALTER SYSTEM_P RESET generic_reset
   11468             :                 {
   11469          48 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11470             : 
   11471          48 :                     n->setstmt = $4;
   11472          48 :                     $$ = (Node *) n;
   11473             :                 }
   11474             :         ;
   11475             : 
   11476             : 
   11477             : /*****************************************************************************
   11478             :  *
   11479             :  * Manipulate a domain
   11480             :  *
   11481             :  *****************************************************************************/
   11482             : 
   11483             : CreateDomainStmt:
   11484             :             CREATE DOMAIN_P any_name opt_as Typename ColQualList
   11485             :                 {
   11486        1114 :                     CreateDomainStmt *n = makeNode(CreateDomainStmt);
   11487             : 
   11488        1114 :                     n->domainname = $3;
   11489        1114 :                     n->typeName = $5;
   11490        1114 :                     SplitColQualList($6, &n->constraints, &n->collClause,
   11491             :                                      yyscanner);
   11492        1114 :                     $$ = (Node *) n;
   11493             :                 }
   11494             :         ;
   11495             : 
   11496             : AlterDomainStmt:
   11497             :             /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
   11498             :             ALTER DOMAIN_P any_name alter_column_default
   11499             :                 {
   11500          14 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11501             : 
   11502          14 :                     n->subtype = 'T';
   11503          14 :                     n->typeName = $3;
   11504          14 :                     n->def = $4;
   11505          14 :                     $$ = (Node *) n;
   11506             :                 }
   11507             :             /* ALTER DOMAIN <domain> DROP NOT NULL */
   11508             :             | ALTER DOMAIN_P any_name DROP NOT NULL_P
   11509             :                 {
   11510          12 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11511             : 
   11512          12 :                     n->subtype = 'N';
   11513          12 :                     n->typeName = $3;
   11514          12 :                     $$ = (Node *) n;
   11515             :                 }
   11516             :             /* ALTER DOMAIN <domain> SET NOT NULL */
   11517             :             | ALTER DOMAIN_P any_name SET NOT NULL_P
   11518             :                 {
   11519          24 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11520             : 
   11521          24 :                     n->subtype = 'O';
   11522          24 :                     n->typeName = $3;
   11523          24 :                     $$ = (Node *) n;
   11524             :                 }
   11525             :             /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
   11526             :             | ALTER DOMAIN_P any_name ADD_P TableConstraint
   11527             :                 {
   11528         168 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11529             : 
   11530         168 :                     n->subtype = 'C';
   11531         168 :                     n->typeName = $3;
   11532         168 :                     n->def = $5;
   11533         168 :                     $$ = (Node *) n;
   11534             :                 }
   11535             :             /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
   11536             :             | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
   11537             :                 {
   11538          48 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11539             : 
   11540          48 :                     n->subtype = 'X';
   11541          48 :                     n->typeName = $3;
   11542          48 :                     n->name = $6;
   11543          48 :                     n->behavior = $7;
   11544          48 :                     n->missing_ok = false;
   11545          48 :                     $$ = (Node *) n;
   11546             :                 }
   11547             :             /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
   11548             :             | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
   11549             :                 {
   11550           6 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11551             : 
   11552           6 :                     n->subtype = 'X';
   11553           6 :                     n->typeName = $3;
   11554           6 :                     n->name = $8;
   11555           6 :                     n->behavior = $9;
   11556           6 :                     n->missing_ok = true;
   11557           6 :                     $$ = (Node *) n;
   11558             :                 }
   11559             :             /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
   11560             :             | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
   11561             :                 {
   11562          12 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11563             : 
   11564          12 :                     n->subtype = 'V';
   11565          12 :                     n->typeName = $3;
   11566          12 :                     n->name = $6;
   11567          12 :                     $$ = (Node *) n;
   11568             :                 }
   11569             :             ;
   11570             : 
   11571             : opt_as:     AS
   11572             :             | /* EMPTY */
   11573             :         ;
   11574             : 
   11575             : 
   11576             : /*****************************************************************************
   11577             :  *
   11578             :  * Manipulate a text search dictionary or configuration
   11579             :  *
   11580             :  *****************************************************************************/
   11581             : 
   11582             : AlterTSDictionaryStmt:
   11583             :             ALTER TEXT_P SEARCH DICTIONARY any_name definition
   11584             :                 {
   11585          40 :                     AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
   11586             : 
   11587          40 :                     n->dictname = $5;
   11588          40 :                     n->options = $6;
   11589          40 :                     $$ = (Node *) n;
   11590             :                 }
   11591             :         ;
   11592             : 
   11593             : AlterTSConfigurationStmt:
   11594             :             ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
   11595             :                 {
   11596        6550 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11597             : 
   11598        6550 :                     n->kind = ALTER_TSCONFIG_ADD_MAPPING;
   11599        6550 :                     n->cfgname = $5;
   11600        6550 :                     n->tokentype = $9;
   11601        6550 :                     n->dicts = $11;
   11602        6550 :                     n->override = false;
   11603        6550 :                     n->replace = false;
   11604        6550 :                     $$ = (Node *) n;
   11605             :                 }
   11606             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
   11607             :                 {
   11608          26 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11609             : 
   11610          26 :                     n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
   11611          26 :                     n->cfgname = $5;
   11612          26 :                     n->tokentype = $9;
   11613          26 :                     n->dicts = $11;
   11614          26 :                     n->override = true;
   11615          26 :                     n->replace = false;
   11616          26 :                     $$ = (Node *) n;
   11617             :                 }
   11618             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
   11619             :                 {
   11620          18 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11621             : 
   11622          18 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT;
   11623          18 :                     n->cfgname = $5;
   11624          18 :                     n->tokentype = NIL;
   11625          18 :                     n->dicts = list_make2($9,$11);
   11626          18 :                     n->override = false;
   11627          18 :                     n->replace = true;
   11628          18 :                     $$ = (Node *) n;
   11629             :                 }
   11630             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
   11631             :                 {
   11632           0 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11633             : 
   11634           0 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN;
   11635           0 :                     n->cfgname = $5;
   11636           0 :                     n->tokentype = $9;
   11637           0 :                     n->dicts = list_make2($11,$13);
   11638           0 :                     n->override = false;
   11639           0 :                     n->replace = true;
   11640           0 :                     $$ = (Node *) n;
   11641             :                 }
   11642             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
   11643             :                 {
   11644          18 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11645             : 
   11646          18 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   11647          18 :                     n->cfgname = $5;
   11648          18 :                     n->tokentype = $9;
   11649          18 :                     n->missing_ok = false;
   11650          18 :                     $$ = (Node *) n;
   11651             :                 }
   11652             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
   11653             :                 {
   11654          12 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11655             : 
   11656          12 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   11657          12 :                     n->cfgname = $5;
   11658          12 :                     n->tokentype = $11;
   11659          12 :                     n->missing_ok = true;
   11660          12 :                     $$ = (Node *) n;
   11661             :                 }
   11662             :         ;
   11663             : 
   11664             : /* Use this if TIME or ORDINALITY after WITH should be taken as an identifier */
   11665             : any_with:   WITH
   11666             :             | WITH_LA
   11667             :         ;
   11668             : 
   11669             : 
   11670             : /*****************************************************************************
   11671             :  *
   11672             :  * Manipulate a conversion
   11673             :  *
   11674             :  *      CREATE [DEFAULT] CONVERSION <conversion_name>
   11675             :  *      FOR <encoding_name> TO <encoding_name> FROM <func_name>
   11676             :  *
   11677             :  *****************************************************************************/
   11678             : 
   11679             : CreateConversionStmt:
   11680             :             CREATE opt_default CONVERSION_P any_name FOR Sconst
   11681             :             TO Sconst FROM any_name
   11682             :             {
   11683          64 :                 CreateConversionStmt *n = makeNode(CreateConversionStmt);
   11684             : 
   11685          64 :                 n->conversion_name = $4;
   11686          64 :                 n->for_encoding_name = $6;
   11687          64 :                 n->to_encoding_name = $8;
   11688          64 :                 n->func_name = $10;
   11689          64 :                 n->def = $2;
   11690          64 :                 $$ = (Node *) n;
   11691             :             }
   11692             :         ;
   11693             : 
   11694             : /*****************************************************************************
   11695             :  *
   11696             :  *      QUERY:
   11697             :  *              CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
   11698             :  *              CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
   11699             :  *              CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
   11700             :  *
   11701             :  *****************************************************************************/
   11702             : 
   11703             : ClusterStmt:
   11704             :             CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
   11705             :                 {
   11706           0 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11707             : 
   11708           0 :                     n->relation = $5;
   11709           0 :                     n->indexname = $6;
   11710           0 :                     n->params = $3;
   11711           0 :                     $$ = (Node *) n;
   11712             :                 }
   11713             :             | CLUSTER '(' utility_option_list ')'
   11714             :                 {
   11715           0 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11716             : 
   11717           0 :                     n->relation = NULL;
   11718           0 :                     n->indexname = NULL;
   11719           0 :                     n->params = $3;
   11720           0 :                     $$ = (Node *) n;
   11721             :                 }
   11722             :             /* unparenthesized VERBOSE kept for pre-14 compatibility */
   11723             :             | CLUSTER opt_verbose qualified_name cluster_index_specification
   11724             :                 {
   11725         190 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11726             : 
   11727         190 :                     n->relation = $3;
   11728         190 :                     n->indexname = $4;
   11729         190 :                     n->params = NIL;
   11730         190 :                     if ($2)
   11731           0 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11732         190 :                     $$ = (Node *) n;
   11733             :                 }
   11734             :             /* unparenthesized VERBOSE kept for pre-17 compatibility */
   11735             :             | CLUSTER opt_verbose
   11736             :                 {
   11737          32 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11738             : 
   11739          32 :                     n->relation = NULL;
   11740          32 :                     n->indexname = NULL;
   11741          32 :                     n->params = NIL;
   11742          32 :                     if ($2)
   11743          16 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11744          32 :                     $$ = (Node *) n;
   11745             :                 }
   11746             :             /* kept for pre-8.3 compatibility */
   11747             :             | CLUSTER opt_verbose name ON qualified_name
   11748             :                 {
   11749          18 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11750             : 
   11751          18 :                     n->relation = $5;
   11752          18 :                     n->indexname = $3;
   11753          18 :                     n->params = NIL;
   11754          18 :                     if ($2)
   11755           0 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11756          18 :                     $$ = (Node *) n;
   11757             :                 }
   11758             :         ;
   11759             : 
   11760             : cluster_index_specification:
   11761         156 :             USING name              { $$ = $2; }
   11762          34 :             | /*EMPTY*/             { $$ = NULL; }
   11763             :         ;
   11764             : 
   11765             : 
   11766             : /*****************************************************************************
   11767             :  *
   11768             :  *      QUERY:
   11769             :  *              VACUUM
   11770             :  *              ANALYZE
   11771             :  *
   11772             :  *****************************************************************************/
   11773             : 
   11774             : VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relation_list
   11775             :                 {
   11776        1052 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11777             : 
   11778        1052 :                     n->options = NIL;
   11779        1052 :                     if ($2)
   11780         116 :                         n->options = lappend(n->options,
   11781         116 :                                              makeDefElem("full", NULL, @2));
   11782        1052 :                     if ($3)
   11783         142 :                         n->options = lappend(n->options,
   11784         142 :                                              makeDefElem("freeze", NULL, @3));
   11785        1052 :                     if ($4)
   11786          18 :                         n->options = lappend(n->options,
   11787          18 :                                              makeDefElem("verbose", NULL, @4));
   11788        1052 :                     if ($5)
   11789         278 :                         n->options = lappend(n->options,
   11790         278 :                                              makeDefElem("analyze", NULL, @5));
   11791        1052 :                     n->rels = $6;
   11792        1052 :                     n->is_vacuumcmd = true;
   11793        1052 :                     $$ = (Node *) n;
   11794             :                 }
   11795             :             | VACUUM '(' utility_option_list ')' opt_vacuum_relation_list
   11796             :                 {
   11797        4954 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11798             : 
   11799        4954 :                     n->options = $3;
   11800        4954 :                     n->rels = $5;
   11801        4954 :                     n->is_vacuumcmd = true;
   11802        4954 :                     $$ = (Node *) n;
   11803             :                 }
   11804             :         ;
   11805             : 
   11806             : AnalyzeStmt: analyze_keyword opt_verbose opt_vacuum_relation_list
   11807             :                 {
   11808        4258 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11809             : 
   11810        4258 :                     n->options = NIL;
   11811        4258 :                     if ($2)
   11812           0 :                         n->options = lappend(n->options,
   11813           0 :                                              makeDefElem("verbose", NULL, @2));
   11814        4258 :                     n->rels = $3;
   11815        4258 :                     n->is_vacuumcmd = false;
   11816        4258 :                     $$ = (Node *) n;
   11817             :                 }
   11818             :             | analyze_keyword '(' utility_option_list ')' opt_vacuum_relation_list
   11819             :                 {
   11820         186 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11821             : 
   11822         186 :                     n->options = $3;
   11823         186 :                     n->rels = $5;
   11824         186 :                     n->is_vacuumcmd = false;
   11825         186 :                     $$ = (Node *) n;
   11826             :                 }
   11827             :         ;
   11828             : 
   11829             : utility_option_list:
   11830             :             utility_option_elem
   11831             :                 {
   11832       17344 :                     $$ = list_make1($1);
   11833             :                 }
   11834             :             | utility_option_list ',' utility_option_elem
   11835             :                 {
   11836        7998 :                     $$ = lappend($1, $3);
   11837             :                 }
   11838             :         ;
   11839             : 
   11840             : analyze_keyword:
   11841             :             ANALYZE
   11842             :             | ANALYSE /* British */
   11843             :         ;
   11844             : 
   11845             : utility_option_elem:
   11846             :             utility_option_name utility_option_arg
   11847             :                 {
   11848       25342 :                     $$ = makeDefElem($1, $2, @1);
   11849             :                 }
   11850             :         ;
   11851             : 
   11852             : utility_option_name:
   11853       23130 :             NonReservedWord                         { $$ = $1; }
   11854        2076 :             | analyze_keyword                       { $$ = "analyze"; }
   11855         142 :             | FORMAT_LA                             { $$ = "format"; }
   11856             :         ;
   11857             : 
   11858             : utility_option_arg:
   11859       14364 :             opt_boolean_or_string                   { $$ = (Node *) makeString($1); }
   11860         368 :             | NumericOnly                           { $$ = (Node *) $1; }
   11861       10610 :             | /* EMPTY */                           { $$ = NULL; }
   11862             :         ;
   11863             : 
   11864             : opt_analyze:
   11865         278 :             analyze_keyword                         { $$ = true; }
   11866         774 :             | /*EMPTY*/                             { $$ = false; }
   11867             :         ;
   11868             : 
   11869             : opt_verbose:
   11870          34 :             VERBOSE                                 { $$ = true; }
   11871        7808 :             | /*EMPTY*/                             { $$ = false; }
   11872             :         ;
   11873             : 
   11874         116 : opt_full:   FULL                                    { $$ = true; }
   11875         936 :             | /*EMPTY*/                             { $$ = false; }
   11876             :         ;
   11877             : 
   11878         142 : opt_freeze: FREEZE                                  { $$ = true; }
   11879         910 :             | /*EMPTY*/                             { $$ = false; }
   11880             :         ;
   11881             : 
   11882             : opt_name_list:
   11883        2444 :             '(' name_list ')'                       { $$ = $2; }
   11884       12320 :             | /*EMPTY*/                             { $$ = NIL; }
   11885             :         ;
   11886             : 
   11887             : vacuum_relation:
   11888             :             qualified_name opt_name_list
   11889             :                 {
   11890       10306 :                     $$ = (Node *) makeVacuumRelation($1, InvalidOid, $2);
   11891             :                 }
   11892             :         ;
   11893             : 
   11894             : vacuum_relation_list:
   11895             :             vacuum_relation
   11896       10158 :                     { $$ = list_make1($1); }
   11897             :             | vacuum_relation_list ',' vacuum_relation
   11898         148 :                     { $$ = lappend($1, $3); }
   11899             :         ;
   11900             : 
   11901             : opt_vacuum_relation_list:
   11902       10158 :             vacuum_relation_list                    { $$ = $1; }
   11903         292 :             | /*EMPTY*/                             { $$ = NIL; }
   11904             :         ;
   11905             : 
   11906             : 
   11907             : /*****************************************************************************
   11908             :  *
   11909             :  *      QUERY:
   11910             :  *              EXPLAIN [ANALYZE] [VERBOSE] query
   11911             :  *              EXPLAIN ( options ) query
   11912             :  *
   11913             :  *****************************************************************************/
   11914             : 
   11915             : ExplainStmt:
   11916             :         EXPLAIN ExplainableStmt
   11917             :                 {
   11918        7638 :                     ExplainStmt *n = makeNode(ExplainStmt);
   11919             : 
   11920        7638 :                     n->query = $2;
   11921        7638 :                     n->options = NIL;
   11922        7638 :                     $$ = (Node *) n;
   11923             :                 }
   11924             :         | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
   11925             :                 {
   11926        2292 :                     ExplainStmt *n = makeNode(ExplainStmt);
   11927             : 
   11928        2292 :                     n->query = $4;
   11929        2292 :                     n->options = list_make1(makeDefElem("analyze", NULL, @2));
   11930        2292 :                     if ($3)
   11931           0 :                         n->options = lappend(n->options,
   11932           0 :                                              makeDefElem("verbose", NULL, @3));
   11933        2292 :                     $$ = (Node *) n;
   11934             :                 }
   11935             :         | EXPLAIN VERBOSE ExplainableStmt
   11936             :                 {
   11937           0 :                     ExplainStmt *n = makeNode(ExplainStmt);
   11938             : 
   11939           0 :                     n->query = $3;
   11940           0 :                     n->options = list_make1(makeDefElem("verbose", NULL, @2));
   11941           0 :                     $$ = (Node *) n;
   11942             :                 }
   11943             :         | EXPLAIN '(' utility_option_list ')' ExplainableStmt
   11944             :                 {
   11945       12048 :                     ExplainStmt *n = makeNode(ExplainStmt);
   11946             : 
   11947       12048 :                     n->query = $5;
   11948       12048 :                     n->options = $3;
   11949       12048 :                     $$ = (Node *) n;
   11950             :                 }
   11951             :         ;
   11952             : 
   11953             : ExplainableStmt:
   11954             :             SelectStmt
   11955             :             | InsertStmt
   11956             :             | UpdateStmt
   11957             :             | DeleteStmt
   11958             :             | MergeStmt
   11959             :             | DeclareCursorStmt
   11960             :             | CreateAsStmt
   11961             :             | CreateMatViewStmt
   11962             :             | RefreshMatViewStmt
   11963             :             | ExecuteStmt                   /* by default all are $$=$1 */
   11964             :         ;
   11965             : 
   11966             : /*****************************************************************************
   11967             :  *
   11968             :  *      QUERY:
   11969             :  *              PREPARE <plan_name> [(args, ...)] AS <query>
   11970             :  *
   11971             :  *****************************************************************************/
   11972             : 
   11973             : PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
   11974             :                 {
   11975        1668 :                     PrepareStmt *n = makeNode(PrepareStmt);
   11976             : 
   11977        1668 :                     n->name = $2;
   11978        1668 :                     n->argtypes = $3;
   11979        1668 :                     n->query = $5;
   11980        1668 :                     $$ = (Node *) n;
   11981             :                 }
   11982             :         ;
   11983             : 
   11984        1398 : prep_type_clause: '(' type_list ')'         { $$ = $2; }
   11985         276 :                 | /* EMPTY */               { $$ = NIL; }
   11986             :         ;
   11987             : 
   11988             : PreparableStmt:
   11989             :             SelectStmt
   11990             :             | InsertStmt
   11991             :             | UpdateStmt
   11992             :             | DeleteStmt
   11993             :             | MergeStmt                     /* by default all are $$=$1 */
   11994             :         ;
   11995             : 
   11996             : /*****************************************************************************
   11997             :  *
   11998             :  * EXECUTE <plan_name> [(params, ...)]
   11999             :  * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
   12000             :  *
   12001             :  *****************************************************************************/
   12002             : 
   12003             : ExecuteStmt: EXECUTE name execute_param_clause
   12004             :                 {
   12005       11688 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12006             : 
   12007       11688 :                     n->name = $2;
   12008       11688 :                     n->params = $3;
   12009       11688 :                     $$ = (Node *) n;
   12010             :                 }
   12011             :             | CREATE OptTemp TABLE create_as_target AS
   12012             :                 EXECUTE name execute_param_clause opt_with_data
   12013             :                 {
   12014          72 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   12015          72 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12016             : 
   12017          72 :                     n->name = $7;
   12018          72 :                     n->params = $8;
   12019          72 :                     ctas->query = (Node *) n;
   12020          72 :                     ctas->into = $4;
   12021          72 :                     ctas->objtype = OBJECT_TABLE;
   12022          72 :                     ctas->is_select_into = false;
   12023          72 :                     ctas->if_not_exists = false;
   12024             :                     /* cram additional flags into the IntoClause */
   12025          72 :                     $4->rel->relpersistence = $2;
   12026          72 :                     $4->skipData = !($9);
   12027          72 :                     $$ = (Node *) ctas;
   12028             :                 }
   12029             :             | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS
   12030             :                 EXECUTE name execute_param_clause opt_with_data
   12031             :                 {
   12032          12 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   12033          12 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12034             : 
   12035          12 :                     n->name = $10;
   12036          12 :                     n->params = $11;
   12037          12 :                     ctas->query = (Node *) n;
   12038          12 :                     ctas->into = $7;
   12039          12 :                     ctas->objtype = OBJECT_TABLE;
   12040          12 :                     ctas->is_select_into = false;
   12041          12 :                     ctas->if_not_exists = true;
   12042             :                     /* cram additional flags into the IntoClause */
   12043          12 :                     $7->rel->relpersistence = $2;
   12044          12 :                     $7->skipData = !($12);
   12045          12 :                     $$ = (Node *) ctas;
   12046             :                 }
   12047             :         ;
   12048             : 
   12049       10694 : execute_param_clause: '(' expr_list ')'             { $$ = $2; }
   12050        1078 :                     | /* EMPTY */                   { $$ = NIL; }
   12051             :                     ;
   12052             : 
   12053             : /*****************************************************************************
   12054             :  *
   12055             :  *      QUERY:
   12056             :  *              DEALLOCATE [PREPARE] <plan_name>
   12057             :  *
   12058             :  *****************************************************************************/
   12059             : 
   12060             : DeallocateStmt: DEALLOCATE name
   12061             :                     {
   12062        3964 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12063             : 
   12064        3964 :                         n->name = $2;
   12065        3964 :                         n->isall = false;
   12066        3964 :                         n->location = @2;
   12067        3964 :                         $$ = (Node *) n;
   12068             :                     }
   12069             :                 | DEALLOCATE PREPARE name
   12070             :                     {
   12071          20 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12072             : 
   12073          20 :                         n->name = $3;
   12074          20 :                         n->isall = false;
   12075          20 :                         n->location = @3;
   12076          20 :                         $$ = (Node *) n;
   12077             :                     }
   12078             :                 | DEALLOCATE ALL
   12079             :                     {
   12080          48 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12081             : 
   12082          48 :                         n->name = NULL;
   12083          48 :                         n->isall = true;
   12084          48 :                         n->location = -1;
   12085          48 :                         $$ = (Node *) n;
   12086             :                     }
   12087             :                 | DEALLOCATE PREPARE ALL
   12088             :                     {
   12089           2 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12090             : 
   12091           2 :                         n->name = NULL;
   12092           2 :                         n->isall = true;
   12093           2 :                         n->location = -1;
   12094           2 :                         $$ = (Node *) n;
   12095             :                     }
   12096             :         ;
   12097             : 
   12098             : /*****************************************************************************
   12099             :  *
   12100             :  *      QUERY:
   12101             :  *              INSERT STATEMENTS
   12102             :  *
   12103             :  *****************************************************************************/
   12104             : 
   12105             : InsertStmt:
   12106             :             opt_with_clause INSERT INTO insert_target insert_rest
   12107             :             opt_on_conflict returning_clause
   12108             :                 {
   12109       70874 :                     $5->relation = $4;
   12110       70874 :                     $5->onConflictClause = $6;
   12111       70874 :                     $5->returningList = $7;
   12112       70874 :                     $5->withClause = $1;
   12113       70874 :                     $$ = (Node *) $5;
   12114             :                 }
   12115             :         ;
   12116             : 
   12117             : /*
   12118             :  * Can't easily make AS optional here, because VALUES in insert_rest would
   12119             :  * have a shift/reduce conflict with VALUES as an optional alias.  We could
   12120             :  * easily allow unreserved_keywords as optional aliases, but that'd be an odd
   12121             :  * divergence from other places.  So just require AS for now.
   12122             :  */
   12123             : insert_target:
   12124             :             qualified_name
   12125             :                 {
   12126       70748 :                     $$ = $1;
   12127             :                 }
   12128             :             | qualified_name AS ColId
   12129             :                 {
   12130         126 :                     $1->alias = makeAlias($3, NIL);
   12131         126 :                     $$ = $1;
   12132             :                 }
   12133             :         ;
   12134             : 
   12135             : insert_rest:
   12136             :             SelectStmt
   12137             :                 {
   12138       47238 :                     $$ = makeNode(InsertStmt);
   12139       47238 :                     $$->cols = NIL;
   12140       47238 :                     $$->selectStmt = $1;
   12141             :                 }
   12142             :             | OVERRIDING override_kind VALUE_P SelectStmt
   12143             :                 {
   12144          96 :                     $$ = makeNode(InsertStmt);
   12145          96 :                     $$->cols = NIL;
   12146          96 :                     $$->override = $2;
   12147          96 :                     $$->selectStmt = $4;
   12148             :                 }
   12149             :             | '(' insert_column_list ')' SelectStmt
   12150             :                 {
   12151       12774 :                     $$ = makeNode(InsertStmt);
   12152       12774 :                     $$->cols = $2;
   12153       12774 :                     $$->selectStmt = $4;
   12154             :                 }
   12155             :             | '(' insert_column_list ')' OVERRIDING override_kind VALUE_P SelectStmt
   12156             :                 {
   12157           0 :                     $$ = makeNode(InsertStmt);
   12158           0 :                     $$->cols = $2;
   12159           0 :                     $$->override = $5;
   12160           0 :                     $$->selectStmt = $7;
   12161             :                 }
   12162             :             | DEFAULT VALUES
   12163             :                 {
   12164       10766 :                     $$ = makeNode(InsertStmt);
   12165       10766 :                     $$->cols = NIL;
   12166       10766 :                     $$->selectStmt = NULL;
   12167             :                 }
   12168             :         ;
   12169             : 
   12170             : override_kind:
   12171          66 :             USER        { $$ = OVERRIDING_USER_VALUE; }
   12172          60 :             | SYSTEM_P  { $$ = OVERRIDING_SYSTEM_VALUE; }
   12173             :         ;
   12174             : 
   12175             : insert_column_list:
   12176             :             insert_column_item
   12177       13038 :                     { $$ = list_make1($1); }
   12178             :             | insert_column_list ',' insert_column_item
   12179       14164 :                     { $$ = lappend($1, $3); }
   12180             :         ;
   12181             : 
   12182             : insert_column_item:
   12183             :             ColId opt_indirection
   12184             :                 {
   12185       27202 :                     $$ = makeNode(ResTarget);
   12186       27202 :                     $$->name = $1;
   12187       27202 :                     $$->indirection = check_indirection($2, yyscanner);
   12188       27202 :                     $$->val = NULL;
   12189       27202 :                     $$->location = @1;
   12190             :                 }
   12191             :         ;
   12192             : 
   12193             : opt_on_conflict:
   12194             :             ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
   12195             :                 {
   12196        1150 :                     $$ = makeNode(OnConflictClause);
   12197        1150 :                     $$->action = ONCONFLICT_UPDATE;
   12198        1150 :                     $$->infer = $3;
   12199        1150 :                     $$->targetList = $7;
   12200        1150 :                     $$->whereClause = $8;
   12201        1150 :                     $$->location = @1;
   12202             :                 }
   12203             :             |
   12204             :             ON CONFLICT opt_conf_expr DO NOTHING
   12205             :                 {
   12206         322 :                     $$ = makeNode(OnConflictClause);
   12207         322 :                     $$->action = ONCONFLICT_NOTHING;
   12208         322 :                     $$->infer = $3;
   12209         322 :                     $$->targetList = NIL;
   12210         322 :                     $$->whereClause = NULL;
   12211         322 :                     $$->location = @1;
   12212             :                 }
   12213             :             | /*EMPTY*/
   12214             :                 {
   12215       69402 :                     $$ = NULL;
   12216             :                 }
   12217             :         ;
   12218             : 
   12219             : opt_conf_expr:
   12220             :             '(' index_params ')' where_clause
   12221             :                 {
   12222        1262 :                     $$ = makeNode(InferClause);
   12223        1262 :                     $$->indexElems = $2;
   12224        1262 :                     $$->whereClause = $4;
   12225        1262 :                     $$->conname = NULL;
   12226        1262 :                     $$->location = @1;
   12227             :                 }
   12228             :             |
   12229             :             ON CONSTRAINT name
   12230             :                 {
   12231          48 :                     $$ = makeNode(InferClause);
   12232          48 :                     $$->indexElems = NIL;
   12233          48 :                     $$->whereClause = NULL;
   12234          48 :                     $$->conname = $3;
   12235          48 :                     $$->location = @1;
   12236             :                 }
   12237             :             | /*EMPTY*/
   12238             :                 {
   12239         162 :                     $$ = NULL;
   12240             :                 }
   12241             :         ;
   12242             : 
   12243             : returning_clause:
   12244        2630 :             RETURNING target_list       { $$ = $2; }
   12245       87984 :             | /* EMPTY */               { $$ = NIL; }
   12246             :         ;
   12247             : 
   12248             : 
   12249             : /*****************************************************************************
   12250             :  *
   12251             :  *      QUERY:
   12252             :  *              DELETE STATEMENTS
   12253             :  *
   12254             :  *****************************************************************************/
   12255             : 
   12256             : DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
   12257             :             using_clause where_or_current_clause returning_clause
   12258             :                 {
   12259        4476 :                     DeleteStmt *n = makeNode(DeleteStmt);
   12260             : 
   12261        4476 :                     n->relation = $4;
   12262        4476 :                     n->usingClause = $5;
   12263        4476 :                     n->whereClause = $6;
   12264        4476 :                     n->returningList = $7;
   12265        4476 :                     n->withClause = $1;
   12266        4476 :                     $$ = (Node *) n;
   12267             :                 }
   12268             :         ;
   12269             : 
   12270             : using_clause:
   12271         108 :                 USING from_list                     { $$ = $2; }
   12272        4368 :             | /*EMPTY*/                             { $$ = NIL; }
   12273             :         ;
   12274             : 
   12275             : 
   12276             : /*****************************************************************************
   12277             :  *
   12278             :  *      QUERY:
   12279             :  *              LOCK TABLE
   12280             :  *
   12281             :  *****************************************************************************/
   12282             : 
   12283             : LockStmt:   LOCK_P opt_table relation_expr_list opt_lock opt_nowait
   12284             :                 {
   12285        1080 :                     LockStmt   *n = makeNode(LockStmt);
   12286             : 
   12287        1080 :                     n->relations = $3;
   12288        1080 :                     n->mode = $4;
   12289        1080 :                     n->nowait = $5;
   12290        1080 :                     $$ = (Node *) n;
   12291             :                 }
   12292             :         ;
   12293             : 
   12294         988 : opt_lock:   IN_P lock_type MODE             { $$ = $2; }
   12295          92 :             | /*EMPTY*/                     { $$ = AccessExclusiveLock; }
   12296             :         ;
   12297             : 
   12298         498 : lock_type:  ACCESS SHARE                    { $$ = AccessShareLock; }
   12299          14 :             | ROW SHARE                     { $$ = RowShareLock; }
   12300          88 :             | ROW EXCLUSIVE                 { $$ = RowExclusiveLock; }
   12301          66 :             | SHARE UPDATE EXCLUSIVE        { $$ = ShareUpdateExclusiveLock; }
   12302          80 :             | SHARE                         { $$ = ShareLock; }
   12303          14 :             | SHARE ROW EXCLUSIVE           { $$ = ShareRowExclusiveLock; }
   12304         102 :             | EXCLUSIVE                     { $$ = ExclusiveLock; }
   12305         126 :             | ACCESS EXCLUSIVE              { $$ = AccessExclusiveLock; }
   12306             :         ;
   12307             : 
   12308         286 : opt_nowait: NOWAIT                          { $$ = true; }
   12309         824 :             | /*EMPTY*/                     { $$ = false; }
   12310             :         ;
   12311             : 
   12312             : opt_nowait_or_skip:
   12313          50 :             NOWAIT                          { $$ = LockWaitError; }
   12314         190 :             | SKIP LOCKED                   { $$ = LockWaitSkip; }
   12315        4898 :             | /*EMPTY*/                     { $$ = LockWaitBlock; }
   12316             :         ;
   12317             : 
   12318             : 
   12319             : /*****************************************************************************
   12320             :  *
   12321             :  *      QUERY:
   12322             :  *              UpdateStmt (UPDATE)
   12323             :  *
   12324             :  *****************************************************************************/
   12325             : 
   12326             : UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
   12327             :             SET set_clause_list
   12328             :             from_clause
   12329             :             where_or_current_clause
   12330             :             returning_clause
   12331             :                 {
   12332       13404 :                     UpdateStmt *n = makeNode(UpdateStmt);
   12333             : 
   12334       13404 :                     n->relation = $3;
   12335       13404 :                     n->targetList = $5;
   12336       13404 :                     n->fromClause = $6;
   12337       13404 :                     n->whereClause = $7;
   12338       13404 :                     n->returningList = $8;
   12339       13404 :                     n->withClause = $1;
   12340       13404 :                     $$ = (Node *) n;
   12341             :                 }
   12342             :         ;
   12343             : 
   12344             : set_clause_list:
   12345       15912 :             set_clause                          { $$ = $1; }
   12346        3658 :             | set_clause_list ',' set_clause    { $$ = list_concat($1,$3); }
   12347             :         ;
   12348             : 
   12349             : set_clause:
   12350             :             set_target '=' a_expr
   12351             :                 {
   12352       19386 :                     $1->val = (Node *) $3;
   12353       19386 :                     $$ = list_make1($1);
   12354             :                 }
   12355             :             | '(' set_target_list ')' '=' a_expr
   12356             :                 {
   12357         184 :                     int         ncolumns = list_length($2);
   12358         184 :                     int         i = 1;
   12359             :                     ListCell   *col_cell;
   12360             : 
   12361             :                     /* Create a MultiAssignRef source for each target */
   12362         568 :                     foreach(col_cell, $2)
   12363             :                     {
   12364         384 :                         ResTarget  *res_col = (ResTarget *) lfirst(col_cell);
   12365         384 :                         MultiAssignRef *r = makeNode(MultiAssignRef);
   12366             : 
   12367         384 :                         r->source = (Node *) $5;
   12368         384 :                         r->colno = i;
   12369         384 :                         r->ncolumns = ncolumns;
   12370         384 :                         res_col->val = (Node *) r;
   12371         384 :                         i++;
   12372             :                     }
   12373             : 
   12374         184 :                     $$ = $2;
   12375             :                 }
   12376             :         ;
   12377             : 
   12378             : set_target:
   12379             :             ColId opt_indirection
   12380             :                 {
   12381       19776 :                     $$ = makeNode(ResTarget);
   12382       19776 :                     $$->name = $1;
   12383       19776 :                     $$->indirection = check_indirection($2, yyscanner);
   12384       19776 :                     $$->val = NULL;  /* upper production sets this */
   12385       19776 :                     $$->location = @1;
   12386             :                 }
   12387             :         ;
   12388             : 
   12389             : set_target_list:
   12390         190 :             set_target                              { $$ = list_make1($1); }
   12391         200 :             | set_target_list ',' set_target        { $$ = lappend($1,$3); }
   12392             :         ;
   12393             : 
   12394             : 
   12395             : /*****************************************************************************
   12396             :  *
   12397             :  *      QUERY:
   12398             :  *              MERGE
   12399             :  *
   12400             :  *****************************************************************************/
   12401             : 
   12402             : MergeStmt:
   12403             :             opt_with_clause MERGE INTO relation_expr_opt_alias
   12404             :             USING table_ref
   12405             :             ON a_expr
   12406             :             merge_when_list
   12407             :             returning_clause
   12408             :                 {
   12409        1860 :                     MergeStmt  *m = makeNode(MergeStmt);
   12410             : 
   12411        1860 :                     m->withClause = $1;
   12412        1860 :                     m->relation = $4;
   12413        1860 :                     m->sourceRelation = $6;
   12414        1860 :                     m->joinCondition = $8;
   12415        1860 :                     m->mergeWhenClauses = $9;
   12416        1860 :                     m->returningList = $10;
   12417             : 
   12418        1860 :                     $$ = (Node *) m;
   12419             :                 }
   12420             :         ;
   12421             : 
   12422             : merge_when_list:
   12423        1860 :             merge_when_clause                       { $$ = list_make1($1); }
   12424         932 :             | merge_when_list merge_when_clause     { $$ = lappend($1,$2); }
   12425             :         ;
   12426             : 
   12427             : merge_when_clause:
   12428             :             WHEN MATCHED opt_merge_when_condition THEN merge_update
   12429             :                 {
   12430        1358 :                     $5->matched = true;
   12431        1358 :                     $5->condition = $3;
   12432             : 
   12433        1358 :                     $$ = (Node *) $5;
   12434             :                 }
   12435             :             | WHEN MATCHED opt_merge_when_condition THEN merge_delete
   12436             :                 {
   12437         404 :                     $5->matched = true;
   12438         404 :                     $5->condition = $3;
   12439             : 
   12440         404 :                     $$ = (Node *) $5;
   12441             :                 }
   12442             :             | WHEN NOT MATCHED opt_merge_when_condition THEN merge_insert
   12443             :                 {
   12444         970 :                     $6->matched = false;
   12445         970 :                     $6->condition = $4;
   12446             : 
   12447         970 :                     $$ = (Node *) $6;
   12448             :                 }
   12449             :             | WHEN MATCHED opt_merge_when_condition THEN DO NOTHING
   12450             :                 {
   12451          46 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12452             : 
   12453          46 :                     m->matched = true;
   12454          46 :                     m->commandType = CMD_NOTHING;
   12455          46 :                     m->condition = $3;
   12456             : 
   12457          46 :                     $$ = (Node *) m;
   12458             :                 }
   12459             :             | WHEN NOT MATCHED opt_merge_when_condition THEN DO NOTHING
   12460             :                 {
   12461          14 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12462             : 
   12463          14 :                     m->matched = false;
   12464          14 :                     m->commandType = CMD_NOTHING;
   12465          14 :                     m->condition = $4;
   12466             : 
   12467          14 :                     $$ = (Node *) m;
   12468             :                 }
   12469             :         ;
   12470             : 
   12471             : opt_merge_when_condition:
   12472         736 :             AND a_expr              { $$ = $2; }
   12473        2086 :             |                       { $$ = NULL; }
   12474             :         ;
   12475             : 
   12476             : merge_update:
   12477             :             UPDATE SET set_clause_list
   12478             :                 {
   12479        1358 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12480        1358 :                     n->commandType = CMD_UPDATE;
   12481        1358 :                     n->override = OVERRIDING_NOT_SET;
   12482        1358 :                     n->targetList = $3;
   12483        1358 :                     n->values = NIL;
   12484             : 
   12485        1358 :                     $$ = n;
   12486             :                 }
   12487             :         ;
   12488             : 
   12489             : merge_delete:
   12490             :             DELETE_P
   12491             :                 {
   12492         404 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12493         404 :                     n->commandType = CMD_DELETE;
   12494         404 :                     n->override = OVERRIDING_NOT_SET;
   12495         404 :                     n->targetList = NIL;
   12496         404 :                     n->values = NIL;
   12497             : 
   12498         404 :                     $$ = n;
   12499             :                 }
   12500             :         ;
   12501             : 
   12502             : merge_insert:
   12503             :             INSERT merge_values_clause
   12504             :                 {
   12505         670 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12506         670 :                     n->commandType = CMD_INSERT;
   12507         670 :                     n->override = OVERRIDING_NOT_SET;
   12508         670 :                     n->targetList = NIL;
   12509         670 :                     n->values = $2;
   12510         670 :                     $$ = n;
   12511             :                 }
   12512             :             | INSERT OVERRIDING override_kind VALUE_P merge_values_clause
   12513             :                 {
   12514           0 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12515           0 :                     n->commandType = CMD_INSERT;
   12516           0 :                     n->override = $3;
   12517           0 :                     n->targetList = NIL;
   12518           0 :                     n->values = $5;
   12519           0 :                     $$ = n;
   12520             :                 }
   12521             :             | INSERT '(' insert_column_list ')' merge_values_clause
   12522             :                 {
   12523         234 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12524         234 :                     n->commandType = CMD_INSERT;
   12525         234 :                     n->override = OVERRIDING_NOT_SET;
   12526         234 :                     n->targetList = $3;
   12527         234 :                     n->values = $5;
   12528         234 :                     $$ = n;
   12529             :                 }
   12530             :             | INSERT '(' insert_column_list ')' OVERRIDING override_kind VALUE_P merge_values_clause
   12531             :                 {
   12532          30 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12533          30 :                     n->commandType = CMD_INSERT;
   12534          30 :                     n->override = $6;
   12535          30 :                     n->targetList = $3;
   12536          30 :                     n->values = $8;
   12537          30 :                     $$ = n;
   12538             :                 }
   12539             :             | INSERT DEFAULT VALUES
   12540             :                 {
   12541          36 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12542          36 :                     n->commandType = CMD_INSERT;
   12543          36 :                     n->override = OVERRIDING_NOT_SET;
   12544          36 :                     n->targetList = NIL;
   12545          36 :                     n->values = NIL;
   12546          36 :                     $$ = n;
   12547             :                 }
   12548             :         ;
   12549             : 
   12550             : merge_values_clause:
   12551             :             VALUES '(' expr_list ')'
   12552             :                 {
   12553         934 :                     $$ = $3;
   12554             :                 }
   12555             :         ;
   12556             : 
   12557             : /*****************************************************************************
   12558             :  *
   12559             :  *      QUERY:
   12560             :  *              CURSOR STATEMENTS
   12561             :  *
   12562             :  *****************************************************************************/
   12563             : DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
   12564             :                 {
   12565        2872 :                     DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
   12566             : 
   12567        2872 :                     n->portalname = $2;
   12568             :                     /* currently we always set FAST_PLAN option */
   12569        2872 :                     n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
   12570        2872 :                     n->query = $7;
   12571        2872 :                     $$ = (Node *) n;
   12572             :                 }
   12573             :         ;
   12574             : 
   12575       11278 : cursor_name:    name                        { $$ = $1; }
   12576             :         ;
   12577             : 
   12578        2872 : cursor_options: /*EMPTY*/                   { $$ = 0; }
   12579         104 :             | cursor_options NO SCROLL      { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
   12580         240 :             | cursor_options SCROLL         { $$ = $1 | CURSOR_OPT_SCROLL; }
   12581          14 :             | cursor_options BINARY         { $$ = $1 | CURSOR_OPT_BINARY; }
   12582           0 :             | cursor_options ASENSITIVE     { $$ = $1 | CURSOR_OPT_ASENSITIVE; }
   12583           6 :             | cursor_options INSENSITIVE    { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
   12584             :         ;
   12585             : 
   12586        2774 : opt_hold: /* EMPTY */                       { $$ = 0; }
   12587          92 :             | WITH HOLD                     { $$ = CURSOR_OPT_HOLD; }
   12588           6 :             | WITHOUT HOLD                  { $$ = 0; }
   12589             :         ;
   12590             : 
   12591             : /*****************************************************************************
   12592             :  *
   12593             :  *      QUERY:
   12594             :  *              SELECT STATEMENTS
   12595             :  *
   12596             :  *****************************************************************************/
   12597             : 
   12598             : /* A complete SELECT statement looks like this.
   12599             :  *
   12600             :  * The rule returns either a single SelectStmt node or a tree of them,
   12601             :  * representing a set-operation tree.
   12602             :  *
   12603             :  * There is an ambiguity when a sub-SELECT is within an a_expr and there
   12604             :  * are excess parentheses: do the parentheses belong to the sub-SELECT or
   12605             :  * to the surrounding a_expr?  We don't really care, but bison wants to know.
   12606             :  * To resolve the ambiguity, we are careful to define the grammar so that
   12607             :  * the decision is staved off as long as possible: as long as we can keep
   12608             :  * absorbing parentheses into the sub-SELECT, we will do so, and only when
   12609             :  * it's no longer possible to do that will we decide that parens belong to
   12610             :  * the expression.  For example, in "SELECT (((SELECT 2)) + 3)" the extra
   12611             :  * parentheses are treated as part of the sub-select.  The necessity of doing
   12612             :  * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)".    Had we
   12613             :  * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
   12614             :  * SELECT viewpoint when we see the UNION.
   12615             :  *
   12616             :  * This approach is implemented by defining a nonterminal select_with_parens,
   12617             :  * which represents a SELECT with at least one outer layer of parentheses,
   12618             :  * and being careful to use select_with_parens, never '(' SelectStmt ')',
   12619             :  * in the expression grammar.  We will then have shift-reduce conflicts
   12620             :  * which we can resolve in favor of always treating '(' <select> ')' as
   12621             :  * a select_with_parens.  To resolve the conflicts, the productions that
   12622             :  * conflict with the select_with_parens productions are manually given
   12623             :  * precedences lower than the precedence of ')', thereby ensuring that we
   12624             :  * shift ')' (and then reduce to select_with_parens) rather than trying to
   12625             :  * reduce the inner <select> nonterminal to something else.  We use UMINUS
   12626             :  * precedence for this, which is a fairly arbitrary choice.
   12627             :  *
   12628             :  * To be able to define select_with_parens itself without ambiguity, we need
   12629             :  * a nonterminal select_no_parens that represents a SELECT structure with no
   12630             :  * outermost parentheses.  This is a little bit tedious, but it works.
   12631             :  *
   12632             :  * In non-expression contexts, we use SelectStmt which can represent a SELECT
   12633             :  * with or without outer parentheses.
   12634             :  */
   12635             : 
   12636             : SelectStmt: select_no_parens            %prec UMINUS
   12637             :             | select_with_parens        %prec UMINUS
   12638             :         ;
   12639             : 
   12640             : select_with_parens:
   12641       51828 :             '(' select_no_parens ')'                { $$ = $2; }
   12642         150 :             | '(' select_with_parens ')'            { $$ = $2; }
   12643             :         ;
   12644             : 
   12645             : /*
   12646             :  * This rule parses the equivalent of the standard's <query expression>.
   12647             :  * The duplicative productions are annoying, but hard to get rid of without
   12648             :  * creating shift/reduce conflicts.
   12649             :  *
   12650             :  *  The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
   12651             :  *  In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
   12652             :  *  We now support both orderings, but prefer LIMIT/OFFSET before the locking
   12653             :  * clause.
   12654             :  *  2002-08-28 bjm
   12655             :  */
   12656             : select_no_parens:
   12657      395006 :             simple_select                       { $$ = $1; }
   12658             :             | select_clause sort_clause
   12659             :                 {
   12660       54040 :                     insertSelectOptions((SelectStmt *) $1, $2, NIL,
   12661             :                                         NULL, NULL,
   12662             :                                         yyscanner);
   12663       54040 :                     $$ = $1;
   12664             :                 }
   12665             :             | select_clause opt_sort_clause for_locking_clause opt_select_limit
   12666             :                 {
   12667        4694 :                     insertSelectOptions((SelectStmt *) $1, $2, $3,
   12668        4694 :                                         $4,
   12669             :                                         NULL,
   12670             :                                         yyscanner);
   12671        4694 :                     $$ = $1;
   12672             :                 }
   12673             :             | select_clause opt_sort_clause select_limit opt_for_locking_clause
   12674             :                 {
   12675        4638 :                     insertSelectOptions((SelectStmt *) $1, $2, $4,
   12676        4638 :                                         $3,
   12677             :                                         NULL,
   12678             :                                         yyscanner);
   12679        4626 :                     $$ = $1;
   12680             :                 }
   12681             :             | with_clause select_clause
   12682             :                 {
   12683        1850 :                     insertSelectOptions((SelectStmt *) $2, NULL, NIL,
   12684             :                                         NULL,
   12685        1850 :                                         $1,
   12686             :                                         yyscanner);
   12687        1850 :                     $$ = $2;
   12688             :                 }
   12689             :             | with_clause select_clause sort_clause
   12690             :                 {
   12691         484 :                     insertSelectOptions((SelectStmt *) $2, $3, NIL,
   12692             :                                         NULL,
   12693         484 :                                         $1,
   12694             :                                         yyscanner);
   12695         484 :                     $$ = $2;
   12696             :                 }
   12697             :             | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
   12698             :                 {
   12699           6 :                     insertSelectOptions((SelectStmt *) $2, $3, $4,
   12700           6 :                                         $5,
   12701           6 :                                         $1,
   12702             :                                         yyscanner);
   12703           6 :                     $$ = $2;
   12704             :                 }
   12705             :             | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
   12706             :                 {
   12707          64 :                     insertSelectOptions((SelectStmt *) $2, $3, $5,
   12708          64 :                                         $4,
   12709          64 :                                         $1,
   12710             :                                         yyscanner);
   12711          64 :                     $$ = $2;
   12712             :                 }
   12713             :         ;
   12714             : 
   12715             : select_clause:
   12716       93252 :             simple_select                           { $$ = $1; }
   12717         472 :             | select_with_parens                    { $$ = $1; }
   12718             :         ;
   12719             : 
   12720             : /*
   12721             :  * This rule parses SELECT statements that can appear within set operations,
   12722             :  * including UNION, INTERSECT and EXCEPT.  '(' and ')' can be used to specify
   12723             :  * the ordering of the set operations.  Without '(' and ')' we want the
   12724             :  * operations to be ordered per the precedence specs at the head of this file.
   12725             :  *
   12726             :  * As with select_no_parens, simple_select cannot have outer parentheses,
   12727             :  * but can have parenthesized subclauses.
   12728             :  *
   12729             :  * It might appear that we could fold the first two alternatives into one
   12730             :  * by using opt_distinct_clause.  However, that causes a shift/reduce conflict
   12731             :  * against INSERT ... SELECT ... ON CONFLICT.  We avoid the ambiguity by
   12732             :  * requiring SELECT DISTINCT [ON] to be followed by a non-empty target_list.
   12733             :  *
   12734             :  * Note that sort clauses cannot be included at this level --- SQL requires
   12735             :  *      SELECT foo UNION SELECT bar ORDER BY baz
   12736             :  * to be parsed as
   12737             :  *      (SELECT foo UNION SELECT bar) ORDER BY baz
   12738             :  * not
   12739             :  *      SELECT foo UNION (SELECT bar ORDER BY baz)
   12740             :  * Likewise for WITH, FOR UPDATE and LIMIT.  Therefore, those clauses are
   12741             :  * described as part of the select_no_parens production, not simple_select.
   12742             :  * This does not limit functionality, because you can reintroduce these
   12743             :  * clauses inside parentheses.
   12744             :  *
   12745             :  * NOTE: only the leftmost component SelectStmt should have INTO.
   12746             :  * However, this is not checked by the grammar; parse analysis must check it.
   12747             :  */
   12748             : simple_select:
   12749             :             SELECT opt_all_clause opt_target_list
   12750             :             into_clause from_clause where_clause
   12751             :             group_clause having_clause window_clause
   12752             :                 {
   12753      412150 :                     SelectStmt *n = makeNode(SelectStmt);
   12754             : 
   12755      412150 :                     n->targetList = $3;
   12756      412150 :                     n->intoClause = $4;
   12757      412150 :                     n->fromClause = $5;
   12758      412150 :                     n->whereClause = $6;
   12759      412150 :                     n->groupClause = ($7)->list;
   12760      412150 :                     n->groupDistinct = ($7)->distinct;
   12761      412150 :                     n->havingClause = $8;
   12762      412150 :                     n->windowClause = $9;
   12763      412150 :                     $$ = (Node *) n;
   12764             :                 }
   12765             :             | SELECT distinct_clause target_list
   12766             :             into_clause from_clause where_clause
   12767             :             group_clause having_clause window_clause
   12768             :                 {
   12769        3006 :                     SelectStmt *n = makeNode(SelectStmt);
   12770             : 
   12771        3006 :                     n->distinctClause = $2;
   12772        3006 :                     n->targetList = $3;
   12773        3006 :                     n->intoClause = $4;
   12774        3006 :                     n->fromClause = $5;
   12775        3006 :                     n->whereClause = $6;
   12776        3006 :                     n->groupClause = ($7)->list;
   12777        3006 :                     n->groupDistinct = ($7)->distinct;
   12778        3006 :                     n->havingClause = $8;
   12779        3006 :                     n->windowClause = $9;
   12780        3006 :                     $$ = (Node *) n;
   12781             :                 }
   12782       58898 :             | values_clause                         { $$ = $1; }
   12783             :             | TABLE relation_expr
   12784             :                 {
   12785             :                     /* same as SELECT * FROM relation_expr */
   12786         236 :                     ColumnRef  *cr = makeNode(ColumnRef);
   12787         236 :                     ResTarget  *rt = makeNode(ResTarget);
   12788         236 :                     SelectStmt *n = makeNode(SelectStmt);
   12789             : 
   12790         236 :                     cr->fields = list_make1(makeNode(A_Star));
   12791         236 :                     cr->location = -1;
   12792             : 
   12793         236 :                     rt->name = NULL;
   12794         236 :                     rt->indirection = NIL;
   12795         236 :                     rt->val = (Node *) cr;
   12796         236 :                     rt->location = -1;
   12797             : 
   12798         236 :                     n->targetList = list_make1(rt);
   12799         236 :                     n->fromClause = list_make1($2);
   12800         236 :                     $$ = (Node *) n;
   12801             :                 }
   12802             :             | select_clause UNION set_quantifier select_clause
   12803             :                 {
   12804       13296 :                     $$ = makeSetOp(SETOP_UNION, $3 == SET_QUANTIFIER_ALL, $1, $4);
   12805             :                 }
   12806             :             | select_clause INTERSECT set_quantifier select_clause
   12807             :                 {
   12808         240 :                     $$ = makeSetOp(SETOP_INTERSECT, $3 == SET_QUANTIFIER_ALL, $1, $4);
   12809             :                 }
   12810             :             | select_clause EXCEPT set_quantifier select_clause
   12811             :                 {
   12812         432 :                     $$ = makeSetOp(SETOP_EXCEPT, $3 == SET_QUANTIFIER_ALL, $1, $4);
   12813             :                 }
   12814             :         ;
   12815             : 
   12816             : /*
   12817             :  * SQL standard WITH clause looks like:
   12818             :  *
   12819             :  * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
   12820             :  *      AS (query) [ SEARCH or CYCLE clause ]
   12821             :  *
   12822             :  * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
   12823             :  */
   12824             : with_clause:
   12825             :         WITH cte_list
   12826             :             {
   12827        1694 :                 $$ = makeNode(WithClause);
   12828        1694 :                 $$->ctes = $2;
   12829        1694 :                 $$->recursive = false;
   12830        1694 :                 $$->location = @1;
   12831             :             }
   12832             :         | WITH_LA cte_list
   12833             :             {
   12834           6 :                 $$ = makeNode(WithClause);
   12835           6 :                 $$->ctes = $2;
   12836           6 :                 $$->recursive = false;
   12837           6 :                 $$->location = @1;
   12838             :             }
   12839             :         | WITH RECURSIVE cte_list
   12840             :             {
   12841        1094 :                 $$ = makeNode(WithClause);
   12842        1094 :                 $$->ctes = $3;
   12843        1094 :                 $$->recursive = true;
   12844        1094 :                 $$->location = @1;
   12845             :             }
   12846             :         ;
   12847             : 
   12848             : cte_list:
   12849        2794 :         common_table_expr                       { $$ = list_make1($1); }
   12850        1074 :         | cte_list ',' common_table_expr        { $$ = lappend($1, $3); }
   12851             :         ;
   12852             : 
   12853             : common_table_expr:  name opt_name_list AS opt_materialized '(' PreparableStmt ')' opt_search_clause opt_cycle_clause
   12854             :             {
   12855        3868 :                 CommonTableExpr *n = makeNode(CommonTableExpr);
   12856             : 
   12857        3868 :                 n->ctename = $1;
   12858        3868 :                 n->aliascolnames = $2;
   12859        3868 :                 n->ctematerialized = $4;
   12860        3868 :                 n->ctequery = $6;
   12861        3868 :                 n->search_clause = castNode(CTESearchClause, $8);
   12862        3868 :                 n->cycle_clause = castNode(CTECycleClause, $9);
   12863        3868 :                 n->location = @1;
   12864        3868 :                 $$ = (Node *) n;
   12865             :             }
   12866             :         ;
   12867             : 
   12868             : opt_materialized:
   12869         160 :         MATERIALIZED                            { $$ = CTEMaterializeAlways; }
   12870          42 :         | NOT MATERIALIZED                      { $$ = CTEMaterializeNever; }
   12871        3666 :         | /*EMPTY*/                             { $$ = CTEMaterializeDefault; }
   12872             :         ;
   12873             : 
   12874             : opt_search_clause:
   12875             :         SEARCH DEPTH FIRST_P BY columnList SET ColId
   12876             :             {
   12877          90 :                 CTESearchClause *n = makeNode(CTESearchClause);
   12878             : 
   12879          90 :                 n->search_col_list = $5;
   12880          90 :                 n->search_breadth_first = false;
   12881          90 :                 n->search_seq_column = $7;
   12882          90 :                 n->location = @1;
   12883          90 :                 $$ = (Node *) n;
   12884             :             }
   12885             :         | SEARCH BREADTH FIRST_P BY columnList SET ColId
   12886             :             {
   12887          36 :                 CTESearchClause *n = makeNode(CTESearchClause);
   12888             : 
   12889          36 :                 n->search_col_list = $5;
   12890          36 :                 n->search_breadth_first = true;
   12891          36 :                 n->search_seq_column = $7;
   12892          36 :                 n->location = @1;
   12893          36 :                 $$ = (Node *) n;
   12894             :             }
   12895             :         | /*EMPTY*/
   12896             :             {
   12897        3742 :                 $$ = NULL;
   12898             :             }
   12899             :         ;
   12900             : 
   12901             : opt_cycle_clause:
   12902             :         CYCLE columnList SET ColId TO AexprConst DEFAULT AexprConst USING ColId
   12903             :             {
   12904          66 :                 CTECycleClause *n = makeNode(CTECycleClause);
   12905             : 
   12906          66 :                 n->cycle_col_list = $2;
   12907          66 :                 n->cycle_mark_column = $4;
   12908          66 :                 n->cycle_mark_value = $6;
   12909          66 :                 n->cycle_mark_default = $8;
   12910          66 :                 n->cycle_path_column = $10;
   12911          66 :                 n->location = @1;
   12912          66 :                 $$ = (Node *) n;
   12913             :             }
   12914             :         | CYCLE columnList SET ColId USING ColId
   12915             :             {
   12916          60 :                 CTECycleClause *n = makeNode(CTECycleClause);
   12917             : 
   12918          60 :                 n->cycle_col_list = $2;
   12919          60 :                 n->cycle_mark_column = $4;
   12920          60 :                 n->cycle_mark_value = makeBoolAConst(true, -1);
   12921          60 :                 n->cycle_mark_default = makeBoolAConst(false, -1);
   12922          60 :                 n->cycle_path_column = $6;
   12923          60 :                 n->location = @1;
   12924          60 :                 $$ = (Node *) n;
   12925             :             }
   12926             :         | /*EMPTY*/
   12927             :             {
   12928        3742 :                 $$ = NULL;
   12929             :             }
   12930             :         ;
   12931             : 
   12932             : opt_with_clause:
   12933         390 :         with_clause                             { $$ = $1; }
   12934       90322 :         | /*EMPTY*/                             { $$ = NULL; }
   12935             :         ;
   12936             : 
   12937             : into_clause:
   12938             :             INTO OptTempTableName
   12939             :                 {
   12940         132 :                     $$ = makeNode(IntoClause);
   12941         132 :                     $$->rel = $2;
   12942         132 :                     $$->colNames = NIL;
   12943         132 :                     $$->options = NIL;
   12944         132 :                     $$->onCommit = ONCOMMIT_NOOP;
   12945         132 :                     $$->tableSpaceName = NULL;
   12946         132 :                     $$->viewQuery = NULL;
   12947         132 :                     $$->skipData = false;
   12948             :                 }
   12949             :             | /*EMPTY*/
   12950      415030 :                 { $$ = NULL; }
   12951             :         ;
   12952             : 
   12953             : /*
   12954             :  * Redundancy here is needed to avoid shift/reduce conflicts,
   12955             :  * since TEMP is not a reserved word.  See also OptTemp.
   12956             :  */
   12957             : OptTempTableName:
   12958             :             TEMPORARY opt_table qualified_name
   12959             :                 {
   12960           0 :                     $$ = $3;
   12961           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   12962             :                 }
   12963             :             | TEMP opt_table qualified_name
   12964             :                 {
   12965           6 :                     $$ = $3;
   12966           6 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   12967             :                 }
   12968             :             | LOCAL TEMPORARY opt_table qualified_name
   12969             :                 {
   12970           0 :                     $$ = $4;
   12971           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   12972             :                 }
   12973             :             | LOCAL TEMP opt_table qualified_name
   12974             :                 {
   12975           0 :                     $$ = $4;
   12976           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   12977             :                 }
   12978             :             | GLOBAL TEMPORARY opt_table qualified_name
   12979             :                 {
   12980           0 :                     ereport(WARNING,
   12981             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   12982             :                              parser_errposition(@1)));
   12983           0 :                     $$ = $4;
   12984           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   12985             :                 }
   12986             :             | GLOBAL TEMP opt_table qualified_name
   12987             :                 {
   12988           0 :                     ereport(WARNING,
   12989             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   12990             :                              parser_errposition(@1)));
   12991           0 :                     $$ = $4;
   12992           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   12993             :                 }
   12994             :             | UNLOGGED opt_table qualified_name
   12995             :                 {
   12996           0 :                     $$ = $3;
   12997           0 :                     $$->relpersistence = RELPERSISTENCE_UNLOGGED;
   12998             :                 }
   12999             :             | TABLE qualified_name
   13000             :                 {
   13001          30 :                     $$ = $2;
   13002          30 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   13003             :                 }
   13004             :             | qualified_name
   13005             :                 {
   13006          96 :                     $$ = $1;
   13007          96 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   13008             :                 }
   13009             :         ;
   13010             : 
   13011             : opt_table:  TABLE
   13012             :             | /*EMPTY*/
   13013             :         ;
   13014             : 
   13015             : set_quantifier:
   13016        6510 :             ALL                                     { $$ = SET_QUANTIFIER_ALL; }
   13017          32 :             | DISTINCT                              { $$ = SET_QUANTIFIER_DISTINCT; }
   13018       11632 :             | /*EMPTY*/                             { $$ = SET_QUANTIFIER_DEFAULT; }
   13019             :         ;
   13020             : 
   13021             : /* We use (NIL) as a placeholder to indicate that all target expressions
   13022             :  * should be placed in the DISTINCT list during parsetree analysis.
   13023             :  */
   13024             : distinct_clause:
   13025        2834 :             DISTINCT                                { $$ = list_make1(NIL); }
   13026         178 :             | DISTINCT ON '(' expr_list ')'         { $$ = $4; }
   13027             :         ;
   13028             : 
   13029             : opt_all_clause:
   13030             :             ALL
   13031             :             | /*EMPTY*/
   13032             :         ;
   13033             : 
   13034             : opt_distinct_clause:
   13035           0 :             distinct_clause                         { $$ = $1; }
   13036       36474 :             | opt_all_clause                        { $$ = NIL; }
   13037             :         ;
   13038             : 
   13039             : opt_sort_clause:
   13040        6530 :             sort_clause                             { $$ = $1; }
   13041      322750 :             | /*EMPTY*/                             { $$ = NIL; }
   13042             :         ;
   13043             : 
   13044             : sort_clause:
   13045       61402 :             ORDER BY sortby_list                    { $$ = $3; }
   13046             :         ;
   13047             : 
   13048             : sortby_list:
   13049       61420 :             sortby                                  { $$ = list_make1($1); }
   13050       23686 :             | sortby_list ',' sortby                { $$ = lappend($1, $3); }
   13051             :         ;
   13052             : 
   13053             : sortby:     a_expr USING qual_all_Op opt_nulls_order
   13054             :                 {
   13055         220 :                     $$ = makeNode(SortBy);
   13056         220 :                     $$->node = $1;
   13057         220 :                     $$->sortby_dir = SORTBY_USING;
   13058         220 :                     $$->sortby_nulls = $4;
   13059         220 :                     $$->useOp = $3;
   13060         220 :                     $$->location = @3;
   13061             :                 }
   13062             :             | a_expr opt_asc_desc opt_nulls_order
   13063             :                 {
   13064       84886 :                     $$ = makeNode(SortBy);
   13065       84886 :                     $$->node = $1;
   13066       84886 :                     $$->sortby_dir = $2;
   13067       84886 :                     $$->sortby_nulls = $3;
   13068       84886 :                     $$->useOp = NIL;
   13069       84886 :                     $$->location = -1;       /* no operator */
   13070             :                 }
   13071             :         ;
   13072             : 
   13073             : 
   13074             : select_limit:
   13075             :             limit_clause offset_clause
   13076             :                 {
   13077         168 :                     $$ = $1;
   13078         168 :                     ($$)->limitOffset = $2;
   13079             :                 }
   13080             :             | offset_clause limit_clause
   13081             :                 {
   13082         214 :                     $$ = $2;
   13083         214 :                     ($$)->limitOffset = $1;
   13084             :                 }
   13085             :             | limit_clause
   13086             :                 {
   13087        4112 :                     $$ = $1;
   13088             :                 }
   13089             :             | offset_clause
   13090             :                 {
   13091         398 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13092             : 
   13093         398 :                     n->limitOffset = $1;
   13094         398 :                     n->limitCount = NULL;
   13095         398 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13096         398 :                     $$ = n;
   13097             :                 }
   13098             :         ;
   13099             : 
   13100             : opt_select_limit:
   13101         190 :             select_limit                        { $$ = $1; }
   13102       40984 :             | /* EMPTY */                       { $$ = NULL; }
   13103             :         ;
   13104             : 
   13105             : limit_clause:
   13106             :             LIMIT select_limit_value
   13107             :                 {
   13108        4414 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13109             : 
   13110        4414 :                     n->limitOffset = NULL;
   13111        4414 :                     n->limitCount = $2;
   13112        4414 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13113        4414 :                     $$ = n;
   13114             :                 }
   13115             :             | LIMIT select_limit_value ',' select_offset_value
   13116             :                 {
   13117             :                     /* Disabled because it was too confusing, bjm 2002-02-18 */
   13118           0 :                     ereport(ERROR,
   13119             :                             (errcode(ERRCODE_SYNTAX_ERROR),
   13120             :                              errmsg("LIMIT #,# syntax is not supported"),
   13121             :                              errhint("Use separate LIMIT and OFFSET clauses."),
   13122             :                              parser_errposition(@1)));
   13123             :                 }
   13124             :             /* SQL:2008 syntax */
   13125             :             /* to avoid shift/reduce conflicts, handle the optional value with
   13126             :              * a separate production rather than an opt_ expression.  The fact
   13127             :              * that ONLY is fully reserved means that this way, we defer any
   13128             :              * decision about what rule reduces ROW or ROWS to the point where
   13129             :              * we can see the ONLY token in the lookahead slot.
   13130             :              */
   13131             :             | FETCH first_or_next select_fetch_first_value row_or_rows ONLY
   13132             :                 {
   13133          20 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13134             : 
   13135          20 :                     n->limitOffset = NULL;
   13136          20 :                     n->limitCount = $3;
   13137          20 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13138          20 :                     $$ = n;
   13139             :                 }
   13140             :             | FETCH first_or_next select_fetch_first_value row_or_rows WITH TIES
   13141             :                 {
   13142          54 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13143             : 
   13144          54 :                     n->limitOffset = NULL;
   13145          54 :                     n->limitCount = $3;
   13146          54 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13147          54 :                     $$ = n;
   13148             :                 }
   13149             :             | FETCH first_or_next row_or_rows ONLY
   13150             :                 {
   13151           0 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13152             : 
   13153           0 :                     n->limitOffset = NULL;
   13154           0 :                     n->limitCount = makeIntConst(1, -1);
   13155           0 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13156           0 :                     $$ = n;
   13157             :                 }
   13158             :             | FETCH first_or_next row_or_rows WITH TIES
   13159             :                 {
   13160           6 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13161             : 
   13162           6 :                     n->limitOffset = NULL;
   13163           6 :                     n->limitCount = makeIntConst(1, -1);
   13164           6 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13165           6 :                     $$ = n;
   13166             :                 }
   13167             :         ;
   13168             : 
   13169             : offset_clause:
   13170             :             OFFSET select_offset_value
   13171         780 :                 { $$ = $2; }
   13172             :             /* SQL:2008 syntax */
   13173             :             | OFFSET select_fetch_first_value row_or_rows
   13174           0 :                 { $$ = $2; }
   13175             :         ;
   13176             : 
   13177             : select_limit_value:
   13178        4412 :             a_expr                                  { $$ = $1; }
   13179             :             | ALL
   13180             :                 {
   13181             :                     /* LIMIT ALL is represented as a NULL constant */
   13182           2 :                     $$ = makeNullAConst(@1);
   13183             :                 }
   13184             :         ;
   13185             : 
   13186             : select_offset_value:
   13187         780 :             a_expr                                  { $$ = $1; }
   13188             :         ;
   13189             : 
   13190             : /*
   13191             :  * Allowing full expressions without parentheses causes various parsing
   13192             :  * problems with the trailing ROW/ROWS key words.  SQL spec only calls for
   13193             :  * <simple value specification>, which is either a literal or a parameter (but
   13194             :  * an <SQL parameter reference> could be an identifier, bringing up conflicts
   13195             :  * with ROW/ROWS). We solve this by leveraging the presence of ONLY (see above)
   13196             :  * to determine whether the expression is missing rather than trying to make it
   13197             :  * optional in this rule.
   13198             :  *
   13199             :  * c_expr covers almost all the spec-required cases (and more), but it doesn't
   13200             :  * cover signed numeric literals, which are allowed by the spec. So we include
   13201             :  * those here explicitly. We need FCONST as well as ICONST because values that
   13202             :  * don't fit in the platform's "long", but do fit in bigint, should still be
   13203             :  * accepted here. (This is possible in 64-bit Windows as well as all 32-bit
   13204             :  * builds.)
   13205             :  */
   13206             : select_fetch_first_value:
   13207          74 :             c_expr                                  { $$ = $1; }
   13208             :             | '+' I_or_F_const
   13209           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   13210             :             | '-' I_or_F_const
   13211           0 :                 { $$ = doNegate($2, @1); }
   13212             :         ;
   13213             : 
   13214             : I_or_F_const:
   13215           0 :             Iconst                                  { $$ = makeIntConst($1,@1); }
   13216           0 :             | FCONST                                { $$ = makeFloatConst($1,@1); }
   13217             :         ;
   13218             : 
   13219             : /* noise words */
   13220          32 : row_or_rows: ROW                                    { $$ = 0; }
   13221          48 :             | ROWS                                  { $$ = 0; }
   13222             :         ;
   13223             : 
   13224          80 : first_or_next: FIRST_P                              { $$ = 0; }
   13225           0 :             | NEXT                                  { $$ = 0; }
   13226             :         ;
   13227             : 
   13228             : 
   13229             : /*
   13230             :  * This syntax for group_clause tries to follow the spec quite closely.
   13231             :  * However, the spec allows only column references, not expressions,
   13232             :  * which introduces an ambiguity between implicit row constructors
   13233             :  * (a,b) and lists of column references.
   13234             :  *
   13235             :  * We handle this by using the a_expr production for what the spec calls
   13236             :  * <ordinary grouping set>, which in the spec represents either one column
   13237             :  * reference or a parenthesized list of column references. Then, we check the
   13238             :  * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
   13239             :  * grab and use the list, discarding the node. (this is done in parse analysis,
   13240             :  * not here)
   13241             :  *
   13242             :  * (we abuse the row_format field of RowExpr to distinguish implicit and
   13243             :  * explicit row constructors; it's debatable if anyone sanely wants to use them
   13244             :  * in a group clause, but if they have a reason to, we make it possible.)
   13245             :  *
   13246             :  * Each item in the group_clause list is either an expression tree or a
   13247             :  * GroupingSet node of some type.
   13248             :  */
   13249             : group_clause:
   13250             :             GROUP_P BY set_quantifier group_by_list
   13251             :                 {
   13252        4194 :                     GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
   13253             : 
   13254        4194 :                     n->distinct = $3 == SET_QUANTIFIER_DISTINCT;
   13255        4194 :                     n->list = $4;
   13256        4194 :                     $$ = n;
   13257             :                 }
   13258             :             | /*EMPTY*/
   13259             :                 {
   13260      447436 :                     GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
   13261             : 
   13262      447436 :                     n->distinct = false;
   13263      447436 :                     n->list = NIL;
   13264      447436 :                     $$ = n;
   13265             :                 }
   13266             :         ;
   13267             : 
   13268             : group_by_list:
   13269        4684 :             group_by_item                           { $$ = list_make1($1); }
   13270        2730 :             | group_by_list ',' group_by_item       { $$ = lappend($1,$3); }
   13271             :         ;
   13272             : 
   13273             : group_by_item:
   13274        6268 :             a_expr                                  { $$ = $1; }
   13275         222 :             | empty_grouping_set                    { $$ = $1; }
   13276         184 :             | cube_clause                           { $$ = $1; }
   13277         250 :             | rollup_clause                         { $$ = $1; }
   13278         490 :             | grouping_sets_clause                  { $$ = $1; }
   13279             :         ;
   13280             : 
   13281             : empty_grouping_set:
   13282             :             '(' ')'
   13283             :                 {
   13284         222 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, @1);
   13285             :                 }
   13286             :         ;
   13287             : 
   13288             : /*
   13289             :  * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
   13290             :  * so that they shift in these rules rather than reducing the conflicting
   13291             :  * unreserved_keyword rule.
   13292             :  */
   13293             : 
   13294             : rollup_clause:
   13295             :             ROLLUP '(' expr_list ')'
   13296             :                 {
   13297         250 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_ROLLUP, $3, @1);
   13298             :                 }
   13299             :         ;
   13300             : 
   13301             : cube_clause:
   13302             :             CUBE '(' expr_list ')'
   13303             :                 {
   13304         184 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_CUBE, $3, @1);
   13305             :                 }
   13306             :         ;
   13307             : 
   13308             : grouping_sets_clause:
   13309             :             GROUPING SETS '(' group_by_list ')'
   13310             :                 {
   13311         490 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_SETS, $4, @1);
   13312             :                 }
   13313             :         ;
   13314             : 
   13315             : having_clause:
   13316         776 :             HAVING a_expr                           { $$ = $2; }
   13317      450854 :             | /*EMPTY*/                             { $$ = NULL; }
   13318             :         ;
   13319             : 
   13320             : for_locking_clause:
   13321        5040 :             for_locking_items                       { $$ = $1; }
   13322           0 :             | FOR READ ONLY                         { $$ = NIL; }
   13323             :         ;
   13324             : 
   13325             : opt_for_locking_clause:
   13326         340 :             for_locking_clause                      { $$ = $1; }
   13327       40836 :             | /* EMPTY */                           { $$ = NIL; }
   13328             :         ;
   13329             : 
   13330             : for_locking_items:
   13331        5040 :             for_locking_item                        { $$ = list_make1($1); }
   13332          98 :             | for_locking_items for_locking_item    { $$ = lappend($1, $2); }
   13333             :         ;
   13334             : 
   13335             : for_locking_item:
   13336             :             for_locking_strength locked_rels_list opt_nowait_or_skip
   13337             :                 {
   13338        5138 :                     LockingClause *n = makeNode(LockingClause);
   13339             : 
   13340        5138 :                     n->lockedRels = $2;
   13341        5138 :                     n->strength = $1;
   13342        5138 :                     n->waitPolicy = $3;
   13343        5138 :                     $$ = (Node *) n;
   13344             :                 }
   13345             :         ;
   13346             : 
   13347             : for_locking_strength:
   13348        1456 :             FOR UPDATE                          { $$ = LCS_FORUPDATE; }
   13349          66 :             | FOR NO KEY UPDATE                 { $$ = LCS_FORNOKEYUPDATE; }
   13350         214 :             | FOR SHARE                         { $$ = LCS_FORSHARE; }
   13351        3402 :             | FOR KEY SHARE                     { $$ = LCS_FORKEYSHARE; }
   13352             :         ;
   13353             : 
   13354             : locked_rels_list:
   13355        3408 :             OF qualified_name_list                  { $$ = $2; }
   13356        1730 :             | /* EMPTY */                           { $$ = NIL; }
   13357             :         ;
   13358             : 
   13359             : 
   13360             : /*
   13361             :  * We should allow ROW '(' expr_list ')' too, but that seems to require
   13362             :  * making VALUES a fully reserved word, which will probably break more apps
   13363             :  * than allowing the noise-word is worth.
   13364             :  */
   13365             : values_clause:
   13366             :             VALUES '(' expr_list ')'
   13367             :                 {
   13368       58898 :                     SelectStmt *n = makeNode(SelectStmt);
   13369             : 
   13370       58898 :                     n->valuesLists = list_make1($3);
   13371       58898 :                     $$ = (Node *) n;
   13372             :                 }
   13373             :             | values_clause ',' '(' expr_list ')'
   13374             :                 {
   13375       24282 :                     SelectStmt *n = (SelectStmt *) $1;
   13376             : 
   13377       24282 :                     n->valuesLists = lappend(n->valuesLists, $4);
   13378       24282 :                     $$ = (Node *) n;
   13379             :                 }
   13380             :         ;
   13381             : 
   13382             : 
   13383             : /*****************************************************************************
   13384             :  *
   13385             :  *  clauses common to all Optimizable Stmts:
   13386             :  *      from_clause     - allow list of both JOIN expressions and table names
   13387             :  *      where_clause    - qualifications for joins or restrictions
   13388             :  *
   13389             :  *****************************************************************************/
   13390             : 
   13391             : from_clause:
   13392      267282 :             FROM from_list                          { $$ = $2; }
   13393      197752 :             | /*EMPTY*/                             { $$ = NIL; }
   13394             :         ;
   13395             : 
   13396             : from_list:
   13397      267950 :             table_ref                               { $$ = list_make1($1); }
   13398       52146 :             | from_list ',' table_ref               { $$ = lappend($1, $3); }
   13399             :         ;
   13400             : 
   13401             : /*
   13402             :  * table_ref is where an alias clause can be attached.
   13403             :  */
   13404             : table_ref:  relation_expr opt_alias_clause
   13405             :                 {
   13406      342054 :                     $1->alias = $2;
   13407      342054 :                     $$ = (Node *) $1;
   13408             :                 }
   13409             :             | relation_expr opt_alias_clause tablesample_clause
   13410             :                 {
   13411         254 :                     RangeTableSample *n = (RangeTableSample *) $3;
   13412             : 
   13413         254 :                     $1->alias = $2;
   13414             :                     /* relation_expr goes inside the RangeTableSample node */
   13415         254 :                     n->relation = (Node *) $1;
   13416         254 :                     $$ = (Node *) n;
   13417             :                 }
   13418             :             | func_table func_alias_clause
   13419             :                 {
   13420       38172 :                     RangeFunction *n = (RangeFunction *) $1;
   13421             : 
   13422       38172 :                     n->alias = linitial($2);
   13423       38172 :                     n->coldeflist = lsecond($2);
   13424       38172 :                     $$ = (Node *) n;
   13425             :                 }
   13426             :             | LATERAL_P func_table func_alias_clause
   13427             :                 {
   13428        1002 :                     RangeFunction *n = (RangeFunction *) $2;
   13429             : 
   13430        1002 :                     n->lateral = true;
   13431        1002 :                     n->alias = linitial($3);
   13432        1002 :                     n->coldeflist = lsecond($3);
   13433        1002 :                     $$ = (Node *) n;
   13434             :                 }
   13435             :             | xmltable opt_alias_clause
   13436             :                 {
   13437          80 :                     RangeTableFunc *n = (RangeTableFunc *) $1;
   13438             : 
   13439          80 :                     n->alias = $2;
   13440          80 :                     $$ = (Node *) n;
   13441             :                 }
   13442             :             | LATERAL_P xmltable opt_alias_clause
   13443             :                 {
   13444         140 :                     RangeTableFunc *n = (RangeTableFunc *) $2;
   13445             : 
   13446         140 :                     n->lateral = true;
   13447         140 :                     n->alias = $3;
   13448         140 :                     $$ = (Node *) n;
   13449             :                 }
   13450             :             | select_with_parens opt_alias_clause
   13451             :                 {
   13452       12488 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13453             : 
   13454       12488 :                     n->lateral = false;
   13455       12488 :                     n->subquery = $1;
   13456       12488 :                     n->alias = $2;
   13457       12488 :                     $$ = (Node *) n;
   13458             :                 }
   13459             :             | LATERAL_P select_with_parens opt_alias_clause
   13460             :                 {
   13461        1400 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13462             : 
   13463        1400 :                     n->lateral = true;
   13464        1400 :                     n->subquery = $2;
   13465        1400 :                     n->alias = $3;
   13466        1400 :                     $$ = (Node *) n;
   13467             :                 }
   13468             :             | joined_table
   13469             :                 {
   13470       73430 :                     $$ = (Node *) $1;
   13471             :                 }
   13472             :             | '(' joined_table ')' alias_clause
   13473             :                 {
   13474         174 :                     $2->alias = $4;
   13475         174 :                     $$ = (Node *) $2;
   13476             :                 }
   13477             :         ;
   13478             : 
   13479             : 
   13480             : /*
   13481             :  * It may seem silly to separate joined_table from table_ref, but there is
   13482             :  * method in SQL's madness: if you don't do it this way you get reduce-
   13483             :  * reduce conflicts, because it's not clear to the parser generator whether
   13484             :  * to expect alias_clause after ')' or not.  For the same reason we must
   13485             :  * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
   13486             :  * join_type to expand to empty; if we try it, the parser generator can't
   13487             :  * figure out when to reduce an empty join_type right after table_ref.
   13488             :  *
   13489             :  * Note that a CROSS JOIN is the same as an unqualified
   13490             :  * INNER JOIN, and an INNER JOIN/ON has the same shape
   13491             :  * but a qualification expression to limit membership.
   13492             :  * A NATURAL JOIN implicitly matches column names between
   13493             :  * tables and the shape is determined by which columns are
   13494             :  * in common. We'll collect columns during the later transformations.
   13495             :  */
   13496             : 
   13497             : joined_table:
   13498             :             '(' joined_table ')'
   13499             :                 {
   13500        3434 :                     $$ = $2;
   13501             :                 }
   13502             :             | table_ref CROSS JOIN table_ref
   13503             :                 {
   13504             :                     /* CROSS JOIN is same as unqualified inner join */
   13505         298 :                     JoinExpr   *n = makeNode(JoinExpr);
   13506             : 
   13507         298 :                     n->jointype = JOIN_INNER;
   13508         298 :                     n->isNatural = false;
   13509         298 :                     n->larg = $1;
   13510         298 :                     n->rarg = $4;
   13511         298 :                     n->usingClause = NIL;
   13512         298 :                     n->join_using_alias = NULL;
   13513         298 :                     n->quals = NULL;
   13514         298 :                     $$ = n;
   13515             :                 }
   13516             :             | table_ref join_type JOIN table_ref join_qual
   13517             :                 {
   13518       44374 :                     JoinExpr   *n = makeNode(JoinExpr);
   13519             : 
   13520       44374 :                     n->jointype = $2;
   13521       44374 :                     n->isNatural = false;
   13522       44374 :                     n->larg = $1;
   13523       44374 :                     n->rarg = $4;
   13524       44374 :                     if ($5 != NULL && IsA($5, List))
   13525             :                     {
   13526             :                          /* USING clause */
   13527         486 :                         n->usingClause = linitial_node(List, castNode(List, $5));
   13528         486 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $5));
   13529             :                     }
   13530             :                     else
   13531             :                     {
   13532             :                         /* ON clause */
   13533       43888 :                         n->quals = $5;
   13534             :                     }
   13535       44374 :                     $$ = n;
   13536             :                 }
   13537             :             | table_ref JOIN table_ref join_qual
   13538             :                 {
   13539             :                     /* letting join_type reduce to empty doesn't work */
   13540       28674 :                     JoinExpr   *n = makeNode(JoinExpr);
   13541             : 
   13542       28674 :                     n->jointype = JOIN_INNER;
   13543       28674 :                     n->isNatural = false;
   13544       28674 :                     n->larg = $1;
   13545       28674 :                     n->rarg = $3;
   13546       28674 :                     if ($4 != NULL && IsA($4, List))
   13547             :                     {
   13548             :                         /* USING clause */
   13549         708 :                         n->usingClause = linitial_node(List, castNode(List, $4));
   13550         708 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $4));
   13551             :                     }
   13552             :                     else
   13553             :                     {
   13554             :                         /* ON clause */
   13555       27966 :                         n->quals = $4;
   13556             :                     }
   13557       28674 :                     $$ = n;
   13558             :                 }
   13559             :             | table_ref NATURAL join_type JOIN table_ref
   13560             :                 {
   13561          78 :                     JoinExpr   *n = makeNode(JoinExpr);
   13562             : 
   13563          78 :                     n->jointype = $3;
   13564          78 :                     n->isNatural = true;
   13565          78 :                     n->larg = $1;
   13566          78 :                     n->rarg = $5;
   13567          78 :                     n->usingClause = NIL; /* figure out which columns later... */
   13568          78 :                     n->join_using_alias = NULL;
   13569          78 :                     n->quals = NULL; /* fill later */
   13570          78 :                     $$ = n;
   13571             :                 }
   13572             :             | table_ref NATURAL JOIN table_ref
   13573             :                 {
   13574             :                     /* letting join_type reduce to empty doesn't work */
   13575         180 :                     JoinExpr   *n = makeNode(JoinExpr);
   13576             : 
   13577         180 :                     n->jointype = JOIN_INNER;
   13578         180 :                     n->isNatural = true;
   13579         180 :                     n->larg = $1;
   13580         180 :                     n->rarg = $4;
   13581         180 :                     n->usingClause = NIL; /* figure out which columns later... */
   13582         180 :                     n->join_using_alias = NULL;
   13583         180 :                     n->quals = NULL; /* fill later */
   13584         180 :                     $$ = n;
   13585             :                 }
   13586             :         ;
   13587             : 
   13588             : alias_clause:
   13589             :             AS ColId '(' name_list ')'
   13590             :                 {
   13591        5406 :                     $$ = makeNode(Alias);
   13592        5406 :                     $$->aliasname = $2;
   13593        5406 :                     $$->colnames = $4;
   13594             :                 }
   13595             :             | AS ColId
   13596             :                 {
   13597       11618 :                     $$ = makeNode(Alias);
   13598       11618 :                     $$->aliasname = $2;
   13599             :                 }
   13600             :             | ColId '(' name_list ')'
   13601             :                 {
   13602        5366 :                     $$ = makeNode(Alias);
   13603        5366 :                     $$->aliasname = $1;
   13604        5366 :                     $$->colnames = $3;
   13605             :                 }
   13606             :             | ColId
   13607             :                 {
   13608      223252 :                     $$ = makeNode(Alias);
   13609      223252 :                     $$->aliasname = $1;
   13610             :                 }
   13611             :         ;
   13612             : 
   13613      219918 : opt_alias_clause: alias_clause                      { $$ = $1; }
   13614      136498 :             | /*EMPTY*/                             { $$ = NULL; }
   13615             :         ;
   13616             : 
   13617             : /*
   13618             :  * The alias clause after JOIN ... USING only accepts the AS ColId spelling,
   13619             :  * per SQL standard.  (The grammar could parse the other variants, but they
   13620             :  * don't seem to be useful, and it might lead to parser problems in the
   13621             :  * future.)
   13622             :  */
   13623             : opt_alias_clause_for_join_using:
   13624             :             AS ColId
   13625             :                 {
   13626          84 :                     $$ = makeNode(Alias);
   13627          84 :                     $$->aliasname = $2;
   13628             :                     /* the column name list will be inserted later */
   13629             :                 }
   13630        1110 :             | /*EMPTY*/                             { $$ = NULL; }
   13631             :         ;
   13632             : 
   13633             : /*
   13634             :  * func_alias_clause can include both an Alias and a coldeflist, so we make it
   13635             :  * return a 2-element list that gets disassembled by calling production.
   13636             :  */
   13637             : func_alias_clause:
   13638             :             alias_clause
   13639             :                 {
   13640       25550 :                     $$ = list_make2($1, NIL);
   13641             :                 }
   13642             :             | AS '(' TableFuncElementList ')'
   13643             :                 {
   13644         104 :                     $$ = list_make2(NULL, $3);
   13645             :                 }
   13646             :             | AS ColId '(' TableFuncElementList ')'
   13647             :                 {
   13648         586 :                     Alias      *a = makeNode(Alias);
   13649             : 
   13650         586 :                     a->aliasname = $2;
   13651         586 :                     $$ = list_make2(a, $4);
   13652             :                 }
   13653             :             | ColId '(' TableFuncElementList ')'
   13654             :                 {
   13655          50 :                     Alias      *a = makeNode(Alias);
   13656             : 
   13657          50 :                     a->aliasname = $1;
   13658          50 :                     $$ = list_make2(a, $3);
   13659             :                 }
   13660             :             | /*EMPTY*/
   13661             :                 {
   13662       12884 :                     $$ = list_make2(NULL, NIL);
   13663             :                 }
   13664             :         ;
   13665             : 
   13666        1018 : join_type:  FULL opt_outer                          { $$ = JOIN_FULL; }
   13667       39308 :             | LEFT opt_outer                        { $$ = JOIN_LEFT; }
   13668         344 :             | RIGHT opt_outer                       { $$ = JOIN_RIGHT; }
   13669        3782 :             | INNER_P                               { $$ = JOIN_INNER; }
   13670             :         ;
   13671             : 
   13672             : /* OUTER is just noise... */
   13673             : opt_outer: OUTER_P
   13674             :             | /*EMPTY*/
   13675             :         ;
   13676             : 
   13677             : /* JOIN qualification clauses
   13678             :  * Possibilities are:
   13679             :  *  USING ( column list ) [ AS alias ]
   13680             :  *                        allows only unqualified column names,
   13681             :  *                        which must match between tables.
   13682             :  *  ON expr allows more general qualifications.
   13683             :  *
   13684             :  * We return USING as a two-element List (the first item being a sub-List
   13685             :  * of the common column names, and the second either an Alias item or NULL).
   13686             :  * An ON-expr will not be a List, so it can be told apart that way.
   13687             :  */
   13688             : 
   13689             : join_qual: USING '(' name_list ')' opt_alias_clause_for_join_using
   13690             :                 {
   13691        1194 :                     $$ = (Node *) list_make2($3, $5);
   13692             :                 }
   13693             :             | ON a_expr
   13694             :                 {
   13695       71854 :                     $$ = $2;
   13696             :                 }
   13697             :         ;
   13698             : 
   13699             : 
   13700             : relation_expr:
   13701             :             qualified_name
   13702             :                 {
   13703             :                     /* inheritance query, implicitly */
   13704      400860 :                     $$ = $1;
   13705      400860 :                     $$->inh = true;
   13706      400860 :                     $$->alias = NULL;
   13707             :                 }
   13708             :             | extended_relation_expr
   13709             :                 {
   13710        7000 :                     $$ = $1;
   13711             :                 }
   13712             :         ;
   13713             : 
   13714             : extended_relation_expr:
   13715             :             qualified_name '*'
   13716             :                 {
   13717             :                     /* inheritance query, explicitly */
   13718         204 :                     $$ = $1;
   13719         204 :                     $$->inh = true;
   13720         204 :                     $$->alias = NULL;
   13721             :                 }
   13722             :             | ONLY qualified_name
   13723             :                 {
   13724             :                     /* no inheritance */
   13725        6802 :                     $$ = $2;
   13726        6802 :                     $$->inh = false;
   13727        6802 :                     $$->alias = NULL;
   13728             :                 }
   13729             :             | ONLY '(' qualified_name ')'
   13730             :                 {
   13731             :                     /* no inheritance, SQL99-style syntax */
   13732           0 :                     $$ = $3;
   13733           0 :                     $$->inh = false;
   13734           0 :                     $$->alias = NULL;
   13735             :                 }
   13736             :         ;
   13737             : 
   13738             : 
   13739             : relation_expr_list:
   13740        2554 :             relation_expr                           { $$ = list_make1($1); }
   13741        9512 :             | relation_expr_list ',' relation_expr  { $$ = lappend($1, $3); }
   13742             :         ;
   13743             : 
   13744             : 
   13745             : /*
   13746             :  * Given "UPDATE foo set set ...", we have to decide without looking any
   13747             :  * further ahead whether the first "set" is an alias or the UPDATE's SET
   13748             :  * keyword.  Since "set" is allowed as a column name both interpretations
   13749             :  * are feasible.  We resolve the shift/reduce conflict by giving the first
   13750             :  * relation_expr_opt_alias production a higher precedence than the SET token
   13751             :  * has, causing the parser to prefer to reduce, in effect assuming that the
   13752             :  * SET is not an alias.
   13753             :  */
   13754             : relation_expr_opt_alias: relation_expr                  %prec UMINUS
   13755             :                 {
   13756       17686 :                     $$ = $1;
   13757             :                 }
   13758             :             | relation_expr ColId
   13759             :                 {
   13760        2018 :                     Alias      *alias = makeNode(Alias);
   13761             : 
   13762        2018 :                     alias->aliasname = $2;
   13763        2018 :                     $1->alias = alias;
   13764        2018 :                     $$ = $1;
   13765             :                 }
   13766             :             | relation_expr AS ColId
   13767             :                 {
   13768          78 :                     Alias      *alias = makeNode(Alias);
   13769             : 
   13770          78 :                     alias->aliasname = $3;
   13771          78 :                     $1->alias = alias;
   13772          78 :                     $$ = $1;
   13773             :                 }
   13774             :         ;
   13775             : 
   13776             : /*
   13777             :  * TABLESAMPLE decoration in a FROM item
   13778             :  */
   13779             : tablesample_clause:
   13780             :             TABLESAMPLE func_name '(' expr_list ')' opt_repeatable_clause
   13781             :                 {
   13782         254 :                     RangeTableSample *n = makeNode(RangeTableSample);
   13783             : 
   13784             :                     /* n->relation will be filled in later */
   13785         254 :                     n->method = $2;
   13786         254 :                     n->args = $4;
   13787         254 :                     n->repeatable = $6;
   13788         254 :                     n->location = @2;
   13789         254 :                     $$ = (Node *) n;
   13790             :                 }
   13791             :         ;
   13792             : 
   13793             : opt_repeatable_clause:
   13794         108 :             REPEATABLE '(' a_expr ')'   { $$ = (Node *) $3; }
   13795         146 :             | /*EMPTY*/                 { $$ = NULL; }
   13796             :         ;
   13797             : 
   13798             : /*
   13799             :  * func_table represents a function invocation in a FROM list. It can be
   13800             :  * a plain function call, like "foo(...)", or a ROWS FROM expression with
   13801             :  * one or more function calls, "ROWS FROM (foo(...), bar(...))",
   13802             :  * optionally with WITH ORDINALITY attached.
   13803             :  * In the ROWS FROM syntax, a column definition list can be given for each
   13804             :  * function, for example:
   13805             :  *     ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
   13806             :  *                bar() AS (bar_res_a text, bar_res_b text))
   13807             :  * It's also possible to attach a column definition list to the RangeFunction
   13808             :  * as a whole, but that's handled by the table_ref production.
   13809             :  */
   13810             : func_table: func_expr_windowless opt_ordinality
   13811             :                 {
   13812       39048 :                     RangeFunction *n = makeNode(RangeFunction);
   13813             : 
   13814       39048 :                     n->lateral = false;
   13815       39048 :                     n->ordinality = $2;
   13816       39048 :                     n->is_rowsfrom = false;
   13817       39048 :                     n->functions = list_make1(list_make2($1, NIL));
   13818             :                     /* alias and coldeflist are set by table_ref production */
   13819       39048 :                     $$ = (Node *) n;
   13820             :                 }
   13821             :             | ROWS FROM '(' rowsfrom_list ')' opt_ordinality
   13822             :                 {
   13823         132 :                     RangeFunction *n = makeNode(RangeFunction);
   13824             : 
   13825         132 :                     n->lateral = false;
   13826         132 :                     n->ordinality = $6;
   13827         132 :                     n->is_rowsfrom = true;
   13828         132 :                     n->functions = $4;
   13829             :                     /* alias and coldeflist are set by table_ref production */
   13830         132 :                     $$ = (Node *) n;
   13831             :                 }
   13832             :         ;
   13833             : 
   13834             : rowsfrom_item: func_expr_windowless opt_col_def_list
   13835         318 :                 { $$ = list_make2($1, $2); }
   13836             :         ;
   13837             : 
   13838             : rowsfrom_list:
   13839         132 :             rowsfrom_item                       { $$ = list_make1($1); }
   13840         186 :             | rowsfrom_list ',' rowsfrom_item   { $$ = lappend($1, $3); }
   13841             :         ;
   13842             : 
   13843          54 : opt_col_def_list: AS '(' TableFuncElementList ')'   { $$ = $3; }
   13844         264 :             | /*EMPTY*/                             { $$ = NIL; }
   13845             :         ;
   13846             : 
   13847         762 : opt_ordinality: WITH_LA ORDINALITY                  { $$ = true; }
   13848       38418 :             | /*EMPTY*/                             { $$ = false; }
   13849             :         ;
   13850             : 
   13851             : 
   13852             : where_clause:
   13853      178674 :             WHERE a_expr                            { $$ = $2; }
   13854      291756 :             | /*EMPTY*/                             { $$ = NULL; }
   13855             :         ;
   13856             : 
   13857             : /* variant for UPDATE and DELETE */
   13858             : where_or_current_clause:
   13859       12860 :             WHERE a_expr                            { $$ = $2; }
   13860             :             | WHERE CURRENT_P OF cursor_name
   13861             :                 {
   13862         254 :                     CurrentOfExpr *n = makeNode(CurrentOfExpr);
   13863             : 
   13864             :                     /* cvarno is filled in by parse analysis */
   13865         254 :                     n->cursor_name = $4;
   13866         254 :                     n->cursor_param = 0;
   13867         254 :                     $$ = (Node *) n;
   13868             :                 }
   13869        4766 :             | /*EMPTY*/                             { $$ = NULL; }
   13870             :         ;
   13871             : 
   13872             : 
   13873             : OptTableFuncElementList:
   13874         678 :             TableFuncElementList                { $$ = $1; }
   13875           6 :             | /*EMPTY*/                         { $$ = NIL; }
   13876             :         ;
   13877             : 
   13878             : TableFuncElementList:
   13879             :             TableFuncElement
   13880             :                 {
   13881        1472 :                     $$ = list_make1($1);
   13882             :                 }
   13883             :             | TableFuncElementList ',' TableFuncElement
   13884             :                 {
   13885        1966 :                     $$ = lappend($1, $3);
   13886             :                 }
   13887             :         ;
   13888             : 
   13889             : TableFuncElement:   ColId Typename opt_collate_clause
   13890             :                 {
   13891        3502 :                     ColumnDef *n = makeNode(ColumnDef);
   13892             : 
   13893        3502 :                     n->colname = $1;
   13894        3502 :                     n->typeName = $2;
   13895        3502 :                     n->inhcount = 0;
   13896        3502 :                     n->is_local = true;
   13897        3502 :                     n->is_not_null = false;
   13898        3502 :                     n->is_from_type = false;
   13899        3502 :                     n->storage = 0;
   13900        3502 :                     n->raw_default = NULL;
   13901        3502 :                     n->cooked_default = NULL;
   13902        3502 :                     n->collClause = (CollateClause *) $3;
   13903        3502 :                     n->collOid = InvalidOid;
   13904        3502 :                     n->constraints = NIL;
   13905        3502 :                     n->location = @1;
   13906        3502 :                     $$ = (Node *) n;
   13907             :                 }
   13908             :         ;
   13909             : 
   13910             : /*
   13911             :  * XMLTABLE
   13912             :  */
   13913             : xmltable:
   13914             :             XMLTABLE '(' c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   13915             :                 {
   13916         200 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   13917             : 
   13918         200 :                     n->rowexpr = $3;
   13919         200 :                     n->docexpr = $4;
   13920         200 :                     n->columns = $6;
   13921         200 :                     n->namespaces = NIL;
   13922         200 :                     n->location = @1;
   13923         200 :                     $$ = (Node *) n;
   13924             :                 }
   13925             :             | XMLTABLE '(' XMLNAMESPACES '(' xml_namespace_list ')' ','
   13926             :                 c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   13927             :                 {
   13928          20 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   13929             : 
   13930          20 :                     n->rowexpr = $8;
   13931          20 :                     n->docexpr = $9;
   13932          20 :                     n->columns = $11;
   13933          20 :                     n->namespaces = $5;
   13934          20 :                     n->location = @1;
   13935          20 :                     $$ = (Node *) n;
   13936             :                 }
   13937             :         ;
   13938             : 
   13939         220 : xmltable_column_list: xmltable_column_el                    { $$ = list_make1($1); }
   13940         530 :             | xmltable_column_list ',' xmltable_column_el   { $$ = lappend($1, $3); }
   13941             :         ;
   13942             : 
   13943             : xmltable_column_el:
   13944             :             ColId Typename
   13945             :                 {
   13946         198 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   13947             : 
   13948         198 :                     fc->colname = $1;
   13949         198 :                     fc->for_ordinality = false;
   13950         198 :                     fc->typeName = $2;
   13951         198 :                     fc->is_not_null = false;
   13952         198 :                     fc->colexpr = NULL;
   13953         198 :                     fc->coldefexpr = NULL;
   13954         198 :                     fc->location = @1;
   13955             : 
   13956         198 :                     $$ = (Node *) fc;
   13957             :                 }
   13958             :             | ColId Typename xmltable_column_option_list
   13959             :                 {
   13960         490 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   13961             :                     ListCell   *option;
   13962         490 :                     bool        nullability_seen = false;
   13963             : 
   13964         490 :                     fc->colname = $1;
   13965         490 :                     fc->typeName = $2;
   13966         490 :                     fc->for_ordinality = false;
   13967         490 :                     fc->is_not_null = false;
   13968         490 :                     fc->colexpr = NULL;
   13969         490 :                     fc->coldefexpr = NULL;
   13970         490 :                     fc->location = @1;
   13971             : 
   13972        1092 :                     foreach(option, $3)
   13973             :                     {
   13974         602 :                         DefElem   *defel = (DefElem *) lfirst(option);
   13975             : 
   13976         602 :                         if (strcmp(defel->defname, "default") == 0)
   13977             :                         {
   13978          56 :                             if (fc->coldefexpr != NULL)
   13979           0 :                                 ereport(ERROR,
   13980             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   13981             :                                          errmsg("only one DEFAULT value is allowed"),
   13982             :                                          parser_errposition(defel->location)));
   13983          56 :                             fc->coldefexpr = defel->arg;
   13984             :                         }
   13985         546 :                         else if (strcmp(defel->defname, "path") == 0)
   13986             :                         {
   13987         490 :                             if (fc->colexpr != NULL)
   13988           0 :                                 ereport(ERROR,
   13989             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   13990             :                                          errmsg("only one PATH value per column is allowed"),
   13991             :                                          parser_errposition(defel->location)));
   13992         490 :                             fc->colexpr = defel->arg;
   13993             :                         }
   13994          56 :                         else if (strcmp(defel->defname, "is_not_null") == 0)
   13995             :                         {
   13996          56 :                             if (nullability_seen)
   13997           0 :                                 ereport(ERROR,
   13998             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   13999             :                                          errmsg("conflicting or redundant NULL / NOT NULL declarations for column \"%s\"", fc->colname),
   14000             :                                          parser_errposition(defel->location)));
   14001          56 :                             fc->is_not_null = boolVal(defel->arg);
   14002          56 :                             nullability_seen = true;
   14003             :                         }
   14004             :                         else
   14005             :                         {
   14006           0 :                             ereport(ERROR,
   14007             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   14008             :                                      errmsg("unrecognized column option \"%s\"",
   14009             :                                             defel->defname),
   14010             :                                      parser_errposition(defel->location)));
   14011             :                         }
   14012             :                     }
   14013         490 :                     $$ = (Node *) fc;
   14014             :                 }
   14015             :             | ColId FOR ORDINALITY
   14016             :                 {
   14017          62 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14018             : 
   14019          62 :                     fc->colname = $1;
   14020          62 :                     fc->for_ordinality = true;
   14021             :                     /* other fields are ignored, initialized by makeNode */
   14022          62 :                     fc->location = @1;
   14023             : 
   14024          62 :                     $$ = (Node *) fc;
   14025             :                 }
   14026             :         ;
   14027             : 
   14028             : xmltable_column_option_list:
   14029             :             xmltable_column_option_el
   14030         490 :                 { $$ = list_make1($1); }
   14031             :             | xmltable_column_option_list xmltable_column_option_el
   14032         112 :                 { $$ = lappend($1, $2); }
   14033             :         ;
   14034             : 
   14035             : xmltable_column_option_el:
   14036             :             IDENT b_expr
   14037         490 :                 { $$ = makeDefElem($1, $2, @1); }
   14038             :             | DEFAULT b_expr
   14039          56 :                 { $$ = makeDefElem("default", $2, @1); }
   14040             :             | NOT NULL_P
   14041          56 :                 { $$ = makeDefElem("is_not_null", (Node *) makeBoolean(true), @1); }
   14042             :             | NULL_P
   14043           0 :                 { $$ = makeDefElem("is_not_null", (Node *) makeBoolean(false), @1); }
   14044             :         ;
   14045             : 
   14046             : xml_namespace_list:
   14047             :             xml_namespace_el
   14048          20 :                 { $$ = list_make1($1); }
   14049             :             | xml_namespace_list ',' xml_namespace_el
   14050           0 :                 { $$ = lappend($1, $3); }
   14051             :         ;
   14052             : 
   14053             : xml_namespace_el:
   14054             :             b_expr AS ColLabel
   14055             :                 {
   14056          14 :                     $$ = makeNode(ResTarget);
   14057          14 :                     $$->name = $3;
   14058          14 :                     $$->indirection = NIL;
   14059          14 :                     $$->val = $1;
   14060          14 :                     $$->location = @1;
   14061             :                 }
   14062             :             | DEFAULT b_expr
   14063             :                 {
   14064           6 :                     $$ = makeNode(ResTarget);
   14065           6 :                     $$->name = NULL;
   14066           6 :                     $$->indirection = NIL;
   14067           6 :                     $$->val = $2;
   14068           6 :                     $$->location = @1;
   14069             :                 }
   14070             :         ;
   14071             : 
   14072             : /*****************************************************************************
   14073             :  *
   14074             :  *  Type syntax
   14075             :  *      SQL introduces a large amount of type-specific syntax.
   14076             :  *      Define individual clauses to handle these cases, and use
   14077             :  *       the generic case to handle regular type-extensible Postgres syntax.
   14078             :  *      - thomas 1997-10-10
   14079             :  *
   14080             :  *****************************************************************************/
   14081             : 
   14082             : Typename:   SimpleTypename opt_array_bounds
   14083             :                 {
   14084      406836 :                     $$ = $1;
   14085      406836 :                     $$->arrayBounds = $2;
   14086             :                 }
   14087             :             | SETOF SimpleTypename opt_array_bounds
   14088             :                 {
   14089        1890 :                     $$ = $2;
   14090        1890 :                     $$->arrayBounds = $3;
   14091        1890 :                     $$->setof = true;
   14092             :                 }
   14093             :             /* SQL standard syntax, currently only one-dimensional */
   14094             :             | SimpleTypename ARRAY '[' Iconst ']'
   14095             :                 {
   14096           6 :                     $$ = $1;
   14097           6 :                     $$->arrayBounds = list_make1(makeInteger($4));
   14098             :                 }
   14099             :             | SETOF SimpleTypename ARRAY '[' Iconst ']'
   14100             :                 {
   14101           0 :                     $$ = $2;
   14102           0 :                     $$->arrayBounds = list_make1(makeInteger($5));
   14103           0 :                     $$->setof = true;
   14104             :                 }
   14105             :             | SimpleTypename ARRAY
   14106             :                 {
   14107           0 :                     $$ = $1;
   14108           0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   14109             :                 }
   14110             :             | SETOF SimpleTypename ARRAY
   14111             :                 {
   14112           0 :                     $$ = $2;
   14113           0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   14114           0 :                     $$->setof = true;
   14115             :                 }
   14116             :         ;
   14117             : 
   14118             : opt_array_bounds:
   14119             :             opt_array_bounds '[' ']'
   14120       11336 :                     {  $$ = lappend($1, makeInteger(-1)); }
   14121             :             | opt_array_bounds '[' Iconst ']'
   14122          62 :                     {  $$ = lappend($1, makeInteger($3)); }
   14123             :             | /*EMPTY*/
   14124      408726 :                     {  $$ = NIL; }
   14125             :         ;
   14126             : 
   14127             : SimpleTypename:
   14128      326898 :             GenericType                             { $$ = $1; }
   14129       68452 :             | Numeric                               { $$ = $1; }
   14130        1830 :             | Bit                                   { $$ = $1; }
   14131        2750 :             | Character                             { $$ = $1; }
   14132        4282 :             | ConstDatetime                         { $$ = $1; }
   14133             :             | ConstInterval opt_interval
   14134             :                 {
   14135        3308 :                     $$ = $1;
   14136        3308 :                     $$->typmods = $2;
   14137             :                 }
   14138             :             | ConstInterval '(' Iconst ')'
   14139             :                 {
   14140           0 :                     $$ = $1;
   14141           0 :                     $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   14142             :                                              makeIntConst($3, @3));
   14143             :                 }
   14144        1592 :             | JsonType                              { $$ = $1; }
   14145             :         ;
   14146             : 
   14147             : /* We have a separate ConstTypename to allow defaulting fixed-length
   14148             :  * types such as CHAR() and BIT() to an unspecified length.
   14149             :  * SQL9x requires that these default to a length of one, but this
   14150             :  * makes no sense for constructs like CHAR 'hi' and BIT '0101',
   14151             :  * where there is an obvious better choice to make.
   14152             :  * Note that ConstInterval is not included here since it must
   14153             :  * be pushed up higher in the rules to accommodate the postfix
   14154             :  * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
   14155             :  * the generic-type-name case in AexprConst to avoid premature
   14156             :  * reduce/reduce conflicts against function names.
   14157             :  */
   14158             : ConstTypename:
   14159          78 :             Numeric                                 { $$ = $1; }
   14160           0 :             | ConstBit                              { $$ = $1; }
   14161          34 :             | ConstCharacter                        { $$ = $1; }
   14162        2534 :             | ConstDatetime                         { $$ = $1; }
   14163         216 :             | JsonType                              { $$ = $1; }
   14164             :         ;
   14165             : 
   14166             : /*
   14167             :  * GenericType covers all type names that don't have special syntax mandated
   14168             :  * by the standard, including qualified names.  We also allow type modifiers.
   14169             :  * To avoid parsing conflicts against function invocations, the modifiers
   14170             :  * have to be shown as expr_list here, but parse analysis will only accept
   14171             :  * constants for them.
   14172             :  */
   14173             : GenericType:
   14174             :             type_function_name opt_type_modifiers
   14175             :                 {
   14176      243506 :                     $$ = makeTypeName($1);
   14177      243506 :                     $$->typmods = $2;
   14178      243506 :                     $$->location = @1;
   14179             :                 }
   14180             :             | type_function_name attrs opt_type_modifiers
   14181             :                 {
   14182       83392 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
   14183       83392 :                     $$->typmods = $3;
   14184       83392 :                     $$->location = @1;
   14185             :                 }
   14186             :         ;
   14187             : 
   14188        1342 : opt_type_modifiers: '(' expr_list ')'               { $$ = $2; }
   14189      331314 :                     | /* EMPTY */                   { $$ = NIL; }
   14190             :         ;
   14191             : 
   14192             : /*
   14193             :  * SQL numeric data types
   14194             :  */
   14195             : Numeric:    INT_P
   14196             :                 {
   14197       33542 :                     $$ = SystemTypeName("int4");
   14198       33542 :                     $$->location = @1;
   14199             :                 }
   14200             :             | INTEGER
   14201             :                 {
   14202       12950 :                     $$ = SystemTypeName("int4");
   14203       12950 :                     $$->location = @1;
   14204             :                 }
   14205             :             | SMALLINT
   14206             :                 {
   14207        1134 :                     $$ = SystemTypeName("int2");
   14208        1134 :                     $$->location = @1;
   14209             :                 }
   14210             :             | BIGINT
   14211             :                 {
   14212        4122 :                     $$ = SystemTypeName("int8");
   14213        4122 :                     $$->location = @1;
   14214             :                 }
   14215             :             | REAL
   14216             :                 {
   14217         368 :                     $$ = SystemTypeName("float4");
   14218         368 :                     $$->location = @1;
   14219             :                 }
   14220             :             | FLOAT_P opt_float
   14221             :                 {
   14222         482 :                     $$ = $2;
   14223         482 :                     $$->location = @1;
   14224             :                 }
   14225             :             | DOUBLE_P PRECISION
   14226             :                 {
   14227         488 :                     $$ = SystemTypeName("float8");
   14228         488 :                     $$->location = @1;
   14229             :                 }
   14230             :             | DECIMAL_P opt_type_modifiers
   14231             :                 {
   14232          36 :                     $$ = SystemTypeName("numeric");
   14233          36 :                     $$->typmods = $2;
   14234          36 :                     $$->location = @1;
   14235             :                 }
   14236             :             | DEC opt_type_modifiers
   14237             :                 {
   14238           0 :                     $$ = SystemTypeName("numeric");
   14239           0 :                     $$->typmods = $2;
   14240           0 :                     $$->location = @1;
   14241             :                 }
   14242             :             | NUMERIC opt_type_modifiers
   14243             :                 {
   14244        5722 :                     $$ = SystemTypeName("numeric");
   14245        5722 :                     $$->typmods = $2;
   14246        5722 :                     $$->location = @1;
   14247             :                 }
   14248             :             | BOOLEAN_P
   14249             :                 {
   14250        9686 :                     $$ = SystemTypeName("bool");
   14251        9686 :                     $$->location = @1;
   14252             :                 }
   14253             :         ;
   14254             : 
   14255             : opt_float:  '(' Iconst ')'
   14256             :                 {
   14257             :                     /*
   14258             :                      * Check FLOAT() precision limits assuming IEEE floating
   14259             :                      * types - thomas 1997-09-18
   14260             :                      */
   14261           2 :                     if ($2 < 1)
   14262           0 :                         ereport(ERROR,
   14263             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   14264             :                                  errmsg("precision for type float must be at least 1 bit"),
   14265             :                                  parser_errposition(@2)));
   14266           2 :                     else if ($2 <= 24)
   14267           2 :                         $$ = SystemTypeName("float4");
   14268           0 :                     else if ($2 <= 53)
   14269           0 :                         $$ = SystemTypeName("float8");
   14270             :                     else
   14271           0 :                         ereport(ERROR,
   14272             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   14273             :                                  errmsg("precision for type float must be less than 54 bits"),
   14274             :                                  parser_errposition(@2)));
   14275             :                 }
   14276             :             | /*EMPTY*/
   14277             :                 {
   14278         480 :                     $$ = SystemTypeName("float8");
   14279             :                 }
   14280             :         ;
   14281             : 
   14282             : /*
   14283             :  * SQL bit-field data types
   14284             :  * The following implements BIT() and BIT VARYING().
   14285             :  */
   14286             : Bit:        BitWithLength
   14287             :                 {
   14288        1642 :                     $$ = $1;
   14289             :                 }
   14290             :             | BitWithoutLength
   14291             :                 {
   14292         188 :                     $$ = $1;
   14293             :                 }
   14294             :         ;
   14295             : 
   14296             : /* ConstBit is like Bit except "BIT" defaults to unspecified length */
   14297             : /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
   14298             : ConstBit:   BitWithLength
   14299             :                 {
   14300           0 :                     $$ = $1;
   14301             :                 }
   14302             :             | BitWithoutLength
   14303             :                 {
   14304           0 :                     $$ = $1;
   14305           0 :                     $$->typmods = NIL;
   14306             :                 }
   14307             :         ;
   14308             : 
   14309             : BitWithLength:
   14310             :             BIT opt_varying '(' expr_list ')'
   14311             :                 {
   14312             :                     char *typname;
   14313             : 
   14314        1642 :                     typname = $2 ? "varbit" : "bit";
   14315        1642 :                     $$ = SystemTypeName(typname);
   14316        1642 :                     $$->typmods = $4;
   14317        1642 :                     $$->location = @1;
   14318             :                 }
   14319             :         ;
   14320             : 
   14321             : BitWithoutLength:
   14322             :             BIT opt_varying
   14323             :                 {
   14324             :                     /* bit defaults to bit(1), varbit to no limit */
   14325         188 :                     if ($2)
   14326             :                     {
   14327          20 :                         $$ = SystemTypeName("varbit");
   14328             :                     }
   14329             :                     else
   14330             :                     {
   14331         168 :                         $$ = SystemTypeName("bit");
   14332         168 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   14333             :                     }
   14334         188 :                     $$->location = @1;
   14335             :                 }
   14336             :         ;
   14337             : 
   14338             : 
   14339             : /*
   14340             :  * SQL character data types
   14341             :  * The following implements CHAR() and VARCHAR().
   14342             :  */
   14343             : Character:  CharacterWithLength
   14344             :                 {
   14345        1554 :                     $$ = $1;
   14346             :                 }
   14347             :             | CharacterWithoutLength
   14348             :                 {
   14349        1196 :                     $$ = $1;
   14350             :                 }
   14351             :         ;
   14352             : 
   14353             : ConstCharacter:  CharacterWithLength
   14354             :                 {
   14355          12 :                     $$ = $1;
   14356             :                 }
   14357             :             | CharacterWithoutLength
   14358             :                 {
   14359             :                     /* Length was not specified so allow to be unrestricted.
   14360             :                      * This handles problems with fixed-length (bpchar) strings
   14361             :                      * which in column definitions must default to a length
   14362             :                      * of one, but should not be constrained if the length
   14363             :                      * was not specified.
   14364             :                      */
   14365          22 :                     $$ = $1;
   14366          22 :                     $$->typmods = NIL;
   14367             :                 }
   14368             :         ;
   14369             : 
   14370             : CharacterWithLength:  character '(' Iconst ')'
   14371             :                 {
   14372        1566 :                     $$ = SystemTypeName($1);
   14373        1566 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14374        1566 :                     $$->location = @1;
   14375             :                 }
   14376             :         ;
   14377             : 
   14378             : CharacterWithoutLength:  character
   14379             :                 {
   14380        1218 :                     $$ = SystemTypeName($1);
   14381             :                     /* char defaults to char(1), varchar to no limit */
   14382        1218 :                     if (strcmp($1, "bpchar") == 0)
   14383         252 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   14384        1218 :                     $$->location = @1;
   14385             :                 }
   14386             :         ;
   14387             : 
   14388             : character:  CHARACTER opt_varying
   14389         500 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14390             :             | CHAR_P opt_varying
   14391        1080 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14392             :             | VARCHAR
   14393        1200 :                                         { $$ = "varchar"; }
   14394             :             | NATIONAL CHARACTER opt_varying
   14395           0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   14396             :             | NATIONAL CHAR_P opt_varying
   14397           0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   14398             :             | NCHAR opt_varying
   14399           4 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14400             :         ;
   14401             : 
   14402             : opt_varying:
   14403         398 :             VARYING                                 { $$ = true; }
   14404        3016 :             | /*EMPTY*/                             { $$ = false; }
   14405             :         ;
   14406             : 
   14407             : /*
   14408             :  * SQL date/time types
   14409             :  */
   14410             : ConstDatetime:
   14411             :             TIMESTAMP '(' Iconst ')' opt_timezone
   14412             :                 {
   14413         114 :                     if ($5)
   14414          90 :                         $$ = SystemTypeName("timestamptz");
   14415             :                     else
   14416          24 :                         $$ = SystemTypeName("timestamp");
   14417         114 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14418         114 :                     $$->location = @1;
   14419             :                 }
   14420             :             | TIMESTAMP opt_timezone
   14421             :                 {
   14422        4604 :                     if ($2)
   14423        1304 :                         $$ = SystemTypeName("timestamptz");
   14424             :                     else
   14425        3300 :                         $$ = SystemTypeName("timestamp");
   14426        4604 :                     $$->location = @1;
   14427             :                 }
   14428             :             | TIME '(' Iconst ')' opt_timezone
   14429             :                 {
   14430          22 :                     if ($5)
   14431           8 :                         $$ = SystemTypeName("timetz");
   14432             :                     else
   14433          14 :                         $$ = SystemTypeName("time");
   14434          22 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14435          22 :                     $$->location = @1;
   14436             :                 }
   14437             :             | TIME opt_timezone
   14438             :                 {
   14439        2076 :                     if ($2)
   14440         266 :                         $$ = SystemTypeName("timetz");
   14441             :                     else
   14442        1810 :                         $$ = SystemTypeName("time");
   14443        2076 :                     $$->location = @1;
   14444             :                 }
   14445             :         ;
   14446             : 
   14447             : ConstInterval:
   14448             :             INTERVAL
   14449             :                 {
   14450        6552 :                     $$ = SystemTypeName("interval");
   14451        6552 :                     $$->location = @1;
   14452             :                 }
   14453             :         ;
   14454             : 
   14455             : opt_timezone:
   14456        1668 :             WITH_LA TIME ZONE                       { $$ = true; }
   14457         508 :             | WITHOUT_LA TIME ZONE                  { $$ = false; }
   14458        4640 :             | /*EMPTY*/                             { $$ = false; }
   14459             :         ;
   14460             : 
   14461             : opt_interval:
   14462             :             YEAR_P
   14463          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
   14464             :             | MONTH_P
   14465          18 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
   14466             :             | DAY_P
   14467          18 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
   14468             :             | HOUR_P
   14469          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
   14470             :             | MINUTE_P
   14471          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
   14472             :             | interval_second
   14473          36 :                 { $$ = $1; }
   14474             :             | YEAR_P TO MONTH_P
   14475             :                 {
   14476          18 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
   14477             :                                                  INTERVAL_MASK(MONTH), @1));
   14478             :                 }
   14479             :             | DAY_P TO HOUR_P
   14480             :                 {
   14481          24 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   14482             :                                                  INTERVAL_MASK(HOUR), @1));
   14483             :                 }
   14484             :             | DAY_P TO MINUTE_P
   14485             :                 {
   14486          24 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   14487             :                                                  INTERVAL_MASK(HOUR) |
   14488             :                                                  INTERVAL_MASK(MINUTE), @1));
   14489             :                 }
   14490             :             | DAY_P TO interval_second
   14491             :                 {
   14492          48 :                     $$ = $3;
   14493          48 :                     linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
   14494             :                                                 INTERVAL_MASK(HOUR) |
   14495             :                                                 INTERVAL_MASK(MINUTE) |
   14496          48 :                                                 INTERVAL_MASK(SECOND), @1);
   14497             :                 }
   14498             :             | HOUR_P TO MINUTE_P
   14499             :                 {
   14500          18 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
   14501             :                                                  INTERVAL_MASK(MINUTE), @1));
   14502             :                 }
   14503             :             | HOUR_P TO interval_second
   14504             :                 {
   14505          36 :                     $$ = $3;
   14506          36 :                     linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
   14507             :                                                 INTERVAL_MASK(MINUTE) |
   14508          36 :                                                 INTERVAL_MASK(SECOND), @1);
   14509             :                 }
   14510             :             | MINUTE_P TO interval_second
   14511             :                 {
   14512          66 :                     $$ = $3;
   14513          66 :                     linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
   14514          66 :                                                 INTERVAL_MASK(SECOND), @1);
   14515             :                 }
   14516             :             | /*EMPTY*/
   14517        6198 :                 { $$ = NIL; }
   14518             :         ;
   14519             : 
   14520             : interval_second:
   14521             :             SECOND_P
   14522             :                 {
   14523         102 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
   14524             :                 }
   14525             :             | SECOND_P '(' Iconst ')'
   14526             :                 {
   14527          84 :                     $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
   14528             :                                     makeIntConst($3, @3));
   14529             :                 }
   14530             :         ;
   14531             : 
   14532             : JsonType:
   14533             :             JSON
   14534             :                 {
   14535        1808 :                     $$ = SystemTypeName("json");
   14536        1808 :                     $$->location = @1;
   14537             :                 }
   14538             :         ;
   14539             : 
   14540             : /*****************************************************************************
   14541             :  *
   14542             :  *  expression grammar
   14543             :  *
   14544             :  *****************************************************************************/
   14545             : 
   14546             : /*
   14547             :  * General expressions
   14548             :  * This is the heart of the expression syntax.
   14549             :  *
   14550             :  * We have two expression types: a_expr is the unrestricted kind, and
   14551             :  * b_expr is a subset that must be used in some places to avoid shift/reduce
   14552             :  * conflicts.  For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
   14553             :  * because that use of AND conflicts with AND as a boolean operator.  So,
   14554             :  * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
   14555             :  *
   14556             :  * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
   14557             :  * always be used by surrounding it with parens.
   14558             :  *
   14559             :  * c_expr is all the productions that are common to a_expr and b_expr;
   14560             :  * it's factored out just to eliminate redundant coding.
   14561             :  *
   14562             :  * Be careful of productions involving more than one terminal token.
   14563             :  * By default, bison will assign such productions the precedence of their
   14564             :  * last terminal, but in nearly all cases you want it to be the precedence
   14565             :  * of the first terminal instead; otherwise you will not get the behavior
   14566             :  * you expect!  So we use %prec annotations freely to set precedences.
   14567             :  */
   14568     3265484 : a_expr:     c_expr                                  { $$ = $1; }
   14569             :             | a_expr TYPECAST Typename
   14570      172822 :                     { $$ = makeTypeCast($1, $3, @2); }
   14571             :             | a_expr COLLATE any_name
   14572             :                 {
   14573        7682 :                     CollateClause *n = makeNode(CollateClause);
   14574             : 
   14575        7682 :                     n->arg = $1;
   14576        7682 :                     n->collname = $3;
   14577        7682 :                     n->location = @2;
   14578        7682 :                     $$ = (Node *) n;
   14579             :                 }
   14580             :             | a_expr AT TIME ZONE a_expr            %prec AT
   14581             :                 {
   14582         396 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   14583         396 :                                                list_make2($5, $1),
   14584             :                                                COERCE_SQL_SYNTAX,
   14585         396 :                                                @2);
   14586             :                 }
   14587             :             | a_expr AT LOCAL                       %prec AT
   14588             :                 {
   14589          42 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   14590          42 :                                                list_make1($1),
   14591             :                                                COERCE_SQL_SYNTAX,
   14592             :                                                -1);
   14593             :                 }
   14594             :         /*
   14595             :          * These operators must be called out explicitly in order to make use
   14596             :          * of bison's automatic operator-precedence handling.  All other
   14597             :          * operator names are handled by the generic productions using "Op",
   14598             :          * below; and all those operators will have the same precedence.
   14599             :          *
   14600             :          * If you add more explicitly-known operators, be sure to add them
   14601             :          * also to b_expr and to the MathOp list below.
   14602             :          */
   14603             :             | '+' a_expr                    %prec UMINUS
   14604          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   14605             :             | '-' a_expr                    %prec UMINUS
   14606       27048 :                 { $$ = doNegate($2, @1); }
   14607             :             | a_expr '+' a_expr
   14608       12902 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   14609             :             | a_expr '-' a_expr
   14610        4088 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   14611             :             | a_expr '*' a_expr
   14612        8516 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   14613             :             | a_expr '/' a_expr
   14614        3808 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   14615             :             | a_expr '%' a_expr
   14616        2596 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   14617             :             | a_expr '^' a_expr
   14618         456 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   14619             :             | a_expr '<' a_expr
   14620       22858 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   14621             :             | a_expr '>' a_expr
   14622       32130 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   14623             :             | a_expr '=' a_expr
   14624      335342 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   14625             :             | a_expr LESS_EQUALS a_expr
   14626        4708 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   14627             :             | a_expr GREATER_EQUALS a_expr
   14628        4828 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   14629             :             | a_expr NOT_EQUALS a_expr
   14630       36350 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   14631             : 
   14632             :             | a_expr qual_Op a_expr             %prec Op
   14633       53762 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   14634             :             | qual_Op a_expr                    %prec Op
   14635         192 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   14636             : 
   14637             :             | a_expr AND a_expr
   14638      197282 :                 { $$ = makeAndExpr($1, $3, @2); }
   14639             :             | a_expr OR a_expr
   14640       14598 :                 { $$ = makeOrExpr($1, $3, @2); }
   14641             :             | NOT a_expr
   14642       13722 :                 { $$ = makeNotExpr($2, @1); }
   14643             :             | NOT_LA a_expr                     %prec NOT
   14644           0 :                 { $$ = makeNotExpr($2, @1); }
   14645             : 
   14646             :             | a_expr LIKE a_expr
   14647             :                 {
   14648        1792 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   14649        1792 :                                                    $1, $3, @2);
   14650             :                 }
   14651             :             | a_expr LIKE a_expr ESCAPE a_expr                  %prec LIKE
   14652             :                 {
   14653          96 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   14654          96 :                                                  list_make2($3, $5),
   14655             :                                                  COERCE_EXPLICIT_CALL,
   14656          96 :                                                  @2);
   14657          96 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   14658          96 :                                                    $1, (Node *) n, @2);
   14659             :                 }
   14660             :             | a_expr NOT_LA LIKE a_expr                         %prec NOT_LA
   14661             :                 {
   14662         198 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   14663         198 :                                                    $1, $4, @2);
   14664             :                 }
   14665             :             | a_expr NOT_LA LIKE a_expr ESCAPE a_expr           %prec NOT_LA
   14666             :                 {
   14667          96 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   14668          96 :                                                  list_make2($4, $6),
   14669             :                                                  COERCE_EXPLICIT_CALL,
   14670          96 :                                                  @2);
   14671          96 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   14672          96 :                                                    $1, (Node *) n, @2);
   14673             :                 }
   14674             :             | a_expr ILIKE a_expr
   14675             :                 {
   14676         174 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   14677         174 :                                                    $1, $3, @2);
   14678             :                 }
   14679             :             | a_expr ILIKE a_expr ESCAPE a_expr                 %prec ILIKE
   14680             :                 {
   14681           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   14682           0 :                                                  list_make2($3, $5),
   14683             :                                                  COERCE_EXPLICIT_CALL,
   14684           0 :                                                  @2);
   14685           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   14686           0 :                                                    $1, (Node *) n, @2);
   14687             :                 }
   14688             :             | a_expr NOT_LA ILIKE a_expr                        %prec NOT_LA
   14689             :                 {
   14690          30 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   14691          30 :                                                    $1, $4, @2);
   14692             :                 }
   14693             :             | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr          %prec NOT_LA
   14694             :                 {
   14695           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   14696           0 :                                                  list_make2($4, $6),
   14697             :                                                  COERCE_EXPLICIT_CALL,
   14698           0 :                                                  @2);
   14699           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   14700           0 :                                                    $1, (Node *) n, @2);
   14701             :                 }
   14702             : 
   14703             :             | a_expr SIMILAR TO a_expr                          %prec SIMILAR
   14704             :                 {
   14705          40 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   14706          40 :                                                  list_make1($4),
   14707             :                                                  COERCE_EXPLICIT_CALL,
   14708          40 :                                                  @2);
   14709          40 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   14710          40 :                                                    $1, (Node *) n, @2);
   14711             :                 }
   14712             :             | a_expr SIMILAR TO a_expr ESCAPE a_expr            %prec SIMILAR
   14713             :                 {
   14714          30 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   14715          30 :                                                  list_make2($4, $6),
   14716             :                                                  COERCE_EXPLICIT_CALL,
   14717          30 :                                                  @2);
   14718          30 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   14719          30 :                                                    $1, (Node *) n, @2);
   14720             :                 }
   14721             :             | a_expr NOT_LA SIMILAR TO a_expr                   %prec NOT_LA
   14722             :                 {
   14723           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   14724           0 :                                                  list_make1($5),
   14725             :                                                  COERCE_EXPLICIT_CALL,
   14726           0 :                                                  @2);
   14727           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   14728           0 :                                                    $1, (Node *) n, @2);
   14729             :                 }
   14730             :             | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr     %prec NOT_LA
   14731             :                 {
   14732           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   14733           0 :                                                  list_make2($5, $7),
   14734             :                                                  COERCE_EXPLICIT_CALL,
   14735           0 :                                                  @2);
   14736           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   14737           0 :                                                    $1, (Node *) n, @2);
   14738             :                 }
   14739             : 
   14740             :             /* NullTest clause
   14741             :              * Define SQL-style Null test clause.
   14742             :              * Allow two forms described in the standard:
   14743             :              *  a IS NULL
   14744             :              *  a IS NOT NULL
   14745             :              * Allow two SQL extensions
   14746             :              *  a ISNULL
   14747             :              *  a NOTNULL
   14748             :              */
   14749             :             | a_expr IS NULL_P                          %prec IS
   14750             :                 {
   14751        4808 :                     NullTest   *n = makeNode(NullTest);
   14752             : 
   14753        4808 :                     n->arg = (Expr *) $1;
   14754        4808 :                     n->nulltesttype = IS_NULL;
   14755        4808 :                     n->location = @2;
   14756        4808 :                     $$ = (Node *) n;
   14757             :                 }
   14758             :             | a_expr ISNULL
   14759             :                 {
   14760          96 :                     NullTest   *n = makeNode(NullTest);
   14761             : 
   14762          96 :                     n->arg = (Expr *) $1;
   14763          96 :                     n->nulltesttype = IS_NULL;
   14764          96 :                     n->location = @2;
   14765          96 :                     $$ = (Node *) n;
   14766             :                 }
   14767             :             | a_expr IS NOT NULL_P                      %prec IS
   14768             :                 {
   14769       10722 :                     NullTest   *n = makeNode(NullTest);
   14770             : 
   14771       10722 :                     n->arg = (Expr *) $1;
   14772       10722 :                     n->nulltesttype = IS_NOT_NULL;
   14773       10722 :                     n->location = @2;
   14774       10722 :                     $$ = (Node *) n;
   14775             :                 }
   14776             :             | a_expr NOTNULL
   14777             :                 {
   14778           6 :                     NullTest   *n = makeNode(NullTest);
   14779             : 
   14780           6 :                     n->arg = (Expr *) $1;
   14781           6 :                     n->nulltesttype = IS_NOT_NULL;
   14782           6 :                     n->location = @2;
   14783           6 :                     $$ = (Node *) n;
   14784             :                 }
   14785             :             | row OVERLAPS row
   14786             :                 {
   14787         786 :                     if (list_length($1) != 2)
   14788           0 :                         ereport(ERROR,
   14789             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   14790             :                                  errmsg("wrong number of parameters on left side of OVERLAPS expression"),
   14791             :                                  parser_errposition(@1)));
   14792         786 :                     if (list_length($3) != 2)
   14793           0 :                         ereport(ERROR,
   14794             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   14795             :                                  errmsg("wrong number of parameters on right side of OVERLAPS expression"),
   14796             :                                  parser_errposition(@3)));
   14797         786 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
   14798         786 :                                                list_concat($1, $3),
   14799             :                                                COERCE_SQL_SYNTAX,
   14800         786 :                                                @2);
   14801             :                 }
   14802             :             | a_expr IS TRUE_P                          %prec IS
   14803             :                 {
   14804         370 :                     BooleanTest *b = makeNode(BooleanTest);
   14805             : 
   14806         370 :                     b->arg = (Expr *) $1;
   14807         370 :                     b->booltesttype = IS_TRUE;
   14808         370 :                     b->location = @2;
   14809         370 :                     $$ = (Node *) b;
   14810             :                 }
   14811             :             | a_expr IS NOT TRUE_P                      %prec IS
   14812             :                 {
   14813         138 :                     BooleanTest *b = makeNode(BooleanTest);
   14814             : 
   14815         138 :                     b->arg = (Expr *) $1;
   14816         138 :                     b->booltesttype = IS_NOT_TRUE;
   14817         138 :                     b->location = @2;
   14818         138 :                     $$ = (Node *) b;
   14819             :                 }
   14820             :             | a_expr IS FALSE_P                         %prec IS
   14821             :                 {
   14822         114 :                     BooleanTest *b = makeNode(BooleanTest);
   14823             : 
   14824         114 :                     b->arg = (Expr *) $1;
   14825         114 :                     b->booltesttype = IS_FALSE;
   14826         114 :                     b->location = @2;
   14827         114 :                     $$ = (Node *) b;
   14828             :                 }
   14829             :             | a_expr IS NOT FALSE_P                     %prec IS
   14830             :                 {
   14831          90 :                     BooleanTest *b = makeNode(BooleanTest);
   14832             : 
   14833          90 :                     b->arg = (Expr *) $1;
   14834          90 :                     b->booltesttype = IS_NOT_FALSE;
   14835          90 :                     b->location = @2;
   14836          90 :                     $$ = (Node *) b;
   14837             :                 }
   14838             :             | a_expr IS UNKNOWN                         %prec IS
   14839             :                 {
   14840          52 :                     BooleanTest *b = makeNode(BooleanTest);
   14841             : 
   14842          52 :                     b->arg = (Expr *) $1;
   14843          52 :                     b->booltesttype = IS_UNKNOWN;
   14844          52 :                     b->location = @2;
   14845          52 :                     $$ = (Node *) b;
   14846             :                 }
   14847             :             | a_expr IS NOT UNKNOWN                     %prec IS
   14848             :                 {
   14849          48 :                     BooleanTest *b = makeNode(BooleanTest);
   14850             : 
   14851          48 :                     b->arg = (Expr *) $1;
   14852          48 :                     b->booltesttype = IS_NOT_UNKNOWN;
   14853          48 :                     b->location = @2;
   14854          48 :                     $$ = (Node *) b;
   14855             :                 }
   14856             :             | a_expr IS DISTINCT FROM a_expr            %prec IS
   14857             :                 {
   14858         880 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   14859             :                 }
   14860             :             | a_expr IS NOT DISTINCT FROM a_expr        %prec IS
   14861             :                 {
   14862          62 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   14863             :                 }
   14864             :             | a_expr BETWEEN opt_asymmetric b_expr AND a_expr       %prec BETWEEN
   14865             :                 {
   14866         454 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN,
   14867             :                                                    "BETWEEN",
   14868         454 :                                                    $1,
   14869         454 :                                                    (Node *) list_make2($4, $6),
   14870         454 :                                                    @2);
   14871             :                 }
   14872             :             | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
   14873             :                 {
   14874          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN,
   14875             :                                                    "NOT BETWEEN",
   14876          12 :                                                    $1,
   14877          12 :                                                    (Node *) list_make2($5, $7),
   14878          12 :                                                    @2);
   14879             :                 }
   14880             :             | a_expr BETWEEN SYMMETRIC b_expr AND a_expr            %prec BETWEEN
   14881             :                 {
   14882          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN_SYM,
   14883             :                                                    "BETWEEN SYMMETRIC",
   14884          12 :                                                    $1,
   14885          12 :                                                    (Node *) list_make2($4, $6),
   14886          12 :                                                    @2);
   14887             :                 }
   14888             :             | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr     %prec NOT_LA
   14889             :                 {
   14890          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN_SYM,
   14891             :                                                    "NOT BETWEEN SYMMETRIC",
   14892          12 :                                                    $1,
   14893          12 :                                                    (Node *) list_make2($5, $7),
   14894          12 :                                                    @2);
   14895             :                 }
   14896             :             | a_expr IN_P in_expr
   14897             :                 {
   14898             :                     /* in_expr returns a SubLink or a list of a_exprs */
   14899       16728 :                     if (IsA($3, SubLink))
   14900             :                     {
   14901             :                         /* generate foo = ANY (subquery) */
   14902        2294 :                         SubLink    *n = (SubLink *) $3;
   14903             : 
   14904        2294 :                         n->subLinkType = ANY_SUBLINK;
   14905        2294 :                         n->subLinkId = 0;
   14906        2294 :                         n->testexpr = $1;
   14907        2294 :                         n->operName = NIL;       /* show it's IN not = ANY */
   14908        2294 :                         n->location = @2;
   14909        2294 :                         $$ = (Node *) n;
   14910             :                     }
   14911             :                     else
   14912             :                     {
   14913             :                         /* generate scalar IN expression */
   14914       14434 :                         $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
   14915             :                     }
   14916             :                 }
   14917             :             | a_expr NOT_LA IN_P in_expr                        %prec NOT_LA
   14918             :                 {
   14919             :                     /* in_expr returns a SubLink or a list of a_exprs */
   14920        2200 :                     if (IsA($4, SubLink))
   14921             :                     {
   14922             :                         /* generate NOT (foo = ANY (subquery)) */
   14923             :                         /* Make an = ANY node */
   14924         120 :                         SubLink    *n = (SubLink *) $4;
   14925             : 
   14926         120 :                         n->subLinkType = ANY_SUBLINK;
   14927         120 :                         n->subLinkId = 0;
   14928         120 :                         n->testexpr = $1;
   14929         120 :                         n->operName = NIL;       /* show it's IN not = ANY */
   14930         120 :                         n->location = @2;
   14931             :                         /* Stick a NOT on top; must have same parse location */
   14932         120 :                         $$ = makeNotExpr((Node *) n, @2);
   14933             :                     }
   14934             :                     else
   14935             :                     {
   14936             :                         /* generate scalar NOT IN expression */
   14937        2080 :                         $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
   14938             :                     }
   14939             :                 }
   14940             :             | a_expr subquery_Op sub_type select_with_parens    %prec Op
   14941             :                 {
   14942         166 :                     SubLink    *n = makeNode(SubLink);
   14943             : 
   14944         166 :                     n->subLinkType = $3;
   14945         166 :                     n->subLinkId = 0;
   14946         166 :                     n->testexpr = $1;
   14947         166 :                     n->operName = $2;
   14948         166 :                     n->subselect = $4;
   14949         166 :                     n->location = @2;
   14950         166 :                     $$ = (Node *) n;
   14951             :                 }
   14952             :             | a_expr subquery_Op sub_type '(' a_expr ')'        %prec Op
   14953             :                 {
   14954       14378 :                     if ($3 == ANY_SUBLINK)
   14955       14078 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
   14956             :                     else
   14957         300 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
   14958             :                 }
   14959             :             | UNIQUE opt_unique_null_treatment select_with_parens
   14960             :                 {
   14961             :                     /* Not sure how to get rid of the parentheses
   14962             :                      * but there are lots of shift/reduce errors without them.
   14963             :                      *
   14964             :                      * Should be able to implement this by plopping the entire
   14965             :                      * select into a node, then transforming the target expressions
   14966             :                      * from whatever they are into count(*), and testing the
   14967             :                      * entire result equal to one.
   14968             :                      * But, will probably implement a separate node in the executor.
   14969             :                      */
   14970           0 :                     ereport(ERROR,
   14971             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   14972             :                              errmsg("UNIQUE predicate is not yet implemented"),
   14973             :                              parser_errposition(@1)));
   14974             :                 }
   14975             :             | a_expr IS DOCUMENT_P                  %prec IS
   14976             :                 {
   14977          18 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   14978          18 :                                      list_make1($1), @2);
   14979             :                 }
   14980             :             | a_expr IS NOT DOCUMENT_P              %prec IS
   14981             :                 {
   14982          18 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   14983          18 :                                                  list_make1($1), @2),
   14984          18 :                                      @2);
   14985             :                 }
   14986             :             | a_expr IS NORMALIZED                              %prec IS
   14987             :                 {
   14988          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   14989          12 :                                                list_make1($1),
   14990             :                                                COERCE_SQL_SYNTAX,
   14991          12 :                                                @2);
   14992             :                 }
   14993             :             | a_expr IS unicode_normal_form NORMALIZED          %prec IS
   14994             :                 {
   14995          36 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   14996          36 :                                                list_make2($1, makeStringConst($3, @3)),
   14997             :                                                COERCE_SQL_SYNTAX,
   14998          36 :                                                @2);
   14999             :                 }
   15000             :             | a_expr IS NOT NORMALIZED                          %prec IS
   15001             :                 {
   15002           0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15003           0 :                                                            list_make1($1),
   15004             :                                                            COERCE_SQL_SYNTAX,
   15005           0 :                                                            @2),
   15006           0 :                                      @2);
   15007             :                 }
   15008             :             | a_expr IS NOT unicode_normal_form NORMALIZED      %prec IS
   15009             :                 {
   15010           0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15011           0 :                                                            list_make2($1, makeStringConst($4, @4)),
   15012             :                                                            COERCE_SQL_SYNTAX,
   15013           0 :                                                            @2),
   15014           0 :                                      @2);
   15015             :                 }
   15016             :             | a_expr IS json_predicate_type_constraint
   15017             :                     json_key_uniqueness_constraint_opt      %prec IS
   15018             :                 {
   15019         304 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   15020             : 
   15021         304 :                     $$ = makeJsonIsPredicate($1, format, $3, $4, @1);
   15022             :                 }
   15023             :             /*
   15024             :              * Required by SQL/JSON, but there are conflicts
   15025             :             | a_expr
   15026             :                 json_format_clause
   15027             :                 IS  json_predicate_type_constraint
   15028             :                     json_key_uniqueness_constraint_opt      %prec IS
   15029             :                 {
   15030             :                     $$ = makeJsonIsPredicate($1, $2, $4, $5, @1);
   15031             :                 }
   15032             :             */
   15033             :             | a_expr IS NOT
   15034             :                     json_predicate_type_constraint
   15035             :                     json_key_uniqueness_constraint_opt      %prec IS
   15036             :                 {
   15037          46 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   15038             : 
   15039          46 :                     $$ = makeNotExpr(makeJsonIsPredicate($1, format, $4, $5, @1), @1);
   15040             :                 }
   15041             :             /*
   15042             :              * Required by SQL/JSON, but there are conflicts
   15043             :             | a_expr
   15044             :                 json_format_clause
   15045             :                 IS NOT
   15046             :                     json_predicate_type_constraint
   15047             :                     json_key_uniqueness_constraint_opt      %prec IS
   15048             :                 {
   15049             :                     $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, @1), @1);
   15050             :                 }
   15051             :             */
   15052             :             | DEFAULT
   15053             :                 {
   15054             :                     /*
   15055             :                      * The SQL spec only allows DEFAULT in "contextually typed
   15056             :                      * expressions", but for us, it's easier to allow it in
   15057             :                      * any a_expr and then throw error during parse analysis
   15058             :                      * if it's in an inappropriate context.  This way also
   15059             :                      * lets us say something smarter than "syntax error".
   15060             :                      */
   15061        1388 :                     SetToDefault *n = makeNode(SetToDefault);
   15062             : 
   15063             :                     /* parse analysis will fill in the rest */
   15064        1388 :                     n->location = @1;
   15065        1388 :                     $$ = (Node *) n;
   15066             :                 }
   15067             :         ;
   15068             : 
   15069             : /*
   15070             :  * Restricted expressions
   15071             :  *
   15072             :  * b_expr is a subset of the complete expression syntax defined by a_expr.
   15073             :  *
   15074             :  * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
   15075             :  * cause trouble in the places where b_expr is used.  For simplicity, we
   15076             :  * just eliminate all the boolean-keyword-operator productions from b_expr.
   15077             :  */
   15078             : b_expr:     c_expr
   15079        3450 :                 { $$ = $1; }
   15080             :             | b_expr TYPECAST Typename
   15081         134 :                 { $$ = makeTypeCast($1, $3, @2); }
   15082             :             | '+' b_expr                    %prec UMINUS
   15083           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   15084             :             | '-' b_expr                    %prec UMINUS
   15085          66 :                 { $$ = doNegate($2, @1); }
   15086             :             | b_expr '+' b_expr
   15087          30 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   15088             :             | b_expr '-' b_expr
   15089          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   15090             :             | b_expr '*' b_expr
   15091          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   15092             :             | b_expr '/' b_expr
   15093           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   15094             :             | b_expr '%' b_expr
   15095           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   15096             :             | b_expr '^' b_expr
   15097           6 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   15098             :             | b_expr '<' b_expr
   15099           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   15100             :             | b_expr '>' b_expr
   15101           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   15102             :             | b_expr '=' b_expr
   15103           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   15104             :             | b_expr LESS_EQUALS b_expr
   15105           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   15106             :             | b_expr GREATER_EQUALS b_expr
   15107           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   15108             :             | b_expr NOT_EQUALS b_expr
   15109           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   15110             :             | b_expr qual_Op b_expr             %prec Op
   15111          12 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   15112             :             | qual_Op b_expr                    %prec Op
   15113           0 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   15114             :             | b_expr IS DISTINCT FROM b_expr        %prec IS
   15115             :                 {
   15116           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   15117             :                 }
   15118             :             | b_expr IS NOT DISTINCT FROM b_expr    %prec IS
   15119             :                 {
   15120           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   15121             :                 }
   15122             :             | b_expr IS DOCUMENT_P                  %prec IS
   15123             :                 {
   15124           0 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15125           0 :                                      list_make1($1), @2);
   15126             :                 }
   15127             :             | b_expr IS NOT DOCUMENT_P              %prec IS
   15128             :                 {
   15129           0 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15130           0 :                                                  list_make1($1), @2),
   15131           0 :                                      @2);
   15132             :                 }
   15133             :         ;
   15134             : 
   15135             : /*
   15136             :  * Productions that can be used in both a_expr and b_expr.
   15137             :  *
   15138             :  * Note: productions that refer recursively to a_expr or b_expr mostly
   15139             :  * cannot appear here.  However, it's OK to refer to a_exprs that occur
   15140             :  * inside parentheses, such as function arguments; that cannot introduce
   15141             :  * ambiguity to the b_expr syntax.
   15142             :  */
   15143     1496254 : c_expr:     columnref                               { $$ = $1; }
   15144     1083486 :             | AexprConst                            { $$ = $1; }
   15145             :             | PARAM opt_indirection
   15146             :                 {
   15147      142438 :                     ParamRef   *p = makeNode(ParamRef);
   15148             : 
   15149      142438 :                     p->number = $1;
   15150      142438 :                     p->location = @1;
   15151      142438 :                     if ($2)
   15152             :                     {
   15153        1138 :                         A_Indirection *n = makeNode(A_Indirection);
   15154             : 
   15155        1138 :                         n->arg = (Node *) p;
   15156        1138 :                         n->indirection = check_indirection($2, yyscanner);
   15157        1138 :                         $$ = (Node *) n;
   15158             :                     }
   15159             :                     else
   15160      141300 :                         $$ = (Node *) p;
   15161             :                 }
   15162             :             | '(' a_expr ')' opt_indirection
   15163             :                 {
   15164       85856 :                     if ($4)
   15165             :                     {
   15166        9964 :                         A_Indirection *n = makeNode(A_Indirection);
   15167             : 
   15168        9964 :                         n->arg = $2;
   15169        9964 :                         n->indirection = check_indirection($4, yyscanner);
   15170        9964 :                         $$ = (Node *) n;
   15171             :                     }
   15172             :                     else
   15173       75892 :                         $$ = $2;
   15174             :                 }
   15175             :             | case_expr
   15176       52486 :                 { $$ = $1; }
   15177             :             | func_expr
   15178      360920 :                 { $$ = $1; }
   15179             :             | select_with_parens            %prec UMINUS
   15180             :                 {
   15181       22088 :                     SubLink    *n = makeNode(SubLink);
   15182             : 
   15183       22088 :                     n->subLinkType = EXPR_SUBLINK;
   15184       22088 :                     n->subLinkId = 0;
   15185       22088 :                     n->testexpr = NULL;
   15186       22088 :                     n->operName = NIL;
   15187       22088 :                     n->subselect = $1;
   15188       22088 :                     n->location = @1;
   15189       22088 :                     $$ = (Node *) n;
   15190             :                 }
   15191             :             | select_with_parens indirection
   15192             :                 {
   15193             :                     /*
   15194             :                      * Because the select_with_parens nonterminal is designed
   15195             :                      * to "eat" as many levels of parens as possible, the
   15196             :                      * '(' a_expr ')' opt_indirection production above will
   15197             :                      * fail to match a sub-SELECT with indirection decoration;
   15198             :                      * the sub-SELECT won't be regarded as an a_expr as long
   15199             :                      * as there are parens around it.  To support applying
   15200             :                      * subscripting or field selection to a sub-SELECT result,
   15201             :                      * we need this redundant-looking production.
   15202             :                      */
   15203          18 :                     SubLink    *n = makeNode(SubLink);
   15204          18 :                     A_Indirection *a = makeNode(A_Indirection);
   15205             : 
   15206          18 :                     n->subLinkType = EXPR_SUBLINK;
   15207          18 :                     n->subLinkId = 0;
   15208          18 :                     n->testexpr = NULL;
   15209          18 :                     n->operName = NIL;
   15210          18 :                     n->subselect = $1;
   15211          18 :                     n->location = @1;
   15212          18 :                     a->arg = (Node *) n;
   15213          18 :                     a->indirection = check_indirection($2, yyscanner);
   15214          18 :                     $$ = (Node *) a;
   15215             :                 }
   15216             :             | EXISTS select_with_parens
   15217             :                 {
   15218        5216 :                     SubLink    *n = makeNode(SubLink);
   15219             : 
   15220        5216 :                     n->subLinkType = EXISTS_SUBLINK;
   15221        5216 :                     n->subLinkId = 0;
   15222        5216 :                     n->testexpr = NULL;
   15223        5216 :                     n->operName = NIL;
   15224        5216 :                     n->subselect = $2;
   15225        5216 :                     n->location = @1;
   15226        5216 :                     $$ = (Node *) n;
   15227             :                 }
   15228             :             | ARRAY select_with_parens
   15229             :                 {
   15230        7240 :                     SubLink    *n = makeNode(SubLink);
   15231             : 
   15232        7240 :                     n->subLinkType = ARRAY_SUBLINK;
   15233        7240 :                     n->subLinkId = 0;
   15234        7240 :                     n->testexpr = NULL;
   15235        7240 :                     n->operName = NIL;
   15236        7240 :                     n->subselect = $2;
   15237        7240 :                     n->location = @1;
   15238        7240 :                     $$ = (Node *) n;
   15239             :                 }
   15240             :             | ARRAY array_expr
   15241             :                 {
   15242        7362 :                     A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
   15243             : 
   15244             :                     /* point outermost A_ArrayExpr to the ARRAY keyword */
   15245        7362 :                     n->location = @1;
   15246        7362 :                     $$ = (Node *) n;
   15247             :                 }
   15248             :             | explicit_row
   15249             :                 {
   15250        3778 :                     RowExpr    *r = makeNode(RowExpr);
   15251             : 
   15252        3778 :                     r->args = $1;
   15253        3778 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15254        3778 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15255        3778 :                     r->row_format = COERCE_EXPLICIT_CALL; /* abuse */
   15256        3778 :                     r->location = @1;
   15257        3778 :                     $$ = (Node *) r;
   15258             :                 }
   15259             :             | implicit_row
   15260             :                 {
   15261        2124 :                     RowExpr    *r = makeNode(RowExpr);
   15262             : 
   15263        2124 :                     r->args = $1;
   15264        2124 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15265        2124 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15266        2124 :                     r->row_format = COERCE_IMPLICIT_CAST; /* abuse */
   15267        2124 :                     r->location = @1;
   15268        2124 :                     $$ = (Node *) r;
   15269             :                 }
   15270             :             | GROUPING '(' expr_list ')'
   15271             :               {
   15272         314 :                   GroupingFunc *g = makeNode(GroupingFunc);
   15273             : 
   15274         314 :                   g->args = $3;
   15275         314 :                   g->location = @1;
   15276         314 :                   $$ = (Node *) g;
   15277             :               }
   15278             :         ;
   15279             : 
   15280             : func_application: func_name '(' ')'
   15281             :                 {
   15282       46592 :                     $$ = (Node *) makeFuncCall($1, NIL,
   15283             :                                                COERCE_EXPLICIT_CALL,
   15284       46592 :                                                @1);
   15285             :                 }
   15286             :             | func_name '(' func_arg_list opt_sort_clause ')'
   15287             :                 {
   15288      279184 :                     FuncCall   *n = makeFuncCall($1, $3,
   15289             :                                                  COERCE_EXPLICIT_CALL,
   15290      279184 :                                                  @1);
   15291             : 
   15292      279184 :                     n->agg_order = $4;
   15293      279184 :                     $$ = (Node *) n;
   15294             :                 }
   15295             :             | func_name '(' VARIADIC func_arg_expr opt_sort_clause ')'
   15296             :                 {
   15297         578 :                     FuncCall   *n = makeFuncCall($1, list_make1($4),
   15298             :                                                  COERCE_EXPLICIT_CALL,
   15299         578 :                                                  @1);
   15300             : 
   15301         578 :                     n->func_variadic = true;
   15302         578 :                     n->agg_order = $5;
   15303         578 :                     $$ = (Node *) n;
   15304             :                 }
   15305             :             | func_name '(' func_arg_list ',' VARIADIC func_arg_expr opt_sort_clause ')'
   15306             :                 {
   15307         120 :                     FuncCall   *n = makeFuncCall($1, lappend($3, $6),
   15308             :                                                  COERCE_EXPLICIT_CALL,
   15309         120 :                                                  @1);
   15310             : 
   15311         120 :                     n->func_variadic = true;
   15312         120 :                     n->agg_order = $7;
   15313         120 :                     $$ = (Node *) n;
   15314             :                 }
   15315             :             | func_name '(' ALL func_arg_list opt_sort_clause ')'
   15316             :                 {
   15317           0 :                     FuncCall   *n = makeFuncCall($1, $4,
   15318             :                                                  COERCE_EXPLICIT_CALL,
   15319           0 :                                                  @1);
   15320             : 
   15321           0 :                     n->agg_order = $5;
   15322             :                     /* Ideally we'd mark the FuncCall node to indicate
   15323             :                      * "must be an aggregate", but there's no provision
   15324             :                      * for that in FuncCall at the moment.
   15325             :                      */
   15326           0 :                     $$ = (Node *) n;
   15327             :                 }
   15328             :             | func_name '(' DISTINCT func_arg_list opt_sort_clause ')'
   15329             :                 {
   15330         522 :                     FuncCall   *n = makeFuncCall($1, $4,
   15331             :                                                  COERCE_EXPLICIT_CALL,
   15332         522 :                                                  @1);
   15333             : 
   15334         522 :                     n->agg_order = $5;
   15335         522 :                     n->agg_distinct = true;
   15336         522 :                     $$ = (Node *) n;
   15337             :                 }
   15338             :             | func_name '(' '*' ')'
   15339             :                 {
   15340             :                     /*
   15341             :                      * We consider AGGREGATE(*) to invoke a parameterless
   15342             :                      * aggregate.  This does the right thing for COUNT(*),
   15343             :                      * and there are no other aggregates in SQL that accept
   15344             :                      * '*' as parameter.
   15345             :                      *
   15346             :                      * The FuncCall node is also marked agg_star = true,
   15347             :                      * so that later processing can detect what the argument
   15348             :                      * really was.
   15349             :                      */
   15350       11968 :                     FuncCall   *n = makeFuncCall($1, NIL,
   15351             :                                                  COERCE_EXPLICIT_CALL,
   15352       11968 :                                                  @1);
   15353             : 
   15354       11968 :                     n->agg_star = true;
   15355       11968 :                     $$ = (Node *) n;
   15356             :                 }
   15357             :         ;
   15358             : 
   15359             : 
   15360             : /*
   15361             :  * func_expr and its cousin func_expr_windowless are split out from c_expr just
   15362             :  * so that we have classifications for "everything that is a function call or
   15363             :  * looks like one".  This isn't very important, but it saves us having to
   15364             :  * document which variants are legal in places like "FROM function()" or the
   15365             :  * backwards-compatible functional-index syntax for CREATE INDEX.
   15366             :  * (Note that many of the special SQL functions wouldn't actually make any
   15367             :  * sense as functional index entries, but we ignore that consideration here.)
   15368             :  */
   15369             : func_expr: func_application within_group_clause filter_clause over_clause
   15370             :                 {
   15371      298742 :                     FuncCall   *n = (FuncCall *) $1;
   15372             : 
   15373             :                     /*
   15374             :                      * The order clause for WITHIN GROUP and the one for
   15375             :                      * plain-aggregate ORDER BY share a field, so we have to
   15376             :                      * check here that at most one is present.  We also check
   15377             :                      * for DISTINCT and VARIADIC here to give a better error
   15378             :                      * location.  Other consistency checks are deferred to
   15379             :                      * parse analysis.
   15380             :                      */
   15381      298742 :                     if ($2 != NIL)
   15382             :                     {
   15383         348 :                         if (n->agg_order != NIL)
   15384           6 :                             ereport(ERROR,
   15385             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15386             :                                      errmsg("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
   15387             :                                      parser_errposition(@2)));
   15388         342 :                         if (n->agg_distinct)
   15389           0 :                             ereport(ERROR,
   15390             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15391             :                                      errmsg("cannot use DISTINCT with WITHIN GROUP"),
   15392             :                                      parser_errposition(@2)));
   15393         342 :                         if (n->func_variadic)
   15394           0 :                             ereport(ERROR,
   15395             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15396             :                                      errmsg("cannot use VARIADIC with WITHIN GROUP"),
   15397             :                                      parser_errposition(@2)));
   15398         342 :                         n->agg_order = $2;
   15399         342 :                         n->agg_within_group = true;
   15400             :                     }
   15401      298736 :                     n->agg_filter = $3;
   15402      298736 :                     n->over = $4;
   15403      298736 :                     $$ = (Node *) n;
   15404             :                 }
   15405             :             | json_aggregate_func filter_clause over_clause
   15406             :                 {
   15407         612 :                     JsonAggConstructor *n = IsA($1, JsonObjectAgg) ?
   15408         306 :                         ((JsonObjectAgg *) $1)->constructor :
   15409         150 :                         ((JsonArrayAgg *) $1)->constructor;
   15410             : 
   15411         306 :                     n->agg_filter = $2;
   15412         306 :                     n->over = $3;
   15413         306 :                     $$ = (Node *) $1;
   15414             :                 }
   15415             :             | func_expr_common_subexpr
   15416       61878 :                 { $$ = $1; }
   15417             :         ;
   15418             : 
   15419             : /*
   15420             :  * As func_expr but does not accept WINDOW functions directly
   15421             :  * (but they can still be contained in arguments for functions etc).
   15422             :  * Use this when window expressions are not allowed, where needed to
   15423             :  * disambiguate the grammar (e.g. in CREATE INDEX).
   15424             :  */
   15425             : func_expr_windowless:
   15426       39688 :             func_application                        { $$ = $1; }
   15427         396 :             | func_expr_common_subexpr              { $$ = $1; }
   15428           0 :             | json_aggregate_func                   { $$ = $1; }
   15429             :         ;
   15430             : 
   15431             : /*
   15432             :  * Special expressions that are considered to be functions.
   15433             :  */
   15434             : func_expr_common_subexpr:
   15435             :             COLLATION FOR '(' a_expr ')'
   15436             :                 {
   15437          30 :                     $$ = (Node *) makeFuncCall(SystemFuncName("pg_collation_for"),
   15438          30 :                                                list_make1($4),
   15439             :                                                COERCE_SQL_SYNTAX,
   15440          30 :                                                @1);
   15441             :                 }
   15442             :             | CURRENT_DATE
   15443             :                 {
   15444         268 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_DATE, -1, @1);
   15445             :                 }
   15446             :             | CURRENT_TIME
   15447             :                 {
   15448          24 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME, -1, @1);
   15449             :                 }
   15450             :             | CURRENT_TIME '(' Iconst ')'
   15451             :                 {
   15452          24 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME_N, $3, @1);
   15453             :                 }
   15454             :             | CURRENT_TIMESTAMP
   15455             :                 {
   15456         282 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP, -1, @1);
   15457             :                 }
   15458             :             | CURRENT_TIMESTAMP '(' Iconst ')'
   15459             :                 {
   15460         154 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP_N, $3, @1);
   15461             :                 }
   15462             :             | LOCALTIME
   15463             :                 {
   15464          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIME, -1, @1);
   15465             :                 }
   15466             :             | LOCALTIME '(' Iconst ')'
   15467             :                 {
   15468          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIME_N, $3, @1);
   15469             :                 }
   15470             :             | LOCALTIMESTAMP
   15471             :                 {
   15472          36 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP, -1, @1);
   15473             :                 }
   15474             :             | LOCALTIMESTAMP '(' Iconst ')'
   15475             :                 {
   15476          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP_N, $3, @1);
   15477             :                 }
   15478             :             | CURRENT_ROLE
   15479             :                 {
   15480          68 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_ROLE, -1, @1);
   15481             :                 }
   15482             :             | CURRENT_USER
   15483             :                 {
   15484         842 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_USER, -1, @1);
   15485             :                 }
   15486             :             | SESSION_USER
   15487             :                 {
   15488         534 :                     $$ = makeSQLValueFunction(SVFOP_SESSION_USER, -1, @1);
   15489             :                 }
   15490             :             | SYSTEM_USER
   15491             :                 {
   15492          20 :                     $$ = (Node *) makeFuncCall(SystemFuncName("system_user"),
   15493             :                                                NIL,
   15494             :                                                COERCE_SQL_SYNTAX,
   15495             :                                                @1);
   15496             :                 }
   15497             :             | USER
   15498             :                 {
   15499          24 :                     $$ = makeSQLValueFunction(SVFOP_USER, -1, @1);
   15500             :                 }
   15501             :             | CURRENT_CATALOG
   15502             :                 {
   15503          30 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_CATALOG, -1, @1);
   15504             :                 }
   15505             :             | CURRENT_SCHEMA
   15506             :                 {
   15507          30 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_SCHEMA, -1, @1);
   15508             :                 }
   15509             :             | CAST '(' a_expr AS Typename ')'
   15510       49612 :                 { $$ = makeTypeCast($3, $5, @1); }
   15511             :             | EXTRACT '(' extract_list ')'
   15512             :                 {
   15513        1200 :                     $$ = (Node *) makeFuncCall(SystemFuncName("extract"),
   15514        1200 :                                                $3,
   15515             :                                                COERCE_SQL_SYNTAX,
   15516        1200 :                                                @1);
   15517             :                 }
   15518             :             | NORMALIZE '(' a_expr ')'
   15519             :                 {
   15520          18 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   15521          18 :                                                list_make1($3),
   15522             :                                                COERCE_SQL_SYNTAX,
   15523          18 :                                                @1);
   15524             :                 }
   15525             :             | NORMALIZE '(' a_expr ',' unicode_normal_form ')'
   15526             :                 {
   15527          36 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   15528          36 :                                                list_make2($3, makeStringConst($5, @5)),
   15529             :                                                COERCE_SQL_SYNTAX,
   15530          36 :                                                @1);
   15531             :                 }
   15532             :             | OVERLAY '(' overlay_list ')'
   15533             :                 {
   15534          82 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlay"),
   15535          82 :                                                $3,
   15536             :                                                COERCE_SQL_SYNTAX,
   15537          82 :                                                @1);
   15538             :                 }
   15539             :             | OVERLAY '(' func_arg_list_opt ')'
   15540             :                 {
   15541             :                     /*
   15542             :                      * allow functions named overlay() to be called without
   15543             :                      * special syntax
   15544             :                      */
   15545           0 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("overlay")),
   15546           0 :                                                $3,
   15547             :                                                COERCE_EXPLICIT_CALL,
   15548           0 :                                                @1);
   15549             :                 }
   15550             :             | POSITION '(' position_list ')'
   15551             :                 {
   15552             :                     /*
   15553             :                      * position(A in B) is converted to position(B, A)
   15554             :                      *
   15555             :                      * We deliberately don't offer a "plain syntax" option
   15556             :                      * for position(), because the reversal of the arguments
   15557             :                      * creates too much risk of confusion.
   15558             :                      */
   15559         350 :                     $$ = (Node *) makeFuncCall(SystemFuncName("position"),
   15560         350 :                                                $3,
   15561             :                                                COERCE_SQL_SYNTAX,
   15562         350 :                                                @1);
   15563             :                 }
   15564             :             | SUBSTRING '(' substr_list ')'
   15565             :                 {
   15566             :                     /* substring(A from B for C) is converted to
   15567             :                      * substring(A, B, C) - thomas 2000-11-28
   15568             :                      */
   15569         630 :                     $$ = (Node *) makeFuncCall(SystemFuncName("substring"),
   15570         630 :                                                $3,
   15571             :                                                COERCE_SQL_SYNTAX,
   15572         630 :                                                @1);
   15573             :                 }
   15574             :             | SUBSTRING '(' func_arg_list_opt ')'
   15575             :                 {
   15576             :                     /*
   15577             :                      * allow functions named substring() to be called without
   15578             :                      * special syntax
   15579             :                      */
   15580         188 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("substring")),
   15581         188 :                                                $3,
   15582             :                                                COERCE_EXPLICIT_CALL,
   15583         188 :                                                @1);
   15584             :                 }
   15585             :             | TREAT '(' a_expr AS Typename ')'
   15586             :                 {
   15587             :                     /* TREAT(expr AS target) converts expr of a particular type to target,
   15588             :                      * which is defined to be a subtype of the original expression.
   15589             :                      * In SQL99, this is intended for use with structured UDTs,
   15590             :                      * but let's make this a generally useful form allowing stronger
   15591             :                      * coercions than are handled by implicit casting.
   15592             :                      *
   15593             :                      * Convert SystemTypeName() to SystemFuncName() even though
   15594             :                      * at the moment they result in the same thing.
   15595             :                      */
   15596           0 :                     $$ = (Node *) makeFuncCall(SystemFuncName(strVal(llast($5->names))),
   15597           0 :                                                list_make1($3),
   15598             :                                                COERCE_EXPLICIT_CALL,
   15599           0 :                                                @1);
   15600             :                 }
   15601             :             | TRIM '(' BOTH trim_list ')'
   15602             :                 {
   15603             :                     /* various trim expressions are defined in SQL
   15604             :                      * - thomas 1997-07-19
   15605             :                      */
   15606          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   15607          12 :                                                $4,
   15608             :                                                COERCE_SQL_SYNTAX,
   15609          12 :                                                @1);
   15610             :                 }
   15611             :             | TRIM '(' LEADING trim_list ')'
   15612             :                 {
   15613          24 :                     $$ = (Node *) makeFuncCall(SystemFuncName("ltrim"),
   15614          24 :                                                $4,
   15615             :                                                COERCE_SQL_SYNTAX,
   15616          24 :                                                @1);
   15617             :                 }
   15618             :             | TRIM '(' TRAILING trim_list ')'
   15619             :                 {
   15620         536 :                     $$ = (Node *) makeFuncCall(SystemFuncName("rtrim"),
   15621         536 :                                                $4,
   15622             :                                                COERCE_SQL_SYNTAX,
   15623         536 :                                                @1);
   15624             :                 }
   15625             :             | TRIM '(' trim_list ')'
   15626             :                 {
   15627          98 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   15628          98 :                                                $3,
   15629             :                                                COERCE_SQL_SYNTAX,
   15630          98 :                                                @1);
   15631             :                 }
   15632             :             | NULLIF '(' a_expr ',' a_expr ')'
   15633             :                 {
   15634         242 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
   15635             :                 }
   15636             :             | COALESCE '(' expr_list ')'
   15637             :                 {
   15638        3038 :                     CoalesceExpr *c = makeNode(CoalesceExpr);
   15639             : 
   15640        3038 :                     c->args = $3;
   15641        3038 :                     c->location = @1;
   15642        3038 :                     $$ = (Node *) c;
   15643             :                 }
   15644             :             | GREATEST '(' expr_list ')'
   15645             :                 {
   15646         132 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   15647             : 
   15648         132 :                     v->args = $3;
   15649         132 :                     v->op = IS_GREATEST;
   15650         132 :                     v->location = @1;
   15651         132 :                     $$ = (Node *) v;
   15652             :                 }
   15653             :             | LEAST '(' expr_list ')'
   15654             :                 {
   15655         142 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   15656             : 
   15657         142 :                     v->args = $3;
   15658         142 :                     v->op = IS_LEAST;
   15659         142 :                     v->location = @1;
   15660         142 :                     $$ = (Node *) v;
   15661             :                 }
   15662             :             | XMLCONCAT '(' expr_list ')'
   15663             :                 {
   15664          62 :                     $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
   15665             :                 }
   15666             :             | XMLELEMENT '(' NAME_P ColLabel ')'
   15667             :                 {
   15668           6 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
   15669             :                 }
   15670             :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
   15671             :                 {
   15672          36 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
   15673             :                 }
   15674             :             | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
   15675             :                 {
   15676         116 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
   15677             :                 }
   15678             :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
   15679             :                 {
   15680          20 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
   15681             :                 }
   15682             :             | XMLEXISTS '(' c_expr xmlexists_argument ')'
   15683             :                 {
   15684             :                     /* xmlexists(A PASSING [BY REF] B [BY REF]) is
   15685             :                      * converted to xmlexists(A, B)*/
   15686          54 :                     $$ = (Node *) makeFuncCall(SystemFuncName("xmlexists"),
   15687          54 :                                                list_make2($3, $4),
   15688             :                                                COERCE_SQL_SYNTAX,
   15689          54 :                                                @1);
   15690             :                 }
   15691             :             | XMLFOREST '(' xml_attribute_list ')'
   15692             :                 {
   15693          32 :                     $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
   15694             :                 }
   15695             :             | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
   15696             :                 {
   15697             :                     XmlExpr *x = (XmlExpr *)
   15698         140 :                         makeXmlExpr(IS_XMLPARSE, NULL, NIL,
   15699         140 :                                     list_make2($4, makeBoolAConst($5, -1)),
   15700         140 :                                     @1);
   15701             : 
   15702         140 :                     x->xmloption = $3;
   15703         140 :                     $$ = (Node *) x;
   15704             :                 }
   15705             :             | XMLPI '(' NAME_P ColLabel ')'
   15706             :                 {
   15707          30 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
   15708             :                 }
   15709             :             | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
   15710             :                 {
   15711          50 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
   15712             :                 }
   15713             :             | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
   15714             :                 {
   15715          68 :                     $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
   15716          68 :                                      list_make3($3, $5, $6), @1);
   15717             :                 }
   15718             :             | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename xml_indent_option ')'
   15719             :                 {
   15720         190 :                     XmlSerialize *n = makeNode(XmlSerialize);
   15721             : 
   15722         190 :                     n->xmloption = $3;
   15723         190 :                     n->expr = $4;
   15724         190 :                     n->typeName = $6;
   15725         190 :                     n->indent = $7;
   15726         190 :                     n->location = @1;
   15727         190 :                     $$ = (Node *) n;
   15728             :                 }
   15729             :             | JSON_OBJECT '(' func_arg_list ')'
   15730             :                 {
   15731             :                     /* Support for legacy (non-standard) json_object() */
   15732          90 :                     $$ = (Node *) makeFuncCall(SystemFuncName("json_object"),
   15733          90 :                                                $3, COERCE_EXPLICIT_CALL, @1);
   15734             :                 }
   15735             :             | JSON_OBJECT '(' json_name_and_value_list
   15736             :                 json_object_constructor_null_clause_opt
   15737             :                 json_key_uniqueness_constraint_opt
   15738             :                 json_returning_clause_opt ')'
   15739             :                 {
   15740         288 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   15741             : 
   15742         288 :                     n->exprs = $3;
   15743         288 :                     n->absent_on_null = $4;
   15744         288 :                     n->unique = $5;
   15745         288 :                     n->output = (JsonOutput *) $6;
   15746         288 :                     n->location = @1;
   15747         288 :                     $$ = (Node *) n;
   15748             :                 }
   15749             :             | JSON_OBJECT '(' json_returning_clause_opt ')'
   15750             :                 {
   15751          92 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   15752             : 
   15753          92 :                     n->exprs = NULL;
   15754          92 :                     n->absent_on_null = false;
   15755          92 :                     n->unique = false;
   15756          92 :                     n->output = (JsonOutput *) $3;
   15757          92 :                     n->location = @1;
   15758          92 :                     $$ = (Node *) n;
   15759             :                 }
   15760             :             | JSON_ARRAY '('
   15761             :                 json_value_expr_list
   15762             :                 json_array_constructor_null_clause_opt
   15763             :                 json_returning_clause_opt
   15764             :             ')'
   15765             :                 {
   15766          96 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   15767             : 
   15768          96 :                     n->exprs = $3;
   15769          96 :                     n->absent_on_null = $4;
   15770          96 :                     n->output = (JsonOutput *) $5;
   15771          96 :                     n->location = @1;
   15772          96 :                     $$ = (Node *) n;
   15773             :                 }
   15774             :             | JSON_ARRAY '('
   15775             :                 select_no_parens
   15776             :                 json_format_clause_opt
   15777             :                 /* json_array_constructor_null_clause_opt */
   15778             :                 json_returning_clause_opt
   15779             :             ')'
   15780             :                 {
   15781          54 :                     JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
   15782             : 
   15783          54 :                     n->query = $3;
   15784          54 :                     n->format = (JsonFormat *) $4;
   15785          54 :                     n->absent_on_null = true;    /* XXX */
   15786          54 :                     n->output = (JsonOutput *) $5;
   15787          54 :                     n->location = @1;
   15788          54 :                     $$ = (Node *) n;
   15789             :                 }
   15790             :             | JSON_ARRAY '('
   15791             :                 json_returning_clause_opt
   15792             :             ')'
   15793             :                 {
   15794          86 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   15795             : 
   15796          86 :                     n->exprs = NIL;
   15797          86 :                     n->absent_on_null = true;
   15798          86 :                     n->output = (JsonOutput *) $3;
   15799          86 :                     n->location = @1;
   15800          86 :                     $$ = (Node *) n;
   15801             :                 }
   15802             :             | JSON '(' json_value_expr json_key_uniqueness_constraint_opt ')'
   15803             :                 {
   15804         164 :                     JsonParseExpr *n = makeNode(JsonParseExpr);
   15805             : 
   15806         164 :                     n->expr = (JsonValueExpr *) $3;
   15807         164 :                     n->unique_keys = $4;
   15808         164 :                     n->output = NULL;
   15809         164 :                     n->location = @1;
   15810         164 :                     $$ = (Node *) n;
   15811             :                 }
   15812             :             | JSON_SCALAR '(' a_expr ')'
   15813             :                 {
   15814         112 :                     JsonScalarExpr *n = makeNode(JsonScalarExpr);
   15815             : 
   15816         112 :                     n->expr = (Expr *) $3;
   15817         112 :                     n->output = NULL;
   15818         112 :                     n->location = @1;
   15819         112 :                     $$ = (Node *) n;
   15820             :                 }
   15821             :             | JSON_SERIALIZE '(' json_value_expr json_returning_clause_opt ')'
   15822             :                 {
   15823          90 :                     JsonSerializeExpr *n = makeNode(JsonSerializeExpr);
   15824             : 
   15825          90 :                     n->expr = (JsonValueExpr *) $3;
   15826          90 :                     n->output = (JsonOutput *) $4;
   15827          90 :                     n->location = @1;
   15828          90 :                     $$ = (Node *) n;
   15829             :                 }
   15830             :             | MERGE_ACTION '(' ')'
   15831             :                 {
   15832         126 :                     MergeSupportFunc *m = makeNode(MergeSupportFunc);
   15833             : 
   15834         126 :                     m->msftype = TEXTOID;
   15835         126 :                     m->location = @1;
   15836         126 :                     $$ = (Node *) m;
   15837             :                 }
   15838             :             | JSON_QUERY '('
   15839             :                 json_value_expr ',' a_expr json_passing_clause_opt
   15840             :                 json_returning_clause_opt
   15841             :                 json_wrapper_behavior
   15842             :                 json_quotes_clause_opt
   15843             :                 json_behavior_clause_opt
   15844             :             ')'
   15845             :                 {
   15846         864 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   15847             : 
   15848         864 :                     n->op = JSON_QUERY_OP;
   15849         864 :                     n->context_item = (JsonValueExpr *) $3;
   15850         864 :                     n->pathspec = $5;
   15851         864 :                     n->passing = $6;
   15852         864 :                     n->output = (JsonOutput *) $7;
   15853         864 :                     n->wrapper = $8;
   15854         864 :                     n->quotes = $9;
   15855         864 :                     n->on_empty = (JsonBehavior *) linitial($10);
   15856         864 :                     n->on_error = (JsonBehavior *) lsecond($10);
   15857         864 :                     n->location = @1;
   15858         864 :                     $$ = (Node *) n;
   15859             :                 }
   15860             :             | JSON_EXISTS '('
   15861             :                 json_value_expr ',' a_expr json_passing_clause_opt
   15862             :                 json_on_error_clause_opt
   15863             :             ')'
   15864             :                 {
   15865         162 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   15866             : 
   15867         162 :                     n->op = JSON_EXISTS_OP;
   15868         162 :                     n->context_item = (JsonValueExpr *) $3;
   15869         162 :                     n->pathspec = $5;
   15870         162 :                     n->passing = $6;
   15871         162 :                     n->output = NULL;
   15872         162 :                     n->on_error = (JsonBehavior *) $7;
   15873         162 :                     n->location = @1;
   15874         162 :                     $$ = (Node *) n;
   15875             :                 }
   15876             :             | JSON_VALUE '('
   15877             :                 json_value_expr ',' a_expr json_passing_clause_opt
   15878             :                 json_returning_clause_opt
   15879             :                 json_behavior_clause_opt
   15880             :             ')'
   15881             :                 {
   15882         468 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   15883             : 
   15884         468 :                     n->op = JSON_VALUE_OP;
   15885         468 :                     n->context_item = (JsonValueExpr *) $3;
   15886         468 :                     n->pathspec = $5;
   15887         468 :                     n->passing = $6;
   15888         468 :                     n->output = (JsonOutput *) $7;
   15889         468 :                     n->on_empty = (JsonBehavior *) linitial($8);
   15890         468 :                     n->on_error = (JsonBehavior *) lsecond($8);
   15891         468 :                     n->location = @1;
   15892         468 :                     $$ = (Node *) n;
   15893             :                 }
   15894             :             ;
   15895             : 
   15896             : 
   15897             : /*
   15898             :  * SQL/XML support
   15899             :  */
   15900             : xml_root_version: VERSION_P a_expr
   15901          24 :                 { $$ = $2; }
   15902             :             | VERSION_P NO VALUE_P
   15903          44 :                 { $$ = makeNullAConst(-1); }
   15904             :         ;
   15905             : 
   15906             : opt_xml_root_standalone: ',' STANDALONE_P YES_P
   15907          26 :                 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
   15908             :             | ',' STANDALONE_P NO
   15909          12 :                 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
   15910             :             | ',' STANDALONE_P NO VALUE_P
   15911          12 :                 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
   15912             :             | /*EMPTY*/
   15913          18 :                 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
   15914             :         ;
   15915             : 
   15916          56 : xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')'    { $$ = $3; }
   15917             :         ;
   15918             : 
   15919          88 : xml_attribute_list: xml_attribute_el                    { $$ = list_make1($1); }
   15920         144 :             | xml_attribute_list ',' xml_attribute_el   { $$ = lappend($1, $3); }
   15921             :         ;
   15922             : 
   15923             : xml_attribute_el: a_expr AS ColLabel
   15924             :                 {
   15925         106 :                     $$ = makeNode(ResTarget);
   15926         106 :                     $$->name = $3;
   15927         106 :                     $$->indirection = NIL;
   15928         106 :                     $$->val = (Node *) $1;
   15929         106 :                     $$->location = @1;
   15930             :                 }
   15931             :             | a_expr
   15932             :                 {
   15933         126 :                     $$ = makeNode(ResTarget);
   15934         126 :                     $$->name = NULL;
   15935         126 :                     $$->indirection = NIL;
   15936         126 :                     $$->val = (Node *) $1;
   15937         126 :                     $$->location = @1;
   15938             :                 }
   15939             :         ;
   15940             : 
   15941         162 : document_or_content: DOCUMENT_P                     { $$ = XMLOPTION_DOCUMENT; }
   15942         180 :             | CONTENT_P                             { $$ = XMLOPTION_CONTENT; }
   15943             :         ;
   15944             : 
   15945         120 : xml_indent_option: INDENT                           { $$ = true; }
   15946          24 :             | NO INDENT                             { $$ = false; }
   15947          46 :             | /*EMPTY*/                             { $$ = false; }
   15948             :         ;
   15949             : 
   15950           0 : xml_whitespace_option: PRESERVE WHITESPACE_P        { $$ = true; }
   15951           2 :             | STRIP_P WHITESPACE_P                  { $$ = false; }
   15952         138 :             | /*EMPTY*/                             { $$ = false; }
   15953             :         ;
   15954             : 
   15955             : /* We allow several variants for SQL and other compatibility. */
   15956             : xmlexists_argument:
   15957             :             PASSING c_expr
   15958             :                 {
   15959         226 :                     $$ = $2;
   15960             :                 }
   15961             :             | PASSING c_expr xml_passing_mech
   15962             :                 {
   15963           0 :                     $$ = $2;
   15964             :                 }
   15965             :             | PASSING xml_passing_mech c_expr
   15966             :                 {
   15967          42 :                     $$ = $3;
   15968             :                 }
   15969             :             | PASSING xml_passing_mech c_expr xml_passing_mech
   15970             :                 {
   15971           6 :                     $$ = $3;
   15972             :                 }
   15973             :         ;
   15974             : 
   15975             : xml_passing_mech:
   15976             :             BY REF_P
   15977             :             | BY VALUE_P
   15978             :         ;
   15979             : 
   15980             : 
   15981             : /*
   15982             :  * Aggregate decoration clauses
   15983             :  */
   15984             : within_group_clause:
   15985         348 :             WITHIN GROUP_P '(' sort_clause ')'      { $$ = $4; }
   15986      298400 :             | /*EMPTY*/                             { $$ = NIL; }
   15987             :         ;
   15988             : 
   15989             : filter_clause:
   15990         836 :             FILTER '(' WHERE a_expr ')'             { $$ = $4; }
   15991      298218 :             | /*EMPTY*/                             { $$ = NULL; }
   15992             :         ;
   15993             : 
   15994             : 
   15995             : /*
   15996             :  * Window Definitions
   15997             :  */
   15998             : window_clause:
   15999         528 :             WINDOW window_definition_list           { $$ = $2; }
   16000      451102 :             | /*EMPTY*/                             { $$ = NIL; }
   16001             :         ;
   16002             : 
   16003             : window_definition_list:
   16004         528 :             window_definition                       { $$ = list_make1($1); }
   16005             :             | window_definition_list ',' window_definition
   16006          12 :                                                     { $$ = lappend($1, $3); }
   16007             :         ;
   16008             : 
   16009             : window_definition:
   16010             :             ColId AS window_specification
   16011             :                 {
   16012         540 :                     WindowDef  *n = $3;
   16013             : 
   16014         540 :                     n->name = $1;
   16015         540 :                     $$ = n;
   16016             :                 }
   16017             :         ;
   16018             : 
   16019             : over_clause: OVER window_specification
   16020        2460 :                 { $$ = $2; }
   16021             :             | OVER ColId
   16022             :                 {
   16023         942 :                     WindowDef  *n = makeNode(WindowDef);
   16024             : 
   16025         942 :                     n->name = $2;
   16026         942 :                     n->refname = NULL;
   16027         942 :                     n->partitionClause = NIL;
   16028         942 :                     n->orderClause = NIL;
   16029         942 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   16030         942 :                     n->startOffset = NULL;
   16031         942 :                     n->endOffset = NULL;
   16032         942 :                     n->location = @2;
   16033         942 :                     $$ = n;
   16034             :                 }
   16035             :             | /*EMPTY*/
   16036      295646 :                 { $$ = NULL; }
   16037             :         ;
   16038             : 
   16039             : window_specification: '(' opt_existing_window_name opt_partition_clause
   16040             :                         opt_sort_clause opt_frame_clause ')'
   16041             :                 {
   16042        3000 :                     WindowDef  *n = makeNode(WindowDef);
   16043             : 
   16044        3000 :                     n->name = NULL;
   16045        3000 :                     n->refname = $2;
   16046        3000 :                     n->partitionClause = $3;
   16047        3000 :                     n->orderClause = $4;
   16048             :                     /* copy relevant fields of opt_frame_clause */
   16049        3000 :                     n->frameOptions = $5->frameOptions;
   16050        3000 :                     n->startOffset = $5->startOffset;
   16051        3000 :                     n->endOffset = $5->endOffset;
   16052        3000 :                     n->location = @1;
   16053        3000 :                     $$ = n;
   16054             :                 }
   16055             :         ;
   16056             : 
   16057             : /*
   16058             :  * If we see PARTITION, RANGE, ROWS or GROUPS as the first token after the '('
   16059             :  * of a window_specification, we want the assumption to be that there is
   16060             :  * no existing_window_name; but those keywords are unreserved and so could
   16061             :  * be ColIds.  We fix this by making them have the same precedence as IDENT
   16062             :  * and giving the empty production here a slightly higher precedence, so
   16063             :  * that the shift/reduce conflict is resolved in favor of reducing the rule.
   16064             :  * These keywords are thus precluded from being an existing_window_name but
   16065             :  * are not reserved for any other purpose.
   16066             :  */
   16067          30 : opt_existing_window_name: ColId                     { $$ = $1; }
   16068        2976 :             | /*EMPTY*/             %prec Op        { $$ = NULL; }
   16069             :         ;
   16070             : 
   16071         822 : opt_partition_clause: PARTITION BY expr_list        { $$ = $3; }
   16072        2178 :             | /*EMPTY*/                             { $$ = NIL; }
   16073             :         ;
   16074             : 
   16075             : /*
   16076             :  * For frame clauses, we return a WindowDef, but only some fields are used:
   16077             :  * frameOptions, startOffset, and endOffset.
   16078             :  */
   16079             : opt_frame_clause:
   16080             :             RANGE frame_extent opt_window_exclusion_clause
   16081             :                 {
   16082         796 :                     WindowDef  *n = $2;
   16083             : 
   16084         796 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
   16085         796 :                     n->frameOptions |= $3;
   16086         796 :                     $$ = n;
   16087             :                 }
   16088             :             | ROWS frame_extent opt_window_exclusion_clause
   16089             :                 {
   16090         618 :                     WindowDef  *n = $2;
   16091             : 
   16092         618 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
   16093         618 :                     n->frameOptions |= $3;
   16094         618 :                     $$ = n;
   16095             :                 }
   16096             :             | GROUPS frame_extent opt_window_exclusion_clause
   16097             :                 {
   16098         204 :                     WindowDef  *n = $2;
   16099             : 
   16100         204 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_GROUPS;
   16101         204 :                     n->frameOptions |= $3;
   16102         204 :                     $$ = n;
   16103             :                 }
   16104             :             | /*EMPTY*/
   16105             :                 {
   16106        1382 :                     WindowDef  *n = makeNode(WindowDef);
   16107             : 
   16108        1382 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   16109        1382 :                     n->startOffset = NULL;
   16110        1382 :                     n->endOffset = NULL;
   16111        1382 :                     $$ = n;
   16112             :                 }
   16113             :         ;
   16114             : 
   16115             : frame_extent: frame_bound
   16116             :                 {
   16117           6 :                     WindowDef  *n = $1;
   16118             : 
   16119             :                     /* reject invalid cases */
   16120           6 :                     if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   16121           0 :                         ereport(ERROR,
   16122             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16123             :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   16124             :                                  parser_errposition(@1)));
   16125           6 :                     if (n->frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING)
   16126           0 :                         ereport(ERROR,
   16127             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16128             :                                  errmsg("frame starting from following row cannot end with current row"),
   16129             :                                  parser_errposition(@1)));
   16130           6 :                     n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
   16131           6 :                     $$ = n;
   16132             :                 }
   16133             :             | BETWEEN frame_bound AND frame_bound
   16134             :                 {
   16135        1612 :                     WindowDef  *n1 = $2;
   16136        1612 :                     WindowDef  *n2 = $4;
   16137             : 
   16138             :                     /* form merged options */
   16139        1612 :                     int     frameOptions = n1->frameOptions;
   16140             :                     /* shift converts START_ options to END_ options */
   16141        1612 :                     frameOptions |= n2->frameOptions << 1;
   16142        1612 :                     frameOptions |= FRAMEOPTION_BETWEEN;
   16143             :                     /* reject invalid cases */
   16144        1612 :                     if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   16145           0 :                         ereport(ERROR,
   16146             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16147             :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   16148             :                                  parser_errposition(@2)));
   16149        1612 :                     if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
   16150           0 :                         ereport(ERROR,
   16151             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16152             :                                  errmsg("frame end cannot be UNBOUNDED PRECEDING"),
   16153             :                                  parser_errposition(@4)));
   16154        1612 :                     if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
   16155         460 :                         (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING))
   16156           0 :                         ereport(ERROR,
   16157             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16158             :                                  errmsg("frame starting from current row cannot have preceding rows"),
   16159             :                                  parser_errposition(@4)));
   16160        1612 :                     if ((frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING) &&
   16161         168 :                         (frameOptions & (FRAMEOPTION_END_OFFSET_PRECEDING |
   16162             :                                          FRAMEOPTION_END_CURRENT_ROW)))
   16163           0 :                         ereport(ERROR,
   16164             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16165             :                                  errmsg("frame starting from following row cannot have preceding rows"),
   16166             :                                  parser_errposition(@4)));
   16167        1612 :                     n1->frameOptions = frameOptions;
   16168        1612 :                     n1->endOffset = n2->startOffset;
   16169        1612 :                     $$ = n1;
   16170             :                 }
   16171             :         ;
   16172             : 
   16173             : /*
   16174             :  * This is used for both frame start and frame end, with output set up on
   16175             :  * the assumption it's frame start; the frame_extent productions must reject
   16176             :  * invalid cases.
   16177             :  */
   16178             : frame_bound:
   16179             :             UNBOUNDED PRECEDING
   16180             :                 {
   16181         198 :                     WindowDef  *n = makeNode(WindowDef);
   16182             : 
   16183         198 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
   16184         198 :                     n->startOffset = NULL;
   16185         198 :                     n->endOffset = NULL;
   16186         198 :                     $$ = n;
   16187             :                 }
   16188             :             | UNBOUNDED FOLLOWING
   16189             :                 {
   16190         376 :                     WindowDef  *n = makeNode(WindowDef);
   16191             : 
   16192         376 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
   16193         376 :                     n->startOffset = NULL;
   16194         376 :                     n->endOffset = NULL;
   16195         376 :                     $$ = n;
   16196             :                 }
   16197             :             | CURRENT_P ROW
   16198             :                 {
   16199         604 :                     WindowDef  *n = makeNode(WindowDef);
   16200             : 
   16201         604 :                     n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
   16202         604 :                     n->startOffset = NULL;
   16203         604 :                     n->endOffset = NULL;
   16204         604 :                     $$ = n;
   16205             :                 }
   16206             :             | a_expr PRECEDING
   16207             :                 {
   16208         900 :                     WindowDef  *n = makeNode(WindowDef);
   16209             : 
   16210         900 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_PRECEDING;
   16211         900 :                     n->startOffset = $1;
   16212         900 :                     n->endOffset = NULL;
   16213         900 :                     $$ = n;
   16214             :                 }
   16215             :             | a_expr FOLLOWING
   16216             :                 {
   16217        1152 :                     WindowDef  *n = makeNode(WindowDef);
   16218             : 
   16219        1152 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_FOLLOWING;
   16220        1152 :                     n->startOffset = $1;
   16221        1152 :                     n->endOffset = NULL;
   16222        1152 :                     $$ = n;
   16223             :                 }
   16224             :         ;
   16225             : 
   16226             : opt_window_exclusion_clause:
   16227          84 :             EXCLUDE CURRENT_P ROW   { $$ = FRAMEOPTION_EXCLUDE_CURRENT_ROW; }
   16228          96 :             | EXCLUDE GROUP_P       { $$ = FRAMEOPTION_EXCLUDE_GROUP; }
   16229         150 :             | EXCLUDE TIES          { $$ = FRAMEOPTION_EXCLUDE_TIES; }
   16230          18 :             | EXCLUDE NO OTHERS     { $$ = 0; }
   16231        1270 :             | /*EMPTY*/             { $$ = 0; }
   16232             :         ;
   16233             : 
   16234             : 
   16235             : /*
   16236             :  * Supporting nonterminals for expressions.
   16237             :  */
   16238             : 
   16239             : /* Explicit row production.
   16240             :  *
   16241             :  * SQL99 allows an optional ROW keyword, so we can now do single-element rows
   16242             :  * without conflicting with the parenthesized a_expr production.  Without the
   16243             :  * ROW keyword, there must be more than one a_expr inside the parens.
   16244             :  */
   16245           0 : row:        ROW '(' expr_list ')'                   { $$ = $3; }
   16246           0 :             | ROW '(' ')'                           { $$ = NIL; }
   16247        1572 :             | '(' expr_list ',' a_expr ')'          { $$ = lappend($2, $4); }
   16248             :         ;
   16249             : 
   16250        3748 : explicit_row:   ROW '(' expr_list ')'               { $$ = $3; }
   16251          30 :             | ROW '(' ')'                           { $$ = NIL; }
   16252             :         ;
   16253             : 
   16254        2124 : implicit_row:   '(' expr_list ',' a_expr ')'        { $$ = lappend($2, $4); }
   16255             :         ;
   16256             : 
   16257       14220 : sub_type:   ANY                                     { $$ = ANY_SUBLINK; }
   16258           0 :             | SOME                                  { $$ = ANY_SUBLINK; }
   16259         324 :             | ALL                                   { $$ = ALL_SUBLINK; }
   16260             :         ;
   16261             : 
   16262       10640 : all_Op:     Op                                      { $$ = $1; }
   16263       24156 :             | MathOp                                { $$ = $1; }
   16264             :         ;
   16265             : 
   16266          38 : MathOp:      '+'                                    { $$ = "+"; }
   16267          46 :             | '-'                                   { $$ = "-"; }
   16268          12 :             | '*'                                   { $$ = "*"; }
   16269           0 :             | '/'                                   { $$ = "/"; }
   16270           8 :             | '%'                                   { $$ = "%"; }
   16271           0 :             | '^'                                   { $$ = "^"; }
   16272         746 :             | '<'                                    { $$ = "<"; }
   16273         588 :             | '>'                                    { $$ = ">"; }
   16274       21054 :             | '='                                   { $$ = "="; }
   16275         612 :             | LESS_EQUALS                           { $$ = "<="; }
   16276         604 :             | GREATER_EQUALS                        { $$ = ">="; }
   16277         448 :             | NOT_EQUALS                            { $$ = "<>"; }
   16278             :         ;
   16279             : 
   16280             : qual_Op:    Op
   16281       40140 :                     { $$ = list_make1(makeString($1)); }
   16282             :             | OPERATOR '(' any_operator ')'
   16283       13832 :                     { $$ = $3; }
   16284             :         ;
   16285             : 
   16286             : qual_all_Op:
   16287             :             all_Op
   16288        1414 :                     { $$ = list_make1(makeString($1)); }
   16289             :             | OPERATOR '(' any_operator ')'
   16290          34 :                     { $$ = $3; }
   16291             :         ;
   16292             : 
   16293             : subquery_Op:
   16294             :             all_Op
   16295       14274 :                     { $$ = list_make1(makeString($1)); }
   16296             :             | OPERATOR '(' any_operator ')'
   16297         236 :                     { $$ = $3; }
   16298             :             | LIKE
   16299          24 :                     { $$ = list_make1(makeString("~~")); }
   16300             :             | NOT_LA LIKE
   16301          12 :                     { $$ = list_make1(makeString("!~~")); }
   16302             :             | ILIKE
   16303          12 :                     { $$ = list_make1(makeString("~~*")); }
   16304             :             | NOT_LA ILIKE
   16305           0 :                     { $$ = list_make1(makeString("!~~*")); }
   16306             : /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
   16307             :  * the regular expression is preprocessed by a function (similar_to_escape),
   16308             :  * and the ~ operator for posix regular expressions is used.
   16309             :  *        x SIMILAR TO y     ->    x ~ similar_to_escape(y)
   16310             :  * this transformation is made on the fly by the parser upwards.
   16311             :  * however the SubLink structure which handles any/some/all stuff
   16312             :  * is not ready for such a thing.
   16313             :  */
   16314             :             ;
   16315             : 
   16316             : expr_list:  a_expr
   16317             :                 {
   16318      147954 :                     $$ = list_make1($1);
   16319             :                 }
   16320             :             | expr_list ',' a_expr
   16321             :                 {
   16322      134760 :                     $$ = lappend($1, $3);
   16323             :                 }
   16324             :         ;
   16325             : 
   16326             : /* function arguments can have names */
   16327             : func_arg_list:  func_arg_expr
   16328             :                 {
   16329      280104 :                     $$ = list_make1($1);
   16330             :                 }
   16331             :             | func_arg_list ',' func_arg_expr
   16332             :                 {
   16333      204848 :                     $$ = lappend($1, $3);
   16334             :                 }
   16335             :         ;
   16336             : 
   16337             : func_arg_expr:  a_expr
   16338             :                 {
   16339      438860 :                     $$ = $1;
   16340             :                 }
   16341             :             | param_name COLON_EQUALS a_expr
   16342             :                 {
   16343       45778 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   16344             : 
   16345       45778 :                     na->name = $1;
   16346       45778 :                     na->arg = (Expr *) $3;
   16347       45778 :                     na->argnumber = -1;      /* until determined */
   16348       45778 :                     na->location = @1;
   16349       45778 :                     $$ = (Node *) na;
   16350             :                 }
   16351             :             | param_name EQUALS_GREATER a_expr
   16352             :                 {
   16353        1012 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   16354             : 
   16355        1012 :                     na->name = $1;
   16356        1012 :                     na->arg = (Expr *) $3;
   16357        1012 :                     na->argnumber = -1;      /* until determined */
   16358        1012 :                     na->location = @1;
   16359        1012 :                     $$ = (Node *) na;
   16360             :                 }
   16361             :         ;
   16362             : 
   16363         188 : func_arg_list_opt:  func_arg_list                   { $$ = $1; }
   16364           0 :             | /*EMPTY*/                             { $$ = NIL; }
   16365             :         ;
   16366             : 
   16367        1680 : type_list:  Typename                                { $$ = list_make1($1); }
   16368         392 :             | type_list ',' Typename                { $$ = lappend($1, $3); }
   16369             :         ;
   16370             : 
   16371             : array_expr: '[' expr_list ']'
   16372             :                 {
   16373        7604 :                     $$ = makeAArrayExpr($2, @1);
   16374             :                 }
   16375             :             | '[' array_expr_list ']'
   16376             :                 {
   16377         406 :                     $$ = makeAArrayExpr($2, @1);
   16378             :                 }
   16379             :             | '[' ']'
   16380             :                 {
   16381          88 :                     $$ = makeAArrayExpr(NIL, @1);
   16382             :                 }
   16383             :         ;
   16384             : 
   16385         406 : array_expr_list: array_expr                         { $$ = list_make1($1); }
   16386         330 :             | array_expr_list ',' array_expr        { $$ = lappend($1, $3); }
   16387             :         ;
   16388             : 
   16389             : 
   16390             : extract_list:
   16391             :             extract_arg FROM a_expr
   16392             :                 {
   16393        1200 :                     $$ = list_make2(makeStringConst($1, @1), $3);
   16394             :                 }
   16395             :         ;
   16396             : 
   16397             : /* Allow delimited string Sconst in extract_arg as an SQL extension.
   16398             :  * - thomas 2001-04-12
   16399             :  */
   16400             : extract_arg:
   16401         990 :             IDENT                                   { $$ = $1; }
   16402          54 :             | YEAR_P                                { $$ = "year"; }
   16403          36 :             | MONTH_P                               { $$ = "month"; }
   16404          48 :             | DAY_P                                 { $$ = "day"; }
   16405          24 :             | HOUR_P                                { $$ = "hour"; }
   16406          24 :             | MINUTE_P                              { $$ = "minute"; }
   16407          24 :             | SECOND_P                              { $$ = "second"; }
   16408           0 :             | Sconst                                { $$ = $1; }
   16409             :         ;
   16410             : 
   16411             : unicode_normal_form:
   16412          24 :             NFC                                     { $$ = "NFC"; }
   16413          12 :             | NFD                                   { $$ = "NFD"; }
   16414          18 :             | NFKC                                  { $$ = "NFKC"; }
   16415          18 :             | NFKD                                  { $$ = "NFKD"; }
   16416             :         ;
   16417             : 
   16418             : /* OVERLAY() arguments */
   16419             : overlay_list:
   16420             :             a_expr PLACING a_expr FROM a_expr FOR a_expr
   16421             :                 {
   16422             :                     /* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D) */
   16423          34 :                     $$ = list_make4($1, $3, $5, $7);
   16424             :                 }
   16425             :             | a_expr PLACING a_expr FROM a_expr
   16426             :                 {
   16427             :                     /* overlay(A PLACING B FROM C) is converted to overlay(A, B, C) */
   16428          48 :                     $$ = list_make3($1, $3, $5);
   16429             :                 }
   16430             :         ;
   16431             : 
   16432             : /* position_list uses b_expr not a_expr to avoid conflict with general IN */
   16433             : position_list:
   16434         350 :             b_expr IN_P b_expr                      { $$ = list_make2($3, $1); }
   16435             :         ;
   16436             : 
   16437             : /*
   16438             :  * SUBSTRING() arguments
   16439             :  *
   16440             :  * Note that SQL:1999 has both
   16441             :  *     text FROM int FOR int
   16442             :  * and
   16443             :  *     text FROM pattern FOR escape
   16444             :  *
   16445             :  * In the parser we map them both to a call to the substring() function and
   16446             :  * rely on type resolution to pick the right one.
   16447             :  *
   16448             :  * In SQL:2003, the second variant was changed to
   16449             :  *     text SIMILAR pattern ESCAPE escape
   16450             :  * We could in theory map that to a different function internally, but
   16451             :  * since we still support the SQL:1999 version, we don't.  However,
   16452             :  * ruleutils.c will reverse-list the call in the newer style.
   16453             :  */
   16454             : substr_list:
   16455             :             a_expr FROM a_expr FOR a_expr
   16456             :                 {
   16457         122 :                     $$ = list_make3($1, $3, $5);
   16458             :                 }
   16459             :             | a_expr FOR a_expr FROM a_expr
   16460             :                 {
   16461             :                     /* not legal per SQL, but might as well allow it */
   16462           0 :                     $$ = list_make3($1, $5, $3);
   16463             :                 }
   16464             :             | a_expr FROM a_expr
   16465             :                 {
   16466             :                     /*
   16467             :                      * Because we aren't restricting data types here, this
   16468             :                      * syntax can end up resolving to textregexsubstr().
   16469             :                      * We've historically allowed that to happen, so continue
   16470             :                      * to accept it.  However, ruleutils.c will reverse-list
   16471             :                      * such a call in regular function call syntax.
   16472             :                      */
   16473         310 :                     $$ = list_make2($1, $3);
   16474             :                 }
   16475             :             | a_expr FOR a_expr
   16476             :                 {
   16477             :                     /* not legal per SQL */
   16478             : 
   16479             :                     /*
   16480             :                      * Since there are no cases where this syntax allows
   16481             :                      * a textual FOR value, we forcibly cast the argument
   16482             :                      * to int4.  The possible matches in pg_proc are
   16483             :                      * substring(text,int4) and substring(text,text),
   16484             :                      * and we don't want the parser to choose the latter,
   16485             :                      * which it is likely to do if the second argument
   16486             :                      * is unknown or doesn't have an implicit cast to int4.
   16487             :                      */
   16488          36 :                     $$ = list_make3($1, makeIntConst(1, -1),
   16489             :                                     makeTypeCast($3,
   16490             :                                                  SystemTypeName("int4"), -1));
   16491             :                 }
   16492             :             | a_expr SIMILAR a_expr ESCAPE a_expr
   16493             :                 {
   16494         162 :                     $$ = list_make3($1, $3, $5);
   16495             :                 }
   16496             :         ;
   16497             : 
   16498         560 : trim_list:  a_expr FROM expr_list                   { $$ = lappend($3, $1); }
   16499          24 :             | FROM expr_list                        { $$ = $2; }
   16500          86 :             | expr_list                             { $$ = $1; }
   16501             :         ;
   16502             : 
   16503             : in_expr:    select_with_parens
   16504             :                 {
   16505        2414 :                     SubLink    *n = makeNode(SubLink);
   16506             : 
   16507        2414 :                     n->subselect = $1;
   16508             :                     /* other fields will be filled later */
   16509        2414 :                     $$ = (Node *) n;
   16510             :                 }
   16511       16514 :             | '(' expr_list ')'                     { $$ = (Node *) $2; }
   16512             :         ;
   16513             : 
   16514             : /*
   16515             :  * Define SQL-style CASE clause.
   16516             :  * - Full specification
   16517             :  *  CASE WHEN a = b THEN c ... ELSE d END
   16518             :  * - Implicit argument
   16519             :  *  CASE a WHEN b THEN c ... ELSE d END
   16520             :  */
   16521             : case_expr:  CASE case_arg when_clause_list case_default END_P
   16522             :                 {
   16523       52486 :                     CaseExpr   *c = makeNode(CaseExpr);
   16524             : 
   16525       52486 :                     c->casetype = InvalidOid; /* not analyzed yet */
   16526       52486 :                     c->arg = (Expr *) $2;
   16527       52486 :                     c->args = $3;
   16528       52486 :                     c->defresult = (Expr *) $4;
   16529       52486 :                     c->location = @1;
   16530       52486 :                     $$ = (Node *) c;
   16531             :                 }
   16532             :         ;
   16533             : 
   16534             : when_clause_list:
   16535             :             /* There must be at least one */
   16536       52486 :             when_clause                             { $$ = list_make1($1); }
   16537       41088 :             | when_clause_list when_clause          { $$ = lappend($1, $2); }
   16538             :         ;
   16539             : 
   16540             : when_clause:
   16541             :             WHEN a_expr THEN a_expr
   16542             :                 {
   16543       93574 :                     CaseWhen   *w = makeNode(CaseWhen);
   16544             : 
   16545       93574 :                     w->expr = (Expr *) $2;
   16546       93574 :                     w->result = (Expr *) $4;
   16547       93574 :                     w->location = @1;
   16548       93574 :                     $$ = (Node *) w;
   16549             :                 }
   16550             :         ;
   16551             : 
   16552             : case_default:
   16553       44714 :             ELSE a_expr                             { $$ = $2; }
   16554        7772 :             | /*EMPTY*/                             { $$ = NULL; }
   16555             :         ;
   16556             : 
   16557        5382 : case_arg:   a_expr                                  { $$ = $1; }
   16558       47104 :             | /*EMPTY*/                             { $$ = NULL; }
   16559             :         ;
   16560             : 
   16561             : columnref:  ColId
   16562             :                 {
   16563      576580 :                     $$ = makeColumnRef($1, NIL, @1, yyscanner);
   16564             :                 }
   16565             :             | ColId indirection
   16566             :                 {
   16567      919674 :                     $$ = makeColumnRef($1, $2, @1, yyscanner);
   16568             :                 }
   16569             :         ;
   16570             : 
   16571             : indirection_el:
   16572             :             '.' attr_name
   16573             :                 {
   16574     1241274 :                     $$ = (Node *) makeString($2);
   16575             :                 }
   16576             :             | '.' '*'
   16577             :                 {
   16578        5822 :                     $$ = (Node *) makeNode(A_Star);
   16579             :                 }
   16580             :             | '[' a_expr ']'
   16581             :                 {
   16582       11580 :                     A_Indices *ai = makeNode(A_Indices);
   16583             : 
   16584       11580 :                     ai->is_slice = false;
   16585       11580 :                     ai->lidx = NULL;
   16586       11580 :                     ai->uidx = $2;
   16587       11580 :                     $$ = (Node *) ai;
   16588             :                 }
   16589             :             | '[' opt_slice_bound ':' opt_slice_bound ']'
   16590             :                 {
   16591         558 :                     A_Indices *ai = makeNode(A_Indices);
   16592             : 
   16593         558 :                     ai->is_slice = true;
   16594         558 :                     ai->lidx = $2;
   16595         558 :                     ai->uidx = $4;
   16596         558 :                     $$ = (Node *) ai;
   16597             :                 }
   16598             :         ;
   16599             : 
   16600             : opt_slice_bound:
   16601         936 :             a_expr                                  { $$ = $1; }
   16602         180 :             | /*EMPTY*/                             { $$ = NULL; }
   16603             :         ;
   16604             : 
   16605             : indirection:
   16606     1241578 :             indirection_el                          { $$ = list_make1($1); }
   16607        2748 :             | indirection indirection_el            { $$ = lappend($1, $2); }
   16608             :         ;
   16609             : 
   16610             : opt_indirection:
   16611      281886 :             /*EMPTY*/                               { $$ = NIL; }
   16612       14908 :             | opt_indirection indirection_el        { $$ = lappend($1, $2); }
   16613             :         ;
   16614             : 
   16615             : opt_asymmetric: ASYMMETRIC
   16616             :             | /*EMPTY*/
   16617             :         ;
   16618             : 
   16619             : /* SQL/JSON support */
   16620             : json_passing_clause_opt:
   16621         198 :             PASSING json_arguments                  { $$ = $2; }
   16622        1296 :             | /*EMPTY*/                             { $$ = NIL; }
   16623             :         ;
   16624             : 
   16625             : json_arguments:
   16626         198 :             json_argument                           { $$ = list_make1($1); }
   16627          30 :             | json_arguments ',' json_argument      { $$ = lappend($1, $3); }
   16628             :         ;
   16629             : 
   16630             : json_argument:
   16631             :             json_value_expr AS ColLabel
   16632             :             {
   16633         228 :                 JsonArgument *n = makeNode(JsonArgument);
   16634             : 
   16635         228 :                 n->val = (JsonValueExpr *) $1;
   16636         228 :                 n->name = $3;
   16637         228 :                 $$ = (Node *) n;
   16638             :             }
   16639             :         ;
   16640             : 
   16641             : /* ARRAY is a noise word */
   16642             : json_wrapper_behavior:
   16643          24 :               WITHOUT WRAPPER                   { $$ = JSW_NONE; }
   16644           0 :             | WITHOUT ARRAY WRAPPER             { $$ = JSW_NONE; }
   16645          42 :             | WITH WRAPPER                      { $$ = JSW_UNCONDITIONAL; }
   16646          12 :             | WITH ARRAY WRAPPER                { $$ = JSW_UNCONDITIONAL; }
   16647           0 :             | WITH CONDITIONAL ARRAY WRAPPER    { $$ = JSW_CONDITIONAL; }
   16648          12 :             | WITH UNCONDITIONAL ARRAY WRAPPER  { $$ = JSW_UNCONDITIONAL; }
   16649          36 :             | WITH CONDITIONAL WRAPPER          { $$ = JSW_CONDITIONAL; }
   16650           0 :             | WITH UNCONDITIONAL WRAPPER        { $$ = JSW_UNCONDITIONAL; }
   16651         738 :             | /* empty */                       { $$ = JSW_UNSPEC; }
   16652             :         ;
   16653             : 
   16654             : json_behavior:
   16655             :             DEFAULT a_expr
   16656         168 :                 { $$ = (Node *) makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); }
   16657             :             | json_behavior_type
   16658         420 :                 { $$ = (Node *) makeJsonBehavior($1, NULL, @1); }
   16659             :         ;
   16660             : 
   16661             : json_behavior_type:
   16662         312 :             ERROR_P     { $$ = JSON_BEHAVIOR_ERROR; }
   16663          18 :             | NULL_P    { $$ = JSON_BEHAVIOR_NULL; }
   16664           0 :             | TRUE_P    { $$ = JSON_BEHAVIOR_TRUE; }
   16665           0 :             | FALSE_P   { $$ = JSON_BEHAVIOR_FALSE; }
   16666           0 :             | UNKNOWN   { $$ = JSON_BEHAVIOR_UNKNOWN; }
   16667          24 :             | EMPTY_P ARRAY { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
   16668          60 :             | EMPTY_P OBJECT_P  { $$ = JSON_BEHAVIOR_EMPTY_OBJECT; }
   16669             :             /* non-standard, for Oracle compatibility only */
   16670           6 :             | EMPTY_P   { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
   16671             :         ;
   16672             : 
   16673             : json_behavior_clause_opt:
   16674             :             json_behavior ON EMPTY_P
   16675          66 :                 { $$ = list_make2($1, NULL); }
   16676             :             | json_behavior ON ERROR_P
   16677         354 :                 { $$ = list_make2(NULL, $1); }
   16678             :             | json_behavior ON EMPTY_P json_behavior ON ERROR_P
   16679          78 :                 { $$ = list_make2($1, $4); }
   16680             :             | /* EMPTY */
   16681         834 :                 { $$ = list_make2(NULL, NULL); }
   16682             :         ;
   16683             : 
   16684             : json_on_error_clause_opt:
   16685             :             json_behavior ON ERROR_P
   16686          12 :                 { $$ = $1; }
   16687             :             | /* EMPTY */
   16688         150 :                 { $$ = NULL; }
   16689             :         ;
   16690             : 
   16691             : json_value_expr:
   16692             :             a_expr json_format_clause_opt
   16693             :             {
   16694             :                 /* formatted_expr will be set during parse-analysis. */
   16695        3024 :                 $$ = (Node *) makeJsonValueExpr((Expr *) $1, NULL,
   16696        3024 :                                                 castNode(JsonFormat, $2));
   16697             :             }
   16698             :         ;
   16699             : 
   16700             : json_format_clause:
   16701             :             FORMAT_LA JSON ENCODING name
   16702             :                 {
   16703             :                     int     encoding;
   16704             : 
   16705         100 :                     if (!pg_strcasecmp($4, "utf8"))
   16706          64 :                         encoding = JS_ENC_UTF8;
   16707          36 :                     else if (!pg_strcasecmp($4, "utf16"))
   16708          12 :                         encoding = JS_ENC_UTF16;
   16709          24 :                     else if (!pg_strcasecmp($4, "utf32"))
   16710          12 :                         encoding = JS_ENC_UTF32;
   16711             :                     else
   16712          12 :                         ereport(ERROR,
   16713             :                                 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   16714             :                                 errmsg("unrecognized JSON encoding: %s", $4));
   16715             : 
   16716          88 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
   16717             :                 }
   16718             :             | FORMAT_LA JSON
   16719             :                 {
   16720         250 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
   16721             :                 }
   16722             :         ;
   16723             : 
   16724             : json_format_clause_opt:
   16725             :             json_format_clause
   16726             :                 {
   16727         338 :                     $$ = $1;
   16728             :                 }
   16729             :             | /* EMPTY */
   16730             :                 {
   16731        3932 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   16732             :                 }
   16733             :         ;
   16734             : 
   16735             : json_quotes_clause_opt:
   16736           6 :             KEEP QUOTES ON SCALAR STRING_P      { $$ = JS_QUOTES_KEEP; }
   16737          60 :             | KEEP QUOTES                       { $$ = JS_QUOTES_KEEP; }
   16738           6 :             | OMIT QUOTES ON SCALAR STRING_P    { $$ = JS_QUOTES_OMIT; }
   16739          96 :             | OMIT QUOTES                       { $$ = JS_QUOTES_OMIT; }
   16740         696 :             | /* EMPTY */                       { $$ = JS_QUOTES_UNSPEC; }
   16741             :         ;
   16742             : 
   16743             : json_returning_clause_opt:
   16744             :             RETURNING Typename json_format_clause_opt
   16745             :                 {
   16746        1192 :                     JsonOutput *n = makeNode(JsonOutput);
   16747             : 
   16748        1192 :                     n->typeName = $2;
   16749        1192 :                     n->returning = makeNode(JsonReturning);
   16750        1192 :                     n->returning->format = (JsonFormat *) $3;
   16751        1192 :                     $$ = (Node *) n;
   16752             :                 }
   16753        1152 :             | /* EMPTY */                           { $$ = NULL; }
   16754             :         ;
   16755             : 
   16756             : /*
   16757             :  * We must assign the only-JSON production a precedence less than IDENT in
   16758             :  * order to favor shifting over reduction when JSON is followed by VALUE_P,
   16759             :  * OBJECT_P, or SCALAR.  (ARRAY doesn't need that treatment, because it's a
   16760             :  * fully reserved word.)  Because json_predicate_type_constraint is always
   16761             :  * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
   16762             :  * production to have precedence less than WITH and WITHOUT.  UNBOUNDED isn't
   16763             :  * really related to this syntax, but it's a convenient choice because it
   16764             :  * already has a precedence less than IDENT for other reasons.
   16765             :  */
   16766             : json_predicate_type_constraint:
   16767         202 :             JSON                    %prec UNBOUNDED { $$ = JS_TYPE_ANY; }
   16768          28 :             | JSON VALUE_P                          { $$ = JS_TYPE_ANY; }
   16769          40 :             | JSON ARRAY                            { $$ = JS_TYPE_ARRAY; }
   16770          40 :             | JSON OBJECT_P                         { $$ = JS_TYPE_OBJECT; }
   16771          40 :             | JSON SCALAR                           { $$ = JS_TYPE_SCALAR; }
   16772             :         ;
   16773             : 
   16774             : /*
   16775             :  * KEYS is a noise word here.  To avoid shift/reduce conflicts, assign the
   16776             :  * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
   16777             :  * This prevents reducing them when the next token is KEYS.
   16778             :  */
   16779             : json_key_uniqueness_constraint_opt:
   16780         108 :             WITH UNIQUE KEYS                            { $$ = true; }
   16781          82 :             | WITH UNIQUE               %prec UNBOUNDED { $$ = true; }
   16782          44 :             | WITHOUT UNIQUE KEYS                       { $$ = false; }
   16783          16 :             | WITHOUT UNIQUE            %prec UNBOUNDED { $$ = false; }
   16784         708 :             | /* EMPTY */               %prec UNBOUNDED { $$ = false; }
   16785             :         ;
   16786             : 
   16787             : json_name_and_value_list:
   16788             :             json_name_and_value
   16789         288 :                 { $$ = list_make1($1); }
   16790             :             | json_name_and_value_list ',' json_name_and_value
   16791         232 :                 { $$ = lappend($1, $3); }
   16792             :         ;
   16793             : 
   16794             : json_name_and_value:
   16795             : /* Supporting this syntax seems to require major surgery
   16796             :             KEY c_expr VALUE_P json_value_expr
   16797             :                 { $$ = makeJsonKeyValue($2, $4); }
   16798             :             |
   16799             : */
   16800             :             c_expr VALUE_P json_value_expr
   16801          24 :                 { $$ = makeJsonKeyValue($1, $3); }
   16802             :             |
   16803             :             a_expr ':' json_value_expr
   16804         652 :                 { $$ = makeJsonKeyValue($1, $3); }
   16805             :         ;
   16806             : 
   16807             : /* empty means false for objects, true for arrays */
   16808             : json_object_constructor_null_clause_opt:
   16809          30 :             NULL_P ON NULL_P                    { $$ = false; }
   16810         110 :             | ABSENT ON NULL_P                  { $$ = true; }
   16811         304 :             | /* EMPTY */                       { $$ = false; }
   16812             :         ;
   16813             : 
   16814             : json_array_constructor_null_clause_opt:
   16815          54 :             NULL_P ON NULL_P                        { $$ = false; }
   16816          36 :             | ABSENT ON NULL_P                      { $$ = true; }
   16817         156 :             | /* EMPTY */                           { $$ = true; }
   16818             :         ;
   16819             : 
   16820             : json_value_expr_list:
   16821          96 :             json_value_expr                             { $$ = list_make1($1); }
   16822         126 :             | json_value_expr_list ',' json_value_expr  { $$ = lappend($1, $3);}
   16823             :         ;
   16824             : 
   16825             : json_aggregate_func:
   16826             :             JSON_OBJECTAGG '('
   16827             :                 json_name_and_value
   16828             :                 json_object_constructor_null_clause_opt
   16829             :                 json_key_uniqueness_constraint_opt
   16830             :                 json_returning_clause_opt
   16831             :             ')'
   16832             :                 {
   16833         156 :                     JsonObjectAgg *n = makeNode(JsonObjectAgg);
   16834             : 
   16835         156 :                     n->arg = (JsonKeyValue *) $3;
   16836         156 :                     n->absent_on_null = $4;
   16837         156 :                     n->unique = $5;
   16838         156 :                     n->constructor = makeNode(JsonAggConstructor);
   16839         156 :                     n->constructor->output = (JsonOutput *) $6;
   16840         156 :                     n->constructor->agg_order = NULL;
   16841         156 :                     n->constructor->location = @1;
   16842         156 :                     $$ = (Node *) n;
   16843             :                 }
   16844             :             | JSON_ARRAYAGG '('
   16845             :                 json_value_expr
   16846             :                 json_array_aggregate_order_by_clause_opt
   16847             :                 json_array_constructor_null_clause_opt
   16848             :                 json_returning_clause_opt
   16849             :             ')'
   16850             :                 {
   16851         150 :                     JsonArrayAgg *n = makeNode(JsonArrayAgg);
   16852             : 
   16853         150 :                     n->arg = (JsonValueExpr *) $3;
   16854         150 :                     n->absent_on_null = $5;
   16855         150 :                     n->constructor = makeNode(JsonAggConstructor);
   16856         150 :                     n->constructor->agg_order = $4;
   16857         150 :                     n->constructor->output = (JsonOutput *) $6;
   16858         150 :                     n->constructor->location = @1;
   16859         150 :                     $$ = (Node *) n;
   16860             :                 }
   16861             :         ;
   16862             : 
   16863             : json_array_aggregate_order_by_clause_opt:
   16864          18 :             ORDER BY sortby_list                    { $$ = $3; }
   16865         132 :             | /* EMPTY */                           { $$ = NIL; }
   16866             :         ;
   16867             : 
   16868             : /*****************************************************************************
   16869             :  *
   16870             :  *  target list for SELECT
   16871             :  *
   16872             :  *****************************************************************************/
   16873             : 
   16874      448348 : opt_target_list: target_list                        { $$ = $1; }
   16875         282 :             | /* EMPTY */                           { $$ = NIL; }
   16876             :         ;
   16877             : 
   16878             : target_list:
   16879      453990 :             target_el                               { $$ = list_make1($1); }
   16880      540698 :             | target_list ',' target_el             { $$ = lappend($1, $3); }
   16881             :         ;
   16882             : 
   16883             : target_el:  a_expr AS ColLabel
   16884             :                 {
   16885      183924 :                     $$ = makeNode(ResTarget);
   16886      183924 :                     $$->name = $3;
   16887      183924 :                     $$->indirection = NIL;
   16888      183924 :                     $$->val = (Node *) $1;
   16889      183924 :                     $$->location = @1;
   16890             :                 }
   16891             :             | a_expr BareColLabel
   16892             :                 {
   16893        3136 :                     $$ = makeNode(ResTarget);
   16894        3136 :                     $$->name = $2;
   16895        3136 :                     $$->indirection = NIL;
   16896        3136 :                     $$->val = (Node *) $1;
   16897        3136 :                     $$->location = @1;
   16898             :                 }
   16899             :             | a_expr
   16900             :                 {
   16901      759322 :                     $$ = makeNode(ResTarget);
   16902      759322 :                     $$->name = NULL;
   16903      759322 :                     $$->indirection = NIL;
   16904      759322 :                     $$->val = (Node *) $1;
   16905      759322 :                     $$->location = @1;
   16906             :                 }
   16907             :             | '*'
   16908             :                 {
   16909       48306 :                     ColumnRef  *n = makeNode(ColumnRef);
   16910             : 
   16911       48306 :                     n->fields = list_make1(makeNode(A_Star));
   16912       48306 :                     n->location = @1;
   16913             : 
   16914       48306 :                     $$ = makeNode(ResTarget);
   16915       48306 :                     $$->name = NULL;
   16916       48306 :                     $$->indirection = NIL;
   16917       48306 :                     $$->val = (Node *) n;
   16918       48306 :                     $$->location = @1;
   16919             :                 }
   16920             :         ;
   16921             : 
   16922             : 
   16923             : /*****************************************************************************
   16924             :  *
   16925             :  *  Names and constants
   16926             :  *
   16927             :  *****************************************************************************/
   16928             : 
   16929             : qualified_name_list:
   16930       13014 :             qualified_name                          { $$ = list_make1($1); }
   16931         362 :             | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
   16932             :         ;
   16933             : 
   16934             : /*
   16935             :  * The production for a qualified relation name has to exactly match the
   16936             :  * production for a qualified func_name, because in a FROM clause we cannot
   16937             :  * tell which we are parsing until we see what comes after it ('(' for a
   16938             :  * func_name, something else for a relation). Therefore we allow 'indirection'
   16939             :  * which may contain subscripts, and reject that case in the C code.
   16940             :  */
   16941             : qualified_name:
   16942             :             ColId
   16943             :                 {
   16944      370624 :                     $$ = makeRangeVar(NULL, $1, @1);
   16945             :                 }
   16946             :             | ColId indirection
   16947             :                 {
   16948      213774 :                     $$ = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   16949             :                 }
   16950             :         ;
   16951             : 
   16952             : name_list:  name
   16953       23692 :                     { $$ = list_make1(makeString($1)); }
   16954             :             | name_list ',' name
   16955       48294 :                     { $$ = lappend($1, makeString($3)); }
   16956             :         ;
   16957             : 
   16958             : 
   16959      142910 : name:       ColId                                   { $$ = $1; };
   16960             : 
   16961     1333058 : attr_name:  ColLabel                                { $$ = $1; };
   16962             : 
   16963          58 : file_name:  Sconst                                  { $$ = $1; };
   16964             : 
   16965             : /*
   16966             :  * The production for a qualified func_name has to exactly match the
   16967             :  * production for a qualified columnref, because we cannot tell which we
   16968             :  * are parsing until we see what comes after it ('(' or Sconst for a func_name,
   16969             :  * anything else for a columnref).  Therefore we allow 'indirection' which
   16970             :  * may contain subscripts, and reject that case in the C code.  (If we
   16971             :  * ever implement SQL99-like methods, such syntax may actually become legal!)
   16972             :  */
   16973             : func_name:  type_function_name
   16974      278364 :                     { $$ = list_make1(makeString($1)); }
   16975             :             | ColId indirection
   16976             :                     {
   16977      108052 :                         $$ = check_func_name(lcons(makeString($1), $2),
   16978             :                                              yyscanner);
   16979             :                     }
   16980             :         ;
   16981             : 
   16982             : 
   16983             : /*
   16984             :  * Constants
   16985             :  */
   16986             : AexprConst: Iconst
   16987             :                 {
   16988      405148 :                     $$ = makeIntConst($1, @1);
   16989             :                 }
   16990             :             | FCONST
   16991             :                 {
   16992       10630 :                     $$ = makeFloatConst($1, @1);
   16993             :                 }
   16994             :             | Sconst
   16995             :                 {
   16996      538180 :                     $$ = makeStringConst($1, @1);
   16997             :                 }
   16998             :             | BCONST
   16999             :                 {
   17000         754 :                     $$ = makeBitStringConst($1, @1);
   17001             :                 }
   17002             :             | XCONST
   17003             :                 {
   17004             :                     /* This is a bit constant per SQL99:
   17005             :                      * Without Feature F511, "BIT data type",
   17006             :                      * a <general literal> shall not be a
   17007             :                      * <bit string literal> or a <hex string literal>.
   17008             :                      */
   17009        3302 :                     $$ = makeBitStringConst($1, @1);
   17010             :                 }
   17011             :             | func_name Sconst
   17012             :                 {
   17013             :                     /* generic type 'literal' syntax */
   17014        9064 :                     TypeName   *t = makeTypeNameFromNameList($1);
   17015             : 
   17016        9064 :                     t->location = @1;
   17017        9064 :                     $$ = makeStringConstCast($2, @2, t);
   17018             :                 }
   17019             :             | func_name '(' func_arg_list opt_sort_clause ')' Sconst
   17020             :                 {
   17021             :                     /* generic syntax with a type modifier */
   17022           0 :                     TypeName   *t = makeTypeNameFromNameList($1);
   17023             :                     ListCell   *lc;
   17024             : 
   17025             :                     /*
   17026             :                      * We must use func_arg_list and opt_sort_clause in the
   17027             :                      * production to avoid reduce/reduce conflicts, but we
   17028             :                      * don't actually wish to allow NamedArgExpr in this
   17029             :                      * context, nor ORDER BY.
   17030             :                      */
   17031           0 :                     foreach(lc, $3)
   17032             :                     {
   17033           0 :                         NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
   17034             : 
   17035           0 :                         if (IsA(arg, NamedArgExpr))
   17036           0 :                             ereport(ERROR,
   17037             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17038             :                                      errmsg("type modifier cannot have parameter name"),
   17039             :                                      parser_errposition(arg->location)));
   17040             :                     }
   17041           0 :                     if ($4 != NIL)
   17042           0 :                             ereport(ERROR,
   17043             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17044             :                                      errmsg("type modifier cannot have ORDER BY"),
   17045             :                                      parser_errposition(@4)));
   17046             : 
   17047           0 :                     t->typmods = $3;
   17048           0 :                     t->location = @1;
   17049           0 :                     $$ = makeStringConstCast($6, @6, t);
   17050             :                 }
   17051             :             | ConstTypename Sconst
   17052             :                 {
   17053        2862 :                     $$ = makeStringConstCast($2, @2, $1);
   17054             :                 }
   17055             :             | ConstInterval Sconst opt_interval
   17056             :                 {
   17057        3232 :                     TypeName   *t = $1;
   17058             : 
   17059        3232 :                     t->typmods = $3;
   17060        3232 :                     $$ = makeStringConstCast($2, @2, t);
   17061             :                 }
   17062             :             | ConstInterval '(' Iconst ')' Sconst
   17063             :                 {
   17064          12 :                     TypeName   *t = $1;
   17065             : 
   17066          12 :                     t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   17067             :                                             makeIntConst($3, @3));
   17068          12 :                     $$ = makeStringConstCast($5, @5, t);
   17069             :                 }
   17070             :             | TRUE_P
   17071             :                 {
   17072       22326 :                     $$ = makeBoolAConst(true, @1);
   17073             :                 }
   17074             :             | FALSE_P
   17075             :                 {
   17076       31494 :                     $$ = makeBoolAConst(false, @1);
   17077             :                 }
   17078             :             | NULL_P
   17079             :                 {
   17080       56614 :                     $$ = makeNullAConst(@1);
   17081             :                 }
   17082             :         ;
   17083             : 
   17084      427956 : Iconst:     ICONST                                  { $$ = $1; };
   17085      601750 : Sconst:     SCONST                                  { $$ = $1; };
   17086             : 
   17087       15100 : SignedIconst: Iconst                                { $$ = $1; }
   17088           0 :             | '+' Iconst                            { $$ = + $2; }
   17089         266 :             | '-' Iconst                            { $$ = - $2; }
   17090             :         ;
   17091             : 
   17092             : /* Role specifications */
   17093             : RoleId:     RoleSpec
   17094             :                 {
   17095        1756 :                     RoleSpec   *spc = (RoleSpec *) $1;
   17096             : 
   17097        1756 :                     switch (spc->roletype)
   17098             :                     {
   17099        1746 :                         case ROLESPEC_CSTRING:
   17100        1746 :                             $$ = spc->rolename;
   17101        1746 :                             break;
   17102           4 :                         case ROLESPEC_PUBLIC:
   17103           4 :                             ereport(ERROR,
   17104             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17105             :                                      errmsg("role name \"%s\" is reserved",
   17106             :                                             "public"),
   17107             :                                      parser_errposition(@1)));
   17108             :                             break;
   17109           2 :                         case ROLESPEC_SESSION_USER:
   17110           2 :                             ereport(ERROR,
   17111             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17112             :                                      errmsg("%s cannot be used as a role name here",
   17113             :                                             "SESSION_USER"),
   17114             :                                      parser_errposition(@1)));
   17115             :                             break;
   17116           2 :                         case ROLESPEC_CURRENT_USER:
   17117           2 :                             ereport(ERROR,
   17118             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17119             :                                      errmsg("%s cannot be used as a role name here",
   17120             :                                             "CURRENT_USER"),
   17121             :                                      parser_errposition(@1)));
   17122             :                             break;
   17123           2 :                         case ROLESPEC_CURRENT_ROLE:
   17124           2 :                             ereport(ERROR,
   17125             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17126             :                                      errmsg("%s cannot be used as a role name here",
   17127             :                                             "CURRENT_ROLE"),
   17128             :                                      parser_errposition(@1)));
   17129             :                             break;
   17130             :                     }
   17131        1746 :                 }
   17132             :             ;
   17133             : 
   17134             : RoleSpec:   NonReservedWord
   17135             :                 {
   17136             :                     /*
   17137             :                      * "public" and "none" are not keywords, but they must
   17138             :                      * be treated specially here.
   17139             :                      */
   17140             :                     RoleSpec   *n;
   17141             : 
   17142       25022 :                     if (strcmp($1, "public") == 0)
   17143             :                     {
   17144       12124 :                         n = (RoleSpec *) makeRoleSpec(ROLESPEC_PUBLIC, @1);
   17145       12124 :                         n->roletype = ROLESPEC_PUBLIC;
   17146             :                     }
   17147       12898 :                     else if (strcmp($1, "none") == 0)
   17148             :                     {
   17149          26 :                         ereport(ERROR,
   17150             :                                 (errcode(ERRCODE_RESERVED_NAME),
   17151             :                                  errmsg("role name \"%s\" is reserved",
   17152             :                                         "none"),
   17153             :                                  parser_errposition(@1)));
   17154             :                     }
   17155             :                     else
   17156             :                     {
   17157       12872 :                         n = makeRoleSpec(ROLESPEC_CSTRING, @1);
   17158       12872 :                         n->rolename = pstrdup($1);
   17159             :                     }
   17160       24996 :                     $$ = n;
   17161             :                 }
   17162             :             | CURRENT_ROLE
   17163             :                 {
   17164         128 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_ROLE, @1);
   17165             :                 }
   17166             :             | CURRENT_USER
   17167             :                 {
   17168         228 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
   17169             :                 }
   17170             :             | SESSION_USER
   17171             :                 {
   17172          36 :                     $$ = makeRoleSpec(ROLESPEC_SESSION_USER, @1);
   17173             :                 }
   17174             :         ;
   17175             : 
   17176             : role_list:  RoleSpec
   17177        3094 :                 { $$ = list_make1($1); }
   17178             :             | role_list ',' RoleSpec
   17179         258 :                 { $$ = lappend($1, $3); }
   17180             :         ;
   17181             : 
   17182             : 
   17183             : /*****************************************************************************
   17184             :  *
   17185             :  * PL/pgSQL extensions
   17186             :  *
   17187             :  * You'd think a PL/pgSQL "expression" should be just an a_expr, but
   17188             :  * historically it can include just about anything that can follow SELECT.
   17189             :  * Therefore the returned struct is a SelectStmt.
   17190             :  *****************************************************************************/
   17191             : 
   17192             : PLpgSQL_Expr: opt_distinct_clause opt_target_list
   17193             :             from_clause where_clause
   17194             :             group_clause having_clause window_clause
   17195             :             opt_sort_clause opt_select_limit opt_for_locking_clause
   17196             :                 {
   17197       36474 :                     SelectStmt *n = makeNode(SelectStmt);
   17198             : 
   17199       36474 :                     n->distinctClause = $1;
   17200       36474 :                     n->targetList = $2;
   17201       36474 :                     n->fromClause = $3;
   17202       36474 :                     n->whereClause = $4;
   17203       36474 :                     n->groupClause = ($5)->list;
   17204       36474 :                     n->groupDistinct = ($5)->distinct;
   17205       36474 :                     n->havingClause = $6;
   17206       36474 :                     n->windowClause = $7;
   17207       36474 :                     n->sortClause = $8;
   17208       36474 :                     if ($9)
   17209             :                     {
   17210           4 :                         n->limitOffset = $9->limitOffset;
   17211           4 :                         n->limitCount = $9->limitCount;
   17212           4 :                         if (!n->sortClause &&
   17213           4 :                             $9->limitOption == LIMIT_OPTION_WITH_TIES)
   17214           0 :                             ereport(ERROR,
   17215             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17216             :                                      errmsg("WITH TIES cannot be specified without ORDER BY clause")));
   17217           4 :                         n->limitOption = $9->limitOption;
   17218             :                     }
   17219       36474 :                     n->lockingClause = $10;
   17220       36474 :                     $$ = (Node *) n;
   17221             :                 }
   17222             :         ;
   17223             : 
   17224             : /*
   17225             :  * PL/pgSQL Assignment statement: name opt_indirection := PLpgSQL_Expr
   17226             :  */
   17227             : 
   17228             : PLAssignStmt: plassign_target opt_indirection plassign_equals PLpgSQL_Expr
   17229             :                 {
   17230        6614 :                     PLAssignStmt *n = makeNode(PLAssignStmt);
   17231             : 
   17232        6614 :                     n->name = $1;
   17233        6614 :                     n->indirection = check_indirection($2, yyscanner);
   17234             :                     /* nnames will be filled by calling production */
   17235        6614 :                     n->val = (SelectStmt *) $4;
   17236        6614 :                     n->location = @1;
   17237        6614 :                     $$ = (Node *) n;
   17238             :                 }
   17239             :         ;
   17240             : 
   17241        6590 : plassign_target: ColId                          { $$ = $1; }
   17242          24 :             | PARAM                             { $$ = psprintf("$%d", $1); }
   17243             :         ;
   17244             : 
   17245             : plassign_equals: COLON_EQUALS
   17246             :             | '='
   17247             :         ;
   17248             : 
   17249             : 
   17250             : /*
   17251             :  * Name classification hierarchy.
   17252             :  *
   17253             :  * IDENT is the lexeme returned by the lexer for identifiers that match
   17254             :  * no known keyword.  In most cases, we can accept certain keywords as
   17255             :  * names, not only IDENTs.  We prefer to accept as many such keywords
   17256             :  * as possible to minimize the impact of "reserved words" on programmers.
   17257             :  * So, we divide names into several possible classes.  The classification
   17258             :  * is chosen in part to make keywords acceptable as names wherever possible.
   17259             :  */
   17260             : 
   17261             : /* Column identifier --- names that can be column, table, etc names.
   17262             :  */
   17263     2835630 : ColId:      IDENT                                   { $$ = $1; }
   17264       52034 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17265        4820 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17266             :         ;
   17267             : 
   17268             : /* Type/function identifier --- names that can be type or function names.
   17269             :  */
   17270      613938 : type_function_name: IDENT                           { $$ = $1; }
   17271       63706 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17272          42 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17273             :         ;
   17274             : 
   17275             : /* Any not-fully-reserved word --- these names can be, eg, role names.
   17276             :  */
   17277       65240 : NonReservedWord:    IDENT                           { $$ = $1; }
   17278       24980 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17279         170 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17280        3496 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17281             :         ;
   17282             : 
   17283             : /* Column label --- allowed labels in "AS" clauses.
   17284             :  * This presently includes *all* Postgres keywords.
   17285             :  */
   17286     1503990 : ColLabel:   IDENT                                   { $$ = $1; }
   17287       33470 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17288         272 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17289        1756 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17290        6996 :             | reserved_keyword                      { $$ = pstrdup($1); }
   17291             :         ;
   17292             : 
   17293             : /* Bare column label --- names that can be column labels without writing "AS".
   17294             :  * This classification is orthogonal to the other keyword categories.
   17295             :  */
   17296        3130 : BareColLabel:   IDENT                               { $$ = $1; }
   17297           6 :             | bare_label_keyword                    { $$ = pstrdup($1); }
   17298             :         ;
   17299             : 
   17300             : 
   17301             : /*
   17302             :  * Keyword category lists.  Generally, every keyword present in
   17303             :  * the Postgres grammar should appear in exactly one of these lists.
   17304             :  *
   17305             :  * Put a new keyword into the first list that it can go into without causing
   17306             :  * shift or reduce conflicts.  The earlier lists define "less reserved"
   17307             :  * categories of keywords.
   17308             :  *
   17309             :  * Make sure that each keyword's category in kwlist.h matches where
   17310             :  * it is listed here.  (Someday we may be able to generate these lists and
   17311             :  * kwlist.h's table from one source of truth.)
   17312             :  */
   17313             : 
   17314             : /* "Unreserved" keywords --- available for use as any kind of name.
   17315             :  */
   17316             : unreserved_keyword:
   17317             :               ABORT_P
   17318             :             | ABSENT
   17319             :             | ABSOLUTE_P
   17320             :             | ACCESS
   17321             :             | ACTION
   17322             :             | ADD_P
   17323             :             | ADMIN
   17324             :             | AFTER
   17325             :             | AGGREGATE
   17326             :             | ALSO
   17327             :             | ALTER
   17328             :             | ALWAYS
   17329             :             | ASENSITIVE
   17330             :             | ASSERTION
   17331             :             | ASSIGNMENT
   17332             :             | AT
   17333             :             | ATOMIC
   17334             :             | ATTACH
   17335             :             | ATTRIBUTE
   17336             :             | BACKWARD
   17337             :             | BEFORE
   17338             :             | BEGIN_P
   17339             :             | BREADTH
   17340             :             | BY
   17341             :             | CACHE
   17342             :             | CALL
   17343             :             | CALLED
   17344             :             | CASCADE
   17345             :             | CASCADED
   17346             :             | CATALOG_P
   17347             :             | CHAIN
   17348             :             | CHARACTERISTICS
   17349             :             | CHECKPOINT
   17350             :             | CLASS
   17351             :             | CLOSE
   17352             :             | CLUSTER
   17353             :             | COLUMNS
   17354             :             | COMMENT
   17355             :             | COMMENTS
   17356             :             | COMMIT
   17357             :             | COMMITTED
   17358             :             | COMPRESSION
   17359             :             | CONDITIONAL
   17360             :             | CONFIGURATION
   17361             :             | CONFLICT
   17362             :             | CONNECTION
   17363             :             | CONSTRAINTS
   17364             :             | CONTENT_P
   17365             :             | CONTINUE_P
   17366             :             | CONVERSION_P
   17367             :             | COPY
   17368             :             | COST
   17369             :             | CSV
   17370             :             | CUBE
   17371             :             | CURRENT_P
   17372             :             | CURSOR
   17373             :             | CYCLE
   17374             :             | DATA_P
   17375             :             | DATABASE
   17376             :             | DAY_P
   17377             :             | DEALLOCATE
   17378             :             | DECLARE
   17379             :             | DEFAULTS
   17380             :             | DEFERRED
   17381             :             | DEFINER
   17382             :             | DELETE_P
   17383             :             | DELIMITER
   17384             :             | DELIMITERS
   17385             :             | DEPENDS
   17386             :             | DEPTH
   17387             :             | DETACH
   17388             :             | DICTIONARY
   17389             :             | DISABLE_P
   17390             :             | DISCARD
   17391             :             | DOCUMENT_P
   17392             :             | DOMAIN_P
   17393             :             | DOUBLE_P
   17394             :             | DROP
   17395             :             | EACH
   17396             :             | EMPTY_P
   17397             :             | ENABLE_P
   17398             :             | ENCODING
   17399             :             | ENCRYPTED
   17400             :             | ENUM_P
   17401             :             | ERROR_P
   17402             :             | ESCAPE
   17403             :             | EVENT
   17404             :             | EXCLUDE
   17405             :             | EXCLUDING
   17406             :             | EXCLUSIVE
   17407             :             | EXECUTE
   17408             :             | EXPLAIN
   17409             :             | EXPRESSION
   17410             :             | EXTENSION
   17411             :             | EXTERNAL
   17412             :             | FAMILY
   17413             :             | FILTER
   17414             :             | FINALIZE
   17415             :             | FIRST_P
   17416             :             | FOLLOWING
   17417             :             | FORCE
   17418             :             | FORMAT
   17419             :             | FORWARD
   17420             :             | FUNCTION
   17421             :             | FUNCTIONS
   17422             :             | GENERATED
   17423             :             | GLOBAL
   17424             :             | GRANTED
   17425             :             | GROUPS
   17426             :             | HANDLER
   17427             :             | HEADER_P
   17428             :             | HOLD
   17429             :             | HOUR_P
   17430             :             | IDENTITY_P
   17431             :             | IF_P
   17432             :             | IMMEDIATE
   17433             :             | IMMUTABLE
   17434             :             | IMPLICIT_P
   17435             :             | IMPORT_P
   17436             :             | INCLUDE
   17437             :             | INCLUDING
   17438             :             | INCREMENT
   17439             :             | INDENT
   17440             :             | INDEX
   17441             :             | INDEXES
   17442             :             | INHERIT
   17443             :             | INHERITS
   17444             :             | INLINE_P
   17445             :             | INPUT_P
   17446             :             | INSENSITIVE
   17447             :             | INSERT
   17448             :             | INSTEAD
   17449             :             | INVOKER
   17450             :             | ISOLATION
   17451             :             | KEEP
   17452             :             | KEY
   17453             :             | KEYS
   17454             :             | LABEL
   17455             :             | LANGUAGE
   17456             :             | LARGE_P
   17457             :             | LAST_P
   17458             :             | LEAKPROOF
   17459             :             | LEVEL
   17460             :             | LISTEN
   17461             :             | LOAD
   17462             :             | LOCAL
   17463             :             | LOCATION
   17464             :             | LOCK_P
   17465             :             | LOCKED
   17466             :             | LOGGED
   17467             :             | MAPPING
   17468             :             | MATCH
   17469             :             | MATCHED
   17470             :             | MATERIALIZED
   17471             :             | MAXVALUE
   17472             :             | MERGE
   17473             :             | METHOD
   17474             :             | MINUTE_P
   17475             :             | MINVALUE
   17476             :             | MODE
   17477             :             | MONTH_P
   17478             :             | MOVE
   17479             :             | NAME_P
   17480             :             | NAMES
   17481             :             | NEW
   17482             :             | NEXT
   17483             :             | NFC
   17484             :             | NFD
   17485             :             | NFKC
   17486             :             | NFKD
   17487             :             | NO
   17488             :             | NORMALIZED
   17489             :             | NOTHING
   17490             :             | NOTIFY
   17491             :             | NOWAIT
   17492             :             | NULLS_P
   17493             :             | OBJECT_P
   17494             :             | OF
   17495             :             | OFF
   17496             :             | OIDS
   17497             :             | OLD
   17498             :             | OMIT
   17499             :             | OPERATOR
   17500             :             | OPTION
   17501             :             | OPTIONS
   17502             :             | ORDINALITY
   17503             :             | OTHERS
   17504             :             | OVER
   17505             :             | OVERRIDING
   17506             :             | OWNED
   17507             :             | OWNER
   17508             :             | PARALLEL
   17509             :             | PARAMETER
   17510             :             | PARSER
   17511             :             | PARTIAL
   17512             :             | PARTITION
   17513             :             | PASSING
   17514             :             | PASSWORD
   17515             :             | PERIOD
   17516             :             | PLANS
   17517             :             | POLICY
   17518             :             | PRECEDING
   17519             :             | PREPARE
   17520             :             | PREPARED
   17521             :             | PRESERVE
   17522             :             | PRIOR
   17523             :             | PRIVILEGES
   17524             :             | PROCEDURAL
   17525             :             | PROCEDURE
   17526             :             | PROCEDURES
   17527             :             | PROGRAM
   17528             :             | PUBLICATION
   17529             :             | QUOTE
   17530             :             | QUOTES
   17531             :             | RANGE
   17532             :             | READ
   17533             :             | REASSIGN
   17534             :             | RECHECK
   17535             :             | RECURSIVE
   17536             :             | REF_P
   17537             :             | REFERENCING
   17538             :             | REFRESH
   17539             :             | REINDEX
   17540             :             | RELATIVE_P
   17541             :             | RELEASE
   17542             :             | RENAME
   17543             :             | REPEATABLE
   17544             :             | REPLACE
   17545             :             | REPLICA
   17546             :             | RESET
   17547             :             | RESTART
   17548             :             | RESTRICT
   17549             :             | RETURN
   17550             :             | RETURNS
   17551             :             | REVOKE
   17552             :             | ROLE
   17553             :             | ROLLBACK
   17554             :             | ROLLUP
   17555             :             | ROUTINE
   17556             :             | ROUTINES
   17557             :             | ROWS
   17558             :             | RULE
   17559             :             | SAVEPOINT
   17560             :             | SCALAR
   17561             :             | SCHEMA
   17562             :             | SCHEMAS
   17563             :             | SCROLL
   17564             :             | SEARCH
   17565             :             | SECOND_P
   17566             :             | SECURITY
   17567             :             | SEQUENCE
   17568             :             | SEQUENCES
   17569             :             | SERIALIZABLE
   17570             :             | SERVER
   17571             :             | SESSION
   17572             :             | SET
   17573             :             | SETS
   17574             :             | SHARE
   17575             :             | SHOW
   17576             :             | SIMPLE
   17577             :             | SKIP
   17578             :             | SNAPSHOT
   17579             :             | SQL_P
   17580             :             | STABLE
   17581             :             | STANDALONE_P
   17582             :             | START
   17583             :             | STATEMENT
   17584             :             | STATISTICS
   17585             :             | STDIN
   17586             :             | STDOUT
   17587             :             | STORAGE
   17588             :             | STORED
   17589             :             | STRICT_P
   17590             :             | STRING_P
   17591             :             | STRIP_P
   17592             :             | SUBSCRIPTION
   17593             :             | SUPPORT
   17594             :             | SYSID
   17595             :             | SYSTEM_P
   17596             :             | TABLES
   17597             :             | TABLESPACE
   17598             :             | TEMP
   17599             :             | TEMPLATE
   17600             :             | TEMPORARY
   17601             :             | TEXT_P
   17602             :             | TIES
   17603             :             | TRANSACTION
   17604             :             | TRANSFORM
   17605             :             | TRIGGER
   17606             :             | TRUNCATE
   17607             :             | TRUSTED
   17608             :             | TYPE_P
   17609             :             | TYPES_P
   17610             :             | UESCAPE
   17611             :             | UNBOUNDED
   17612             :             | UNCOMMITTED
   17613             :             | UNCONDITIONAL
   17614             :             | UNENCRYPTED
   17615             :             | UNKNOWN
   17616             :             | UNLISTEN
   17617             :             | UNLOGGED
   17618             :             | UNTIL
   17619             :             | UPDATE
   17620             :             | VACUUM
   17621             :             | VALID
   17622             :             | VALIDATE
   17623             :             | VALIDATOR
   17624             :             | VALUE_P
   17625             :             | VARYING
   17626             :             | VERSION_P
   17627             :             | VIEW
   17628             :             | VIEWS
   17629             :             | VOLATILE
   17630             :             | WHITESPACE_P
   17631             :             | WITHIN
   17632             :             | WITHOUT
   17633             :             | WORK
   17634             :             | WRAPPER
   17635             :             | WRITE
   17636             :             | XML_P
   17637             :             | YEAR_P
   17638             :             | YES_P
   17639             :             | ZONE
   17640             :         ;
   17641             : 
   17642             : /* Column identifier --- keywords that can be column, table, etc names.
   17643             :  *
   17644             :  * Many of these keywords will in fact be recognized as type or function
   17645             :  * names too; but they have special productions for the purpose, and so
   17646             :  * can't be treated as "generic" type or function names.
   17647             :  *
   17648             :  * The type names appearing here are not usable as function names
   17649             :  * because they can be followed by '(' in typename productions, which
   17650             :  * looks too much like a function call for an LR(1) parser.
   17651             :  */
   17652             : col_name_keyword:
   17653             :               BETWEEN
   17654             :             | BIGINT
   17655             :             | BIT
   17656             :             | BOOLEAN_P
   17657             :             | CHAR_P
   17658             :             | CHARACTER
   17659             :             | COALESCE
   17660             :             | DEC
   17661             :             | DECIMAL_P
   17662             :             | EXISTS
   17663             :             | EXTRACT
   17664             :             | FLOAT_P
   17665             :             | GREATEST
   17666             :             | GROUPING
   17667             :             | INOUT
   17668             :             | INT_P
   17669             :             | INTEGER
   17670             :             | INTERVAL
   17671             :             | JSON
   17672             :             | JSON_ARRAY
   17673             :             | JSON_ARRAYAGG
   17674             :             | JSON_EXISTS
   17675             :             | JSON_OBJECT
   17676             :             | JSON_OBJECTAGG
   17677             :             | JSON_QUERY
   17678             :             | JSON_SCALAR
   17679             :             | JSON_SERIALIZE
   17680             :             | JSON_VALUE
   17681             :             | LEAST
   17682             :             | MERGE_ACTION
   17683             :             | NATIONAL
   17684             :             | NCHAR
   17685             :             | NONE
   17686             :             | NORMALIZE
   17687             :             | NULLIF
   17688             :             | NUMERIC
   17689             :             | OUT_P
   17690             :             | OVERLAY
   17691             :             | POSITION
   17692             :             | PRECISION
   17693             :             | REAL
   17694             :             | ROW
   17695             :             | SETOF
   17696             :             | SMALLINT
   17697             :             | SUBSTRING
   17698             :             | TIME
   17699             :             | TIMESTAMP
   17700             :             | TREAT
   17701             :             | TRIM
   17702             :             | VALUES
   17703             :             | VARCHAR
   17704             :             | XMLATTRIBUTES
   17705             :             | XMLCONCAT
   17706             :             | XMLELEMENT
   17707             :             | XMLEXISTS
   17708             :             | XMLFOREST
   17709             :             | XMLNAMESPACES
   17710             :             | XMLPARSE
   17711             :             | XMLPI
   17712             :             | XMLROOT
   17713             :             | XMLSERIALIZE
   17714             :             | XMLTABLE
   17715             :         ;
   17716             : 
   17717             : /* Type/function identifier --- keywords that can be type or function names.
   17718             :  *
   17719             :  * Most of these are keywords that are used as operators in expressions;
   17720             :  * in general such keywords can't be column names because they would be
   17721             :  * ambiguous with variables, but they are unambiguous as function identifiers.
   17722             :  *
   17723             :  * Do not include POSITION, SUBSTRING, etc here since they have explicit
   17724             :  * productions in a_expr to support the goofy SQL9x argument syntax.
   17725             :  * - thomas 2000-11-28
   17726             :  */
   17727             : type_func_name_keyword:
   17728             :               AUTHORIZATION
   17729             :             | BINARY
   17730             :             | COLLATION
   17731             :             | CONCURRENTLY
   17732             :             | CROSS
   17733             :             | CURRENT_SCHEMA
   17734             :             | FREEZE
   17735             :             | FULL
   17736             :             | ILIKE
   17737             :             | INNER_P
   17738             :             | IS
   17739             :             | ISNULL
   17740             :             | JOIN
   17741             :             | LEFT
   17742             :             | LIKE
   17743             :             | NATURAL
   17744             :             | NOTNULL
   17745             :             | OUTER_P
   17746             :             | OVERLAPS
   17747             :             | RIGHT
   17748             :             | SIMILAR
   17749             :             | TABLESAMPLE
   17750             :             | VERBOSE
   17751             :         ;
   17752             : 
   17753             : /* Reserved keyword --- these keywords are usable only as a ColLabel.
   17754             :  *
   17755             :  * Keywords appear here if they could not be distinguished from variable,
   17756             :  * type, or function names in some contexts.  Don't put things here unless
   17757             :  * forced to.
   17758             :  */
   17759             : reserved_keyword:
   17760             :               ALL
   17761             :             | ANALYSE
   17762             :             | ANALYZE
   17763             :             | AND
   17764             :             | ANY
   17765             :             | ARRAY
   17766             :             | AS
   17767             :             | ASC
   17768             :             | ASYMMETRIC
   17769             :             | BOTH
   17770             :             | CASE
   17771             :             | CAST
   17772             :             | CHECK
   17773             :             | COLLATE
   17774             :             | COLUMN
   17775             :             | CONSTRAINT
   17776             :             | CREATE
   17777             :             | CURRENT_CATALOG
   17778             :             | CURRENT_DATE
   17779             :             | CURRENT_ROLE
   17780             :             | CURRENT_TIME
   17781             :             | CURRENT_TIMESTAMP
   17782             :             | CURRENT_USER
   17783             :             | DEFAULT
   17784             :             | DEFERRABLE
   17785             :             | DESC
   17786             :             | DISTINCT
   17787             :             | DO
   17788             :             | ELSE
   17789             :             | END_P
   17790             :             | EXCEPT
   17791             :             | FALSE_P
   17792             :             | FETCH
   17793             :             | FOR
   17794             :             | FOREIGN
   17795             :             | FROM
   17796             :             | GRANT
   17797             :             | GROUP_P
   17798             :             | HAVING
   17799             :             | IN_P
   17800             :             | INITIALLY
   17801             :             | INTERSECT
   17802             :             | INTO
   17803             :             | LATERAL_P
   17804             :             | LEADING
   17805             :             | LIMIT
   17806             :             | LOCALTIME
   17807             :             | LOCALTIMESTAMP
   17808             :             | NOT
   17809             :             | NULL_P
   17810             :             | OFFSET
   17811             :             | ON
   17812             :             | ONLY
   17813             :             | OR
   17814             :             | ORDER
   17815             :             | PLACING
   17816             :             | PRIMARY
   17817             :             | REFERENCES
   17818             :             | RETURNING
   17819             :             | SELECT
   17820             :             | SESSION_USER
   17821             :             | SOME
   17822             :             | SYMMETRIC
   17823             :             | SYSTEM_USER
   17824             :             | TABLE
   17825             :             | THEN
   17826             :             | TO
   17827             :             | TRAILING
   17828             :             | TRUE_P
   17829             :             | UNION
   17830             :             | UNIQUE
   17831             :             | USER
   17832             :             | USING
   17833             :             | VARIADIC
   17834             :             | WHEN
   17835             :             | WHERE
   17836             :             | WINDOW
   17837             :             | WITH
   17838             :         ;
   17839             : 
   17840             : /*
   17841             :  * While all keywords can be used as column labels when preceded by AS,
   17842             :  * not all of them can be used as a "bare" column label without AS.
   17843             :  * Those that can be used as a bare label must be listed here,
   17844             :  * in addition to appearing in one of the category lists above.
   17845             :  *
   17846             :  * Always add a new keyword to this list if possible.  Mark it BARE_LABEL
   17847             :  * in kwlist.h if it is included here, or AS_LABEL if it is not.
   17848             :  */
   17849             : bare_label_keyword:
   17850             :               ABORT_P
   17851             :             | ABSENT
   17852             :             | ABSOLUTE_P
   17853             :             | ACCESS
   17854             :             | ACTION
   17855             :             | ADD_P
   17856             :             | ADMIN
   17857             :             | AFTER
   17858             :             | AGGREGATE
   17859             :             | ALL
   17860             :             | ALSO
   17861             :             | ALTER
   17862             :             | ALWAYS
   17863             :             | ANALYSE
   17864             :             | ANALYZE
   17865             :             | AND
   17866             :             | ANY
   17867             :             | ASC
   17868             :             | ASENSITIVE
   17869             :             | ASSERTION
   17870             :             | ASSIGNMENT
   17871             :             | ASYMMETRIC
   17872             :             | AT
   17873             :             | ATOMIC
   17874             :             | ATTACH
   17875             :             | ATTRIBUTE
   17876             :             | AUTHORIZATION
   17877             :             | BACKWARD
   17878             :             | BEFORE
   17879             :             | BEGIN_P
   17880             :             | BETWEEN
   17881             :             | BIGINT
   17882             :             | BINARY
   17883             :             | BIT
   17884             :             | BOOLEAN_P
   17885             :             | BOTH
   17886             :             | BREADTH
   17887             :             | BY
   17888             :             | CACHE
   17889             :             | CALL
   17890             :             | CALLED
   17891             :             | CASCADE
   17892             :             | CASCADED
   17893             :             | CASE
   17894             :             | CAST
   17895             :             | CATALOG_P
   17896             :             | CHAIN
   17897             :             | CHARACTERISTICS
   17898             :             | CHECK
   17899             :             | CHECKPOINT
   17900             :             | CLASS
   17901             :             | CLOSE
   17902             :             | CLUSTER
   17903             :             | COALESCE
   17904             :             | COLLATE
   17905             :             | COLLATION
   17906             :             | COLUMN
   17907             :             | COLUMNS
   17908             :             | COMMENT
   17909             :             | COMMENTS
   17910             :             | COMMIT
   17911             :             | COMMITTED
   17912             :             | COMPRESSION
   17913             :             | CONCURRENTLY
   17914             :             | CONDITIONAL
   17915             :             | CONFIGURATION
   17916             :             | CONFLICT
   17917             :             | CONNECTION
   17918             :             | CONSTRAINT
   17919             :             | CONSTRAINTS
   17920             :             | CONTENT_P
   17921             :             | CONTINUE_P
   17922             :             | CONVERSION_P
   17923             :             | COPY
   17924             :             | COST
   17925             :             | CROSS
   17926             :             | CSV
   17927             :             | CUBE
   17928             :             | CURRENT_P
   17929             :             | CURRENT_CATALOG
   17930             :             | CURRENT_DATE
   17931             :             | CURRENT_ROLE
   17932             :             | CURRENT_SCHEMA
   17933             :             | CURRENT_TIME
   17934             :             | CURRENT_TIMESTAMP
   17935             :             | CURRENT_USER
   17936             :             | CURSOR
   17937             :             | CYCLE
   17938             :             | DATA_P
   17939             :             | DATABASE
   17940             :             | DEALLOCATE
   17941             :             | DEC
   17942             :             | DECIMAL_P
   17943             :             | DECLARE
   17944             :             | DEFAULT
   17945             :             | DEFAULTS
   17946             :             | DEFERRABLE
   17947             :             | DEFERRED
   17948             :             | DEFINER
   17949             :             | DELETE_P
   17950             :             | DELIMITER
   17951             :             | DELIMITERS
   17952             :             | DEPENDS
   17953             :             | DEPTH
   17954             :             | DESC
   17955             :             | DETACH
   17956             :             | DICTIONARY
   17957             :             | DISABLE_P
   17958             :             | DISCARD
   17959             :             | DISTINCT
   17960             :             | DO
   17961             :             | DOCUMENT_P
   17962             :             | DOMAIN_P
   17963             :             | DOUBLE_P
   17964             :             | DROP
   17965             :             | EACH
   17966             :             | ELSE
   17967             :             | EMPTY_P
   17968             :             | ENABLE_P
   17969             :             | ENCODING
   17970             :             | ENCRYPTED
   17971             :             | END_P
   17972             :             | ENUM_P
   17973             :             | ERROR_P
   17974             :             | ESCAPE
   17975             :             | EVENT
   17976             :             | EXCLUDE
   17977             :             | EXCLUDING
   17978             :             | EXCLUSIVE
   17979             :             | EXECUTE
   17980             :             | EXISTS
   17981             :             | EXPLAIN
   17982             :             | EXPRESSION
   17983             :             | EXTENSION
   17984             :             | EXTERNAL
   17985             :             | EXTRACT
   17986             :             | FALSE_P
   17987             :             | FAMILY
   17988             :             | FINALIZE
   17989             :             | FIRST_P
   17990             :             | FLOAT_P
   17991             :             | FOLLOWING
   17992             :             | FORCE
   17993             :             | FOREIGN
   17994             :             | FORMAT
   17995             :             | FORWARD
   17996             :             | FREEZE
   17997             :             | FULL
   17998             :             | FUNCTION
   17999             :             | FUNCTIONS
   18000             :             | GENERATED
   18001             :             | GLOBAL
   18002             :             | GRANTED
   18003             :             | GREATEST
   18004             :             | GROUPING
   18005             :             | GROUPS
   18006             :             | HANDLER
   18007             :             | HEADER_P
   18008             :             | HOLD
   18009             :             | IDENTITY_P
   18010             :             | IF_P
   18011             :             | ILIKE
   18012             :             | IMMEDIATE
   18013             :             | IMMUTABLE
   18014             :             | IMPLICIT_P
   18015             :             | IMPORT_P
   18016             :             | IN_P
   18017             :             | INCLUDE
   18018             :             | INCLUDING
   18019             :             | INCREMENT
   18020             :             | INDENT
   18021             :             | INDEX
   18022             :             | INDEXES
   18023             :             | INHERIT
   18024             :             | INHERITS
   18025             :             | INITIALLY
   18026             :             | INLINE_P
   18027             :             | INNER_P
   18028             :             | INOUT
   18029             :             | INPUT_P
   18030             :             | INSENSITIVE
   18031             :             | INSERT
   18032             :             | INSTEAD
   18033             :             | INT_P
   18034             :             | INTEGER
   18035             :             | INTERVAL
   18036             :             | INVOKER
   18037             :             | IS
   18038             :             | ISOLATION
   18039             :             | JOIN
   18040             :             | JSON
   18041             :             | JSON_ARRAY
   18042             :             | JSON_ARRAYAGG
   18043             :             | JSON_EXISTS
   18044             :             | JSON_OBJECT
   18045             :             | JSON_OBJECTAGG
   18046             :             | JSON_QUERY
   18047             :             | JSON_SCALAR
   18048             :             | JSON_SERIALIZE
   18049             :             | JSON_VALUE
   18050             :             | KEEP
   18051             :             | KEY
   18052             :             | KEYS
   18053             :             | LABEL
   18054             :             | LANGUAGE
   18055             :             | LARGE_P
   18056             :             | LAST_P
   18057             :             | LATERAL_P
   18058             :             | LEADING
   18059             :             | LEAKPROOF
   18060             :             | LEAST
   18061             :             | LEFT
   18062             :             | LEVEL
   18063             :             | LIKE
   18064             :             | LISTEN
   18065             :             | LOAD
   18066             :             | LOCAL
   18067             :             | LOCALTIME
   18068             :             | LOCALTIMESTAMP
   18069             :             | LOCATION
   18070             :             | LOCK_P
   18071             :             | LOCKED
   18072             :             | LOGGED
   18073             :             | MAPPING
   18074             :             | MATCH
   18075             :             | MATCHED
   18076             :             | MATERIALIZED
   18077             :             | MAXVALUE
   18078             :             | MERGE
   18079             :             | MERGE_ACTION
   18080             :             | METHOD
   18081             :             | MINVALUE
   18082             :             | MODE
   18083             :             | MOVE
   18084             :             | NAME_P
   18085             :             | NAMES
   18086             :             | NATIONAL
   18087             :             | NATURAL
   18088             :             | NCHAR
   18089             :             | NEW
   18090             :             | NEXT
   18091             :             | NFC
   18092             :             | NFD
   18093             :             | NFKC
   18094             :             | NFKD
   18095             :             | NO
   18096             :             | NONE
   18097             :             | NORMALIZE
   18098             :             | NORMALIZED
   18099             :             | NOT
   18100             :             | NOTHING
   18101             :             | NOTIFY
   18102             :             | NOWAIT
   18103             :             | NULL_P
   18104             :             | NULLIF
   18105             :             | NULLS_P
   18106             :             | NUMERIC
   18107             :             | OBJECT_P
   18108             :             | OF
   18109             :             | OFF
   18110             :             | OIDS
   18111             :             | OLD
   18112             :             | OMIT
   18113             :             | ONLY
   18114             :             | OPERATOR
   18115             :             | OPTION
   18116             :             | OPTIONS
   18117             :             | OR
   18118             :             | ORDINALITY
   18119             :             | OTHERS
   18120             :             | OUT_P
   18121             :             | OUTER_P
   18122             :             | OVERLAY
   18123             :             | OVERRIDING
   18124             :             | OWNED
   18125             :             | OWNER
   18126             :             | PARALLEL
   18127             :             | PARAMETER
   18128             :             | PARSER
   18129             :             | PARTIAL
   18130             :             | PARTITION
   18131             :             | PASSING
   18132             :             | PASSWORD
   18133             :             | PERIOD
   18134             :             | PLACING
   18135             :             | PLANS
   18136             :             | POLICY
   18137             :             | POSITION
   18138             :             | PRECEDING
   18139             :             | PREPARE
   18140             :             | PREPARED
   18141             :             | PRESERVE
   18142             :             | PRIMARY
   18143             :             | PRIOR
   18144             :             | PRIVILEGES
   18145             :             | PROCEDURAL
   18146             :             | PROCEDURE
   18147             :             | PROCEDURES
   18148             :             | PROGRAM
   18149             :             | PUBLICATION
   18150             :             | QUOTE
   18151             :             | QUOTES
   18152             :             | RANGE
   18153             :             | READ
   18154             :             | REAL
   18155             :             | REASSIGN
   18156             :             | RECHECK
   18157             :             | RECURSIVE
   18158             :             | REF_P
   18159             :             | REFERENCES
   18160             :             | REFERENCING
   18161             :             | REFRESH
   18162             :             | REINDEX
   18163             :             | RELATIVE_P
   18164             :             | RELEASE
   18165             :             | RENAME
   18166             :             | REPEATABLE
   18167             :             | REPLACE
   18168             :             | REPLICA
   18169             :             | RESET
   18170             :             | RESTART
   18171             :             | RESTRICT
   18172             :             | RETURN
   18173             :             | RETURNS
   18174             :             | REVOKE
   18175             :             | RIGHT
   18176             :             | ROLE
   18177             :             | ROLLBACK
   18178             :             | ROLLUP
   18179             :             | ROUTINE
   18180             :             | ROUTINES
   18181             :             | ROW
   18182             :             | ROWS
   18183             :             | RULE
   18184             :             | SAVEPOINT
   18185             :             | SCALAR
   18186             :             | SCHEMA
   18187             :             | SCHEMAS
   18188             :             | SCROLL
   18189             :             | SEARCH
   18190             :             | SECURITY
   18191             :             | SELECT
   18192             :             | SEQUENCE
   18193             :             | SEQUENCES
   18194             :             | SERIALIZABLE
   18195             :             | SERVER
   18196             :             | SESSION
   18197             :             | SESSION_USER
   18198             :             | SET
   18199             :             | SETOF
   18200             :             | SETS
   18201             :             | SHARE
   18202             :             | SHOW
   18203             :             | SIMILAR
   18204             :             | SIMPLE
   18205             :             | SKIP
   18206             :             | SMALLINT
   18207             :             | SNAPSHOT
   18208             :             | SOME
   18209             :             | SQL_P
   18210             :             | STABLE
   18211             :             | STANDALONE_P
   18212             :             | START
   18213             :             | STATEMENT
   18214             :             | STATISTICS
   18215             :             | STDIN
   18216             :             | STDOUT
   18217             :             | STORAGE
   18218             :             | STORED
   18219             :             | STRICT_P
   18220             :             | STRING_P
   18221             :             | STRIP_P
   18222             :             | SUBSCRIPTION
   18223             :             | SUBSTRING
   18224             :             | SUPPORT
   18225             :             | SYMMETRIC
   18226             :             | SYSID
   18227             :             | SYSTEM_P
   18228             :             | SYSTEM_USER
   18229             :             | TABLE
   18230             :             | TABLES
   18231             :             | TABLESAMPLE
   18232             :             | TABLESPACE
   18233             :             | TEMP
   18234             :             | TEMPLATE
   18235             :             | TEMPORARY
   18236             :             | TEXT_P
   18237             :             | THEN
   18238             :             | TIES
   18239             :             | TIME
   18240             :             | TIMESTAMP
   18241             :             | TRAILING
   18242             :             | TRANSACTION
   18243             :             | TRANSFORM
   18244             :             | TREAT
   18245             :             | TRIGGER
   18246             :             | TRIM
   18247             :             | TRUE_P
   18248             :             | TRUNCATE
   18249             :             | TRUSTED
   18250             :             | TYPE_P
   18251             :             | TYPES_P
   18252             :             | UESCAPE
   18253             :             | UNBOUNDED
   18254             :             | UNCOMMITTED
   18255             :             | UNCONDITIONAL
   18256             :             | UNENCRYPTED
   18257             :             | UNIQUE
   18258             :             | UNKNOWN
   18259             :             | UNLISTEN
   18260             :             | UNLOGGED
   18261             :             | UNTIL
   18262             :             | UPDATE
   18263             :             | USER
   18264             :             | USING
   18265             :             | VACUUM
   18266             :             | VALID
   18267             :             | VALIDATE
   18268             :             | VALIDATOR
   18269             :             | VALUE_P
   18270             :             | VALUES
   18271             :             | VARCHAR
   18272             :             | VARIADIC
   18273             :             | VERBOSE
   18274             :             | VERSION_P
   18275             :             | VIEW
   18276             :             | VIEWS
   18277             :             | VOLATILE
   18278             :             | WHEN
   18279             :             | WHITESPACE_P
   18280             :             | WORK
   18281             :             | WRAPPER
   18282             :             | WRITE
   18283             :             | XML_P
   18284             :             | XMLATTRIBUTES
   18285             :             | XMLCONCAT
   18286             :             | XMLELEMENT
   18287             :             | XMLEXISTS
   18288             :             | XMLFOREST
   18289             :             | XMLNAMESPACES
   18290             :             | XMLPARSE
   18291             :             | XMLPI
   18292             :             | XMLROOT
   18293             :             | XMLSERIALIZE
   18294             :             | XMLTABLE
   18295             :             | YES_P
   18296             :             | ZONE
   18297             :         ;
   18298             : 
   18299             : %%
   18300             : 
   18301             : /*
   18302             :  * The signature of this function is required by bison.  However, we
   18303             :  * ignore the passed yylloc and instead use the last token position
   18304             :  * available from the scanner.
   18305             :  */
   18306             : static void
   18307         656 : base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
   18308             : {
   18309         656 :     parser_yyerror(msg);
   18310             : }
   18311             : 
   18312             : static RawStmt *
   18313      754284 : makeRawStmt(Node *stmt, int stmt_location)
   18314             : {
   18315      754284 :     RawStmt    *rs = makeNode(RawStmt);
   18316             : 
   18317      754284 :     rs->stmt = stmt;
   18318      754284 :     rs->stmt_location = stmt_location;
   18319      754284 :     rs->stmt_len = 0;            /* might get changed later */
   18320      754284 :     return rs;
   18321             : }
   18322             : 
   18323             : /* Adjust a RawStmt to reflect that it doesn't run to the end of the string */
   18324             : static void
   18325      542228 : updateRawStmtEnd(RawStmt *rs, int end_location)
   18326             : {
   18327             :     /*
   18328             :      * If we already set the length, don't change it.  This is for situations
   18329             :      * like "select foo ;; select bar" where the same statement will be last
   18330             :      * in the string for more than one semicolon.
   18331             :      */
   18332      542228 :     if (rs->stmt_len > 0)
   18333          10 :         return;
   18334             : 
   18335             :     /* OK, update length of RawStmt */
   18336      542218 :     rs->stmt_len = end_location - rs->stmt_location;
   18337             : }
   18338             : 
   18339             : static Node *
   18340     1496268 : makeColumnRef(char *colname, List *indirection,
   18341             :               int location, core_yyscan_t yyscanner)
   18342             : {
   18343             :     /*
   18344             :      * Generate a ColumnRef node, with an A_Indirection node added if there
   18345             :      * is any subscripting in the specified indirection list.  However,
   18346             :      * any field selection at the start of the indirection list must be
   18347             :      * transposed into the "fields" part of the ColumnRef node.
   18348             :      */
   18349     1496268 :     ColumnRef  *c = makeNode(ColumnRef);
   18350     1496268 :     int         nfields = 0;
   18351             :     ListCell   *l;
   18352             : 
   18353     1496268 :     c->location = location;
   18354     2409758 :     foreach(l, indirection)
   18355             :     {
   18356      922148 :         if (IsA(lfirst(l), A_Indices))
   18357             :         {
   18358        8658 :             A_Indirection *i = makeNode(A_Indirection);
   18359             : 
   18360        8658 :             if (nfields == 0)
   18361             :             {
   18362             :                 /* easy case - all indirection goes to A_Indirection */
   18363        6264 :                 c->fields = list_make1(makeString(colname));
   18364        6264 :                 i->indirection = check_indirection(indirection, yyscanner);
   18365             :             }
   18366             :             else
   18367             :             {
   18368             :                 /* got to split the list in two */
   18369        2394 :                 i->indirection = check_indirection(list_copy_tail(indirection,
   18370             :                                                                   nfields),
   18371             :                                                    yyscanner);
   18372        2394 :                 indirection = list_truncate(indirection, nfields);
   18373        2394 :                 c->fields = lcons(makeString(colname), indirection);
   18374             :             }
   18375        8658 :             i->arg = (Node *) c;
   18376        8658 :             return (Node *) i;
   18377             :         }
   18378      913490 :         else if (IsA(lfirst(l), A_Star))
   18379             :         {
   18380             :             /* We only allow '*' at the end of a ColumnRef */
   18381        4586 :             if (lnext(indirection, l) != NULL)
   18382           0 :                 parser_yyerror("improper use of \"*\"");
   18383             :         }
   18384      913490 :         nfields++;
   18385             :     }
   18386             :     /* No subscripting, so all indirection gets added to field list */
   18387     1487610 :     c->fields = lcons(makeString(colname), indirection);
   18388     1487610 :     return (Node *) c;
   18389             : }
   18390             : 
   18391             : static Node *
   18392      237774 : makeTypeCast(Node *arg, TypeName *typename, int location)
   18393             : {
   18394      237774 :     TypeCast   *n = makeNode(TypeCast);
   18395             : 
   18396      237774 :     n->arg = arg;
   18397      237774 :     n->typeName = typename;
   18398      237774 :     n->location = location;
   18399      237774 :     return (Node *) n;
   18400             : }
   18401             : 
   18402             : static Node *
   18403      577284 : makeStringConst(char *str, int location)
   18404             : {
   18405      577284 :     A_Const    *n = makeNode(A_Const);
   18406             : 
   18407      577284 :     n->val.sval.type = T_String;
   18408      577284 :     n->val.sval.sval = str;
   18409      577284 :     n->location = location;
   18410             : 
   18411      577284 :    return (Node *) n;
   18412             : }
   18413             : 
   18414             : static Node *
   18415       15170 : makeStringConstCast(char *str, int location, TypeName *typename)
   18416             : {
   18417       15170 :     Node       *s = makeStringConst(str, location);
   18418             : 
   18419       15170 :     return makeTypeCast(s, typename, -1);
   18420             : }
   18421             : 
   18422             : static Node *
   18423      413458 : makeIntConst(int val, int location)
   18424             : {
   18425      413458 :     A_Const    *n = makeNode(A_Const);
   18426             : 
   18427      413458 :     n->val.ival.type = T_Integer;
   18428      413458 :     n->val.ival.ival = val;
   18429      413458 :     n->location = location;
   18430             : 
   18431      413458 :    return (Node *) n;
   18432             : }
   18433             : 
   18434             : static Node *
   18435       10848 : makeFloatConst(char *str, int location)
   18436             : {
   18437       10848 :     A_Const    *n = makeNode(A_Const);
   18438             : 
   18439       10848 :     n->val.fval.type = T_Float;
   18440       10848 :     n->val.fval.fval = str;
   18441       10848 :     n->location = location;
   18442             : 
   18443       10848 :    return (Node *) n;
   18444             : }
   18445             : 
   18446             : static Node *
   18447       54080 : makeBoolAConst(bool state, int location)
   18448             : {
   18449       54080 :     A_Const    *n = makeNode(A_Const);
   18450             : 
   18451       54080 :     n->val.boolval.type = T_Boolean;
   18452       54080 :     n->val.boolval.boolval = state;
   18453       54080 :     n->location = location;
   18454             : 
   18455       54080 :    return (Node *) n;
   18456             : }
   18457             : 
   18458             : static Node *
   18459        4056 : makeBitStringConst(char *str, int location)
   18460             : {
   18461        4056 :     A_Const    *n = makeNode(A_Const);
   18462             : 
   18463        4056 :     n->val.bsval.type = T_BitString;
   18464        4056 :     n->val.bsval.bsval = str;
   18465        4056 :     n->location = location;
   18466             : 
   18467        4056 :    return (Node *) n;
   18468             : }
   18469             : 
   18470             : static Node *
   18471       56660 : makeNullAConst(int location)
   18472             : {
   18473       56660 :     A_Const    *n = makeNode(A_Const);
   18474             : 
   18475       56660 :     n->isnull = true;
   18476       56660 :     n->location = location;
   18477             : 
   18478       56660 :     return (Node *) n;
   18479             : }
   18480             : 
   18481             : static Node *
   18482        4264 : makeAConst(Node *v, int location)
   18483             : {
   18484             :     Node       *n;
   18485             : 
   18486        4264 :     switch (v->type)
   18487             :     {
   18488         218 :         case T_Float:
   18489         218 :             n = makeFloatConst(castNode(Float, v)->fval, location);
   18490         218 :             break;
   18491             : 
   18492        4046 :         case T_Integer:
   18493        4046 :             n = makeIntConst(castNode(Integer, v)->ival, location);
   18494        4046 :             break;
   18495             : 
   18496           0 :         default:
   18497             :             /* currently not used */
   18498             :             Assert(false);
   18499           0 :             n = NULL;
   18500             :     }
   18501             : 
   18502        4264 :     return n;
   18503             : }
   18504             : 
   18505             : /* makeRoleSpec
   18506             :  * Create a RoleSpec with the given type
   18507             :  */
   18508             : static RoleSpec *
   18509       25962 : makeRoleSpec(RoleSpecType type, int location)
   18510             : {
   18511       25962 :     RoleSpec   *spec = makeNode(RoleSpec);
   18512             : 
   18513       25962 :     spec->roletype = type;
   18514       25962 :     spec->location = location;
   18515             : 
   18516       25962 :     return spec;
   18517             : }
   18518             : 
   18519             : /* check_qualified_name --- check the result of qualified_name production
   18520             :  *
   18521             :  * It's easiest to let the grammar production for qualified_name allow
   18522             :  * subscripts and '*', which we then must reject here.
   18523             :  */
   18524             : static void
   18525      213806 : check_qualified_name(List *names, core_yyscan_t yyscanner)
   18526             : {
   18527             :     ListCell   *i;
   18528             : 
   18529      427612 :     foreach(i, names)
   18530             :     {
   18531      213806 :         if (!IsA(lfirst(i), String))
   18532           0 :             parser_yyerror("syntax error");
   18533             :     }
   18534      213806 : }
   18535             : 
   18536             : /* check_func_name --- check the result of func_name production
   18537             :  *
   18538             :  * It's easiest to let the grammar production for func_name allow subscripts
   18539             :  * and '*', which we then must reject here.
   18540             :  */
   18541             : static List *
   18542      108080 : check_func_name(List *names, core_yyscan_t yyscanner)
   18543             : {
   18544             :     ListCell   *i;
   18545             : 
   18546      324240 :     foreach(i, names)
   18547             :     {
   18548      216160 :         if (!IsA(lfirst(i), String))
   18549           0 :             parser_yyerror("syntax error");
   18550             :     }
   18551      108080 :     return names;
   18552             : }
   18553             : 
   18554             : /* check_indirection --- check the result of indirection production
   18555             :  *
   18556             :  * We only allow '*' at the end of the list, but it's hard to enforce that
   18557             :  * in the grammar, so do it here.
   18558             :  */
   18559             : static List *
   18560       73370 : check_indirection(List *indirection, core_yyscan_t yyscanner)
   18561             : {
   18562             :     ListCell *l;
   18563             : 
   18564       97228 :     foreach(l, indirection)
   18565             :     {
   18566       23858 :         if (IsA(lfirst(l), A_Star))
   18567             :         {
   18568        1236 :             if (lnext(indirection, l) != NULL)
   18569           0 :                 parser_yyerror("improper use of \"*\"");
   18570             :         }
   18571             :     }
   18572       73370 :     return indirection;
   18573             : }
   18574             : 
   18575             : /* extractArgTypes()
   18576             :  * Given a list of FunctionParameter nodes, extract a list of just the
   18577             :  * argument types (TypeNames) for input parameters only.  This is what
   18578             :  * is needed to look up an existing function, which is what is wanted by
   18579             :  * the productions that use this call.
   18580             :  */
   18581             : static List *
   18582       13460 : extractArgTypes(List *parameters)
   18583             : {
   18584       13460 :     List       *result = NIL;
   18585             :     ListCell   *i;
   18586             : 
   18587       30020 :     foreach(i, parameters)
   18588             :     {
   18589       16560 :         FunctionParameter *p = (FunctionParameter *) lfirst(i);
   18590             : 
   18591       16560 :         if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
   18592       16410 :             result = lappend(result, p->argType);
   18593             :     }
   18594       13460 :     return result;
   18595             : }
   18596             : 
   18597             : /* extractAggrArgTypes()
   18598             :  * As above, but work from the output of the aggr_args production.
   18599             :  */
   18600             : static List *
   18601         362 : extractAggrArgTypes(List *aggrargs)
   18602             : {
   18603             :     Assert(list_length(aggrargs) == 2);
   18604         362 :     return extractArgTypes((List *) linitial(aggrargs));
   18605             : }
   18606             : 
   18607             : /* makeOrderedSetArgs()
   18608             :  * Build the result of the aggr_args production (which see the comments for).
   18609             :  * This handles only the case where both given lists are nonempty, so that
   18610             :  * we have to deal with multiple VARIADIC arguments.
   18611             :  */
   18612             : static List *
   18613          32 : makeOrderedSetArgs(List *directargs, List *orderedargs,
   18614             :                    core_yyscan_t yyscanner)
   18615             : {
   18616          32 :     FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
   18617             :     Integer    *ndirectargs;
   18618             : 
   18619             :     /* No restriction unless last direct arg is VARIADIC */
   18620          32 :     if (lastd->mode == FUNC_PARAM_VARIADIC)
   18621             :     {
   18622          16 :         FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
   18623             : 
   18624             :         /*
   18625             :          * We ignore the names, though the aggr_arg production allows them;
   18626             :          * it doesn't allow default values, so those need not be checked.
   18627             :          */
   18628          16 :         if (list_length(orderedargs) != 1 ||
   18629          16 :             firsto->mode != FUNC_PARAM_VARIADIC ||
   18630          16 :             !equal(lastd->argType, firsto->argType))
   18631           0 :             ereport(ERROR,
   18632             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   18633             :                      errmsg("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
   18634             :                      parser_errposition(exprLocation((Node *) firsto))));
   18635             : 
   18636             :         /* OK, drop the duplicate VARIADIC argument from the internal form */
   18637          16 :         orderedargs = NIL;
   18638             :     }
   18639             : 
   18640             :     /* don't merge into the next line, as list_concat changes directargs */
   18641          32 :     ndirectargs = makeInteger(list_length(directargs));
   18642             : 
   18643          32 :     return list_make2(list_concat(directargs, orderedargs),
   18644             :                       ndirectargs);
   18645             : }
   18646             : 
   18647             : /* insertSelectOptions()
   18648             :  * Insert ORDER BY, etc into an already-constructed SelectStmt.
   18649             :  *
   18650             :  * This routine is just to avoid duplicating code in SelectStmt productions.
   18651             :  */
   18652             : static void
   18653       65776 : insertSelectOptions(SelectStmt *stmt,
   18654             :                     List *sortClause, List *lockingClause,
   18655             :                     SelectLimit *limitClause,
   18656             :                     WithClause *withClause,
   18657             :                     core_yyscan_t yyscanner)
   18658             : {
   18659             :     Assert(IsA(stmt, SelectStmt));
   18660             : 
   18661             :     /*
   18662             :      * Tests here are to reject constructs like
   18663             :      *  (SELECT foo ORDER BY bar) ORDER BY baz
   18664             :      */
   18665       65776 :     if (sortClause)
   18666             :     {
   18667       56922 :         if (stmt->sortClause)
   18668           0 :             ereport(ERROR,
   18669             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   18670             :                      errmsg("multiple ORDER BY clauses not allowed"),
   18671             :                      parser_errposition(exprLocation((Node *) sortClause))));
   18672       56922 :         stmt->sortClause = sortClause;
   18673             :     }
   18674             :     /* We can handle multiple locking clauses, though */
   18675       65776 :     stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
   18676       65776 :     if (limitClause && limitClause->limitOffset)
   18677             :     {
   18678         780 :         if (stmt->limitOffset)
   18679           0 :             ereport(ERROR,
   18680             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   18681             :                      errmsg("multiple OFFSET clauses not allowed"),
   18682             :                      parser_errposition(exprLocation(limitClause->limitOffset))));
   18683         780 :         stmt->limitOffset = limitClause->limitOffset;
   18684             :     }
   18685       65776 :     if (limitClause && limitClause->limitCount)
   18686             :     {
   18687        4490 :         if (stmt->limitCount)
   18688           0 :             ereport(ERROR,
   18689             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   18690             :                      errmsg("multiple LIMIT clauses not allowed"),
   18691             :                      parser_errposition(exprLocation(limitClause->limitCount))));
   18692        4490 :         stmt->limitCount = limitClause->limitCount;
   18693             :     }
   18694       65776 :     if (limitClause)
   18695             :     {
   18696        4888 :         if (stmt->limitOption)
   18697           0 :             ereport(ERROR,
   18698             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   18699             :                      errmsg("multiple limit options not allowed")));
   18700        4888 :         if (!stmt->sortClause && limitClause->limitOption == LIMIT_OPTION_WITH_TIES)
   18701           6 :             ereport(ERROR,
   18702             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   18703             :                      errmsg("WITH TIES cannot be specified without ORDER BY clause")));
   18704        4882 :         if (limitClause->limitOption == LIMIT_OPTION_WITH_TIES && stmt->lockingClause)
   18705             :         {
   18706             :             ListCell   *lc;
   18707             : 
   18708           6 :             foreach(lc, stmt->lockingClause)
   18709             :             {
   18710           6 :                 LockingClause *lock = lfirst_node(LockingClause, lc);
   18711             : 
   18712           6 :                 if (lock->waitPolicy == LockWaitSkip)
   18713           6 :                     ereport(ERROR,
   18714             :                             (errcode(ERRCODE_SYNTAX_ERROR),
   18715             :                              errmsg("%s and %s options cannot be used together",
   18716             :                                     "SKIP LOCKED", "WITH TIES")));
   18717             :             }
   18718             :         }
   18719        4876 :         stmt->limitOption = limitClause->limitOption;
   18720             :     }
   18721       65764 :     if (withClause)
   18722             :     {
   18723        2404 :         if (stmt->withClause)
   18724           0 :             ereport(ERROR,
   18725             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   18726             :                      errmsg("multiple WITH clauses not allowed"),
   18727             :                      parser_errposition(exprLocation((Node *) withClause))));
   18728        2404 :         stmt->withClause = withClause;
   18729             :     }
   18730       65764 : }
   18731             : 
   18732             : static Node *
   18733       13968 : makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
   18734             : {
   18735       13968 :     SelectStmt *n = makeNode(SelectStmt);
   18736             : 
   18737       13968 :     n->op = op;
   18738       13968 :     n->all = all;
   18739       13968 :     n->larg = (SelectStmt *) larg;
   18740       13968 :     n->rarg = (SelectStmt *) rarg;
   18741       13968 :     return (Node *) n;
   18742             : }
   18743             : 
   18744             : /* SystemFuncName()
   18745             :  * Build a properly-qualified reference to a built-in function.
   18746             :  */
   18747             : List *
   18748       16620 : SystemFuncName(char *name)
   18749             : {
   18750       16620 :     return list_make2(makeString("pg_catalog"), makeString(name));
   18751             : }
   18752             : 
   18753             : /* SystemTypeName()
   18754             :  * Build a properly-qualified reference to a built-in type.
   18755             :  *
   18756             :  * typmod is defaulted, but may be changed afterwards by caller.
   18757             :  * Likewise for the location.
   18758             :  */
   18759             : TypeName *
   18760       89252 : SystemTypeName(char *name)
   18761             : {
   18762       89252 :     return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
   18763             :                                                makeString(name)));
   18764             : }
   18765             : 
   18766             : /* doNegate()
   18767             :  * Handle negation of a numeric constant.
   18768             :  *
   18769             :  * Formerly, we did this here because the optimizer couldn't cope with
   18770             :  * indexquals that looked like "var = -4" --- it wants "var = const"
   18771             :  * and a unary minus operator applied to a constant didn't qualify.
   18772             :  * As of Postgres 7.0, that problem doesn't exist anymore because there
   18773             :  * is a constant-subexpression simplifier in the optimizer.  However,
   18774             :  * there's still a good reason for doing this here, which is that we can
   18775             :  * postpone committing to a particular internal representation for simple
   18776             :  * negative constants.  It's better to leave "-123.456" in string form
   18777             :  * until we know what the desired type is.
   18778             :  */
   18779             : static Node *
   18780       27114 : doNegate(Node *n, int location)
   18781             : {
   18782       27114 :     if (IsA(n, A_Const))
   18783             :     {
   18784       26184 :         A_Const    *con = (A_Const *) n;
   18785             : 
   18786             :         /* report the constant's location as that of the '-' sign */
   18787       26184 :         con->location = location;
   18788             : 
   18789       26184 :         if (IsA(&con->val, Integer))
   18790             :         {
   18791       25262 :             con->val.ival.ival = -con->val.ival.ival;
   18792       25262 :             return n;
   18793             :         }
   18794         922 :         if (IsA(&con->val, Float))
   18795             :         {
   18796         922 :             doNegateFloat(&con->val.fval);
   18797         922 :             return n;
   18798             :         }
   18799             :     }
   18800             : 
   18801         930 :     return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
   18802             : }
   18803             : 
   18804             : static void
   18805         942 : doNegateFloat(Float *v)
   18806             : {
   18807         942 :     char       *oldval = v->fval;
   18808             : 
   18809         942 :     if (*oldval == '+')
   18810           0 :         oldval++;
   18811         942 :     if (*oldval == '-')
   18812           0 :         v->fval = oldval+1;  /* just strip the '-' */
   18813             :     else
   18814         942 :         v->fval = psprintf("-%s", oldval);
   18815         942 : }
   18816             : 
   18817             : static Node *
   18818      197282 : makeAndExpr(Node *lexpr, Node *rexpr, int location)
   18819             : {
   18820             :     /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
   18821      197282 :     if (IsA(lexpr, BoolExpr))
   18822             :     {
   18823       92238 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   18824             : 
   18825       92238 :         if (blexpr->boolop == AND_EXPR)
   18826             :         {
   18827       89874 :             blexpr->args = lappend(blexpr->args, rexpr);
   18828       89874 :             return (Node *) blexpr;
   18829             :         }
   18830             :     }
   18831      107408 :     return (Node *) makeBoolExpr(AND_EXPR, list_make2(lexpr, rexpr), location);
   18832             : }
   18833             : 
   18834             : static Node *
   18835       14598 : makeOrExpr(Node *lexpr, Node *rexpr, int location)
   18836             : {
   18837             :     /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
   18838       14598 :     if (IsA(lexpr, BoolExpr))
   18839             :     {
   18840        6148 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   18841             : 
   18842        6148 :         if (blexpr->boolop == OR_EXPR)
   18843             :         {
   18844        3364 :             blexpr->args = lappend(blexpr->args, rexpr);
   18845        3364 :             return (Node *) blexpr;
   18846             :         }
   18847             :     }
   18848       11234 :     return (Node *) makeBoolExpr(OR_EXPR, list_make2(lexpr, rexpr), location);
   18849             : }
   18850             : 
   18851             : static Node *
   18852       13906 : makeNotExpr(Node *expr, int location)
   18853             : {
   18854       13906 :     return (Node *) makeBoolExpr(NOT_EXPR, list_make1(expr), location);
   18855             : }
   18856             : 
   18857             : static Node *
   18858        8098 : makeAArrayExpr(List *elements, int location)
   18859             : {
   18860        8098 :     A_ArrayExpr *n = makeNode(A_ArrayExpr);
   18861             : 
   18862        8098 :     n->elements = elements;
   18863        8098 :     n->location = location;
   18864        8098 :     return (Node *) n;
   18865             : }
   18866             : 
   18867             : static Node *
   18868        2388 : makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod, int location)
   18869             : {
   18870        2388 :     SQLValueFunction *svf = makeNode(SQLValueFunction);
   18871             : 
   18872        2388 :     svf->op = op;
   18873             :     /* svf->type will be filled during parse analysis */
   18874        2388 :     svf->typmod = typmod;
   18875        2388 :     svf->location = location;
   18876        2388 :     return (Node *) svf;
   18877             : }
   18878             : 
   18879             : static Node *
   18880         596 : makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
   18881             :             int location)
   18882             : {
   18883         596 :     XmlExpr     *x = makeNode(XmlExpr);
   18884             : 
   18885         596 :     x->op = op;
   18886         596 :     x->name = name;
   18887             :     /*
   18888             :      * named_args is a list of ResTarget; it'll be split apart into separate
   18889             :      * expression and name lists in transformXmlExpr().
   18890             :      */
   18891         596 :     x->named_args = named_args;
   18892         596 :     x->arg_names = NIL;
   18893         596 :     x->args = args;
   18894             :     /* xmloption, if relevant, must be filled in by caller */
   18895             :     /* type and typmod will be filled in during parse analysis */
   18896         596 :     x->type = InvalidOid;            /* marks the node as not analyzed */
   18897         596 :     x->location = location;
   18898         596 :     return (Node *) x;
   18899             : }
   18900             : 
   18901             : /*
   18902             :  * Merge the input and output parameters of a table function.
   18903             :  */
   18904             : static List *
   18905         188 : mergeTableFuncParameters(List *func_args, List *columns)
   18906             : {
   18907             :     ListCell   *lc;
   18908             : 
   18909             :     /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
   18910         382 :     foreach(lc, func_args)
   18911             :     {
   18912         194 :         FunctionParameter *p = (FunctionParameter *) lfirst(lc);
   18913             : 
   18914         194 :         if (p->mode != FUNC_PARAM_DEFAULT &&
   18915           0 :             p->mode != FUNC_PARAM_IN &&
   18916           0 :             p->mode != FUNC_PARAM_VARIADIC)
   18917           0 :             ereport(ERROR,
   18918             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   18919             :                      errmsg("OUT and INOUT arguments aren't allowed in TABLE functions")));
   18920             :     }
   18921             : 
   18922         188 :     return list_concat(func_args, columns);
   18923             : }
   18924             : 
   18925             : /*
   18926             :  * Determine return type of a TABLE function.  A single result column
   18927             :  * returns setof that column's type; otherwise return setof record.
   18928             :  */
   18929             : static TypeName *
   18930         188 : TableFuncTypeName(List *columns)
   18931             : {
   18932             :     TypeName   *result;
   18933             : 
   18934         188 :     if (list_length(columns) == 1)
   18935             :     {
   18936          62 :         FunctionParameter *p = (FunctionParameter *) linitial(columns);
   18937             : 
   18938          62 :         result = copyObject(p->argType);
   18939             :     }
   18940             :     else
   18941         126 :         result = SystemTypeName("record");
   18942             : 
   18943         188 :     result->setof = true;
   18944             : 
   18945         188 :     return result;
   18946             : }
   18947             : 
   18948             : /*
   18949             :  * Convert a list of (dotted) names to a RangeVar (like
   18950             :  * makeRangeVarFromNameList, but with position support).  The
   18951             :  * "AnyName" refers to the any_name production in the grammar.
   18952             :  */
   18953             : static RangeVar *
   18954         916 : makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
   18955             : {
   18956         916 :     RangeVar   *r = makeNode(RangeVar);
   18957             : 
   18958         916 :     switch (list_length(names))
   18959             :     {
   18960         834 :         case 1:
   18961         834 :             r->catalogname = NULL;
   18962         834 :             r->schemaname = NULL;
   18963         834 :             r->relname = strVal(linitial(names));
   18964         834 :             break;
   18965          82 :         case 2:
   18966          82 :             r->catalogname = NULL;
   18967          82 :             r->schemaname = strVal(linitial(names));
   18968          82 :             r->relname = strVal(lsecond(names));
   18969          82 :             break;
   18970           0 :         case 3:
   18971           0 :             r->catalogname = strVal(linitial(names));
   18972           0 :             r->schemaname = strVal(lsecond(names));
   18973           0 :             r->relname = strVal(lthird(names));
   18974           0 :             break;
   18975           0 :         default:
   18976           0 :             ereport(ERROR,
   18977             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   18978             :                      errmsg("improper qualified name (too many dotted names): %s",
   18979             :                             NameListToString(names)),
   18980             :                      parser_errposition(position)));
   18981             :             break;
   18982             :     }
   18983             : 
   18984         916 :     r->relpersistence = RELPERSISTENCE_PERMANENT;
   18985         916 :     r->location = position;
   18986             : 
   18987         916 :     return r;
   18988             : }
   18989             : 
   18990             : /*
   18991             :  * Convert a relation_name with name and namelist to a RangeVar using
   18992             :  * makeRangeVar.
   18993             :  */
   18994             : static RangeVar *
   18995      213806 : makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
   18996             :                               core_yyscan_t yyscanner)
   18997             : {
   18998             :     RangeVar   *r;
   18999             : 
   19000      213806 :     check_qualified_name(namelist, yyscanner);
   19001      213806 :     r = makeRangeVar(NULL, NULL, location);
   19002             : 
   19003      213806 :     switch (list_length(namelist))
   19004             :     {
   19005      213806 :         case 1:
   19006      213806 :             r->catalogname = NULL;
   19007      213806 :             r->schemaname = name;
   19008      213806 :             r->relname = strVal(linitial(namelist));
   19009      213806 :             break;
   19010           0 :         case 2:
   19011           0 :             r->catalogname = name;
   19012           0 :             r->schemaname = strVal(linitial(namelist));
   19013           0 :             r->relname = strVal(lsecond(namelist));
   19014           0 :             break;
   19015           0 :         default:
   19016           0 :             ereport(ERROR,
   19017             :                     errcode(ERRCODE_SYNTAX_ERROR),
   19018             :                     errmsg("improper qualified name (too many dotted names): %s",
   19019             :                            NameListToString(lcons(makeString(name), namelist))),
   19020             :                            parser_errposition(location));
   19021             :             break;
   19022             :     }
   19023             : 
   19024      213806 :     return r;
   19025             : }
   19026             : 
   19027             : /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
   19028             : static void
   19029       63108 : SplitColQualList(List *qualList,
   19030             :                  List **constraintList, CollateClause **collClause,
   19031             :                  core_yyscan_t yyscanner)
   19032             : {
   19033             :     ListCell   *cell;
   19034             : 
   19035       63108 :     *collClause = NULL;
   19036       79940 :     foreach(cell, qualList)
   19037             :     {
   19038       16832 :         Node       *n = (Node *) lfirst(cell);
   19039             : 
   19040       16832 :         if (IsA(n, Constraint))
   19041             :         {
   19042             :             /* keep it in list */
   19043       16218 :             continue;
   19044             :         }
   19045         614 :         if (IsA(n, CollateClause))
   19046             :         {
   19047         614 :             CollateClause *c = (CollateClause *) n;
   19048             : 
   19049         614 :             if (*collClause)
   19050           0 :                 ereport(ERROR,
   19051             :                         (errcode(ERRCODE_SYNTAX_ERROR),
   19052             :                          errmsg("multiple COLLATE clauses not allowed"),
   19053             :                          parser_errposition(c->location)));
   19054         614 :             *collClause = c;
   19055             :         }
   19056             :         else
   19057           0 :             elog(ERROR, "unexpected node type %d", (int) n->type);
   19058             :         /* remove non-Constraint nodes from qualList */
   19059         614 :         qualList = foreach_delete_current(qualList, cell);
   19060             :     }
   19061       63108 :     *constraintList = qualList;
   19062       63108 : }
   19063             : 
   19064             : /*
   19065             :  * Process result of ConstraintAttributeSpec, and set appropriate bool flags
   19066             :  * in the output command node.  Pass NULL for any flags the particular
   19067             :  * command doesn't support.
   19068             :  */
   19069             : static void
   19070       14354 : processCASbits(int cas_bits, int location, const char *constrType,
   19071             :                bool *deferrable, bool *initdeferred, bool *not_valid,
   19072             :                bool *no_inherit, core_yyscan_t yyscanner)
   19073             : {
   19074             :     /* defaults */
   19075       14354 :     if (deferrable)
   19076       13002 :         *deferrable = false;
   19077       14354 :     if (initdeferred)
   19078       13002 :         *initdeferred = false;
   19079       14354 :     if (not_valid)
   19080        2902 :         *not_valid = false;
   19081             : 
   19082       14354 :     if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
   19083             :     {
   19084         246 :         if (deferrable)
   19085         246 :             *deferrable = true;
   19086             :         else
   19087           0 :             ereport(ERROR,
   19088             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19089             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19090             :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   19091             :                             constrType),
   19092             :                      parser_errposition(location)));
   19093             :     }
   19094             : 
   19095       14354 :     if (cas_bits & CAS_INITIALLY_DEFERRED)
   19096             :     {
   19097         156 :         if (initdeferred)
   19098         156 :             *initdeferred = true;
   19099             :         else
   19100           0 :             ereport(ERROR,
   19101             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19102             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19103             :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   19104             :                             constrType),
   19105             :                      parser_errposition(location)));
   19106             :     }
   19107             : 
   19108       14354 :     if (cas_bits & CAS_NOT_VALID)
   19109             :     {
   19110         516 :         if (not_valid)
   19111         516 :             *not_valid = true;
   19112             :         else
   19113           0 :             ereport(ERROR,
   19114             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19115             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19116             :                      errmsg("%s constraints cannot be marked NOT VALID",
   19117             :                             constrType),
   19118             :                      parser_errposition(location)));
   19119             :     }
   19120             : 
   19121       14354 :     if (cas_bits & CAS_NO_INHERIT)
   19122             :     {
   19123         142 :         if (no_inherit)
   19124         142 :             *no_inherit = true;
   19125             :         else
   19126           0 :             ereport(ERROR,
   19127             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19128             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19129             :                      errmsg("%s constraints cannot be marked NO INHERIT",
   19130             :                             constrType),
   19131             :                      parser_errposition(location)));
   19132             :     }
   19133       14354 : }
   19134             : 
   19135             : /*
   19136             :  * Parse a user-supplied partition strategy string into parse node
   19137             :  * PartitionStrategy representation, or die trying.
   19138             :  */
   19139             : static PartitionStrategy
   19140        4630 : parsePartitionStrategy(char *strategy)
   19141             : {
   19142        4630 :     if (pg_strcasecmp(strategy, "list") == 0)
   19143        2312 :         return PARTITION_STRATEGY_LIST;
   19144        2318 :     else if (pg_strcasecmp(strategy, "range") == 0)
   19145        2084 :         return PARTITION_STRATEGY_RANGE;
   19146         234 :     else if (pg_strcasecmp(strategy, "hash") == 0)
   19147         228 :         return PARTITION_STRATEGY_HASH;
   19148             : 
   19149           6 :     ereport(ERROR,
   19150             :             (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   19151             :              errmsg("unrecognized partitioning strategy \"%s\"",
   19152             :                     strategy)));
   19153             :     return PARTITION_STRATEGY_LIST;     /* keep compiler quiet */
   19154             : 
   19155             : }
   19156             : 
   19157             : /*
   19158             :  * Process pubobjspec_list to check for errors in any of the objects and
   19159             :  * convert PUBLICATIONOBJ_CONTINUATION into appropriate PublicationObjSpecType.
   19160             :  */
   19161             : static void
   19162        1470 : preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
   19163             : {
   19164             :     ListCell   *cell;
   19165             :     PublicationObjSpec *pubobj;
   19166        1470 :     PublicationObjSpecType prevobjtype = PUBLICATIONOBJ_CONTINUATION;
   19167             : 
   19168        1470 :     if (!pubobjspec_list)
   19169           0 :         return;
   19170             : 
   19171        1470 :     pubobj = (PublicationObjSpec *) linitial(pubobjspec_list);
   19172        1470 :     if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   19173          12 :         ereport(ERROR,
   19174             :                 errcode(ERRCODE_SYNTAX_ERROR),
   19175             :                 errmsg("invalid publication object list"),
   19176             :                 errdetail("One of TABLE or TABLES IN SCHEMA must be specified before a standalone table or schema name."),
   19177             :                 parser_errposition(pubobj->location));
   19178             : 
   19179        3116 :     foreach(cell, pubobjspec_list)
   19180             :     {
   19181        1682 :         pubobj = (PublicationObjSpec *) lfirst(cell);
   19182             : 
   19183        1682 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   19184         174 :             pubobj->pubobjtype = prevobjtype;
   19185             : 
   19186        1682 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE)
   19187             :         {
   19188             :             /* relation name or pubtable must be set for this type of object */
   19189        1278 :             if (!pubobj->name && !pubobj->pubtable)
   19190           6 :                 ereport(ERROR,
   19191             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19192             :                         errmsg("invalid table name"),
   19193             :                         parser_errposition(pubobj->location));
   19194             : 
   19195        1272 :             if (pubobj->name)
   19196             :             {
   19197             :                 /* convert it to PublicationTable */
   19198          58 :                 PublicationTable *pubtable = makeNode(PublicationTable);
   19199             : 
   19200          58 :                 pubtable->relation =
   19201          58 :                     makeRangeVar(NULL, pubobj->name, pubobj->location);
   19202          58 :                 pubobj->pubtable = pubtable;
   19203          58 :                 pubobj->name = NULL;
   19204             :             }
   19205             :         }
   19206         404 :         else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
   19207          24 :                  pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA)
   19208             :         {
   19209             :             /* WHERE clause is not allowed on a schema object */
   19210         404 :             if (pubobj->pubtable && pubobj->pubtable->whereClause)
   19211           6 :                 ereport(ERROR,
   19212             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19213             :                         errmsg("WHERE clause not allowed for schema"),
   19214             :                         parser_errposition(pubobj->location));
   19215             : 
   19216             :             /* Column list is not allowed on a schema object */
   19217         398 :             if (pubobj->pubtable && pubobj->pubtable->columns)
   19218           6 :                 ereport(ERROR,
   19219             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19220             :                         errmsg("column specification not allowed for schema"),
   19221             :                         parser_errposition(pubobj->location));
   19222             : 
   19223             :             /*
   19224             :              * We can distinguish between the different type of schema
   19225             :              * objects based on whether name and pubtable is set.
   19226             :              */
   19227         392 :             if (pubobj->name)
   19228         362 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   19229          30 :             else if (!pubobj->name && !pubobj->pubtable)
   19230          24 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   19231             :             else
   19232           6 :                 ereport(ERROR,
   19233             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19234             :                         errmsg("invalid schema name"),
   19235             :                         parser_errposition(pubobj->location));
   19236             :         }
   19237             : 
   19238        1658 :         prevobjtype = pubobj->pubobjtype;
   19239             :     }
   19240             : }
   19241             : 
   19242             : /*----------
   19243             :  * Recursive view transformation
   19244             :  *
   19245             :  * Convert
   19246             :  *
   19247             :  *     CREATE RECURSIVE VIEW relname (aliases) AS query
   19248             :  *
   19249             :  * to
   19250             :  *
   19251             :  *     CREATE VIEW relname (aliases) AS
   19252             :  *         WITH RECURSIVE relname (aliases) AS (query)
   19253             :  *         SELECT aliases FROM relname
   19254             :  *
   19255             :  * Actually, just the WITH ... part, which is then inserted into the original
   19256             :  * view definition as the query.
   19257             :  * ----------
   19258             :  */
   19259             : static Node *
   19260          14 : makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
   19261             : {
   19262          14 :     SelectStmt *s = makeNode(SelectStmt);
   19263          14 :     WithClause *w = makeNode(WithClause);
   19264          14 :     CommonTableExpr *cte = makeNode(CommonTableExpr);
   19265          14 :     List       *tl = NIL;
   19266             :     ListCell   *lc;
   19267             : 
   19268             :     /* create common table expression */
   19269          14 :     cte->ctename = relname;
   19270          14 :     cte->aliascolnames = aliases;
   19271          14 :     cte->ctematerialized = CTEMaterializeDefault;
   19272          14 :     cte->ctequery = query;
   19273          14 :     cte->location = -1;
   19274             : 
   19275             :     /* create WITH clause and attach CTE */
   19276          14 :     w->recursive = true;
   19277          14 :     w->ctes = list_make1(cte);
   19278          14 :     w->location = -1;
   19279             : 
   19280             :     /* create target list for the new SELECT from the alias list of the
   19281             :      * recursive view specification */
   19282          28 :     foreach (lc, aliases)
   19283             :     {
   19284          14 :         ResTarget *rt = makeNode(ResTarget);
   19285             : 
   19286          14 :         rt->name = NULL;
   19287          14 :         rt->indirection = NIL;
   19288          14 :         rt->val = makeColumnRef(strVal(lfirst(lc)), NIL, -1, 0);
   19289          14 :         rt->location = -1;
   19290             : 
   19291          14 :         tl = lappend(tl, rt);
   19292             :     }
   19293             : 
   19294             :     /* create new SELECT combining WITH clause, target list, and fake FROM
   19295             :      * clause */
   19296          14 :     s->withClause = w;
   19297          14 :     s->targetList = tl;
   19298          14 :     s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));
   19299             : 
   19300          14 :     return (Node *) s;
   19301             : }
   19302             : 
   19303             : /* parser_init()
   19304             :  * Initialize to parse one query string
   19305             :  */
   19306             : void
   19307      716774 : parser_init(base_yy_extra_type *yyext)
   19308             : {
   19309      716774 :     yyext->parsetree = NIL;      /* in case grammar forgets to set it */
   19310      716774 : }

Generated by: LCOV version 1.14