LCOV - code coverage report
Current view: top level - src/backend/parser - gram.y (source / functions) Hit Total Coverage
Test: PostgreSQL 19devel Lines: 6827 7532 90.6 %
Date: 2025-10-24 12:17:48 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-2025, 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 "catalog/index.h"
      52             : #include "catalog/namespace.h"
      53             : #include "catalog/pg_am.h"
      54             : #include "catalog/pg_trigger.h"
      55             : #include "commands/defrem.h"
      56             : #include "commands/trigger.h"
      57             : #include "gramparse.h"
      58             : #include "nodes/makefuncs.h"
      59             : #include "nodes/nodeFuncs.h"
      60             : #include "parser/parser.h"
      61             : #include "utils/datetime.h"
      62             : #include "utils/xml.h"
      63             : 
      64             : 
      65             : /*
      66             :  * Location tracking support.  Unlike bison's default, we only want
      67             :  * to track the start position not the end position of each nonterminal.
      68             :  * Nonterminals that reduce to empty receive position "-1".  Since a
      69             :  * production's leading RHS nonterminal(s) may have reduced to empty,
      70             :  * we have to scan to find the first one that's not -1.
      71             :  */
      72             : #define YYLLOC_DEFAULT(Current, Rhs, N) \
      73             :     do { \
      74             :         (Current) = (-1); \
      75             :         for (int _i = 1; _i <= (N); _i++) \
      76             :         { \
      77             :             if ((Rhs)[_i] >= 0) \
      78             :             { \
      79             :                 (Current) = (Rhs)[_i]; \
      80             :                 break; \
      81             :             } \
      82             :         } \
      83             :     } while (0)
      84             : 
      85             : /*
      86             :  * Bison doesn't allocate anything that needs to live across parser calls,
      87             :  * so we can easily have it use palloc instead of malloc.  This prevents
      88             :  * memory leaks if we error out during parsing.
      89             :  */
      90             : #define YYMALLOC palloc
      91             : #define YYFREE   pfree
      92             : 
      93             : /* Private struct for the result of privilege_target production */
      94             : typedef struct PrivTarget
      95             : {
      96             :     GrantTargetType targtype;
      97             :     ObjectType  objtype;
      98             :     List       *objs;
      99             : } PrivTarget;
     100             : 
     101             : /* Private struct for the result of import_qualification production */
     102             : typedef struct ImportQual
     103             : {
     104             :     ImportForeignSchemaType type;
     105             :     List       *table_names;
     106             : } ImportQual;
     107             : 
     108             : /* Private struct for the result of select_limit & limit_clause productions */
     109             : typedef struct SelectLimit
     110             : {
     111             :     Node       *limitOffset;
     112             :     Node       *limitCount;
     113             :     LimitOption limitOption;    /* indicates presence of WITH TIES */
     114             :     ParseLoc    offsetLoc;      /* location of OFFSET token, if present */
     115             :     ParseLoc    countLoc;       /* location of LIMIT/FETCH token, if present */
     116             :     ParseLoc    optionLoc;      /* location of WITH TIES, if present */
     117             : } SelectLimit;
     118             : 
     119             : /* Private struct for the result of group_clause production */
     120             : typedef struct GroupClause
     121             : {
     122             :     bool        distinct;
     123             :     bool        all;
     124             :     List       *list;
     125             : } GroupClause;
     126             : 
     127             : /* Private structs for the result of key_actions and key_action productions */
     128             : typedef struct KeyAction
     129             : {
     130             :     char        action;
     131             :     List       *cols;
     132             : } KeyAction;
     133             : 
     134             : typedef struct KeyActions
     135             : {
     136             :     KeyAction *updateAction;
     137             :     KeyAction *deleteAction;
     138             : } KeyActions;
     139             : 
     140             : /* ConstraintAttributeSpec yields an integer bitmask of these flags: */
     141             : #define CAS_NOT_DEFERRABLE          0x01
     142             : #define CAS_DEFERRABLE              0x02
     143             : #define CAS_INITIALLY_IMMEDIATE     0x04
     144             : #define CAS_INITIALLY_DEFERRED      0x08
     145             : #define CAS_NOT_VALID               0x10
     146             : #define CAS_NO_INHERIT              0x20
     147             : #define CAS_NOT_ENFORCED            0x40
     148             : #define CAS_ENFORCED                0x80
     149             : 
     150             : 
     151             : #define parser_yyerror(msg)  scanner_yyerror(msg, yyscanner)
     152             : #define parser_errposition(pos)  scanner_errposition(pos, yyscanner)
     153             : 
     154             : static void base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner,
     155             :                          const char *msg);
     156             : static RawStmt *makeRawStmt(Node *stmt, int stmt_location);
     157             : static void updateRawStmtEnd(RawStmt *rs, int end_location);
     158             : static Node *makeColumnRef(char *colname, List *indirection,
     159             :                            int location, core_yyscan_t yyscanner);
     160             : static Node *makeTypeCast(Node *arg, TypeName *typename, int location);
     161             : static Node *makeStringConstCast(char *str, int location, TypeName *typename);
     162             : static Node *makeIntConst(int val, int location);
     163             : static Node *makeFloatConst(char *str, int location);
     164             : static Node *makeBoolAConst(bool state, int location);
     165             : static Node *makeBitStringConst(char *str, int location);
     166             : static Node *makeNullAConst(int location);
     167             : static Node *makeAConst(Node *v, int location);
     168             : static RoleSpec *makeRoleSpec(RoleSpecType type, int location);
     169             : static void check_qualified_name(List *names, core_yyscan_t yyscanner);
     170             : static List *check_func_name(List *names, core_yyscan_t yyscanner);
     171             : static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
     172             : static List *extractArgTypes(List *parameters);
     173             : static List *extractAggrArgTypes(List *aggrargs);
     174             : static List *makeOrderedSetArgs(List *directargs, List *orderedargs,
     175             :                                 core_yyscan_t yyscanner);
     176             : static void insertSelectOptions(SelectStmt *stmt,
     177             :                                 List *sortClause, List *lockingClause,
     178             :                                 SelectLimit *limitClause,
     179             :                                 WithClause *withClause,
     180             :                                 core_yyscan_t yyscanner);
     181             : static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
     182             : static Node *doNegate(Node *n, int location);
     183             : static void doNegateFloat(Float *v);
     184             : static Node *makeAndExpr(Node *lexpr, Node *rexpr, int location);
     185             : static Node *makeOrExpr(Node *lexpr, Node *rexpr, int location);
     186             : static Node *makeNotExpr(Node *expr, int location);
     187             : static Node *makeAArrayExpr(List *elements, int location, int end_location);
     188             : static Node *makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod,
     189             :                                   int location);
     190             : static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
     191             :                          List *args, int location);
     192             : static List *mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner);
     193             : static TypeName *TableFuncTypeName(List *columns);
     194             : static RangeVar *makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner);
     195             : static RangeVar *makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
     196             :                                                core_yyscan_t yyscanner);
     197             : static void SplitColQualList(List *qualList,
     198             :                              List **constraintList, CollateClause **collClause,
     199             :                              core_yyscan_t yyscanner);
     200             : static void processCASbits(int cas_bits, int location, const char *constrType,
     201             :                bool *deferrable, bool *initdeferred, bool *is_enforced,
     202             :                bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner);
     203             : static PartitionStrategy parsePartitionStrategy(char *strategy, int location,
     204             :                                                 core_yyscan_t yyscanner);
     205             : static void preprocess_pub_all_objtype_list(List *all_objects_list,
     206             :                                             bool *all_tables,
     207             :                                             bool *all_sequences,
     208             :                                             core_yyscan_t yyscanner);
     209             : static void preprocess_pubobj_list(List *pubobjspec_list,
     210             :                                    core_yyscan_t yyscanner);
     211             : static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
     212             : 
     213             : %}
     214             : 
     215             : %pure-parser
     216             : %expect 0
     217             : %name-prefix="base_yy"
     218             : %locations
     219             : 
     220             : %parse-param {core_yyscan_t yyscanner}
     221             : %lex-param   {core_yyscan_t yyscanner}
     222             : 
     223             : %union
     224             : {
     225             :     core_YYSTYPE core_yystype;
     226             :     /* these fields must match core_YYSTYPE: */
     227             :     int         ival;
     228             :     char       *str;
     229             :     const char *keyword;
     230             : 
     231             :     char        chr;
     232             :     bool        boolean;
     233             :     JoinType    jtype;
     234             :     DropBehavior dbehavior;
     235             :     OnCommitAction oncommit;
     236             :     List       *list;
     237             :     Node       *node;
     238             :     ObjectType  objtype;
     239             :     TypeName   *typnam;
     240             :     FunctionParameter *fun_param;
     241             :     FunctionParameterMode fun_param_mode;
     242             :     ObjectWithArgs *objwithargs;
     243             :     DefElem    *defelt;
     244             :     SortBy     *sortby;
     245             :     WindowDef  *windef;
     246             :     JoinExpr   *jexpr;
     247             :     IndexElem  *ielem;
     248             :     StatsElem  *selem;
     249             :     Alias      *alias;
     250             :     RangeVar   *range;
     251             :     IntoClause *into;
     252             :     WithClause *with;
     253             :     InferClause *infer;
     254             :     OnConflictClause *onconflict;
     255             :     A_Indices  *aind;
     256             :     ResTarget  *target;
     257             :     struct PrivTarget *privtarget;
     258             :     AccessPriv *accesspriv;
     259             :     struct ImportQual *importqual;
     260             :     InsertStmt *istmt;
     261             :     VariableSetStmt *vsetstmt;
     262             :     PartitionElem *partelem;
     263             :     PartitionSpec *partspec;
     264             :     PartitionBoundSpec *partboundspec;
     265             :     RoleSpec   *rolespec;
     266             :     PublicationObjSpec *publicationobjectspec;
     267             :     PublicationAllObjSpec *publicationallobjectspec;
     268             :     struct SelectLimit *selectlimit;
     269             :     SetQuantifier setquantifier;
     270             :     struct GroupClause *groupclause;
     271             :     MergeMatchKind mergematch;
     272             :     MergeWhenClause *mergewhen;
     273             :     struct KeyActions *keyactions;
     274             :     struct KeyAction *keyaction;
     275             :     ReturningClause *retclause;
     276             :     ReturningOptionKind retoptionkind;
     277             : }
     278             : 
     279             : %type <node>  stmt toplevel_stmt schema_stmt routine_body_stmt
     280             :         AlterEventTrigStmt AlterCollationStmt
     281             :         AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt
     282             :         AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
     283             :         AlterObjectDependsStmt AlterObjectSchemaStmt AlterOwnerStmt
     284             :         AlterOperatorStmt AlterTypeStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
     285             :         AlterTblSpcStmt AlterExtensionStmt AlterExtensionContentsStmt
     286             :         AlterCompositeTypeStmt AlterUserMappingStmt
     287             :         AlterRoleStmt AlterRoleSetStmt AlterPolicyStmt AlterStatsStmt
     288             :         AlterDefaultPrivilegesStmt DefACLAction
     289             :         AnalyzeStmt CallStmt ClosePortalStmt ClusterStmt CommentStmt
     290             :         ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
     291             :         CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt
     292             :         CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
     293             :         CreateSchemaStmt CreateSeqStmt CreateStmt CreateStatsStmt CreateTableSpaceStmt
     294             :         CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt
     295             :         CreateAssertionStmt CreateTransformStmt CreateTrigStmt CreateEventTrigStmt
     296             :         CreateUserStmt CreateUserMappingStmt CreateRoleStmt CreatePolicyStmt
     297             :         CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
     298             :         DropOpClassStmt DropOpFamilyStmt DropStmt
     299             :         DropCastStmt DropRoleStmt
     300             :         DropdbStmt DropTableSpaceStmt
     301             :         DropTransformStmt
     302             :         DropUserMappingStmt ExplainStmt FetchStmt
     303             :         GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
     304             :         ListenStmt LoadStmt LockStmt MergeStmt NotifyStmt ExplainableStmt PreparableStmt
     305             :         CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
     306             :         RemoveFuncStmt RemoveOperStmt RenameStmt ReturnStmt RevokeStmt RevokeRoleStmt
     307             :         RuleActionStmt RuleActionStmtOrEmpty RuleStmt
     308             :         SecLabelStmt SelectStmt TransactionStmt TransactionStmtLegacy TruncateStmt
     309             :         UnlistenStmt UpdateStmt VacuumStmt
     310             :         VariableResetStmt VariableSetStmt VariableShowStmt
     311             :         ViewStmt CheckPointStmt CreateConversionStmt
     312             :         DeallocateStmt PrepareStmt ExecuteStmt
     313             :         DropOwnedStmt ReassignOwnedStmt
     314             :         AlterTSConfigurationStmt AlterTSDictionaryStmt
     315             :         CreateMatViewStmt RefreshMatViewStmt CreateAmStmt
     316             :         CreatePublicationStmt AlterPublicationStmt
     317             :         CreateSubscriptionStmt AlterSubscriptionStmt DropSubscriptionStmt
     318             : 
     319             : %type <node>  select_no_parens select_with_parens select_clause
     320             :                 simple_select values_clause
     321             :                 PLpgSQL_Expr PLAssignStmt
     322             : 
     323             : %type <str>           opt_single_name
     324             : %type <list>      opt_qualified_name
     325             : %type <boolean>       opt_concurrently
     326             : %type <dbehavior> opt_drop_behavior
     327             : %type <list>      opt_utility_option_list
     328             : %type <list>      utility_option_list
     329             : %type <defelt>        utility_option_elem
     330             : %type <str>           utility_option_name
     331             : %type <node>      utility_option_arg
     332             : 
     333             : %type <node>  alter_column_default opclass_item opclass_drop alter_using
     334             : %type <ival>  add_drop opt_asc_desc opt_nulls_order
     335             : 
     336             : %type <node>  alter_table_cmd alter_type_cmd opt_collate_clause
     337             :        replica_identity partition_cmd index_partition_cmd
     338             : %type <list>  alter_table_cmds alter_type_cmds
     339             : %type <list>    alter_identity_column_option_list
     340             : %type <defelt>  alter_identity_column_option
     341             : %type <node>  set_statistics_value
     342             : %type <str>       set_access_method_name
     343             : 
     344             : %type <list>  createdb_opt_list createdb_opt_items copy_opt_list
     345             :                 transaction_mode_list
     346             :                 create_extension_opt_list alter_extension_opt_list
     347             : %type <defelt>    createdb_opt_item copy_opt_item
     348             :                 transaction_mode_item
     349             :                 create_extension_opt_item alter_extension_opt_item
     350             : 
     351             : %type <ival>  opt_lock lock_type cast_context
     352             : %type <defelt>    drop_option
     353             : %type <boolean>   opt_or_replace opt_no
     354             :                 opt_grant_grant_option
     355             :                 opt_nowait opt_if_exists opt_with_data
     356             :                 opt_transaction_chain
     357             : %type <list>  grant_role_opt_list
     358             : %type <defelt>    grant_role_opt
     359             : %type <node>  grant_role_opt_value
     360             : %type <ival>  opt_nowait_or_skip
     361             : 
     362             : %type <list>  OptRoleList AlterOptRoleList
     363             : %type <defelt>    CreateOptRoleElem AlterOptRoleElem
     364             : 
     365             : %type <str>       opt_type
     366             : %type <str>       foreign_server_version opt_foreign_server_version
     367             : %type <str>       opt_in_database
     368             : 
     369             : %type <str>       parameter_name
     370             : %type <list>  OptSchemaEltList parameter_name_list
     371             : 
     372             : %type <chr>       am_type
     373             : 
     374             : %type <boolean> TriggerForSpec TriggerForType
     375             : %type <ival>  TriggerActionTime
     376             : %type <list>  TriggerEvents TriggerOneEvent
     377             : %type <node>  TriggerFuncArg
     378             : %type <node>  TriggerWhen
     379             : %type <str>       TransitionRelName
     380             : %type <boolean>   TransitionRowOrTable TransitionOldOrNew
     381             : %type <node>  TriggerTransition
     382             : 
     383             : %type <list>  event_trigger_when_list event_trigger_value_list
     384             : %type <defelt>    event_trigger_when_item
     385             : %type <chr>       enable_trigger
     386             : 
     387             : %type <str>       copy_file_name
     388             :                 access_method_clause attr_name
     389             :                 table_access_method_clause name cursor_name file_name
     390             :                 cluster_index_specification
     391             : 
     392             : %type <list>  func_name handler_name qual_Op qual_all_Op subquery_Op
     393             :                 opt_inline_handler opt_validator validator_clause
     394             :                 opt_collate
     395             : 
     396             : %type <range> qualified_name insert_target OptConstrFromTable
     397             : 
     398             : %type <str>       all_Op MathOp
     399             : 
     400             : %type <str>       row_security_cmd RowSecurityDefaultForCmd
     401             : %type <boolean> RowSecurityDefaultPermissive
     402             : %type <node>  RowSecurityOptionalWithCheck RowSecurityOptionalExpr
     403             : %type <list>  RowSecurityDefaultToRole RowSecurityOptionalToRole
     404             : 
     405             : %type <str>       iso_level opt_encoding
     406             : %type <rolespec> grantee
     407             : %type <list>  grantee_list
     408             : %type <accesspriv> privilege
     409             : %type <list>  privileges privilege_list
     410             : %type <privtarget> privilege_target
     411             : %type <objwithargs> function_with_argtypes aggregate_with_argtypes operator_with_argtypes
     412             : %type <list>  function_with_argtypes_list aggregate_with_argtypes_list operator_with_argtypes_list
     413             : %type <ival>  defacl_privilege_target
     414             : %type <defelt>    DefACLOption
     415             : %type <list>  DefACLOptionList
     416             : %type <ival>  import_qualification_type
     417             : %type <importqual> import_qualification
     418             : %type <node>  vacuum_relation
     419             : %type <selectlimit> opt_select_limit select_limit limit_clause
     420             : 
     421             : %type <list>  parse_toplevel stmtmulti routine_body_stmt_list
     422             :                 OptTableElementList TableElementList OptInherit definition
     423             :                 OptTypedTableElementList TypedTableElementList
     424             :                 reloptions opt_reloptions
     425             :                 OptWith opt_definition func_args func_args_list
     426             :                 func_args_with_defaults func_args_with_defaults_list
     427             :                 aggr_args aggr_args_list
     428             :                 func_as createfunc_opt_list opt_createfunc_opt_list alterfunc_opt_list
     429             :                 old_aggr_definition old_aggr_list
     430             :                 oper_argtypes RuleActionList RuleActionMulti
     431             :                 opt_column_list columnList opt_name_list
     432             :                 sort_clause opt_sort_clause sortby_list index_params
     433             :                 stats_params
     434             :                 opt_include opt_c_include index_including_params
     435             :                 name_list role_list from_clause from_list opt_array_bounds
     436             :                 qualified_name_list any_name any_name_list type_name_list
     437             :                 any_operator expr_list attrs
     438             :                 distinct_clause opt_distinct_clause
     439             :                 target_list opt_target_list insert_column_list set_target_list
     440             :                 merge_values_clause
     441             :                 set_clause_list set_clause
     442             :                 def_list operator_def_list indirection opt_indirection
     443             :                 reloption_list TriggerFuncArgs opclass_item_list opclass_drop_list
     444             :                 opclass_purpose opt_opfamily transaction_mode_list_or_empty
     445             :                 OptTableFuncElementList TableFuncElementList opt_type_modifiers
     446             :                 prep_type_clause
     447             :                 execute_param_clause using_clause
     448             :                 returning_with_clause returning_options
     449             :                 opt_enum_val_list enum_val_list table_func_column_list
     450             :                 create_generic_options alter_generic_options
     451             :                 relation_expr_list dostmt_opt_list
     452             :                 transform_element_list transform_type_list
     453             :                 TriggerTransitions TriggerReferencing
     454             :                 vacuum_relation_list opt_vacuum_relation_list
     455             :                 drop_option_list pub_obj_list pub_obj_type_list
     456             : 
     457             : %type <retclause> returning_clause
     458             : %type <node>  returning_option
     459             : %type <retoptionkind> returning_option_kind
     460             : %type <node>  opt_routine_body
     461             : %type <groupclause> group_clause
     462             : %type <list>  group_by_list
     463             : %type <node>  group_by_item empty_grouping_set rollup_clause cube_clause
     464             : %type <node>  grouping_sets_clause
     465             : 
     466             : %type <list>  opt_fdw_options fdw_options
     467             : %type <defelt>    fdw_option
     468             : 
     469             : %type <range> OptTempTableName
     470             : %type <into>  into_clause create_as_target create_mv_target
     471             : 
     472             : %type <defelt>    createfunc_opt_item common_func_opt_item dostmt_opt_item
     473             : %type <fun_param> func_arg func_arg_with_default table_func_column aggr_arg
     474             : %type <fun_param_mode> arg_class
     475             : %type <typnam>    func_return func_type
     476             : 
     477             : %type <boolean>  opt_trusted opt_restart_seqs
     478             : %type <ival>   OptTemp
     479             : %type <ival>   OptNoLog
     480             : %type <oncommit> OnCommitOption
     481             : 
     482             : %type <ival>  for_locking_strength
     483             : %type <node>  for_locking_item
     484             : %type <list>  for_locking_clause opt_for_locking_clause for_locking_items
     485             : %type <list>  locked_rels_list
     486             : %type <setquantifier> set_quantifier
     487             : 
     488             : %type <node>  join_qual
     489             : %type <jtype> join_type
     490             : 
     491             : %type <list>  extract_list overlay_list position_list
     492             : %type <list>  substr_list trim_list
     493             : %type <list>  opt_interval interval_second
     494             : %type <str>       unicode_normal_form
     495             : 
     496             : %type <boolean> opt_instead
     497             : %type <boolean> opt_unique opt_verbose opt_full
     498             : %type <boolean> opt_freeze opt_analyze opt_default
     499             : %type <defelt>    opt_binary copy_delimiter
     500             : 
     501             : %type <boolean> copy_from opt_program
     502             : 
     503             : %type <ival>  event cursor_options opt_hold opt_set_data
     504             : %type <objtype>   object_type_any_name object_type_name object_type_name_on_any_name
     505             :                 drop_type_name
     506             : 
     507             : %type <node>  fetch_args select_limit_value
     508             :                 offset_clause select_offset_value
     509             :                 select_fetch_first_value I_or_F_const
     510             : %type <ival>  row_or_rows first_or_next
     511             : 
     512             : %type <list>  OptSeqOptList SeqOptList OptParenthesizedSeqOptList
     513             : %type <defelt>    SeqOptElem
     514             : 
     515             : %type <istmt> insert_rest
     516             : %type <infer> opt_conf_expr
     517             : %type <onconflict> opt_on_conflict
     518             : %type <mergewhen> merge_insert merge_update merge_delete
     519             : 
     520             : %type <mergematch> merge_when_tgt_matched merge_when_tgt_not_matched
     521             : %type <node>  merge_when_clause opt_merge_when_condition
     522             : %type <list>  merge_when_list
     523             : 
     524             : %type <vsetstmt> generic_set set_rest set_rest_more generic_reset reset_rest
     525             :                  SetResetClause FunctionSetResetClause
     526             : 
     527             : %type <node>  TableElement TypedTableElement ConstraintElem DomainConstraintElem TableFuncElement
     528             : %type <node>  columnDef columnOptions optionalPeriodName
     529             : %type <defelt>    def_elem reloption_elem old_aggr_elem operator_def_elem
     530             : %type <node>  def_arg columnElem where_clause where_or_current_clause
     531             :                 a_expr b_expr c_expr AexprConst indirection_el opt_slice_bound
     532             :                 columnref having_clause func_table xmltable array_expr
     533             :                 OptWhereClause operator_def_arg
     534             : %type <list>  opt_column_and_period_list
     535             : %type <list>  rowsfrom_item rowsfrom_list opt_col_def_list
     536             : %type <boolean> opt_ordinality opt_without_overlaps
     537             : %type <list>  ExclusionConstraintList ExclusionConstraintElem
     538             : %type <list>  func_arg_list func_arg_list_opt
     539             : %type <node>  func_arg_expr
     540             : %type <list>  row explicit_row implicit_row type_list array_expr_list
     541             : %type <node>  case_expr case_arg when_clause case_default
     542             : %type <list>  when_clause_list
     543             : %type <node>  opt_search_clause opt_cycle_clause
     544             : %type <ival>  sub_type opt_materialized
     545             : %type <node>  NumericOnly
     546             : %type <list>  NumericOnly_list
     547             : %type <alias> alias_clause opt_alias_clause opt_alias_clause_for_join_using
     548             : %type <list>  func_alias_clause
     549             : %type <sortby>    sortby
     550             : %type <ielem> index_elem index_elem_options
     551             : %type <selem> stats_param
     552             : %type <node>  table_ref
     553             : %type <jexpr> joined_table
     554             : %type <range> relation_expr
     555             : %type <range> extended_relation_expr
     556             : %type <range> relation_expr_opt_alias
     557             : %type <node>  tablesample_clause opt_repeatable_clause
     558             : %type <target>    target_el set_target insert_column_item
     559             : 
     560             : %type <str>       generic_option_name
     561             : %type <node>  generic_option_arg
     562             : %type <defelt>    generic_option_elem alter_generic_option_elem
     563             : %type <list>  generic_option_list alter_generic_option_list
     564             : 
     565             : %type <ival>  reindex_target_relation reindex_target_all
     566             : 
     567             : %type <node>  copy_generic_opt_arg copy_generic_opt_arg_list_item
     568             : %type <defelt>    copy_generic_opt_elem
     569             : %type <list>  copy_generic_opt_list copy_generic_opt_arg_list
     570             : %type <list>  copy_options
     571             : 
     572             : %type <typnam>    Typename SimpleTypename ConstTypename
     573             :                 GenericType Numeric opt_float JsonType
     574             :                 Character ConstCharacter
     575             :                 CharacterWithLength CharacterWithoutLength
     576             :                 ConstDatetime ConstInterval
     577             :                 Bit ConstBit BitWithLength BitWithoutLength
     578             : %type <str>       character
     579             : %type <str>       extract_arg
     580             : %type <boolean> opt_varying opt_timezone opt_no_inherit
     581             : 
     582             : %type <ival>  Iconst SignedIconst
     583             : %type <str>       Sconst comment_text notify_payload
     584             : %type <str>       RoleId opt_boolean_or_string
     585             : %type <list>  var_list
     586             : %type <str>       ColId ColLabel BareColLabel
     587             : %type <str>       NonReservedWord NonReservedWord_or_Sconst
     588             : %type <str>       var_name type_function_name param_name
     589             : %type <str>       createdb_opt_name plassign_target
     590             : %type <node>  var_value zone_value
     591             : %type <rolespec> auth_ident RoleSpec opt_granted_by
     592             : %type <publicationobjectspec> PublicationObjSpec
     593             : %type <publicationallobjectspec> PublicationAllObjSpec
     594             : 
     595             : %type <keyword> unreserved_keyword type_func_name_keyword
     596             : %type <keyword> col_name_keyword reserved_keyword
     597             : %type <keyword> bare_label_keyword
     598             : 
     599             : %type <node>  DomainConstraint TableConstraint TableLikeClause
     600             : %type <ival>  TableLikeOptionList TableLikeOption
     601             : %type <str>       column_compression opt_column_compression column_storage opt_column_storage
     602             : %type <list>  ColQualList
     603             : %type <node>  ColConstraint ColConstraintElem ConstraintAttr
     604             : %type <ival>  key_match
     605             : %type <keyaction> key_delete key_update key_action
     606             : %type <keyactions> key_actions
     607             : %type <ival>  ConstraintAttributeSpec ConstraintAttributeElem
     608             : %type <str>       ExistingIndex
     609             : 
     610             : %type <list>  constraints_set_list
     611             : %type <boolean> constraints_set_mode
     612             : %type <str>       OptTableSpace OptConsTableSpace
     613             : %type <rolespec> OptTableSpaceOwner
     614             : %type <ival>  opt_check_option
     615             : 
     616             : %type <str>       opt_provider security_label
     617             : 
     618             : %type <target>    xml_attribute_el
     619             : %type <list>  xml_attribute_list xml_attributes
     620             : %type <node>  xml_root_version opt_xml_root_standalone
     621             : %type <node>  xmlexists_argument
     622             : %type <ival>  document_or_content
     623             : %type <boolean>   xml_indent_option xml_whitespace_option
     624             : %type <list>  xmltable_column_list xmltable_column_option_list
     625             : %type <node>  xmltable_column_el
     626             : %type <defelt>    xmltable_column_option_el
     627             : %type <list>  xml_namespace_list
     628             : %type <target>    xml_namespace_el
     629             : 
     630             : %type <node>  func_application func_expr_common_subexpr
     631             : %type <node>  func_expr func_expr_windowless
     632             : %type <node>  common_table_expr
     633             : %type <with>  with_clause opt_with_clause
     634             : %type <list>  cte_list
     635             : 
     636             : %type <list>  within_group_clause
     637             : %type <node>  filter_clause
     638             : %type <list>  window_clause window_definition_list opt_partition_clause
     639             : %type <windef>    window_definition over_clause window_specification
     640             :                 opt_frame_clause frame_extent frame_bound
     641             : %type <ival>  null_treatment opt_window_exclusion_clause
     642             : %type <str>       opt_existing_window_name
     643             : %type <boolean> opt_if_not_exists
     644             : %type <boolean> opt_unique_null_treatment
     645             : %type <ival>  generated_when override_kind opt_virtual_or_stored
     646             : %type <partspec>  PartitionSpec OptPartitionSpec
     647             : %type <partelem>  part_elem
     648             : %type <list>      part_params
     649             : %type <partboundspec> PartitionBoundSpec
     650             : %type <list>      hash_partbound
     651             : %type <defelt>        hash_partbound_elem
     652             : 
     653             : %type <node>  json_format_clause
     654             :                 json_format_clause_opt
     655             :                 json_value_expr
     656             :                 json_returning_clause_opt
     657             :                 json_name_and_value
     658             :                 json_aggregate_func
     659             :                 json_argument
     660             :                 json_behavior
     661             :                 json_on_error_clause_opt
     662             :                 json_table
     663             :                 json_table_column_definition
     664             :                 json_table_column_path_clause_opt
     665             : %type <list>  json_name_and_value_list
     666             :                 json_value_expr_list
     667             :                 json_array_aggregate_order_by_clause_opt
     668             :                 json_arguments
     669             :                 json_behavior_clause_opt
     670             :                 json_passing_clause_opt
     671             :                 json_table_column_definition_list
     672             : %type <str>       json_table_path_name_opt
     673             : %type <ival>  json_behavior_type
     674             :                 json_predicate_type_constraint
     675             :                 json_quotes_clause_opt
     676             :                 json_wrapper_behavior
     677             : %type <boolean>   json_key_uniqueness_constraint_opt
     678             :                 json_object_constructor_null_clause_opt
     679             :                 json_array_constructor_null_clause_opt
     680             : 
     681             : 
     682             : /*
     683             :  * Non-keyword token types.  These are hard-wired into the "flex" lexer.
     684             :  * They must be listed first so that their numeric codes do not depend on
     685             :  * the set of keywords.  PL/pgSQL depends on this so that it can share the
     686             :  * same lexer.  If you add/change tokens here, fix PL/pgSQL to match!
     687             :  *
     688             :  * UIDENT and USCONST are reduced to IDENT and SCONST in parser.c, so that
     689             :  * they need no productions here; but we must assign token codes to them.
     690             :  *
     691             :  * DOT_DOT is unused in the core SQL grammar, and so will always provoke
     692             :  * parse errors.  It is needed by PL/pgSQL.
     693             :  */
     694             : %token <str>  IDENT UIDENT FCONST SCONST USCONST BCONST XCONST Op
     695             : %token <ival> ICONST PARAM
     696             : %token          TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
     697             : %token          LESS_EQUALS GREATER_EQUALS NOT_EQUALS
     698             : 
     699             : /*
     700             :  * If you want to make any keyword changes, update the keyword table in
     701             :  * src/include/parser/kwlist.h and add new keywords to the appropriate one
     702             :  * of the reserved-or-not-so-reserved keyword lists, below; search
     703             :  * this file for "Keyword category lists".
     704             :  */
     705             : 
     706             : /* ordinary key words in alphabetical order */
     707             : %token <keyword> ABORT_P ABSENT ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
     708             :     AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
     709             :     ASENSITIVE ASSERTION ASSIGNMENT ASYMMETRIC ATOMIC AT ATTACH ATTRIBUTE AUTHORIZATION
     710             : 
     711             :     BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
     712             :     BOOLEAN_P BOTH BREADTH BY
     713             : 
     714             :     CACHE CALL CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
     715             :     CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
     716             :     CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
     717             :     COMMITTED COMPRESSION CONCURRENTLY CONDITIONAL CONFIGURATION CONFLICT
     718             :     CONNECTION CONSTRAINT CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY
     719             :     COST CREATE CROSS CSV CUBE CURRENT_P
     720             :     CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
     721             :     CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
     722             : 
     723             :     DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
     724             :     DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DEPENDS DEPTH DESC
     725             :     DETACH DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P
     726             :     DOUBLE_P DROP
     727             : 
     728             :     EACH ELSE EMPTY_P ENABLE_P ENCODING ENCRYPTED END_P ENFORCED ENUM_P ERROR_P
     729             :     ESCAPE EVENT EXCEPT EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN
     730             :     EXPRESSION EXTENSION EXTERNAL EXTRACT
     731             : 
     732             :     FALSE_P FAMILY FETCH FILTER FINALIZE FIRST_P FLOAT_P FOLLOWING FOR
     733             :     FORCE FOREIGN FORMAT FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
     734             : 
     735             :     GENERATED GLOBAL GRANT GRANTED GREATEST GROUP_P GROUPING GROUPS
     736             : 
     737             :     HANDLER HAVING HEADER_P HOLD HOUR_P
     738             : 
     739             :     IDENTITY_P IF_P IGNORE_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P INCLUDE
     740             :     INCLUDING INCREMENT INDENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
     741             :     INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
     742             :     INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
     743             : 
     744             :     JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_EXISTS JSON_OBJECT JSON_OBJECTAGG
     745             :     JSON_QUERY JSON_SCALAR JSON_SERIALIZE JSON_TABLE JSON_VALUE
     746             : 
     747             :     KEEP KEY KEYS
     748             : 
     749             :     LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
     750             :     LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
     751             :     LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED
     752             : 
     753             :     MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE MERGE_ACTION METHOD
     754             :     MINUTE_P MINVALUE MODE MONTH_P MOVE
     755             : 
     756             :     NAME_P NAMES NATIONAL NATURAL NCHAR NESTED NEW NEXT NFC NFD NFKC NFKD NO
     757             :     NONE NORMALIZE NORMALIZED
     758             :     NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
     759             :     NULLS_P NUMERIC
     760             : 
     761             :     OBJECT_P OBJECTS_P OF OFF OFFSET OIDS OLD OMIT ON ONLY OPERATOR OPTION OPTIONS OR
     762             :     ORDER ORDINALITY OTHERS OUT_P OUTER_P
     763             :     OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
     764             : 
     765             :     PARALLEL PARAMETER PARSER PARTIAL PARTITION PASSING PASSWORD PATH
     766             :     PERIOD PLACING PLAN PLANS POLICY
     767             :     POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
     768             :     PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PUBLICATION
     769             : 
     770             :     QUOTE QUOTES
     771             : 
     772             :     RANGE READ REAL REASSIGN RECURSIVE REF_P REFERENCES REFERENCING
     773             :     REFRESH REINDEX RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
     774             :     RESET RESPECT_P RESTART RESTRICT RETURN RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
     775             :     ROUTINE ROUTINES ROW ROWS RULE
     776             : 
     777             :     SAVEPOINT SCALAR SCHEMA SCHEMAS SCROLL SEARCH SECOND_P SECURITY SELECT
     778             :     SEQUENCE SEQUENCES
     779             :     SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
     780             :     SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SOURCE SQL_P STABLE STANDALONE_P
     781             :     START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRING_P STRIP_P
     782             :     SUBSCRIPTION SUBSTRING SUPPORT SYMMETRIC SYSID SYSTEM_P SYSTEM_USER
     783             : 
     784             :     TABLE TABLES TABLESAMPLE TABLESPACE TARGET TEMP TEMPLATE TEMPORARY TEXT_P THEN
     785             :     TIES TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM
     786             :     TREAT TRIGGER TRIM TRUE_P
     787             :     TRUNCATE TRUSTED TYPE_P TYPES_P
     788             : 
     789             :     UESCAPE UNBOUNDED UNCONDITIONAL UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
     790             :     UNLISTEN UNLOGGED UNTIL UPDATE USER USING
     791             : 
     792             :     VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
     793             :     VERBOSE VERSION_P VIEW VIEWS VIRTUAL VOLATILE
     794             : 
     795             :     WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
     796             : 
     797             :     XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLNAMESPACES
     798             :     XMLPARSE XMLPI XMLROOT XMLSERIALIZE XMLTABLE
     799             : 
     800             :     YEAR_P YES_P
     801             : 
     802             :     ZONE
     803             : 
     804             : /*
     805             :  * The grammar thinks these are keywords, but they are not in the kwlist.h
     806             :  * list and so can never be entered directly.  The filter in parser.c
     807             :  * creates these tokens when required (based on looking one token ahead).
     808             :  *
     809             :  * NOT_LA exists so that productions such as NOT LIKE can be given the same
     810             :  * precedence as LIKE; otherwise they'd effectively have the same precedence
     811             :  * as NOT, at least with respect to their left-hand subexpression.
     812             :  * FORMAT_LA, NULLS_LA, WITH_LA, and WITHOUT_LA are needed to make the grammar
     813             :  * LALR(1).
     814             :  */
     815             : %token      FORMAT_LA NOT_LA NULLS_LA WITH_LA WITHOUT_LA
     816             : 
     817             : /*
     818             :  * The grammar likewise thinks these tokens are keywords, but they are never
     819             :  * generated by the scanner.  Rather, they can be injected by parser.c as
     820             :  * the initial token of the string (using the lookahead-token mechanism
     821             :  * implemented there).  This provides a way to tell the grammar to parse
     822             :  * something other than the usual list of SQL commands.
     823             :  */
     824             : %token      MODE_TYPE_NAME
     825             : %token      MODE_PLPGSQL_EXPR
     826             : %token      MODE_PLPGSQL_ASSIGN1
     827             : %token      MODE_PLPGSQL_ASSIGN2
     828             : %token      MODE_PLPGSQL_ASSIGN3
     829             : 
     830             : 
     831             : /* Precedence: lowest to highest */
     832             : %left       UNION EXCEPT
     833             : %left       INTERSECT
     834             : %left       OR
     835             : %left       AND
     836             : %right      NOT
     837             : %nonassoc   IS ISNULL NOTNULL   /* IS sets precedence for IS NULL, etc */
     838             : %nonassoc   '<' '>' '=' LESS_EQUALS GREATER_EQUALS NOT_EQUALS
     839             : %nonassoc   BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
     840             : %nonassoc   ESCAPE          /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
     841             : 
     842             : /*
     843             :  * Sometimes it is necessary to assign precedence to keywords that are not
     844             :  * really part of the operator hierarchy, in order to resolve grammar
     845             :  * ambiguities.  It's best to avoid doing so whenever possible, because such
     846             :  * assignments have global effect and may hide ambiguities besides the one
     847             :  * you intended to solve.  (Attaching a precedence to a single rule with
     848             :  * %prec is far safer and should be preferred.)  If you must give precedence
     849             :  * to a new keyword, try very hard to give it the same precedence as IDENT.
     850             :  * If the keyword has IDENT's precedence then it clearly acts the same as
     851             :  * non-keywords and other similar keywords, thus reducing the risk of
     852             :  * unexpected precedence effects.
     853             :  *
     854             :  * We used to need to assign IDENT an explicit precedence just less than Op,
     855             :  * to support target_el without AS.  While that's not really necessary since
     856             :  * we removed postfix operators, we continue to do so because it provides a
     857             :  * reference point for a precedence level that we can assign to other
     858             :  * keywords that lack a natural precedence level.
     859             :  *
     860             :  * We need to do this for PARTITION, RANGE, ROWS, and GROUPS to support
     861             :  * opt_existing_window_name (see comment there).
     862             :  *
     863             :  * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
     864             :  * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
     865             :  * there is no principled way to distinguish these from the productions
     866             :  * a_expr PRECEDING/FOLLOWING.  We hack this up by giving UNBOUNDED slightly
     867             :  * lower precedence than PRECEDING and FOLLOWING.  At present this doesn't
     868             :  * appear to cause UNBOUNDED to be treated differently from other unreserved
     869             :  * keywords anywhere else in the grammar, but it's definitely risky.  We can
     870             :  * blame any funny behavior of UNBOUNDED on the SQL standard, though.
     871             :  *
     872             :  * To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
     873             :  * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
     874             :  * rather than reducing a conflicting rule that takes CUBE as a function name.
     875             :  * Using the same precedence as IDENT seems right for the reasons given above.
     876             :  *
     877             :  * SET is likewise assigned the same precedence as IDENT, to support the
     878             :  * relation_expr_opt_alias production (see comment there).
     879             :  *
     880             :  * KEYS, OBJECT_P, SCALAR, VALUE_P, WITH, and WITHOUT are similarly assigned
     881             :  * the same precedence as IDENT.  This allows resolving conflicts in the
     882             :  * json_predicate_type_constraint and json_key_uniqueness_constraint_opt
     883             :  * productions (see comments there).
     884             :  *
     885             :  * Like the UNBOUNDED PRECEDING/FOLLOWING case, NESTED is assigned a lower
     886             :  * precedence than PATH to fix ambiguity in the json_table production.
     887             :  */
     888             : %nonassoc   UNBOUNDED NESTED /* ideally would have same precedence as IDENT */
     889             : %nonassoc   IDENT PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
     890             :             SET KEYS OBJECT_P SCALAR VALUE_P WITH WITHOUT PATH
     891             : %left       Op OPERATOR     /* multi-character ops and user-defined operators */
     892             : %left       '+' '-'
     893             : %left       '*' '/' '%'
     894             : %left       '^'
     895             : /* Unary Operators */
     896             : %left       AT              /* sets precedence for AT TIME ZONE, AT LOCAL */
     897             : %left       COLLATE
     898             : %right      UMINUS
     899             : %left       '[' ']'
     900             : %left       '(' ')'
     901             : %left       TYPECAST
     902             : %left       '.'
     903             : /*
     904             :  * These might seem to be low-precedence, but actually they are not part
     905             :  * of the arithmetic hierarchy at all in their use as JOIN operators.
     906             :  * We make them high-precedence to support their use as function names.
     907             :  * They wouldn't be given a precedence at all, were it not that we need
     908             :  * left-associativity among the JOIN rules themselves.
     909             :  */
     910             : %left       JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
     911             : 
     912             : %%
     913             : 
     914             : /*
     915             :  *  The target production for the whole parse.
     916             :  *
     917             :  * Ordinarily we parse a list of statements, but if we see one of the
     918             :  * special MODE_XXX symbols as first token, we parse something else.
     919             :  * The options here correspond to enum RawParseMode, which see for details.
     920             :  */
     921             : parse_toplevel:
     922             :             stmtmulti
     923             :             {
     924      714790 :                 pg_yyget_extra(yyscanner)->parsetree = $1;
     925             :                 (void) yynerrs;     /* suppress compiler warning */
     926             :             }
     927             :             | MODE_TYPE_NAME Typename
     928             :             {
     929        9670 :                 pg_yyget_extra(yyscanner)->parsetree = list_make1($2);
     930             :             }
     931             :             | MODE_PLPGSQL_EXPR PLpgSQL_Expr
     932             :             {
     933       33370 :                 pg_yyget_extra(yyscanner)->parsetree =
     934       33370 :                     list_make1(makeRawStmt($2, @2));
     935             :             }
     936             :             | MODE_PLPGSQL_ASSIGN1 PLAssignStmt
     937             :             {
     938        6342 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     939             : 
     940        6342 :                 n->nnames = 1;
     941        6342 :                 pg_yyget_extra(yyscanner)->parsetree =
     942        6342 :                     list_make1(makeRawStmt((Node *) n, @2));
     943             :             }
     944             :             | MODE_PLPGSQL_ASSIGN2 PLAssignStmt
     945             :             {
     946         674 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     947             : 
     948         674 :                 n->nnames = 2;
     949         674 :                 pg_yyget_extra(yyscanner)->parsetree =
     950         674 :                     list_make1(makeRawStmt((Node *) n, @2));
     951             :             }
     952             :             | MODE_PLPGSQL_ASSIGN3 PLAssignStmt
     953             :             {
     954          28 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     955             : 
     956          28 :                 n->nnames = 3;
     957          28 :                 pg_yyget_extra(yyscanner)->parsetree =
     958          28 :                     list_make1(makeRawStmt((Node *) n, @2));
     959             :             }
     960             :         ;
     961             : 
     962             : /*
     963             :  * At top level, we wrap each stmt with a RawStmt node carrying start location
     964             :  * and length of the stmt's text.
     965             :  * We also take care to discard empty statements entirely (which among other
     966             :  * things dodges the problem of assigning them a location).
     967             :  */
     968             : stmtmulti:  stmtmulti ';' toplevel_stmt
     969             :                 {
     970      584240 :                     if ($1 != NIL)
     971             :                     {
     972             :                         /* update length of previous stmt */
     973      583674 :                         updateRawStmtEnd(llast_node(RawStmt, $1), @2);
     974             :                     }
     975      584238 :                     if ($3 != NULL)
     976       59224 :                         $$ = lappend($1, makeRawStmt($3, @3));
     977             :                     else
     978      525014 :                         $$ = $1;
     979             :                 }
     980             :             | toplevel_stmt
     981             :                 {
     982      714798 :                     if ($1 != NULL)
     983      713480 :                         $$ = list_make1(makeRawStmt($1, @1));
     984             :                     else
     985        1318 :                         $$ = NIL;
     986             :                 }
     987             :         ;
     988             : 
     989             : /*
     990             :  * toplevel_stmt includes BEGIN and END.  stmt does not include them, because
     991             :  * those words have different meanings in function bodies.
     992             :  */
     993             : toplevel_stmt:
     994             :             stmt
     995             :             | TransactionStmtLegacy
     996             :         ;
     997             : 
     998             : stmt:
     999             :             AlterEventTrigStmt
    1000             :             | AlterCollationStmt
    1001             :             | AlterDatabaseStmt
    1002             :             | AlterDatabaseSetStmt
    1003             :             | AlterDefaultPrivilegesStmt
    1004             :             | AlterDomainStmt
    1005             :             | AlterEnumStmt
    1006             :             | AlterExtensionStmt
    1007             :             | AlterExtensionContentsStmt
    1008             :             | AlterFdwStmt
    1009             :             | AlterForeignServerStmt
    1010             :             | AlterFunctionStmt
    1011             :             | AlterGroupStmt
    1012             :             | AlterObjectDependsStmt
    1013             :             | AlterObjectSchemaStmt
    1014             :             | AlterOwnerStmt
    1015             :             | AlterOperatorStmt
    1016             :             | AlterTypeStmt
    1017             :             | AlterPolicyStmt
    1018             :             | AlterSeqStmt
    1019             :             | AlterSystemStmt
    1020             :             | AlterTableStmt
    1021             :             | AlterTblSpcStmt
    1022             :             | AlterCompositeTypeStmt
    1023             :             | AlterPublicationStmt
    1024             :             | AlterRoleSetStmt
    1025             :             | AlterRoleStmt
    1026             :             | AlterSubscriptionStmt
    1027             :             | AlterStatsStmt
    1028             :             | AlterTSConfigurationStmt
    1029             :             | AlterTSDictionaryStmt
    1030             :             | AlterUserMappingStmt
    1031             :             | AnalyzeStmt
    1032             :             | CallStmt
    1033             :             | CheckPointStmt
    1034             :             | ClosePortalStmt
    1035             :             | ClusterStmt
    1036             :             | CommentStmt
    1037             :             | ConstraintsSetStmt
    1038             :             | CopyStmt
    1039             :             | CreateAmStmt
    1040             :             | CreateAsStmt
    1041             :             | CreateAssertionStmt
    1042             :             | CreateCastStmt
    1043             :             | CreateConversionStmt
    1044             :             | CreateDomainStmt
    1045             :             | CreateExtensionStmt
    1046             :             | CreateFdwStmt
    1047             :             | CreateForeignServerStmt
    1048             :             | CreateForeignTableStmt
    1049             :             | CreateFunctionStmt
    1050             :             | CreateGroupStmt
    1051             :             | CreateMatViewStmt
    1052             :             | CreateOpClassStmt
    1053             :             | CreateOpFamilyStmt
    1054             :             | CreatePublicationStmt
    1055             :             | AlterOpFamilyStmt
    1056             :             | CreatePolicyStmt
    1057             :             | CreatePLangStmt
    1058             :             | CreateSchemaStmt
    1059             :             | CreateSeqStmt
    1060             :             | CreateStmt
    1061             :             | CreateSubscriptionStmt
    1062             :             | CreateStatsStmt
    1063             :             | CreateTableSpaceStmt
    1064             :             | CreateTransformStmt
    1065             :             | CreateTrigStmt
    1066             :             | CreateEventTrigStmt
    1067             :             | CreateRoleStmt
    1068             :             | CreateUserStmt
    1069             :             | CreateUserMappingStmt
    1070             :             | CreatedbStmt
    1071             :             | DeallocateStmt
    1072             :             | DeclareCursorStmt
    1073             :             | DefineStmt
    1074             :             | DeleteStmt
    1075             :             | DiscardStmt
    1076             :             | DoStmt
    1077             :             | DropCastStmt
    1078             :             | DropOpClassStmt
    1079             :             | DropOpFamilyStmt
    1080             :             | DropOwnedStmt
    1081             :             | DropStmt
    1082             :             | DropSubscriptionStmt
    1083             :             | DropTableSpaceStmt
    1084             :             | DropTransformStmt
    1085             :             | DropRoleStmt
    1086             :             | DropUserMappingStmt
    1087             :             | DropdbStmt
    1088             :             | ExecuteStmt
    1089             :             | ExplainStmt
    1090             :             | FetchStmt
    1091             :             | GrantStmt
    1092             :             | GrantRoleStmt
    1093             :             | ImportForeignSchemaStmt
    1094             :             | IndexStmt
    1095             :             | InsertStmt
    1096             :             | ListenStmt
    1097             :             | RefreshMatViewStmt
    1098             :             | LoadStmt
    1099             :             | LockStmt
    1100             :             | MergeStmt
    1101             :             | NotifyStmt
    1102             :             | PrepareStmt
    1103             :             | ReassignOwnedStmt
    1104             :             | ReindexStmt
    1105             :             | RemoveAggrStmt
    1106             :             | RemoveFuncStmt
    1107             :             | RemoveOperStmt
    1108             :             | RenameStmt
    1109             :             | RevokeStmt
    1110             :             | RevokeRoleStmt
    1111             :             | RuleStmt
    1112             :             | SecLabelStmt
    1113             :             | SelectStmt
    1114             :             | TransactionStmt
    1115             :             | TruncateStmt
    1116             :             | UnlistenStmt
    1117             :             | UpdateStmt
    1118             :             | VacuumStmt
    1119             :             | VariableResetStmt
    1120             :             | VariableSetStmt
    1121             :             | VariableShowStmt
    1122             :             | ViewStmt
    1123             :             | /*EMPTY*/
    1124      526350 :                 { $$ = NULL; }
    1125             :         ;
    1126             : 
    1127             : /*
    1128             :  * Generic supporting productions for DDL
    1129             :  */
    1130             : opt_single_name:
    1131        5336 :             ColId                           { $$ = $1; }
    1132        1566 :             | /* EMPTY */                   { $$ = NULL; }
    1133             :         ;
    1134             : 
    1135             : opt_qualified_name:
    1136        1888 :             any_name                        { $$ = $1; }
    1137       15300 :             | /*EMPTY*/                     { $$ = NIL; }
    1138             :         ;
    1139             : 
    1140             : opt_concurrently:
    1141        1004 :             CONCURRENTLY                    { $$ = true; }
    1142        7648 :             | /*EMPTY*/                     { $$ = false; }
    1143             :         ;
    1144             : 
    1145             : opt_drop_behavior:
    1146        1984 :             CASCADE                         { $$ = DROP_CASCADE; }
    1147         170 :             | RESTRICT                      { $$ = DROP_RESTRICT; }
    1148       39312 :             | /* EMPTY */                   { $$ = DROP_RESTRICT; /* default */ }
    1149             :         ;
    1150             : 
    1151             : opt_utility_option_list:
    1152         366 :             '(' utility_option_list ')'     { $$ = $2; }
    1153        5908 :             | /* EMPTY */                   { $$ = NULL; }
    1154             :         ;
    1155             : 
    1156             : utility_option_list:
    1157             :             utility_option_elem
    1158             :                 {
    1159       22328 :                     $$ = list_make1($1);
    1160             :                 }
    1161             :             | utility_option_list ',' utility_option_elem
    1162             :                 {
    1163       12758 :                     $$ = lappend($1, $3);
    1164             :                 }
    1165             :         ;
    1166             : 
    1167             : utility_option_elem:
    1168             :             utility_option_name utility_option_arg
    1169             :                 {
    1170       35086 :                     $$ = makeDefElem($1, $2, @1);
    1171             :                 }
    1172             :         ;
    1173             : 
    1174             : utility_option_name:
    1175       31292 :             NonReservedWord                 { $$ = $1; }
    1176        3652 :             | analyze_keyword               { $$ = "analyze"; }
    1177         148 :             | FORMAT_LA                     { $$ = "format"; }
    1178             :         ;
    1179             : 
    1180             : utility_option_arg:
    1181       17982 :             opt_boolean_or_string           { $$ = (Node *) makeString($1); }
    1182         382 :             | NumericOnly                   { $$ = (Node *) $1; }
    1183       16722 :             | /* EMPTY */                   { $$ = NULL; }
    1184             :         ;
    1185             : 
    1186             : /*****************************************************************************
    1187             :  *
    1188             :  * CALL statement
    1189             :  *
    1190             :  *****************************************************************************/
    1191             : 
    1192             : CallStmt:   CALL func_application
    1193             :                 {
    1194         628 :                     CallStmt   *n = makeNode(CallStmt);
    1195             : 
    1196         628 :                     n->funccall = castNode(FuncCall, $2);
    1197         628 :                     $$ = (Node *) n;
    1198             :                 }
    1199             :         ;
    1200             : 
    1201             : /*****************************************************************************
    1202             :  *
    1203             :  * Create a new Postgres DBMS role
    1204             :  *
    1205             :  *****************************************************************************/
    1206             : 
    1207             : CreateRoleStmt:
    1208             :             CREATE ROLE RoleId opt_with OptRoleList
    1209             :                 {
    1210        1386 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1211             : 
    1212        1386 :                     n->stmt_type = ROLESTMT_ROLE;
    1213        1386 :                     n->role = $3;
    1214        1386 :                     n->options = $5;
    1215        1386 :                     $$ = (Node *) n;
    1216             :                 }
    1217             :         ;
    1218             : 
    1219             : 
    1220             : opt_with:   WITH
    1221             :             | WITH_LA
    1222             :             | /*EMPTY*/
    1223             :         ;
    1224             : 
    1225             : /*
    1226             :  * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
    1227             :  * for backwards compatibility).  Note: the only option required by SQL99
    1228             :  * is "WITH ADMIN name".
    1229             :  */
    1230             : OptRoleList:
    1231        1162 :             OptRoleList CreateOptRoleElem           { $$ = lappend($1, $2); }
    1232        1866 :             | /* EMPTY */                           { $$ = NIL; }
    1233             :         ;
    1234             : 
    1235             : AlterOptRoleList:
    1236         770 :             AlterOptRoleList AlterOptRoleElem       { $$ = lappend($1, $2); }
    1237         434 :             | /* EMPTY */                           { $$ = NIL; }
    1238             :         ;
    1239             : 
    1240             : AlterOptRoleElem:
    1241             :             PASSWORD Sconst
    1242             :                 {
    1243         188 :                     $$ = makeDefElem("password",
    1244         188 :                                      (Node *) makeString($2), @1);
    1245             :                 }
    1246             :             | PASSWORD NULL_P
    1247             :                 {
    1248          12 :                     $$ = makeDefElem("password", NULL, @1);
    1249             :                 }
    1250             :             | ENCRYPTED PASSWORD Sconst
    1251             :                 {
    1252             :                     /*
    1253             :                      * These days, passwords are always stored in encrypted
    1254             :                      * form, so there is no difference between PASSWORD and
    1255             :                      * ENCRYPTED PASSWORD.
    1256             :                      */
    1257          16 :                     $$ = makeDefElem("password",
    1258          16 :                                      (Node *) makeString($3), @1);
    1259             :                 }
    1260             :             | UNENCRYPTED PASSWORD Sconst
    1261             :                 {
    1262           0 :                     ereport(ERROR,
    1263             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1264             :                              errmsg("UNENCRYPTED PASSWORD is no longer supported"),
    1265             :                              errhint("Remove UNENCRYPTED to store the password in encrypted form instead."),
    1266             :                              parser_errposition(@1)));
    1267             :                 }
    1268             :             | INHERIT
    1269             :                 {
    1270         108 :                     $$ = makeDefElem("inherit", (Node *) makeBoolean(true), @1);
    1271             :                 }
    1272             :             | CONNECTION LIMIT SignedIconst
    1273             :                 {
    1274          24 :                     $$ = makeDefElem("connectionlimit", (Node *) makeInteger($3), @1);
    1275             :                 }
    1276             :             | VALID UNTIL Sconst
    1277             :                 {
    1278           2 :                     $$ = makeDefElem("validUntil", (Node *) makeString($3), @1);
    1279             :                 }
    1280             :         /*  Supported but not documented for roles, for use by ALTER GROUP. */
    1281             :             | USER role_list
    1282             :                 {
    1283           6 :                     $$ = makeDefElem("rolemembers", (Node *) $2, @1);
    1284             :                 }
    1285             :             | IDENT
    1286             :                 {
    1287             :                     /*
    1288             :                      * We handle identifiers that aren't parser keywords with
    1289             :                      * the following special-case codes, to avoid bloating the
    1290             :                      * size of the main parser.
    1291             :                      */
    1292        1428 :                     if (strcmp($1, "superuser") == 0)
    1293         192 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(true), @1);
    1294        1236 :                     else if (strcmp($1, "nosuperuser") == 0)
    1295         112 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(false), @1);
    1296        1124 :                     else if (strcmp($1, "createrole") == 0)
    1297         102 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(true), @1);
    1298        1022 :                     else if (strcmp($1, "nocreaterole") == 0)
    1299          50 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(false), @1);
    1300         972 :                     else if (strcmp($1, "replication") == 0)
    1301         130 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(true), @1);
    1302         842 :                     else if (strcmp($1, "noreplication") == 0)
    1303         108 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(false), @1);
    1304         734 :                     else if (strcmp($1, "createdb") == 0)
    1305          92 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(true), @1);
    1306         642 :                     else if (strcmp($1, "nocreatedb") == 0)
    1307          58 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(false), @1);
    1308         584 :                     else if (strcmp($1, "login") == 0)
    1309         284 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(true), @1);
    1310         300 :                     else if (strcmp($1, "nologin") == 0)
    1311         102 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(false), @1);
    1312         198 :                     else if (strcmp($1, "bypassrls") == 0)
    1313          82 :                         $$ = makeDefElem("bypassrls", (Node *) makeBoolean(true), @1);
    1314         116 :                     else if (strcmp($1, "nobypassrls") == 0)
    1315          80 :                         $$ = makeDefElem("bypassrls", (Node *) makeBoolean(false), @1);
    1316          36 :                     else if (strcmp($1, "noinherit") == 0)
    1317             :                     {
    1318             :                         /*
    1319             :                          * Note that INHERIT is a keyword, so it's handled by main parser, but
    1320             :                          * NOINHERIT is handled here.
    1321             :                          */
    1322          36 :                         $$ = makeDefElem("inherit", (Node *) makeBoolean(false), @1);
    1323             :                     }
    1324             :                     else
    1325           0 :                         ereport(ERROR,
    1326             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    1327             :                                  errmsg("unrecognized role option \"%s\"", $1),
    1328             :                                      parser_errposition(@1)));
    1329             :                 }
    1330             :         ;
    1331             : 
    1332             : CreateOptRoleElem:
    1333        1014 :             AlterOptRoleElem            { $$ = $1; }
    1334             :             /* The following are not supported by ALTER ROLE/USER/GROUP */
    1335             :             | SYSID Iconst
    1336             :                 {
    1337           6 :                     $$ = makeDefElem("sysid", (Node *) makeInteger($2), @1);
    1338             :                 }
    1339             :             | ADMIN role_list
    1340             :                 {
    1341          22 :                     $$ = makeDefElem("adminmembers", (Node *) $2, @1);
    1342             :                 }
    1343             :             | ROLE role_list
    1344             :                 {
    1345          22 :                     $$ = makeDefElem("rolemembers", (Node *) $2, @1);
    1346             :                 }
    1347             :             | IN_P ROLE role_list
    1348             :                 {
    1349          98 :                     $$ = makeDefElem("addroleto", (Node *) $3, @1);
    1350             :                 }
    1351             :             | IN_P GROUP_P role_list
    1352             :                 {
    1353           0 :                     $$ = makeDefElem("addroleto", (Node *) $3, @1);
    1354             :                 }
    1355             :         ;
    1356             : 
    1357             : 
    1358             : /*****************************************************************************
    1359             :  *
    1360             :  * Create a new Postgres DBMS user (role with implied login ability)
    1361             :  *
    1362             :  *****************************************************************************/
    1363             : 
    1364             : CreateUserStmt:
    1365             :             CREATE USER RoleId opt_with OptRoleList
    1366             :                 {
    1367         456 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1368             : 
    1369         456 :                     n->stmt_type = ROLESTMT_USER;
    1370         456 :                     n->role = $3;
    1371         456 :                     n->options = $5;
    1372         456 :                     $$ = (Node *) n;
    1373             :                 }
    1374             :         ;
    1375             : 
    1376             : 
    1377             : /*****************************************************************************
    1378             :  *
    1379             :  * Alter a postgresql DBMS role
    1380             :  *
    1381             :  *****************************************************************************/
    1382             : 
    1383             : AlterRoleStmt:
    1384             :             ALTER ROLE RoleSpec opt_with AlterOptRoleList
    1385             :                  {
    1386         342 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1387             : 
    1388         342 :                     n->role = $3;
    1389         342 :                     n->action = +1;  /* add, if there are members */
    1390         342 :                     n->options = $5;
    1391         342 :                     $$ = (Node *) n;
    1392             :                  }
    1393             :             | ALTER USER RoleSpec opt_with AlterOptRoleList
    1394             :                  {
    1395          92 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1396             : 
    1397          92 :                     n->role = $3;
    1398          92 :                     n->action = +1;  /* add, if there are members */
    1399          92 :                     n->options = $5;
    1400          92 :                     $$ = (Node *) n;
    1401             :                  }
    1402             :         ;
    1403             : 
    1404             : opt_in_database:
    1405          94 :                /* EMPTY */                  { $$ = NULL; }
    1406           4 :             | IN_P DATABASE name    { $$ = $3; }
    1407             :         ;
    1408             : 
    1409             : AlterRoleSetStmt:
    1410             :             ALTER ROLE RoleSpec opt_in_database SetResetClause
    1411             :                 {
    1412          58 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1413             : 
    1414          58 :                     n->role = $3;
    1415          58 :                     n->database = $4;
    1416          58 :                     n->setstmt = $5;
    1417          58 :                     $$ = (Node *) n;
    1418             :                 }
    1419             :             | ALTER ROLE ALL opt_in_database SetResetClause
    1420             :                 {
    1421           4 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1422             : 
    1423           4 :                     n->role = NULL;
    1424           4 :                     n->database = $4;
    1425           4 :                     n->setstmt = $5;
    1426           4 :                     $$ = (Node *) n;
    1427             :                 }
    1428             :             | ALTER USER RoleSpec opt_in_database SetResetClause
    1429             :                 {
    1430          28 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1431             : 
    1432          28 :                     n->role = $3;
    1433          28 :                     n->database = $4;
    1434          28 :                     n->setstmt = $5;
    1435          28 :                     $$ = (Node *) n;
    1436             :                 }
    1437             :             | ALTER USER ALL opt_in_database SetResetClause
    1438             :                 {
    1439           4 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1440             : 
    1441           4 :                     n->role = NULL;
    1442           4 :                     n->database = $4;
    1443           4 :                     n->setstmt = $5;
    1444           4 :                     $$ = (Node *) n;
    1445             :                 }
    1446             :         ;
    1447             : 
    1448             : 
    1449             : /*****************************************************************************
    1450             :  *
    1451             :  * Drop a postgresql DBMS role
    1452             :  *
    1453             :  * XXX Ideally this would have CASCADE/RESTRICT options, but a role
    1454             :  * might own objects in multiple databases, and there is presently no way to
    1455             :  * implement cascading to other databases.  So we always behave as RESTRICT.
    1456             :  *****************************************************************************/
    1457             : 
    1458             : DropRoleStmt:
    1459             :             DROP ROLE role_list
    1460             :                 {
    1461        1106 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1462             : 
    1463        1106 :                     n->missing_ok = false;
    1464        1106 :                     n->roles = $3;
    1465        1106 :                     $$ = (Node *) n;
    1466             :                 }
    1467             :             | DROP ROLE IF_P EXISTS role_list
    1468             :                 {
    1469         134 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1470             : 
    1471         134 :                     n->missing_ok = true;
    1472         134 :                     n->roles = $5;
    1473         134 :                     $$ = (Node *) n;
    1474             :                 }
    1475             :             | DROP USER role_list
    1476             :                 {
    1477         406 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1478             : 
    1479         406 :                     n->missing_ok = false;
    1480         406 :                     n->roles = $3;
    1481         406 :                     $$ = (Node *) n;
    1482             :                 }
    1483             :             | DROP USER IF_P EXISTS role_list
    1484             :                 {
    1485          36 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1486             : 
    1487          36 :                     n->roles = $5;
    1488          36 :                     n->missing_ok = true;
    1489          36 :                     $$ = (Node *) n;
    1490             :                 }
    1491             :             | DROP GROUP_P role_list
    1492             :                 {
    1493          36 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1494             : 
    1495          36 :                     n->missing_ok = false;
    1496          36 :                     n->roles = $3;
    1497          36 :                     $$ = (Node *) n;
    1498             :                 }
    1499             :             | DROP GROUP_P IF_P EXISTS role_list
    1500             :                 {
    1501           6 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1502             : 
    1503           6 :                     n->missing_ok = true;
    1504           6 :                     n->roles = $5;
    1505           6 :                     $$ = (Node *) n;
    1506             :                 }
    1507             :             ;
    1508             : 
    1509             : 
    1510             : /*****************************************************************************
    1511             :  *
    1512             :  * Create a postgresql group (role without login ability)
    1513             :  *
    1514             :  *****************************************************************************/
    1515             : 
    1516             : CreateGroupStmt:
    1517             :             CREATE GROUP_P RoleId opt_with OptRoleList
    1518             :                 {
    1519          24 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1520             : 
    1521          24 :                     n->stmt_type = ROLESTMT_GROUP;
    1522          24 :                     n->role = $3;
    1523          24 :                     n->options = $5;
    1524          24 :                     $$ = (Node *) n;
    1525             :                 }
    1526             :         ;
    1527             : 
    1528             : 
    1529             : /*****************************************************************************
    1530             :  *
    1531             :  * Alter a postgresql group
    1532             :  *
    1533             :  *****************************************************************************/
    1534             : 
    1535             : AlterGroupStmt:
    1536             :             ALTER GROUP_P RoleSpec add_drop USER role_list
    1537             :                 {
    1538          42 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1539             : 
    1540          42 :                     n->role = $3;
    1541          42 :                     n->action = $4;
    1542          42 :                     n->options = list_make1(makeDefElem("rolemembers",
    1543             :                                                         (Node *) $6, @6));
    1544          42 :                     $$ = (Node *) n;
    1545             :                 }
    1546             :         ;
    1547             : 
    1548          94 : add_drop:   ADD_P                                   { $$ = +1; }
    1549         224 :             | DROP                                  { $$ = -1; }
    1550             :         ;
    1551             : 
    1552             : 
    1553             : /*****************************************************************************
    1554             :  *
    1555             :  * Manipulate a schema
    1556             :  *
    1557             :  *****************************************************************************/
    1558             : 
    1559             : CreateSchemaStmt:
    1560             :             CREATE SCHEMA opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
    1561             :                 {
    1562         158 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1563             : 
    1564             :                     /* One can omit the schema name or the authorization id. */
    1565         158 :                     n->schemaname = $3;
    1566         158 :                     n->authrole = $5;
    1567         158 :                     n->schemaElts = $6;
    1568         158 :                     n->if_not_exists = false;
    1569         158 :                     $$ = (Node *) n;
    1570             :                 }
    1571             :             | CREATE SCHEMA ColId OptSchemaEltList
    1572             :                 {
    1573         874 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1574             : 
    1575             :                     /* ...but not both */
    1576         874 :                     n->schemaname = $3;
    1577         874 :                     n->authrole = NULL;
    1578         874 :                     n->schemaElts = $4;
    1579         874 :                     n->if_not_exists = false;
    1580         874 :                     $$ = (Node *) n;
    1581             :                 }
    1582             :             | CREATE SCHEMA IF_P NOT EXISTS opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
    1583             :                 {
    1584          18 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1585             : 
    1586             :                     /* schema name can be omitted here, too */
    1587          18 :                     n->schemaname = $6;
    1588          18 :                     n->authrole = $8;
    1589          18 :                     if ($9 != NIL)
    1590           0 :                         ereport(ERROR,
    1591             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1592             :                                  errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
    1593             :                                  parser_errposition(@9)));
    1594          18 :                     n->schemaElts = $9;
    1595          18 :                     n->if_not_exists = true;
    1596          18 :                     $$ = (Node *) n;
    1597             :                 }
    1598             :             | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
    1599             :                 {
    1600          34 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1601             : 
    1602             :                     /* ...but not here */
    1603          34 :                     n->schemaname = $6;
    1604          34 :                     n->authrole = NULL;
    1605          34 :                     if ($7 != NIL)
    1606           6 :                         ereport(ERROR,
    1607             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1608             :                                  errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
    1609             :                                  parser_errposition(@7)));
    1610          28 :                     n->schemaElts = $7;
    1611          28 :                     n->if_not_exists = true;
    1612          28 :                     $$ = (Node *) n;
    1613             :                 }
    1614             :         ;
    1615             : 
    1616             : OptSchemaEltList:
    1617             :             OptSchemaEltList schema_stmt
    1618             :                 {
    1619         564 :                     $$ = lappend($1, $2);
    1620             :                 }
    1621             :             | /* EMPTY */
    1622        1084 :                 { $$ = NIL; }
    1623             :         ;
    1624             : 
    1625             : /*
    1626             :  *  schema_stmt are the ones that can show up inside a CREATE SCHEMA
    1627             :  *  statement (in addition to by themselves).
    1628             :  */
    1629             : schema_stmt:
    1630             :             CreateStmt
    1631             :             | IndexStmt
    1632             :             | CreateSeqStmt
    1633             :             | CreateTrigStmt
    1634             :             | GrantStmt
    1635             :             | ViewStmt
    1636             :         ;
    1637             : 
    1638             : 
    1639             : /*****************************************************************************
    1640             :  *
    1641             :  * Set PG internal variable
    1642             :  *    SET name TO 'var_value'
    1643             :  * Include SQL syntax (thomas 1997-10-22):
    1644             :  *    SET TIME ZONE 'var_value'
    1645             :  *
    1646             :  *****************************************************************************/
    1647             : 
    1648             : VariableSetStmt:
    1649             :             SET set_rest
    1650             :                 {
    1651       21786 :                     VariableSetStmt *n = $2;
    1652             : 
    1653       21786 :                     n->is_local = false;
    1654       21786 :                     $$ = (Node *) n;
    1655             :                 }
    1656             :             | SET LOCAL set_rest
    1657             :                 {
    1658        1236 :                     VariableSetStmt *n = $3;
    1659             : 
    1660        1236 :                     n->is_local = true;
    1661        1236 :                     $$ = (Node *) n;
    1662             :                 }
    1663             :             | SET SESSION set_rest
    1664             :                 {
    1665          84 :                     VariableSetStmt *n = $3;
    1666             : 
    1667          84 :                     n->is_local = false;
    1668          84 :                     $$ = (Node *) n;
    1669             :                 }
    1670             :         ;
    1671             : 
    1672             : set_rest:
    1673             :             TRANSACTION transaction_mode_list
    1674             :                 {
    1675         582 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1676             : 
    1677         582 :                     n->kind = VAR_SET_MULTI;
    1678         582 :                     n->name = "TRANSACTION";
    1679         582 :                     n->args = $2;
    1680         582 :                     n->jumble_args = true;
    1681         582 :                     n->location = -1;
    1682         582 :                     $$ = n;
    1683             :                 }
    1684             :             | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
    1685             :                 {
    1686          18 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1687             : 
    1688          18 :                     n->kind = VAR_SET_MULTI;
    1689          18 :                     n->name = "SESSION CHARACTERISTICS";
    1690          18 :                     n->args = $5;
    1691          18 :                     n->jumble_args = true;
    1692          18 :                     n->location = -1;
    1693          18 :                     $$ = n;
    1694             :                 }
    1695             :             | set_rest_more
    1696             :             ;
    1697             : 
    1698             : generic_set:
    1699             :             var_name TO var_list
    1700             :                 {
    1701        5188 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1702             : 
    1703        5188 :                     n->kind = VAR_SET_VALUE;
    1704        5188 :                     n->name = $1;
    1705        5188 :                     n->args = $3;
    1706        5188 :                     n->location = @3;
    1707        5188 :                     $$ = n;
    1708             :                 }
    1709             :             | var_name '=' var_list
    1710             :                 {
    1711       15004 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1712             : 
    1713       15004 :                     n->kind = VAR_SET_VALUE;
    1714       15004 :                     n->name = $1;
    1715       15004 :                     n->args = $3;
    1716       15004 :                     n->location = @3;
    1717       15004 :                     $$ = n;
    1718             :                 }
    1719             :             | var_name TO DEFAULT
    1720             :                 {
    1721         136 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1722             : 
    1723         136 :                     n->kind = VAR_SET_DEFAULT;
    1724         136 :                     n->name = $1;
    1725         136 :                     n->location = -1;
    1726         136 :                     $$ = n;
    1727             :                 }
    1728             :             | var_name '=' DEFAULT
    1729             :                 {
    1730          10 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1731             : 
    1732          10 :                     n->kind = VAR_SET_DEFAULT;
    1733          10 :                     n->name = $1;
    1734          10 :                     n->location = -1;
    1735          10 :                     $$ = n;
    1736             :                 }
    1737             :         ;
    1738             : 
    1739             : set_rest_more:  /* Generic SET syntaxes: */
    1740       20210 :             generic_set                         {$$ = $1;}
    1741             :             | var_name FROM CURRENT_P
    1742             :                 {
    1743           4 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1744             : 
    1745           4 :                     n->kind = VAR_SET_CURRENT;
    1746           4 :                     n->name = $1;
    1747           4 :                     n->location = -1;
    1748           4 :                     $$ = n;
    1749             :                 }
    1750             :             /* Special syntaxes mandated by SQL standard: */
    1751             :             | TIME ZONE zone_value
    1752             :                 {
    1753         104 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1754             : 
    1755         104 :                     n->kind = VAR_SET_VALUE;
    1756         104 :                     n->name = "timezone";
    1757         104 :                     n->location = -1;
    1758         104 :                     n->jumble_args = true;
    1759         104 :                     if ($3 != NULL)
    1760          88 :                         n->args = list_make1($3);
    1761             :                     else
    1762          16 :                         n->kind = VAR_SET_DEFAULT;
    1763         104 :                     $$ = n;
    1764             :                 }
    1765             :             | CATALOG_P Sconst
    1766             :                 {
    1767           0 :                     ereport(ERROR,
    1768             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1769             :                              errmsg("current database cannot be changed"),
    1770             :                              parser_errposition(@2)));
    1771             :                     $$ = NULL; /*not reached*/
    1772             :                 }
    1773             :             | SCHEMA Sconst
    1774             :                 {
    1775           4 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1776             : 
    1777           4 :                     n->kind = VAR_SET_VALUE;
    1778           4 :                     n->name = "search_path";
    1779           4 :                     n->args = list_make1(makeStringConst($2, @2));
    1780           4 :                     n->location = @2;
    1781           4 :                     $$ = n;
    1782             :                 }
    1783             :             | NAMES opt_encoding
    1784             :                 {
    1785           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1786             : 
    1787           0 :                     n->kind = VAR_SET_VALUE;
    1788           0 :                     n->name = "client_encoding";
    1789           0 :                     n->location = @2;
    1790           0 :                     if ($2 != NULL)
    1791           0 :                         n->args = list_make1(makeStringConst($2, @2));
    1792             :                     else
    1793           0 :                         n->kind = VAR_SET_DEFAULT;
    1794           0 :                     $$ = n;
    1795             :                 }
    1796             :             | ROLE NonReservedWord_or_Sconst
    1797             :                 {
    1798         962 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1799             : 
    1800         962 :                     n->kind = VAR_SET_VALUE;
    1801         962 :                     n->name = "role";
    1802         962 :                     n->args = list_make1(makeStringConst($2, @2));
    1803         962 :                     n->location = @2;
    1804         962 :                     $$ = n;
    1805             :                 }
    1806             :             | SESSION AUTHORIZATION NonReservedWord_or_Sconst
    1807             :                 {
    1808        2586 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1809             : 
    1810        2586 :                     n->kind = VAR_SET_VALUE;
    1811        2586 :                     n->name = "session_authorization";
    1812        2586 :                     n->args = list_make1(makeStringConst($3, @3));
    1813        2586 :                     n->location = @3;
    1814        2586 :                     $$ = n;
    1815             :                 }
    1816             :             | SESSION AUTHORIZATION DEFAULT
    1817             :                 {
    1818           4 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1819             : 
    1820           4 :                     n->kind = VAR_SET_DEFAULT;
    1821           4 :                     n->name = "session_authorization";
    1822           4 :                     n->location = -1;
    1823           4 :                     $$ = n;
    1824             :                 }
    1825             :             | XML_P OPTION document_or_content
    1826             :                 {
    1827          16 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1828             : 
    1829          16 :                     n->kind = VAR_SET_VALUE;
    1830          16 :                     n->name = "xmloption";
    1831          16 :                     n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
    1832          16 :                     n->jumble_args = true;
    1833          16 :                     n->location = -1;
    1834          16 :                     $$ = n;
    1835             :                 }
    1836             :             /* Special syntaxes invented by PostgreSQL: */
    1837             :             | TRANSACTION SNAPSHOT Sconst
    1838             :                 {
    1839          44 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1840             : 
    1841          44 :                     n->kind = VAR_SET_MULTI;
    1842          44 :                     n->name = "TRANSACTION SNAPSHOT";
    1843          44 :                     n->args = list_make1(makeStringConst($3, @3));
    1844          44 :                     n->location = @3;
    1845          44 :                     $$ = n;
    1846             :                 }
    1847             :         ;
    1848             : 
    1849       25166 : var_name:   ColId                               { $$ = $1; }
    1850             :             | var_name '.' ColId
    1851         496 :                 { $$ = psprintf("%s.%s", $1, $3); }
    1852             :         ;
    1853             : 
    1854       20192 : var_list:   var_value                               { $$ = list_make1($1); }
    1855         182 :             | var_list ',' var_value                { $$ = lappend($1, $3); }
    1856             :         ;
    1857             : 
    1858             : var_value:  opt_boolean_or_string
    1859       15050 :                 { $$ = makeStringConst($1, @1); }
    1860             :             | NumericOnly
    1861        5324 :                 { $$ = makeAConst($1, @1); }
    1862             :         ;
    1863             : 
    1864           0 : iso_level:  READ UNCOMMITTED                        { $$ = "read uncommitted"; }
    1865        1004 :             | READ COMMITTED                        { $$ = "read committed"; }
    1866        2642 :             | REPEATABLE READ                       { $$ = "repeatable read"; }
    1867        3228 :             | SERIALIZABLE                          { $$ = "serializable"; }
    1868             :         ;
    1869             : 
    1870             : opt_boolean_or_string:
    1871         702 :             TRUE_P                                  { $$ = "true"; }
    1872        1486 :             | FALSE_P                               { $$ = "false"; }
    1873        2270 :             | ON                                    { $$ = "on"; }
    1874             :             /*
    1875             :              * OFF is also accepted as a boolean value, but is handled by
    1876             :              * the NonReservedWord rule.  The action for booleans and strings
    1877             :              * is the same, so we don't need to distinguish them here.
    1878             :              */
    1879       30944 :             | NonReservedWord_or_Sconst             { $$ = $1; }
    1880             :         ;
    1881             : 
    1882             : /* Timezone values can be:
    1883             :  * - a string such as 'pst8pdt'
    1884             :  * - an identifier such as "pst8pdt"
    1885             :  * - an integer or floating point number
    1886             :  * - a time interval per SQL99
    1887             :  * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
    1888             :  * so use IDENT (meaning we reject anything that is a key word).
    1889             :  */
    1890             : zone_value:
    1891             :             Sconst
    1892             :                 {
    1893          60 :                     $$ = makeStringConst($1, @1);
    1894             :                 }
    1895             :             | IDENT
    1896             :                 {
    1897           4 :                     $$ = makeStringConst($1, @1);
    1898             :                 }
    1899             :             | ConstInterval Sconst opt_interval
    1900             :                 {
    1901           0 :                     TypeName   *t = $1;
    1902             : 
    1903           0 :                     if ($3 != NIL)
    1904             :                     {
    1905           0 :                         A_Const    *n = (A_Const *) linitial($3);
    1906             : 
    1907           0 :                         if ((n->val.ival.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
    1908           0 :                             ereport(ERROR,
    1909             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    1910             :                                      errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
    1911             :                                      parser_errposition(@3)));
    1912             :                     }
    1913           0 :                     t->typmods = $3;
    1914           0 :                     $$ = makeStringConstCast($2, @2, t);
    1915             :                 }
    1916             :             | ConstInterval '(' Iconst ')' Sconst
    1917             :                 {
    1918           0 :                     TypeName   *t = $1;
    1919             : 
    1920           0 :                     t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
    1921             :                                             makeIntConst($3, @3));
    1922           0 :                     $$ = makeStringConstCast($5, @5, t);
    1923             :                 }
    1924          24 :             | NumericOnly                           { $$ = makeAConst($1, @1); }
    1925          14 :             | DEFAULT                               { $$ = NULL; }
    1926           2 :             | LOCAL                                 { $$ = NULL; }
    1927             :         ;
    1928             : 
    1929             : opt_encoding:
    1930           0 :             Sconst                                  { $$ = $1; }
    1931           0 :             | DEFAULT                               { $$ = NULL; }
    1932           0 :             | /*EMPTY*/                             { $$ = NULL; }
    1933             :         ;
    1934             : 
    1935             : NonReservedWord_or_Sconst:
    1936       54742 :             NonReservedWord                         { $$ = $1; }
    1937        5652 :             | Sconst                                { $$ = $1; }
    1938             :         ;
    1939             : 
    1940             : VariableResetStmt:
    1941        4736 :             RESET reset_rest                        { $$ = (Node *) $2; }
    1942             :         ;
    1943             : 
    1944             : reset_rest:
    1945        3932 :             generic_reset                           { $$ = $1; }
    1946             :             | TIME ZONE
    1947             :                 {
    1948          14 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1949             : 
    1950          14 :                     n->kind = VAR_RESET;
    1951          14 :                     n->name = "timezone";
    1952          14 :                     n->location = -1;
    1953          14 :                     $$ = n;
    1954             :                 }
    1955             :             | TRANSACTION ISOLATION LEVEL
    1956             :                 {
    1957           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1958             : 
    1959           0 :                     n->kind = VAR_RESET;
    1960           0 :                     n->name = "transaction_isolation";
    1961           0 :                     n->location = -1;
    1962           0 :                     $$ = n;
    1963             :                 }
    1964             :             | SESSION AUTHORIZATION
    1965             :                 {
    1966         790 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1967             : 
    1968         790 :                     n->kind = VAR_RESET;
    1969         790 :                     n->name = "session_authorization";
    1970         790 :                     n->location = -1;
    1971         790 :                     $$ = n;
    1972             :                 }
    1973             :         ;
    1974             : 
    1975             : generic_reset:
    1976             :             var_name
    1977             :                 {
    1978        3960 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1979             : 
    1980        3960 :                     n->kind = VAR_RESET;
    1981        3960 :                     n->name = $1;
    1982        3960 :                     n->location = -1;
    1983        3960 :                     $$ = n;
    1984             :                 }
    1985             :             | ALL
    1986             :                 {
    1987          28 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1988             : 
    1989          28 :                     n->kind = VAR_RESET_ALL;
    1990          28 :                     n->location = -1;
    1991          28 :                     $$ = n;
    1992             :                 }
    1993             :         ;
    1994             : 
    1995             : /* SetResetClause allows SET or RESET without LOCAL */
    1996             : SetResetClause:
    1997        1294 :             SET set_rest                    { $$ = $2; }
    1998          42 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    1999             :         ;
    2000             : 
    2001             : /* SetResetClause allows SET or RESET without LOCAL */
    2002             : FunctionSetResetClause:
    2003         134 :             SET set_rest_more               { $$ = $2; }
    2004          12 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    2005             :         ;
    2006             : 
    2007             : 
    2008             : VariableShowStmt:
    2009             :             SHOW var_name
    2010             :                 {
    2011         864 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    2012             : 
    2013         864 :                     n->name = $2;
    2014         864 :                     $$ = (Node *) n;
    2015             :                 }
    2016             :             | SHOW TIME ZONE
    2017             :                 {
    2018          10 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    2019             : 
    2020          10 :                     n->name = "timezone";
    2021          10 :                     $$ = (Node *) n;
    2022             :                 }
    2023             :             | SHOW TRANSACTION ISOLATION LEVEL
    2024             :                 {
    2025           4 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    2026             : 
    2027           4 :                     n->name = "transaction_isolation";
    2028           4 :                     $$ = (Node *) n;
    2029             :                 }
    2030             :             | SHOW SESSION AUTHORIZATION
    2031             :                 {
    2032           0 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    2033             : 
    2034           0 :                     n->name = "session_authorization";
    2035           0 :                     $$ = (Node *) n;
    2036             :                 }
    2037             :             | SHOW ALL
    2038             :                 {
    2039           0 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    2040             : 
    2041           0 :                     n->name = "all";
    2042           0 :                     $$ = (Node *) n;
    2043             :                 }
    2044             :         ;
    2045             : 
    2046             : 
    2047             : ConstraintsSetStmt:
    2048             :             SET CONSTRAINTS constraints_set_list constraints_set_mode
    2049             :                 {
    2050         104 :                     ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
    2051             : 
    2052         104 :                     n->constraints = $3;
    2053         104 :                     n->deferred = $4;
    2054         104 :                     $$ = (Node *) n;
    2055             :                 }
    2056             :         ;
    2057             : 
    2058             : constraints_set_list:
    2059          56 :             ALL                                     { $$ = NIL; }
    2060          48 :             | qualified_name_list                   { $$ = $1; }
    2061             :         ;
    2062             : 
    2063             : constraints_set_mode:
    2064          68 :             DEFERRED                                { $$ = true; }
    2065          36 :             | IMMEDIATE                             { $$ = false; }
    2066             :         ;
    2067             : 
    2068             : 
    2069             : /*
    2070             :  * Checkpoint statement
    2071             :  */
    2072             : CheckPointStmt:
    2073             :             CHECKPOINT opt_utility_option_list
    2074             :                 {
    2075         240 :                     CheckPointStmt *n = makeNode(CheckPointStmt);
    2076             : 
    2077         240 :                     $$ = (Node *) n;
    2078         240 :                     n->options = $2;
    2079             :                 }
    2080             :         ;
    2081             : 
    2082             : 
    2083             : /*****************************************************************************
    2084             :  *
    2085             :  * DISCARD { ALL | TEMP | PLANS | SEQUENCES }
    2086             :  *
    2087             :  *****************************************************************************/
    2088             : 
    2089             : DiscardStmt:
    2090             :             DISCARD ALL
    2091             :                 {
    2092           6 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2093             : 
    2094           6 :                     n->target = DISCARD_ALL;
    2095           6 :                     $$ = (Node *) n;
    2096             :                 }
    2097             :             | DISCARD TEMP
    2098             :                 {
    2099           8 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2100             : 
    2101           8 :                     n->target = DISCARD_TEMP;
    2102           8 :                     $$ = (Node *) n;
    2103             :                 }
    2104             :             | DISCARD TEMPORARY
    2105             :                 {
    2106           0 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2107             : 
    2108           0 :                     n->target = DISCARD_TEMP;
    2109           0 :                     $$ = (Node *) n;
    2110             :                 }
    2111             :             | DISCARD PLANS
    2112             :                 {
    2113           4 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2114             : 
    2115           4 :                     n->target = DISCARD_PLANS;
    2116           4 :                     $$ = (Node *) n;
    2117             :                 }
    2118             :             | DISCARD SEQUENCES
    2119             :                 {
    2120          12 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2121             : 
    2122          12 :                     n->target = DISCARD_SEQUENCES;
    2123          12 :                     $$ = (Node *) n;
    2124             :                 }
    2125             : 
    2126             :         ;
    2127             : 
    2128             : 
    2129             : /*****************************************************************************
    2130             :  *
    2131             :  *  ALTER [ TABLE | INDEX | SEQUENCE | VIEW | MATERIALIZED VIEW | FOREIGN TABLE ] variations
    2132             :  *
    2133             :  * Note: we accept all subcommands for each of the variants, and sort
    2134             :  * out what's really legal at execution time.
    2135             :  *****************************************************************************/
    2136             : 
    2137             : AlterTableStmt:
    2138             :             ALTER TABLE relation_expr alter_table_cmds
    2139             :                 {
    2140       26370 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2141             : 
    2142       26370 :                     n->relation = $3;
    2143       26370 :                     n->cmds = $4;
    2144       26370 :                     n->objtype = OBJECT_TABLE;
    2145       26370 :                     n->missing_ok = false;
    2146       26370 :                     $$ = (Node *) n;
    2147             :                 }
    2148             :         |   ALTER TABLE IF_P EXISTS relation_expr alter_table_cmds
    2149             :                 {
    2150          54 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2151             : 
    2152          54 :                     n->relation = $5;
    2153          54 :                     n->cmds = $6;
    2154          54 :                     n->objtype = OBJECT_TABLE;
    2155          54 :                     n->missing_ok = true;
    2156          54 :                     $$ = (Node *) n;
    2157             :                 }
    2158             :         |   ALTER TABLE relation_expr partition_cmd
    2159             :                 {
    2160        3064 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2161             : 
    2162        3064 :                     n->relation = $3;
    2163        3064 :                     n->cmds = list_make1($4);
    2164        3064 :                     n->objtype = OBJECT_TABLE;
    2165        3064 :                     n->missing_ok = false;
    2166        3064 :                     $$ = (Node *) n;
    2167             :                 }
    2168             :         |   ALTER TABLE IF_P EXISTS relation_expr partition_cmd
    2169             :                 {
    2170           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2171             : 
    2172           0 :                     n->relation = $5;
    2173           0 :                     n->cmds = list_make1($6);
    2174           0 :                     n->objtype = OBJECT_TABLE;
    2175           0 :                     n->missing_ok = true;
    2176           0 :                     $$ = (Node *) n;
    2177             :                 }
    2178             :         |   ALTER TABLE ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2179             :                 {
    2180             :                     AlterTableMoveAllStmt *n =
    2181          12 :                         makeNode(AlterTableMoveAllStmt);
    2182             : 
    2183          12 :                     n->orig_tablespacename = $6;
    2184          12 :                     n->objtype = OBJECT_TABLE;
    2185          12 :                     n->roles = NIL;
    2186          12 :                     n->new_tablespacename = $9;
    2187          12 :                     n->nowait = $10;
    2188          12 :                     $$ = (Node *) n;
    2189             :                 }
    2190             :         |   ALTER TABLE ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2191             :                 {
    2192             :                     AlterTableMoveAllStmt *n =
    2193           0 :                         makeNode(AlterTableMoveAllStmt);
    2194             : 
    2195           0 :                     n->orig_tablespacename = $6;
    2196           0 :                     n->objtype = OBJECT_TABLE;
    2197           0 :                     n->roles = $9;
    2198           0 :                     n->new_tablespacename = $12;
    2199           0 :                     n->nowait = $13;
    2200           0 :                     $$ = (Node *) n;
    2201             :                 }
    2202             :         |   ALTER INDEX qualified_name alter_table_cmds
    2203             :                 {
    2204         228 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2205             : 
    2206         228 :                     n->relation = $3;
    2207         228 :                     n->cmds = $4;
    2208         228 :                     n->objtype = OBJECT_INDEX;
    2209         228 :                     n->missing_ok = false;
    2210         228 :                     $$ = (Node *) n;
    2211             :                 }
    2212             :         |   ALTER INDEX IF_P EXISTS qualified_name alter_table_cmds
    2213             :                 {
    2214           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2215             : 
    2216           0 :                     n->relation = $5;
    2217           0 :                     n->cmds = $6;
    2218           0 :                     n->objtype = OBJECT_INDEX;
    2219           0 :                     n->missing_ok = true;
    2220           0 :                     $$ = (Node *) n;
    2221             :                 }
    2222             :         |   ALTER INDEX qualified_name index_partition_cmd
    2223             :                 {
    2224         386 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2225             : 
    2226         386 :                     n->relation = $3;
    2227         386 :                     n->cmds = list_make1($4);
    2228         386 :                     n->objtype = OBJECT_INDEX;
    2229         386 :                     n->missing_ok = false;
    2230         386 :                     $$ = (Node *) n;
    2231             :                 }
    2232             :         |   ALTER INDEX ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2233             :                 {
    2234             :                     AlterTableMoveAllStmt *n =
    2235           6 :                         makeNode(AlterTableMoveAllStmt);
    2236             : 
    2237           6 :                     n->orig_tablespacename = $6;
    2238           6 :                     n->objtype = OBJECT_INDEX;
    2239           6 :                     n->roles = NIL;
    2240           6 :                     n->new_tablespacename = $9;
    2241           6 :                     n->nowait = $10;
    2242           6 :                     $$ = (Node *) n;
    2243             :                 }
    2244             :         |   ALTER INDEX ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2245             :                 {
    2246             :                     AlterTableMoveAllStmt *n =
    2247           0 :                         makeNode(AlterTableMoveAllStmt);
    2248             : 
    2249           0 :                     n->orig_tablespacename = $6;
    2250           0 :                     n->objtype = OBJECT_INDEX;
    2251           0 :                     n->roles = $9;
    2252           0 :                     n->new_tablespacename = $12;
    2253           0 :                     n->nowait = $13;
    2254           0 :                     $$ = (Node *) n;
    2255             :                 }
    2256             :         |   ALTER SEQUENCE qualified_name alter_table_cmds
    2257             :                 {
    2258          94 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2259             : 
    2260          94 :                     n->relation = $3;
    2261          94 :                     n->cmds = $4;
    2262          94 :                     n->objtype = OBJECT_SEQUENCE;
    2263          94 :                     n->missing_ok = false;
    2264          94 :                     $$ = (Node *) n;
    2265             :                 }
    2266             :         |   ALTER SEQUENCE IF_P EXISTS qualified_name alter_table_cmds
    2267             :                 {
    2268           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2269             : 
    2270           0 :                     n->relation = $5;
    2271           0 :                     n->cmds = $6;
    2272           0 :                     n->objtype = OBJECT_SEQUENCE;
    2273           0 :                     n->missing_ok = true;
    2274           0 :                     $$ = (Node *) n;
    2275             :                 }
    2276             :         |   ALTER VIEW qualified_name alter_table_cmds
    2277             :                 {
    2278         254 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2279             : 
    2280         254 :                     n->relation = $3;
    2281         254 :                     n->cmds = $4;
    2282         254 :                     n->objtype = OBJECT_VIEW;
    2283         254 :                     n->missing_ok = false;
    2284         254 :                     $$ = (Node *) n;
    2285             :                 }
    2286             :         |   ALTER VIEW IF_P EXISTS qualified_name alter_table_cmds
    2287             :                 {
    2288           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2289             : 
    2290           0 :                     n->relation = $5;
    2291           0 :                     n->cmds = $6;
    2292           0 :                     n->objtype = OBJECT_VIEW;
    2293           0 :                     n->missing_ok = true;
    2294           0 :                     $$ = (Node *) n;
    2295             :                 }
    2296             :         |   ALTER MATERIALIZED VIEW qualified_name alter_table_cmds
    2297             :                 {
    2298          48 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2299             : 
    2300          48 :                     n->relation = $4;
    2301          48 :                     n->cmds = $5;
    2302          48 :                     n->objtype = OBJECT_MATVIEW;
    2303          48 :                     n->missing_ok = false;
    2304          48 :                     $$ = (Node *) n;
    2305             :                 }
    2306             :         |   ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name alter_table_cmds
    2307             :                 {
    2308           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2309             : 
    2310           0 :                     n->relation = $6;
    2311           0 :                     n->cmds = $7;
    2312           0 :                     n->objtype = OBJECT_MATVIEW;
    2313           0 :                     n->missing_ok = true;
    2314           0 :                     $$ = (Node *) n;
    2315             :                 }
    2316             :         |   ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2317             :                 {
    2318             :                     AlterTableMoveAllStmt *n =
    2319          12 :                         makeNode(AlterTableMoveAllStmt);
    2320             : 
    2321          12 :                     n->orig_tablespacename = $7;
    2322          12 :                     n->objtype = OBJECT_MATVIEW;
    2323          12 :                     n->roles = NIL;
    2324          12 :                     n->new_tablespacename = $10;
    2325          12 :                     n->nowait = $11;
    2326          12 :                     $$ = (Node *) n;
    2327             :                 }
    2328             :         |   ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2329             :                 {
    2330             :                     AlterTableMoveAllStmt *n =
    2331           0 :                         makeNode(AlterTableMoveAllStmt);
    2332             : 
    2333           0 :                     n->orig_tablespacename = $7;
    2334           0 :                     n->objtype = OBJECT_MATVIEW;
    2335           0 :                     n->roles = $10;
    2336           0 :                     n->new_tablespacename = $13;
    2337           0 :                     n->nowait = $14;
    2338           0 :                     $$ = (Node *) n;
    2339             :                 }
    2340             :         |   ALTER FOREIGN TABLE relation_expr alter_table_cmds
    2341             :                 {
    2342         378 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2343             : 
    2344         378 :                     n->relation = $4;
    2345         378 :                     n->cmds = $5;
    2346         378 :                     n->objtype = OBJECT_FOREIGN_TABLE;
    2347         378 :                     n->missing_ok = false;
    2348         378 :                     $$ = (Node *) n;
    2349             :                 }
    2350             :         |   ALTER FOREIGN TABLE IF_P EXISTS relation_expr alter_table_cmds
    2351             :                 {
    2352         108 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2353             : 
    2354         108 :                     n->relation = $6;
    2355         108 :                     n->cmds = $7;
    2356         108 :                     n->objtype = OBJECT_FOREIGN_TABLE;
    2357         108 :                     n->missing_ok = true;
    2358         108 :                     $$ = (Node *) n;
    2359             :                 }
    2360             :         ;
    2361             : 
    2362             : alter_table_cmds:
    2363       27534 :             alter_table_cmd                         { $$ = list_make1($1); }
    2364        1020 :             | alter_table_cmds ',' alter_table_cmd  { $$ = lappend($1, $3); }
    2365             :         ;
    2366             : 
    2367             : partition_cmd:
    2368             :             /* ALTER TABLE <name> ATTACH PARTITION <table_name> FOR VALUES */
    2369             :             ATTACH PARTITION qualified_name PartitionBoundSpec
    2370             :                 {
    2371        2442 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2372        2442 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2373             : 
    2374        2442 :                     n->subtype = AT_AttachPartition;
    2375        2442 :                     cmd->name = $3;
    2376        2442 :                     cmd->bound = $4;
    2377        2442 :                     cmd->concurrent = false;
    2378        2442 :                     n->def = (Node *) cmd;
    2379             : 
    2380        2442 :                     $$ = (Node *) n;
    2381             :                 }
    2382             :             /* ALTER TABLE <name> DETACH PARTITION <partition_name> [CONCURRENTLY] */
    2383             :             | DETACH PARTITION qualified_name opt_concurrently
    2384             :                 {
    2385         602 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2386         602 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2387             : 
    2388         602 :                     n->subtype = AT_DetachPartition;
    2389         602 :                     cmd->name = $3;
    2390         602 :                     cmd->bound = NULL;
    2391         602 :                     cmd->concurrent = $4;
    2392         602 :                     n->def = (Node *) cmd;
    2393             : 
    2394         602 :                     $$ = (Node *) n;
    2395             :                 }
    2396             :             | DETACH PARTITION qualified_name FINALIZE
    2397             :                 {
    2398          20 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2399          20 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2400             : 
    2401          20 :                     n->subtype = AT_DetachPartitionFinalize;
    2402          20 :                     cmd->name = $3;
    2403          20 :                     cmd->bound = NULL;
    2404          20 :                     cmd->concurrent = false;
    2405          20 :                     n->def = (Node *) cmd;
    2406          20 :                     $$ = (Node *) n;
    2407             :                 }
    2408             :         ;
    2409             : 
    2410             : index_partition_cmd:
    2411             :             /* ALTER INDEX <name> ATTACH PARTITION <index_name> */
    2412             :             ATTACH PARTITION qualified_name
    2413             :                 {
    2414         386 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2415         386 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2416             : 
    2417         386 :                     n->subtype = AT_AttachPartition;
    2418         386 :                     cmd->name = $3;
    2419         386 :                     cmd->bound = NULL;
    2420         386 :                     cmd->concurrent = false;
    2421         386 :                     n->def = (Node *) cmd;
    2422             : 
    2423         386 :                     $$ = (Node *) n;
    2424             :                 }
    2425             :         ;
    2426             : 
    2427             : alter_table_cmd:
    2428             :             /* ALTER TABLE <name> ADD <coldef> */
    2429             :             ADD_P columnDef
    2430             :                 {
    2431         192 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2432             : 
    2433         192 :                     n->subtype = AT_AddColumn;
    2434         192 :                     n->def = $2;
    2435         192 :                     n->missing_ok = false;
    2436         192 :                     $$ = (Node *) n;
    2437             :                 }
    2438             :             /* ALTER TABLE <name> ADD IF NOT EXISTS <coldef> */
    2439             :             | ADD_P IF_P NOT EXISTS columnDef
    2440             :                 {
    2441           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2442             : 
    2443           0 :                     n->subtype = AT_AddColumn;
    2444           0 :                     n->def = $5;
    2445           0 :                     n->missing_ok = true;
    2446           0 :                     $$ = (Node *) n;
    2447             :                 }
    2448             :             /* ALTER TABLE <name> ADD COLUMN <coldef> */
    2449             :             | ADD_P COLUMN columnDef
    2450             :                 {
    2451        1922 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2452             : 
    2453        1922 :                     n->subtype = AT_AddColumn;
    2454        1922 :                     n->def = $3;
    2455        1922 :                     n->missing_ok = false;
    2456        1922 :                     $$ = (Node *) n;
    2457             :                 }
    2458             :             /* ALTER TABLE <name> ADD COLUMN IF NOT EXISTS <coldef> */
    2459             :             | ADD_P COLUMN IF_P NOT EXISTS columnDef
    2460             :                 {
    2461          60 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2462             : 
    2463          60 :                     n->subtype = AT_AddColumn;
    2464          60 :                     n->def = $6;
    2465          60 :                     n->missing_ok = true;
    2466          60 :                     $$ = (Node *) n;
    2467             :                 }
    2468             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
    2469             :             | ALTER opt_column ColId alter_column_default
    2470             :                 {
    2471         550 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2472             : 
    2473         550 :                     n->subtype = AT_ColumnDefault;
    2474         550 :                     n->name = $3;
    2475         550 :                     n->def = $4;
    2476         550 :                     $$ = (Node *) n;
    2477             :                 }
    2478             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
    2479             :             | ALTER opt_column ColId DROP NOT NULL_P
    2480             :                 {
    2481         294 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2482             : 
    2483         294 :                     n->subtype = AT_DropNotNull;
    2484         294 :                     n->name = $3;
    2485         294 :                     $$ = (Node *) n;
    2486             :                 }
    2487             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
    2488             :             | ALTER opt_column ColId SET NOT NULL_P
    2489             :                 {
    2490         440 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2491             : 
    2492         440 :                     n->subtype = AT_SetNotNull;
    2493         440 :                     n->name = $3;
    2494         440 :                     $$ = (Node *) n;
    2495             :                 }
    2496             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET EXPRESSION AS <expr> */
    2497             :             | ALTER opt_column ColId SET EXPRESSION AS '(' a_expr ')'
    2498             :                 {
    2499         168 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2500             : 
    2501         168 :                     n->subtype = AT_SetExpression;
    2502         168 :                     n->name = $3;
    2503         168 :                     n->def = $8;
    2504         168 :                     $$ = (Node *) n;
    2505             :                 }
    2506             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
    2507             :             | ALTER opt_column ColId DROP EXPRESSION
    2508             :                 {
    2509          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2510             : 
    2511          62 :                     n->subtype = AT_DropExpression;
    2512          62 :                     n->name = $3;
    2513          62 :                     $$ = (Node *) n;
    2514             :                 }
    2515             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION IF EXISTS */
    2516             :             | ALTER opt_column ColId DROP EXPRESSION IF_P EXISTS
    2517             :                 {
    2518          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2519             : 
    2520          12 :                     n->subtype = AT_DropExpression;
    2521          12 :                     n->name = $3;
    2522          12 :                     n->missing_ok = true;
    2523          12 :                     $$ = (Node *) n;
    2524             :                 }
    2525             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS */
    2526             :             | ALTER opt_column ColId SET STATISTICS set_statistics_value
    2527             :                 {
    2528          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2529             : 
    2530          62 :                     n->subtype = AT_SetStatistics;
    2531          62 :                     n->name = $3;
    2532          62 :                     n->def = $6;
    2533          62 :                     $$ = (Node *) n;
    2534             :                 }
    2535             :             /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS */
    2536             :             | ALTER opt_column Iconst SET STATISTICS set_statistics_value
    2537             :                 {
    2538          70 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2539             : 
    2540          70 :                     if ($3 <= 0 || $3 > PG_INT16_MAX)
    2541           6 :                         ereport(ERROR,
    2542             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
    2543             :                                  errmsg("column number must be in range from 1 to %d", PG_INT16_MAX),
    2544             :                                  parser_errposition(@3)));
    2545             : 
    2546          64 :                     n->subtype = AT_SetStatistics;
    2547          64 :                     n->num = (int16) $3;
    2548          64 :                     n->def = $6;
    2549          64 :                     $$ = (Node *) n;
    2550             :                 }
    2551             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
    2552             :             | ALTER opt_column ColId SET reloptions
    2553             :                 {
    2554          38 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2555             : 
    2556          38 :                     n->subtype = AT_SetOptions;
    2557          38 :                     n->name = $3;
    2558          38 :                     n->def = (Node *) $5;
    2559          38 :                     $$ = (Node *) n;
    2560             :                 }
    2561             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> RESET ( column_parameter [, ... ] ) */
    2562             :             | ALTER opt_column ColId RESET reloptions
    2563             :                 {
    2564           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2565             : 
    2566           6 :                     n->subtype = AT_ResetOptions;
    2567           6 :                     n->name = $3;
    2568           6 :                     n->def = (Node *) $5;
    2569           6 :                     $$ = (Node *) n;
    2570             :                 }
    2571             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
    2572             :             | ALTER opt_column ColId SET column_storage
    2573             :                 {
    2574         238 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2575             : 
    2576         238 :                     n->subtype = AT_SetStorage;
    2577         238 :                     n->name = $3;
    2578         238 :                     n->def = (Node *) makeString($5);
    2579         238 :                     $$ = (Node *) n;
    2580             :                 }
    2581             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET COMPRESSION <cm> */
    2582             :             | ALTER opt_column ColId SET column_compression
    2583             :                 {
    2584          78 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2585             : 
    2586          78 :                     n->subtype = AT_SetCompression;
    2587          78 :                     n->name = $3;
    2588          78 :                     n->def = (Node *) makeString($5);
    2589          78 :                     $$ = (Node *) n;
    2590             :                 }
    2591             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> ADD GENERATED ... AS IDENTITY ... */
    2592             :             | ALTER opt_column ColId ADD_P GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    2593             :                 {
    2594         166 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2595         166 :                     Constraint *c = makeNode(Constraint);
    2596             : 
    2597         166 :                     c->contype = CONSTR_IDENTITY;
    2598         166 :                     c->generated_when = $6;
    2599         166 :                     c->options = $9;
    2600         166 :                     c->location = @5;
    2601             : 
    2602         166 :                     n->subtype = AT_AddIdentity;
    2603         166 :                     n->name = $3;
    2604         166 :                     n->def = (Node *) c;
    2605             : 
    2606         166 :                     $$ = (Node *) n;
    2607             :                 }
    2608             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET <sequence options>/RESET */
    2609             :             | ALTER opt_column ColId alter_identity_column_option_list
    2610             :                 {
    2611          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2612             : 
    2613          62 :                     n->subtype = AT_SetIdentity;
    2614          62 :                     n->name = $3;
    2615          62 :                     n->def = (Node *) $4;
    2616          62 :                     $$ = (Node *) n;
    2617             :                 }
    2618             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY */
    2619             :             | ALTER opt_column ColId DROP IDENTITY_P
    2620             :                 {
    2621          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2622             : 
    2623          50 :                     n->subtype = AT_DropIdentity;
    2624          50 :                     n->name = $3;
    2625          50 :                     n->missing_ok = false;
    2626          50 :                     $$ = (Node *) n;
    2627             :                 }
    2628             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY IF EXISTS */
    2629             :             | ALTER opt_column ColId DROP IDENTITY_P IF_P EXISTS
    2630             :                 {
    2631           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2632             : 
    2633           6 :                     n->subtype = AT_DropIdentity;
    2634           6 :                     n->name = $3;
    2635           6 :                     n->missing_ok = true;
    2636           6 :                     $$ = (Node *) n;
    2637             :                 }
    2638             :             /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
    2639             :             | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
    2640             :                 {
    2641          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2642             : 
    2643          18 :                     n->subtype = AT_DropColumn;
    2644          18 :                     n->name = $5;
    2645          18 :                     n->behavior = $6;
    2646          18 :                     n->missing_ok = true;
    2647          18 :                     $$ = (Node *) n;
    2648             :                 }
    2649             :             /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
    2650             :             | DROP opt_column ColId opt_drop_behavior
    2651             :                 {
    2652        1574 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2653             : 
    2654        1574 :                     n->subtype = AT_DropColumn;
    2655        1574 :                     n->name = $3;
    2656        1574 :                     n->behavior = $4;
    2657        1574 :                     n->missing_ok = false;
    2658        1574 :                     $$ = (Node *) n;
    2659             :                 }
    2660             :             /*
    2661             :              * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
    2662             :              *      [ USING <expression> ]
    2663             :              */
    2664             :             | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using
    2665             :                 {
    2666        1024 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2667        1024 :                     ColumnDef *def = makeNode(ColumnDef);
    2668             : 
    2669        1024 :                     n->subtype = AT_AlterColumnType;
    2670        1024 :                     n->name = $3;
    2671        1024 :                     n->def = (Node *) def;
    2672             :                     /* We only use these fields of the ColumnDef node */
    2673        1024 :                     def->typeName = $6;
    2674        1024 :                     def->collClause = (CollateClause *) $7;
    2675        1024 :                     def->raw_default = $8;
    2676        1024 :                     def->location = @3;
    2677        1024 :                     $$ = (Node *) n;
    2678             :                 }
    2679             :             /* ALTER FOREIGN TABLE <name> ALTER [COLUMN] <colname> OPTIONS */
    2680             :             | ALTER opt_column ColId alter_generic_options
    2681             :                 {
    2682          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2683             : 
    2684          50 :                     n->subtype = AT_AlterColumnGenericOptions;
    2685          50 :                     n->name = $3;
    2686          50 :                     n->def = (Node *) $4;
    2687          50 :                     $$ = (Node *) n;
    2688             :                 }
    2689             :             /* ALTER TABLE <name> ADD CONSTRAINT ... */
    2690             :             | ADD_P TableConstraint
    2691             :                 {
    2692       14560 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2693             : 
    2694       14560 :                     n->subtype = AT_AddConstraint;
    2695       14560 :                     n->def = $2;
    2696       14560 :                     $$ = (Node *) n;
    2697             :                 }
    2698             :             /* ALTER TABLE <name> ALTER CONSTRAINT ... */
    2699             :             | ALTER CONSTRAINT name ConstraintAttributeSpec
    2700             :                 {
    2701         240 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2702         240 :                     ATAlterConstraint *c = makeNode(ATAlterConstraint);
    2703             : 
    2704         240 :                     n->subtype = AT_AlterConstraint;
    2705         240 :                     n->def = (Node *) c;
    2706         240 :                     c->conname = $3;
    2707         240 :                     if ($4 & (CAS_NOT_ENFORCED | CAS_ENFORCED))
    2708          84 :                         c->alterEnforceability = true;
    2709         240 :                     if ($4 & (CAS_DEFERRABLE | CAS_NOT_DEFERRABLE |
    2710             :                               CAS_INITIALLY_DEFERRED | CAS_INITIALLY_IMMEDIATE))
    2711         120 :                         c->alterDeferrability = true;
    2712         240 :                     if ($4 & CAS_NO_INHERIT)
    2713          30 :                         c->alterInheritability = true;
    2714             :                     /* handle unsupported case with specific error message */
    2715         240 :                     if ($4 & CAS_NOT_VALID)
    2716          12 :                         ereport(ERROR,
    2717             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    2718             :                                 errmsg("constraints cannot be altered to be NOT VALID"),
    2719             :                                 parser_errposition(@4));
    2720         228 :                     processCASbits($4, @4, "FOREIGN KEY",
    2721             :                                     &c->deferrable,
    2722             :                                     &c->initdeferred,
    2723             :                                     &c->is_enforced,
    2724             :                                     NULL,
    2725             :                                     &c->noinherit,
    2726             :                                     yyscanner);
    2727         228 :                     $$ = (Node *) n;
    2728             :                 }
    2729             :             /* ALTER TABLE <name> ALTER CONSTRAINT INHERIT */
    2730             :             | ALTER CONSTRAINT name INHERIT
    2731             :                 {
    2732          66 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2733          66 :                     ATAlterConstraint *c = makeNode(ATAlterConstraint);
    2734             : 
    2735          66 :                     n->subtype = AT_AlterConstraint;
    2736          66 :                     n->def = (Node *) c;
    2737          66 :                     c->conname = $3;
    2738          66 :                     c->alterInheritability = true;
    2739          66 :                     c->noinherit = false;
    2740             : 
    2741          66 :                     $$ = (Node *) n;
    2742             :                 }
    2743             :             /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
    2744             :             | VALIDATE CONSTRAINT name
    2745             :                 {
    2746         476 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2747             : 
    2748         476 :                     n->subtype = AT_ValidateConstraint;
    2749         476 :                     n->name = $3;
    2750         476 :                     $$ = (Node *) n;
    2751             :                 }
    2752             :             /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
    2753             :             | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
    2754             :                 {
    2755          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2756             : 
    2757          18 :                     n->subtype = AT_DropConstraint;
    2758          18 :                     n->name = $5;
    2759          18 :                     n->behavior = $6;
    2760          18 :                     n->missing_ok = true;
    2761          18 :                     $$ = (Node *) n;
    2762             :                 }
    2763             :             /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
    2764             :             | DROP CONSTRAINT name opt_drop_behavior
    2765             :                 {
    2766         818 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2767             : 
    2768         818 :                     n->subtype = AT_DropConstraint;
    2769         818 :                     n->name = $3;
    2770         818 :                     n->behavior = $4;
    2771         818 :                     n->missing_ok = false;
    2772         818 :                     $$ = (Node *) n;
    2773             :                 }
    2774             :             /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat */
    2775             :             | SET WITHOUT OIDS
    2776             :                 {
    2777           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2778             : 
    2779           6 :                     n->subtype = AT_DropOids;
    2780           6 :                     $$ = (Node *) n;
    2781             :                 }
    2782             :             /* ALTER TABLE <name> CLUSTER ON <indexname> */
    2783             :             | CLUSTER ON name
    2784             :                 {
    2785          46 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2786             : 
    2787          46 :                     n->subtype = AT_ClusterOn;
    2788          46 :                     n->name = $3;
    2789          46 :                     $$ = (Node *) n;
    2790             :                 }
    2791             :             /* ALTER TABLE <name> SET WITHOUT CLUSTER */
    2792             :             | SET WITHOUT CLUSTER
    2793             :                 {
    2794          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2795             : 
    2796          18 :                     n->subtype = AT_DropCluster;
    2797          18 :                     n->name = NULL;
    2798          18 :                     $$ = (Node *) n;
    2799             :                 }
    2800             :             /* ALTER TABLE <name> SET LOGGED */
    2801             :             | SET LOGGED
    2802             :                 {
    2803          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2804             : 
    2805          50 :                     n->subtype = AT_SetLogged;
    2806          50 :                     $$ = (Node *) n;
    2807             :                 }
    2808             :             /* ALTER TABLE <name> SET UNLOGGED */
    2809             :             | SET UNLOGGED
    2810             :                 {
    2811          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2812             : 
    2813          62 :                     n->subtype = AT_SetUnLogged;
    2814          62 :                     $$ = (Node *) n;
    2815             :                 }
    2816             :             /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
    2817             :             | ENABLE_P TRIGGER name
    2818             :                 {
    2819         122 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2820             : 
    2821         122 :                     n->subtype = AT_EnableTrig;
    2822         122 :                     n->name = $3;
    2823         122 :                     $$ = (Node *) n;
    2824             :                 }
    2825             :             /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
    2826             :             | ENABLE_P ALWAYS TRIGGER name
    2827             :                 {
    2828          42 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2829             : 
    2830          42 :                     n->subtype = AT_EnableAlwaysTrig;
    2831          42 :                     n->name = $4;
    2832          42 :                     $$ = (Node *) n;
    2833             :                 }
    2834             :             /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
    2835             :             | ENABLE_P REPLICA TRIGGER name
    2836             :                 {
    2837          16 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2838             : 
    2839          16 :                     n->subtype = AT_EnableReplicaTrig;
    2840          16 :                     n->name = $4;
    2841          16 :                     $$ = (Node *) n;
    2842             :                 }
    2843             :             /* ALTER TABLE <name> ENABLE TRIGGER ALL */
    2844             :             | ENABLE_P TRIGGER ALL
    2845             :                 {
    2846           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2847             : 
    2848           0 :                     n->subtype = AT_EnableTrigAll;
    2849           0 :                     $$ = (Node *) n;
    2850             :                 }
    2851             :             /* ALTER TABLE <name> ENABLE TRIGGER USER */
    2852             :             | ENABLE_P TRIGGER USER
    2853             :                 {
    2854           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2855             : 
    2856           0 :                     n->subtype = AT_EnableTrigUser;
    2857           0 :                     $$ = (Node *) n;
    2858             :                 }
    2859             :             /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
    2860             :             | DISABLE_P TRIGGER name
    2861             :                 {
    2862         138 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2863             : 
    2864         138 :                     n->subtype = AT_DisableTrig;
    2865         138 :                     n->name = $3;
    2866         138 :                     $$ = (Node *) n;
    2867             :                 }
    2868             :             /* ALTER TABLE <name> DISABLE TRIGGER ALL */
    2869             :             | DISABLE_P TRIGGER ALL
    2870             :                 {
    2871          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2872             : 
    2873          12 :                     n->subtype = AT_DisableTrigAll;
    2874          12 :                     $$ = (Node *) n;
    2875             :                 }
    2876             :             /* ALTER TABLE <name> DISABLE TRIGGER USER */
    2877             :             | DISABLE_P TRIGGER USER
    2878             :                 {
    2879          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2880             : 
    2881          12 :                     n->subtype = AT_DisableTrigUser;
    2882          12 :                     $$ = (Node *) n;
    2883             :                 }
    2884             :             /* ALTER TABLE <name> ENABLE RULE <rule> */
    2885             :             | ENABLE_P RULE name
    2886             :                 {
    2887           8 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2888             : 
    2889           8 :                     n->subtype = AT_EnableRule;
    2890           8 :                     n->name = $3;
    2891           8 :                     $$ = (Node *) n;
    2892             :                 }
    2893             :             /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
    2894             :             | ENABLE_P ALWAYS RULE name
    2895             :                 {
    2896           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2897             : 
    2898           0 :                     n->subtype = AT_EnableAlwaysRule;
    2899           0 :                     n->name = $4;
    2900           0 :                     $$ = (Node *) n;
    2901             :                 }
    2902             :             /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
    2903             :             | ENABLE_P REPLICA RULE name
    2904             :                 {
    2905           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2906             : 
    2907           6 :                     n->subtype = AT_EnableReplicaRule;
    2908           6 :                     n->name = $4;
    2909           6 :                     $$ = (Node *) n;
    2910             :                 }
    2911             :             /* ALTER TABLE <name> DISABLE RULE <rule> */
    2912             :             | DISABLE_P RULE name
    2913             :                 {
    2914          32 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2915             : 
    2916          32 :                     n->subtype = AT_DisableRule;
    2917          32 :                     n->name = $3;
    2918          32 :                     $$ = (Node *) n;
    2919             :                 }
    2920             :             /* ALTER TABLE <name> INHERIT <parent> */
    2921             :             | INHERIT qualified_name
    2922             :                 {
    2923         464 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2924             : 
    2925         464 :                     n->subtype = AT_AddInherit;
    2926         464 :                     n->def = (Node *) $2;
    2927         464 :                     $$ = (Node *) n;
    2928             :                 }
    2929             :             /* ALTER TABLE <name> NO INHERIT <parent> */
    2930             :             | NO INHERIT qualified_name
    2931             :                 {
    2932          94 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2933             : 
    2934          94 :                     n->subtype = AT_DropInherit;
    2935          94 :                     n->def = (Node *) $3;
    2936          94 :                     $$ = (Node *) n;
    2937             :                 }
    2938             :             /* ALTER TABLE <name> OF <type_name> */
    2939             :             | OF any_name
    2940             :                 {
    2941          66 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2942          66 :                     TypeName   *def = makeTypeNameFromNameList($2);
    2943             : 
    2944          66 :                     def->location = @2;
    2945          66 :                     n->subtype = AT_AddOf;
    2946          66 :                     n->def = (Node *) def;
    2947          66 :                     $$ = (Node *) n;
    2948             :                 }
    2949             :             /* ALTER TABLE <name> NOT OF */
    2950             :             | NOT OF
    2951             :                 {
    2952           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2953             : 
    2954           6 :                     n->subtype = AT_DropOf;
    2955           6 :                     $$ = (Node *) n;
    2956             :                 }
    2957             :             /* ALTER TABLE <name> OWNER TO RoleSpec */
    2958             :             | OWNER TO RoleSpec
    2959             :                 {
    2960        2024 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2961             : 
    2962        2024 :                     n->subtype = AT_ChangeOwner;
    2963        2024 :                     n->newowner = $3;
    2964        2024 :                     $$ = (Node *) n;
    2965             :                 }
    2966             :             /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
    2967             :             | SET ACCESS METHOD set_access_method_name
    2968             :                 {
    2969         128 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2970             : 
    2971         128 :                     n->subtype = AT_SetAccessMethod;
    2972         128 :                     n->name = $4;
    2973         128 :                     $$ = (Node *) n;
    2974             :                 }
    2975             :             /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
    2976             :             | SET TABLESPACE name
    2977             :                 {
    2978         104 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2979             : 
    2980         104 :                     n->subtype = AT_SetTableSpace;
    2981         104 :                     n->name = $3;
    2982         104 :                     $$ = (Node *) n;
    2983             :                 }
    2984             :             /* ALTER TABLE <name> SET (...) */
    2985             :             | SET reloptions
    2986             :                 {
    2987         600 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2988             : 
    2989         600 :                     n->subtype = AT_SetRelOptions;
    2990         600 :                     n->def = (Node *) $2;
    2991         600 :                     $$ = (Node *) n;
    2992             :                 }
    2993             :             /* ALTER TABLE <name> RESET (...) */
    2994             :             | RESET reloptions
    2995             :                 {
    2996         170 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2997             : 
    2998         170 :                     n->subtype = AT_ResetRelOptions;
    2999         170 :                     n->def = (Node *) $2;
    3000         170 :                     $$ = (Node *) n;
    3001             :                 }
    3002             :             /* ALTER TABLE <name> REPLICA IDENTITY */
    3003             :             | REPLICA IDENTITY_P replica_identity
    3004             :                 {
    3005         494 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3006             : 
    3007         494 :                     n->subtype = AT_ReplicaIdentity;
    3008         494 :                     n->def = $3;
    3009         494 :                     $$ = (Node *) n;
    3010             :                 }
    3011             :             /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
    3012             :             | ENABLE_P ROW LEVEL SECURITY
    3013             :                 {
    3014         326 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3015             : 
    3016         326 :                     n->subtype = AT_EnableRowSecurity;
    3017         326 :                     $$ = (Node *) n;
    3018             :                 }
    3019             :             /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
    3020             :             | DISABLE_P ROW LEVEL SECURITY
    3021             :                 {
    3022          10 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3023             : 
    3024          10 :                     n->subtype = AT_DisableRowSecurity;
    3025          10 :                     $$ = (Node *) n;
    3026             :                 }
    3027             :             /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
    3028             :             | FORCE ROW LEVEL SECURITY
    3029             :                 {
    3030         100 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3031             : 
    3032         100 :                     n->subtype = AT_ForceRowSecurity;
    3033         100 :                     $$ = (Node *) n;
    3034             :                 }
    3035             :             /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
    3036             :             | NO FORCE ROW LEVEL SECURITY
    3037             :                 {
    3038          32 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3039             : 
    3040          32 :                     n->subtype = AT_NoForceRowSecurity;
    3041          32 :                     $$ = (Node *) n;
    3042             :                 }
    3043             :             | alter_generic_options
    3044             :                 {
    3045          64 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3046             : 
    3047          64 :                     n->subtype = AT_GenericOptions;
    3048          64 :                     n->def = (Node *) $1;
    3049          64 :                     $$ = (Node *) n;
    3050             :                 }
    3051             :         ;
    3052             : 
    3053             : alter_column_default:
    3054         378 :             SET DEFAULT a_expr          { $$ = $3; }
    3055         186 :             | DROP DEFAULT              { $$ = NULL; }
    3056             :         ;
    3057             : 
    3058             : opt_collate_clause:
    3059             :             COLLATE any_name
    3060             :                 {
    3061          18 :                     CollateClause *n = makeNode(CollateClause);
    3062             : 
    3063          18 :                     n->arg = NULL;
    3064          18 :                     n->collname = $2;
    3065          18 :                     n->location = @1;
    3066          18 :                     $$ = (Node *) n;
    3067             :                 }
    3068        4732 :             | /* EMPTY */               { $$ = NULL; }
    3069             :         ;
    3070             : 
    3071             : alter_using:
    3072         180 :             USING a_expr                { $$ = $2; }
    3073         844 :             | /* EMPTY */               { $$ = NULL; }
    3074             :         ;
    3075             : 
    3076             : replica_identity:
    3077             :             NOTHING
    3078             :                 {
    3079          48 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3080             : 
    3081          48 :                     n->identity_type = REPLICA_IDENTITY_NOTHING;
    3082          48 :                     n->name = NULL;
    3083          48 :                     $$ = (Node *) n;
    3084             :                 }
    3085             :             | FULL
    3086             :                 {
    3087         170 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3088             : 
    3089         170 :                     n->identity_type = REPLICA_IDENTITY_FULL;
    3090         170 :                     n->name = NULL;
    3091         170 :                     $$ = (Node *) n;
    3092             :                 }
    3093             :             | DEFAULT
    3094             :                 {
    3095           6 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3096             : 
    3097           6 :                     n->identity_type = REPLICA_IDENTITY_DEFAULT;
    3098           6 :                     n->name = NULL;
    3099           6 :                     $$ = (Node *) n;
    3100             :                 }
    3101             :             | USING INDEX name
    3102             :                 {
    3103         270 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3104             : 
    3105         270 :                     n->identity_type = REPLICA_IDENTITY_INDEX;
    3106         270 :                     n->name = $3;
    3107         270 :                     $$ = (Node *) n;
    3108             :                 }
    3109             : ;
    3110             : 
    3111             : reloptions:
    3112        2698 :             '(' reloption_list ')'                  { $$ = $2; }
    3113             :         ;
    3114             : 
    3115         964 : opt_reloptions:     WITH reloptions                 { $$ = $2; }
    3116       23490 :              |      /* EMPTY */                     { $$ = NIL; }
    3117             :         ;
    3118             : 
    3119             : reloption_list:
    3120        2698 :             reloption_elem                          { $$ = list_make1($1); }
    3121         250 :             | reloption_list ',' reloption_elem     { $$ = lappend($1, $3); }
    3122             :         ;
    3123             : 
    3124             : /* This should match def_elem and also allow qualified names */
    3125             : reloption_elem:
    3126             :             ColLabel '=' def_arg
    3127             :                 {
    3128        2286 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    3129             :                 }
    3130             :             | ColLabel
    3131             :                 {
    3132         584 :                     $$ = makeDefElem($1, NULL, @1);
    3133             :                 }
    3134             :             | ColLabel '.' ColLabel '=' def_arg
    3135             :                 {
    3136          72 :                     $$ = makeDefElemExtended($1, $3, (Node *) $5,
    3137          72 :                                              DEFELEM_UNSPEC, @1);
    3138             :                 }
    3139             :             | ColLabel '.' ColLabel
    3140             :                 {
    3141           6 :                     $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC, @1);
    3142             :                 }
    3143             :         ;
    3144             : 
    3145             : alter_identity_column_option_list:
    3146             :             alter_identity_column_option
    3147          62 :                 { $$ = list_make1($1); }
    3148             :             | alter_identity_column_option_list alter_identity_column_option
    3149          60 :                 { $$ = lappend($1, $2); }
    3150             :         ;
    3151             : 
    3152             : alter_identity_column_option:
    3153             :             RESTART
    3154             :                 {
    3155          24 :                     $$ = makeDefElem("restart", NULL, @1);
    3156             :                 }
    3157             :             | RESTART opt_with NumericOnly
    3158             :                 {
    3159           0 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    3160             :                 }
    3161             :             | SET SeqOptElem
    3162             :                 {
    3163          54 :                     if (strcmp($2->defname, "as") == 0 ||
    3164          54 :                         strcmp($2->defname, "restart") == 0 ||
    3165          54 :                         strcmp($2->defname, "owned_by") == 0)
    3166           0 :                         ereport(ERROR,
    3167             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3168             :                                  errmsg("sequence option \"%s\" not supported here", $2->defname),
    3169             :                                  parser_errposition(@2)));
    3170          54 :                     $$ = $2;
    3171             :                 }
    3172             :             | SET GENERATED generated_when
    3173             :                 {
    3174          44 :                     $$ = makeDefElem("generated", (Node *) makeInteger($3), @1);
    3175             :                 }
    3176             :         ;
    3177             : 
    3178             : set_statistics_value:
    3179         158 :             SignedIconst                    { $$ = (Node *) makeInteger($1); }
    3180           0 :             | DEFAULT                       { $$ = NULL; }
    3181             :         ;
    3182             : 
    3183             : set_access_method_name:
    3184          92 :             ColId                           { $$ = $1; }
    3185          36 :             | DEFAULT                       { $$ = NULL; }
    3186             :         ;
    3187             : 
    3188             : PartitionBoundSpec:
    3189             :             /* a HASH partition */
    3190             :             FOR VALUES WITH '(' hash_partbound ')'
    3191             :                 {
    3192             :                     ListCell   *lc;
    3193         732 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3194             : 
    3195         732 :                     n->strategy = PARTITION_STRATEGY_HASH;
    3196         732 :                     n->modulus = n->remainder = -1;
    3197             : 
    3198        2196 :                     foreach (lc, $5)
    3199             :                     {
    3200        1464 :                         DefElem    *opt = lfirst_node(DefElem, lc);
    3201             : 
    3202        1464 :                         if (strcmp(opt->defname, "modulus") == 0)
    3203             :                         {
    3204         732 :                             if (n->modulus != -1)
    3205           0 :                                 ereport(ERROR,
    3206             :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    3207             :                                          errmsg("modulus for hash partition provided more than once"),
    3208             :                                          parser_errposition(opt->location)));
    3209         732 :                             n->modulus = defGetInt32(opt);
    3210             :                         }
    3211         732 :                         else if (strcmp(opt->defname, "remainder") == 0)
    3212             :                         {
    3213         732 :                             if (n->remainder != -1)
    3214           0 :                                 ereport(ERROR,
    3215             :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    3216             :                                          errmsg("remainder for hash partition provided more than once"),
    3217             :                                          parser_errposition(opt->location)));
    3218         732 :                             n->remainder = defGetInt32(opt);
    3219             :                         }
    3220             :                         else
    3221           0 :                             ereport(ERROR,
    3222             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    3223             :                                      errmsg("unrecognized hash partition bound specification \"%s\"",
    3224             :                                             opt->defname),
    3225             :                                      parser_errposition(opt->location)));
    3226             :                     }
    3227             : 
    3228         732 :                     if (n->modulus == -1)
    3229           0 :                         ereport(ERROR,
    3230             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3231             :                                  errmsg("modulus for hash partition must be specified"),
    3232             :                                  parser_errposition(@3)));
    3233         732 :                     if (n->remainder == -1)
    3234           0 :                         ereport(ERROR,
    3235             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3236             :                                  errmsg("remainder for hash partition must be specified"),
    3237             :                                  parser_errposition(@3)));
    3238             : 
    3239         732 :                     n->location = @3;
    3240             : 
    3241         732 :                     $$ = n;
    3242             :                 }
    3243             : 
    3244             :             /* a LIST partition */
    3245             :             | FOR VALUES IN_P '(' expr_list ')'
    3246             :                 {
    3247        4994 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3248             : 
    3249        4994 :                     n->strategy = PARTITION_STRATEGY_LIST;
    3250        4994 :                     n->is_default = false;
    3251        4994 :                     n->listdatums = $5;
    3252        4994 :                     n->location = @3;
    3253             : 
    3254        4994 :                     $$ = n;
    3255             :                 }
    3256             : 
    3257             :             /* a RANGE partition */
    3258             :             | FOR VALUES FROM '(' expr_list ')' TO '(' expr_list ')'
    3259             :                 {
    3260        4322 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3261             : 
    3262        4322 :                     n->strategy = PARTITION_STRATEGY_RANGE;
    3263        4322 :                     n->is_default = false;
    3264        4322 :                     n->lowerdatums = $5;
    3265        4322 :                     n->upperdatums = $9;
    3266        4322 :                     n->location = @3;
    3267             : 
    3268        4322 :                     $$ = n;
    3269             :                 }
    3270             : 
    3271             :             /* a DEFAULT partition */
    3272             :             | DEFAULT
    3273             :                 {
    3274         598 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3275             : 
    3276         598 :                     n->is_default = true;
    3277         598 :                     n->location = @1;
    3278             : 
    3279         598 :                     $$ = n;
    3280             :                 }
    3281             :         ;
    3282             : 
    3283             : hash_partbound_elem:
    3284             :         NonReservedWord Iconst
    3285             :             {
    3286        1464 :                 $$ = makeDefElem($1, (Node *) makeInteger($2), @1);
    3287             :             }
    3288             :         ;
    3289             : 
    3290             : hash_partbound:
    3291             :         hash_partbound_elem
    3292             :             {
    3293         732 :                 $$ = list_make1($1);
    3294             :             }
    3295             :         | hash_partbound ',' hash_partbound_elem
    3296             :             {
    3297         732 :                 $$ = lappend($1, $3);
    3298             :             }
    3299             :         ;
    3300             : 
    3301             : /*****************************************************************************
    3302             :  *
    3303             :  *  ALTER TYPE
    3304             :  *
    3305             :  * really variants of the ALTER TABLE subcommands with different spellings
    3306             :  *****************************************************************************/
    3307             : 
    3308             : AlterCompositeTypeStmt:
    3309             :             ALTER TYPE_P any_name alter_type_cmds
    3310             :                 {
    3311         210 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    3312             : 
    3313             :                     /* can't use qualified_name, sigh */
    3314         210 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
    3315         210 :                     n->cmds = $4;
    3316         210 :                     n->objtype = OBJECT_TYPE;
    3317         210 :                     $$ = (Node *) n;
    3318             :                 }
    3319             :             ;
    3320             : 
    3321             : alter_type_cmds:
    3322         210 :             alter_type_cmd                          { $$ = list_make1($1); }
    3323          12 :             | alter_type_cmds ',' alter_type_cmd    { $$ = lappend($1, $3); }
    3324             :         ;
    3325             : 
    3326             : alter_type_cmd:
    3327             :             /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
    3328             :             ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
    3329             :                 {
    3330          64 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3331             : 
    3332          64 :                     n->subtype = AT_AddColumn;
    3333          64 :                     n->def = $3;
    3334          64 :                     n->behavior = $4;
    3335          64 :                     $$ = (Node *) n;
    3336             :                 }
    3337             :             /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
    3338             :             | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
    3339             :                 {
    3340           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3341             : 
    3342           6 :                     n->subtype = AT_DropColumn;
    3343           6 :                     n->name = $5;
    3344           6 :                     n->behavior = $6;
    3345           6 :                     n->missing_ok = true;
    3346           6 :                     $$ = (Node *) n;
    3347             :                 }
    3348             :             /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
    3349             :             | DROP ATTRIBUTE ColId opt_drop_behavior
    3350             :                 {
    3351          78 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3352             : 
    3353          78 :                     n->subtype = AT_DropColumn;
    3354          78 :                     n->name = $3;
    3355          78 :                     n->behavior = $4;
    3356          78 :                     n->missing_ok = false;
    3357          78 :                     $$ = (Node *) n;
    3358             :                 }
    3359             :             /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
    3360             :             | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
    3361             :                 {
    3362          74 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3363          74 :                     ColumnDef *def = makeNode(ColumnDef);
    3364             : 
    3365          74 :                     n->subtype = AT_AlterColumnType;
    3366          74 :                     n->name = $3;
    3367          74 :                     n->def = (Node *) def;
    3368          74 :                     n->behavior = $8;
    3369             :                     /* We only use these fields of the ColumnDef node */
    3370          74 :                     def->typeName = $6;
    3371          74 :                     def->collClause = (CollateClause *) $7;
    3372          74 :                     def->raw_default = NULL;
    3373          74 :                     def->location = @3;
    3374          74 :                     $$ = (Node *) n;
    3375             :                 }
    3376             :         ;
    3377             : 
    3378             : 
    3379             : /*****************************************************************************
    3380             :  *
    3381             :  *      QUERY :
    3382             :  *              close <portalname>
    3383             :  *
    3384             :  *****************************************************************************/
    3385             : 
    3386             : ClosePortalStmt:
    3387             :             CLOSE cursor_name
    3388             :                 {
    3389        2228 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3390             : 
    3391        2228 :                     n->portalname = $2;
    3392        2228 :                     $$ = (Node *) n;
    3393             :                 }
    3394             :             | CLOSE ALL
    3395             :                 {
    3396          12 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3397             : 
    3398          12 :                     n->portalname = NULL;
    3399          12 :                     $$ = (Node *) n;
    3400             :                 }
    3401             :         ;
    3402             : 
    3403             : 
    3404             : /*****************************************************************************
    3405             :  *
    3406             :  *      QUERY :
    3407             :  *              COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
    3408             :  *              COPY ( query ) TO file  [WITH] [(options)]
    3409             :  *
    3410             :  *              where 'query' can be one of:
    3411             :  *              { SELECT | UPDATE | INSERT | DELETE }
    3412             :  *
    3413             :  *              and 'file' can be one of:
    3414             :  *              { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
    3415             :  *
    3416             :  *              In the preferred syntax the options are comma-separated
    3417             :  *              and use generic identifiers instead of keywords.  The pre-9.0
    3418             :  *              syntax had a hard-wired, space-separated set of options.
    3419             :  *
    3420             :  *              Really old syntax, from versions 7.2 and prior:
    3421             :  *              COPY [ BINARY ] table FROM/TO file
    3422             :  *                  [ [ USING ] DELIMITERS 'delimiter' ] ]
    3423             :  *                  [ WITH NULL AS 'null string' ]
    3424             :  *              This option placement is not supported with COPY (query...).
    3425             :  *
    3426             :  *****************************************************************************/
    3427             : 
    3428             : CopyStmt:   COPY opt_binary qualified_name opt_column_list
    3429             :             copy_from opt_program copy_file_name copy_delimiter opt_with
    3430             :             copy_options where_clause
    3431             :                 {
    3432       10692 :                     CopyStmt *n = makeNode(CopyStmt);
    3433             : 
    3434       10692 :                     n->relation = $3;
    3435       10692 :                     n->query = NULL;
    3436       10692 :                     n->attlist = $4;
    3437       10692 :                     n->is_from = $5;
    3438       10692 :                     n->is_program = $6;
    3439       10692 :                     n->filename = $7;
    3440       10692 :                     n->whereClause = $11;
    3441             : 
    3442       10692 :                     if (n->is_program && n->filename == NULL)
    3443           0 :                         ereport(ERROR,
    3444             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3445             :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3446             :                                  parser_errposition(@8)));
    3447             : 
    3448       10692 :                     if (!n->is_from && n->whereClause != NULL)
    3449           6 :                         ereport(ERROR,
    3450             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3451             :                                  errmsg("WHERE clause not allowed with COPY TO"),
    3452             :                                  errhint("Try the COPY (SELECT ... WHERE ...) TO variant."),
    3453             :                                  parser_errposition(@11)));
    3454             : 
    3455       10686 :                     n->options = NIL;
    3456             :                     /* Concatenate user-supplied flags */
    3457       10686 :                     if ($2)
    3458          12 :                         n->options = lappend(n->options, $2);
    3459       10686 :                     if ($8)
    3460           0 :                         n->options = lappend(n->options, $8);
    3461       10686 :                     if ($10)
    3462         992 :                         n->options = list_concat(n->options, $10);
    3463       10686 :                     $$ = (Node *) n;
    3464             :                 }
    3465             :             | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
    3466             :                 {
    3467         608 :                     CopyStmt *n = makeNode(CopyStmt);
    3468             : 
    3469         608 :                     n->relation = NULL;
    3470         608 :                     n->query = $3;
    3471         608 :                     n->attlist = NIL;
    3472         608 :                     n->is_from = false;
    3473         608 :                     n->is_program = $6;
    3474         608 :                     n->filename = $7;
    3475         608 :                     n->options = $9;
    3476             : 
    3477         608 :                     if (n->is_program && n->filename == NULL)
    3478           0 :                         ereport(ERROR,
    3479             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3480             :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3481             :                                  parser_errposition(@5)));
    3482             : 
    3483         608 :                     $$ = (Node *) n;
    3484             :                 }
    3485             :         ;
    3486             : 
    3487             : copy_from:
    3488        1858 :             FROM                                    { $$ = true; }
    3489        8834 :             | TO                                    { $$ = false; }
    3490             :         ;
    3491             : 
    3492             : opt_program:
    3493           0 :             PROGRAM                                 { $$ = true; }
    3494       11300 :             | /* EMPTY */                           { $$ = false; }
    3495             :         ;
    3496             : 
    3497             : /*
    3498             :  * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
    3499             :  * used depends on the direction. (It really doesn't make sense to copy from
    3500             :  * stdout. We silently correct the "typo".)        - AY 9/94
    3501             :  */
    3502             : copy_file_name:
    3503         452 :             Sconst                                  { $$ = $1; }
    3504        1470 :             | STDIN                                 { $$ = NULL; }
    3505        9378 :             | STDOUT                                { $$ = NULL; }
    3506             :         ;
    3507             : 
    3508       10578 : copy_options: copy_opt_list                         { $$ = $1; }
    3509         722 :             | '(' copy_generic_opt_list ')'         { $$ = $2; }
    3510             :         ;
    3511             : 
    3512             : /* old COPY option syntax */
    3513             : copy_opt_list:
    3514         504 :             copy_opt_list copy_opt_item             { $$ = lappend($1, $2); }
    3515       10578 :             | /* EMPTY */                           { $$ = NIL; }
    3516             :         ;
    3517             : 
    3518             : copy_opt_item:
    3519             :             BINARY
    3520             :                 {
    3521           0 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3522             :                 }
    3523             :             | FREEZE
    3524             :                 {
    3525          50 :                     $$ = makeDefElem("freeze", (Node *) makeBoolean(true), @1);
    3526             :                 }
    3527             :             | DELIMITER opt_as Sconst
    3528             :                 {
    3529         172 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @1);
    3530             :                 }
    3531             :             | NULL_P opt_as Sconst
    3532             :                 {
    3533          48 :                     $$ = makeDefElem("null", (Node *) makeString($3), @1);
    3534             :                 }
    3535             :             | CSV
    3536             :                 {
    3537         150 :                     $$ = makeDefElem("format", (Node *) makeString("csv"), @1);
    3538             :                 }
    3539             :             | HEADER_P
    3540             :                 {
    3541          18 :                     $$ = makeDefElem("header", (Node *) makeBoolean(true), @1);
    3542             :                 }
    3543             :             | QUOTE opt_as Sconst
    3544             :                 {
    3545          18 :                     $$ = makeDefElem("quote", (Node *) makeString($3), @1);
    3546             :                 }
    3547             :             | ESCAPE opt_as Sconst
    3548             :                 {
    3549          18 :                     $$ = makeDefElem("escape", (Node *) makeString($3), @1);
    3550             :                 }
    3551             :             | FORCE QUOTE columnList
    3552             :                 {
    3553          12 :                     $$ = makeDefElem("force_quote", (Node *) $3, @1);
    3554             :                 }
    3555             :             | FORCE QUOTE '*'
    3556             :                 {
    3557           6 :                     $$ = makeDefElem("force_quote", (Node *) makeNode(A_Star), @1);
    3558             :                 }
    3559             :             | FORCE NOT NULL_P columnList
    3560             :                 {
    3561           0 :                     $$ = makeDefElem("force_not_null", (Node *) $4, @1);
    3562             :                 }
    3563             :             | FORCE NOT NULL_P '*'
    3564             :                 {
    3565           0 :                     $$ = makeDefElem("force_not_null", (Node *) makeNode(A_Star), @1);
    3566             :                 }
    3567             :             | FORCE NULL_P columnList
    3568             :                 {
    3569           0 :                     $$ = makeDefElem("force_null", (Node *) $3, @1);
    3570             :                 }
    3571             :             | FORCE NULL_P '*'
    3572             :                 {
    3573           0 :                     $$ = makeDefElem("force_null", (Node *) makeNode(A_Star), @1);
    3574             :                 }
    3575             :             | ENCODING Sconst
    3576             :                 {
    3577          12 :                     $$ = makeDefElem("encoding", (Node *) makeString($2), @1);
    3578             :                 }
    3579             :         ;
    3580             : 
    3581             : /* The following exist for backward compatibility with very old versions */
    3582             : 
    3583             : opt_binary:
    3584             :             BINARY
    3585             :                 {
    3586          12 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3587             :                 }
    3588       10680 :             | /*EMPTY*/                             { $$ = NULL; }
    3589             :         ;
    3590             : 
    3591             : copy_delimiter:
    3592             :             opt_using DELIMITERS Sconst
    3593             :                 {
    3594           0 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @2);
    3595             :                 }
    3596       10692 :             | /*EMPTY*/                             { $$ = NULL; }
    3597             :         ;
    3598             : 
    3599             : opt_using:
    3600             :             USING
    3601             :             | /*EMPTY*/
    3602             :         ;
    3603             : 
    3604             : /* new COPY option syntax */
    3605             : copy_generic_opt_list:
    3606             :             copy_generic_opt_elem
    3607             :                 {
    3608         722 :                     $$ = list_make1($1);
    3609             :                 }
    3610             :             | copy_generic_opt_list ',' copy_generic_opt_elem
    3611             :                 {
    3612         468 :                     $$ = lappend($1, $3);
    3613             :                 }
    3614             :         ;
    3615             : 
    3616             : copy_generic_opt_elem:
    3617             :             ColLabel copy_generic_opt_arg
    3618             :                 {
    3619        1190 :                     $$ = makeDefElem($1, $2, @1);
    3620             :                 }
    3621             :         ;
    3622             : 
    3623             : copy_generic_opt_arg:
    3624         836 :             opt_boolean_or_string           { $$ = (Node *) makeString($1); }
    3625          60 :             | NumericOnly                   { $$ = (Node *) $1; }
    3626          90 :             | '*'                           { $$ = (Node *) makeNode(A_Star); }
    3627           6 :             | DEFAULT                       { $$ = (Node *) makeString("default"); }
    3628         150 :             | '(' copy_generic_opt_arg_list ')'     { $$ = (Node *) $2; }
    3629          48 :             | /* EMPTY */                   { $$ = NULL; }
    3630             :         ;
    3631             : 
    3632             : copy_generic_opt_arg_list:
    3633             :               copy_generic_opt_arg_list_item
    3634             :                 {
    3635         150 :                     $$ = list_make1($1);
    3636             :                 }
    3637             :             | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
    3638             :                 {
    3639          12 :                     $$ = lappend($1, $3);
    3640             :                 }
    3641             :         ;
    3642             : 
    3643             : /* beware of emitting non-string list elements here; see commands/define.c */
    3644             : copy_generic_opt_arg_list_item:
    3645         162 :             opt_boolean_or_string   { $$ = (Node *) makeString($1); }
    3646             :         ;
    3647             : 
    3648             : 
    3649             : /*****************************************************************************
    3650             :  *
    3651             :  *      QUERY :
    3652             :  *              CREATE TABLE relname
    3653             :  *
    3654             :  *****************************************************************************/
    3655             : 
    3656             : CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
    3657             :             OptInherit OptPartitionSpec table_access_method_clause OptWith
    3658             :             OnCommitOption OptTableSpace
    3659             :                 {
    3660       29950 :                     CreateStmt *n = makeNode(CreateStmt);
    3661             : 
    3662       29950 :                     $4->relpersistence = $2;
    3663       29950 :                     n->relation = $4;
    3664       29950 :                     n->tableElts = $6;
    3665       29950 :                     n->inhRelations = $8;
    3666       29950 :                     n->partspec = $9;
    3667       29950 :                     n->ofTypename = NULL;
    3668       29950 :                     n->constraints = NIL;
    3669       29950 :                     n->accessMethod = $10;
    3670       29950 :                     n->options = $11;
    3671       29950 :                     n->oncommit = $12;
    3672       29950 :                     n->tablespacename = $13;
    3673       29950 :                     n->if_not_exists = false;
    3674       29950 :                     $$ = (Node *) n;
    3675             :                 }
    3676             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
    3677             :             OptTableElementList ')' OptInherit OptPartitionSpec table_access_method_clause
    3678             :             OptWith OnCommitOption OptTableSpace
    3679             :                 {
    3680          30 :                     CreateStmt *n = makeNode(CreateStmt);
    3681             : 
    3682          30 :                     $7->relpersistence = $2;
    3683          30 :                     n->relation = $7;
    3684          30 :                     n->tableElts = $9;
    3685          30 :                     n->inhRelations = $11;
    3686          30 :                     n->partspec = $12;
    3687          30 :                     n->ofTypename = NULL;
    3688          30 :                     n->constraints = NIL;
    3689          30 :                     n->accessMethod = $13;
    3690          30 :                     n->options = $14;
    3691          30 :                     n->oncommit = $15;
    3692          30 :                     n->tablespacename = $16;
    3693          30 :                     n->if_not_exists = true;
    3694          30 :                     $$ = (Node *) n;
    3695             :                 }
    3696             :         | CREATE OptTemp TABLE qualified_name OF any_name
    3697             :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3698             :             OptWith OnCommitOption OptTableSpace
    3699             :                 {
    3700         122 :                     CreateStmt *n = makeNode(CreateStmt);
    3701             : 
    3702         122 :                     $4->relpersistence = $2;
    3703         122 :                     n->relation = $4;
    3704         122 :                     n->tableElts = $7;
    3705         122 :                     n->inhRelations = NIL;
    3706         122 :                     n->partspec = $8;
    3707         122 :                     n->ofTypename = makeTypeNameFromNameList($6);
    3708         122 :                     n->ofTypename->location = @6;
    3709         122 :                     n->constraints = NIL;
    3710         122 :                     n->accessMethod = $9;
    3711         122 :                     n->options = $10;
    3712         122 :                     n->oncommit = $11;
    3713         122 :                     n->tablespacename = $12;
    3714         122 :                     n->if_not_exists = false;
    3715         122 :                     $$ = (Node *) n;
    3716             :                 }
    3717             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
    3718             :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3719             :             OptWith OnCommitOption OptTableSpace
    3720             :                 {
    3721           6 :                     CreateStmt *n = makeNode(CreateStmt);
    3722             : 
    3723           6 :                     $7->relpersistence = $2;
    3724           6 :                     n->relation = $7;
    3725           6 :                     n->tableElts = $10;
    3726           6 :                     n->inhRelations = NIL;
    3727           6 :                     n->partspec = $11;
    3728           6 :                     n->ofTypename = makeTypeNameFromNameList($9);
    3729           6 :                     n->ofTypename->location = @9;
    3730           6 :                     n->constraints = NIL;
    3731           6 :                     n->accessMethod = $12;
    3732           6 :                     n->options = $13;
    3733           6 :                     n->oncommit = $14;
    3734           6 :                     n->tablespacename = $15;
    3735           6 :                     n->if_not_exists = true;
    3736           6 :                     $$ = (Node *) n;
    3737             :                 }
    3738             :         | CREATE OptTemp TABLE qualified_name PARTITION OF qualified_name
    3739             :             OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3740             :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3741             :                 {
    3742        8114 :                     CreateStmt *n = makeNode(CreateStmt);
    3743             : 
    3744        8114 :                     $4->relpersistence = $2;
    3745        8114 :                     n->relation = $4;
    3746        8114 :                     n->tableElts = $8;
    3747        8114 :                     n->inhRelations = list_make1($7);
    3748        8114 :                     n->partbound = $9;
    3749        8114 :                     n->partspec = $10;
    3750        8114 :                     n->ofTypename = NULL;
    3751        8114 :                     n->constraints = NIL;
    3752        8114 :                     n->accessMethod = $11;
    3753        8114 :                     n->options = $12;
    3754        8114 :                     n->oncommit = $13;
    3755        8114 :                     n->tablespacename = $14;
    3756        8114 :                     n->if_not_exists = false;
    3757        8114 :                     $$ = (Node *) n;
    3758             :                 }
    3759             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name PARTITION OF
    3760             :             qualified_name OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3761             :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3762             :                 {
    3763           0 :                     CreateStmt *n = makeNode(CreateStmt);
    3764             : 
    3765           0 :                     $7->relpersistence = $2;
    3766           0 :                     n->relation = $7;
    3767           0 :                     n->tableElts = $11;
    3768           0 :                     n->inhRelations = list_make1($10);
    3769           0 :                     n->partbound = $12;
    3770           0 :                     n->partspec = $13;
    3771           0 :                     n->ofTypename = NULL;
    3772           0 :                     n->constraints = NIL;
    3773           0 :                     n->accessMethod = $14;
    3774           0 :                     n->options = $15;
    3775           0 :                     n->oncommit = $16;
    3776           0 :                     n->tablespacename = $17;
    3777           0 :                     n->if_not_exists = true;
    3778           0 :                     $$ = (Node *) n;
    3779             :                 }
    3780             :         ;
    3781             : 
    3782             : /*
    3783             :  * Redundancy here is needed to avoid shift/reduce conflicts,
    3784             :  * since TEMP is not a reserved word.  See also OptTempTableName.
    3785             :  *
    3786             :  * NOTE: we accept both GLOBAL and LOCAL options.  They currently do nothing,
    3787             :  * but future versions might consider GLOBAL to request SQL-spec-compliant
    3788             :  * temp table behavior, so warn about that.  Since we have no modules the
    3789             :  * LOCAL keyword is really meaningless; furthermore, some other products
    3790             :  * implement LOCAL as meaning the same as our default temp table behavior,
    3791             :  * so we'll probably continue to treat LOCAL as a noise word.
    3792             :  */
    3793         352 : OptTemp:    TEMPORARY                   { $$ = RELPERSISTENCE_TEMP; }
    3794        2792 :             | TEMP                      { $$ = RELPERSISTENCE_TEMP; }
    3795           0 :             | LOCAL TEMPORARY           { $$ = RELPERSISTENCE_TEMP; }
    3796           0 :             | LOCAL TEMP                { $$ = RELPERSISTENCE_TEMP; }
    3797             :             | GLOBAL TEMPORARY
    3798             :                 {
    3799           0 :                     ereport(WARNING,
    3800             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3801             :                              parser_errposition(@1)));
    3802           0 :                     $$ = RELPERSISTENCE_TEMP;
    3803             :                 }
    3804             :             | GLOBAL TEMP
    3805             :                 {
    3806           0 :                     ereport(WARNING,
    3807             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3808             :                              parser_errposition(@1)));
    3809           0 :                     $$ = RELPERSISTENCE_TEMP;
    3810             :                 }
    3811         162 :             | UNLOGGED                  { $$ = RELPERSISTENCE_UNLOGGED; }
    3812       54174 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    3813             :         ;
    3814             : 
    3815             : OptTableElementList:
    3816       28754 :             TableElementList                    { $$ = $1; }
    3817        1668 :             | /*EMPTY*/                         { $$ = NIL; }
    3818             :         ;
    3819             : 
    3820             : OptTypedTableElementList:
    3821         354 :             '(' TypedTableElementList ')'       { $$ = $2; }
    3822        7984 :             | /*EMPTY*/                         { $$ = NIL; }
    3823             :         ;
    3824             : 
    3825             : TableElementList:
    3826             :             TableElement
    3827             :                 {
    3828       28808 :                     $$ = list_make1($1);
    3829             :                 }
    3830             :             | TableElementList ',' TableElement
    3831             :                 {
    3832       40856 :                     $$ = lappend($1, $3);
    3833             :                 }
    3834             :         ;
    3835             : 
    3836             : TypedTableElementList:
    3837             :             TypedTableElement
    3838             :                 {
    3839         354 :                     $$ = list_make1($1);
    3840             :                 }
    3841             :             | TypedTableElementList ',' TypedTableElement
    3842             :                 {
    3843          68 :                     $$ = lappend($1, $3);
    3844             :                 }
    3845             :         ;
    3846             : 
    3847             : TableElement:
    3848       66132 :             columnDef                           { $$ = $1; }
    3849         774 :             | TableLikeClause                   { $$ = $1; }
    3850        2758 :             | TableConstraint                   { $$ = $1; }
    3851             :         ;
    3852             : 
    3853             : TypedTableElement:
    3854         358 :             columnOptions                       { $$ = $1; }
    3855          64 :             | TableConstraint                   { $$ = $1; }
    3856             :         ;
    3857             : 
    3858             : columnDef:  ColId Typename opt_column_storage opt_column_compression create_generic_options ColQualList
    3859             :                 {
    3860       68306 :                     ColumnDef *n = makeNode(ColumnDef);
    3861             : 
    3862       68306 :                     n->colname = $1;
    3863       68306 :                     n->typeName = $2;
    3864       68306 :                     n->storage_name = $3;
    3865       68306 :                     n->compression = $4;
    3866       68306 :                     n->inhcount = 0;
    3867       68306 :                     n->is_local = true;
    3868       68306 :                     n->is_not_null = false;
    3869       68306 :                     n->is_from_type = false;
    3870       68306 :                     n->storage = 0;
    3871       68306 :                     n->raw_default = NULL;
    3872       68306 :                     n->cooked_default = NULL;
    3873       68306 :                     n->collOid = InvalidOid;
    3874       68306 :                     n->fdwoptions = $5;
    3875       68306 :                     SplitColQualList($6, &n->constraints, &n->collClause,
    3876             :                                      yyscanner);
    3877       68306 :                     n->location = @1;
    3878       68306 :                     $$ = (Node *) n;
    3879             :                 }
    3880             :         ;
    3881             : 
    3882             : columnOptions:  ColId ColQualList
    3883             :                 {
    3884         138 :                     ColumnDef *n = makeNode(ColumnDef);
    3885             : 
    3886         138 :                     n->colname = $1;
    3887         138 :                     n->typeName = NULL;
    3888         138 :                     n->inhcount = 0;
    3889         138 :                     n->is_local = true;
    3890         138 :                     n->is_not_null = false;
    3891         138 :                     n->is_from_type = false;
    3892         138 :                     n->storage = 0;
    3893         138 :                     n->raw_default = NULL;
    3894         138 :                     n->cooked_default = NULL;
    3895         138 :                     n->collOid = InvalidOid;
    3896         138 :                     SplitColQualList($2, &n->constraints, &n->collClause,
    3897             :                                      yyscanner);
    3898         138 :                     n->location = @1;
    3899         138 :                     $$ = (Node *) n;
    3900             :                 }
    3901             :                 | ColId WITH OPTIONS ColQualList
    3902             :                 {
    3903         220 :                     ColumnDef *n = makeNode(ColumnDef);
    3904             : 
    3905         220 :                     n->colname = $1;
    3906         220 :                     n->typeName = NULL;
    3907         220 :                     n->inhcount = 0;
    3908         220 :                     n->is_local = true;
    3909         220 :                     n->is_not_null = false;
    3910         220 :                     n->is_from_type = false;
    3911         220 :                     n->storage = 0;
    3912         220 :                     n->raw_default = NULL;
    3913         220 :                     n->cooked_default = NULL;
    3914         220 :                     n->collOid = InvalidOid;
    3915         220 :                     SplitColQualList($4, &n->constraints, &n->collClause,
    3916             :                                      yyscanner);
    3917         220 :                     n->location = @1;
    3918         220 :                     $$ = (Node *) n;
    3919             :                 }
    3920             :         ;
    3921             : 
    3922             : column_compression:
    3923         166 :             COMPRESSION ColId                       { $$ = $2; }
    3924           6 :             | COMPRESSION DEFAULT                   { $$ = pstrdup("default"); }
    3925             :         ;
    3926             : 
    3927             : opt_column_compression:
    3928          94 :             column_compression                      { $$ = $1; }
    3929       68278 :             | /*EMPTY*/                             { $$ = NULL; }
    3930             :         ;
    3931             : 
    3932             : column_storage:
    3933         258 :             STORAGE ColId                           { $$ = $2; }
    3934           6 :             | STORAGE DEFAULT                       { $$ = pstrdup("default"); }
    3935             :         ;
    3936             : 
    3937             : opt_column_storage:
    3938          26 :             column_storage                          { $$ = $1; }
    3939       68346 :             | /*EMPTY*/                             { $$ = NULL; }
    3940             :         ;
    3941             : 
    3942             : ColQualList:
    3943       20164 :             ColQualList ColConstraint               { $$ = lappend($1, $2); }
    3944       70194 :             | /*EMPTY*/                             { $$ = NIL; }
    3945             :         ;
    3946             : 
    3947             : ColConstraint:
    3948             :             CONSTRAINT name ColConstraintElem
    3949             :                 {
    3950         802 :                     Constraint *n = castNode(Constraint, $3);
    3951             : 
    3952         802 :                     n->conname = $2;
    3953         802 :                     n->location = @1;
    3954         802 :                     $$ = (Node *) n;
    3955             :                 }
    3956       18294 :             | ColConstraintElem                     { $$ = $1; }
    3957         294 :             | ConstraintAttr                        { $$ = $1; }
    3958             :             | COLLATE any_name
    3959             :                 {
    3960             :                     /*
    3961             :                      * Note: the CollateClause is momentarily included in
    3962             :                      * the list built by ColQualList, but we split it out
    3963             :                      * again in SplitColQualList.
    3964             :                      */
    3965         774 :                     CollateClause *n = makeNode(CollateClause);
    3966             : 
    3967         774 :                     n->arg = NULL;
    3968         774 :                     n->collname = $2;
    3969         774 :                     n->location = @1;
    3970         774 :                     $$ = (Node *) n;
    3971             :                 }
    3972             :         ;
    3973             : 
    3974             : /* DEFAULT NULL is already the default for Postgres.
    3975             :  * But define it here and carry it forward into the system
    3976             :  * to make it explicit.
    3977             :  * - thomas 1998-09-13
    3978             :  *
    3979             :  * WITH NULL and NULL are not SQL-standard syntax elements,
    3980             :  * so leave them out. Use DEFAULT NULL to explicitly indicate
    3981             :  * that a column may have that value. WITH NULL leads to
    3982             :  * shift/reduce conflicts with WITH TIME ZONE anyway.
    3983             :  * - thomas 1999-01-08
    3984             :  *
    3985             :  * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
    3986             :  * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
    3987             :  * or be part of a_expr NOT LIKE or similar constructs).
    3988             :  */
    3989             : ColConstraintElem:
    3990             :             NOT NULL_P opt_no_inherit
    3991             :                 {
    3992        6890 :                     Constraint *n = makeNode(Constraint);
    3993             : 
    3994        6890 :                     n->contype = CONSTR_NOTNULL;
    3995        6890 :                     n->location = @1;
    3996        6890 :                     n->is_no_inherit = $3;
    3997        6890 :                     n->is_enforced = true;
    3998        6890 :                     n->skip_validation = false;
    3999        6890 :                     n->initially_valid = true;
    4000        6890 :                     $$ = (Node *) n;
    4001             :                 }
    4002             :             | NULL_P
    4003             :                 {
    4004          30 :                     Constraint *n = makeNode(Constraint);
    4005             : 
    4006          30 :                     n->contype = CONSTR_NULL;
    4007          30 :                     n->location = @1;
    4008          30 :                     $$ = (Node *) n;
    4009             :                 }
    4010             :             | UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace
    4011             :                 {
    4012         462 :                     Constraint *n = makeNode(Constraint);
    4013             : 
    4014         462 :                     n->contype = CONSTR_UNIQUE;
    4015         462 :                     n->location = @1;
    4016         462 :                     n->nulls_not_distinct = !$2;
    4017         462 :                     n->keys = NULL;
    4018         462 :                     n->options = $3;
    4019         462 :                     n->indexname = NULL;
    4020         462 :                     n->indexspace = $4;
    4021         462 :                     $$ = (Node *) n;
    4022             :                 }
    4023             :             | PRIMARY KEY opt_definition OptConsTableSpace
    4024             :                 {
    4025        5868 :                     Constraint *n = makeNode(Constraint);
    4026             : 
    4027        5868 :                     n->contype = CONSTR_PRIMARY;
    4028        5868 :                     n->location = @1;
    4029        5868 :                     n->keys = NULL;
    4030        5868 :                     n->options = $3;
    4031        5868 :                     n->indexname = NULL;
    4032        5868 :                     n->indexspace = $4;
    4033        5868 :                     $$ = (Node *) n;
    4034             :                 }
    4035             :             | CHECK '(' a_expr ')' opt_no_inherit
    4036             :                 {
    4037        1086 :                     Constraint *n = makeNode(Constraint);
    4038             : 
    4039        1086 :                     n->contype = CONSTR_CHECK;
    4040        1086 :                     n->location = @1;
    4041        1086 :                     n->is_no_inherit = $5;
    4042        1086 :                     n->raw_expr = $3;
    4043        1086 :                     n->cooked_expr = NULL;
    4044        1086 :                     n->is_enforced = true;
    4045        1086 :                     n->skip_validation = false;
    4046        1086 :                     n->initially_valid = true;
    4047        1086 :                     $$ = (Node *) n;
    4048             :                 }
    4049             :             | DEFAULT b_expr
    4050             :                 {
    4051        1850 :                     Constraint *n = makeNode(Constraint);
    4052             : 
    4053        1850 :                     n->contype = CONSTR_DEFAULT;
    4054        1850 :                     n->location = @1;
    4055        1850 :                     n->raw_expr = $2;
    4056        1850 :                     n->cooked_expr = NULL;
    4057        1850 :                     $$ = (Node *) n;
    4058             :                 }
    4059             :             | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    4060             :                 {
    4061         330 :                     Constraint *n = makeNode(Constraint);
    4062             : 
    4063         330 :                     n->contype = CONSTR_IDENTITY;
    4064         330 :                     n->generated_when = $2;
    4065         330 :                     n->options = $5;
    4066         330 :                     n->location = @1;
    4067         330 :                     $$ = (Node *) n;
    4068             :                 }
    4069             :             | GENERATED generated_when AS '(' a_expr ')' opt_virtual_or_stored
    4070             :                 {
    4071        1752 :                     Constraint *n = makeNode(Constraint);
    4072             : 
    4073        1752 :                     n->contype = CONSTR_GENERATED;
    4074        1752 :                     n->generated_when = $2;
    4075        1752 :                     n->raw_expr = $5;
    4076        1752 :                     n->cooked_expr = NULL;
    4077        1752 :                     n->generated_kind = $7;
    4078        1752 :                     n->location = @1;
    4079             : 
    4080             :                     /*
    4081             :                      * Can't do this in the grammar because of shift/reduce
    4082             :                      * conflicts.  (IDENTITY allows both ALWAYS and BY
    4083             :                      * DEFAULT, but generated columns only allow ALWAYS.)  We
    4084             :                      * can also give a more useful error message and location.
    4085             :                      */
    4086        1752 :                     if ($2 != ATTRIBUTE_IDENTITY_ALWAYS)
    4087          12 :                         ereport(ERROR,
    4088             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    4089             :                                  errmsg("for a generated column, GENERATED ALWAYS must be specified"),
    4090             :                                  parser_errposition(@2)));
    4091             : 
    4092        1740 :                     $$ = (Node *) n;
    4093             :                 }
    4094             :             | REFERENCES qualified_name opt_column_list key_match key_actions
    4095             :                 {
    4096         840 :                     Constraint *n = makeNode(Constraint);
    4097             : 
    4098         840 :                     n->contype = CONSTR_FOREIGN;
    4099         840 :                     n->location = @1;
    4100         840 :                     n->pktable = $2;
    4101         840 :                     n->fk_attrs = NIL;
    4102         840 :                     n->pk_attrs = $3;
    4103         840 :                     n->fk_matchtype = $4;
    4104         840 :                     n->fk_upd_action = ($5)->updateAction->action;
    4105         840 :                     n->fk_del_action = ($5)->deleteAction->action;
    4106         840 :                     n->fk_del_set_cols = ($5)->deleteAction->cols;
    4107         840 :                     n->is_enforced = true;
    4108         840 :                     n->skip_validation = false;
    4109         840 :                     n->initially_valid = true;
    4110         840 :                     $$ = (Node *) n;
    4111             :                 }
    4112             :         ;
    4113             : 
    4114             : opt_unique_null_treatment:
    4115          12 :             NULLS_P DISTINCT        { $$ = true; }
    4116          36 :             | NULLS_P NOT DISTINCT  { $$ = false; }
    4117        7682 :             | /*EMPTY*/             { $$ = true; }
    4118             :         ;
    4119             : 
    4120             : generated_when:
    4121        2110 :             ALWAYS          { $$ = ATTRIBUTE_IDENTITY_ALWAYS; }
    4122         182 :             | BY DEFAULT    { $$ = ATTRIBUTE_IDENTITY_BY_DEFAULT; }
    4123             :         ;
    4124             : 
    4125             : opt_virtual_or_stored:
    4126        1004 :             STORED          { $$ = ATTRIBUTE_GENERATED_STORED; }
    4127         640 :             | VIRTUAL       { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
    4128         108 :             | /*EMPTY*/     { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
    4129             :         ;
    4130             : 
    4131             : /*
    4132             :  * ConstraintAttr represents constraint attributes, which we parse as if
    4133             :  * they were independent constraint clauses, in order to avoid shift/reduce
    4134             :  * conflicts (since NOT might start either an independent NOT NULL clause
    4135             :  * or an attribute).  parse_utilcmd.c is responsible for attaching the
    4136             :  * attribute information to the preceding "real" constraint node, and for
    4137             :  * complaining if attribute clauses appear in the wrong place or wrong
    4138             :  * combinations.
    4139             :  *
    4140             :  * See also ConstraintAttributeSpec, which can be used in places where
    4141             :  * there is no parsing conflict.  (Note: currently, NOT VALID and NO INHERIT
    4142             :  * are allowed clauses in ConstraintAttributeSpec, but not here.  Someday we
    4143             :  * might need to allow them here too, but for the moment it doesn't seem
    4144             :  * useful in the statements that use ConstraintAttr.)
    4145             :  */
    4146             : ConstraintAttr:
    4147             :             DEFERRABLE
    4148             :                 {
    4149         102 :                     Constraint *n = makeNode(Constraint);
    4150             : 
    4151         102 :                     n->contype = CONSTR_ATTR_DEFERRABLE;
    4152         102 :                     n->location = @1;
    4153         102 :                     $$ = (Node *) n;
    4154             :                 }
    4155             :             | NOT DEFERRABLE
    4156             :                 {
    4157           0 :                     Constraint *n = makeNode(Constraint);
    4158             : 
    4159           0 :                     n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
    4160           0 :                     n->location = @1;
    4161           0 :                     $$ = (Node *) n;
    4162             :                 }
    4163             :             | INITIALLY DEFERRED
    4164             :                 {
    4165          78 :                     Constraint *n = makeNode(Constraint);
    4166             : 
    4167          78 :                     n->contype = CONSTR_ATTR_DEFERRED;
    4168          78 :                     n->location = @1;
    4169          78 :                     $$ = (Node *) n;
    4170             :                 }
    4171             :             | INITIALLY IMMEDIATE
    4172             :                 {
    4173           6 :                     Constraint *n = makeNode(Constraint);
    4174             : 
    4175           6 :                     n->contype = CONSTR_ATTR_IMMEDIATE;
    4176           6 :                     n->location = @1;
    4177           6 :                     $$ = (Node *) n;
    4178             :                 }
    4179             :             | ENFORCED
    4180             :                 {
    4181          42 :                     Constraint *n = makeNode(Constraint);
    4182             : 
    4183          42 :                     n->contype = CONSTR_ATTR_ENFORCED;
    4184          42 :                     n->location = @1;
    4185          42 :                     $$ = (Node *) n;
    4186             :                 }
    4187             :             | NOT ENFORCED
    4188             :                 {
    4189          66 :                     Constraint *n = makeNode(Constraint);
    4190             : 
    4191          66 :                     n->contype = CONSTR_ATTR_NOT_ENFORCED;
    4192          66 :                     n->location = @1;
    4193          66 :                     $$ = (Node *) n;
    4194             :                 }
    4195             :         ;
    4196             : 
    4197             : 
    4198             : TableLikeClause:
    4199             :             LIKE qualified_name TableLikeOptionList
    4200             :                 {
    4201         774 :                     TableLikeClause *n = makeNode(TableLikeClause);
    4202             : 
    4203         774 :                     n->relation = $2;
    4204         774 :                     n->options = $3;
    4205         774 :                     n->relationOid = InvalidOid;
    4206         774 :                     $$ = (Node *) n;
    4207             :                 }
    4208             :         ;
    4209             : 
    4210             : TableLikeOptionList:
    4211         288 :                 TableLikeOptionList INCLUDING TableLikeOption   { $$ = $1 | $3; }
    4212           8 :                 | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
    4213         774 :                 | /* EMPTY */                       { $$ = 0; }
    4214             :         ;
    4215             : 
    4216             : TableLikeOption:
    4217          30 :                 COMMENTS            { $$ = CREATE_TABLE_LIKE_COMMENTS; }
    4218           6 :                 | COMPRESSION       { $$ = CREATE_TABLE_LIKE_COMPRESSION; }
    4219          54 :                 | CONSTRAINTS       { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
    4220          20 :                 | DEFAULTS          { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
    4221          12 :                 | IDENTITY_P        { $$ = CREATE_TABLE_LIKE_IDENTITY; }
    4222          30 :                 | GENERATED         { $$ = CREATE_TABLE_LIKE_GENERATED; }
    4223          50 :                 | INDEXES           { $$ = CREATE_TABLE_LIKE_INDEXES; }
    4224           0 :                 | STATISTICS        { $$ = CREATE_TABLE_LIKE_STATISTICS; }
    4225          26 :                 | STORAGE           { $$ = CREATE_TABLE_LIKE_STORAGE; }
    4226          68 :                 | ALL               { $$ = CREATE_TABLE_LIKE_ALL; }
    4227             :         ;
    4228             : 
    4229             : 
    4230             : /* ConstraintElem specifies constraint syntax which is not embedded into
    4231             :  *  a column definition. ColConstraintElem specifies the embedded form.
    4232             :  * - thomas 1997-12-03
    4233             :  */
    4234             : TableConstraint:
    4235             :             CONSTRAINT name ConstraintElem
    4236             :                 {
    4237        4104 :                     Constraint *n = castNode(Constraint, $3);
    4238             : 
    4239        4104 :                     n->conname = $2;
    4240        4104 :                     n->location = @1;
    4241        4104 :                     $$ = (Node *) n;
    4242             :                 }
    4243       13278 :             | ConstraintElem                        { $$ = $1; }
    4244             :         ;
    4245             : 
    4246             : ConstraintElem:
    4247             :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    4248             :                 {
    4249        1268 :                     Constraint *n = makeNode(Constraint);
    4250             : 
    4251        1268 :                     n->contype = CONSTR_CHECK;
    4252        1268 :                     n->location = @1;
    4253        1268 :                     n->raw_expr = $3;
    4254        1268 :                     n->cooked_expr = NULL;
    4255        1268 :                     processCASbits($5, @5, "CHECK",
    4256             :                                    NULL, NULL, &n->is_enforced, &n->skip_validation,
    4257             :                                    &n->is_no_inherit, yyscanner);
    4258        1268 :                     n->initially_valid = !n->skip_validation;
    4259        1268 :                     $$ = (Node *) n;
    4260             :                 }
    4261             :             | NOT NULL_P ColId ConstraintAttributeSpec
    4262             :                 {
    4263         598 :                     Constraint *n = makeNode(Constraint);
    4264             : 
    4265         598 :                     n->contype = CONSTR_NOTNULL;
    4266         598 :                     n->location = @1;
    4267         598 :                     n->keys = list_make1(makeString($3));
    4268         598 :                     processCASbits($4, @4, "NOT NULL",
    4269             :                                    NULL, NULL, NULL, &n->skip_validation,
    4270             :                                    &n->is_no_inherit, yyscanner);
    4271         598 :                     n->initially_valid = !n->skip_validation;
    4272         598 :                     $$ = (Node *) n;
    4273             :                 }
    4274             :             | UNIQUE opt_unique_null_treatment '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
    4275             :                 ConstraintAttributeSpec
    4276             :                 {
    4277         598 :                     Constraint *n = makeNode(Constraint);
    4278             : 
    4279         598 :                     n->contype = CONSTR_UNIQUE;
    4280         598 :                     n->location = @1;
    4281         598 :                     n->nulls_not_distinct = !$2;
    4282         598 :                     n->keys = $4;
    4283         598 :                     n->without_overlaps = $5;
    4284         598 :                     n->including = $7;
    4285         598 :                     n->options = $8;
    4286         598 :                     n->indexname = NULL;
    4287         598 :                     n->indexspace = $9;
    4288         598 :                     processCASbits($10, @10, "UNIQUE",
    4289             :                                    &n->deferrable, &n->initdeferred, NULL,
    4290             :                                    NULL, NULL, yyscanner);
    4291         598 :                     $$ = (Node *) n;
    4292             :                 }
    4293             :             | UNIQUE ExistingIndex ConstraintAttributeSpec
    4294             :                 {
    4295        4648 :                     Constraint *n = makeNode(Constraint);
    4296             : 
    4297        4648 :                     n->contype = CONSTR_UNIQUE;
    4298        4648 :                     n->location = @1;
    4299        4648 :                     n->keys = NIL;
    4300        4648 :                     n->including = NIL;
    4301        4648 :                     n->options = NIL;
    4302        4648 :                     n->indexname = $2;
    4303        4648 :                     n->indexspace = NULL;
    4304        4648 :                     processCASbits($3, @3, "UNIQUE",
    4305             :                                    &n->deferrable, &n->initdeferred, NULL,
    4306             :                                    NULL, NULL, yyscanner);
    4307        4648 :                     $$ = (Node *) n;
    4308             :                 }
    4309             :             | PRIMARY KEY '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
    4310             :                 ConstraintAttributeSpec
    4311             :                 {
    4312        2174 :                     Constraint *n = makeNode(Constraint);
    4313             : 
    4314        2174 :                     n->contype = CONSTR_PRIMARY;
    4315        2174 :                     n->location = @1;
    4316        2174 :                     n->keys = $4;
    4317        2174 :                     n->without_overlaps = $5;
    4318        2174 :                     n->including = $7;
    4319        2174 :                     n->options = $8;
    4320        2174 :                     n->indexname = NULL;
    4321        2174 :                     n->indexspace = $9;
    4322        2174 :                     processCASbits($10, @10, "PRIMARY KEY",
    4323             :                                    &n->deferrable, &n->initdeferred, NULL,
    4324             :                                    NULL, NULL, yyscanner);
    4325        2174 :                     $$ = (Node *) n;
    4326             :                 }
    4327             :             | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
    4328             :                 {
    4329        6018 :                     Constraint *n = makeNode(Constraint);
    4330             : 
    4331        6018 :                     n->contype = CONSTR_PRIMARY;
    4332        6018 :                     n->location = @1;
    4333        6018 :                     n->keys = NIL;
    4334        6018 :                     n->including = NIL;
    4335        6018 :                     n->options = NIL;
    4336        6018 :                     n->indexname = $3;
    4337        6018 :                     n->indexspace = NULL;
    4338        6018 :                     processCASbits($4, @4, "PRIMARY KEY",
    4339             :                                    &n->deferrable, &n->initdeferred, NULL,
    4340             :                                    NULL, NULL, yyscanner);
    4341        6018 :                     $$ = (Node *) n;
    4342             :                 }
    4343             :             | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
    4344             :                 opt_c_include opt_definition OptConsTableSpace OptWhereClause
    4345             :                 ConstraintAttributeSpec
    4346             :                 {
    4347         234 :                     Constraint *n = makeNode(Constraint);
    4348             : 
    4349         234 :                     n->contype = CONSTR_EXCLUSION;
    4350         234 :                     n->location = @1;
    4351         234 :                     n->access_method = $2;
    4352         234 :                     n->exclusions = $4;
    4353         234 :                     n->including = $6;
    4354         234 :                     n->options = $7;
    4355         234 :                     n->indexname = NULL;
    4356         234 :                     n->indexspace = $8;
    4357         234 :                     n->where_clause = $9;
    4358         234 :                     processCASbits($10, @10, "EXCLUDE",
    4359             :                                    &n->deferrable, &n->initdeferred, NULL,
    4360             :                                    NULL, NULL, yyscanner);
    4361         234 :                     $$ = (Node *) n;
    4362             :                 }
    4363             :             | FOREIGN KEY '(' columnList optionalPeriodName ')' REFERENCES qualified_name
    4364             :                 opt_column_and_period_list key_match key_actions ConstraintAttributeSpec
    4365             :                 {
    4366        1844 :                     Constraint *n = makeNode(Constraint);
    4367             : 
    4368        1844 :                     n->contype = CONSTR_FOREIGN;
    4369        1844 :                     n->location = @1;
    4370        1844 :                     n->pktable = $8;
    4371        1844 :                     n->fk_attrs = $4;
    4372        1844 :                     if ($5)
    4373             :                     {
    4374         326 :                         n->fk_attrs = lappend(n->fk_attrs, $5);
    4375         326 :                         n->fk_with_period = true;
    4376             :                     }
    4377        1844 :                     n->pk_attrs = linitial($9);
    4378        1844 :                     if (lsecond($9))
    4379             :                     {
    4380         170 :                         n->pk_attrs = lappend(n->pk_attrs, lsecond($9));
    4381         170 :                         n->pk_with_period = true;
    4382             :                     }
    4383        1844 :                     n->fk_matchtype = $10;
    4384        1844 :                     n->fk_upd_action = ($11)->updateAction->action;
    4385        1844 :                     n->fk_del_action = ($11)->deleteAction->action;
    4386        1844 :                     n->fk_del_set_cols = ($11)->deleteAction->cols;
    4387        1844 :                     processCASbits($12, @12, "FOREIGN KEY",
    4388             :                                    &n->deferrable, &n->initdeferred,
    4389             :                                    &n->is_enforced, &n->skip_validation, NULL,
    4390             :                                    yyscanner);
    4391        1844 :                     n->initially_valid = !n->skip_validation;
    4392        1844 :                     $$ = (Node *) n;
    4393             :                 }
    4394             :         ;
    4395             : 
    4396             : /*
    4397             :  * DomainConstraint is separate from TableConstraint because the syntax for
    4398             :  * NOT NULL constraints is different.  For table constraints, we need to
    4399             :  * accept a column name, but for domain constraints, we don't.  (We could
    4400             :  * accept something like NOT NULL VALUE, but that seems weird.)  CREATE DOMAIN
    4401             :  * (which uses ColQualList) has for a long time accepted NOT NULL without a
    4402             :  * column name, so it makes sense that ALTER DOMAIN (which uses
    4403             :  * DomainConstraint) does as well.  None of these syntaxes are per SQL
    4404             :  * standard; we are just living with the bits of inconsistency that have built
    4405             :  * up over time.
    4406             :  */
    4407             : DomainConstraint:
    4408             :             CONSTRAINT name DomainConstraintElem
    4409             :                 {
    4410         164 :                     Constraint *n = castNode(Constraint, $3);
    4411             : 
    4412         164 :                     n->conname = $2;
    4413         164 :                     n->location = @1;
    4414         164 :                     $$ = (Node *) n;
    4415             :                 }
    4416          18 :             | DomainConstraintElem                  { $$ = $1; }
    4417             :         ;
    4418             : 
    4419             : DomainConstraintElem:
    4420             :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    4421             :                 {
    4422         164 :                     Constraint *n = makeNode(Constraint);
    4423             : 
    4424         164 :                     n->contype = CONSTR_CHECK;
    4425         164 :                     n->location = @1;
    4426         164 :                     n->raw_expr = $3;
    4427         164 :                     n->cooked_expr = NULL;
    4428         164 :                     processCASbits($5, @5, "CHECK",
    4429             :                                    NULL, NULL, NULL, &n->skip_validation,
    4430             :                                    &n->is_no_inherit, yyscanner);
    4431         152 :                     n->is_enforced = true;
    4432         152 :                     n->initially_valid = !n->skip_validation;
    4433         152 :                     $$ = (Node *) n;
    4434             :                 }
    4435             :             | NOT NULL_P ConstraintAttributeSpec
    4436             :                 {
    4437          30 :                     Constraint *n = makeNode(Constraint);
    4438             : 
    4439          30 :                     n->contype = CONSTR_NOTNULL;
    4440          30 :                     n->location = @1;
    4441          30 :                     n->keys = list_make1(makeString("value"));
    4442             :                     /* no NOT VALID, NO INHERIT support */
    4443          30 :                     processCASbits($3, @3, "NOT NULL",
    4444             :                                    NULL, NULL, NULL,
    4445             :                                    NULL, NULL, yyscanner);
    4446          30 :                     n->initially_valid = true;
    4447          30 :                     $$ = (Node *) n;
    4448             :                 }
    4449             :         ;
    4450             : 
    4451         138 : opt_no_inherit: NO INHERIT                          {  $$ = true; }
    4452        7838 :             | /* EMPTY */                           {  $$ = false; }
    4453             :         ;
    4454             : 
    4455             : opt_without_overlaps:
    4456         590 :             WITHOUT OVERLAPS                        { $$ = true; }
    4457        2182 :             | /*EMPTY*/                             { $$ = false; }
    4458             :     ;
    4459             : 
    4460             : opt_column_list:
    4461       10234 :             '(' columnList ')'                      { $$ = $2; }
    4462       42848 :             | /*EMPTY*/                             { $$ = NIL; }
    4463             :         ;
    4464             : 
    4465             : columnList:
    4466       16544 :             columnElem                              { $$ = list_make1($1); }
    4467       28550 :             | columnList ',' columnElem             { $$ = lappend($1, $3); }
    4468             :         ;
    4469             : 
    4470             : optionalPeriodName:
    4471         496 :             ',' PERIOD columnElem { $$ = $3; }
    4472        2478 :             | /*EMPTY*/               { $$ = NULL; }
    4473             :     ;
    4474             : 
    4475             : opt_column_and_period_list:
    4476        1124 :             '(' columnList optionalPeriodName ')'           { $$ = list_make2($2, $3); }
    4477         726 :             | /*EMPTY*/                             { $$ = list_make2(NIL, NULL); }
    4478             :         ;
    4479             : 
    4480             : columnElem: ColId
    4481             :                 {
    4482       45590 :                     $$ = (Node *) makeString($1);
    4483             :                 }
    4484             :         ;
    4485             : 
    4486         168 : opt_c_include:  INCLUDE '(' columnList ')'          { $$ = $3; }
    4487        2838 :              |      /* EMPTY */                     { $$ = NIL; }
    4488             :         ;
    4489             : 
    4490             : key_match:  MATCH FULL
    4491             :             {
    4492          98 :                 $$ = FKCONSTR_MATCH_FULL;
    4493             :             }
    4494             :         | MATCH PARTIAL
    4495             :             {
    4496           0 :                 ereport(ERROR,
    4497             :                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4498             :                          errmsg("MATCH PARTIAL not yet implemented"),
    4499             :                          parser_errposition(@1)));
    4500             :                 $$ = FKCONSTR_MATCH_PARTIAL;
    4501             :             }
    4502             :         | MATCH SIMPLE
    4503             :             {
    4504           6 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4505             :             }
    4506             :         | /*EMPTY*/
    4507             :             {
    4508        2586 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4509             :             }
    4510             :         ;
    4511             : 
    4512             : ExclusionConstraintList:
    4513         234 :             ExclusionConstraintElem                 { $$ = list_make1($1); }
    4514             :             | ExclusionConstraintList ',' ExclusionConstraintElem
    4515         106 :                                                     { $$ = lappend($1, $3); }
    4516             :         ;
    4517             : 
    4518             : ExclusionConstraintElem: index_elem WITH any_operator
    4519             :             {
    4520         340 :                 $$ = list_make2($1, $3);
    4521             :             }
    4522             :             /* allow OPERATOR() decoration for the benefit of ruleutils.c */
    4523             :             | index_elem WITH OPERATOR '(' any_operator ')'
    4524             :             {
    4525           0 :                 $$ = list_make2($1, $5);
    4526             :             }
    4527             :         ;
    4528             : 
    4529             : OptWhereClause:
    4530         464 :             WHERE '(' a_expr ')'                    { $$ = $3; }
    4531        1264 :             | /*EMPTY*/                             { $$ = NULL; }
    4532             :         ;
    4533             : 
    4534             : key_actions:
    4535             :             key_update
    4536             :                 {
    4537          74 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4538             : 
    4539          74 :                     n->updateAction = $1;
    4540          74 :                     n->deleteAction = palloc(sizeof(KeyAction));
    4541          74 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4542          74 :                     n->deleteAction->cols = NIL;
    4543          74 :                     $$ = n;
    4544             :                 }
    4545             :             | key_delete
    4546             :                 {
    4547         150 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4548             : 
    4549         150 :                     n->updateAction = palloc(sizeof(KeyAction));
    4550         150 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4551         150 :                     n->updateAction->cols = NIL;
    4552         150 :                     n->deleteAction = $1;
    4553         150 :                     $$ = n;
    4554             :                 }
    4555             :             | key_update key_delete
    4556             :                 {
    4557         156 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4558             : 
    4559         156 :                     n->updateAction = $1;
    4560         156 :                     n->deleteAction = $2;
    4561         156 :                     $$ = n;
    4562             :                 }
    4563             :             | key_delete key_update
    4564             :                 {
    4565         150 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4566             : 
    4567         150 :                     n->updateAction = $2;
    4568         150 :                     n->deleteAction = $1;
    4569         150 :                     $$ = n;
    4570             :                 }
    4571             :             | /*EMPTY*/
    4572             :                 {
    4573        2154 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4574             : 
    4575        2154 :                     n->updateAction = palloc(sizeof(KeyAction));
    4576        2154 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4577        2154 :                     n->updateAction->cols = NIL;
    4578        2154 :                     n->deleteAction = palloc(sizeof(KeyAction));
    4579        2154 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4580        2154 :                     n->deleteAction->cols = NIL;
    4581        2154 :                     $$ = n;
    4582             :                 }
    4583             :         ;
    4584             : 
    4585             : key_update: ON UPDATE key_action
    4586             :                 {
    4587         386 :                     if (($3)->cols)
    4588           6 :                         ereport(ERROR,
    4589             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4590             :                                  errmsg("a column list with %s is only supported for ON DELETE actions",
    4591             :                                         ($3)->action == FKCONSTR_ACTION_SETNULL ? "SET NULL" : "SET DEFAULT"),
    4592             :                                  parser_errposition(@1)));
    4593         380 :                     $$ = $3;
    4594             :                 }
    4595             :         ;
    4596             : 
    4597             : key_delete: ON DELETE_P key_action
    4598             :                 {
    4599         456 :                     $$ = $3;
    4600             :                 }
    4601             :         ;
    4602             : 
    4603             : key_action:
    4604             :             NO ACTION
    4605             :                 {
    4606          80 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4607             : 
    4608          80 :                     n->action = FKCONSTR_ACTION_NOACTION;
    4609          80 :                     n->cols = NIL;
    4610          80 :                     $$ = n;
    4611             :                 }
    4612             :             | RESTRICT
    4613             :                 {
    4614          48 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4615             : 
    4616          48 :                     n->action = FKCONSTR_ACTION_RESTRICT;
    4617          48 :                     n->cols = NIL;
    4618          48 :                     $$ = n;
    4619             :                 }
    4620             :             | CASCADE
    4621             :                 {
    4622         422 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4623             : 
    4624         422 :                     n->action = FKCONSTR_ACTION_CASCADE;
    4625         422 :                     n->cols = NIL;
    4626         422 :                     $$ = n;
    4627             :                 }
    4628             :             | SET NULL_P opt_column_list
    4629             :                 {
    4630         190 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4631             : 
    4632         190 :                     n->action = FKCONSTR_ACTION_SETNULL;
    4633         190 :                     n->cols = $3;
    4634         190 :                     $$ = n;
    4635             :                 }
    4636             :             | SET DEFAULT opt_column_list
    4637             :                 {
    4638         102 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4639             : 
    4640         102 :                     n->action = FKCONSTR_ACTION_SETDEFAULT;
    4641         102 :                     n->cols = $3;
    4642         102 :                     $$ = n;
    4643             :                 }
    4644             :         ;
    4645             : 
    4646        2132 : OptInherit: INHERITS '(' qualified_name_list ')'    { $$ = $3; }
    4647       28272 :             | /*EMPTY*/                             { $$ = NIL; }
    4648             :         ;
    4649             : 
    4650             : /* Optional partition key specification */
    4651        5106 : OptPartitionSpec: PartitionSpec { $$ = $1; }
    4652       33128 :             | /*EMPTY*/         { $$ = NULL; }
    4653             :         ;
    4654             : 
    4655             : PartitionSpec: PARTITION BY ColId '(' part_params ')'
    4656             :                 {
    4657        5112 :                     PartitionSpec *n = makeNode(PartitionSpec);
    4658             : 
    4659        5112 :                     n->strategy = parsePartitionStrategy($3, @3, yyscanner);
    4660        5106 :                     n->partParams = $5;
    4661        5106 :                     n->location = @1;
    4662             : 
    4663        5106 :                     $$ = n;
    4664             :                 }
    4665             :         ;
    4666             : 
    4667        5112 : part_params:    part_elem                       { $$ = list_make1($1); }
    4668         456 :             | part_params ',' part_elem         { $$ = lappend($1, $3); }
    4669             :         ;
    4670             : 
    4671             : part_elem: ColId opt_collate opt_qualified_name
    4672             :                 {
    4673        5264 :                     PartitionElem *n = makeNode(PartitionElem);
    4674             : 
    4675        5264 :                     n->name = $1;
    4676        5264 :                     n->expr = NULL;
    4677        5264 :                     n->collation = $2;
    4678        5264 :                     n->opclass = $3;
    4679        5264 :                     n->location = @1;
    4680        5264 :                     $$ = n;
    4681             :                 }
    4682             :             | func_expr_windowless opt_collate opt_qualified_name
    4683             :                 {
    4684         130 :                     PartitionElem *n = makeNode(PartitionElem);
    4685             : 
    4686         130 :                     n->name = NULL;
    4687         130 :                     n->expr = $1;
    4688         130 :                     n->collation = $2;
    4689         130 :                     n->opclass = $3;
    4690         130 :                     n->location = @1;
    4691         130 :                     $$ = n;
    4692             :                 }
    4693             :             | '(' a_expr ')' opt_collate opt_qualified_name
    4694             :                 {
    4695         174 :                     PartitionElem *n = makeNode(PartitionElem);
    4696             : 
    4697         174 :                     n->name = NULL;
    4698         174 :                     n->expr = $2;
    4699         174 :                     n->collation = $4;
    4700         174 :                     n->opclass = $5;
    4701         174 :                     n->location = @1;
    4702         174 :                     $$ = n;
    4703             :                 }
    4704             :         ;
    4705             : 
    4706             : table_access_method_clause:
    4707         122 :             USING name                          { $$ = $2; }
    4708       40052 :             | /*EMPTY*/                         { $$ = NULL; }
    4709             :         ;
    4710             : 
    4711             : /* WITHOUT OIDS is legacy only */
    4712             : OptWith:
    4713         754 :             WITH reloptions             { $$ = $2; }
    4714          24 :             | WITHOUT OIDS              { $$ = NIL; }
    4715       38808 :             | /*EMPTY*/                 { $$ = NIL; }
    4716             :         ;
    4717             : 
    4718          60 : OnCommitOption:  ON COMMIT DROP             { $$ = ONCOMMIT_DROP; }
    4719         104 :             | ON COMMIT DELETE_P ROWS       { $$ = ONCOMMIT_DELETE_ROWS; }
    4720          24 :             | ON COMMIT PRESERVE ROWS       { $$ = ONCOMMIT_PRESERVE_ROWS; }
    4721       39398 :             | /*EMPTY*/                     { $$ = ONCOMMIT_NOOP; }
    4722             :         ;
    4723             : 
    4724         216 : OptTableSpace:   TABLESPACE name                    { $$ = $2; }
    4725       46622 :             | /*EMPTY*/                             { $$ = NULL; }
    4726             :         ;
    4727             : 
    4728          66 : OptConsTableSpace:   USING INDEX TABLESPACE name    { $$ = $4; }
    4729        9270 :             | /*EMPTY*/                             { $$ = NULL; }
    4730             :         ;
    4731             : 
    4732       10666 : ExistingIndex:   USING INDEX name                   { $$ = $3; }
    4733             :         ;
    4734             : 
    4735             : /*****************************************************************************
    4736             :  *
    4737             :  *      QUERY :
    4738             :  *              CREATE STATISTICS [[IF NOT EXISTS] stats_name] [(stat types)]
    4739             :  *                  ON expression-list FROM from_list
    4740             :  *
    4741             :  * Note: the expectation here is that the clauses after ON are a subset of
    4742             :  * SELECT syntax, allowing for expressions and joined tables, and probably
    4743             :  * someday a WHERE clause.  Much less than that is currently implemented,
    4744             :  * but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
    4745             :  * errors as necessary at execution.
    4746             :  *
    4747             :  * Statistics name is optional unless IF NOT EXISTS is specified.
    4748             :  *
    4749             :  *****************************************************************************/
    4750             : 
    4751             : CreateStatsStmt:
    4752             :             CREATE STATISTICS opt_qualified_name
    4753             :             opt_name_list ON stats_params FROM from_list
    4754             :                 {
    4755         736 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4756             : 
    4757         736 :                     n->defnames = $3;
    4758         736 :                     n->stat_types = $4;
    4759         736 :                     n->exprs = $6;
    4760         736 :                     n->relations = $8;
    4761         736 :                     n->stxcomment = NULL;
    4762         736 :                     n->if_not_exists = false;
    4763         736 :                     $$ = (Node *) n;
    4764             :                 }
    4765             :             | CREATE STATISTICS IF_P NOT EXISTS any_name
    4766             :             opt_name_list ON stats_params FROM from_list
    4767             :                 {
    4768          12 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4769             : 
    4770          12 :                     n->defnames = $6;
    4771          12 :                     n->stat_types = $7;
    4772          12 :                     n->exprs = $9;
    4773          12 :                     n->relations = $11;
    4774          12 :                     n->stxcomment = NULL;
    4775          12 :                     n->if_not_exists = true;
    4776          12 :                     $$ = (Node *) n;
    4777             :                 }
    4778             :             ;
    4779             : 
    4780             : /*
    4781             :  * Statistics attributes can be either simple column references, or arbitrary
    4782             :  * expressions in parens.  For compatibility with index attributes permitted
    4783             :  * in CREATE INDEX, we allow an expression that's just a function call to be
    4784             :  * written without parens.
    4785             :  */
    4786             : 
    4787         760 : stats_params:   stats_param                         { $$ = list_make1($1); }
    4788         978 :             | stats_params ',' stats_param          { $$ = lappend($1, $3); }
    4789             :         ;
    4790             : 
    4791             : stats_param:    ColId
    4792             :                 {
    4793        1228 :                     $$ = makeNode(StatsElem);
    4794        1228 :                     $$->name = $1;
    4795        1228 :                     $$->expr = NULL;
    4796             :                 }
    4797             :             | func_expr_windowless
    4798             :                 {
    4799          38 :                     $$ = makeNode(StatsElem);
    4800          38 :                     $$->name = NULL;
    4801          38 :                     $$->expr = $1;
    4802             :                 }
    4803             :             | '(' a_expr ')'
    4804             :                 {
    4805         472 :                     $$ = makeNode(StatsElem);
    4806         472 :                     $$->name = NULL;
    4807         472 :                     $$->expr = $2;
    4808             :                 }
    4809             :         ;
    4810             : 
    4811             : /*****************************************************************************
    4812             :  *
    4813             :  *      QUERY :
    4814             :  *              ALTER STATISTICS [IF EXISTS] stats_name
    4815             :  *                  SET STATISTICS  <SignedIconst>
    4816             :  *
    4817             :  *****************************************************************************/
    4818             : 
    4819             : AlterStatsStmt:
    4820             :             ALTER STATISTICS any_name SET STATISTICS set_statistics_value
    4821             :                 {
    4822          20 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4823             : 
    4824          20 :                     n->defnames = $3;
    4825          20 :                     n->missing_ok = false;
    4826          20 :                     n->stxstattarget = $6;
    4827          20 :                     $$ = (Node *) n;
    4828             :                 }
    4829             :             | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
    4830             :                 {
    4831           6 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4832             : 
    4833           6 :                     n->defnames = $5;
    4834           6 :                     n->missing_ok = true;
    4835           6 :                     n->stxstattarget = $8;
    4836           6 :                     $$ = (Node *) n;
    4837             :                 }
    4838             :             ;
    4839             : 
    4840             : /*****************************************************************************
    4841             :  *
    4842             :  *      QUERY :
    4843             :  *              CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
    4844             :  *
    4845             :  *
    4846             :  * Note: SELECT ... INTO is a now-deprecated alternative for this.
    4847             :  *
    4848             :  *****************************************************************************/
    4849             : 
    4850             : CreateAsStmt:
    4851             :         CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
    4852             :                 {
    4853        1224 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4854             : 
    4855        1224 :                     ctas->query = $6;
    4856        1224 :                     ctas->into = $4;
    4857        1224 :                     ctas->objtype = OBJECT_TABLE;
    4858        1224 :                     ctas->is_select_into = false;
    4859        1224 :                     ctas->if_not_exists = false;
    4860             :                     /* cram additional flags into the IntoClause */
    4861        1224 :                     $4->rel->relpersistence = $2;
    4862        1224 :                     $4->skipData = !($7);
    4863        1224 :                     $$ = (Node *) ctas;
    4864             :                 }
    4865             :         | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
    4866             :                 {
    4867          52 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4868             : 
    4869          52 :                     ctas->query = $9;
    4870          52 :                     ctas->into = $7;
    4871          52 :                     ctas->objtype = OBJECT_TABLE;
    4872          52 :                     ctas->is_select_into = false;
    4873          52 :                     ctas->if_not_exists = true;
    4874             :                     /* cram additional flags into the IntoClause */
    4875          52 :                     $7->rel->relpersistence = $2;
    4876          52 :                     $7->skipData = !($10);
    4877          52 :                     $$ = (Node *) ctas;
    4878             :                 }
    4879             :         ;
    4880             : 
    4881             : create_as_target:
    4882             :             qualified_name opt_column_list table_access_method_clause
    4883             :             OptWith OnCommitOption OptTableSpace
    4884             :                 {
    4885        1364 :                     $$ = makeNode(IntoClause);
    4886        1364 :                     $$->rel = $1;
    4887        1364 :                     $$->colNames = $2;
    4888        1364 :                     $$->accessMethod = $3;
    4889        1364 :                     $$->options = $4;
    4890        1364 :                     $$->onCommit = $5;
    4891        1364 :                     $$->tableSpaceName = $6;
    4892        1364 :                     $$->viewQuery = NULL;
    4893        1364 :                     $$->skipData = false;        /* might get changed later */
    4894             :                 }
    4895             :         ;
    4896             : 
    4897             : opt_with_data:
    4898          36 :             WITH DATA_P                             { $$ = true; }
    4899         218 :             | WITH NO DATA_P                        { $$ = false; }
    4900        1960 :             | /*EMPTY*/                             { $$ = true; }
    4901             :         ;
    4902             : 
    4903             : 
    4904             : /*****************************************************************************
    4905             :  *
    4906             :  *      QUERY :
    4907             :  *              CREATE MATERIALIZED VIEW relname AS SelectStmt
    4908             :  *
    4909             :  *****************************************************************************/
    4910             : 
    4911             : CreateMatViewStmt:
    4912             :         CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
    4913             :                 {
    4914         534 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4915             : 
    4916         534 :                     ctas->query = $7;
    4917         534 :                     ctas->into = $5;
    4918         534 :                     ctas->objtype = OBJECT_MATVIEW;
    4919         534 :                     ctas->is_select_into = false;
    4920         534 :                     ctas->if_not_exists = false;
    4921             :                     /* cram additional flags into the IntoClause */
    4922         534 :                     $5->rel->relpersistence = $2;
    4923         534 :                     $5->skipData = !($8);
    4924         534 :                     $$ = (Node *) ctas;
    4925             :                 }
    4926             :         | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
    4927             :                 {
    4928          48 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4929             : 
    4930          48 :                     ctas->query = $10;
    4931          48 :                     ctas->into = $8;
    4932          48 :                     ctas->objtype = OBJECT_MATVIEW;
    4933          48 :                     ctas->is_select_into = false;
    4934          48 :                     ctas->if_not_exists = true;
    4935             :                     /* cram additional flags into the IntoClause */
    4936          48 :                     $8->rel->relpersistence = $2;
    4937          48 :                     $8->skipData = !($11);
    4938          48 :                     $$ = (Node *) ctas;
    4939             :                 }
    4940             :         ;
    4941             : 
    4942             : create_mv_target:
    4943             :             qualified_name opt_column_list table_access_method_clause opt_reloptions OptTableSpace
    4944             :                 {
    4945         582 :                     $$ = makeNode(IntoClause);
    4946         582 :                     $$->rel = $1;
    4947         582 :                     $$->colNames = $2;
    4948         582 :                     $$->accessMethod = $3;
    4949         582 :                     $$->options = $4;
    4950         582 :                     $$->onCommit = ONCOMMIT_NOOP;
    4951         582 :                     $$->tableSpaceName = $5;
    4952         582 :                     $$->viewQuery = NULL;        /* filled at analysis time */
    4953         582 :                     $$->skipData = false;        /* might get changed later */
    4954             :                 }
    4955             :         ;
    4956             : 
    4957           0 : OptNoLog:   UNLOGGED                    { $$ = RELPERSISTENCE_UNLOGGED; }
    4958         582 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    4959             :         ;
    4960             : 
    4961             : 
    4962             : /*****************************************************************************
    4963             :  *
    4964             :  *      QUERY :
    4965             :  *              REFRESH MATERIALIZED VIEW qualified_name
    4966             :  *
    4967             :  *****************************************************************************/
    4968             : 
    4969             : RefreshMatViewStmt:
    4970             :             REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
    4971             :                 {
    4972         268 :                     RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
    4973             : 
    4974         268 :                     n->concurrent = $4;
    4975         268 :                     n->relation = $5;
    4976         268 :                     n->skipData = !($6);
    4977         268 :                     $$ = (Node *) n;
    4978             :                 }
    4979             :         ;
    4980             : 
    4981             : 
    4982             : /*****************************************************************************
    4983             :  *
    4984             :  *      QUERY :
    4985             :  *              CREATE SEQUENCE seqname
    4986             :  *              ALTER SEQUENCE seqname
    4987             :  *
    4988             :  *****************************************************************************/
    4989             : 
    4990             : CreateSeqStmt:
    4991             :             CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
    4992             :                 {
    4993         672 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    4994             : 
    4995         672 :                     $4->relpersistence = $2;
    4996         672 :                     n->sequence = $4;
    4997         672 :                     n->options = $5;
    4998         672 :                     n->ownerId = InvalidOid;
    4999         672 :                     n->if_not_exists = false;
    5000         672 :                     $$ = (Node *) n;
    5001             :                 }
    5002             :             | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
    5003             :                 {
    5004          24 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    5005             : 
    5006          24 :                     $7->relpersistence = $2;
    5007          24 :                     n->sequence = $7;
    5008          24 :                     n->options = $8;
    5009          24 :                     n->ownerId = InvalidOid;
    5010          24 :                     n->if_not_exists = true;
    5011          24 :                     $$ = (Node *) n;
    5012             :                 }
    5013             :         ;
    5014             : 
    5015             : AlterSeqStmt:
    5016             :             ALTER SEQUENCE qualified_name SeqOptList
    5017             :                 {
    5018         184 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    5019             : 
    5020         184 :                     n->sequence = $3;
    5021         184 :                     n->options = $4;
    5022         184 :                     n->missing_ok = false;
    5023         184 :                     $$ = (Node *) n;
    5024             :                 }
    5025             :             | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
    5026             :                 {
    5027          12 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    5028             : 
    5029          12 :                     n->sequence = $5;
    5030          12 :                     n->options = $6;
    5031          12 :                     n->missing_ok = true;
    5032          12 :                     $$ = (Node *) n;
    5033             :                 }
    5034             : 
    5035             :         ;
    5036             : 
    5037         262 : OptSeqOptList: SeqOptList                           { $$ = $1; }
    5038         434 :             | /*EMPTY*/                             { $$ = NIL; }
    5039             :         ;
    5040             : 
    5041          74 : OptParenthesizedSeqOptList: '(' SeqOptList ')'      { $$ = $2; }
    5042         422 :             | /*EMPTY*/                             { $$ = NIL; }
    5043             :         ;
    5044             : 
    5045         532 : SeqOptList: SeqOptElem                              { $$ = list_make1($1); }
    5046         802 :             | SeqOptList SeqOptElem                 { $$ = lappend($1, $2); }
    5047             :         ;
    5048             : 
    5049             : SeqOptElem: AS SimpleTypename
    5050             :                 {
    5051         190 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    5052             :                 }
    5053             :             | CACHE NumericOnly
    5054             :                 {
    5055         130 :                     $$ = makeDefElem("cache", (Node *) $2, @1);
    5056             :                 }
    5057             :             | CYCLE
    5058             :                 {
    5059          34 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(true), @1);
    5060             :                 }
    5061             :             | NO CYCLE
    5062             :                 {
    5063          14 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(false), @1);
    5064             :                 }
    5065             :             | INCREMENT opt_by NumericOnly
    5066             :                 {
    5067         246 :                     $$ = makeDefElem("increment", (Node *) $3, @1);
    5068             :                 }
    5069             :             | LOGGED
    5070             :                 {
    5071           2 :                     $$ = makeDefElem("logged", NULL, @1);
    5072             :                 }
    5073             :             | MAXVALUE NumericOnly
    5074             :                 {
    5075          68 :                     $$ = makeDefElem("maxvalue", (Node *) $2, @1);
    5076             :                 }
    5077             :             | MINVALUE NumericOnly
    5078             :                 {
    5079          68 :                     $$ = makeDefElem("minvalue", (Node *) $2, @1);
    5080             :                 }
    5081             :             | NO MAXVALUE
    5082             :                 {
    5083         108 :                     $$ = makeDefElem("maxvalue", NULL, @1);
    5084             :                 }
    5085             :             | NO MINVALUE
    5086             :                 {
    5087         108 :                     $$ = makeDefElem("minvalue", NULL, @1);
    5088             :                 }
    5089             :             | OWNED BY any_name
    5090             :                 {
    5091          72 :                     $$ = makeDefElem("owned_by", (Node *) $3, @1);
    5092             :                 }
    5093             :             | SEQUENCE NAME_P any_name
    5094             :                 {
    5095          44 :                     $$ = makeDefElem("sequence_name", (Node *) $3, @1);
    5096             :                 }
    5097             :             | START opt_with NumericOnly
    5098             :                 {
    5099         236 :                     $$ = makeDefElem("start", (Node *) $3, @1);
    5100             :                 }
    5101             :             | RESTART
    5102             :                 {
    5103           6 :                     $$ = makeDefElem("restart", NULL, @1);
    5104             :                 }
    5105             :             | RESTART opt_with NumericOnly
    5106             :                 {
    5107          60 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    5108             :                 }
    5109             :             | UNLOGGED
    5110             :                 {
    5111           2 :                     $$ = makeDefElem("unlogged", NULL, @1);
    5112             :                 }
    5113             :         ;
    5114             : 
    5115             : opt_by:     BY
    5116             :             | /* EMPTY */
    5117             :       ;
    5118             : 
    5119             : NumericOnly:
    5120         324 :             FCONST                              { $$ = (Node *) makeFloat($1); }
    5121           0 :             | '+' FCONST                        { $$ = (Node *) makeFloat($2); }
    5122             :             | '-' FCONST
    5123             :                 {
    5124          20 :                     Float      *f = makeFloat($2);
    5125             : 
    5126          20 :                     doNegateFloat(f);
    5127          20 :                     $$ = (Node *) f;
    5128             :                 }
    5129       12986 :             | SignedIconst                      { $$ = (Node *) makeInteger($1); }
    5130             :         ;
    5131             : 
    5132          90 : NumericOnly_list:   NumericOnly                     { $$ = list_make1($1); }
    5133           6 :                 | NumericOnly_list ',' NumericOnly  { $$ = lappend($1, $3); }
    5134             :         ;
    5135             : 
    5136             : /*****************************************************************************
    5137             :  *
    5138             :  *      QUERIES :
    5139             :  *              CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
    5140             :  *              DROP [PROCEDURAL] LANGUAGE ...
    5141             :  *
    5142             :  *****************************************************************************/
    5143             : 
    5144             : CreatePLangStmt:
    5145             :             CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
    5146             :             {
    5147             :                 /*
    5148             :                  * We now interpret parameterless CREATE LANGUAGE as
    5149             :                  * CREATE EXTENSION.  "OR REPLACE" is silently translated
    5150             :                  * to "IF NOT EXISTS", which isn't quite the same, but
    5151             :                  * seems more useful than throwing an error.  We just
    5152             :                  * ignore TRUSTED, as the previous code would have too.
    5153             :                  */
    5154           0 :                 CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5155             : 
    5156           0 :                 n->if_not_exists = $2;
    5157           0 :                 n->extname = $6;
    5158           0 :                 n->options = NIL;
    5159           0 :                 $$ = (Node *) n;
    5160             :             }
    5161             :             | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
    5162             :               HANDLER handler_name opt_inline_handler opt_validator
    5163             :             {
    5164         142 :                 CreatePLangStmt *n = makeNode(CreatePLangStmt);
    5165             : 
    5166         142 :                 n->replace = $2;
    5167         142 :                 n->plname = $6;
    5168         142 :                 n->plhandler = $8;
    5169         142 :                 n->plinline = $9;
    5170         142 :                 n->plvalidator = $10;
    5171         142 :                 n->pltrusted = $3;
    5172         142 :                 $$ = (Node *) n;
    5173             :             }
    5174             :         ;
    5175             : 
    5176             : opt_trusted:
    5177         112 :             TRUSTED                                 { $$ = true; }
    5178          38 :             | /*EMPTY*/                             { $$ = false; }
    5179             :         ;
    5180             : 
    5181             : /* This ought to be just func_name, but that causes reduce/reduce conflicts
    5182             :  * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
    5183             :  * Work around by using simple names, instead.
    5184             :  */
    5185             : handler_name:
    5186         558 :             name                        { $$ = list_make1(makeString($1)); }
    5187           2 :             | name attrs                { $$ = lcons(makeString($1), $2); }
    5188             :         ;
    5189             : 
    5190             : opt_inline_handler:
    5191         124 :             INLINE_P handler_name                   { $$ = $2; }
    5192          18 :             | /*EMPTY*/                             { $$ = NIL; }
    5193             :         ;
    5194             : 
    5195             : validator_clause:
    5196         124 :             VALIDATOR handler_name                  { $$ = $2; }
    5197           0 :             | NO VALIDATOR                          { $$ = NIL; }
    5198             :         ;
    5199             : 
    5200             : opt_validator:
    5201         124 :             validator_clause                        { $$ = $1; }
    5202          18 :             | /*EMPTY*/                             { $$ = NIL; }
    5203             :         ;
    5204             : 
    5205             : opt_procedural:
    5206             :             PROCEDURAL
    5207             :             | /*EMPTY*/
    5208             :         ;
    5209             : 
    5210             : /*****************************************************************************
    5211             :  *
    5212             :  *      QUERY:
    5213             :  *             CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
    5214             :  *
    5215             :  *****************************************************************************/
    5216             : 
    5217             : CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
    5218             :                 {
    5219         130 :                     CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
    5220             : 
    5221         130 :                     n->tablespacename = $3;
    5222         130 :                     n->owner = $4;
    5223         130 :                     n->location = $6;
    5224         130 :                     n->options = $7;
    5225         130 :                     $$ = (Node *) n;
    5226             :                 }
    5227             :         ;
    5228             : 
    5229          10 : OptTableSpaceOwner: OWNER RoleSpec      { $$ = $2; }
    5230         120 :             | /*EMPTY */                { $$ = NULL; }
    5231             :         ;
    5232             : 
    5233             : /*****************************************************************************
    5234             :  *
    5235             :  *      QUERY :
    5236             :  *              DROP TABLESPACE <tablespace>
    5237             :  *
    5238             :  *      No need for drop behaviour as we cannot implement dependencies for
    5239             :  *      objects in other databases; we can only support RESTRICT.
    5240             :  *
    5241             :  ****************************************************************************/
    5242             : 
    5243             : DropTableSpaceStmt: DROP TABLESPACE name
    5244             :                 {
    5245          64 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    5246             : 
    5247          64 :                     n->tablespacename = $3;
    5248          64 :                     n->missing_ok = false;
    5249          64 :                     $$ = (Node *) n;
    5250             :                 }
    5251             :                 |  DROP TABLESPACE IF_P EXISTS name
    5252             :                 {
    5253           0 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    5254             : 
    5255           0 :                     n->tablespacename = $5;
    5256           0 :                     n->missing_ok = true;
    5257           0 :                     $$ = (Node *) n;
    5258             :                 }
    5259             :         ;
    5260             : 
    5261             : /*****************************************************************************
    5262             :  *
    5263             :  *      QUERY:
    5264             :  *             CREATE EXTENSION extension
    5265             :  *             [ WITH ] [ SCHEMA schema ] [ VERSION version ]
    5266             :  *
    5267             :  *****************************************************************************/
    5268             : 
    5269             : CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
    5270             :                 {
    5271         538 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5272             : 
    5273         538 :                     n->extname = $3;
    5274         538 :                     n->if_not_exists = false;
    5275         538 :                     n->options = $5;
    5276         538 :                     $$ = (Node *) n;
    5277             :                 }
    5278             :                 | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
    5279             :                 {
    5280          20 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5281             : 
    5282          20 :                     n->extname = $6;
    5283          20 :                     n->if_not_exists = true;
    5284          20 :                     n->options = $8;
    5285          20 :                     $$ = (Node *) n;
    5286             :                 }
    5287             :         ;
    5288             : 
    5289             : create_extension_opt_list:
    5290             :             create_extension_opt_list create_extension_opt_item
    5291          98 :                 { $$ = lappend($1, $2); }
    5292             :             | /* EMPTY */
    5293         558 :                 { $$ = NIL; }
    5294             :         ;
    5295             : 
    5296             : create_extension_opt_item:
    5297             :             SCHEMA name
    5298             :                 {
    5299          46 :                     $$ = makeDefElem("schema", (Node *) makeString($2), @1);
    5300             :                 }
    5301             :             | VERSION_P NonReservedWord_or_Sconst
    5302             :                 {
    5303          12 :                     $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
    5304             :                 }
    5305             :             | FROM NonReservedWord_or_Sconst
    5306             :                 {
    5307           0 :                     ereport(ERROR,
    5308             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    5309             :                              errmsg("CREATE EXTENSION ... FROM is no longer supported"),
    5310             :                              parser_errposition(@1)));
    5311             :                 }
    5312             :             | CASCADE
    5313             :                 {
    5314          40 :                     $$ = makeDefElem("cascade", (Node *) makeBoolean(true), @1);
    5315             :                 }
    5316             :         ;
    5317             : 
    5318             : /*****************************************************************************
    5319             :  *
    5320             :  * ALTER EXTENSION name UPDATE [ TO version ]
    5321             :  *
    5322             :  *****************************************************************************/
    5323             : 
    5324             : AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
    5325             :                 {
    5326          40 :                     AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
    5327             : 
    5328          40 :                     n->extname = $3;
    5329          40 :                     n->options = $5;
    5330          40 :                     $$ = (Node *) n;
    5331             :                 }
    5332             :         ;
    5333             : 
    5334             : alter_extension_opt_list:
    5335             :             alter_extension_opt_list alter_extension_opt_item
    5336          40 :                 { $$ = lappend($1, $2); }
    5337             :             | /* EMPTY */
    5338          40 :                 { $$ = NIL; }
    5339             :         ;
    5340             : 
    5341             : alter_extension_opt_item:
    5342             :             TO NonReservedWord_or_Sconst
    5343             :                 {
    5344          40 :                     $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
    5345             :                 }
    5346             :         ;
    5347             : 
    5348             : /*****************************************************************************
    5349             :  *
    5350             :  * ALTER EXTENSION name ADD/DROP object-identifier
    5351             :  *
    5352             :  *****************************************************************************/
    5353             : 
    5354             : AlterExtensionContentsStmt:
    5355             :             ALTER EXTENSION name add_drop object_type_name name
    5356             :                 {
    5357          18 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5358             : 
    5359          18 :                     n->extname = $3;
    5360          18 :                     n->action = $4;
    5361          18 :                     n->objtype = $5;
    5362          18 :                     n->object = (Node *) makeString($6);
    5363          18 :                     $$ = (Node *) n;
    5364             :                 }
    5365             :             | ALTER EXTENSION name add_drop object_type_any_name any_name
    5366             :                 {
    5367          88 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5368             : 
    5369          88 :                     n->extname = $3;
    5370          88 :                     n->action = $4;
    5371          88 :                     n->objtype = $5;
    5372          88 :                     n->object = (Node *) $6;
    5373          88 :                     $$ = (Node *) n;
    5374             :                 }
    5375             :             | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
    5376             :                 {
    5377           8 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5378             : 
    5379           8 :                     n->extname = $3;
    5380           8 :                     n->action = $4;
    5381           8 :                     n->objtype = OBJECT_AGGREGATE;
    5382           8 :                     n->object = (Node *) $6;
    5383           8 :                     $$ = (Node *) n;
    5384             :                 }
    5385             :             | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
    5386             :                 {
    5387           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5388             : 
    5389           4 :                     n->extname = $3;
    5390           4 :                     n->action = $4;
    5391           4 :                     n->objtype = OBJECT_CAST;
    5392           4 :                     n->object = (Node *) list_make2($7, $9);
    5393           4 :                     $$ = (Node *) n;
    5394             :                 }
    5395             :             | ALTER EXTENSION name add_drop DOMAIN_P Typename
    5396             :                 {
    5397           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5398             : 
    5399           0 :                     n->extname = $3;
    5400           0 :                     n->action = $4;
    5401           0 :                     n->objtype = OBJECT_DOMAIN;
    5402           0 :                     n->object = (Node *) $6;
    5403           0 :                     $$ = (Node *) n;
    5404             :                 }
    5405             :             | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
    5406             :                 {
    5407         120 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5408             : 
    5409         120 :                     n->extname = $3;
    5410         120 :                     n->action = $4;
    5411         120 :                     n->objtype = OBJECT_FUNCTION;
    5412         120 :                     n->object = (Node *) $6;
    5413         120 :                     $$ = (Node *) n;
    5414             :                 }
    5415             :             | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
    5416             :                 {
    5417          18 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5418             : 
    5419          18 :                     n->extname = $3;
    5420          18 :                     n->action = $4;
    5421          18 :                     n->objtype = OBJECT_OPERATOR;
    5422          18 :                     n->object = (Node *) $6;
    5423          18 :                     $$ = (Node *) n;
    5424             :                 }
    5425             :             | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING name
    5426             :                 {
    5427           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5428             : 
    5429           4 :                     n->extname = $3;
    5430           4 :                     n->action = $4;
    5431           4 :                     n->objtype = OBJECT_OPCLASS;
    5432           4 :                     n->object = (Node *) lcons(makeString($9), $7);
    5433           4 :                     $$ = (Node *) n;
    5434             :                 }
    5435             :             | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING name
    5436             :                 {
    5437           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5438             : 
    5439           4 :                     n->extname = $3;
    5440           4 :                     n->action = $4;
    5441           4 :                     n->objtype = OBJECT_OPFAMILY;
    5442           4 :                     n->object = (Node *) lcons(makeString($9), $7);
    5443           4 :                     $$ = (Node *) n;
    5444             :                 }
    5445             :             | ALTER EXTENSION name add_drop PROCEDURE function_with_argtypes
    5446             :                 {
    5447           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5448             : 
    5449           0 :                     n->extname = $3;
    5450           0 :                     n->action = $4;
    5451           0 :                     n->objtype = OBJECT_PROCEDURE;
    5452           0 :                     n->object = (Node *) $6;
    5453           0 :                     $$ = (Node *) n;
    5454             :                 }
    5455             :             | ALTER EXTENSION name add_drop ROUTINE function_with_argtypes
    5456             :                 {
    5457           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5458             : 
    5459           0 :                     n->extname = $3;
    5460           0 :                     n->action = $4;
    5461           0 :                     n->objtype = OBJECT_ROUTINE;
    5462           0 :                     n->object = (Node *) $6;
    5463           0 :                     $$ = (Node *) n;
    5464             :                 }
    5465             :             | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
    5466             :                 {
    5467           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5468             : 
    5469           4 :                     n->extname = $3;
    5470           4 :                     n->action = $4;
    5471           4 :                     n->objtype = OBJECT_TRANSFORM;
    5472           4 :                     n->object = (Node *) list_make2($7, makeString($9));
    5473           4 :                     $$ = (Node *) n;
    5474             :                 }
    5475             :             | ALTER EXTENSION name add_drop TYPE_P Typename
    5476             :                 {
    5477           8 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5478             : 
    5479           8 :                     n->extname = $3;
    5480           8 :                     n->action = $4;
    5481           8 :                     n->objtype = OBJECT_TYPE;
    5482           8 :                     n->object = (Node *) $6;
    5483           8 :                     $$ = (Node *) n;
    5484             :                 }
    5485             :         ;
    5486             : 
    5487             : /*****************************************************************************
    5488             :  *
    5489             :  *      QUERY:
    5490             :  *             CREATE FOREIGN DATA WRAPPER name options
    5491             :  *
    5492             :  *****************************************************************************/
    5493             : 
    5494             : CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
    5495             :                 {
    5496         208 :                     CreateFdwStmt *n = makeNode(CreateFdwStmt);
    5497             : 
    5498         208 :                     n->fdwname = $5;
    5499         208 :                     n->func_options = $6;
    5500         208 :                     n->options = $7;
    5501         208 :                     $$ = (Node *) n;
    5502             :                 }
    5503             :         ;
    5504             : 
    5505             : fdw_option:
    5506          58 :             HANDLER handler_name                { $$ = makeDefElem("handler", (Node *) $2, @1); }
    5507           0 :             | NO HANDLER                        { $$ = makeDefElem("handler", NULL, @1); }
    5508          50 :             | VALIDATOR handler_name            { $$ = makeDefElem("validator", (Node *) $2, @1); }
    5509           6 :             | NO VALIDATOR                      { $$ = makeDefElem("validator", NULL, @1); }
    5510             :         ;
    5511             : 
    5512             : fdw_options:
    5513          92 :             fdw_option                          { $$ = list_make1($1); }
    5514          22 :             | fdw_options fdw_option            { $$ = lappend($1, $2); }
    5515             :         ;
    5516             : 
    5517             : opt_fdw_options:
    5518          56 :             fdw_options                         { $$ = $1; }
    5519         244 :             | /*EMPTY*/                         { $$ = NIL; }
    5520             :         ;
    5521             : 
    5522             : /*****************************************************************************
    5523             :  *
    5524             :  *      QUERY :
    5525             :  *              ALTER FOREIGN DATA WRAPPER name options
    5526             :  *
    5527             :  ****************************************************************************/
    5528             : 
    5529             : AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
    5530             :                 {
    5531          86 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5532             : 
    5533          86 :                     n->fdwname = $5;
    5534          86 :                     n->func_options = $6;
    5535          86 :                     n->options = $7;
    5536          86 :                     $$ = (Node *) n;
    5537             :                 }
    5538             :             | ALTER FOREIGN DATA_P WRAPPER name fdw_options
    5539             :                 {
    5540          36 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5541             : 
    5542          36 :                     n->fdwname = $5;
    5543          36 :                     n->func_options = $6;
    5544          36 :                     n->options = NIL;
    5545          36 :                     $$ = (Node *) n;
    5546             :                 }
    5547             :         ;
    5548             : 
    5549             : /* Options definition for CREATE FDW, SERVER and USER MAPPING */
    5550             : create_generic_options:
    5551         746 :             OPTIONS '(' generic_option_list ')'         { $$ = $3; }
    5552       68924 :             | /*EMPTY*/                                 { $$ = NIL; }
    5553             :         ;
    5554             : 
    5555             : generic_option_list:
    5556             :             generic_option_elem
    5557             :                 {
    5558         746 :                     $$ = list_make1($1);
    5559             :                 }
    5560             :             | generic_option_list ',' generic_option_elem
    5561             :                 {
    5562         482 :                     $$ = lappend($1, $3);
    5563             :                 }
    5564             :         ;
    5565             : 
    5566             : /* Options definition for ALTER FDW, SERVER and USER MAPPING */
    5567             : alter_generic_options:
    5568         508 :             OPTIONS '(' alter_generic_option_list ')'       { $$ = $3; }
    5569             :         ;
    5570             : 
    5571             : alter_generic_option_list:
    5572             :             alter_generic_option_elem
    5573             :                 {
    5574         508 :                     $$ = list_make1($1);
    5575             :                 }
    5576             :             | alter_generic_option_list ',' alter_generic_option_elem
    5577             :                 {
    5578         168 :                     $$ = lappend($1, $3);
    5579             :                 }
    5580             :         ;
    5581             : 
    5582             : alter_generic_option_elem:
    5583             :             generic_option_elem
    5584             :                 {
    5585         200 :                     $$ = $1;
    5586             :                 }
    5587             :             | SET generic_option_elem
    5588             :                 {
    5589         128 :                     $$ = $2;
    5590         128 :                     $$->defaction = DEFELEM_SET;
    5591             :                 }
    5592             :             | ADD_P generic_option_elem
    5593             :                 {
    5594         220 :                     $$ = $2;
    5595         220 :                     $$->defaction = DEFELEM_ADD;
    5596             :                 }
    5597             :             | DROP generic_option_name
    5598             :                 {
    5599         128 :                     $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP, @2);
    5600             :                 }
    5601             :         ;
    5602             : 
    5603             : generic_option_elem:
    5604             :             generic_option_name generic_option_arg
    5605             :                 {
    5606        1776 :                     $$ = makeDefElem($1, $2, @1);
    5607             :                 }
    5608             :         ;
    5609             : 
    5610             : generic_option_name:
    5611        1904 :                 ColLabel            { $$ = $1; }
    5612             :         ;
    5613             : 
    5614             : /* We could use def_arg here, but the spec only requires string literals */
    5615             : generic_option_arg:
    5616        1776 :                 Sconst              { $$ = (Node *) makeString($1); }
    5617             :         ;
    5618             : 
    5619             : /*****************************************************************************
    5620             :  *
    5621             :  *      QUERY:
    5622             :  *             CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
    5623             :  *
    5624             :  *****************************************************************************/
    5625             : 
    5626             : CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
    5627             :                          FOREIGN DATA_P WRAPPER name create_generic_options
    5628             :                 {
    5629         274 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5630             : 
    5631         274 :                     n->servername = $3;
    5632         274 :                     n->servertype = $4;
    5633         274 :                     n->version = $5;
    5634         274 :                     n->fdwname = $9;
    5635         274 :                     n->options = $10;
    5636         274 :                     n->if_not_exists = false;
    5637         274 :                     $$ = (Node *) n;
    5638             :                 }
    5639             :                 | CREATE SERVER IF_P NOT EXISTS name opt_type opt_foreign_server_version
    5640             :                          FOREIGN DATA_P WRAPPER name create_generic_options
    5641             :                 {
    5642          24 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5643             : 
    5644          24 :                     n->servername = $6;
    5645          24 :                     n->servertype = $7;
    5646          24 :                     n->version = $8;
    5647          24 :                     n->fdwname = $12;
    5648          24 :                     n->options = $13;
    5649          24 :                     n->if_not_exists = true;
    5650          24 :                     $$ = (Node *) n;
    5651             :                 }
    5652             :         ;
    5653             : 
    5654             : opt_type:
    5655          18 :             TYPE_P Sconst           { $$ = $2; }
    5656         280 :             | /*EMPTY*/             { $$ = NULL; }
    5657             :         ;
    5658             : 
    5659             : 
    5660             : foreign_server_version:
    5661          66 :             VERSION_P Sconst        { $$ = $2; }
    5662           0 :         |   VERSION_P NULL_P        { $$ = NULL; }
    5663             :         ;
    5664             : 
    5665             : opt_foreign_server_version:
    5666          18 :             foreign_server_version  { $$ = $1; }
    5667         280 :             | /*EMPTY*/             { $$ = NULL; }
    5668             :         ;
    5669             : 
    5670             : /*****************************************************************************
    5671             :  *
    5672             :  *      QUERY :
    5673             :  *              ALTER SERVER name [VERSION] [OPTIONS]
    5674             :  *
    5675             :  ****************************************************************************/
    5676             : 
    5677             : AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
    5678             :                 {
    5679           6 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5680             : 
    5681           6 :                     n->servername = $3;
    5682           6 :                     n->version = $4;
    5683           6 :                     n->options = $5;
    5684           6 :                     n->has_version = true;
    5685           6 :                     $$ = (Node *) n;
    5686             :                 }
    5687             :             | ALTER SERVER name foreign_server_version
    5688             :                 {
    5689          42 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5690             : 
    5691          42 :                     n->servername = $3;
    5692          42 :                     n->version = $4;
    5693          42 :                     n->has_version = true;
    5694          42 :                     $$ = (Node *) n;
    5695             :                 }
    5696             :             | ALTER SERVER name alter_generic_options
    5697             :                 {
    5698         184 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5699             : 
    5700         184 :                     n->servername = $3;
    5701         184 :                     n->options = $4;
    5702         184 :                     $$ = (Node *) n;
    5703             :                 }
    5704             :         ;
    5705             : 
    5706             : /*****************************************************************************
    5707             :  *
    5708             :  *      QUERY:
    5709             :  *             CREATE FOREIGN TABLE relname (...) SERVER name (...)
    5710             :  *
    5711             :  *****************************************************************************/
    5712             : 
    5713             : CreateForeignTableStmt:
    5714             :         CREATE FOREIGN TABLE qualified_name
    5715             :             '(' OptTableElementList ')'
    5716             :             OptInherit SERVER name create_generic_options
    5717             :                 {
    5718         400 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5719             : 
    5720         400 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5721         400 :                     n->base.relation = $4;
    5722         400 :                     n->base.tableElts = $6;
    5723         400 :                     n->base.inhRelations = $8;
    5724         400 :                     n->base.ofTypename = NULL;
    5725         400 :                     n->base.constraints = NIL;
    5726         400 :                     n->base.options = NIL;
    5727         400 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5728         400 :                     n->base.tablespacename = NULL;
    5729         400 :                     n->base.if_not_exists = false;
    5730             :                     /* FDW-specific data */
    5731         400 :                     n->servername = $10;
    5732         400 :                     n->options = $11;
    5733         400 :                     $$ = (Node *) n;
    5734             :                 }
    5735             :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5736             :             '(' OptTableElementList ')'
    5737             :             OptInherit SERVER name create_generic_options
    5738             :                 {
    5739           0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5740             : 
    5741           0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5742           0 :                     n->base.relation = $7;
    5743           0 :                     n->base.tableElts = $9;
    5744           0 :                     n->base.inhRelations = $11;
    5745           0 :                     n->base.ofTypename = NULL;
    5746           0 :                     n->base.constraints = NIL;
    5747           0 :                     n->base.options = NIL;
    5748           0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5749           0 :                     n->base.tablespacename = NULL;
    5750           0 :                     n->base.if_not_exists = true;
    5751             :                     /* FDW-specific data */
    5752           0 :                     n->servername = $13;
    5753           0 :                     n->options = $14;
    5754           0 :                     $$ = (Node *) n;
    5755             :                 }
    5756             :         | CREATE FOREIGN TABLE qualified_name
    5757             :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5758             :             SERVER name create_generic_options
    5759             :                 {
    5760          90 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5761             : 
    5762          90 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5763          90 :                     n->base.relation = $4;
    5764          90 :                     n->base.inhRelations = list_make1($7);
    5765          90 :                     n->base.tableElts = $8;
    5766          90 :                     n->base.partbound = $9;
    5767          90 :                     n->base.ofTypename = NULL;
    5768          90 :                     n->base.constraints = NIL;
    5769          90 :                     n->base.options = NIL;
    5770          90 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5771          90 :                     n->base.tablespacename = NULL;
    5772          90 :                     n->base.if_not_exists = false;
    5773             :                     /* FDW-specific data */
    5774          90 :                     n->servername = $11;
    5775          90 :                     n->options = $12;
    5776          90 :                     $$ = (Node *) n;
    5777             :                 }
    5778             :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5779             :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5780             :             SERVER name create_generic_options
    5781             :                 {
    5782           0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5783             : 
    5784           0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5785           0 :                     n->base.relation = $7;
    5786           0 :                     n->base.inhRelations = list_make1($10);
    5787           0 :                     n->base.tableElts = $11;
    5788           0 :                     n->base.partbound = $12;
    5789           0 :                     n->base.ofTypename = NULL;
    5790           0 :                     n->base.constraints = NIL;
    5791           0 :                     n->base.options = NIL;
    5792           0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5793           0 :                     n->base.tablespacename = NULL;
    5794           0 :                     n->base.if_not_exists = true;
    5795             :                     /* FDW-specific data */
    5796           0 :                     n->servername = $14;
    5797           0 :                     n->options = $15;
    5798           0 :                     $$ = (Node *) n;
    5799             :                 }
    5800             :         ;
    5801             : 
    5802             : /*****************************************************************************
    5803             :  *
    5804             :  *      QUERY:
    5805             :  *              IMPORT FOREIGN SCHEMA remote_schema
    5806             :  *              [ { LIMIT TO | EXCEPT } ( table_list ) ]
    5807             :  *              FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
    5808             :  *
    5809             :  ****************************************************************************/
    5810             : 
    5811             : ImportForeignSchemaStmt:
    5812             :         IMPORT_P FOREIGN SCHEMA name import_qualification
    5813             :           FROM SERVER name INTO name create_generic_options
    5814             :             {
    5815          48 :                 ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
    5816             : 
    5817          48 :                 n->server_name = $8;
    5818          48 :                 n->remote_schema = $4;
    5819          48 :                 n->local_schema = $10;
    5820          48 :                 n->list_type = $5->type;
    5821          48 :                 n->table_list = $5->table_names;
    5822          48 :                 n->options = $11;
    5823          48 :                 $$ = (Node *) n;
    5824             :             }
    5825             :         ;
    5826             : 
    5827             : import_qualification_type:
    5828          14 :         LIMIT TO                { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
    5829          14 :         | EXCEPT                { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
    5830             :         ;
    5831             : 
    5832             : import_qualification:
    5833             :         import_qualification_type '(' relation_expr_list ')'
    5834             :             {
    5835          28 :                 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
    5836             : 
    5837          28 :                 n->type = $1;
    5838          28 :                 n->table_names = $3;
    5839          28 :                 $$ = n;
    5840             :             }
    5841             :         | /*EMPTY*/
    5842             :             {
    5843          20 :                 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
    5844          20 :                 n->type = FDW_IMPORT_SCHEMA_ALL;
    5845          20 :                 n->table_names = NIL;
    5846          20 :                 $$ = n;
    5847             :             }
    5848             :         ;
    5849             : 
    5850             : /*****************************************************************************
    5851             :  *
    5852             :  *      QUERY:
    5853             :  *             CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
    5854             :  *
    5855             :  *****************************************************************************/
    5856             : 
    5857             : CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
    5858             :                 {
    5859         248 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5860             : 
    5861         248 :                     n->user = $5;
    5862         248 :                     n->servername = $7;
    5863         248 :                     n->options = $8;
    5864         248 :                     n->if_not_exists = false;
    5865         248 :                     $$ = (Node *) n;
    5866             :                 }
    5867             :                 | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
    5868             :                 {
    5869           6 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5870             : 
    5871           6 :                     n->user = $8;
    5872           6 :                     n->servername = $10;
    5873           6 :                     n->options = $11;
    5874           6 :                     n->if_not_exists = true;
    5875           6 :                     $$ = (Node *) n;
    5876             :                 }
    5877             :         ;
    5878             : 
    5879             : /* User mapping authorization identifier */
    5880         452 : auth_ident: RoleSpec            { $$ = $1; }
    5881          46 :             | USER              { $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1); }
    5882             :         ;
    5883             : 
    5884             : /*****************************************************************************
    5885             :  *
    5886             :  *      QUERY :
    5887             :  *              DROP USER MAPPING FOR auth_ident SERVER name
    5888             :  *
    5889             :  * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
    5890             :  * only pro forma; but the SQL standard doesn't show one.
    5891             :  ****************************************************************************/
    5892             : 
    5893             : DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
    5894             :                 {
    5895          88 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5896             : 
    5897          88 :                     n->user = $5;
    5898          88 :                     n->servername = $7;
    5899          88 :                     n->missing_ok = false;
    5900          88 :                     $$ = (Node *) n;
    5901             :                 }
    5902             :                 |  DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
    5903             :                 {
    5904          38 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5905             : 
    5906          38 :                     n->user = $7;
    5907          38 :                     n->servername = $9;
    5908          38 :                     n->missing_ok = true;
    5909          38 :                     $$ = (Node *) n;
    5910             :                 }
    5911             :         ;
    5912             : 
    5913             : /*****************************************************************************
    5914             :  *
    5915             :  *      QUERY :
    5916             :  *              ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
    5917             :  *
    5918             :  ****************************************************************************/
    5919             : 
    5920             : AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
    5921             :                 {
    5922         118 :                     AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
    5923             : 
    5924         118 :                     n->user = $5;
    5925         118 :                     n->servername = $7;
    5926         118 :                     n->options = $8;
    5927         118 :                     $$ = (Node *) n;
    5928             :                 }
    5929             :         ;
    5930             : 
    5931             : /*****************************************************************************
    5932             :  *
    5933             :  *      QUERIES:
    5934             :  *              CREATE POLICY name ON table
    5935             :  *                  [AS { PERMISSIVE | RESTRICTIVE } ]
    5936             :  *                  [FOR { SELECT | INSERT | UPDATE | DELETE } ]
    5937             :  *                  [TO role, ...]
    5938             :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    5939             :  *              ALTER POLICY name ON table [TO role, ...]
    5940             :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    5941             :  *
    5942             :  *****************************************************************************/
    5943             : 
    5944             : CreatePolicyStmt:
    5945             :             CREATE POLICY name ON qualified_name RowSecurityDefaultPermissive
    5946             :                 RowSecurityDefaultForCmd RowSecurityDefaultToRole
    5947             :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    5948             :                 {
    5949         736 :                     CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
    5950             : 
    5951         736 :                     n->policy_name = $3;
    5952         736 :                     n->table = $5;
    5953         736 :                     n->permissive = $6;
    5954         736 :                     n->cmd_name = $7;
    5955         736 :                     n->roles = $8;
    5956         736 :                     n->qual = $9;
    5957         736 :                     n->with_check = $10;
    5958         736 :                     $$ = (Node *) n;
    5959             :                 }
    5960             :         ;
    5961             : 
    5962             : AlterPolicyStmt:
    5963             :             ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
    5964             :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    5965             :                 {
    5966          84 :                     AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
    5967             : 
    5968          84 :                     n->policy_name = $3;
    5969          84 :                     n->table = $5;
    5970          84 :                     n->roles = $6;
    5971          84 :                     n->qual = $7;
    5972          84 :                     n->with_check = $8;
    5973          84 :                     $$ = (Node *) n;
    5974             :                 }
    5975             :         ;
    5976             : 
    5977             : RowSecurityOptionalExpr:
    5978         762 :             USING '(' a_expr ')'    { $$ = $3; }
    5979          58 :             | /* EMPTY */           { $$ = NULL; }
    5980             :         ;
    5981             : 
    5982             : RowSecurityOptionalWithCheck:
    5983         122 :             WITH CHECK '(' a_expr ')'       { $$ = $4; }
    5984         698 :             | /* EMPTY */                   { $$ = NULL; }
    5985             :         ;
    5986             : 
    5987             : RowSecurityDefaultToRole:
    5988         130 :             TO role_list            { $$ = $2; }
    5989         606 :             | /* EMPTY */           { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
    5990             :         ;
    5991             : 
    5992             : RowSecurityOptionalToRole:
    5993          12 :             TO role_list            { $$ = $2; }
    5994          72 :             | /* EMPTY */           { $$ = NULL; }
    5995             :         ;
    5996             : 
    5997             : RowSecurityDefaultPermissive:
    5998             :             AS IDENT
    5999             :                 {
    6000          98 :                     if (strcmp($2, "permissive") == 0)
    6001          24 :                         $$ = true;
    6002          74 :                     else if (strcmp($2, "restrictive") == 0)
    6003          68 :                         $$ = false;
    6004             :                     else
    6005           6 :                         ereport(ERROR,
    6006             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6007             :                                  errmsg("unrecognized row security option \"%s\"", $2),
    6008             :                                  errhint("Only PERMISSIVE or RESTRICTIVE policies are supported currently."),
    6009             :                                  parser_errposition(@2)));
    6010             : 
    6011             :                 }
    6012         644 :             | /* EMPTY */           { $$ = true; }
    6013             :         ;
    6014             : 
    6015             : RowSecurityDefaultForCmd:
    6016         320 :             FOR row_security_cmd    { $$ = $2; }
    6017         416 :             | /* EMPTY */           { $$ = "all"; }
    6018             :         ;
    6019             : 
    6020             : row_security_cmd:
    6021          44 :             ALL             { $$ = "all"; }
    6022         112 :         |   SELECT          { $$ = "select"; }
    6023          44 :         |   INSERT          { $$ = "insert"; }
    6024          78 :         |   UPDATE          { $$ = "update"; }
    6025          42 :         |   DELETE_P        { $$ = "delete"; }
    6026             :         ;
    6027             : 
    6028             : /*****************************************************************************
    6029             :  *
    6030             :  *      QUERY:
    6031             :  *             CREATE ACCESS METHOD name HANDLER handler_name
    6032             :  *
    6033             :  *****************************************************************************/
    6034             : 
    6035             : CreateAmStmt: CREATE ACCESS METHOD name TYPE_P am_type HANDLER handler_name
    6036             :                 {
    6037          62 :                     CreateAmStmt *n = makeNode(CreateAmStmt);
    6038             : 
    6039          62 :                     n->amname = $4;
    6040          62 :                     n->handler_name = $8;
    6041          62 :                     n->amtype = $6;
    6042          62 :                     $$ = (Node *) n;
    6043             :                 }
    6044             :         ;
    6045             : 
    6046             : am_type:
    6047          34 :             INDEX           { $$ = AMTYPE_INDEX; }
    6048          28 :         |   TABLE           { $$ = AMTYPE_TABLE; }
    6049             :         ;
    6050             : 
    6051             : /*****************************************************************************
    6052             :  *
    6053             :  *      QUERIES :
    6054             :  *              CREATE TRIGGER ...
    6055             :  *
    6056             :  *****************************************************************************/
    6057             : 
    6058             : CreateTrigStmt:
    6059             :             CREATE opt_or_replace TRIGGER name TriggerActionTime TriggerEvents ON
    6060             :             qualified_name TriggerReferencing TriggerForSpec TriggerWhen
    6061             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    6062             :                 {
    6063        3168 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    6064             : 
    6065        3168 :                     n->replace = $2;
    6066        3168 :                     n->isconstraint = false;
    6067        3168 :                     n->trigname = $4;
    6068        3168 :                     n->relation = $8;
    6069        3168 :                     n->funcname = $14;
    6070        3168 :                     n->args = $16;
    6071        3168 :                     n->row = $10;
    6072        3168 :                     n->timing = $5;
    6073        3168 :                     n->events = intVal(linitial($6));
    6074        3168 :                     n->columns = (List *) lsecond($6);
    6075        3168 :                     n->whenClause = $11;
    6076        3168 :                     n->transitionRels = $9;
    6077        3168 :                     n->deferrable = false;
    6078        3168 :                     n->initdeferred = false;
    6079        3168 :                     n->constrrel = NULL;
    6080        3168 :                     $$ = (Node *) n;
    6081             :                 }
    6082             :           | CREATE opt_or_replace CONSTRAINT TRIGGER name AFTER TriggerEvents ON
    6083             :             qualified_name OptConstrFromTable ConstraintAttributeSpec
    6084             :             FOR EACH ROW TriggerWhen
    6085             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    6086             :                 {
    6087          80 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    6088             :                     bool        dummy;
    6089             : 
    6090          80 :                     if (($11 & CAS_NOT_VALID) != 0)
    6091           6 :                         ereport(ERROR,
    6092             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6093             :                                 errmsg("constraint triggers cannot be marked %s",
    6094             :                                        "NOT VALID"),
    6095             :                                 parser_errposition(@11));
    6096          74 :                     if (($11 & CAS_NO_INHERIT) != 0)
    6097           6 :                         ereport(ERROR,
    6098             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6099             :                                 errmsg("constraint triggers cannot be marked %s",
    6100             :                                        "NO INHERIT"),
    6101             :                                 parser_errposition(@11));
    6102          68 :                     if (($11 & CAS_NOT_ENFORCED) != 0)
    6103           6 :                         ereport(ERROR,
    6104             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6105             :                                 errmsg("constraint triggers cannot be marked %s",
    6106             :                                        "NOT ENFORCED"),
    6107             :                                 parser_errposition(@11));
    6108             : 
    6109          62 :                     n->replace = $2;
    6110          62 :                     if (n->replace) /* not supported, see CreateTrigger */
    6111           0 :                         ereport(ERROR,
    6112             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6113             :                                  errmsg("CREATE OR REPLACE CONSTRAINT TRIGGER is not supported"),
    6114             :                                  parser_errposition(@1)));
    6115          62 :                     n->isconstraint = true;
    6116          62 :                     n->trigname = $5;
    6117          62 :                     n->relation = $9;
    6118          62 :                     n->funcname = $18;
    6119          62 :                     n->args = $20;
    6120          62 :                     n->row = true;
    6121          62 :                     n->timing = TRIGGER_TYPE_AFTER;
    6122          62 :                     n->events = intVal(linitial($7));
    6123          62 :                     n->columns = (List *) lsecond($7);
    6124          62 :                     n->whenClause = $15;
    6125          62 :                     n->transitionRels = NIL;
    6126          62 :                     processCASbits($11, @11, "TRIGGER",
    6127             :                                    &n->deferrable, &n->initdeferred, &dummy,
    6128             :                                    NULL, NULL, yyscanner);
    6129          62 :                     n->constrrel = $10;
    6130          62 :                     $$ = (Node *) n;
    6131             :                 }
    6132             :         ;
    6133             : 
    6134             : TriggerActionTime:
    6135        1436 :             BEFORE                              { $$ = TRIGGER_TYPE_BEFORE; }
    6136        1600 :             | AFTER                             { $$ = TRIGGER_TYPE_AFTER; }
    6137         144 :             | INSTEAD OF                        { $$ = TRIGGER_TYPE_INSTEAD; }
    6138             :         ;
    6139             : 
    6140             : TriggerEvents:
    6141             :             TriggerOneEvent
    6142        3260 :                 { $$ = $1; }
    6143             :             | TriggerEvents OR TriggerOneEvent
    6144             :                 {
    6145        1156 :                     int         events1 = intVal(linitial($1));
    6146        1156 :                     int         events2 = intVal(linitial($3));
    6147        1156 :                     List       *columns1 = (List *) lsecond($1);
    6148        1156 :                     List       *columns2 = (List *) lsecond($3);
    6149             : 
    6150        1156 :                     if (events1 & events2)
    6151           6 :                         parser_yyerror("duplicate trigger events specified");
    6152             :                     /*
    6153             :                      * concat'ing the columns lists loses information about
    6154             :                      * which columns went with which event, but so long as
    6155             :                      * only UPDATE carries columns and we disallow multiple
    6156             :                      * UPDATE items, it doesn't matter.  Command execution
    6157             :                      * should just ignore the columns for non-UPDATE events.
    6158             :                      */
    6159        1150 :                     $$ = list_make2(makeInteger(events1 | events2),
    6160             :                                     list_concat(columns1, columns2));
    6161             :                 }
    6162             :         ;
    6163             : 
    6164             : TriggerOneEvent:
    6165             :             INSERT
    6166        1674 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
    6167             :             | DELETE_P
    6168         886 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
    6169             :             | UPDATE
    6170        1718 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
    6171             :             | UPDATE OF columnList
    6172         100 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
    6173             :             | TRUNCATE
    6174          38 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
    6175             :         ;
    6176             : 
    6177             : TriggerReferencing:
    6178         464 :             REFERENCING TriggerTransitions          { $$ = $2; }
    6179        2704 :             | /*EMPTY*/                             { $$ = NIL; }
    6180             :         ;
    6181             : 
    6182             : TriggerTransitions:
    6183         464 :             TriggerTransition                       { $$ = list_make1($1); }
    6184         142 :             | TriggerTransitions TriggerTransition  { $$ = lappend($1, $2); }
    6185             :         ;
    6186             : 
    6187             : TriggerTransition:
    6188             :             TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
    6189             :                 {
    6190         606 :                     TriggerTransition *n = makeNode(TriggerTransition);
    6191             : 
    6192         606 :                     n->name = $4;
    6193         606 :                     n->isNew = $1;
    6194         606 :                     n->isTable = $2;
    6195         606 :                     $$ = (Node *) n;
    6196             :                 }
    6197             :         ;
    6198             : 
    6199             : TransitionOldOrNew:
    6200         330 :             NEW                                     { $$ = true; }
    6201         276 :             | OLD                                   { $$ = false; }
    6202             :         ;
    6203             : 
    6204             : TransitionRowOrTable:
    6205         606 :             TABLE                                   { $$ = true; }
    6206             :             /*
    6207             :              * According to the standard, lack of a keyword here implies ROW.
    6208             :              * Support for that would require prohibiting ROW entirely here,
    6209             :              * reserving the keyword ROW, and/or requiring AS (instead of
    6210             :              * allowing it to be optional, as the standard specifies) as the
    6211             :              * next token.  Requiring ROW seems cleanest and easiest to
    6212             :              * explain.
    6213             :              */
    6214           0 :             | ROW                                   { $$ = false; }
    6215             :         ;
    6216             : 
    6217             : TransitionRelName:
    6218         606 :             ColId                                   { $$ = $1; }
    6219             :         ;
    6220             : 
    6221             : TriggerForSpec:
    6222             :             FOR TriggerForOptEach TriggerForType
    6223             :                 {
    6224        2928 :                     $$ = $3;
    6225             :                 }
    6226             :             | /* EMPTY */
    6227             :                 {
    6228             :                     /*
    6229             :                      * If ROW/STATEMENT not specified, default to
    6230             :                      * STATEMENT, per SQL
    6231             :                      */
    6232         240 :                     $$ = false;
    6233             :                 }
    6234             :         ;
    6235             : 
    6236             : TriggerForOptEach:
    6237             :             EACH
    6238             :             | /*EMPTY*/
    6239             :         ;
    6240             : 
    6241             : TriggerForType:
    6242        2108 :             ROW                                     { $$ = true; }
    6243         820 :             | STATEMENT                             { $$ = false; }
    6244             :         ;
    6245             : 
    6246             : TriggerWhen:
    6247         190 :             WHEN '(' a_expr ')'                     { $$ = $3; }
    6248        3058 :             | /*EMPTY*/                             { $$ = NULL; }
    6249             :         ;
    6250             : 
    6251             : FUNCTION_or_PROCEDURE:
    6252             :             FUNCTION
    6253             :         |   PROCEDURE
    6254             :         ;
    6255             : 
    6256             : TriggerFuncArgs:
    6257         546 :             TriggerFuncArg                          { $$ = list_make1($1); }
    6258         162 :             | TriggerFuncArgs ',' TriggerFuncArg    { $$ = lappend($1, $3); }
    6259        2702 :             | /*EMPTY*/                             { $$ = NIL; }
    6260             :         ;
    6261             : 
    6262             : TriggerFuncArg:
    6263             :             Iconst
    6264             :                 {
    6265          94 :                     $$ = (Node *) makeString(psprintf("%d", $1));
    6266             :                 }
    6267           0 :             | FCONST                                { $$ = (Node *) makeString($1); }
    6268         592 :             | Sconst                                { $$ = (Node *) makeString($1); }
    6269          22 :             | ColLabel                              { $$ = (Node *) makeString($1); }
    6270             :         ;
    6271             : 
    6272             : OptConstrFromTable:
    6273          12 :             FROM qualified_name                     { $$ = $2; }
    6274          68 :             | /*EMPTY*/                             { $$ = NULL; }
    6275             :         ;
    6276             : 
    6277             : ConstraintAttributeSpec:
    6278             :             /*EMPTY*/
    6279       17908 :                 { $$ = 0; }
    6280             :             | ConstraintAttributeSpec ConstraintAttributeElem
    6281             :                 {
    6282             :                     /*
    6283             :                      * We must complain about conflicting options.
    6284             :                      * We could, but choose not to, complain about redundant
    6285             :                      * options (ie, where $2's bit is already set in $1).
    6286             :                      */
    6287        1682 :                     int     newspec = $1 | $2;
    6288             : 
    6289             :                     /* special message for this case */
    6290        1682 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
    6291           6 :                         ereport(ERROR,
    6292             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6293             :                                  errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
    6294             :                                  parser_errposition(@2)));
    6295             :                     /* generic message for other conflicts */
    6296        1676 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
    6297        1676 :                         (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED) ||
    6298        1676 :                         (newspec & (CAS_NOT_ENFORCED | CAS_ENFORCED)) == (CAS_NOT_ENFORCED | CAS_ENFORCED))
    6299           6 :                         ereport(ERROR,
    6300             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6301             :                                  errmsg("conflicting constraint properties"),
    6302             :                                  parser_errposition(@2)));
    6303        1670 :                     $$ = newspec;
    6304             :                 }
    6305             :         ;
    6306             : 
    6307             : ConstraintAttributeElem:
    6308          42 :             NOT DEFERRABLE                  { $$ = CAS_NOT_DEFERRABLE; }
    6309         200 :             | DEFERRABLE                    { $$ = CAS_DEFERRABLE; }
    6310          30 :             | INITIALLY IMMEDIATE           { $$ = CAS_INITIALLY_IMMEDIATE; }
    6311         152 :             | INITIALLY DEFERRED            { $$ = CAS_INITIALLY_DEFERRED; }
    6312         732 :             | NOT VALID                     { $$ = CAS_NOT_VALID; }
    6313         250 :             | NO INHERIT                    { $$ = CAS_NO_INHERIT; }
    6314         168 :             | NOT ENFORCED                  { $$ = CAS_NOT_ENFORCED; }
    6315         108 :             | ENFORCED                      { $$ = CAS_ENFORCED; }
    6316             :         ;
    6317             : 
    6318             : 
    6319             : /*****************************************************************************
    6320             :  *
    6321             :  *      QUERIES :
    6322             :  *              CREATE EVENT TRIGGER ...
    6323             :  *              ALTER EVENT TRIGGER ...
    6324             :  *
    6325             :  *****************************************************************************/
    6326             : 
    6327             : CreateEventTrigStmt:
    6328             :             CREATE EVENT TRIGGER name ON ColLabel
    6329             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    6330             :                 {
    6331         102 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6332             : 
    6333         102 :                     n->trigname = $4;
    6334         102 :                     n->eventname = $6;
    6335         102 :                     n->whenclause = NULL;
    6336         102 :                     n->funcname = $9;
    6337         102 :                     $$ = (Node *) n;
    6338             :                 }
    6339             :           | CREATE EVENT TRIGGER name ON ColLabel
    6340             :             WHEN event_trigger_when_list
    6341             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    6342             :                 {
    6343          98 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6344             : 
    6345          98 :                     n->trigname = $4;
    6346          98 :                     n->eventname = $6;
    6347          98 :                     n->whenclause = $8;
    6348          98 :                     n->funcname = $11;
    6349          98 :                     $$ = (Node *) n;
    6350             :                 }
    6351             :         ;
    6352             : 
    6353             : event_trigger_when_list:
    6354             :           event_trigger_when_item
    6355          98 :             { $$ = list_make1($1); }
    6356             :         | event_trigger_when_list AND event_trigger_when_item
    6357           6 :             { $$ = lappend($1, $3); }
    6358             :         ;
    6359             : 
    6360             : event_trigger_when_item:
    6361             :         ColId IN_P '(' event_trigger_value_list ')'
    6362         104 :             { $$ = makeDefElem($1, (Node *) $4, @1); }
    6363             :         ;
    6364             : 
    6365             : event_trigger_value_list:
    6366             :           SCONST
    6367         104 :             { $$ = list_make1(makeString($1)); }
    6368             :         | event_trigger_value_list ',' SCONST
    6369          66 :             { $$ = lappend($1, makeString($3)); }
    6370             :         ;
    6371             : 
    6372             : AlterEventTrigStmt:
    6373             :             ALTER EVENT TRIGGER name enable_trigger
    6374             :                 {
    6375          48 :                     AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
    6376             : 
    6377          48 :                     n->trigname = $4;
    6378          48 :                     n->tgenabled = $5;
    6379          48 :                     $$ = (Node *) n;
    6380             :                 }
    6381             :         ;
    6382             : 
    6383             : enable_trigger:
    6384           6 :             ENABLE_P                    { $$ = TRIGGER_FIRES_ON_ORIGIN; }
    6385           6 :             | ENABLE_P REPLICA          { $$ = TRIGGER_FIRES_ON_REPLICA; }
    6386          16 :             | ENABLE_P ALWAYS           { $$ = TRIGGER_FIRES_ALWAYS; }
    6387          20 :             | DISABLE_P                 { $$ = TRIGGER_DISABLED; }
    6388             :         ;
    6389             : 
    6390             : /*****************************************************************************
    6391             :  *
    6392             :  *      QUERY :
    6393             :  *              CREATE ASSERTION ...
    6394             :  *
    6395             :  *****************************************************************************/
    6396             : 
    6397             : CreateAssertionStmt:
    6398             :             CREATE ASSERTION any_name CHECK '(' a_expr ')' ConstraintAttributeSpec
    6399             :                 {
    6400           0 :                     ereport(ERROR,
    6401             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6402             :                              errmsg("CREATE ASSERTION is not yet implemented"),
    6403             :                              parser_errposition(@1)));
    6404             : 
    6405             :                     $$ = NULL;
    6406             :                 }
    6407             :         ;
    6408             : 
    6409             : 
    6410             : /*****************************************************************************
    6411             :  *
    6412             :  *      QUERY :
    6413             :  *              define (aggregate,operator,type)
    6414             :  *
    6415             :  *****************************************************************************/
    6416             : 
    6417             : DefineStmt:
    6418             :             CREATE opt_or_replace AGGREGATE func_name aggr_args definition
    6419             :                 {
    6420         544 :                     DefineStmt *n = makeNode(DefineStmt);
    6421             : 
    6422         544 :                     n->kind = OBJECT_AGGREGATE;
    6423         544 :                     n->oldstyle = false;
    6424         544 :                     n->replace = $2;
    6425         544 :                     n->defnames = $4;
    6426         544 :                     n->args = $5;
    6427         544 :                     n->definition = $6;
    6428         544 :                     $$ = (Node *) n;
    6429             :                 }
    6430             :             | CREATE opt_or_replace AGGREGATE func_name old_aggr_definition
    6431             :                 {
    6432             :                     /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
    6433         362 :                     DefineStmt *n = makeNode(DefineStmt);
    6434             : 
    6435         362 :                     n->kind = OBJECT_AGGREGATE;
    6436         362 :                     n->oldstyle = true;
    6437         362 :                     n->replace = $2;
    6438         362 :                     n->defnames = $4;
    6439         362 :                     n->args = NIL;
    6440         362 :                     n->definition = $5;
    6441         362 :                     $$ = (Node *) n;
    6442             :                 }
    6443             :             | CREATE OPERATOR any_operator definition
    6444             :                 {
    6445        1642 :                     DefineStmt *n = makeNode(DefineStmt);
    6446             : 
    6447        1642 :                     n->kind = OBJECT_OPERATOR;
    6448        1642 :                     n->oldstyle = false;
    6449        1642 :                     n->defnames = $3;
    6450        1642 :                     n->args = NIL;
    6451        1642 :                     n->definition = $4;
    6452        1642 :                     $$ = (Node *) n;
    6453             :                 }
    6454             :             | CREATE TYPE_P any_name definition
    6455             :                 {
    6456         240 :                     DefineStmt *n = makeNode(DefineStmt);
    6457             : 
    6458         240 :                     n->kind = OBJECT_TYPE;
    6459         240 :                     n->oldstyle = false;
    6460         240 :                     n->defnames = $3;
    6461         240 :                     n->args = NIL;
    6462         240 :                     n->definition = $4;
    6463         240 :                     $$ = (Node *) n;
    6464             :                 }
    6465             :             | CREATE TYPE_P any_name
    6466             :                 {
    6467             :                     /* Shell type (identified by lack of definition) */
    6468         156 :                     DefineStmt *n = makeNode(DefineStmt);
    6469             : 
    6470         156 :                     n->kind = OBJECT_TYPE;
    6471         156 :                     n->oldstyle = false;
    6472         156 :                     n->defnames = $3;
    6473         156 :                     n->args = NIL;
    6474         156 :                     n->definition = NIL;
    6475         156 :                     $$ = (Node *) n;
    6476             :                 }
    6477             :             | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
    6478             :                 {
    6479        4502 :                     CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
    6480             : 
    6481             :                     /* can't use qualified_name, sigh */
    6482        4502 :                     n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
    6483        4502 :                     n->coldeflist = $6;
    6484        4502 :                     $$ = (Node *) n;
    6485             :                 }
    6486             :             | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
    6487             :                 {
    6488         208 :                     CreateEnumStmt *n = makeNode(CreateEnumStmt);
    6489             : 
    6490         208 :                     n->typeName = $3;
    6491         208 :                     n->vals = $7;
    6492         208 :                     $$ = (Node *) n;
    6493             :                 }
    6494             :             | CREATE TYPE_P any_name AS RANGE definition
    6495             :                 {
    6496         184 :                     CreateRangeStmt *n = makeNode(CreateRangeStmt);
    6497             : 
    6498         184 :                     n->typeName = $3;
    6499         184 :                     n->params = $6;
    6500         184 :                     $$ = (Node *) n;
    6501             :                 }
    6502             :             | CREATE TEXT_P SEARCH PARSER any_name definition
    6503             :                 {
    6504          40 :                     DefineStmt *n = makeNode(DefineStmt);
    6505             : 
    6506          40 :                     n->kind = OBJECT_TSPARSER;
    6507          40 :                     n->args = NIL;
    6508          40 :                     n->defnames = $5;
    6509          40 :                     n->definition = $6;
    6510          40 :                     $$ = (Node *) n;
    6511             :                 }
    6512             :             | CREATE TEXT_P SEARCH DICTIONARY any_name definition
    6513             :                 {
    6514        2930 :                     DefineStmt *n = makeNode(DefineStmt);
    6515             : 
    6516        2930 :                     n->kind = OBJECT_TSDICTIONARY;
    6517        2930 :                     n->args = NIL;
    6518        2930 :                     n->defnames = $5;
    6519        2930 :                     n->definition = $6;
    6520        2930 :                     $$ = (Node *) n;
    6521             :                 }
    6522             :             | CREATE TEXT_P SEARCH TEMPLATE any_name definition
    6523             :                 {
    6524         140 :                     DefineStmt *n = makeNode(DefineStmt);
    6525             : 
    6526         140 :                     n->kind = OBJECT_TSTEMPLATE;
    6527         140 :                     n->args = NIL;
    6528         140 :                     n->defnames = $5;
    6529         140 :                     n->definition = $6;
    6530         140 :                     $$ = (Node *) n;
    6531             :                 }
    6532             :             | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
    6533             :                 {
    6534        2872 :                     DefineStmt *n = makeNode(DefineStmt);
    6535             : 
    6536        2872 :                     n->kind = OBJECT_TSCONFIGURATION;
    6537        2872 :                     n->args = NIL;
    6538        2872 :                     n->defnames = $5;
    6539        2872 :                     n->definition = $6;
    6540        2872 :                     $$ = (Node *) n;
    6541             :                 }
    6542             :             | CREATE COLLATION any_name definition
    6543             :                 {
    6544         292 :                     DefineStmt *n = makeNode(DefineStmt);
    6545             : 
    6546         292 :                     n->kind = OBJECT_COLLATION;
    6547         292 :                     n->args = NIL;
    6548         292 :                     n->defnames = $3;
    6549         292 :                     n->definition = $4;
    6550         292 :                     $$ = (Node *) n;
    6551             :                 }
    6552             :             | CREATE COLLATION IF_P NOT EXISTS any_name definition
    6553             :                 {
    6554          18 :                     DefineStmt *n = makeNode(DefineStmt);
    6555             : 
    6556          18 :                     n->kind = OBJECT_COLLATION;
    6557          18 :                     n->args = NIL;
    6558          18 :                     n->defnames = $6;
    6559          18 :                     n->definition = $7;
    6560          18 :                     n->if_not_exists = true;
    6561          18 :                     $$ = (Node *) n;
    6562             :                 }
    6563             :             | CREATE COLLATION any_name FROM any_name
    6564             :                 {
    6565          54 :                     DefineStmt *n = makeNode(DefineStmt);
    6566             : 
    6567          54 :                     n->kind = OBJECT_COLLATION;
    6568          54 :                     n->args = NIL;
    6569          54 :                     n->defnames = $3;
    6570          54 :                     n->definition = list_make1(makeDefElem("from", (Node *) $5, @5));
    6571          54 :                     $$ = (Node *) n;
    6572             :                 }
    6573             :             | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
    6574             :                 {
    6575           0 :                     DefineStmt *n = makeNode(DefineStmt);
    6576             : 
    6577           0 :                     n->kind = OBJECT_COLLATION;
    6578           0 :                     n->args = NIL;
    6579           0 :                     n->defnames = $6;
    6580           0 :                     n->definition = list_make1(makeDefElem("from", (Node *) $8, @8));
    6581           0 :                     n->if_not_exists = true;
    6582           0 :                     $$ = (Node *) n;
    6583             :                 }
    6584             :         ;
    6585             : 
    6586        9970 : definition: '(' def_list ')'                        { $$ = $2; }
    6587             :         ;
    6588             : 
    6589        9970 : def_list:   def_elem                                { $$ = list_make1($1); }
    6590       14814 :             | def_list ',' def_elem                 { $$ = lappend($1, $3); }
    6591             :         ;
    6592             : 
    6593             : def_elem:   ColLabel '=' def_arg
    6594             :                 {
    6595       24446 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6596             :                 }
    6597             :             | ColLabel
    6598             :                 {
    6599         338 :                     $$ = makeDefElem($1, NULL, @1);
    6600             :                 }
    6601             :         ;
    6602             : 
    6603             : /* Note: any simple identifier will be returned as a type name! */
    6604       19732 : def_arg:    func_type                       { $$ = (Node *) $1; }
    6605        4128 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
    6606        1176 :             | qual_all_Op                   { $$ = (Node *) $1; }
    6607        1334 :             | NumericOnly                   { $$ = (Node *) $1; }
    6608        1906 :             | Sconst                        { $$ = (Node *) makeString($1); }
    6609         182 :             | NONE                          { $$ = (Node *) makeString(pstrdup($1)); }
    6610             :         ;
    6611             : 
    6612         362 : old_aggr_definition: '(' old_aggr_list ')'          { $$ = $2; }
    6613             :         ;
    6614             : 
    6615         362 : old_aggr_list: old_aggr_elem                        { $$ = list_make1($1); }
    6616        1292 :             | old_aggr_list ',' old_aggr_elem       { $$ = lappend($1, $3); }
    6617             :         ;
    6618             : 
    6619             : /*
    6620             :  * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
    6621             :  * the item names needed in old aggregate definitions are likely to become
    6622             :  * SQL keywords.
    6623             :  */
    6624             : old_aggr_elem:  IDENT '=' def_arg
    6625             :                 {
    6626        1654 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6627             :                 }
    6628             :         ;
    6629             : 
    6630             : opt_enum_val_list:
    6631         200 :         enum_val_list                           { $$ = $1; }
    6632           8 :         | /*EMPTY*/                             { $$ = NIL; }
    6633             :         ;
    6634             : 
    6635             : enum_val_list:  Sconst
    6636         200 :                 { $$ = list_make1(makeString($1)); }
    6637             :             | enum_val_list ',' Sconst
    6638       10420 :                 { $$ = lappend($1, makeString($3)); }
    6639             :         ;
    6640             : 
    6641             : /*****************************************************************************
    6642             :  *
    6643             :  *  ALTER TYPE enumtype ADD ...
    6644             :  *
    6645             :  *****************************************************************************/
    6646             : 
    6647             : AlterEnumStmt:
    6648             :         ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
    6649             :             {
    6650         154 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6651             : 
    6652         154 :                 n->typeName = $3;
    6653         154 :                 n->oldVal = NULL;
    6654         154 :                 n->newVal = $7;
    6655         154 :                 n->newValNeighbor = NULL;
    6656         154 :                 n->newValIsAfter = true;
    6657         154 :                 n->skipIfNewValExists = $6;
    6658         154 :                 $$ = (Node *) n;
    6659             :             }
    6660             :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
    6661             :             {
    6662         196 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6663             : 
    6664         196 :                 n->typeName = $3;
    6665         196 :                 n->oldVal = NULL;
    6666         196 :                 n->newVal = $7;
    6667         196 :                 n->newValNeighbor = $9;
    6668         196 :                 n->newValIsAfter = false;
    6669         196 :                 n->skipIfNewValExists = $6;
    6670         196 :                 $$ = (Node *) n;
    6671             :             }
    6672             :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
    6673             :             {
    6674          22 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6675             : 
    6676          22 :                 n->typeName = $3;
    6677          22 :                 n->oldVal = NULL;
    6678          22 :                 n->newVal = $7;
    6679          22 :                 n->newValNeighbor = $9;
    6680          22 :                 n->newValIsAfter = true;
    6681          22 :                 n->skipIfNewValExists = $6;
    6682          22 :                 $$ = (Node *) n;
    6683             :             }
    6684             :          | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
    6685             :             {
    6686          24 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6687             : 
    6688          24 :                 n->typeName = $3;
    6689          24 :                 n->oldVal = $6;
    6690          24 :                 n->newVal = $8;
    6691          24 :                 n->newValNeighbor = NULL;
    6692          24 :                 n->newValIsAfter = false;
    6693          24 :                 n->skipIfNewValExists = false;
    6694          24 :                 $$ = (Node *) n;
    6695             :             }
    6696             :          | ALTER TYPE_P any_name DROP VALUE_P Sconst
    6697             :             {
    6698             :                 /*
    6699             :                  * The following problems must be solved before this can be
    6700             :                  * implemented:
    6701             :                  *
    6702             :                  * - There must be no instance of the target value in
    6703             :                  *   any table.
    6704             :                  *
    6705             :                  * - The value must not appear in any catalog metadata,
    6706             :                  *   such as stored view expressions or column defaults.
    6707             :                  *
    6708             :                  * - The value must not appear in any non-leaf page of a
    6709             :                  *   btree (and similar issues with other index types).
    6710             :                  *   This is problematic because a value could persist
    6711             :                  *   there long after it's gone from user-visible data.
    6712             :                  *
    6713             :                  * - Concurrent sessions must not be able to insert the
    6714             :                  *   value while the preceding conditions are being checked.
    6715             :                  *
    6716             :                  * - Possibly more...
    6717             :                  */
    6718           0 :                 ereport(ERROR,
    6719             :                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6720             :                          errmsg("dropping an enum value is not implemented"),
    6721             :                          parser_errposition(@4)));
    6722             :             }
    6723             :          ;
    6724             : 
    6725          12 : opt_if_not_exists: IF_P NOT EXISTS              { $$ = true; }
    6726         360 :         | /* EMPTY */                          { $$ = false; }
    6727             :         ;
    6728             : 
    6729             : 
    6730             : /*****************************************************************************
    6731             :  *
    6732             :  *      QUERIES :
    6733             :  *              CREATE OPERATOR CLASS ...
    6734             :  *              CREATE OPERATOR FAMILY ...
    6735             :  *              ALTER OPERATOR FAMILY ...
    6736             :  *              DROP OPERATOR CLASS ...
    6737             :  *              DROP OPERATOR FAMILY ...
    6738             :  *
    6739             :  *****************************************************************************/
    6740             : 
    6741             : CreateOpClassStmt:
    6742             :             CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
    6743             :             USING name opt_opfamily AS opclass_item_list
    6744             :                 {
    6745         556 :                     CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
    6746             : 
    6747         556 :                     n->opclassname = $4;
    6748         556 :                     n->isDefault = $5;
    6749         556 :                     n->datatype = $8;
    6750         556 :                     n->amname = $10;
    6751         556 :                     n->opfamilyname = $11;
    6752         556 :                     n->items = $13;
    6753         556 :                     $$ = (Node *) n;
    6754             :                 }
    6755             :         ;
    6756             : 
    6757             : opclass_item_list:
    6758        1412 :             opclass_item                            { $$ = list_make1($1); }
    6759        5388 :             | opclass_item_list ',' opclass_item    { $$ = lappend($1, $3); }
    6760             :         ;
    6761             : 
    6762             : opclass_item:
    6763             :             OPERATOR Iconst any_operator opclass_purpose
    6764             :                 {
    6765        1866 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6766        1866 :                     ObjectWithArgs *owa = makeNode(ObjectWithArgs);
    6767             : 
    6768        1866 :                     owa->objname = $3;
    6769        1866 :                     owa->objargs = NIL;
    6770        1866 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6771        1866 :                     n->name = owa;
    6772        1866 :                     n->number = $2;
    6773        1866 :                     n->order_family = $4;
    6774        1866 :                     $$ = (Node *) n;
    6775             :                 }
    6776             :             | OPERATOR Iconst operator_with_argtypes opclass_purpose
    6777             :                 {
    6778        1570 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6779             : 
    6780        1570 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6781        1570 :                     n->name = $3;
    6782        1570 :                     n->number = $2;
    6783        1570 :                     n->order_family = $4;
    6784        1570 :                     $$ = (Node *) n;
    6785             :                 }
    6786             :             | FUNCTION Iconst function_with_argtypes
    6787             :                 {
    6788        2414 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6789             : 
    6790        2414 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6791        2414 :                     n->name = $3;
    6792        2414 :                     n->number = $2;
    6793        2414 :                     $$ = (Node *) n;
    6794             :                 }
    6795             :             | FUNCTION Iconst '(' type_list ')' function_with_argtypes
    6796             :                 {
    6797         590 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6798             : 
    6799         590 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6800         590 :                     n->name = $6;
    6801         590 :                     n->number = $2;
    6802         590 :                     n->class_args = $4;
    6803         590 :                     $$ = (Node *) n;
    6804             :                 }
    6805             :             | STORAGE Typename
    6806             :                 {
    6807         360 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6808             : 
    6809         360 :                     n->itemtype = OPCLASS_ITEM_STORAGETYPE;
    6810         360 :                     n->storedtype = $2;
    6811         360 :                     $$ = (Node *) n;
    6812             :                 }
    6813             :         ;
    6814             : 
    6815         452 : opt_default:    DEFAULT                     { $$ = true; }
    6816         168 :             | /*EMPTY*/                     { $$ = false; }
    6817             :         ;
    6818             : 
    6819          44 : opt_opfamily:   FAMILY any_name             { $$ = $2; }
    6820         512 :             | /*EMPTY*/                     { $$ = NIL; }
    6821             :         ;
    6822             : 
    6823           0 : opclass_purpose: FOR SEARCH                 { $$ = NIL; }
    6824         120 :             | FOR ORDER BY any_name         { $$ = $4; }
    6825        3316 :             | /*EMPTY*/                     { $$ = NIL; }
    6826             :         ;
    6827             : 
    6828             : 
    6829             : CreateOpFamilyStmt:
    6830             :             CREATE OPERATOR FAMILY any_name USING name
    6831             :                 {
    6832         148 :                     CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
    6833             : 
    6834         148 :                     n->opfamilyname = $4;
    6835         148 :                     n->amname = $6;
    6836         148 :                     $$ = (Node *) n;
    6837             :                 }
    6838             :         ;
    6839             : 
    6840             : AlterOpFamilyStmt:
    6841             :             ALTER OPERATOR FAMILY any_name USING name ADD_P opclass_item_list
    6842             :                 {
    6843         856 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6844             : 
    6845         856 :                     n->opfamilyname = $4;
    6846         856 :                     n->amname = $6;
    6847         856 :                     n->isDrop = false;
    6848         856 :                     n->items = $8;
    6849         856 :                     $$ = (Node *) n;
    6850             :                 }
    6851             :             | ALTER OPERATOR FAMILY any_name USING name DROP opclass_drop_list
    6852             :                 {
    6853          64 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6854             : 
    6855          64 :                     n->opfamilyname = $4;
    6856          64 :                     n->amname = $6;
    6857          64 :                     n->isDrop = true;
    6858          64 :                     n->items = $8;
    6859          64 :                     $$ = (Node *) n;
    6860             :                 }
    6861             :         ;
    6862             : 
    6863             : opclass_drop_list:
    6864          64 :             opclass_drop                            { $$ = list_make1($1); }
    6865          30 :             | opclass_drop_list ',' opclass_drop    { $$ = lappend($1, $3); }
    6866             :         ;
    6867             : 
    6868             : opclass_drop:
    6869             :             OPERATOR Iconst '(' type_list ')'
    6870             :                 {
    6871          56 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6872             : 
    6873          56 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6874          56 :                     n->number = $2;
    6875          56 :                     n->class_args = $4;
    6876          56 :                     $$ = (Node *) n;
    6877             :                 }
    6878             :             | FUNCTION Iconst '(' type_list ')'
    6879             :                 {
    6880          38 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6881             : 
    6882          38 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6883          38 :                     n->number = $2;
    6884          38 :                     n->class_args = $4;
    6885          38 :                     $$ = (Node *) n;
    6886             :                 }
    6887             :         ;
    6888             : 
    6889             : 
    6890             : DropOpClassStmt:
    6891             :             DROP OPERATOR CLASS any_name USING name opt_drop_behavior
    6892             :                 {
    6893          38 :                     DropStmt *n = makeNode(DropStmt);
    6894             : 
    6895          38 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6896          38 :                     n->removeType = OBJECT_OPCLASS;
    6897          38 :                     n->behavior = $7;
    6898          38 :                     n->missing_ok = false;
    6899          38 :                     n->concurrent = false;
    6900          38 :                     $$ = (Node *) n;
    6901             :                 }
    6902             :             | DROP OPERATOR CLASS IF_P EXISTS any_name USING name opt_drop_behavior
    6903             :                 {
    6904          18 :                     DropStmt *n = makeNode(DropStmt);
    6905             : 
    6906          18 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6907          18 :                     n->removeType = OBJECT_OPCLASS;
    6908          18 :                     n->behavior = $9;
    6909          18 :                     n->missing_ok = true;
    6910          18 :                     n->concurrent = false;
    6911          18 :                     $$ = (Node *) n;
    6912             :                 }
    6913             :         ;
    6914             : 
    6915             : DropOpFamilyStmt:
    6916             :             DROP OPERATOR FAMILY any_name USING name opt_drop_behavior
    6917             :                 {
    6918         110 :                     DropStmt *n = makeNode(DropStmt);
    6919             : 
    6920         110 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6921         110 :                     n->removeType = OBJECT_OPFAMILY;
    6922         110 :                     n->behavior = $7;
    6923         110 :                     n->missing_ok = false;
    6924         110 :                     n->concurrent = false;
    6925         110 :                     $$ = (Node *) n;
    6926             :                 }
    6927             :             | DROP OPERATOR FAMILY IF_P EXISTS any_name USING name opt_drop_behavior
    6928             :                 {
    6929          18 :                     DropStmt *n = makeNode(DropStmt);
    6930             : 
    6931          18 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6932          18 :                     n->removeType = OBJECT_OPFAMILY;
    6933          18 :                     n->behavior = $9;
    6934          18 :                     n->missing_ok = true;
    6935          18 :                     n->concurrent = false;
    6936          18 :                     $$ = (Node *) n;
    6937             :                 }
    6938             :         ;
    6939             : 
    6940             : 
    6941             : /*****************************************************************************
    6942             :  *
    6943             :  *      QUERY:
    6944             :  *
    6945             :  *      DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
    6946             :  *      REASSIGN OWNED BY username [, username ...] TO username
    6947             :  *
    6948             :  *****************************************************************************/
    6949             : DropOwnedStmt:
    6950             :             DROP OWNED BY role_list opt_drop_behavior
    6951             :                 {
    6952         148 :                     DropOwnedStmt *n = makeNode(DropOwnedStmt);
    6953             : 
    6954         148 :                     n->roles = $4;
    6955         148 :                     n->behavior = $5;
    6956         148 :                     $$ = (Node *) n;
    6957             :                 }
    6958             :         ;
    6959             : 
    6960             : ReassignOwnedStmt:
    6961             :             REASSIGN OWNED BY role_list TO RoleSpec
    6962             :                 {
    6963          46 :                     ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
    6964             : 
    6965          46 :                     n->roles = $4;
    6966          46 :                     n->newrole = $6;
    6967          46 :                     $$ = (Node *) n;
    6968             :                 }
    6969             :         ;
    6970             : 
    6971             : /*****************************************************************************
    6972             :  *
    6973             :  *      QUERY:
    6974             :  *
    6975             :  *      DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
    6976             :  *           [ RESTRICT | CASCADE ]
    6977             :  *
    6978             :  *****************************************************************************/
    6979             : 
    6980             : DropStmt:   DROP object_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
    6981             :                 {
    6982        1352 :                     DropStmt *n = makeNode(DropStmt);
    6983             : 
    6984        1352 :                     n->removeType = $2;
    6985        1352 :                     n->missing_ok = true;
    6986        1352 :                     n->objects = $5;
    6987        1352 :                     n->behavior = $6;
    6988        1352 :                     n->concurrent = false;
    6989        1352 :                     $$ = (Node *) n;
    6990             :                 }
    6991             :             | DROP object_type_any_name any_name_list opt_drop_behavior
    6992             :                 {
    6993       16394 :                     DropStmt *n = makeNode(DropStmt);
    6994             : 
    6995       16394 :                     n->removeType = $2;
    6996       16394 :                     n->missing_ok = false;
    6997       16394 :                     n->objects = $3;
    6998       16394 :                     n->behavior = $4;
    6999       16394 :                     n->concurrent = false;
    7000       16394 :                     $$ = (Node *) n;
    7001             :                 }
    7002             :             | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
    7003             :                 {
    7004          86 :                     DropStmt *n = makeNode(DropStmt);
    7005             : 
    7006          86 :                     n->removeType = $2;
    7007          86 :                     n->missing_ok = true;
    7008          86 :                     n->objects = $5;
    7009          86 :                     n->behavior = $6;
    7010          86 :                     n->concurrent = false;
    7011          86 :                     $$ = (Node *) n;
    7012             :                 }
    7013             :             | DROP drop_type_name name_list opt_drop_behavior
    7014             :                 {
    7015        1464 :                     DropStmt *n = makeNode(DropStmt);
    7016             : 
    7017        1464 :                     n->removeType = $2;
    7018        1464 :                     n->missing_ok = false;
    7019        1464 :                     n->objects = $3;
    7020        1464 :                     n->behavior = $4;
    7021        1464 :                     n->concurrent = false;
    7022        1464 :                     $$ = (Node *) n;
    7023             :                 }
    7024             :             | DROP object_type_name_on_any_name name ON any_name opt_drop_behavior
    7025             :                 {
    7026        1130 :                     DropStmt *n = makeNode(DropStmt);
    7027             : 
    7028        1130 :                     n->removeType = $2;
    7029        1130 :                     n->objects = list_make1(lappend($5, makeString($3)));
    7030        1130 :                     n->behavior = $6;
    7031        1130 :                     n->missing_ok = false;
    7032        1130 :                     n->concurrent = false;
    7033        1130 :                     $$ = (Node *) n;
    7034             :                 }
    7035             :             | DROP object_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
    7036             :                 {
    7037          48 :                     DropStmt *n = makeNode(DropStmt);
    7038             : 
    7039          48 :                     n->removeType = $2;
    7040          48 :                     n->objects = list_make1(lappend($7, makeString($5)));
    7041          48 :                     n->behavior = $8;
    7042          48 :                     n->missing_ok = true;
    7043          48 :                     n->concurrent = false;
    7044          48 :                     $$ = (Node *) n;
    7045             :                 }
    7046             :             | DROP TYPE_P type_name_list opt_drop_behavior
    7047             :                 {
    7048         560 :                     DropStmt *n = makeNode(DropStmt);
    7049             : 
    7050         560 :                     n->removeType = OBJECT_TYPE;
    7051         560 :                     n->missing_ok = false;
    7052         560 :                     n->objects = $3;
    7053         560 :                     n->behavior = $4;
    7054         560 :                     n->concurrent = false;
    7055         560 :                     $$ = (Node *) n;
    7056             :                 }
    7057             :             | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
    7058             :                 {
    7059          26 :                     DropStmt *n = makeNode(DropStmt);
    7060             : 
    7061          26 :                     n->removeType = OBJECT_TYPE;
    7062          26 :                     n->missing_ok = true;
    7063          26 :                     n->objects = $5;
    7064          26 :                     n->behavior = $6;
    7065          26 :                     n->concurrent = false;
    7066          26 :                     $$ = (Node *) n;
    7067             :                 }
    7068             :             | DROP DOMAIN_P type_name_list opt_drop_behavior
    7069             :                 {
    7070         470 :                     DropStmt *n = makeNode(DropStmt);
    7071             : 
    7072         470 :                     n->removeType = OBJECT_DOMAIN;
    7073         470 :                     n->missing_ok = false;
    7074         470 :                     n->objects = $3;
    7075         470 :                     n->behavior = $4;
    7076         470 :                     n->concurrent = false;
    7077         470 :                     $$ = (Node *) n;
    7078             :                 }
    7079             :             | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
    7080             :                 {
    7081          18 :                     DropStmt *n = makeNode(DropStmt);
    7082             : 
    7083          18 :                     n->removeType = OBJECT_DOMAIN;
    7084          18 :                     n->missing_ok = true;
    7085          18 :                     n->objects = $5;
    7086          18 :                     n->behavior = $6;
    7087          18 :                     n->concurrent = false;
    7088          18 :                     $$ = (Node *) n;
    7089             :                 }
    7090             :             | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
    7091             :                 {
    7092         120 :                     DropStmt *n = makeNode(DropStmt);
    7093             : 
    7094         120 :                     n->removeType = OBJECT_INDEX;
    7095         120 :                     n->missing_ok = false;
    7096         120 :                     n->objects = $4;
    7097         120 :                     n->behavior = $5;
    7098         120 :                     n->concurrent = true;
    7099         120 :                     $$ = (Node *) n;
    7100             :                 }
    7101             :             | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
    7102             :                 {
    7103          12 :                     DropStmt *n = makeNode(DropStmt);
    7104             : 
    7105          12 :                     n->removeType = OBJECT_INDEX;
    7106          12 :                     n->missing_ok = true;
    7107          12 :                     n->objects = $6;
    7108          12 :                     n->behavior = $7;
    7109          12 :                     n->concurrent = true;
    7110          12 :                     $$ = (Node *) n;
    7111             :                 }
    7112             :         ;
    7113             : 
    7114             : /* object types taking any_name/any_name_list */
    7115             : object_type_any_name:
    7116       15318 :             TABLE                                   { $$ = OBJECT_TABLE; }
    7117         198 :             | SEQUENCE                              { $$ = OBJECT_SEQUENCE; }
    7118        1046 :             | VIEW                                  { $$ = OBJECT_VIEW; }
    7119         130 :             | MATERIALIZED VIEW                     { $$ = OBJECT_MATVIEW; }
    7120         778 :             | INDEX                                 { $$ = OBJECT_INDEX; }
    7121         186 :             | FOREIGN TABLE                         { $$ = OBJECT_FOREIGN_TABLE; }
    7122          96 :             | COLLATION                             { $$ = OBJECT_COLLATION; }
    7123          56 :             | CONVERSION_P                          { $$ = OBJECT_CONVERSION; }
    7124         222 :             | STATISTICS                            { $$ = OBJECT_STATISTIC_EXT; }
    7125          20 :             | TEXT_P SEARCH PARSER                  { $$ = OBJECT_TSPARSER; }
    7126        2814 :             | TEXT_P SEARCH DICTIONARY              { $$ = OBJECT_TSDICTIONARY; }
    7127         116 :             | TEXT_P SEARCH TEMPLATE                { $$ = OBJECT_TSTEMPLATE; }
    7128        2818 :             | TEXT_P SEARCH CONFIGURATION           { $$ = OBJECT_TSCONFIGURATION; }
    7129             :         ;
    7130             : 
    7131             : /*
    7132             :  * object types taking name/name_list
    7133             :  *
    7134             :  * DROP handles some of them separately
    7135             :  */
    7136             : 
    7137             : object_type_name:
    7138         250 :             drop_type_name                          { $$ = $1; }
    7139         238 :             | DATABASE                              { $$ = OBJECT_DATABASE; }
    7140          52 :             | ROLE                                  { $$ = OBJECT_ROLE; }
    7141          10 :             | SUBSCRIPTION                          { $$ = OBJECT_SUBSCRIPTION; }
    7142           0 :             | TABLESPACE                            { $$ = OBJECT_TABLESPACE; }
    7143             :         ;
    7144             : 
    7145             : drop_type_name:
    7146          46 :             ACCESS METHOD                           { $$ = OBJECT_ACCESS_METHOD; }
    7147         128 :             | EVENT TRIGGER                         { $$ = OBJECT_EVENT_TRIGGER; }
    7148         176 :             | EXTENSION                             { $$ = OBJECT_EXTENSION; }
    7149         154 :             | FOREIGN DATA_P WRAPPER                { $$ = OBJECT_FDW; }
    7150         154 :             | opt_procedural LANGUAGE               { $$ = OBJECT_LANGUAGE; }
    7151         420 :             | PUBLICATION                           { $$ = OBJECT_PUBLICATION; }
    7152         590 :             | SCHEMA                                { $$ = OBJECT_SCHEMA; }
    7153         132 :             | SERVER                                { $$ = OBJECT_FOREIGN_SERVER; }
    7154             :         ;
    7155             : 
    7156             : /* object types attached to a table */
    7157             : object_type_name_on_any_name:
    7158         166 :             POLICY                                  { $$ = OBJECT_POLICY; }
    7159         268 :             | RULE                                  { $$ = OBJECT_RULE; }
    7160         798 :             | TRIGGER                               { $$ = OBJECT_TRIGGER; }
    7161             :         ;
    7162             : 
    7163             : any_name_list:
    7164       26560 :             any_name                                { $$ = list_make1($1); }
    7165        4264 :             | any_name_list ',' any_name            { $$ = lappend($1, $3); }
    7166             :         ;
    7167             : 
    7168       67718 : any_name:   ColId                       { $$ = list_make1(makeString($1)); }
    7169        8988 :             | ColId attrs               { $$ = lcons(makeString($1), $2); }
    7170             :         ;
    7171             : 
    7172             : attrs:      '.' attr_name
    7173      125236 :                     { $$ = list_make1(makeString($2)); }
    7174             :             | attrs '.' attr_name
    7175          64 :                     { $$ = lappend($1, makeString($3)); }
    7176             :         ;
    7177             : 
    7178             : type_name_list:
    7179        1074 :             Typename                                { $$ = list_make1($1); }
    7180         102 :             | type_name_list ',' Typename           { $$ = lappend($1, $3); }
    7181             :         ;
    7182             : 
    7183             : /*****************************************************************************
    7184             :  *
    7185             :  *      QUERY:
    7186             :  *              truncate table relname1, relname2, ...
    7187             :  *
    7188             :  *****************************************************************************/
    7189             : 
    7190             : TruncateStmt:
    7191             :             TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
    7192             :                 {
    7193        1752 :                     TruncateStmt *n = makeNode(TruncateStmt);
    7194             : 
    7195        1752 :                     n->relations = $3;
    7196        1752 :                     n->restart_seqs = $4;
    7197        1752 :                     n->behavior = $5;
    7198        1752 :                     $$ = (Node *) n;
    7199             :                 }
    7200             :         ;
    7201             : 
    7202             : opt_restart_seqs:
    7203          24 :             CONTINUE_P IDENTITY_P       { $$ = false; }
    7204          22 :             | RESTART IDENTITY_P        { $$ = true; }
    7205        1706 :             | /* EMPTY */               { $$ = false; }
    7206             :         ;
    7207             : 
    7208             : /*****************************************************************************
    7209             :  *
    7210             :  * COMMENT ON <object> IS <text>
    7211             :  *
    7212             :  *****************************************************************************/
    7213             : 
    7214             : CommentStmt:
    7215             :             COMMENT ON object_type_any_name any_name IS comment_text
    7216             :                 {
    7217        5898 :                     CommentStmt *n = makeNode(CommentStmt);
    7218             : 
    7219        5898 :                     n->objtype = $3;
    7220        5898 :                     n->object = (Node *) $4;
    7221        5898 :                     n->comment = $6;
    7222        5898 :                     $$ = (Node *) n;
    7223             :                 }
    7224             :             | COMMENT ON COLUMN any_name IS comment_text
    7225             :                 {
    7226         114 :                     CommentStmt *n = makeNode(CommentStmt);
    7227             : 
    7228         114 :                     n->objtype = OBJECT_COLUMN;
    7229         114 :                     n->object = (Node *) $4;
    7230         114 :                     n->comment = $6;
    7231         114 :                     $$ = (Node *) n;
    7232             :                 }
    7233             :             | COMMENT ON object_type_name name IS comment_text
    7234             :                 {
    7235         488 :                     CommentStmt *n = makeNode(CommentStmt);
    7236             : 
    7237         488 :                     n->objtype = $3;
    7238         488 :                     n->object = (Node *) makeString($4);
    7239         488 :                     n->comment = $6;
    7240         488 :                     $$ = (Node *) n;
    7241             :                 }
    7242             :             | COMMENT ON TYPE_P Typename IS comment_text
    7243             :                 {
    7244          56 :                     CommentStmt *n = makeNode(CommentStmt);
    7245             : 
    7246          56 :                     n->objtype = OBJECT_TYPE;
    7247          56 :                     n->object = (Node *) $4;
    7248          56 :                     n->comment = $6;
    7249          56 :                     $$ = (Node *) n;
    7250             :                 }
    7251             :             | COMMENT ON DOMAIN_P Typename IS comment_text
    7252             :                 {
    7253           8 :                     CommentStmt *n = makeNode(CommentStmt);
    7254             : 
    7255           8 :                     n->objtype = OBJECT_DOMAIN;
    7256           8 :                     n->object = (Node *) $4;
    7257           8 :                     n->comment = $6;
    7258           8 :                     $$ = (Node *) n;
    7259             :                 }
    7260             :             | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
    7261             :                 {
    7262          40 :                     CommentStmt *n = makeNode(CommentStmt);
    7263             : 
    7264          40 :                     n->objtype = OBJECT_AGGREGATE;
    7265          40 :                     n->object = (Node *) $4;
    7266          40 :                     n->comment = $6;
    7267          40 :                     $$ = (Node *) n;
    7268             :                 }
    7269             :             | COMMENT ON FUNCTION function_with_argtypes IS comment_text
    7270             :                 {
    7271         170 :                     CommentStmt *n = makeNode(CommentStmt);
    7272             : 
    7273         170 :                     n->objtype = OBJECT_FUNCTION;
    7274         170 :                     n->object = (Node *) $4;
    7275         170 :                     n->comment = $6;
    7276         170 :                     $$ = (Node *) n;
    7277             :                 }
    7278             :             | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
    7279             :                 {
    7280          18 :                     CommentStmt *n = makeNode(CommentStmt);
    7281             : 
    7282          18 :                     n->objtype = OBJECT_OPERATOR;
    7283          18 :                     n->object = (Node *) $4;
    7284          18 :                     n->comment = $6;
    7285          18 :                     $$ = (Node *) n;
    7286             :                 }
    7287             :             | COMMENT ON CONSTRAINT name ON any_name IS comment_text
    7288             :                 {
    7289         150 :                     CommentStmt *n = makeNode(CommentStmt);
    7290             : 
    7291         150 :                     n->objtype = OBJECT_TABCONSTRAINT;
    7292         150 :                     n->object = (Node *) lappend($6, makeString($4));
    7293         150 :                     n->comment = $8;
    7294         150 :                     $$ = (Node *) n;
    7295             :                 }
    7296             :             | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
    7297             :                 {
    7298          48 :                     CommentStmt *n = makeNode(CommentStmt);
    7299             : 
    7300          48 :                     n->objtype = OBJECT_DOMCONSTRAINT;
    7301             :                     /*
    7302             :                      * should use Typename not any_name in the production, but
    7303             :                      * there's a shift/reduce conflict if we do that, so fix it
    7304             :                      * up here.
    7305             :                      */
    7306          48 :                     n->object = (Node *) list_make2(makeTypeNameFromNameList($7), makeString($4));
    7307          48 :                     n->comment = $9;
    7308          48 :                     $$ = (Node *) n;
    7309             :                 }
    7310             :             | COMMENT ON object_type_name_on_any_name name ON any_name IS comment_text
    7311             :                 {
    7312          42 :                     CommentStmt *n = makeNode(CommentStmt);
    7313             : 
    7314          42 :                     n->objtype = $3;
    7315          42 :                     n->object = (Node *) lappend($6, makeString($4));
    7316          42 :                     n->comment = $8;
    7317          42 :                     $$ = (Node *) n;
    7318             :                 }
    7319             :             | COMMENT ON PROCEDURE function_with_argtypes IS comment_text
    7320             :                 {
    7321           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7322             : 
    7323           0 :                     n->objtype = OBJECT_PROCEDURE;
    7324           0 :                     n->object = (Node *) $4;
    7325           0 :                     n->comment = $6;
    7326           0 :                     $$ = (Node *) n;
    7327             :                 }
    7328             :             | COMMENT ON ROUTINE function_with_argtypes IS comment_text
    7329             :                 {
    7330           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7331             : 
    7332           0 :                     n->objtype = OBJECT_ROUTINE;
    7333           0 :                     n->object = (Node *) $4;
    7334           0 :                     n->comment = $6;
    7335           0 :                     $$ = (Node *) n;
    7336             :                 }
    7337             :             | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
    7338             :                 {
    7339          14 :                     CommentStmt *n = makeNode(CommentStmt);
    7340             : 
    7341          14 :                     n->objtype = OBJECT_TRANSFORM;
    7342          14 :                     n->object = (Node *) list_make2($5, makeString($7));
    7343          14 :                     n->comment = $9;
    7344          14 :                     $$ = (Node *) n;
    7345             :                 }
    7346             :             | COMMENT ON OPERATOR CLASS any_name USING name IS comment_text
    7347             :                 {
    7348           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7349             : 
    7350           0 :                     n->objtype = OBJECT_OPCLASS;
    7351           0 :                     n->object = (Node *) lcons(makeString($7), $5);
    7352           0 :                     n->comment = $9;
    7353           0 :                     $$ = (Node *) n;
    7354             :                 }
    7355             :             | COMMENT ON OPERATOR FAMILY any_name USING name IS comment_text
    7356             :                 {
    7357           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7358             : 
    7359           0 :                     n->objtype = OBJECT_OPFAMILY;
    7360           0 :                     n->object = (Node *) lcons(makeString($7), $5);
    7361           0 :                     n->comment = $9;
    7362           0 :                     $$ = (Node *) n;
    7363             :                 }
    7364             :             | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
    7365             :                 {
    7366          42 :                     CommentStmt *n = makeNode(CommentStmt);
    7367             : 
    7368          42 :                     n->objtype = OBJECT_LARGEOBJECT;
    7369          42 :                     n->object = (Node *) $5;
    7370          42 :                     n->comment = $7;
    7371          42 :                     $$ = (Node *) n;
    7372             :                 }
    7373             :             | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
    7374             :                 {
    7375           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7376             : 
    7377           0 :                     n->objtype = OBJECT_CAST;
    7378           0 :                     n->object = (Node *) list_make2($5, $7);
    7379           0 :                     n->comment = $10;
    7380           0 :                     $$ = (Node *) n;
    7381             :                 }
    7382             :         ;
    7383             : 
    7384             : comment_text:
    7385        6984 :             Sconst                              { $$ = $1; }
    7386         104 :             | NULL_P                            { $$ = NULL; }
    7387             :         ;
    7388             : 
    7389             : 
    7390             : /*****************************************************************************
    7391             :  *
    7392             :  *  SECURITY LABEL [FOR <provider>] ON <object> IS <label>
    7393             :  *
    7394             :  *  As with COMMENT ON, <object> can refer to various types of database
    7395             :  *  objects (e.g. TABLE, COLUMN, etc.).
    7396             :  *
    7397             :  *****************************************************************************/
    7398             : 
    7399             : SecLabelStmt:
    7400             :             SECURITY LABEL opt_provider ON object_type_any_name any_name
    7401             :             IS security_label
    7402             :                 {
    7403          48 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7404             : 
    7405          48 :                     n->provider = $3;
    7406          48 :                     n->objtype = $5;
    7407          48 :                     n->object = (Node *) $6;
    7408          48 :                     n->label = $8;
    7409          48 :                     $$ = (Node *) n;
    7410             :                 }
    7411             :             | SECURITY LABEL opt_provider ON COLUMN any_name
    7412             :               IS security_label
    7413             :                 {
    7414           4 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7415             : 
    7416           4 :                     n->provider = $3;
    7417           4 :                     n->objtype = OBJECT_COLUMN;
    7418           4 :                     n->object = (Node *) $6;
    7419           4 :                     n->label = $8;
    7420           4 :                     $$ = (Node *) n;
    7421             :                 }
    7422             :             | SECURITY LABEL opt_provider ON object_type_name name
    7423             :               IS security_label
    7424             :                 {
    7425          44 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7426             : 
    7427          44 :                     n->provider = $3;
    7428          44 :                     n->objtype = $5;
    7429          44 :                     n->object = (Node *) makeString($6);
    7430          44 :                     n->label = $8;
    7431          44 :                     $$ = (Node *) n;
    7432             :                 }
    7433             :             | SECURITY LABEL opt_provider ON TYPE_P Typename
    7434             :               IS security_label
    7435             :                 {
    7436           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7437             : 
    7438           0 :                     n->provider = $3;
    7439           0 :                     n->objtype = OBJECT_TYPE;
    7440           0 :                     n->object = (Node *) $6;
    7441           0 :                     n->label = $8;
    7442           0 :                     $$ = (Node *) n;
    7443             :                 }
    7444             :             | SECURITY LABEL opt_provider ON DOMAIN_P Typename
    7445             :               IS security_label
    7446             :                 {
    7447           2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7448             : 
    7449           2 :                     n->provider = $3;
    7450           2 :                     n->objtype = OBJECT_DOMAIN;
    7451           2 :                     n->object = (Node *) $6;
    7452           2 :                     n->label = $8;
    7453           2 :                     $$ = (Node *) n;
    7454             :                 }
    7455             :             | SECURITY LABEL opt_provider ON AGGREGATE aggregate_with_argtypes
    7456             :               IS security_label
    7457             :                 {
    7458           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7459             : 
    7460           0 :                     n->provider = $3;
    7461           0 :                     n->objtype = OBJECT_AGGREGATE;
    7462           0 :                     n->object = (Node *) $6;
    7463           0 :                     n->label = $8;
    7464           0 :                     $$ = (Node *) n;
    7465             :                 }
    7466             :             | SECURITY LABEL opt_provider ON FUNCTION function_with_argtypes
    7467             :               IS security_label
    7468             :                 {
    7469           2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7470             : 
    7471           2 :                     n->provider = $3;
    7472           2 :                     n->objtype = OBJECT_FUNCTION;
    7473           2 :                     n->object = (Node *) $6;
    7474           2 :                     n->label = $8;
    7475           2 :                     $$ = (Node *) n;
    7476             :                 }
    7477             :             | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
    7478             :               IS security_label
    7479             :                 {
    7480          18 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7481             : 
    7482          18 :                     n->provider = $3;
    7483          18 :                     n->objtype = OBJECT_LARGEOBJECT;
    7484          18 :                     n->object = (Node *) $7;
    7485          18 :                     n->label = $9;
    7486          18 :                     $$ = (Node *) n;
    7487             :                 }
    7488             :             | SECURITY LABEL opt_provider ON PROCEDURE function_with_argtypes
    7489             :               IS security_label
    7490             :                 {
    7491           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7492             : 
    7493           0 :                     n->provider = $3;
    7494           0 :                     n->objtype = OBJECT_PROCEDURE;
    7495           0 :                     n->object = (Node *) $6;
    7496           0 :                     n->label = $8;
    7497           0 :                     $$ = (Node *) n;
    7498             :                 }
    7499             :             | SECURITY LABEL opt_provider ON ROUTINE function_with_argtypes
    7500             :               IS security_label
    7501             :                 {
    7502           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7503             : 
    7504           0 :                     n->provider = $3;
    7505           0 :                     n->objtype = OBJECT_ROUTINE;
    7506           0 :                     n->object = (Node *) $6;
    7507           0 :                     n->label = $8;
    7508           0 :                     $$ = (Node *) n;
    7509             :                 }
    7510             :         ;
    7511             : 
    7512          28 : opt_provider:   FOR NonReservedWord_or_Sconst   { $$ = $2; }
    7513          90 :                 | /* EMPTY */                   { $$ = NULL; }
    7514             :         ;
    7515             : 
    7516         118 : security_label: Sconst              { $$ = $1; }
    7517           0 :                 | NULL_P            { $$ = NULL; }
    7518             :         ;
    7519             : 
    7520             : /*****************************************************************************
    7521             :  *
    7522             :  *      QUERY:
    7523             :  *          fetch/move
    7524             :  *
    7525             :  *****************************************************************************/
    7526             : 
    7527             : FetchStmt:  FETCH fetch_args
    7528             :                 {
    7529        7638 :                     FetchStmt *n = (FetchStmt *) $2;
    7530             : 
    7531        7638 :                     n->ismove = false;
    7532        7638 :                     $$ = (Node *) n;
    7533             :                 }
    7534             :             | MOVE fetch_args
    7535             :                 {
    7536          68 :                     FetchStmt *n = (FetchStmt *) $2;
    7537             : 
    7538          68 :                     n->ismove = true;
    7539          68 :                     $$ = (Node *) n;
    7540             :                 }
    7541             :         ;
    7542             : 
    7543             : fetch_args: cursor_name
    7544             :                 {
    7545         272 :                     FetchStmt *n = makeNode(FetchStmt);
    7546             : 
    7547         272 :                     n->portalname = $1;
    7548         272 :                     n->direction = FETCH_FORWARD;
    7549         272 :                     n->howMany = 1;
    7550         272 :                     n->location = -1;
    7551         272 :                     n->direction_keyword = FETCH_KEYWORD_NONE;
    7552         272 :                     $$ = (Node *) n;
    7553             :                 }
    7554             :             | from_in cursor_name
    7555             :                 {
    7556         218 :                     FetchStmt *n = makeNode(FetchStmt);
    7557             : 
    7558         218 :                     n->portalname = $2;
    7559         218 :                     n->direction = FETCH_FORWARD;
    7560         218 :                     n->howMany = 1;
    7561         218 :                     n->location = -1;
    7562         218 :                     n->direction_keyword = FETCH_KEYWORD_NONE;
    7563         218 :                     $$ = (Node *) n;
    7564             :                 }
    7565             :             | SignedIconst opt_from_in cursor_name
    7566             :                 {
    7567        4272 :                     FetchStmt *n = makeNode(FetchStmt);
    7568             : 
    7569        4272 :                     n->portalname = $3;
    7570        4272 :                     n->direction = FETCH_FORWARD;
    7571        4272 :                     n->howMany = $1;
    7572        4272 :                     n->location = @1;
    7573        4272 :                     n->direction_keyword = FETCH_KEYWORD_NONE;
    7574        4272 :                     $$ = (Node *) n;
    7575             :                 }
    7576             :             | NEXT opt_from_in cursor_name
    7577             :                 {
    7578        2010 :                     FetchStmt *n = makeNode(FetchStmt);
    7579             : 
    7580        2010 :                     n->portalname = $3;
    7581        2010 :                     n->direction = FETCH_FORWARD;
    7582        2010 :                     n->howMany = 1;
    7583        2010 :                     n->location = -1;
    7584        2010 :                     n->direction_keyword = FETCH_KEYWORD_NEXT;
    7585        2010 :                     $$ = (Node *) n;
    7586             :                 }
    7587             :             | PRIOR opt_from_in cursor_name
    7588             :                 {
    7589          32 :                     FetchStmt *n = makeNode(FetchStmt);
    7590             : 
    7591          32 :                     n->portalname = $3;
    7592          32 :                     n->direction = FETCH_BACKWARD;
    7593          32 :                     n->howMany = 1;
    7594          32 :                     n->location = -1;
    7595          32 :                     n->direction_keyword = FETCH_KEYWORD_PRIOR;
    7596          32 :                     $$ = (Node *) n;
    7597             :                 }
    7598             :             | FIRST_P opt_from_in cursor_name
    7599             :                 {
    7600          26 :                     FetchStmt *n = makeNode(FetchStmt);
    7601             : 
    7602          26 :                     n->portalname = $3;
    7603          26 :                     n->direction = FETCH_ABSOLUTE;
    7604          26 :                     n->howMany = 1;
    7605          26 :                     n->location = -1;
    7606          26 :                     n->direction_keyword = FETCH_KEYWORD_FIRST;
    7607          26 :                     $$ = (Node *) n;
    7608             :                 }
    7609             :             | LAST_P opt_from_in cursor_name
    7610             :                 {
    7611          20 :                     FetchStmt *n = makeNode(FetchStmt);
    7612             : 
    7613          20 :                     n->portalname = $3;
    7614          20 :                     n->direction = FETCH_ABSOLUTE;
    7615          20 :                     n->howMany = -1;
    7616          20 :                     n->location = -1;
    7617          20 :                     n->direction_keyword = FETCH_KEYWORD_LAST;
    7618          20 :                     $$ = (Node *) n;
    7619             :                 }
    7620             :             | ABSOLUTE_P SignedIconst opt_from_in cursor_name
    7621             :                 {
    7622          94 :                     FetchStmt *n = makeNode(FetchStmt);
    7623             : 
    7624          94 :                     n->portalname = $4;
    7625          94 :                     n->direction = FETCH_ABSOLUTE;
    7626          94 :                     n->howMany = $2;
    7627          94 :                     n->location = @2;
    7628          94 :                     n->direction_keyword = FETCH_KEYWORD_ABSOLUTE;
    7629          94 :                     $$ = (Node *) n;
    7630             :                 }
    7631             :             | RELATIVE_P SignedIconst opt_from_in cursor_name
    7632             :                 {
    7633          36 :                     FetchStmt *n = makeNode(FetchStmt);
    7634             : 
    7635          36 :                     n->portalname = $4;
    7636          36 :                     n->direction = FETCH_RELATIVE;
    7637          36 :                     n->howMany = $2;
    7638          36 :                     n->location = @2;
    7639          36 :                     n->direction_keyword = FETCH_KEYWORD_RELATIVE;
    7640          36 :                     $$ = (Node *) n;
    7641             :                 }
    7642             :             | ALL opt_from_in cursor_name
    7643             :                 {
    7644         270 :                     FetchStmt *n = makeNode(FetchStmt);
    7645             : 
    7646         270 :                     n->portalname = $3;
    7647         270 :                     n->direction = FETCH_FORWARD;
    7648         270 :                     n->howMany = FETCH_ALL;
    7649         270 :                     n->location = -1;
    7650         270 :                     n->direction_keyword = FETCH_KEYWORD_ALL;
    7651         270 :                     $$ = (Node *) n;
    7652             :                 }
    7653             :             | FORWARD opt_from_in cursor_name
    7654             :                 {
    7655          30 :                     FetchStmt *n = makeNode(FetchStmt);
    7656             : 
    7657          30 :                     n->portalname = $3;
    7658          30 :                     n->direction = FETCH_FORWARD;
    7659          30 :                     n->howMany = 1;
    7660          30 :                     n->location = -1;
    7661          30 :                     n->direction_keyword = FETCH_KEYWORD_FORWARD;
    7662          30 :                     $$ = (Node *) n;
    7663             :                 }
    7664             :             | FORWARD SignedIconst opt_from_in cursor_name
    7665             :                 {
    7666          12 :                     FetchStmt *n = makeNode(FetchStmt);
    7667             : 
    7668          12 :                     n->portalname = $4;
    7669          12 :                     n->direction = FETCH_FORWARD;
    7670          12 :                     n->howMany = $2;
    7671          12 :                     n->location = @2;
    7672          12 :                     n->direction_keyword = FETCH_KEYWORD_FORWARD;
    7673          12 :                     $$ = (Node *) n;
    7674             :                 }
    7675             :             | FORWARD ALL opt_from_in cursor_name
    7676             :                 {
    7677          16 :                     FetchStmt *n = makeNode(FetchStmt);
    7678             : 
    7679          16 :                     n->portalname = $4;
    7680          16 :                     n->direction = FETCH_FORWARD;
    7681          16 :                     n->howMany = FETCH_ALL;
    7682          16 :                     n->location = -1;
    7683          16 :                     n->direction_keyword = FETCH_KEYWORD_FORWARD_ALL;
    7684          16 :                     $$ = (Node *) n;
    7685             :                 }
    7686             :             | BACKWARD opt_from_in cursor_name
    7687             :                 {
    7688          80 :                     FetchStmt *n = makeNode(FetchStmt);
    7689             : 
    7690          80 :                     n->portalname = $3;
    7691          80 :                     n->direction = FETCH_BACKWARD;
    7692          80 :                     n->howMany = 1;
    7693          80 :                     n->location = -1;
    7694          80 :                     n->direction_keyword = FETCH_KEYWORD_BACKWARD;
    7695          80 :                     $$ = (Node *) n;
    7696             :                 }
    7697             :             | BACKWARD SignedIconst opt_from_in cursor_name
    7698             :                 {
    7699         226 :                     FetchStmt *n = makeNode(FetchStmt);
    7700             : 
    7701         226 :                     n->portalname = $4;
    7702         226 :                     n->direction = FETCH_BACKWARD;
    7703         226 :                     n->howMany = $2;
    7704         226 :                     n->location = @2;
    7705         226 :                     n->direction_keyword = FETCH_KEYWORD_BACKWARD;
    7706         226 :                     $$ = (Node *) n;
    7707             :                 }
    7708             :             | BACKWARD ALL opt_from_in cursor_name
    7709             :                 {
    7710          92 :                     FetchStmt *n = makeNode(FetchStmt);
    7711             : 
    7712          92 :                     n->portalname = $4;
    7713          92 :                     n->direction = FETCH_BACKWARD;
    7714          92 :                     n->howMany = FETCH_ALL;
    7715          92 :                     n->location = -1;
    7716          92 :                     n->direction_keyword = FETCH_KEYWORD_BACKWARD_ALL;
    7717          92 :                     $$ = (Node *) n;
    7718             :                 }
    7719             :         ;
    7720             : 
    7721             : from_in:    FROM
    7722             :             | IN_P
    7723             :         ;
    7724             : 
    7725             : opt_from_in:    from_in
    7726             :             | /* EMPTY */
    7727             :         ;
    7728             : 
    7729             : 
    7730             : /*****************************************************************************
    7731             :  *
    7732             :  * GRANT and REVOKE statements
    7733             :  *
    7734             :  *****************************************************************************/
    7735             : 
    7736             : GrantStmt:  GRANT privileges ON privilege_target TO grantee_list
    7737             :             opt_grant_grant_option opt_granted_by
    7738             :                 {
    7739       11632 :                     GrantStmt *n = makeNode(GrantStmt);
    7740             : 
    7741       11632 :                     n->is_grant = true;
    7742       11632 :                     n->privileges = $2;
    7743       11632 :                     n->targtype = ($4)->targtype;
    7744       11632 :                     n->objtype = ($4)->objtype;
    7745       11632 :                     n->objects = ($4)->objs;
    7746       11632 :                     n->grantees = $6;
    7747       11632 :                     n->grant_option = $7;
    7748       11632 :                     n->grantor = $8;
    7749       11632 :                     $$ = (Node *) n;
    7750             :                 }
    7751             :         ;
    7752             : 
    7753             : RevokeStmt:
    7754             :             REVOKE privileges ON privilege_target
    7755             :             FROM grantee_list opt_granted_by opt_drop_behavior
    7756             :                 {
    7757       10288 :                     GrantStmt *n = makeNode(GrantStmt);
    7758             : 
    7759       10288 :                     n->is_grant = false;
    7760       10288 :                     n->grant_option = false;
    7761       10288 :                     n->privileges = $2;
    7762       10288 :                     n->targtype = ($4)->targtype;
    7763       10288 :                     n->objtype = ($4)->objtype;
    7764       10288 :                     n->objects = ($4)->objs;
    7765       10288 :                     n->grantees = $6;
    7766       10288 :                     n->grantor = $7;
    7767       10288 :                     n->behavior = $8;
    7768       10288 :                     $$ = (Node *) n;
    7769             :                 }
    7770             :             | REVOKE GRANT OPTION FOR privileges ON privilege_target
    7771             :             FROM grantee_list opt_granted_by opt_drop_behavior
    7772             :                 {
    7773          16 :                     GrantStmt *n = makeNode(GrantStmt);
    7774             : 
    7775          16 :                     n->is_grant = false;
    7776          16 :                     n->grant_option = true;
    7777          16 :                     n->privileges = $5;
    7778          16 :                     n->targtype = ($7)->targtype;
    7779          16 :                     n->objtype = ($7)->objtype;
    7780          16 :                     n->objects = ($7)->objs;
    7781          16 :                     n->grantees = $9;
    7782          16 :                     n->grantor = $10;
    7783          16 :                     n->behavior = $11;
    7784          16 :                     $$ = (Node *) n;
    7785             :                 }
    7786             :         ;
    7787             : 
    7788             : 
    7789             : /*
    7790             :  * Privilege names are represented as strings; the validity of the privilege
    7791             :  * names gets checked at execution.  This is a bit annoying but we have little
    7792             :  * choice because of the syntactic conflict with lists of role names in
    7793             :  * GRANT/REVOKE.  What's more, we have to call out in the "privilege"
    7794             :  * production any reserved keywords that need to be usable as privilege names.
    7795             :  */
    7796             : 
    7797             : /* either ALL [PRIVILEGES] or a list of individual privileges */
    7798             : privileges: privilege_list
    7799       19322 :                 { $$ = $1; }
    7800             :             | ALL
    7801        2694 :                 { $$ = NIL; }
    7802             :             | ALL PRIVILEGES
    7803         120 :                 { $$ = NIL; }
    7804             :             | ALL '(' columnList ')'
    7805             :                 {
    7806          18 :                     AccessPriv *n = makeNode(AccessPriv);
    7807             : 
    7808          18 :                     n->priv_name = NULL;
    7809          18 :                     n->cols = $3;
    7810          18 :                     $$ = list_make1(n);
    7811             :                 }
    7812             :             | ALL PRIVILEGES '(' columnList ')'
    7813             :                 {
    7814           0 :                     AccessPriv *n = makeNode(AccessPriv);
    7815             : 
    7816           0 :                     n->priv_name = NULL;
    7817           0 :                     n->cols = $4;
    7818           0 :                     $$ = list_make1(n);
    7819             :                 }
    7820             :         ;
    7821             : 
    7822       20234 : privilege_list: privilege                           { $$ = list_make1($1); }
    7823         550 :             | privilege_list ',' privilege          { $$ = lappend($1, $3); }
    7824             :         ;
    7825             : 
    7826             : privilege:  SELECT opt_column_list
    7827             :             {
    7828        9264 :                 AccessPriv *n = makeNode(AccessPriv);
    7829             : 
    7830        9264 :                 n->priv_name = pstrdup($1);
    7831        9264 :                 n->cols = $2;
    7832        9264 :                 $$ = n;
    7833             :             }
    7834             :         | REFERENCES opt_column_list
    7835             :             {
    7836          14 :                 AccessPriv *n = makeNode(AccessPriv);
    7837             : 
    7838          14 :                 n->priv_name = pstrdup($1);
    7839          14 :                 n->cols = $2;
    7840          14 :                 $$ = n;
    7841             :             }
    7842             :         | CREATE opt_column_list
    7843             :             {
    7844         290 :                 AccessPriv *n = makeNode(AccessPriv);
    7845             : 
    7846         290 :                 n->priv_name = pstrdup($1);
    7847         290 :                 n->cols = $2;
    7848         290 :                 $$ = n;
    7849             :             }
    7850             :         | ALTER SYSTEM_P
    7851             :             {
    7852          24 :                 AccessPriv *n = makeNode(AccessPriv);
    7853          24 :                 n->priv_name = pstrdup("alter system");
    7854          24 :                 n->cols = NIL;
    7855          24 :                 $$ = n;
    7856             :             }
    7857             :         | ColId opt_column_list
    7858             :             {
    7859       11192 :                 AccessPriv *n = makeNode(AccessPriv);
    7860             : 
    7861       11192 :                 n->priv_name = $1;
    7862       11192 :                 n->cols = $2;
    7863       11192 :                 $$ = n;
    7864             :             }
    7865             :         ;
    7866             : 
    7867             : parameter_name_list:
    7868             :         parameter_name
    7869             :             {
    7870          76 :                 $$ = list_make1(makeString($1));
    7871             :             }
    7872             :         | parameter_name_list ',' parameter_name
    7873             :             {
    7874          50 :                 $$ = lappend($1, makeString($3));
    7875             :             }
    7876             :         ;
    7877             : 
    7878             : parameter_name:
    7879             :         ColId
    7880             :             {
    7881         126 :                 $$ = $1;
    7882             :             }
    7883             :         | parameter_name '.' ColId
    7884             :             {
    7885          32 :                 $$ = psprintf("%s.%s", $1, $3);
    7886             :             }
    7887             :         ;
    7888             : 
    7889             : 
    7890             : /* Don't bother trying to fold the first two rules into one using
    7891             :  * opt_table.  You're going to get conflicts.
    7892             :  */
    7893             : privilege_target:
    7894             :             qualified_name_list
    7895             :                 {
    7896       11294 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7897             : 
    7898       11294 :                     n->targtype = ACL_TARGET_OBJECT;
    7899       11294 :                     n->objtype = OBJECT_TABLE;
    7900       11294 :                     n->objs = $1;
    7901       11294 :                     $$ = n;
    7902             :                 }
    7903             :             | TABLE qualified_name_list
    7904             :                 {
    7905         388 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7906             : 
    7907         388 :                     n->targtype = ACL_TARGET_OBJECT;
    7908         388 :                     n->objtype = OBJECT_TABLE;
    7909         388 :                     n->objs = $2;
    7910         388 :                     $$ = n;
    7911             :                 }
    7912             :             | SEQUENCE qualified_name_list
    7913             :                 {
    7914          22 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7915             : 
    7916          22 :                     n->targtype = ACL_TARGET_OBJECT;
    7917          22 :                     n->objtype = OBJECT_SEQUENCE;
    7918          22 :                     n->objs = $2;
    7919          22 :                     $$ = n;
    7920             :                 }
    7921             :             | FOREIGN DATA_P WRAPPER name_list
    7922             :                 {
    7923          92 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7924             : 
    7925          92 :                     n->targtype = ACL_TARGET_OBJECT;
    7926          92 :                     n->objtype = OBJECT_FDW;
    7927          92 :                     n->objs = $4;
    7928          92 :                     $$ = n;
    7929             :                 }
    7930             :             | FOREIGN SERVER name_list
    7931             :                 {
    7932          88 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7933             : 
    7934          88 :                     n->targtype = ACL_TARGET_OBJECT;
    7935          88 :                     n->objtype = OBJECT_FOREIGN_SERVER;
    7936          88 :                     n->objs = $3;
    7937          88 :                     $$ = n;
    7938             :                 }
    7939             :             | FUNCTION function_with_argtypes_list
    7940             :                 {
    7941        8932 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7942             : 
    7943        8932 :                     n->targtype = ACL_TARGET_OBJECT;
    7944        8932 :                     n->objtype = OBJECT_FUNCTION;
    7945        8932 :                     n->objs = $2;
    7946        8932 :                     $$ = n;
    7947             :                 }
    7948             :             | PROCEDURE function_with_argtypes_list
    7949             :                 {
    7950          42 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7951             : 
    7952          42 :                     n->targtype = ACL_TARGET_OBJECT;
    7953          42 :                     n->objtype = OBJECT_PROCEDURE;
    7954          42 :                     n->objs = $2;
    7955          42 :                     $$ = n;
    7956             :                 }
    7957             :             | ROUTINE function_with_argtypes_list
    7958             :                 {
    7959           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7960             : 
    7961           0 :                     n->targtype = ACL_TARGET_OBJECT;
    7962           0 :                     n->objtype = OBJECT_ROUTINE;
    7963           0 :                     n->objs = $2;
    7964           0 :                     $$ = n;
    7965             :                 }
    7966             :             | DATABASE name_list
    7967             :                 {
    7968         346 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7969             : 
    7970         346 :                     n->targtype = ACL_TARGET_OBJECT;
    7971         346 :                     n->objtype = OBJECT_DATABASE;
    7972         346 :                     n->objs = $2;
    7973         346 :                     $$ = n;
    7974             :                 }
    7975             :             | DOMAIN_P any_name_list
    7976             :                 {
    7977          26 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7978             : 
    7979          26 :                     n->targtype = ACL_TARGET_OBJECT;
    7980          26 :                     n->objtype = OBJECT_DOMAIN;
    7981          26 :                     n->objs = $2;
    7982          26 :                     $$ = n;
    7983             :                 }
    7984             :             | LANGUAGE name_list
    7985             :                 {
    7986          42 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7987             : 
    7988          42 :                     n->targtype = ACL_TARGET_OBJECT;
    7989          42 :                     n->objtype = OBJECT_LANGUAGE;
    7990          42 :                     n->objs = $2;
    7991          42 :                     $$ = n;
    7992             :                 }
    7993             :             | LARGE_P OBJECT_P NumericOnly_list
    7994             :                 {
    7995          90 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7996             : 
    7997          90 :                     n->targtype = ACL_TARGET_OBJECT;
    7998          90 :                     n->objtype = OBJECT_LARGEOBJECT;
    7999          90 :                     n->objs = $3;
    8000          90 :                     $$ = n;
    8001             :                 }
    8002             :             | PARAMETER parameter_name_list
    8003             :                 {
    8004          76 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    8005          76 :                     n->targtype = ACL_TARGET_OBJECT;
    8006          76 :                     n->objtype = OBJECT_PARAMETER_ACL;
    8007          76 :                     n->objs = $2;
    8008          76 :                     $$ = n;
    8009             :                 }
    8010             :             | SCHEMA name_list
    8011             :                 {
    8012         362 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    8013             : 
    8014         362 :                     n->targtype = ACL_TARGET_OBJECT;
    8015         362 :                     n->objtype = OBJECT_SCHEMA;
    8016         362 :                     n->objs = $2;
    8017         362 :                     $$ = n;
    8018             :                 }
    8019             :             | TABLESPACE name_list
    8020             :                 {
    8021           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    8022             : 
    8023           6 :                     n->targtype = ACL_TARGET_OBJECT;
    8024           6 :                     n->objtype = OBJECT_TABLESPACE;
    8025           6 :                     n->objs = $2;
    8026           6 :                     $$ = n;
    8027             :                 }
    8028             :             | TYPE_P any_name_list
    8029             :                 {
    8030         112 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    8031             : 
    8032         112 :                     n->targtype = ACL_TARGET_OBJECT;
    8033         112 :                     n->objtype = OBJECT_TYPE;
    8034         112 :                     n->objs = $2;
    8035         112 :                     $$ = n;
    8036             :                 }
    8037             :             | ALL TABLES IN_P SCHEMA name_list
    8038             :                 {
    8039          12 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    8040             : 
    8041          12 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8042          12 :                     n->objtype = OBJECT_TABLE;
    8043          12 :                     n->objs = $5;
    8044          12 :                     $$ = n;
    8045             :                 }
    8046             :             | ALL SEQUENCES IN_P SCHEMA name_list
    8047             :                 {
    8048           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    8049             : 
    8050           0 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8051           0 :                     n->objtype = OBJECT_SEQUENCE;
    8052           0 :                     n->objs = $5;
    8053           0 :                     $$ = n;
    8054             :                 }
    8055             :             | ALL FUNCTIONS IN_P SCHEMA name_list
    8056             :                 {
    8057           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    8058             : 
    8059           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8060           6 :                     n->objtype = OBJECT_FUNCTION;
    8061           6 :                     n->objs = $5;
    8062           6 :                     $$ = n;
    8063             :                 }
    8064             :             | ALL PROCEDURES IN_P SCHEMA name_list
    8065             :                 {
    8066           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    8067             : 
    8068           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8069           6 :                     n->objtype = OBJECT_PROCEDURE;
    8070           6 :                     n->objs = $5;
    8071           6 :                     $$ = n;
    8072             :                 }
    8073             :             | ALL ROUTINES IN_P SCHEMA name_list
    8074             :                 {
    8075           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    8076             : 
    8077           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8078           6 :                     n->objtype = OBJECT_ROUTINE;
    8079           6 :                     n->objs = $5;
    8080           6 :                     $$ = n;
    8081             :                 }
    8082             :         ;
    8083             : 
    8084             : 
    8085             : grantee_list:
    8086       22142 :             grantee                                 { $$ = list_make1($1); }
    8087         108 :             | grantee_list ',' grantee              { $$ = lappend($1, $3); }
    8088             :         ;
    8089             : 
    8090             : grantee:
    8091       22226 :             RoleSpec                                { $$ = $1; }
    8092          24 :             | GROUP_P RoleSpec                      { $$ = $2; }
    8093             :         ;
    8094             : 
    8095             : 
    8096             : opt_grant_grant_option:
    8097         102 :             WITH GRANT OPTION { $$ = true; }
    8098       11654 :             | /*EMPTY*/ { $$ = false; }
    8099             :         ;
    8100             : 
    8101             : /*****************************************************************************
    8102             :  *
    8103             :  * GRANT and REVOKE ROLE statements
    8104             :  *
    8105             :  *****************************************************************************/
    8106             : 
    8107             : GrantRoleStmt:
    8108             :             GRANT privilege_list TO role_list opt_granted_by
    8109             :                 {
    8110         578 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8111             : 
    8112         578 :                     n->is_grant = true;
    8113         578 :                     n->granted_roles = $2;
    8114         578 :                     n->grantee_roles = $4;
    8115         578 :                     n->opt = NIL;
    8116         578 :                     n->grantor = $5;
    8117         578 :                     $$ = (Node *) n;
    8118             :                 }
    8119             :           | GRANT privilege_list TO role_list WITH grant_role_opt_list opt_granted_by
    8120             :                 {
    8121         178 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8122             : 
    8123         178 :                     n->is_grant = true;
    8124         178 :                     n->granted_roles = $2;
    8125         178 :                     n->grantee_roles = $4;
    8126         178 :                     n->opt = $6;
    8127         178 :                     n->grantor = $7;
    8128         178 :                     $$ = (Node *) n;
    8129             :                 }
    8130             :         ;
    8131             : 
    8132             : RevokeRoleStmt:
    8133             :             REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
    8134             :                 {
    8135          90 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8136             : 
    8137          90 :                     n->is_grant = false;
    8138          90 :                     n->opt = NIL;
    8139          90 :                     n->granted_roles = $2;
    8140          90 :                     n->grantee_roles = $4;
    8141          90 :                     n->grantor = $5;
    8142          90 :                     n->behavior = $6;
    8143          90 :                     $$ = (Node *) n;
    8144             :                 }
    8145             :             | REVOKE ColId OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
    8146             :                 {
    8147          66 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8148             :                     DefElem *opt;
    8149             : 
    8150          66 :                     opt = makeDefElem(pstrdup($2),
    8151          66 :                                       (Node *) makeBoolean(false), @2);
    8152          66 :                     n->is_grant = false;
    8153          66 :                     n->opt = list_make1(opt);
    8154          66 :                     n->granted_roles = $5;
    8155          66 :                     n->grantee_roles = $7;
    8156          66 :                     n->grantor = $8;
    8157          66 :                     n->behavior = $9;
    8158          66 :                     $$ = (Node *) n;
    8159             :                 }
    8160             :         ;
    8161             : 
    8162             : grant_role_opt_list:
    8163         120 :             grant_role_opt_list ',' grant_role_opt  { $$ = lappend($1, $3); }
    8164         178 :             | grant_role_opt                        { $$ = list_make1($1); }
    8165             :         ;
    8166             : 
    8167             : grant_role_opt:
    8168             :         ColLabel grant_role_opt_value
    8169             :             {
    8170         298 :                 $$ = makeDefElem(pstrdup($1), $2, @1);
    8171             :             }
    8172             :         ;
    8173             : 
    8174             : grant_role_opt_value:
    8175          72 :         OPTION          { $$ = (Node *) makeBoolean(true); }
    8176         112 :         | TRUE_P        { $$ = (Node *) makeBoolean(true); }
    8177         114 :         | FALSE_P       { $$ = (Node *) makeBoolean(false); }
    8178             :         ;
    8179             : 
    8180         138 : opt_granted_by: GRANTED BY RoleSpec                     { $$ = $3; }
    8181       22710 :             | /*EMPTY*/                                 { $$ = NULL; }
    8182             :         ;
    8183             : 
    8184             : /*****************************************************************************
    8185             :  *
    8186             :  * ALTER DEFAULT PRIVILEGES statement
    8187             :  *
    8188             :  *****************************************************************************/
    8189             : 
    8190             : AlterDefaultPrivilegesStmt:
    8191             :             ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
    8192             :                 {
    8193         206 :                     AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
    8194             : 
    8195         206 :                     n->options = $4;
    8196         206 :                     n->action = (GrantStmt *) $5;
    8197         206 :                     $$ = (Node *) n;
    8198             :                 }
    8199             :         ;
    8200             : 
    8201             : DefACLOptionList:
    8202         144 :             DefACLOptionList DefACLOption           { $$ = lappend($1, $2); }
    8203         206 :             | /* EMPTY */                           { $$ = NIL; }
    8204             :         ;
    8205             : 
    8206             : DefACLOption:
    8207             :             IN_P SCHEMA name_list
    8208             :                 {
    8209          60 :                     $$ = makeDefElem("schemas", (Node *) $3, @1);
    8210             :                 }
    8211             :             | FOR ROLE role_list
    8212             :                 {
    8213          84 :                     $$ = makeDefElem("roles", (Node *) $3, @1);
    8214             :                 }
    8215             :             | FOR USER role_list
    8216             :                 {
    8217           0 :                     $$ = makeDefElem("roles", (Node *) $3, @1);
    8218             :                 }
    8219             :         ;
    8220             : 
    8221             : /*
    8222             :  * This should match GRANT/REVOKE, except that individual target objects
    8223             :  * are not mentioned and we only allow a subset of object types.
    8224             :  */
    8225             : DefACLAction:
    8226             :             GRANT privileges ON defacl_privilege_target TO grantee_list
    8227             :             opt_grant_grant_option
    8228             :                 {
    8229         124 :                     GrantStmt *n = makeNode(GrantStmt);
    8230             : 
    8231         124 :                     n->is_grant = true;
    8232         124 :                     n->privileges = $2;
    8233         124 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8234         124 :                     n->objtype = $4;
    8235         124 :                     n->objects = NIL;
    8236         124 :                     n->grantees = $6;
    8237         124 :                     n->grant_option = $7;
    8238         124 :                     $$ = (Node *) n;
    8239             :                 }
    8240             :             | REVOKE privileges ON defacl_privilege_target
    8241             :             FROM grantee_list opt_drop_behavior
    8242             :                 {
    8243          82 :                     GrantStmt *n = makeNode(GrantStmt);
    8244             : 
    8245          82 :                     n->is_grant = false;
    8246          82 :                     n->grant_option = false;
    8247          82 :                     n->privileges = $2;
    8248          82 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8249          82 :                     n->objtype = $4;
    8250          82 :                     n->objects = NIL;
    8251          82 :                     n->grantees = $6;
    8252          82 :                     n->behavior = $7;
    8253          82 :                     $$ = (Node *) n;
    8254             :                 }
    8255             :             | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
    8256             :             FROM grantee_list opt_drop_behavior
    8257             :                 {
    8258           0 :                     GrantStmt *n = makeNode(GrantStmt);
    8259             : 
    8260           0 :                     n->is_grant = false;
    8261           0 :                     n->grant_option = true;
    8262           0 :                     n->privileges = $5;
    8263           0 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8264           0 :                     n->objtype = $7;
    8265           0 :                     n->objects = NIL;
    8266           0 :                     n->grantees = $9;
    8267           0 :                     n->behavior = $10;
    8268           0 :                     $$ = (Node *) n;
    8269             :                 }
    8270             :         ;
    8271             : 
    8272             : defacl_privilege_target:
    8273          78 :             TABLES          { $$ = OBJECT_TABLE; }
    8274          16 :             | FUNCTIONS     { $$ = OBJECT_FUNCTION; }
    8275           6 :             | ROUTINES      { $$ = OBJECT_FUNCTION; }
    8276           6 :             | SEQUENCES     { $$ = OBJECT_SEQUENCE; }
    8277          34 :             | TYPES_P       { $$ = OBJECT_TYPE; }
    8278          36 :             | SCHEMAS       { $$ = OBJECT_SCHEMA; }
    8279          30 :             | LARGE_P OBJECTS_P { $$ = OBJECT_LARGEOBJECT; }
    8280             :         ;
    8281             : 
    8282             : 
    8283             : /*****************************************************************************
    8284             :  *
    8285             :  *      QUERY: CREATE INDEX
    8286             :  *
    8287             :  * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
    8288             :  * willing to make TABLESPACE a fully reserved word.
    8289             :  *****************************************************************************/
    8290             : 
    8291             : IndexStmt:  CREATE opt_unique INDEX opt_concurrently opt_single_name
    8292             :             ON relation_expr access_method_clause '(' index_params ')'
    8293             :             opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
    8294             :                 {
    8295        6652 :                     IndexStmt *n = makeNode(IndexStmt);
    8296             : 
    8297        6652 :                     n->unique = $2;
    8298        6652 :                     n->concurrent = $4;
    8299        6652 :                     n->idxname = $5;
    8300        6652 :                     n->relation = $7;
    8301        6652 :                     n->accessMethod = $8;
    8302        6652 :                     n->indexParams = $10;
    8303        6652 :                     n->indexIncludingParams = $12;
    8304        6652 :                     n->nulls_not_distinct = !$13;
    8305        6652 :                     n->options = $14;
    8306        6652 :                     n->tableSpace = $15;
    8307        6652 :                     n->whereClause = $16;
    8308        6652 :                     n->excludeOpNames = NIL;
    8309        6652 :                     n->idxcomment = NULL;
    8310        6652 :                     n->indexOid = InvalidOid;
    8311        6652 :                     n->oldNumber = InvalidRelFileNumber;
    8312        6652 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8313        6652 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8314        6652 :                     n->primary = false;
    8315        6652 :                     n->isconstraint = false;
    8316        6652 :                     n->deferrable = false;
    8317        6652 :                     n->initdeferred = false;
    8318        6652 :                     n->transformed = false;
    8319        6652 :                     n->if_not_exists = false;
    8320        6652 :                     n->reset_default_tblspc = false;
    8321        6652 :                     $$ = (Node *) n;
    8322             :                 }
    8323             :             | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS name
    8324             :             ON relation_expr access_method_clause '(' index_params ')'
    8325             :             opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
    8326             :                 {
    8327          18 :                     IndexStmt *n = makeNode(IndexStmt);
    8328             : 
    8329          18 :                     n->unique = $2;
    8330          18 :                     n->concurrent = $4;
    8331          18 :                     n->idxname = $8;
    8332          18 :                     n->relation = $10;
    8333          18 :                     n->accessMethod = $11;
    8334          18 :                     n->indexParams = $13;
    8335          18 :                     n->indexIncludingParams = $15;
    8336          18 :                     n->nulls_not_distinct = !$16;
    8337          18 :                     n->options = $17;
    8338          18 :                     n->tableSpace = $18;
    8339          18 :                     n->whereClause = $19;
    8340          18 :                     n->excludeOpNames = NIL;
    8341          18 :                     n->idxcomment = NULL;
    8342          18 :                     n->indexOid = InvalidOid;
    8343          18 :                     n->oldNumber = InvalidRelFileNumber;
    8344          18 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8345          18 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8346          18 :                     n->primary = false;
    8347          18 :                     n->isconstraint = false;
    8348          18 :                     n->deferrable = false;
    8349          18 :                     n->initdeferred = false;
    8350          18 :                     n->transformed = false;
    8351          18 :                     n->if_not_exists = true;
    8352          18 :                     n->reset_default_tblspc = false;
    8353          18 :                     $$ = (Node *) n;
    8354             :                 }
    8355             :         ;
    8356             : 
    8357             : opt_unique:
    8358        1294 :             UNIQUE                                  { $$ = true; }
    8359        5382 :             | /*EMPTY*/                             { $$ = false; }
    8360             :         ;
    8361             : 
    8362             : access_method_clause:
    8363        3002 :             USING name                              { $$ = $2; }
    8364        3902 :             | /*EMPTY*/                             { $$ = DEFAULT_INDEX_TYPE; }
    8365             :         ;
    8366             : 
    8367        8108 : index_params:   index_elem                          { $$ = list_make1($1); }
    8368        2164 :             | index_params ',' index_elem           { $$ = lappend($1, $3); }
    8369             :         ;
    8370             : 
    8371             : 
    8372             : index_elem_options:
    8373             :     opt_collate opt_qualified_name opt_asc_desc opt_nulls_order
    8374             :         {
    8375       10854 :             $$ = makeNode(IndexElem);
    8376       10854 :             $$->name = NULL;
    8377       10854 :             $$->expr = NULL;
    8378       10854 :             $$->indexcolname = NULL;
    8379       10854 :             $$->collation = $1;
    8380       10854 :             $$->opclass = $2;
    8381       10854 :             $$->opclassopts = NIL;
    8382       10854 :             $$->ordering = $3;
    8383       10854 :             $$->nulls_ordering = $4;
    8384             :         }
    8385             :     | opt_collate any_name reloptions opt_asc_desc opt_nulls_order
    8386             :         {
    8387         142 :             $$ = makeNode(IndexElem);
    8388         142 :             $$->name = NULL;
    8389         142 :             $$->expr = NULL;
    8390         142 :             $$->indexcolname = NULL;
    8391         142 :             $$->collation = $1;
    8392         142 :             $$->opclass = $2;
    8393         142 :             $$->opclassopts = $3;
    8394         142 :             $$->ordering = $4;
    8395         142 :             $$->nulls_ordering = $5;
    8396             :         }
    8397             :     ;
    8398             : 
    8399             : /*
    8400             :  * Index attributes can be either simple column references, or arbitrary
    8401             :  * expressions in parens.  For backwards-compatibility reasons, we allow
    8402             :  * an expression that's just a function call to be written without parens.
    8403             :  */
    8404             : index_elem: ColId index_elem_options
    8405             :                 {
    8406        9870 :                     $$ = $2;
    8407        9870 :                     $$->name = $1;
    8408             :                 }
    8409             :             | func_expr_windowless index_elem_options
    8410             :                 {
    8411         610 :                     $$ = $2;
    8412         610 :                     $$->expr = $1;
    8413             :                 }
    8414             :             | '(' a_expr ')' index_elem_options
    8415             :                 {
    8416         516 :                     $$ = $4;
    8417         516 :                     $$->expr = $2;
    8418             :                 }
    8419             :         ;
    8420             : 
    8421         218 : opt_include:        INCLUDE '(' index_including_params ')'          { $$ = $3; }
    8422        6452 :              |      /* EMPTY */                     { $$ = NIL; }
    8423             :         ;
    8424             : 
    8425         218 : index_including_params: index_elem                      { $$ = list_make1($1); }
    8426         166 :             | index_including_params ',' index_elem     { $$ = lappend($1, $3); }
    8427             :         ;
    8428             : 
    8429         192 : opt_collate: COLLATE any_name                       { $$ = $2; }
    8430       16372 :             | /*EMPTY*/                             { $$ = NIL; }
    8431             :         ;
    8432             : 
    8433             : 
    8434        1820 : opt_asc_desc: ASC                           { $$ = SORTBY_ASC; }
    8435        3558 :             | DESC                          { $$ = SORTBY_DESC; }
    8436      113350 :             | /*EMPTY*/                     { $$ = SORTBY_DEFAULT; }
    8437             :         ;
    8438             : 
    8439         344 : opt_nulls_order: NULLS_LA FIRST_P           { $$ = SORTBY_NULLS_FIRST; }
    8440        1732 :             | NULLS_LA LAST_P               { $$ = SORTBY_NULLS_LAST; }
    8441      116872 :             | /*EMPTY*/                     { $$ = SORTBY_NULLS_DEFAULT; }
    8442             :         ;
    8443             : 
    8444             : 
    8445             : /*****************************************************************************
    8446             :  *
    8447             :  *      QUERY:
    8448             :  *              create [or replace] function <fname>
    8449             :  *                      [(<type-1> { , <type-n>})]
    8450             :  *                      returns <type-r>
    8451             :  *                      as <filename or code in language as appropriate>
    8452             :  *                      language <lang> [with parameters]
    8453             :  *
    8454             :  *****************************************************************************/
    8455             : 
    8456             : CreateFunctionStmt:
    8457             :             CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8458             :             RETURNS func_return opt_createfunc_opt_list opt_routine_body
    8459             :                 {
    8460       24646 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8461             : 
    8462       24646 :                     n->is_procedure = false;
    8463       24646 :                     n->replace = $2;
    8464       24646 :                     n->funcname = $4;
    8465       24646 :                     n->parameters = $5;
    8466       24646 :                     n->returnType = $7;
    8467       24646 :                     n->options = $8;
    8468       24646 :                     n->sql_body = $9;
    8469       24646 :                     $$ = (Node *) n;
    8470             :                 }
    8471             :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8472             :               RETURNS TABLE '(' table_func_column_list ')' opt_createfunc_opt_list opt_routine_body
    8473             :                 {
    8474         194 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8475             : 
    8476         194 :                     n->is_procedure = false;
    8477         194 :                     n->replace = $2;
    8478         194 :                     n->funcname = $4;
    8479         194 :                     n->parameters = mergeTableFuncParameters($5, $9, yyscanner);
    8480         194 :                     n->returnType = TableFuncTypeName($9);
    8481         194 :                     n->returnType->location = @7;
    8482         194 :                     n->options = $11;
    8483         194 :                     n->sql_body = $12;
    8484         194 :                     $$ = (Node *) n;
    8485             :                 }
    8486             :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8487             :               opt_createfunc_opt_list opt_routine_body
    8488             :                 {
    8489         488 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8490             : 
    8491         488 :                     n->is_procedure = false;
    8492         488 :                     n->replace = $2;
    8493         488 :                     n->funcname = $4;
    8494         488 :                     n->parameters = $5;
    8495         488 :                     n->returnType = NULL;
    8496         488 :                     n->options = $6;
    8497         488 :                     n->sql_body = $7;
    8498         488 :                     $$ = (Node *) n;
    8499             :                 }
    8500             :             | CREATE opt_or_replace PROCEDURE func_name func_args_with_defaults
    8501             :               opt_createfunc_opt_list opt_routine_body
    8502             :                 {
    8503         370 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8504             : 
    8505         370 :                     n->is_procedure = true;
    8506         370 :                     n->replace = $2;
    8507         370 :                     n->funcname = $4;
    8508         370 :                     n->parameters = $5;
    8509         370 :                     n->returnType = NULL;
    8510         370 :                     n->options = $6;
    8511         370 :                     n->sql_body = $7;
    8512         370 :                     $$ = (Node *) n;
    8513             :                 }
    8514             :         ;
    8515             : 
    8516             : opt_or_replace:
    8517       10096 :             OR REPLACE                              { $$ = true; }
    8518       21060 :             | /*EMPTY*/                             { $$ = false; }
    8519             :         ;
    8520             : 
    8521       12122 : func_args:  '(' func_args_list ')'                  { $$ = $2; }
    8522        5916 :             | '(' ')'                               { $$ = NIL; }
    8523             :         ;
    8524             : 
    8525             : func_args_list:
    8526       12122 :             func_arg                                { $$ = list_make1($1); }
    8527       11402 :             | func_args_list ',' func_arg           { $$ = lappend($1, $3); }
    8528             :         ;
    8529             : 
    8530             : function_with_argtypes_list:
    8531       12744 :             function_with_argtypes                  { $$ = list_make1($1); }
    8532             :             | function_with_argtypes_list ',' function_with_argtypes
    8533          84 :                                                     { $$ = lappend($1, $3); }
    8534             :         ;
    8535             : 
    8536             : function_with_argtypes:
    8537             :             func_name func_args
    8538             :                 {
    8539       18038 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8540             : 
    8541       18038 :                     n->objname = $1;
    8542       18038 :                     n->objargs = extractArgTypes($2);
    8543       18038 :                     n->objfuncargs = $2;
    8544       18038 :                     $$ = n;
    8545             :                 }
    8546             :             /*
    8547             :              * Because of reduce/reduce conflicts, we can't use func_name
    8548             :              * below, but we can write it out the long way, which actually
    8549             :              * allows more cases.
    8550             :              */
    8551             :             | type_func_name_keyword
    8552             :                 {
    8553           0 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8554             : 
    8555           0 :                     n->objname = list_make1(makeString(pstrdup($1)));
    8556           0 :                     n->args_unspecified = true;
    8557           0 :                     $$ = n;
    8558             :                 }
    8559             :             | ColId
    8560             :                 {
    8561         370 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8562             : 
    8563         370 :                     n->objname = list_make1(makeString($1));
    8564         370 :                     n->args_unspecified = true;
    8565         370 :                     $$ = n;
    8566             :                 }
    8567             :             | ColId indirection
    8568             :                 {
    8569          28 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8570             : 
    8571          28 :                     n->objname = check_func_name(lcons(makeString($1), $2),
    8572             :                                                   yyscanner);
    8573          28 :                     n->args_unspecified = true;
    8574          28 :                     $$ = n;
    8575             :                 }
    8576             :         ;
    8577             : 
    8578             : /*
    8579             :  * func_args_with_defaults is separate because we only want to accept
    8580             :  * defaults in CREATE FUNCTION, not in ALTER etc.
    8581             :  */
    8582             : func_args_with_defaults:
    8583       21072 :         '(' func_args_with_defaults_list ')'        { $$ = $2; }
    8584        4626 :         | '(' ')'                                   { $$ = NIL; }
    8585             :         ;
    8586             : 
    8587             : func_args_with_defaults_list:
    8588       21072 :         func_arg_with_default                       { $$ = list_make1($1); }
    8589             :         | func_args_with_defaults_list ',' func_arg_with_default
    8590       35960 :                                                     { $$ = lappend($1, $3); }
    8591             :         ;
    8592             : 
    8593             : /*
    8594             :  * The style with arg_class first is SQL99 standard, but Oracle puts
    8595             :  * param_name first; accept both since it's likely people will try both
    8596             :  * anyway.  Don't bother trying to save productions by letting arg_class
    8597             :  * have an empty alternative ... you'll get shift/reduce conflicts.
    8598             :  *
    8599             :  * We can catch over-specified arguments here if we want to,
    8600             :  * but for now better to silently swallow typmod, etc.
    8601             :  * - thomas 2000-03-22
    8602             :  */
    8603             : func_arg:
    8604             :             arg_class param_name func_type
    8605             :                 {
    8606       16960 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8607             : 
    8608       16960 :                     n->name = $2;
    8609       16960 :                     n->argType = $3;
    8610       16960 :                     n->mode = $1;
    8611       16960 :                     n->defexpr = NULL;
    8612       16960 :                     n->location = @1;
    8613       16960 :                     $$ = n;
    8614             :                 }
    8615             :             | param_name arg_class func_type
    8616             :                 {
    8617         420 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8618             : 
    8619         420 :                     n->name = $1;
    8620         420 :                     n->argType = $3;
    8621         420 :                     n->mode = $2;
    8622         420 :                     n->defexpr = NULL;
    8623         420 :                     n->location = @1;
    8624         420 :                     $$ = n;
    8625             :                 }
    8626             :             | param_name func_type
    8627             :                 {
    8628       15922 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8629             : 
    8630       15922 :                     n->name = $1;
    8631       15922 :                     n->argType = $2;
    8632       15922 :                     n->mode = FUNC_PARAM_DEFAULT;
    8633       15922 :                     n->defexpr = NULL;
    8634       15922 :                     n->location = @1;
    8635       15922 :                     $$ = n;
    8636             :                 }
    8637             :             | arg_class func_type
    8638             :                 {
    8639         328 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8640             : 
    8641         328 :                     n->name = NULL;
    8642         328 :                     n->argType = $2;
    8643         328 :                     n->mode = $1;
    8644         328 :                     n->defexpr = NULL;
    8645         328 :                     n->location = @1;
    8646         328 :                     $$ = n;
    8647             :                 }
    8648             :             | func_type
    8649             :                 {
    8650       47826 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8651             : 
    8652       47826 :                     n->name = NULL;
    8653       47826 :                     n->argType = $1;
    8654       47826 :                     n->mode = FUNC_PARAM_DEFAULT;
    8655       47826 :                     n->defexpr = NULL;
    8656       47826 :                     n->location = @1;
    8657       47826 :                     $$ = n;
    8658             :                 }
    8659             :         ;
    8660             : 
    8661             : /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
    8662        4020 : arg_class:  IN_P                                { $$ = FUNC_PARAM_IN; }
    8663       12912 :             | OUT_P                             { $$ = FUNC_PARAM_OUT; }
    8664         198 :             | INOUT                             { $$ = FUNC_PARAM_INOUT; }
    8665           0 :             | IN_P OUT_P                        { $$ = FUNC_PARAM_INOUT; }
    8666         578 :             | VARIADIC                          { $$ = FUNC_PARAM_VARIADIC; }
    8667             :         ;
    8668             : 
    8669             : /*
    8670             :  * Ideally param_name should be ColId, but that causes too many conflicts.
    8671             :  */
    8672             : param_name: type_function_name
    8673             :         ;
    8674             : 
    8675             : func_return:
    8676             :             func_type
    8677             :                 {
    8678             :                     /* We can catch over-specified results here if we want to,
    8679             :                      * but for now better to silently swallow typmod, etc.
    8680             :                      * - thomas 2000-03-22
    8681             :                      */
    8682       24646 :                     $$ = $1;
    8683             :                 }
    8684             :         ;
    8685             : 
    8686             : /*
    8687             :  * We would like to make the %TYPE productions here be ColId attrs etc,
    8688             :  * but that causes reduce/reduce conflicts.  type_function_name
    8689             :  * is next best choice.
    8690             :  */
    8691      127296 : func_type:  Typename                                { $$ = $1; }
    8692             :             | type_function_name attrs '%' TYPE_P
    8693             :                 {
    8694          18 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
    8695          18 :                     $$->pct_type = true;
    8696          18 :                     $$->location = @1;
    8697             :                 }
    8698             :             | SETOF type_function_name attrs '%' TYPE_P
    8699             :                 {
    8700           6 :                     $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
    8701           6 :                     $$->pct_type = true;
    8702           6 :                     $$->setof = true;
    8703           6 :                     $$->location = @2;
    8704             :                 }
    8705             :         ;
    8706             : 
    8707             : func_arg_with_default:
    8708             :         func_arg
    8709             :                 {
    8710       50500 :                     $$ = $1;
    8711             :                 }
    8712             :         | func_arg DEFAULT a_expr
    8713             :                 {
    8714        6336 :                     $$ = $1;
    8715        6336 :                     $$->defexpr = $3;
    8716             :                 }
    8717             :         | func_arg '=' a_expr
    8718             :                 {
    8719         196 :                     $$ = $1;
    8720         196 :                     $$->defexpr = $3;
    8721             :                 }
    8722             :         ;
    8723             : 
    8724             : /* Aggregate args can be most things that function args can be */
    8725             : aggr_arg:   func_arg
    8726             :                 {
    8727         900 :                     if (!($1->mode == FUNC_PARAM_DEFAULT ||
    8728          60 :                           $1->mode == FUNC_PARAM_IN ||
    8729          60 :                           $1->mode == FUNC_PARAM_VARIADIC))
    8730           0 :                         ereport(ERROR,
    8731             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    8732             :                                  errmsg("aggregates cannot have output arguments"),
    8733             :                                  parser_errposition(@1)));
    8734         900 :                     $$ = $1;
    8735             :                 }
    8736             :         ;
    8737             : 
    8738             : /*
    8739             :  * The SQL standard offers no guidance on how to declare aggregate argument
    8740             :  * lists, since it doesn't have CREATE AGGREGATE etc.  We accept these cases:
    8741             :  *
    8742             :  * (*)                                  - normal agg with no args
    8743             :  * (aggr_arg,...)                       - normal agg with args
    8744             :  * (ORDER BY aggr_arg,...)              - ordered-set agg with no direct args
    8745             :  * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
    8746             :  *
    8747             :  * The zero-argument case is spelled with '*' for consistency with COUNT(*).
    8748             :  *
    8749             :  * An additional restriction is that if the direct-args list ends in a
    8750             :  * VARIADIC item, the ordered-args list must contain exactly one item that
    8751             :  * is also VARIADIC with the same type.  This allows us to collapse the two
    8752             :  * VARIADIC items into one, which is necessary to represent the aggregate in
    8753             :  * pg_proc.  We check this at the grammar stage so that we can return a list
    8754             :  * in which the second VARIADIC item is already discarded, avoiding extra work
    8755             :  * in cases such as DROP AGGREGATE.
    8756             :  *
    8757             :  * The return value of this production is a two-element list, in which the
    8758             :  * first item is a sublist of FunctionParameter nodes (with any duplicate
    8759             :  * VARIADIC item already dropped, as per above) and the second is an Integer
    8760             :  * node, containing -1 if there was no ORDER BY and otherwise the number
    8761             :  * of argument declarations before the ORDER BY.  (If this number is equal
    8762             :  * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
    8763             :  * This representation is passed as-is to CREATE AGGREGATE; for operations
    8764             :  * on existing aggregates, we can just apply extractArgTypes to the first
    8765             :  * sublist.
    8766             :  */
    8767             : aggr_args:  '(' '*' ')'
    8768             :                 {
    8769         136 :                     $$ = list_make2(NIL, makeInteger(-1));
    8770             :                 }
    8771             :             | '(' aggr_args_list ')'
    8772             :                 {
    8773         732 :                     $$ = list_make2($2, makeInteger(-1));
    8774             :                 }
    8775             :             | '(' ORDER BY aggr_args_list ')'
    8776             :                 {
    8777           6 :                     $$ = list_make2($4, makeInteger(0));
    8778             :                 }
    8779             :             | '(' aggr_args_list ORDER BY aggr_args_list ')'
    8780             :                 {
    8781             :                     /* this is the only case requiring consistency checking */
    8782          32 :                     $$ = makeOrderedSetArgs($2, $5, yyscanner);
    8783             :                 }
    8784             :         ;
    8785             : 
    8786             : aggr_args_list:
    8787         802 :             aggr_arg                                { $$ = list_make1($1); }
    8788          98 :             | aggr_args_list ',' aggr_arg           { $$ = lappend($1, $3); }
    8789             :         ;
    8790             : 
    8791             : aggregate_with_argtypes:
    8792             :             func_name aggr_args
    8793             :                 {
    8794         362 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8795             : 
    8796         362 :                     n->objname = $1;
    8797         362 :                     n->objargs = extractAggrArgTypes($2);
    8798         362 :                     n->objfuncargs = (List *) linitial($2);
    8799         362 :                     $$ = n;
    8800             :                 }
    8801             :         ;
    8802             : 
    8803             : aggregate_with_argtypes_list:
    8804         104 :             aggregate_with_argtypes                 { $$ = list_make1($1); }
    8805             :             | aggregate_with_argtypes_list ',' aggregate_with_argtypes
    8806           0 :                                                     { $$ = lappend($1, $3); }
    8807             :         ;
    8808             : 
    8809             : opt_createfunc_opt_list:
    8810             :             createfunc_opt_list
    8811          54 :             | /*EMPTY*/ { $$ = NIL; }
    8812             :     ;
    8813             : 
    8814             : createfunc_opt_list:
    8815             :             /* Must be at least one to prevent conflict */
    8816       25644 :             createfunc_opt_item                     { $$ = list_make1($1); }
    8817       68120 :             | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
    8818             :     ;
    8819             : 
    8820             : /*
    8821             :  * Options common to both CREATE FUNCTION and ALTER FUNCTION
    8822             :  */
    8823             : common_func_opt_item:
    8824             :             CALLED ON NULL_P INPUT_P
    8825             :                 {
    8826         380 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(false), @1);
    8827             :                 }
    8828             :             | RETURNS NULL_P ON NULL_P INPUT_P
    8829             :                 {
    8830         882 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8831             :                 }
    8832             :             | STRICT_P
    8833             :                 {
    8834       13954 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8835             :                 }
    8836             :             | IMMUTABLE
    8837             :                 {
    8838       10206 :                     $$ = makeDefElem("volatility", (Node *) makeString("immutable"), @1);
    8839             :                 }
    8840             :             | STABLE
    8841             :                 {
    8842        2524 :                     $$ = makeDefElem("volatility", (Node *) makeString("stable"), @1);
    8843             :                 }
    8844             :             | VOLATILE
    8845             :                 {
    8846        1844 :                     $$ = makeDefElem("volatility", (Node *) makeString("volatile"), @1);
    8847             :                 }
    8848             :             | EXTERNAL SECURITY DEFINER
    8849             :                 {
    8850           0 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8851             :                 }
    8852             :             | EXTERNAL SECURITY INVOKER
    8853             :                 {
    8854           0 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8855             :                 }
    8856             :             | SECURITY DEFINER
    8857             :                 {
    8858          58 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8859             :                 }
    8860             :             | SECURITY INVOKER
    8861             :                 {
    8862          18 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8863             :                 }
    8864             :             | LEAKPROOF
    8865             :                 {
    8866          46 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(true), @1);
    8867             :                 }
    8868             :             | NOT LEAKPROOF
    8869             :                 {
    8870          12 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(false), @1);
    8871             :                 }
    8872             :             | COST NumericOnly
    8873             :                 {
    8874        4360 :                     $$ = makeDefElem("cost", (Node *) $2, @1);
    8875             :                 }
    8876             :             | ROWS NumericOnly
    8877             :                 {
    8878         600 :                     $$ = makeDefElem("rows", (Node *) $2, @1);
    8879             :                 }
    8880             :             | SUPPORT any_name
    8881             :                 {
    8882         114 :                     $$ = makeDefElem("support", (Node *) $2, @1);
    8883             :                 }
    8884             :             | FunctionSetResetClause
    8885             :                 {
    8886             :                     /* we abuse the normal content of a DefElem here */
    8887         146 :                     $$ = makeDefElem("set", (Node *) $1, @1);
    8888             :                 }
    8889             :             | PARALLEL ColId
    8890             :                 {
    8891       14228 :                     $$ = makeDefElem("parallel", (Node *) makeString($2), @1);
    8892             :                 }
    8893             :         ;
    8894             : 
    8895             : createfunc_opt_item:
    8896             :             AS func_as
    8897             :                 {
    8898       20024 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    8899             :                 }
    8900             :             | LANGUAGE NonReservedWord_or_Sconst
    8901             :                 {
    8902       25624 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    8903             :                 }
    8904             :             | TRANSFORM transform_type_list
    8905             :                 {
    8906         118 :                     $$ = makeDefElem("transform", (Node *) $2, @1);
    8907             :                 }
    8908             :             | WINDOW
    8909             :                 {
    8910          20 :                     $$ = makeDefElem("window", (Node *) makeBoolean(true), @1);
    8911             :                 }
    8912             :             | common_func_opt_item
    8913             :                 {
    8914       47978 :                     $$ = $1;
    8915             :                 }
    8916             :         ;
    8917             : 
    8918       16662 : func_as:    Sconst                      { $$ = list_make1(makeString($1)); }
    8919             :             | Sconst ',' Sconst
    8920             :                 {
    8921        3362 :                     $$ = list_make2(makeString($1), makeString($3));
    8922             :                 }
    8923             :         ;
    8924             : 
    8925             : ReturnStmt: RETURN a_expr
    8926             :                 {
    8927        4878 :                     ReturnStmt *r = makeNode(ReturnStmt);
    8928             : 
    8929        4878 :                     r->returnval = (Node *) $2;
    8930        4878 :                     $$ = (Node *) r;
    8931             :                 }
    8932             :         ;
    8933             : 
    8934             : opt_routine_body:
    8935             :             ReturnStmt
    8936             :                 {
    8937        4872 :                     $$ = $1;
    8938             :                 }
    8939             :             | BEGIN_P ATOMIC routine_body_stmt_list END_P
    8940             :                 {
    8941             :                     /*
    8942             :                      * A compound statement is stored as a single-item list
    8943             :                      * containing the list of statements as its member.  That
    8944             :                      * way, the parse analysis code can tell apart an empty
    8945             :                      * body from no body at all.
    8946             :                      */
    8947         808 :                     $$ = (Node *) list_make1($3);
    8948             :                 }
    8949             :             | /*EMPTY*/
    8950             :                 {
    8951       20018 :                     $$ = NULL;
    8952             :                 }
    8953             :         ;
    8954             : 
    8955             : routine_body_stmt_list:
    8956             :             routine_body_stmt_list routine_body_stmt ';'
    8957             :                 {
    8958             :                     /* As in stmtmulti, discard empty statements */
    8959         824 :                     if ($2 != NULL)
    8960         806 :                         $$ = lappend($1, $2);
    8961             :                     else
    8962          18 :                         $$ = $1;
    8963             :                 }
    8964             :             | /*EMPTY*/
    8965             :                 {
    8966         808 :                     $$ = NIL;
    8967             :                 }
    8968             :         ;
    8969             : 
    8970             : routine_body_stmt:
    8971             :             stmt
    8972             :             | ReturnStmt
    8973             :         ;
    8974             : 
    8975             : transform_type_list:
    8976         118 :             FOR TYPE_P Typename { $$ = list_make1($3); }
    8977           4 :             | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
    8978             :         ;
    8979             : 
    8980             : opt_definition:
    8981         670 :             WITH definition                         { $$ = $2; }
    8982       10260 :             | /*EMPTY*/                             { $$ = NIL; }
    8983             :         ;
    8984             : 
    8985             : table_func_column:  param_name func_type
    8986             :                 {
    8987         454 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8988             : 
    8989         454 :                     n->name = $1;
    8990         454 :                     n->argType = $2;
    8991         454 :                     n->mode = FUNC_PARAM_TABLE;
    8992         454 :                     n->defexpr = NULL;
    8993         454 :                     n->location = @1;
    8994         454 :                     $$ = n;
    8995             :                 }
    8996             :         ;
    8997             : 
    8998             : table_func_column_list:
    8999             :             table_func_column
    9000             :                 {
    9001         194 :                     $$ = list_make1($1);
    9002             :                 }
    9003             :             | table_func_column_list ',' table_func_column
    9004             :                 {
    9005         260 :                     $$ = lappend($1, $3);
    9006             :                 }
    9007             :         ;
    9008             : 
    9009             : /*****************************************************************************
    9010             :  * ALTER FUNCTION / ALTER PROCEDURE / ALTER ROUTINE
    9011             :  *
    9012             :  * RENAME and OWNER subcommands are already provided by the generic
    9013             :  * ALTER infrastructure, here we just specify alterations that can
    9014             :  * only be applied to functions.
    9015             :  *
    9016             :  *****************************************************************************/
    9017             : AlterFunctionStmt:
    9018             :             ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
    9019             :                 {
    9020        1372 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    9021             : 
    9022        1372 :                     n->objtype = OBJECT_FUNCTION;
    9023        1372 :                     n->func = $3;
    9024        1372 :                     n->actions = $4;
    9025        1372 :                     $$ = (Node *) n;
    9026             :                 }
    9027             :             | ALTER PROCEDURE function_with_argtypes alterfunc_opt_list opt_restrict
    9028             :                 {
    9029          18 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    9030             : 
    9031          18 :                     n->objtype = OBJECT_PROCEDURE;
    9032          18 :                     n->func = $3;
    9033          18 :                     n->actions = $4;
    9034          18 :                     $$ = (Node *) n;
    9035             :                 }
    9036             :             | ALTER ROUTINE function_with_argtypes alterfunc_opt_list opt_restrict
    9037             :                 {
    9038           0 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    9039             : 
    9040           0 :                     n->objtype = OBJECT_ROUTINE;
    9041           0 :                     n->func = $3;
    9042           0 :                     n->actions = $4;
    9043           0 :                     $$ = (Node *) n;
    9044             :                 }
    9045             :         ;
    9046             : 
    9047             : alterfunc_opt_list:
    9048             :             /* At least one option must be specified */
    9049        1390 :             common_func_opt_item                    { $$ = list_make1($1); }
    9050           4 :             | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
    9051             :         ;
    9052             : 
    9053             : /* Ignored, merely for SQL compliance */
    9054             : opt_restrict:
    9055             :             RESTRICT
    9056             :             | /* EMPTY */
    9057             :         ;
    9058             : 
    9059             : 
    9060             : /*****************************************************************************
    9061             :  *
    9062             :  *      QUERY:
    9063             :  *
    9064             :  *      DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    9065             :  *      DROP PROCEDURE procname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    9066             :  *      DROP ROUTINE routname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    9067             :  *      DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
    9068             :  *      DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
    9069             :  *
    9070             :  *****************************************************************************/
    9071             : 
    9072             : RemoveFuncStmt:
    9073             :             DROP FUNCTION function_with_argtypes_list opt_drop_behavior
    9074             :                 {
    9075        3346 :                     DropStmt *n = makeNode(DropStmt);
    9076             : 
    9077        3346 :                     n->removeType = OBJECT_FUNCTION;
    9078        3346 :                     n->objects = $3;
    9079        3346 :                     n->behavior = $4;
    9080        3346 :                     n->missing_ok = false;
    9081        3346 :                     n->concurrent = false;
    9082        3346 :                     $$ = (Node *) n;
    9083             :                 }
    9084             :             | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9085             :                 {
    9086         260 :                     DropStmt *n = makeNode(DropStmt);
    9087             : 
    9088         260 :                     n->removeType = OBJECT_FUNCTION;
    9089         260 :                     n->objects = $5;
    9090         260 :                     n->behavior = $6;
    9091         260 :                     n->missing_ok = true;
    9092         260 :                     n->concurrent = false;
    9093         260 :                     $$ = (Node *) n;
    9094             :                 }
    9095             :             | DROP PROCEDURE function_with_argtypes_list opt_drop_behavior
    9096             :                 {
    9097         140 :                     DropStmt *n = makeNode(DropStmt);
    9098             : 
    9099         140 :                     n->removeType = OBJECT_PROCEDURE;
    9100         140 :                     n->objects = $3;
    9101         140 :                     n->behavior = $4;
    9102         140 :                     n->missing_ok = false;
    9103         140 :                     n->concurrent = false;
    9104         140 :                     $$ = (Node *) n;
    9105             :                 }
    9106             :             | DROP PROCEDURE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9107             :                 {
    9108           6 :                     DropStmt *n = makeNode(DropStmt);
    9109             : 
    9110           6 :                     n->removeType = OBJECT_PROCEDURE;
    9111           6 :                     n->objects = $5;
    9112           6 :                     n->behavior = $6;
    9113           6 :                     n->missing_ok = true;
    9114           6 :                     n->concurrent = false;
    9115           6 :                     $$ = (Node *) n;
    9116             :                 }
    9117             :             | DROP ROUTINE function_with_argtypes_list opt_drop_behavior
    9118             :                 {
    9119          12 :                     DropStmt *n = makeNode(DropStmt);
    9120             : 
    9121          12 :                     n->removeType = OBJECT_ROUTINE;
    9122          12 :                     n->objects = $3;
    9123          12 :                     n->behavior = $4;
    9124          12 :                     n->missing_ok = false;
    9125          12 :                     n->concurrent = false;
    9126          12 :                     $$ = (Node *) n;
    9127             :                 }
    9128             :             | DROP ROUTINE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9129             :                 {
    9130           6 :                     DropStmt *n = makeNode(DropStmt);
    9131             : 
    9132           6 :                     n->removeType = OBJECT_ROUTINE;
    9133           6 :                     n->objects = $5;
    9134           6 :                     n->behavior = $6;
    9135           6 :                     n->missing_ok = true;
    9136           6 :                     n->concurrent = false;
    9137           6 :                     $$ = (Node *) n;
    9138             :                 }
    9139             :         ;
    9140             : 
    9141             : RemoveAggrStmt:
    9142             :             DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
    9143             :                 {
    9144          74 :                     DropStmt *n = makeNode(DropStmt);
    9145             : 
    9146          74 :                     n->removeType = OBJECT_AGGREGATE;
    9147          74 :                     n->objects = $3;
    9148          74 :                     n->behavior = $4;
    9149          74 :                     n->missing_ok = false;
    9150          74 :                     n->concurrent = false;
    9151          74 :                     $$ = (Node *) n;
    9152             :                 }
    9153             :             | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
    9154             :                 {
    9155          30 :                     DropStmt *n = makeNode(DropStmt);
    9156             : 
    9157          30 :                     n->removeType = OBJECT_AGGREGATE;
    9158          30 :                     n->objects = $5;
    9159          30 :                     n->behavior = $6;
    9160          30 :                     n->missing_ok = true;
    9161          30 :                     n->concurrent = false;
    9162          30 :                     $$ = (Node *) n;
    9163             :                 }
    9164             :         ;
    9165             : 
    9166             : RemoveOperStmt:
    9167             :             DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
    9168             :                 {
    9169         200 :                     DropStmt *n = makeNode(DropStmt);
    9170             : 
    9171         200 :                     n->removeType = OBJECT_OPERATOR;
    9172         200 :                     n->objects = $3;
    9173         200 :                     n->behavior = $4;
    9174         200 :                     n->missing_ok = false;
    9175         200 :                     n->concurrent = false;
    9176         200 :                     $$ = (Node *) n;
    9177             :                 }
    9178             :             | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
    9179             :                 {
    9180          30 :                     DropStmt *n = makeNode(DropStmt);
    9181             : 
    9182          30 :                     n->removeType = OBJECT_OPERATOR;
    9183          30 :                     n->objects = $5;
    9184          30 :                     n->behavior = $6;
    9185          30 :                     n->missing_ok = true;
    9186          30 :                     n->concurrent = false;
    9187          30 :                     $$ = (Node *) n;
    9188             :                 }
    9189             :         ;
    9190             : 
    9191             : oper_argtypes:
    9192             :             '(' Typename ')'
    9193             :                 {
    9194          12 :                    ereport(ERROR,
    9195             :                            (errcode(ERRCODE_SYNTAX_ERROR),
    9196             :                             errmsg("missing argument"),
    9197             :                             errhint("Use NONE to denote the missing argument of a unary operator."),
    9198             :                             parser_errposition(@3)));
    9199             :                 }
    9200             :             | '(' Typename ',' Typename ')'
    9201        2464 :                     { $$ = list_make2($2, $4); }
    9202             :             | '(' NONE ',' Typename ')'                 /* left unary */
    9203          32 :                     { $$ = list_make2(NULL, $4); }
    9204             :             | '(' Typename ',' NONE ')'                 /* right unary */
    9205          12 :                     { $$ = list_make2($2, NULL); }
    9206             :         ;
    9207             : 
    9208             : any_operator:
    9209             :             all_Op
    9210       22496 :                     { $$ = list_make1(makeString($1)); }
    9211             :             | ColId '.' any_operator
    9212       16246 :                     { $$ = lcons(makeString($1), $3); }
    9213             :         ;
    9214             : 
    9215             : operator_with_argtypes_list:
    9216         230 :             operator_with_argtypes                  { $$ = list_make1($1); }
    9217             :             | operator_with_argtypes_list ',' operator_with_argtypes
    9218           0 :                                                     { $$ = lappend($1, $3); }
    9219             :         ;
    9220             : 
    9221             : operator_with_argtypes:
    9222             :             any_operator oper_argtypes
    9223             :                 {
    9224        2508 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    9225             : 
    9226        2508 :                     n->objname = $1;
    9227        2508 :                     n->objargs = $2;
    9228        2508 :                     $$ = n;
    9229             :                 }
    9230             :         ;
    9231             : 
    9232             : /*****************************************************************************
    9233             :  *
    9234             :  *      DO <anonymous code block> [ LANGUAGE language ]
    9235             :  *
    9236             :  * We use a DefElem list for future extensibility, and to allow flexibility
    9237             :  * in the clause order.
    9238             :  *
    9239             :  *****************************************************************************/
    9240             : 
    9241             : DoStmt: DO dostmt_opt_list
    9242             :                 {
    9243        1142 :                     DoStmt *n = makeNode(DoStmt);
    9244             : 
    9245        1142 :                     n->args = $2;
    9246        1142 :                     $$ = (Node *) n;
    9247             :                 }
    9248             :         ;
    9249             : 
    9250             : dostmt_opt_list:
    9251        1142 :             dostmt_opt_item                     { $$ = list_make1($1); }
    9252         198 :             | dostmt_opt_list dostmt_opt_item   { $$ = lappend($1, $2); }
    9253             :         ;
    9254             : 
    9255             : dostmt_opt_item:
    9256             :             Sconst
    9257             :                 {
    9258        1142 :                     $$ = makeDefElem("as", (Node *) makeString($1), @1);
    9259             :                 }
    9260             :             | LANGUAGE NonReservedWord_or_Sconst
    9261             :                 {
    9262         198 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    9263             :                 }
    9264             :         ;
    9265             : 
    9266             : /*****************************************************************************
    9267             :  *
    9268             :  *      CREATE CAST / DROP CAST
    9269             :  *
    9270             :  *****************************************************************************/
    9271             : 
    9272             : CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
    9273             :                     WITH FUNCTION function_with_argtypes cast_context
    9274             :                 {
    9275         108 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9276             : 
    9277         108 :                     n->sourcetype = $4;
    9278         108 :                     n->targettype = $6;
    9279         108 :                     n->func = $10;
    9280         108 :                     n->context = (CoercionContext) $11;
    9281         108 :                     n->inout = false;
    9282         108 :                     $$ = (Node *) n;
    9283             :                 }
    9284             :             | CREATE CAST '(' Typename AS Typename ')'
    9285             :                     WITHOUT FUNCTION cast_context
    9286             :                 {
    9287         162 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9288             : 
    9289         162 :                     n->sourcetype = $4;
    9290         162 :                     n->targettype = $6;
    9291         162 :                     n->func = NULL;
    9292         162 :                     n->context = (CoercionContext) $10;
    9293         162 :                     n->inout = false;
    9294         162 :                     $$ = (Node *) n;
    9295             :                 }
    9296             :             | CREATE CAST '(' Typename AS Typename ')'
    9297             :                     WITH INOUT cast_context
    9298             :                 {
    9299           8 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9300             : 
    9301           8 :                     n->sourcetype = $4;
    9302           8 :                     n->targettype = $6;
    9303           8 :                     n->func = NULL;
    9304           8 :                     n->context = (CoercionContext) $10;
    9305           8 :                     n->inout = true;
    9306           8 :                     $$ = (Node *) n;
    9307             :                 }
    9308             :         ;
    9309             : 
    9310          36 : cast_context:  AS IMPLICIT_P                    { $$ = COERCION_IMPLICIT; }
    9311          58 :         | AS ASSIGNMENT                         { $$ = COERCION_ASSIGNMENT; }
    9312         184 :         | /*EMPTY*/                             { $$ = COERCION_EXPLICIT; }
    9313             :         ;
    9314             : 
    9315             : 
    9316             : DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
    9317             :                 {
    9318          60 :                     DropStmt *n = makeNode(DropStmt);
    9319             : 
    9320          60 :                     n->removeType = OBJECT_CAST;
    9321          60 :                     n->objects = list_make1(list_make2($5, $7));
    9322          60 :                     n->behavior = $9;
    9323          60 :                     n->missing_ok = $3;
    9324          60 :                     n->concurrent = false;
    9325          60 :                     $$ = (Node *) n;
    9326             :                 }
    9327             :         ;
    9328             : 
    9329          36 : opt_if_exists: IF_P EXISTS                      { $$ = true; }
    9330          38 :         | /*EMPTY*/                             { $$ = false; }
    9331             :         ;
    9332             : 
    9333             : 
    9334             : /*****************************************************************************
    9335             :  *
    9336             :  *      CREATE TRANSFORM / DROP TRANSFORM
    9337             :  *
    9338             :  *****************************************************************************/
    9339             : 
    9340             : CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name '(' transform_element_list ')'
    9341             :                 {
    9342          50 :                     CreateTransformStmt *n = makeNode(CreateTransformStmt);
    9343             : 
    9344          50 :                     n->replace = $2;
    9345          50 :                     n->type_name = $5;
    9346          50 :                     n->lang = $7;
    9347          50 :                     n->fromsql = linitial($9);
    9348          50 :                     n->tosql = lsecond($9);
    9349          50 :                     $$ = (Node *) n;
    9350             :                 }
    9351             :         ;
    9352             : 
    9353             : transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes ',' TO SQL_P WITH FUNCTION function_with_argtypes
    9354             :                 {
    9355          44 :                     $$ = list_make2($5, $11);
    9356             :                 }
    9357             :                 | TO SQL_P WITH FUNCTION function_with_argtypes ',' FROM SQL_P WITH FUNCTION function_with_argtypes
    9358             :                 {
    9359           0 :                     $$ = list_make2($11, $5);
    9360             :                 }
    9361             :                 | FROM SQL_P WITH FUNCTION function_with_argtypes
    9362             :                 {
    9363           4 :                     $$ = list_make2($5, NULL);
    9364             :                 }
    9365             :                 | TO SQL_P WITH FUNCTION function_with_argtypes
    9366             :                 {
    9367           2 :                     $$ = list_make2(NULL, $5);
    9368             :                 }
    9369             :         ;
    9370             : 
    9371             : 
    9372             : DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
    9373             :                 {
    9374          14 :                     DropStmt *n = makeNode(DropStmt);
    9375             : 
    9376          14 :                     n->removeType = OBJECT_TRANSFORM;
    9377          14 :                     n->objects = list_make1(list_make2($5, makeString($7)));
    9378          14 :                     n->behavior = $8;
    9379          14 :                     n->missing_ok = $3;
    9380          14 :                     $$ = (Node *) n;
    9381             :                 }
    9382             :         ;
    9383             : 
    9384             : 
    9385             : /*****************************************************************************
    9386             :  *
    9387             :  *      QUERY:
    9388             :  *
    9389             :  *      REINDEX [ (options) ] {INDEX | TABLE | SCHEMA} [CONCURRENTLY] <name>
    9390             :  *      REINDEX [ (options) ] {DATABASE | SYSTEM} [CONCURRENTLY] [<name>]
    9391             :  *****************************************************************************/
    9392             : 
    9393             : ReindexStmt:
    9394             :             REINDEX opt_utility_option_list reindex_target_relation opt_concurrently qualified_name
    9395             :                 {
    9396         926 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9397             : 
    9398         926 :                     n->kind = $3;
    9399         926 :                     n->relation = $5;
    9400         926 :                     n->name = NULL;
    9401         926 :                     n->params = $2;
    9402         926 :                     if ($4)
    9403         522 :                         n->params = lappend(n->params,
    9404         522 :                                             makeDefElem("concurrently", NULL, @4));
    9405         926 :                     $$ = (Node *) n;
    9406             :                 }
    9407             :             | REINDEX opt_utility_option_list SCHEMA opt_concurrently name
    9408             :                 {
    9409         114 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9410             : 
    9411         114 :                     n->kind = REINDEX_OBJECT_SCHEMA;
    9412         114 :                     n->relation = NULL;
    9413         114 :                     n->name = $5;
    9414         114 :                     n->params = $2;
    9415         114 :                     if ($4)
    9416          40 :                         n->params = lappend(n->params,
    9417          40 :                                             makeDefElem("concurrently", NULL, @4));
    9418         114 :                     $$ = (Node *) n;
    9419             :                 }
    9420             :             | REINDEX opt_utility_option_list reindex_target_all opt_concurrently opt_single_name
    9421             :                 {
    9422          66 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9423             : 
    9424          66 :                     n->kind = $3;
    9425          66 :                     n->relation = NULL;
    9426          66 :                     n->name = $5;
    9427          66 :                     n->params = $2;
    9428          66 :                     if ($4)
    9429          10 :                         n->params = lappend(n->params,
    9430          10 :                                             makeDefElem("concurrently", NULL, @4));
    9431          66 :                     $$ = (Node *) n;
    9432             :                 }
    9433             :         ;
    9434             : reindex_target_relation:
    9435         398 :             INDEX                   { $$ = REINDEX_OBJECT_INDEX; }
    9436         528 :             | TABLE                 { $$ = REINDEX_OBJECT_TABLE; }
    9437             :         ;
    9438             : reindex_target_all:
    9439          34 :             SYSTEM_P                { $$ = REINDEX_OBJECT_SYSTEM; }
    9440          32 :             | DATABASE              { $$ = REINDEX_OBJECT_DATABASE; }
    9441             :         ;
    9442             : 
    9443             : /*****************************************************************************
    9444             :  *
    9445             :  * ALTER TABLESPACE
    9446             :  *
    9447             :  *****************************************************************************/
    9448             : 
    9449             : AlterTblSpcStmt:
    9450             :             ALTER TABLESPACE name SET reloptions
    9451             :                 {
    9452             :                     AlterTableSpaceOptionsStmt *n =
    9453          12 :                         makeNode(AlterTableSpaceOptionsStmt);
    9454             : 
    9455          12 :                     n->tablespacename = $3;
    9456          12 :                     n->options = $5;
    9457          12 :                     n->isReset = false;
    9458          12 :                     $$ = (Node *) n;
    9459             :                 }
    9460             :             | ALTER TABLESPACE name RESET reloptions
    9461             :                 {
    9462             :                     AlterTableSpaceOptionsStmt *n =
    9463          12 :                         makeNode(AlterTableSpaceOptionsStmt);
    9464             : 
    9465          12 :                     n->tablespacename = $3;
    9466          12 :                     n->options = $5;
    9467          12 :                     n->isReset = true;
    9468          12 :                     $$ = (Node *) n;
    9469             :                 }
    9470             :         ;
    9471             : 
    9472             : /*****************************************************************************
    9473             :  *
    9474             :  * ALTER THING name RENAME TO newname
    9475             :  *
    9476             :  *****************************************************************************/
    9477             : 
    9478             : RenameStmt: ALTER AGGREGATE aggregate_with_argtypes RENAME TO name
    9479             :                 {
    9480          42 :                     RenameStmt *n = makeNode(RenameStmt);
    9481             : 
    9482          42 :                     n->renameType = OBJECT_AGGREGATE;
    9483          42 :                     n->object = (Node *) $3;
    9484          42 :                     n->newname = $6;
    9485          42 :                     n->missing_ok = false;
    9486          42 :                     $$ = (Node *) n;
    9487             :                 }
    9488             :             | ALTER COLLATION any_name RENAME TO name
    9489             :                 {
    9490          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9491             : 
    9492          18 :                     n->renameType = OBJECT_COLLATION;
    9493          18 :                     n->object = (Node *) $3;
    9494          18 :                     n->newname = $6;
    9495          18 :                     n->missing_ok = false;
    9496          18 :                     $$ = (Node *) n;
    9497             :                 }
    9498             :             | ALTER CONVERSION_P any_name RENAME TO name
    9499             :                 {
    9500          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9501             : 
    9502          24 :                     n->renameType = OBJECT_CONVERSION;
    9503          24 :                     n->object = (Node *) $3;
    9504          24 :                     n->newname = $6;
    9505          24 :                     n->missing_ok = false;
    9506          24 :                     $$ = (Node *) n;
    9507             :                 }
    9508             :             | ALTER DATABASE name RENAME TO name
    9509             :                 {
    9510          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9511             : 
    9512          12 :                     n->renameType = OBJECT_DATABASE;
    9513          12 :                     n->subname = $3;
    9514          12 :                     n->newname = $6;
    9515          12 :                     n->missing_ok = false;
    9516          12 :                     $$ = (Node *) n;
    9517             :                 }
    9518             :             | ALTER DOMAIN_P any_name RENAME TO name
    9519             :                 {
    9520           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9521             : 
    9522           6 :                     n->renameType = OBJECT_DOMAIN;
    9523           6 :                     n->object = (Node *) $3;
    9524           6 :                     n->newname = $6;
    9525           6 :                     n->missing_ok = false;
    9526           6 :                     $$ = (Node *) n;
    9527             :                 }
    9528             :             | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
    9529             :                 {
    9530           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9531             : 
    9532           6 :                     n->renameType = OBJECT_DOMCONSTRAINT;
    9533           6 :                     n->object = (Node *) $3;
    9534           6 :                     n->subname = $6;
    9535           6 :                     n->newname = $8;
    9536           6 :                     $$ = (Node *) n;
    9537             :                 }
    9538             :             | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
    9539             :                 {
    9540          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9541             : 
    9542          24 :                     n->renameType = OBJECT_FDW;
    9543          24 :                     n->object = (Node *) makeString($5);
    9544          24 :                     n->newname = $8;
    9545          24 :                     n->missing_ok = false;
    9546          24 :                     $$ = (Node *) n;
    9547             :                 }
    9548             :             | ALTER FUNCTION function_with_argtypes RENAME TO name
    9549             :                 {
    9550          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9551             : 
    9552          24 :                     n->renameType = OBJECT_FUNCTION;
    9553          24 :                     n->object = (Node *) $3;
    9554          24 :                     n->newname = $6;
    9555          24 :                     n->missing_ok = false;
    9556          24 :                     $$ = (Node *) n;
    9557             :                 }
    9558             :             | ALTER GROUP_P RoleId RENAME TO RoleId
    9559             :                 {
    9560           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9561             : 
    9562           0 :                     n->renameType = OBJECT_ROLE;
    9563           0 :                     n->subname = $3;
    9564           0 :                     n->newname = $6;
    9565           0 :                     n->missing_ok = false;
    9566           0 :                     $$ = (Node *) n;
    9567             :                 }
    9568             :             | ALTER opt_procedural LANGUAGE name RENAME TO name
    9569             :                 {
    9570          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9571             : 
    9572          18 :                     n->renameType = OBJECT_LANGUAGE;
    9573          18 :                     n->object = (Node *) makeString($4);
    9574          18 :                     n->newname = $7;
    9575          18 :                     n->missing_ok = false;
    9576          18 :                     $$ = (Node *) n;
    9577             :                 }
    9578             :             | ALTER OPERATOR CLASS any_name USING name RENAME TO name
    9579             :                 {
    9580          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9581             : 
    9582          24 :                     n->renameType = OBJECT_OPCLASS;
    9583          24 :                     n->object = (Node *) lcons(makeString($6), $4);
    9584          24 :                     n->newname = $9;
    9585          24 :                     n->missing_ok = false;
    9586          24 :                     $$ = (Node *) n;
    9587             :                 }
    9588             :             | ALTER OPERATOR FAMILY any_name USING name RENAME TO name
    9589             :                 {
    9590          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9591             : 
    9592          24 :                     n->renameType = OBJECT_OPFAMILY;
    9593          24 :                     n->object = (Node *) lcons(makeString($6), $4);
    9594          24 :                     n->newname = $9;
    9595          24 :                     n->missing_ok = false;
    9596          24 :                     $$ = (Node *) n;
    9597             :                 }
    9598             :             | ALTER POLICY name ON qualified_name RENAME TO name
    9599             :                 {
    9600          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9601             : 
    9602          18 :                     n->renameType = OBJECT_POLICY;
    9603          18 :                     n->relation = $5;
    9604          18 :                     n->subname = $3;
    9605          18 :                     n->newname = $8;
    9606          18 :                     n->missing_ok = false;
    9607          18 :                     $$ = (Node *) n;
    9608             :                 }
    9609             :             | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
    9610             :                 {
    9611           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9612             : 
    9613           0 :                     n->renameType = OBJECT_POLICY;
    9614           0 :                     n->relation = $7;
    9615           0 :                     n->subname = $5;
    9616           0 :                     n->newname = $10;
    9617           0 :                     n->missing_ok = true;
    9618           0 :                     $$ = (Node *) n;
    9619             :                 }
    9620             :             | ALTER PROCEDURE function_with_argtypes RENAME TO name
    9621             :                 {
    9622           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9623             : 
    9624           0 :                     n->renameType = OBJECT_PROCEDURE;
    9625           0 :                     n->object = (Node *) $3;
    9626           0 :                     n->newname = $6;
    9627           0 :                     n->missing_ok = false;
    9628           0 :                     $$ = (Node *) n;
    9629             :                 }
    9630             :             | ALTER PUBLICATION name RENAME TO name
    9631             :                 {
    9632          42 :                     RenameStmt *n = makeNode(RenameStmt);
    9633             : 
    9634          42 :                     n->renameType = OBJECT_PUBLICATION;
    9635          42 :                     n->object = (Node *) makeString($3);
    9636          42 :                     n->newname = $6;
    9637          42 :                     n->missing_ok = false;
    9638          42 :                     $$ = (Node *) n;
    9639             :                 }
    9640             :             | ALTER ROUTINE function_with_argtypes RENAME TO name
    9641             :                 {
    9642          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9643             : 
    9644          24 :                     n->renameType = OBJECT_ROUTINE;
    9645          24 :                     n->object = (Node *) $3;
    9646          24 :                     n->newname = $6;
    9647          24 :                     n->missing_ok = false;
    9648          24 :                     $$ = (Node *) n;
    9649             :                 }
    9650             :             | ALTER SCHEMA name RENAME TO name
    9651             :                 {
    9652          20 :                     RenameStmt *n = makeNode(RenameStmt);
    9653             : 
    9654          20 :                     n->renameType = OBJECT_SCHEMA;
    9655          20 :                     n->subname = $3;
    9656          20 :                     n->newname = $6;
    9657          20 :                     n->missing_ok = false;
    9658          20 :                     $$ = (Node *) n;
    9659             :                 }
    9660             :             | ALTER SERVER name RENAME TO name
    9661             :                 {
    9662          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9663             : 
    9664          24 :                     n->renameType = OBJECT_FOREIGN_SERVER;
    9665          24 :                     n->object = (Node *) makeString($3);
    9666          24 :                     n->newname = $6;
    9667          24 :                     n->missing_ok = false;
    9668          24 :                     $$ = (Node *) n;
    9669             :                 }
    9670             :             | ALTER SUBSCRIPTION name RENAME TO name
    9671             :                 {
    9672          38 :                     RenameStmt *n = makeNode(RenameStmt);
    9673             : 
    9674          38 :                     n->renameType = OBJECT_SUBSCRIPTION;
    9675          38 :                     n->object = (Node *) makeString($3);
    9676          38 :                     n->newname = $6;
    9677          38 :                     n->missing_ok = false;
    9678          38 :                     $$ = (Node *) n;
    9679             :                 }
    9680             :             | ALTER TABLE relation_expr RENAME TO name
    9681             :                 {
    9682         288 :                     RenameStmt *n = makeNode(RenameStmt);
    9683             : 
    9684         288 :                     n->renameType = OBJECT_TABLE;
    9685         288 :                     n->relation = $3;
    9686         288 :                     n->subname = NULL;
    9687         288 :                     n->newname = $6;
    9688         288 :                     n->missing_ok = false;
    9689         288 :                     $$ = (Node *) n;
    9690             :                 }
    9691             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
    9692             :                 {
    9693           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9694             : 
    9695           0 :                     n->renameType = OBJECT_TABLE;
    9696           0 :                     n->relation = $5;
    9697           0 :                     n->subname = NULL;
    9698           0 :                     n->newname = $8;
    9699           0 :                     n->missing_ok = true;
    9700           0 :                     $$ = (Node *) n;
    9701             :                 }
    9702             :             | ALTER SEQUENCE qualified_name RENAME TO name
    9703             :                 {
    9704           2 :                     RenameStmt *n = makeNode(RenameStmt);
    9705             : 
    9706           2 :                     n->renameType = OBJECT_SEQUENCE;
    9707           2 :                     n->relation = $3;
    9708           2 :                     n->subname = NULL;
    9709           2 :                     n->newname = $6;
    9710           2 :                     n->missing_ok = false;
    9711           2 :                     $$ = (Node *) n;
    9712             :                 }
    9713             :             | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
    9714             :                 {
    9715           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9716             : 
    9717           0 :                     n->renameType = OBJECT_SEQUENCE;
    9718           0 :                     n->relation = $5;
    9719           0 :                     n->subname = NULL;
    9720           0 :                     n->newname = $8;
    9721           0 :                     n->missing_ok = true;
    9722           0 :                     $$ = (Node *) n;
    9723             :                 }
    9724             :             | ALTER VIEW qualified_name RENAME TO name
    9725             :                 {
    9726           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9727             : 
    9728           6 :                     n->renameType = OBJECT_VIEW;
    9729           6 :                     n->relation = $3;
    9730           6 :                     n->subname = NULL;
    9731           6 :                     n->newname = $6;
    9732           6 :                     n->missing_ok = false;
    9733           6 :                     $$ = (Node *) n;
    9734             :                 }
    9735             :             | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
    9736             :                 {
    9737           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9738             : 
    9739           0 :                     n->renameType = OBJECT_VIEW;
    9740           0 :                     n->relation = $5;
    9741           0 :                     n->subname = NULL;
    9742           0 :                     n->newname = $8;
    9743           0 :                     n->missing_ok = true;
    9744           0 :                     $$ = (Node *) n;
    9745             :                 }
    9746             :             | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
    9747             :                 {
    9748           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9749             : 
    9750           0 :                     n->renameType = OBJECT_MATVIEW;
    9751           0 :                     n->relation = $4;
    9752           0 :                     n->subname = NULL;
    9753           0 :                     n->newname = $7;
    9754           0 :                     n->missing_ok = false;
    9755           0 :                     $$ = (Node *) n;
    9756             :                 }
    9757             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
    9758             :                 {
    9759           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9760             : 
    9761           0 :                     n->renameType = OBJECT_MATVIEW;
    9762           0 :                     n->relation = $6;
    9763           0 :                     n->subname = NULL;
    9764           0 :                     n->newname = $9;
    9765           0 :                     n->missing_ok = true;
    9766           0 :                     $$ = (Node *) n;
    9767             :                 }
    9768             :             | ALTER INDEX qualified_name RENAME TO name
    9769             :                 {
    9770         192 :                     RenameStmt *n = makeNode(RenameStmt);
    9771             : 
    9772         192 :                     n->renameType = OBJECT_INDEX;
    9773         192 :                     n->relation = $3;
    9774         192 :                     n->subname = NULL;
    9775         192 :                     n->newname = $6;
    9776         192 :                     n->missing_ok = false;
    9777         192 :                     $$ = (Node *) n;
    9778             :                 }
    9779             :             | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
    9780             :                 {
    9781          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9782             : 
    9783          12 :                     n->renameType = OBJECT_INDEX;
    9784          12 :                     n->relation = $5;
    9785          12 :                     n->subname = NULL;
    9786          12 :                     n->newname = $8;
    9787          12 :                     n->missing_ok = true;
    9788          12 :                     $$ = (Node *) n;
    9789             :                 }
    9790             :             | ALTER FOREIGN TABLE relation_expr RENAME TO name
    9791             :                 {
    9792           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9793             : 
    9794           6 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9795           6 :                     n->relation = $4;
    9796           6 :                     n->subname = NULL;
    9797           6 :                     n->newname = $7;
    9798           6 :                     n->missing_ok = false;
    9799           6 :                     $$ = (Node *) n;
    9800             :                 }
    9801             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
    9802             :                 {
    9803           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9804             : 
    9805           6 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9806           6 :                     n->relation = $6;
    9807           6 :                     n->subname = NULL;
    9808           6 :                     n->newname = $9;
    9809           6 :                     n->missing_ok = true;
    9810           6 :                     $$ = (Node *) n;
    9811             :                 }
    9812             :             | ALTER TABLE relation_expr RENAME opt_column name TO name
    9813             :                 {
    9814         238 :                     RenameStmt *n = makeNode(RenameStmt);
    9815             : 
    9816         238 :                     n->renameType = OBJECT_COLUMN;
    9817         238 :                     n->relationType = OBJECT_TABLE;
    9818         238 :                     n->relation = $3;
    9819         238 :                     n->subname = $6;
    9820         238 :                     n->newname = $8;
    9821         238 :                     n->missing_ok = false;
    9822         238 :                     $$ = (Node *) n;
    9823             :                 }
    9824             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9825             :                 {
    9826          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9827             : 
    9828          24 :                     n->renameType = OBJECT_COLUMN;
    9829          24 :                     n->relationType = OBJECT_TABLE;
    9830          24 :                     n->relation = $5;
    9831          24 :                     n->subname = $8;
    9832          24 :                     n->newname = $10;
    9833          24 :                     n->missing_ok = true;
    9834          24 :                     $$ = (Node *) n;
    9835             :                 }
    9836             :             | ALTER VIEW qualified_name RENAME opt_column name TO name
    9837             :                 {
    9838          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9839             : 
    9840          18 :                     n->renameType = OBJECT_COLUMN;
    9841          18 :                     n->relationType = OBJECT_VIEW;
    9842          18 :                     n->relation = $3;
    9843          18 :                     n->subname = $6;
    9844          18 :                     n->newname = $8;
    9845          18 :                     n->missing_ok = false;
    9846          18 :                     $$ = (Node *) n;
    9847             :                 }
    9848             :             | ALTER VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    9849             :                 {
    9850           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9851             : 
    9852           0 :                     n->renameType = OBJECT_COLUMN;
    9853           0 :                     n->relationType = OBJECT_VIEW;
    9854           0 :                     n->relation = $5;
    9855           0 :                     n->subname = $8;
    9856           0 :                     n->newname = $10;
    9857           0 :                     n->missing_ok = true;
    9858           0 :                     $$ = (Node *) n;
    9859             :                 }
    9860             :             | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
    9861             :                 {
    9862           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9863             : 
    9864           0 :                     n->renameType = OBJECT_COLUMN;
    9865           0 :                     n->relationType = OBJECT_MATVIEW;
    9866           0 :                     n->relation = $4;
    9867           0 :                     n->subname = $7;
    9868           0 :                     n->newname = $9;
    9869           0 :                     n->missing_ok = false;
    9870           0 :                     $$ = (Node *) n;
    9871             :                 }
    9872             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    9873             :                 {
    9874           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9875             : 
    9876           0 :                     n->renameType = OBJECT_COLUMN;
    9877           0 :                     n->relationType = OBJECT_MATVIEW;
    9878           0 :                     n->relation = $6;
    9879           0 :                     n->subname = $9;
    9880           0 :                     n->newname = $11;
    9881           0 :                     n->missing_ok = true;
    9882           0 :                     $$ = (Node *) n;
    9883             :                 }
    9884             :             | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
    9885             :                 {
    9886          72 :                     RenameStmt *n = makeNode(RenameStmt);
    9887             : 
    9888          72 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9889          72 :                     n->relation = $3;
    9890          72 :                     n->subname = $6;
    9891          72 :                     n->newname = $8;
    9892          72 :                     n->missing_ok = false;
    9893          72 :                     $$ = (Node *) n;
    9894             :                 }
    9895             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
    9896             :                 {
    9897           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9898             : 
    9899           6 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9900           6 :                     n->relation = $5;
    9901           6 :                     n->subname = $8;
    9902           6 :                     n->newname = $10;
    9903           6 :                     n->missing_ok = true;
    9904           6 :                     $$ = (Node *) n;
    9905             :                 }
    9906             :             | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
    9907             :                 {
    9908           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9909             : 
    9910           6 :                     n->renameType = OBJECT_COLUMN;
    9911           6 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    9912           6 :                     n->relation = $4;
    9913           6 :                     n->subname = $7;
    9914           6 :                     n->newname = $9;
    9915           6 :                     n->missing_ok = false;
    9916           6 :                     $$ = (Node *) n;
    9917             :                 }
    9918             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9919             :                 {
    9920           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9921             : 
    9922           6 :                     n->renameType = OBJECT_COLUMN;
    9923           6 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    9924           6 :                     n->relation = $6;
    9925           6 :                     n->subname = $9;
    9926           6 :                     n->newname = $11;
    9927           6 :                     n->missing_ok = true;
    9928           6 :                     $$ = (Node *) n;
    9929             :                 }
    9930             :             | ALTER RULE name ON qualified_name RENAME TO name
    9931             :                 {
    9932          34 :                     RenameStmt *n = makeNode(RenameStmt);
    9933             : 
    9934          34 :                     n->renameType = OBJECT_RULE;
    9935          34 :                     n->relation = $5;
    9936          34 :                     n->subname = $3;
    9937          34 :                     n->newname = $8;
    9938          34 :                     n->missing_ok = false;
    9939          34 :                     $$ = (Node *) n;
    9940             :                 }
    9941             :             | ALTER TRIGGER name ON qualified_name RENAME TO name
    9942             :                 {
    9943          40 :                     RenameStmt *n = makeNode(RenameStmt);
    9944             : 
    9945          40 :                     n->renameType = OBJECT_TRIGGER;
    9946          40 :                     n->relation = $5;
    9947          40 :                     n->subname = $3;
    9948          40 :                     n->newname = $8;
    9949          40 :                     n->missing_ok = false;
    9950          40 :                     $$ = (Node *) n;
    9951             :                 }
    9952             :             | ALTER EVENT TRIGGER name RENAME TO name
    9953             :                 {
    9954          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9955             : 
    9956          12 :                     n->renameType = OBJECT_EVENT_TRIGGER;
    9957          12 :                     n->object = (Node *) makeString($4);
    9958          12 :                     n->newname = $7;
    9959          12 :                     $$ = (Node *) n;
    9960             :                 }
    9961             :             | ALTER ROLE RoleId RENAME TO RoleId
    9962             :                 {
    9963          32 :                     RenameStmt *n = makeNode(RenameStmt);
    9964             : 
    9965          32 :                     n->renameType = OBJECT_ROLE;
    9966          32 :                     n->subname = $3;
    9967          32 :                     n->newname = $6;
    9968          32 :                     n->missing_ok = false;
    9969          32 :                     $$ = (Node *) n;
    9970             :                 }
    9971             :             | ALTER USER RoleId RENAME TO RoleId
    9972             :                 {
    9973           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9974             : 
    9975           0 :                     n->renameType = OBJECT_ROLE;
    9976           0 :                     n->subname = $3;
    9977           0 :                     n->newname = $6;
    9978           0 :                     n->missing_ok = false;
    9979           0 :                     $$ = (Node *) n;
    9980             :                 }
    9981             :             | ALTER TABLESPACE name RENAME TO name
    9982             :                 {
    9983           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9984             : 
    9985           6 :                     n->renameType = OBJECT_TABLESPACE;
    9986           6 :                     n->subname = $3;
    9987           6 :                     n->newname = $6;
    9988           6 :                     n->missing_ok = false;
    9989           6 :                     $$ = (Node *) n;
    9990             :                 }
    9991             :             | ALTER STATISTICS any_name RENAME TO name
    9992             :                 {
    9993          30 :                     RenameStmt *n = makeNode(RenameStmt);
    9994             : 
    9995          30 :                     n->renameType = OBJECT_STATISTIC_EXT;
    9996          30 :                     n->object = (Node *) $3;
    9997          30 :                     n->newname = $6;
    9998          30 :                     n->missing_ok = false;
    9999          30 :                     $$ = (Node *) n;
   10000             :                 }
   10001             :             | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
   10002             :                 {
   10003          12 :                     RenameStmt *n = makeNode(RenameStmt);
   10004             : 
   10005          12 :                     n->renameType = OBJECT_TSPARSER;
   10006          12 :                     n->object = (Node *) $5;
   10007          12 :                     n->newname = $8;
   10008          12 :                     n->missing_ok = false;
   10009          12 :                     $$ = (Node *) n;
   10010             :                 }
   10011             :             | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
   10012             :                 {
   10013          24 :                     RenameStmt *n = makeNode(RenameStmt);
   10014             : 
   10015          24 :                     n->renameType = OBJECT_TSDICTIONARY;
   10016          24 :                     n->object = (Node *) $5;
   10017          24 :                     n->newname = $8;
   10018          24 :                     n->missing_ok = false;
   10019          24 :                     $$ = (Node *) n;
   10020             :                 }
   10021             :             | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
   10022             :                 {
   10023          12 :                     RenameStmt *n = makeNode(RenameStmt);
   10024             : 
   10025          12 :                     n->renameType = OBJECT_TSTEMPLATE;
   10026          12 :                     n->object = (Node *) $5;
   10027          12 :                     n->newname = $8;
   10028          12 :                     n->missing_ok = false;
   10029          12 :                     $$ = (Node *) n;
   10030             :                 }
   10031             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
   10032             :                 {
   10033          24 :                     RenameStmt *n = makeNode(RenameStmt);
   10034             : 
   10035          24 :                     n->renameType = OBJECT_TSCONFIGURATION;
   10036          24 :                     n->object = (Node *) $5;
   10037          24 :                     n->newname = $8;
   10038          24 :                     n->missing_ok = false;
   10039          24 :                     $$ = (Node *) n;
   10040             :                 }
   10041             :             | ALTER TYPE_P any_name RENAME TO name
   10042             :                 {
   10043          26 :                     RenameStmt *n = makeNode(RenameStmt);
   10044             : 
   10045          26 :                     n->renameType = OBJECT_TYPE;
   10046          26 :                     n->object = (Node *) $3;
   10047          26 :                     n->newname = $6;
   10048          26 :                     n->missing_ok = false;
   10049          26 :                     $$ = (Node *) n;
   10050             :                 }
   10051             :             | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
   10052             :                 {
   10053          24 :                     RenameStmt *n = makeNode(RenameStmt);
   10054             : 
   10055          24 :                     n->renameType = OBJECT_ATTRIBUTE;
   10056          24 :                     n->relationType = OBJECT_TYPE;
   10057          24 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
   10058          24 :                     n->subname = $6;
   10059          24 :                     n->newname = $8;
   10060          24 :                     n->behavior = $9;
   10061          24 :                     n->missing_ok = false;
   10062          24 :                     $$ = (Node *) n;
   10063             :                 }
   10064             :         ;
   10065             : 
   10066             : opt_column: COLUMN
   10067             :             | /*EMPTY*/
   10068             :         ;
   10069             : 
   10070         184 : opt_set_data: SET DATA_P                            { $$ = 1; }
   10071         914 :             | /*EMPTY*/                             { $$ = 0; }
   10072             :         ;
   10073             : 
   10074             : /*****************************************************************************
   10075             :  *
   10076             :  * ALTER THING name DEPENDS ON EXTENSION name
   10077             :  *
   10078             :  *****************************************************************************/
   10079             : 
   10080             : AlterObjectDependsStmt:
   10081             :             ALTER FUNCTION function_with_argtypes opt_no DEPENDS ON EXTENSION name
   10082             :                 {
   10083          12 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10084             : 
   10085          12 :                     n->objectType = OBJECT_FUNCTION;
   10086          12 :                     n->object = (Node *) $3;
   10087          12 :                     n->extname = makeString($8);
   10088          12 :                     n->remove = $4;
   10089          12 :                     $$ = (Node *) n;
   10090             :                 }
   10091             :             | ALTER PROCEDURE function_with_argtypes opt_no DEPENDS ON EXTENSION name
   10092             :                 {
   10093           0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10094             : 
   10095           0 :                     n->objectType = OBJECT_PROCEDURE;
   10096           0 :                     n->object = (Node *) $3;
   10097           0 :                     n->extname = makeString($8);
   10098           0 :                     n->remove = $4;
   10099           0 :                     $$ = (Node *) n;
   10100             :                 }
   10101             :             | ALTER ROUTINE function_with_argtypes opt_no DEPENDS ON EXTENSION name
   10102             :                 {
   10103           0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10104             : 
   10105           0 :                     n->objectType = OBJECT_ROUTINE;
   10106           0 :                     n->object = (Node *) $3;
   10107           0 :                     n->extname = makeString($8);
   10108           0 :                     n->remove = $4;
   10109           0 :                     $$ = (Node *) n;
   10110             :                 }
   10111             :             | ALTER TRIGGER name ON qualified_name opt_no DEPENDS ON EXTENSION name
   10112             :                 {
   10113          10 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10114             : 
   10115          10 :                     n->objectType = OBJECT_TRIGGER;
   10116          10 :                     n->relation = $5;
   10117          10 :                     n->object = (Node *) list_make1(makeString($3));
   10118          10 :                     n->extname = makeString($10);
   10119          10 :                     n->remove = $6;
   10120          10 :                     $$ = (Node *) n;
   10121             :                 }
   10122             :             | ALTER MATERIALIZED VIEW qualified_name opt_no DEPENDS ON EXTENSION name
   10123             :                 {
   10124          10 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10125             : 
   10126          10 :                     n->objectType = OBJECT_MATVIEW;
   10127          10 :                     n->relation = $4;
   10128          10 :                     n->extname = makeString($9);
   10129          10 :                     n->remove = $5;
   10130          10 :                     $$ = (Node *) n;
   10131             :                 }
   10132             :             | ALTER INDEX qualified_name opt_no DEPENDS ON EXTENSION name
   10133             :                 {
   10134          14 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10135             : 
   10136          14 :                     n->objectType = OBJECT_INDEX;
   10137          14 :                     n->relation = $3;
   10138          14 :                     n->extname = makeString($8);
   10139          14 :                     n->remove = $4;
   10140          14 :                     $$ = (Node *) n;
   10141             :                 }
   10142             :         ;
   10143             : 
   10144           8 : opt_no:     NO              { $$ = true; }
   10145          38 :             | /* EMPTY */   { $$ = false;   }
   10146             :         ;
   10147             : 
   10148             : /*****************************************************************************
   10149             :  *
   10150             :  * ALTER THING name SET SCHEMA name
   10151             :  *
   10152             :  *****************************************************************************/
   10153             : 
   10154             : AlterObjectSchemaStmt:
   10155             :             ALTER AGGREGATE aggregate_with_argtypes SET SCHEMA name
   10156             :                 {
   10157          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10158             : 
   10159          24 :                     n->objectType = OBJECT_AGGREGATE;
   10160          24 :                     n->object = (Node *) $3;
   10161          24 :                     n->newschema = $6;
   10162          24 :                     n->missing_ok = false;
   10163          24 :                     $$ = (Node *) n;
   10164             :                 }
   10165             :             | ALTER COLLATION any_name SET SCHEMA name
   10166             :                 {
   10167           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10168             : 
   10169           6 :                     n->objectType = OBJECT_COLLATION;
   10170           6 :                     n->object = (Node *) $3;
   10171           6 :                     n->newschema = $6;
   10172           6 :                     n->missing_ok = false;
   10173           6 :                     $$ = (Node *) n;
   10174             :                 }
   10175             :             | ALTER CONVERSION_P any_name SET SCHEMA name
   10176             :                 {
   10177          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10178             : 
   10179          24 :                     n->objectType = OBJECT_CONVERSION;
   10180          24 :                     n->object = (Node *) $3;
   10181          24 :                     n->newschema = $6;
   10182          24 :                     n->missing_ok = false;
   10183          24 :                     $$ = (Node *) n;
   10184             :                 }
   10185             :             | ALTER DOMAIN_P any_name SET SCHEMA name
   10186             :                 {
   10187           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10188             : 
   10189           6 :                     n->objectType = OBJECT_DOMAIN;
   10190           6 :                     n->object = (Node *) $3;
   10191           6 :                     n->newschema = $6;
   10192           6 :                     n->missing_ok = false;
   10193           6 :                     $$ = (Node *) n;
   10194             :                 }
   10195             :             | ALTER EXTENSION name SET SCHEMA name
   10196             :                 {
   10197          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10198             : 
   10199          12 :                     n->objectType = OBJECT_EXTENSION;
   10200          12 :                     n->object = (Node *) makeString($3);
   10201          12 :                     n->newschema = $6;
   10202          12 :                     n->missing_ok = false;
   10203          12 :                     $$ = (Node *) n;
   10204             :                 }
   10205             :             | ALTER FUNCTION function_with_argtypes SET SCHEMA name
   10206             :                 {
   10207          42 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10208             : 
   10209          42 :                     n->objectType = OBJECT_FUNCTION;
   10210          42 :                     n->object = (Node *) $3;
   10211          42 :                     n->newschema = $6;
   10212          42 :                     n->missing_ok = false;
   10213          42 :                     $$ = (Node *) n;
   10214             :                 }
   10215             :             | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
   10216             :                 {
   10217          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10218             : 
   10219          18 :                     n->objectType = OBJECT_OPERATOR;
   10220          18 :                     n->object = (Node *) $3;
   10221          18 :                     n->newschema = $6;
   10222          18 :                     n->missing_ok = false;
   10223          18 :                     $$ = (Node *) n;
   10224             :                 }
   10225             :             | ALTER OPERATOR CLASS any_name USING name SET SCHEMA name
   10226             :                 {
   10227          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10228             : 
   10229          24 :                     n->objectType = OBJECT_OPCLASS;
   10230          24 :                     n->object = (Node *) lcons(makeString($6), $4);
   10231          24 :                     n->newschema = $9;
   10232          24 :                     n->missing_ok = false;
   10233          24 :                     $$ = (Node *) n;
   10234             :                 }
   10235             :             | ALTER OPERATOR FAMILY any_name USING name SET SCHEMA name
   10236             :                 {
   10237          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10238             : 
   10239          24 :                     n->objectType = OBJECT_OPFAMILY;
   10240          24 :                     n->object = (Node *) lcons(makeString($6), $4);
   10241          24 :                     n->newschema = $9;
   10242          24 :                     n->missing_ok = false;
   10243          24 :                     $$ = (Node *) n;
   10244             :                 }
   10245             :             | ALTER PROCEDURE function_with_argtypes SET SCHEMA name
   10246             :                 {
   10247           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10248             : 
   10249           0 :                     n->objectType = OBJECT_PROCEDURE;
   10250           0 :                     n->object = (Node *) $3;
   10251           0 :                     n->newschema = $6;
   10252           0 :                     n->missing_ok = false;
   10253           0 :                     $$ = (Node *) n;
   10254             :                 }
   10255             :             | ALTER ROUTINE function_with_argtypes SET SCHEMA name
   10256             :                 {
   10257           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10258             : 
   10259           0 :                     n->objectType = OBJECT_ROUTINE;
   10260           0 :                     n->object = (Node *) $3;
   10261           0 :                     n->newschema = $6;
   10262           0 :                     n->missing_ok = false;
   10263           0 :                     $$ = (Node *) n;
   10264             :                 }
   10265             :             | ALTER TABLE relation_expr SET SCHEMA name
   10266             :                 {
   10267          66 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10268             : 
   10269          66 :                     n->objectType = OBJECT_TABLE;
   10270          66 :                     n->relation = $3;
   10271          66 :                     n->newschema = $6;
   10272          66 :                     n->missing_ok = false;
   10273          66 :                     $$ = (Node *) n;
   10274             :                 }
   10275             :             | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10276             :                 {
   10277          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10278             : 
   10279          12 :                     n->objectType = OBJECT_TABLE;
   10280          12 :                     n->relation = $5;
   10281          12 :                     n->newschema = $8;
   10282          12 :                     n->missing_ok = true;
   10283          12 :                     $$ = (Node *) n;
   10284             :                 }
   10285             :             | ALTER STATISTICS any_name SET SCHEMA name
   10286             :                 {
   10287          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10288             : 
   10289          18 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10290          18 :                     n->object = (Node *) $3;
   10291          18 :                     n->newschema = $6;
   10292          18 :                     n->missing_ok = false;
   10293          18 :                     $$ = (Node *) n;
   10294             :                 }
   10295             :             | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
   10296             :                 {
   10297          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10298             : 
   10299          18 :                     n->objectType = OBJECT_TSPARSER;
   10300          18 :                     n->object = (Node *) $5;
   10301          18 :                     n->newschema = $8;
   10302          18 :                     n->missing_ok = false;
   10303          18 :                     $$ = (Node *) n;
   10304             :                 }
   10305             :             | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
   10306             :                 {
   10307          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10308             : 
   10309          24 :                     n->objectType = OBJECT_TSDICTIONARY;
   10310          24 :                     n->object = (Node *) $5;
   10311          24 :                     n->newschema = $8;
   10312          24 :                     n->missing_ok = false;
   10313          24 :                     $$ = (Node *) n;
   10314             :                 }
   10315             :             | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
   10316             :                 {
   10317          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10318             : 
   10319          18 :                     n->objectType = OBJECT_TSTEMPLATE;
   10320          18 :                     n->object = (Node *) $5;
   10321          18 :                     n->newschema = $8;
   10322          18 :                     n->missing_ok = false;
   10323          18 :                     $$ = (Node *) n;
   10324             :                 }
   10325             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
   10326             :                 {
   10327          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10328             : 
   10329          24 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10330          24 :                     n->object = (Node *) $5;
   10331          24 :                     n->newschema = $8;
   10332          24 :                     n->missing_ok = false;
   10333          24 :                     $$ = (Node *) n;
   10334             :                 }
   10335             :             | ALTER SEQUENCE qualified_name SET SCHEMA name
   10336             :                 {
   10337           8 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10338             : 
   10339           8 :                     n->objectType = OBJECT_SEQUENCE;
   10340           8 :                     n->relation = $3;
   10341           8 :                     n->newschema = $6;
   10342           8 :                     n->missing_ok = false;
   10343           8 :                     $$ = (Node *) n;
   10344             :                 }
   10345             :             | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
   10346             :                 {
   10347           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10348             : 
   10349           0 :                     n->objectType = OBJECT_SEQUENCE;
   10350           0 :                     n->relation = $5;
   10351           0 :                     n->newschema = $8;
   10352           0 :                     n->missing_ok = true;
   10353           0 :                     $$ = (Node *) n;
   10354             :                 }
   10355             :             | ALTER VIEW qualified_name SET SCHEMA name
   10356             :                 {
   10357           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10358             : 
   10359           0 :                     n->objectType = OBJECT_VIEW;
   10360           0 :                     n->relation = $3;
   10361           0 :                     n->newschema = $6;
   10362           0 :                     n->missing_ok = false;
   10363           0 :                     $$ = (Node *) n;
   10364             :                 }
   10365             :             | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
   10366             :                 {
   10367           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10368             : 
   10369           0 :                     n->objectType = OBJECT_VIEW;
   10370           0 :                     n->relation = $5;
   10371           0 :                     n->newschema = $8;
   10372           0 :                     n->missing_ok = true;
   10373           0 :                     $$ = (Node *) n;
   10374             :                 }
   10375             :             | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
   10376             :                 {
   10377           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10378             : 
   10379           6 :                     n->objectType = OBJECT_MATVIEW;
   10380           6 :                     n->relation = $4;
   10381           6 :                     n->newschema = $7;
   10382           6 :                     n->missing_ok = false;
   10383           6 :                     $$ = (Node *) n;
   10384             :                 }
   10385             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
   10386             :                 {
   10387           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10388             : 
   10389           0 :                     n->objectType = OBJECT_MATVIEW;
   10390           0 :                     n->relation = $6;
   10391           0 :                     n->newschema = $9;
   10392           0 :                     n->missing_ok = true;
   10393           0 :                     $$ = (Node *) n;
   10394             :                 }
   10395             :             | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
   10396             :                 {
   10397           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10398             : 
   10399           6 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10400           6 :                     n->relation = $4;
   10401           6 :                     n->newschema = $7;
   10402           6 :                     n->missing_ok = false;
   10403           6 :                     $$ = (Node *) n;
   10404             :                 }
   10405             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10406             :                 {
   10407           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10408             : 
   10409           6 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10410           6 :                     n->relation = $6;
   10411           6 :                     n->newschema = $9;
   10412           6 :                     n->missing_ok = true;
   10413           6 :                     $$ = (Node *) n;
   10414             :                 }
   10415             :             | ALTER TYPE_P any_name SET SCHEMA name
   10416             :                 {
   10417          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10418             : 
   10419          12 :                     n->objectType = OBJECT_TYPE;
   10420          12 :                     n->object = (Node *) $3;
   10421          12 :                     n->newschema = $6;
   10422          12 :                     n->missing_ok = false;
   10423          12 :                     $$ = (Node *) n;
   10424             :                 }
   10425             :         ;
   10426             : 
   10427             : /*****************************************************************************
   10428             :  *
   10429             :  * ALTER OPERATOR name SET define
   10430             :  *
   10431             :  *****************************************************************************/
   10432             : 
   10433             : AlterOperatorStmt:
   10434             :             ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
   10435             :                 {
   10436         608 :                     AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
   10437             : 
   10438         608 :                     n->opername = $3;
   10439         608 :                     n->options = $6;
   10440         608 :                     $$ = (Node *) n;
   10441             :                 }
   10442             :         ;
   10443             : 
   10444         668 : operator_def_list:  operator_def_elem                               { $$ = list_make1($1); }
   10445         506 :             | operator_def_list ',' operator_def_elem               { $$ = lappend($1, $3); }
   10446             :         ;
   10447             : 
   10448             : operator_def_elem: ColLabel '=' NONE
   10449          30 :                         { $$ = makeDefElem($1, NULL, @1); }
   10450             :                    | ColLabel '=' operator_def_arg
   10451        1110 :                         { $$ = makeDefElem($1, (Node *) $3, @1); }
   10452             :                    | ColLabel
   10453          34 :                         { $$ = makeDefElem($1, NULL, @1); }
   10454             :         ;
   10455             : 
   10456             : /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
   10457             : operator_def_arg:
   10458        1032 :             func_type                       { $$ = (Node *) $1; }
   10459          24 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
   10460          54 :             | qual_all_Op                   { $$ = (Node *) $1; }
   10461           0 :             | NumericOnly                   { $$ = (Node *) $1; }
   10462           0 :             | Sconst                        { $$ = (Node *) makeString($1); }
   10463             :         ;
   10464             : 
   10465             : /*****************************************************************************
   10466             :  *
   10467             :  * ALTER TYPE name SET define
   10468             :  *
   10469             :  * We repurpose ALTER OPERATOR's version of "definition" here
   10470             :  *
   10471             :  *****************************************************************************/
   10472             : 
   10473             : AlterTypeStmt:
   10474             :             ALTER TYPE_P any_name SET '(' operator_def_list ')'
   10475             :                 {
   10476          60 :                     AlterTypeStmt *n = makeNode(AlterTypeStmt);
   10477             : 
   10478          60 :                     n->typeName = $3;
   10479          60 :                     n->options = $6;
   10480          60 :                     $$ = (Node *) n;
   10481             :                 }
   10482             :         ;
   10483             : 
   10484             : /*****************************************************************************
   10485             :  *
   10486             :  * ALTER THING name OWNER TO newname
   10487             :  *
   10488             :  *****************************************************************************/
   10489             : 
   10490             : AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec
   10491             :                 {
   10492         142 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10493             : 
   10494         142 :                     n->objectType = OBJECT_AGGREGATE;
   10495         142 :                     n->object = (Node *) $3;
   10496         142 :                     n->newowner = $6;
   10497         142 :                     $$ = (Node *) n;
   10498             :                 }
   10499             :             | ALTER COLLATION any_name OWNER TO RoleSpec
   10500             :                 {
   10501          18 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10502             : 
   10503          18 :                     n->objectType = OBJECT_COLLATION;
   10504          18 :                     n->object = (Node *) $3;
   10505          18 :                     n->newowner = $6;
   10506          18 :                     $$ = (Node *) n;
   10507             :                 }
   10508             :             | ALTER CONVERSION_P any_name OWNER TO RoleSpec
   10509             :                 {
   10510          24 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10511             : 
   10512          24 :                     n->objectType = OBJECT_CONVERSION;
   10513          24 :                     n->object = (Node *) $3;
   10514          24 :                     n->newowner = $6;
   10515          24 :                     $$ = (Node *) n;
   10516             :                 }
   10517             :             | ALTER DATABASE name OWNER TO RoleSpec
   10518             :                 {
   10519          86 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10520             : 
   10521          86 :                     n->objectType = OBJECT_DATABASE;
   10522          86 :                     n->object = (Node *) makeString($3);
   10523          86 :                     n->newowner = $6;
   10524          86 :                     $$ = (Node *) n;
   10525             :                 }
   10526             :             | ALTER DOMAIN_P any_name OWNER TO RoleSpec
   10527             :                 {
   10528          48 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10529             : 
   10530          48 :                     n->objectType = OBJECT_DOMAIN;
   10531          48 :                     n->object = (Node *) $3;
   10532          48 :                     n->newowner = $6;
   10533          48 :                     $$ = (Node *) n;
   10534             :                 }
   10535             :             | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
   10536             :                 {
   10537         594 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10538             : 
   10539         594 :                     n->objectType = OBJECT_FUNCTION;
   10540         594 :                     n->object = (Node *) $3;
   10541         594 :                     n->newowner = $6;
   10542         594 :                     $$ = (Node *) n;
   10543             :                 }
   10544             :             | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
   10545             :                 {
   10546         142 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10547             : 
   10548         142 :                     n->objectType = OBJECT_LANGUAGE;
   10549         142 :                     n->object = (Node *) makeString($4);
   10550         142 :                     n->newowner = $7;
   10551         142 :                     $$ = (Node *) n;
   10552             :                 }
   10553             :             | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
   10554             :                 {
   10555          16 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10556             : 
   10557          16 :                     n->objectType = OBJECT_LARGEOBJECT;
   10558          16 :                     n->object = (Node *) $4;
   10559          16 :                     n->newowner = $7;
   10560          16 :                     $$ = (Node *) n;
   10561             :                 }
   10562             :             | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
   10563             :                 {
   10564          46 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10565             : 
   10566          46 :                     n->objectType = OBJECT_OPERATOR;
   10567          46 :                     n->object = (Node *) $3;
   10568          46 :                     n->newowner = $6;
   10569          46 :                     $$ = (Node *) n;
   10570             :                 }
   10571             :             | ALTER OPERATOR CLASS any_name USING name OWNER TO RoleSpec
   10572             :                 {
   10573          54 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10574             : 
   10575          54 :                     n->objectType = OBJECT_OPCLASS;
   10576          54 :                     n->object = (Node *) lcons(makeString($6), $4);
   10577          54 :                     n->newowner = $9;
   10578          54 :                     $$ = (Node *) n;
   10579             :                 }
   10580             :             | ALTER OPERATOR FAMILY any_name USING name OWNER TO RoleSpec
   10581             :                 {
   10582          62 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10583             : 
   10584          62 :                     n->objectType = OBJECT_OPFAMILY;
   10585          62 :                     n->object = (Node *) lcons(makeString($6), $4);
   10586          62 :                     n->newowner = $9;
   10587          62 :                     $$ = (Node *) n;
   10588             :                 }
   10589             :             | ALTER PROCEDURE function_with_argtypes OWNER TO RoleSpec
   10590             :                 {
   10591          24 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10592             : 
   10593          24 :                     n->objectType = OBJECT_PROCEDURE;
   10594          24 :                     n->object = (Node *) $3;
   10595          24 :                     n->newowner = $6;
   10596          24 :                     $$ = (Node *) n;
   10597             :                 }
   10598             :             | ALTER ROUTINE function_with_argtypes OWNER TO RoleSpec
   10599             :                 {
   10600           0 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10601             : 
   10602           0 :                     n->objectType = OBJECT_ROUTINE;
   10603           0 :                     n->object = (Node *) $3;
   10604           0 :                     n->newowner = $6;
   10605           0 :                     $$ = (Node *) n;
   10606             :                 }
   10607             :             | ALTER SCHEMA name OWNER TO RoleSpec
   10608             :                 {
   10609          64 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10610             : 
   10611          64 :                     n->objectType = OBJECT_SCHEMA;
   10612          64 :                     n->object = (Node *) makeString($3);
   10613          64 :                     n->newowner = $6;
   10614          64 :                     $$ = (Node *) n;
   10615             :                 }
   10616             :             | ALTER TYPE_P any_name OWNER TO RoleSpec
   10617             :                 {
   10618          84 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10619             : 
   10620          84 :                     n->objectType = OBJECT_TYPE;
   10621          84 :                     n->object = (Node *) $3;
   10622          84 :                     n->newowner = $6;
   10623          84 :                     $$ = (Node *) n;
   10624             :                 }
   10625             :             | ALTER TABLESPACE name OWNER TO RoleSpec
   10626             :                 {
   10627           6 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10628             : 
   10629           6 :                     n->objectType = OBJECT_TABLESPACE;
   10630           6 :                     n->object = (Node *) makeString($3);
   10631           6 :                     n->newowner = $6;
   10632           6 :                     $$ = (Node *) n;
   10633             :                 }
   10634             :             | ALTER STATISTICS any_name OWNER TO RoleSpec
   10635             :                 {
   10636          32 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10637             : 
   10638          32 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10639          32 :                     n->object = (Node *) $3;
   10640          32 :                     n->newowner = $6;
   10641          32 :                     $$ = (Node *) n;
   10642             :                 }
   10643             :             | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
   10644             :                 {
   10645          42 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10646             : 
   10647          42 :                     n->objectType = OBJECT_TSDICTIONARY;
   10648          42 :                     n->object = (Node *) $5;
   10649          42 :                     n->newowner = $8;
   10650          42 :                     $$ = (Node *) n;
   10651             :                 }
   10652             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
   10653             :                 {
   10654          32 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10655             : 
   10656          32 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10657          32 :                     n->object = (Node *) $5;
   10658          32 :                     n->newowner = $8;
   10659          32 :                     $$ = (Node *) n;
   10660             :                 }
   10661             :             | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
   10662             :                 {
   10663          20 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10664             : 
   10665          20 :                     n->objectType = OBJECT_FDW;
   10666          20 :                     n->object = (Node *) makeString($5);
   10667          20 :                     n->newowner = $8;
   10668          20 :                     $$ = (Node *) n;
   10669             :                 }
   10670             :             | ALTER SERVER name OWNER TO RoleSpec
   10671             :                 {
   10672          68 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10673             : 
   10674          68 :                     n->objectType = OBJECT_FOREIGN_SERVER;
   10675          68 :                     n->object = (Node *) makeString($3);
   10676          68 :                     n->newowner = $6;
   10677          68 :                     $$ = (Node *) n;
   10678             :                 }
   10679             :             | ALTER EVENT TRIGGER name OWNER TO RoleSpec
   10680             :                 {
   10681          14 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10682             : 
   10683          14 :                     n->objectType = OBJECT_EVENT_TRIGGER;
   10684          14 :                     n->object = (Node *) makeString($4);
   10685          14 :                     n->newowner = $7;
   10686          14 :                     $$ = (Node *) n;
   10687             :                 }
   10688             :             | ALTER PUBLICATION name OWNER TO RoleSpec
   10689             :                 {
   10690          36 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10691             : 
   10692          36 :                     n->objectType = OBJECT_PUBLICATION;
   10693          36 :                     n->object = (Node *) makeString($3);
   10694          36 :                     n->newowner = $6;
   10695          36 :                     $$ = (Node *) n;
   10696             :                 }
   10697             :             | ALTER SUBSCRIPTION name OWNER TO RoleSpec
   10698             :                 {
   10699          18 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10700             : 
   10701          18 :                     n->objectType = OBJECT_SUBSCRIPTION;
   10702          18 :                     n->object = (Node *) makeString($3);
   10703          18 :                     n->newowner = $6;
   10704          18 :                     $$ = (Node *) n;
   10705             :                 }
   10706             :         ;
   10707             : 
   10708             : 
   10709             : /*****************************************************************************
   10710             :  *
   10711             :  * CREATE PUBLICATION name [WITH options]
   10712             :  *
   10713             :  * CREATE PUBLICATION FOR ALL pub_obj_type [, ...] [WITH options]
   10714             :  *
   10715             :  * pub_obj_type is one of:
   10716             :  *
   10717             :  *      TABLES
   10718             :  *      SEQUENCES
   10719             :  *
   10720             :  * CREATE PUBLICATION FOR pub_obj [, ...] [WITH options]
   10721             :  *
   10722             :  * pub_obj is one of:
   10723             :  *
   10724             :  *      TABLE table [, ...]
   10725             :  *      TABLES IN SCHEMA schema [, ...]
   10726             :  *
   10727             :  *****************************************************************************/
   10728             : 
   10729             : CreatePublicationStmt:
   10730             :             CREATE PUBLICATION name opt_definition
   10731             :                 {
   10732         146 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10733             : 
   10734         146 :                     n->pubname = $3;
   10735         146 :                     n->options = $4;
   10736         146 :                     $$ = (Node *) n;
   10737             :                 }
   10738             :             | CREATE PUBLICATION name FOR pub_obj_type_list opt_definition
   10739             :                 {
   10740         148 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10741             : 
   10742         148 :                     n->pubname = $3;
   10743         148 :                     n->pubobjects = (List *) $5;
   10744         148 :                     preprocess_pub_all_objtype_list($5, &n->for_all_tables,
   10745             :                                                     &n->for_all_sequences,
   10746             :                                                     yyscanner);
   10747         136 :                     n->options = $6;
   10748         136 :                     $$ = (Node *) n;
   10749             :                 }
   10750             :             | CREATE PUBLICATION name FOR pub_obj_list opt_definition
   10751             :                 {
   10752         658 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10753             : 
   10754         658 :                     n->pubname = $3;
   10755         658 :                     n->options = $6;
   10756         658 :                     n->pubobjects = (List *) $5;
   10757         658 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10758         628 :                     $$ = (Node *) n;
   10759             :                 }
   10760             :         ;
   10761             : 
   10762             : /*
   10763             :  * FOR TABLE and FOR TABLES IN SCHEMA specifications
   10764             :  *
   10765             :  * This rule parses publication objects with and without keyword prefixes.
   10766             :  *
   10767             :  * The actual type of the object without keyword prefix depends on the previous
   10768             :  * one with keyword prefix. It will be preprocessed in preprocess_pubobj_list().
   10769             :  *
   10770             :  * For the object without keyword prefix, we cannot just use relation_expr here,
   10771             :  * because some extended expressions in relation_expr cannot be used as a
   10772             :  * schemaname and we cannot differentiate it. So, we extract the rules from
   10773             :  * relation_expr here.
   10774             :  */
   10775             : PublicationObjSpec:
   10776             :             TABLE relation_expr opt_column_list OptWhereClause
   10777             :                 {
   10778        1326 :                     $$ = makeNode(PublicationObjSpec);
   10779        1326 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLE;
   10780        1326 :                     $$->pubtable = makeNode(PublicationTable);
   10781        1326 :                     $$->pubtable->relation = $2;
   10782        1326 :                     $$->pubtable->columns = $3;
   10783        1326 :                     $$->pubtable->whereClause = $4;
   10784             :                 }
   10785             :             | TABLES IN_P SCHEMA ColId
   10786             :                 {
   10787         372 :                     $$ = makeNode(PublicationObjSpec);
   10788         372 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   10789         372 :                     $$->name = $4;
   10790         372 :                     $$->location = @4;
   10791             :                 }
   10792             :             | TABLES IN_P SCHEMA CURRENT_SCHEMA
   10793             :                 {
   10794          18 :                     $$ = makeNode(PublicationObjSpec);
   10795          18 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   10796          18 :                     $$->location = @4;
   10797             :                 }
   10798             :             | ColId opt_column_list OptWhereClause
   10799             :                 {
   10800         130 :                     $$ = makeNode(PublicationObjSpec);
   10801         130 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10802             :                     /*
   10803             :                      * If either a row filter or column list is specified, create
   10804             :                      * a PublicationTable object.
   10805             :                      */
   10806         130 :                     if ($2 || $3)
   10807             :                     {
   10808             :                         /*
   10809             :                          * The OptWhereClause must be stored here but it is
   10810             :                          * valid only for tables. For non-table objects, an
   10811             :                          * error will be thrown later via
   10812             :                          * preprocess_pubobj_list().
   10813             :                          */
   10814          42 :                         $$->pubtable = makeNode(PublicationTable);
   10815          42 :                         $$->pubtable->relation = makeRangeVar(NULL, $1, @1);
   10816          42 :                         $$->pubtable->columns = $2;
   10817          42 :                         $$->pubtable->whereClause = $3;
   10818             :                     }
   10819             :                     else
   10820             :                     {
   10821          88 :                         $$->name = $1;
   10822             :                     }
   10823         130 :                     $$->location = @1;
   10824             :                 }
   10825             :             | ColId indirection opt_column_list OptWhereClause
   10826             :                 {
   10827          32 :                     $$ = makeNode(PublicationObjSpec);
   10828          32 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10829          32 :                     $$->pubtable = makeNode(PublicationTable);
   10830          32 :                     $$->pubtable->relation = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   10831          32 :                     $$->pubtable->columns = $3;
   10832          32 :                     $$->pubtable->whereClause = $4;
   10833          32 :                     $$->location = @1;
   10834             :                 }
   10835             :             /* grammar like tablename * , ONLY tablename, ONLY ( tablename ) */
   10836             :             | extended_relation_expr opt_column_list OptWhereClause
   10837             :                 {
   10838           6 :                     $$ = makeNode(PublicationObjSpec);
   10839           6 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10840           6 :                     $$->pubtable = makeNode(PublicationTable);
   10841           6 :                     $$->pubtable->relation = $1;
   10842           6 :                     $$->pubtable->columns = $2;
   10843           6 :                     $$->pubtable->whereClause = $3;
   10844             :                 }
   10845             :             | CURRENT_SCHEMA
   10846             :                 {
   10847          18 :                     $$ = makeNode(PublicationObjSpec);
   10848          18 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10849          18 :                     $$->location = @1;
   10850             :                 }
   10851             :                 ;
   10852             : 
   10853             : pub_obj_list:   PublicationObjSpec
   10854        1648 :                     { $$ = list_make1($1); }
   10855             :             | pub_obj_list ',' PublicationObjSpec
   10856         254 :                     { $$ = lappend($1, $3); }
   10857             :     ;
   10858             : 
   10859             : PublicationAllObjSpec:
   10860             :                 ALL TABLES
   10861             :                     {
   10862         132 :                         $$ = makeNode(PublicationAllObjSpec);
   10863         132 :                         $$->pubobjtype = PUBLICATION_ALL_TABLES;
   10864         132 :                         $$->location = @1;
   10865             :                     }
   10866             :                 | ALL SEQUENCES
   10867             :                     {
   10868          54 :                         $$ = makeNode(PublicationAllObjSpec);
   10869          54 :                         $$->pubobjtype = PUBLICATION_ALL_SEQUENCES;
   10870          54 :                         $$->location = @1;
   10871             :                     }
   10872             :                     ;
   10873             : 
   10874             : pub_obj_type_list:  PublicationAllObjSpec
   10875         148 :                     { $$ = list_make1($1); }
   10876             :                 | pub_obj_type_list ',' PublicationAllObjSpec
   10877          38 :                     { $$ = lappend($1, $3); }
   10878             :     ;
   10879             : 
   10880             : 
   10881             : /*****************************************************************************
   10882             :  *
   10883             :  * ALTER PUBLICATION name SET ( options )
   10884             :  *
   10885             :  * ALTER PUBLICATION name ADD pub_obj [, ...]
   10886             :  *
   10887             :  * ALTER PUBLICATION name DROP pub_obj [, ...]
   10888             :  *
   10889             :  * ALTER PUBLICATION name SET pub_obj [, ...]
   10890             :  *
   10891             :  * pub_obj is one of:
   10892             :  *
   10893             :  *      TABLE table_name [, ...]
   10894             :  *      TABLES IN SCHEMA schema_name [, ...]
   10895             :  *
   10896             :  *****************************************************************************/
   10897             : 
   10898             : AlterPublicationStmt:
   10899             :             ALTER PUBLICATION name SET definition
   10900             :                 {
   10901         116 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10902             : 
   10903         116 :                     n->pubname = $3;
   10904         116 :                     n->options = $5;
   10905         116 :                     $$ = (Node *) n;
   10906             :                 }
   10907             :             | ALTER PUBLICATION name ADD_P pub_obj_list
   10908             :                 {
   10909         370 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10910             : 
   10911         370 :                     n->pubname = $3;
   10912         370 :                     n->pubobjects = $5;
   10913         370 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10914         364 :                     n->action = AP_AddObjects;
   10915         364 :                     $$ = (Node *) n;
   10916             :                 }
   10917             :             | ALTER PUBLICATION name SET pub_obj_list
   10918             :                 {
   10919         464 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10920             : 
   10921         464 :                     n->pubname = $3;
   10922         464 :                     n->pubobjects = $5;
   10923         464 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10924         464 :                     n->action = AP_SetObjects;
   10925         464 :                     $$ = (Node *) n;
   10926             :                 }
   10927             :             | ALTER PUBLICATION name DROP pub_obj_list
   10928             :                 {
   10929         156 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10930             : 
   10931         156 :                     n->pubname = $3;
   10932         156 :                     n->pubobjects = $5;
   10933         156 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10934         156 :                     n->action = AP_DropObjects;
   10935         156 :                     $$ = (Node *) n;
   10936             :                 }
   10937             :         ;
   10938             : 
   10939             : /*****************************************************************************
   10940             :  *
   10941             :  * CREATE SUBSCRIPTION name ...
   10942             :  *
   10943             :  *****************************************************************************/
   10944             : 
   10945             : CreateSubscriptionStmt:
   10946             :             CREATE SUBSCRIPTION name CONNECTION Sconst PUBLICATION name_list opt_definition
   10947             :                 {
   10948             :                     CreateSubscriptionStmt *n =
   10949         482 :                         makeNode(CreateSubscriptionStmt);
   10950         482 :                     n->subname = $3;
   10951         482 :                     n->conninfo = $5;
   10952         482 :                     n->publication = $7;
   10953         482 :                     n->options = $8;
   10954         482 :                     $$ = (Node *) n;
   10955             :                 }
   10956             :         ;
   10957             : 
   10958             : /*****************************************************************************
   10959             :  *
   10960             :  * ALTER SUBSCRIPTION name ...
   10961             :  *
   10962             :  *****************************************************************************/
   10963             : 
   10964             : AlterSubscriptionStmt:
   10965             :             ALTER SUBSCRIPTION name SET definition
   10966             :                 {
   10967             :                     AlterSubscriptionStmt *n =
   10968         218 :                         makeNode(AlterSubscriptionStmt);
   10969             : 
   10970         218 :                     n->kind = ALTER_SUBSCRIPTION_OPTIONS;
   10971         218 :                     n->subname = $3;
   10972         218 :                     n->options = $5;
   10973         218 :                     $$ = (Node *) n;
   10974             :                 }
   10975             :             | ALTER SUBSCRIPTION name CONNECTION Sconst
   10976             :                 {
   10977             :                     AlterSubscriptionStmt *n =
   10978          26 :                         makeNode(AlterSubscriptionStmt);
   10979             : 
   10980          26 :                     n->kind = ALTER_SUBSCRIPTION_CONNECTION;
   10981          26 :                     n->subname = $3;
   10982          26 :                     n->conninfo = $5;
   10983          26 :                     $$ = (Node *) n;
   10984             :                 }
   10985             :             | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
   10986             :                 {
   10987             :                     AlterSubscriptionStmt *n =
   10988          62 :                         makeNode(AlterSubscriptionStmt);
   10989             : 
   10990          62 :                     n->kind = ALTER_SUBSCRIPTION_REFRESH_PUBLICATION;
   10991          62 :                     n->subname = $3;
   10992          62 :                     n->options = $6;
   10993          62 :                     $$ = (Node *) n;
   10994             :                 }
   10995             :             | ALTER SUBSCRIPTION name REFRESH SEQUENCES
   10996             :                 {
   10997             :                     AlterSubscriptionStmt *n =
   10998           0 :                         makeNode(AlterSubscriptionStmt);
   10999             : 
   11000           0 :                     n->kind = ALTER_SUBSCRIPTION_REFRESH_SEQUENCES;
   11001           0 :                     n->subname = $3;
   11002           0 :                     $$ = (Node *) n;
   11003             :                 }
   11004             :             | ALTER SUBSCRIPTION name ADD_P PUBLICATION name_list opt_definition
   11005             :                 {
   11006             :                     AlterSubscriptionStmt *n =
   11007          28 :                         makeNode(AlterSubscriptionStmt);
   11008             : 
   11009          28 :                     n->kind = ALTER_SUBSCRIPTION_ADD_PUBLICATION;
   11010          28 :                     n->subname = $3;
   11011          28 :                     n->publication = $6;
   11012          28 :                     n->options = $7;
   11013          28 :                     $$ = (Node *) n;
   11014             :                 }
   11015             :             | ALTER SUBSCRIPTION name DROP PUBLICATION name_list opt_definition
   11016             :                 {
   11017             :                     AlterSubscriptionStmt *n =
   11018          26 :                         makeNode(AlterSubscriptionStmt);
   11019             : 
   11020          26 :                     n->kind = ALTER_SUBSCRIPTION_DROP_PUBLICATION;
   11021          26 :                     n->subname = $3;
   11022          26 :                     n->publication = $6;
   11023          26 :                     n->options = $7;
   11024          26 :                     $$ = (Node *) n;
   11025             :                 }
   11026             :             | ALTER SUBSCRIPTION name SET PUBLICATION name_list opt_definition
   11027             :                 {
   11028             :                     AlterSubscriptionStmt *n =
   11029          44 :                         makeNode(AlterSubscriptionStmt);
   11030             : 
   11031          44 :                     n->kind = ALTER_SUBSCRIPTION_SET_PUBLICATION;
   11032          44 :                     n->subname = $3;
   11033          44 :                     n->publication = $6;
   11034          44 :                     n->options = $7;
   11035          44 :                     $$ = (Node *) n;
   11036             :                 }
   11037             :             | ALTER SUBSCRIPTION name ENABLE_P
   11038             :                 {
   11039             :                     AlterSubscriptionStmt *n =
   11040          60 :                         makeNode(AlterSubscriptionStmt);
   11041             : 
   11042          60 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   11043          60 :                     n->subname = $3;
   11044          60 :                     n->options = list_make1(makeDefElem("enabled",
   11045             :                                             (Node *) makeBoolean(true), @1));
   11046          60 :                     $$ = (Node *) n;
   11047             :                 }
   11048             :             | ALTER SUBSCRIPTION name DISABLE_P
   11049             :                 {
   11050             :                     AlterSubscriptionStmt *n =
   11051          44 :                         makeNode(AlterSubscriptionStmt);
   11052             : 
   11053          44 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   11054          44 :                     n->subname = $3;
   11055          44 :                     n->options = list_make1(makeDefElem("enabled",
   11056             :                                             (Node *) makeBoolean(false), @1));
   11057          44 :                     $$ = (Node *) n;
   11058             :                 }
   11059             :             | ALTER SUBSCRIPTION name SKIP definition
   11060             :                 {
   11061             :                     AlterSubscriptionStmt *n =
   11062          24 :                         makeNode(AlterSubscriptionStmt);
   11063             : 
   11064          24 :                     n->kind = ALTER_SUBSCRIPTION_SKIP;
   11065          24 :                     n->subname = $3;
   11066          24 :                     n->options = $5;
   11067          24 :                     $$ = (Node *) n;
   11068             :                 }
   11069             :         ;
   11070             : 
   11071             : /*****************************************************************************
   11072             :  *
   11073             :  * DROP SUBSCRIPTION [ IF EXISTS ] name
   11074             :  *
   11075             :  *****************************************************************************/
   11076             : 
   11077             : DropSubscriptionStmt: DROP SUBSCRIPTION name opt_drop_behavior
   11078             :                 {
   11079         242 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   11080             : 
   11081         242 :                     n->subname = $3;
   11082         242 :                     n->missing_ok = false;
   11083         242 :                     n->behavior = $4;
   11084         242 :                     $$ = (Node *) n;
   11085             :                 }
   11086             :                 |  DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
   11087             :                 {
   11088           6 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   11089             : 
   11090           6 :                     n->subname = $5;
   11091           6 :                     n->missing_ok = true;
   11092           6 :                     n->behavior = $6;
   11093           6 :                     $$ = (Node *) n;
   11094             :                 }
   11095             :         ;
   11096             : 
   11097             : /*****************************************************************************
   11098             :  *
   11099             :  *      QUERY:  Define Rewrite Rule
   11100             :  *
   11101             :  *****************************************************************************/
   11102             : 
   11103             : RuleStmt:   CREATE opt_or_replace RULE name AS
   11104             :             ON event TO qualified_name where_clause
   11105             :             DO opt_instead RuleActionList
   11106             :                 {
   11107        1092 :                     RuleStmt   *n = makeNode(RuleStmt);
   11108             : 
   11109        1092 :                     n->replace = $2;
   11110        1092 :                     n->relation = $9;
   11111        1092 :                     n->rulename = $4;
   11112        1092 :                     n->whereClause = $10;
   11113        1092 :                     n->event = $7;
   11114        1092 :                     n->instead = $12;
   11115        1092 :                     n->actions = $13;
   11116        1092 :                     $$ = (Node *) n;
   11117             :                 }
   11118             :         ;
   11119             : 
   11120             : RuleActionList:
   11121         162 :             NOTHING                                 { $$ = NIL; }
   11122         884 :             | RuleActionStmt                        { $$ = list_make1($1); }
   11123          46 :             | '(' RuleActionMulti ')'               { $$ = $2; }
   11124             :         ;
   11125             : 
   11126             : /* the thrashing around here is to discard "empty" statements... */
   11127             : RuleActionMulti:
   11128             :             RuleActionMulti ';' RuleActionStmtOrEmpty
   11129          62 :                 { if ($3 != NULL)
   11130          46 :                     $$ = lappend($1, $3);
   11131             :                   else
   11132          16 :                     $$ = $1;
   11133             :                 }
   11134             :             | RuleActionStmtOrEmpty
   11135          46 :                 { if ($1 != NULL)
   11136          46 :                     $$ = list_make1($1);
   11137             :                   else
   11138           0 :                     $$ = NIL;
   11139             :                 }
   11140             :         ;
   11141             : 
   11142             : RuleActionStmt:
   11143             :             SelectStmt
   11144             :             | InsertStmt
   11145             :             | UpdateStmt
   11146             :             | DeleteStmt
   11147             :             | NotifyStmt
   11148             :         ;
   11149             : 
   11150             : RuleActionStmtOrEmpty:
   11151          92 :             RuleActionStmt                          { $$ = $1; }
   11152          16 :             |   /*EMPTY*/                           { $$ = NULL; }
   11153             :         ;
   11154             : 
   11155          18 : event:      SELECT                                  { $$ = CMD_SELECT; }
   11156         432 :             | UPDATE                                { $$ = CMD_UPDATE; }
   11157         164 :             | DELETE_P                              { $$ = CMD_DELETE; }
   11158         478 :             | INSERT                                { $$ = CMD_INSERT; }
   11159             :          ;
   11160             : 
   11161             : opt_instead:
   11162         752 :             INSTEAD                                 { $$ = true; }
   11163         156 :             | ALSO                                  { $$ = false; }
   11164         184 :             | /*EMPTY*/                             { $$ = false; }
   11165             :         ;
   11166             : 
   11167             : 
   11168             : /*****************************************************************************
   11169             :  *
   11170             :  *      QUERY:
   11171             :  *              NOTIFY <identifier> can appear both in rule bodies and
   11172             :  *              as a query-level command
   11173             :  *
   11174             :  *****************************************************************************/
   11175             : 
   11176             : NotifyStmt: NOTIFY ColId notify_payload
   11177             :                 {
   11178         128 :                     NotifyStmt *n = makeNode(NotifyStmt);
   11179             : 
   11180         128 :                     n->conditionname = $2;
   11181         128 :                     n->payload = $3;
   11182         128 :                     $$ = (Node *) n;
   11183             :                 }
   11184             :         ;
   11185             : 
   11186             : notify_payload:
   11187          62 :             ',' Sconst                          { $$ = $2; }
   11188          66 :             | /*EMPTY*/                         { $$ = NULL; }
   11189             :         ;
   11190             : 
   11191             : ListenStmt: LISTEN ColId
   11192             :                 {
   11193          74 :                     ListenStmt *n = makeNode(ListenStmt);
   11194             : 
   11195          74 :                     n->conditionname = $2;
   11196          74 :                     $$ = (Node *) n;
   11197             :                 }
   11198             :         ;
   11199             : 
   11200             : UnlistenStmt:
   11201             :             UNLISTEN ColId
   11202             :                 {
   11203           6 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   11204             : 
   11205           6 :                     n->conditionname = $2;
   11206           6 :                     $$ = (Node *) n;
   11207             :                 }
   11208             :             | UNLISTEN '*'
   11209             :                 {
   11210          32 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   11211             : 
   11212          32 :                     n->conditionname = NULL;
   11213          32 :                     $$ = (Node *) n;
   11214             :                 }
   11215             :         ;
   11216             : 
   11217             : 
   11218             : /*****************************************************************************
   11219             :  *
   11220             :  *      Transactions:
   11221             :  *
   11222             :  *      BEGIN / COMMIT / ROLLBACK
   11223             :  *      (also older versions END / ABORT)
   11224             :  *
   11225             :  *****************************************************************************/
   11226             : 
   11227             : TransactionStmt:
   11228             :             ABORT_P opt_transaction opt_transaction_chain
   11229             :                 {
   11230         232 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11231             : 
   11232         232 :                     n->kind = TRANS_STMT_ROLLBACK;
   11233         232 :                     n->options = NIL;
   11234         232 :                     n->chain = $3;
   11235         232 :                     n->location = -1;
   11236         232 :                     $$ = (Node *) n;
   11237             :                 }
   11238             :             | START TRANSACTION transaction_mode_list_or_empty
   11239             :                 {
   11240        1640 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11241             : 
   11242        1640 :                     n->kind = TRANS_STMT_START;
   11243        1640 :                     n->options = $3;
   11244        1640 :                     n->location = -1;
   11245        1640 :                     $$ = (Node *) n;
   11246             :                 }
   11247             :             | COMMIT opt_transaction opt_transaction_chain
   11248             :                 {
   11249       11994 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11250             : 
   11251       11994 :                     n->kind = TRANS_STMT_COMMIT;
   11252       11994 :                     n->options = NIL;
   11253       11994 :                     n->chain = $3;
   11254       11994 :                     n->location = -1;
   11255       11994 :                     $$ = (Node *) n;
   11256             :                 }
   11257             :             | ROLLBACK opt_transaction opt_transaction_chain
   11258             :                 {
   11259        2676 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11260             : 
   11261        2676 :                     n->kind = TRANS_STMT_ROLLBACK;
   11262        2676 :                     n->options = NIL;
   11263        2676 :                     n->chain = $3;
   11264        2676 :                     n->location = -1;
   11265        2676 :                     $$ = (Node *) n;
   11266             :                 }
   11267             :             | SAVEPOINT ColId
   11268             :                 {
   11269        1930 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11270             : 
   11271        1930 :                     n->kind = TRANS_STMT_SAVEPOINT;
   11272        1930 :                     n->savepoint_name = $2;
   11273        1930 :                     n->location = @2;
   11274        1930 :                     $$ = (Node *) n;
   11275             :                 }
   11276             :             | RELEASE SAVEPOINT ColId
   11277             :                 {
   11278         208 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11279             : 
   11280         208 :                     n->kind = TRANS_STMT_RELEASE;
   11281         208 :                     n->savepoint_name = $3;
   11282         208 :                     n->location = @3;
   11283         208 :                     $$ = (Node *) n;
   11284             :                 }
   11285             :             | RELEASE ColId
   11286             :                 {
   11287          86 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11288             : 
   11289          86 :                     n->kind = TRANS_STMT_RELEASE;
   11290          86 :                     n->savepoint_name = $2;
   11291          86 :                     n->location = @2;
   11292          86 :                     $$ = (Node *) n;
   11293             :                 }
   11294             :             | ROLLBACK opt_transaction TO SAVEPOINT ColId
   11295             :                 {
   11296         228 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11297             : 
   11298         228 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   11299         228 :                     n->savepoint_name = $5;
   11300         228 :                     n->location = @5;
   11301         228 :                     $$ = (Node *) n;
   11302             :                 }
   11303             :             | ROLLBACK opt_transaction TO ColId
   11304             :                 {
   11305         496 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11306             : 
   11307         496 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   11308         496 :                     n->savepoint_name = $4;
   11309         496 :                     n->location = @4;
   11310         496 :                     $$ = (Node *) n;
   11311             :                 }
   11312             :             | PREPARE TRANSACTION Sconst
   11313             :                 {
   11314         630 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11315             : 
   11316         630 :                     n->kind = TRANS_STMT_PREPARE;
   11317         630 :                     n->gid = $3;
   11318         630 :                     n->location = @3;
   11319         630 :                     $$ = (Node *) n;
   11320             :                 }
   11321             :             | COMMIT PREPARED Sconst
   11322             :                 {
   11323         470 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11324             : 
   11325         470 :                     n->kind = TRANS_STMT_COMMIT_PREPARED;
   11326         470 :                     n->gid = $3;
   11327         470 :                     n->location = @3;
   11328         470 :                     $$ = (Node *) n;
   11329             :                 }
   11330             :             | ROLLBACK PREPARED Sconst
   11331             :                 {
   11332          74 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11333             : 
   11334          74 :                     n->kind = TRANS_STMT_ROLLBACK_PREPARED;
   11335          74 :                     n->gid = $3;
   11336          74 :                     n->location = @3;
   11337          74 :                     $$ = (Node *) n;
   11338             :                 }
   11339             :         ;
   11340             : 
   11341             : TransactionStmtLegacy:
   11342             :             BEGIN_P opt_transaction transaction_mode_list_or_empty
   11343             :                 {
   11344       14618 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11345             : 
   11346       14618 :                     n->kind = TRANS_STMT_BEGIN;
   11347       14618 :                     n->options = $3;
   11348       14618 :                     n->location = -1;
   11349       14618 :                     $$ = (Node *) n;
   11350             :                 }
   11351             :             | END_P opt_transaction opt_transaction_chain
   11352             :                 {
   11353         370 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11354             : 
   11355         370 :                     n->kind = TRANS_STMT_COMMIT;
   11356         370 :                     n->options = NIL;
   11357         370 :                     n->chain = $3;
   11358         370 :                     n->location = -1;
   11359         370 :                     $$ = (Node *) n;
   11360             :                 }
   11361             :         ;
   11362             : 
   11363             : opt_transaction:    WORK
   11364             :             | TRANSACTION
   11365             :             | /*EMPTY*/
   11366             :         ;
   11367             : 
   11368             : transaction_mode_item:
   11369             :             ISOLATION LEVEL iso_level
   11370        6874 :                     { $$ = makeDefElem("transaction_isolation",
   11371        6874 :                                        makeStringConst($3, @3), @1); }
   11372             :             | READ ONLY
   11373        1410 :                     { $$ = makeDefElem("transaction_read_only",
   11374        1410 :                                        makeIntConst(true, @1), @1); }
   11375             :             | READ WRITE
   11376          90 :                     { $$ = makeDefElem("transaction_read_only",
   11377          90 :                                        makeIntConst(false, @1), @1); }
   11378             :             | DEFERRABLE
   11379          44 :                     { $$ = makeDefElem("transaction_deferrable",
   11380             :                                        makeIntConst(true, @1), @1); }
   11381             :             | NOT DEFERRABLE
   11382          10 :                     { $$ = makeDefElem("transaction_deferrable",
   11383          10 :                                        makeIntConst(false, @1), @1); }
   11384             :         ;
   11385             : 
   11386             : /* Syntax with commas is SQL-spec, without commas is Postgres historical */
   11387             : transaction_mode_list:
   11388             :             transaction_mode_item
   11389        7090 :                     { $$ = list_make1($1); }
   11390             :             | transaction_mode_list ',' transaction_mode_item
   11391         940 :                     { $$ = lappend($1, $3); }
   11392             :             | transaction_mode_list transaction_mode_item
   11393         398 :                     { $$ = lappend($1, $2); }
   11394             :         ;
   11395             : 
   11396             : transaction_mode_list_or_empty:
   11397             :             transaction_mode_list
   11398             :             | /* EMPTY */
   11399        9768 :                     { $$ = NIL; }
   11400             :         ;
   11401             : 
   11402             : opt_transaction_chain:
   11403         120 :             AND CHAIN       { $$ = true; }
   11404           2 :             | AND NO CHAIN  { $$ = false; }
   11405       15150 :             | /* EMPTY */   { $$ = false; }
   11406             :         ;
   11407             : 
   11408             : 
   11409             : /*****************************************************************************
   11410             :  *
   11411             :  *  QUERY:
   11412             :  *      CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
   11413             :  *          AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
   11414             :  *
   11415             :  *****************************************************************************/
   11416             : 
   11417             : ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11418             :                 AS SelectStmt opt_check_option
   11419             :                 {
   11420       16808 :                     ViewStmt   *n = makeNode(ViewStmt);
   11421             : 
   11422       16808 :                     n->view = $4;
   11423       16808 :                     n->view->relpersistence = $2;
   11424       16808 :                     n->aliases = $5;
   11425       16808 :                     n->query = $8;
   11426       16808 :                     n->replace = false;
   11427       16808 :                     n->options = $6;
   11428       16808 :                     n->withCheckOption = $9;
   11429       16808 :                     $$ = (Node *) n;
   11430             :                 }
   11431             :         | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11432             :                 AS SelectStmt opt_check_option
   11433             :                 {
   11434         244 :                     ViewStmt   *n = makeNode(ViewStmt);
   11435             : 
   11436         244 :                     n->view = $6;
   11437         244 :                     n->view->relpersistence = $4;
   11438         244 :                     n->aliases = $7;
   11439         244 :                     n->query = $10;
   11440         244 :                     n->replace = true;
   11441         244 :                     n->options = $8;
   11442         244 :                     n->withCheckOption = $11;
   11443         244 :                     $$ = (Node *) n;
   11444             :                 }
   11445             :         | CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11446             :                 AS SelectStmt opt_check_option
   11447             :                 {
   11448           8 :                     ViewStmt   *n = makeNode(ViewStmt);
   11449             : 
   11450           8 :                     n->view = $5;
   11451           8 :                     n->view->relpersistence = $2;
   11452           8 :                     n->aliases = $7;
   11453           8 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
   11454           8 :                     n->replace = false;
   11455           8 :                     n->options = $9;
   11456           8 :                     n->withCheckOption = $12;
   11457           8 :                     if (n->withCheckOption != NO_CHECK_OPTION)
   11458           0 :                         ereport(ERROR,
   11459             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   11460             :                                  errmsg("WITH CHECK OPTION not supported on recursive views"),
   11461             :                                  parser_errposition(@12)));
   11462           8 :                     $$ = (Node *) n;
   11463             :                 }
   11464             :         | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11465             :                 AS SelectStmt opt_check_option
   11466             :                 {
   11467           6 :                     ViewStmt   *n = makeNode(ViewStmt);
   11468             : 
   11469           6 :                     n->view = $7;
   11470           6 :                     n->view->relpersistence = $4;
   11471           6 :                     n->aliases = $9;
   11472           6 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
   11473           6 :                     n->replace = true;
   11474           6 :                     n->options = $11;
   11475           6 :                     n->withCheckOption = $14;
   11476           6 :                     if (n->withCheckOption != NO_CHECK_OPTION)
   11477           0 :                         ereport(ERROR,
   11478             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   11479             :                                  errmsg("WITH CHECK OPTION not supported on recursive views"),
   11480             :                                  parser_errposition(@14)));
   11481           6 :                     $$ = (Node *) n;
   11482             :                 }
   11483             :         ;
   11484             : 
   11485             : opt_check_option:
   11486          96 :         WITH CHECK OPTION               { $$ = CASCADED_CHECK_OPTION; }
   11487           6 :         | WITH CASCADED CHECK OPTION    { $$ = CASCADED_CHECK_OPTION; }
   11488          24 :         | WITH LOCAL CHECK OPTION       { $$ = LOCAL_CHECK_OPTION; }
   11489       16940 :         | /* EMPTY */                   { $$ = NO_CHECK_OPTION; }
   11490             :         ;
   11491             : 
   11492             : /*****************************************************************************
   11493             :  *
   11494             :  *      QUERY:
   11495             :  *              LOAD "filename"
   11496             :  *
   11497             :  *****************************************************************************/
   11498             : 
   11499             : LoadStmt:   LOAD file_name
   11500             :                 {
   11501          64 :                     LoadStmt   *n = makeNode(LoadStmt);
   11502             : 
   11503          64 :                     n->filename = $2;
   11504          64 :                     $$ = (Node *) n;
   11505             :                 }
   11506             :         ;
   11507             : 
   11508             : 
   11509             : /*****************************************************************************
   11510             :  *
   11511             :  *      CREATE DATABASE
   11512             :  *
   11513             :  *****************************************************************************/
   11514             : 
   11515             : CreatedbStmt:
   11516             :             CREATE DATABASE name opt_with createdb_opt_list
   11517             :                 {
   11518         802 :                     CreatedbStmt *n = makeNode(CreatedbStmt);
   11519             : 
   11520         802 :                     n->dbname = $3;
   11521         802 :                     n->options = $5;
   11522         802 :                     $$ = (Node *) n;
   11523             :                 }
   11524             :         ;
   11525             : 
   11526             : createdb_opt_list:
   11527         654 :             createdb_opt_items                      { $$ = $1; }
   11528         208 :             | /* EMPTY */                           { $$ = NIL; }
   11529             :         ;
   11530             : 
   11531             : createdb_opt_items:
   11532         654 :             createdb_opt_item                       { $$ = list_make1($1); }
   11533         984 :             | createdb_opt_items createdb_opt_item  { $$ = lappend($1, $2); }
   11534             :         ;
   11535             : 
   11536             : createdb_opt_item:
   11537             :             createdb_opt_name opt_equal NumericOnly
   11538             :                 {
   11539         266 :                     $$ = makeDefElem($1, $3, @1);
   11540             :                 }
   11541             :             | createdb_opt_name opt_equal opt_boolean_or_string
   11542             :                 {
   11543        1372 :                     $$ = makeDefElem($1, (Node *) makeString($3), @1);
   11544             :                 }
   11545             :             | createdb_opt_name opt_equal DEFAULT
   11546             :                 {
   11547           0 :                     $$ = makeDefElem($1, NULL, @1);
   11548             :                 }
   11549             :         ;
   11550             : 
   11551             : /*
   11552             :  * Ideally we'd use ColId here, but that causes shift/reduce conflicts against
   11553             :  * the ALTER DATABASE SET/RESET syntaxes.  Instead call out specific keywords
   11554             :  * we need, and allow IDENT so that database option names don't have to be
   11555             :  * parser keywords unless they are already keywords for other reasons.
   11556             :  *
   11557             :  * XXX this coding technique is fragile since if someone makes a formerly
   11558             :  * non-keyword option name into a keyword and forgets to add it here, the
   11559             :  * option will silently break.  Best defense is to provide a regression test
   11560             :  * exercising every such option, at least at the syntax level.
   11561             :  */
   11562             : createdb_opt_name:
   11563        1140 :             IDENT                           { $$ = $1; }
   11564           2 :             | CONNECTION LIMIT              { $$ = pstrdup("connection_limit"); }
   11565         102 :             | ENCODING                      { $$ = pstrdup($1); }
   11566           0 :             | LOCATION                      { $$ = pstrdup($1); }
   11567           2 :             | OWNER                         { $$ = pstrdup($1); }
   11568          34 :             | TABLESPACE                    { $$ = pstrdup($1); }
   11569         358 :             | TEMPLATE                      { $$ = pstrdup($1); }
   11570             :         ;
   11571             : 
   11572             : /*
   11573             :  *  Though the equals sign doesn't match other WITH options, pg_dump uses
   11574             :  *  equals for backward compatibility, and it doesn't seem worth removing it.
   11575             :  */
   11576             : opt_equal:  '='
   11577             :             | /*EMPTY*/
   11578             :         ;
   11579             : 
   11580             : 
   11581             : /*****************************************************************************
   11582             :  *
   11583             :  *      ALTER DATABASE
   11584             :  *
   11585             :  *****************************************************************************/
   11586             : 
   11587             : AlterDatabaseStmt:
   11588             :             ALTER DATABASE name WITH createdb_opt_list
   11589             :                  {
   11590           0 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11591             : 
   11592           0 :                     n->dbname = $3;
   11593           0 :                     n->options = $5;
   11594           0 :                     $$ = (Node *) n;
   11595             :                  }
   11596             :             | ALTER DATABASE name createdb_opt_list
   11597             :                  {
   11598          60 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11599             : 
   11600          60 :                     n->dbname = $3;
   11601          60 :                     n->options = $4;
   11602          60 :                     $$ = (Node *) n;
   11603             :                  }
   11604             :             | ALTER DATABASE name SET TABLESPACE name
   11605             :                  {
   11606          22 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11607             : 
   11608          22 :                     n->dbname = $3;
   11609          22 :                     n->options = list_make1(makeDefElem("tablespace",
   11610             :                                                         (Node *) makeString($6), @6));
   11611          22 :                     $$ = (Node *) n;
   11612             :                  }
   11613             :             | ALTER DATABASE name REFRESH COLLATION VERSION_P
   11614             :                  {
   11615           6 :                     AlterDatabaseRefreshCollStmt *n = makeNode(AlterDatabaseRefreshCollStmt);
   11616             : 
   11617           6 :                     n->dbname = $3;
   11618           6 :                     $$ = (Node *) n;
   11619             :                  }
   11620             :         ;
   11621             : 
   11622             : AlterDatabaseSetStmt:
   11623             :             ALTER DATABASE name SetResetClause
   11624             :                 {
   11625        1242 :                     AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
   11626             : 
   11627        1242 :                     n->dbname = $3;
   11628        1242 :                     n->setstmt = $4;
   11629        1242 :                     $$ = (Node *) n;
   11630             :                 }
   11631             :         ;
   11632             : 
   11633             : 
   11634             : /*****************************************************************************
   11635             :  *
   11636             :  *      DROP DATABASE [ IF EXISTS ] dbname [ [ WITH ] ( options ) ]
   11637             :  *
   11638             :  * This is implicitly CASCADE, no need for drop behavior
   11639             :  *****************************************************************************/
   11640             : 
   11641             : DropdbStmt: DROP DATABASE name
   11642             :                 {
   11643          94 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11644             : 
   11645          94 :                     n->dbname = $3;
   11646          94 :                     n->missing_ok = false;
   11647          94 :                     n->options = NULL;
   11648          94 :                     $$ = (Node *) n;
   11649             :                 }
   11650             :             | DROP DATABASE IF_P EXISTS name
   11651             :                 {
   11652           4 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11653             : 
   11654           4 :                     n->dbname = $5;
   11655           4 :                     n->missing_ok = true;
   11656           4 :                     n->options = NULL;
   11657           4 :                     $$ = (Node *) n;
   11658             :                 }
   11659             :             | DROP DATABASE name opt_with '(' drop_option_list ')'
   11660             :                 {
   11661          14 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11662             : 
   11663          14 :                     n->dbname = $3;
   11664          14 :                     n->missing_ok = false;
   11665          14 :                     n->options = $6;
   11666          14 :                     $$ = (Node *) n;
   11667             :                 }
   11668             :             | DROP DATABASE IF_P EXISTS name opt_with '(' drop_option_list ')'
   11669             :                 {
   11670          12 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11671             : 
   11672          12 :                     n->dbname = $5;
   11673          12 :                     n->missing_ok = true;
   11674          12 :                     n->options = $8;
   11675          12 :                     $$ = (Node *) n;
   11676             :                 }
   11677             :         ;
   11678             : 
   11679             : drop_option_list:
   11680             :             drop_option
   11681             :                 {
   11682          26 :                     $$ = list_make1((Node *) $1);
   11683             :                 }
   11684             :             | drop_option_list ',' drop_option
   11685             :                 {
   11686           0 :                     $$ = lappend($1, (Node *) $3);
   11687             :                 }
   11688             :         ;
   11689             : 
   11690             : /*
   11691             :  * Currently only the FORCE option is supported, but the syntax is designed
   11692             :  * to be extensible so that we can add more options in the future if required.
   11693             :  */
   11694             : drop_option:
   11695             :             FORCE
   11696             :                 {
   11697          26 :                     $$ = makeDefElem("force", NULL, @1);
   11698             :                 }
   11699             :         ;
   11700             : 
   11701             : /*****************************************************************************
   11702             :  *
   11703             :  *      ALTER COLLATION
   11704             :  *
   11705             :  *****************************************************************************/
   11706             : 
   11707             : AlterCollationStmt: ALTER COLLATION any_name REFRESH VERSION_P
   11708             :                 {
   11709           6 :                     AlterCollationStmt *n = makeNode(AlterCollationStmt);
   11710             : 
   11711           6 :                     n->collname = $3;
   11712           6 :                     $$ = (Node *) n;
   11713             :                 }
   11714             :         ;
   11715             : 
   11716             : 
   11717             : /*****************************************************************************
   11718             :  *
   11719             :  *      ALTER SYSTEM
   11720             :  *
   11721             :  * This is used to change configuration parameters persistently.
   11722             :  *****************************************************************************/
   11723             : 
   11724             : AlterSystemStmt:
   11725             :             ALTER SYSTEM_P SET generic_set
   11726             :                 {
   11727         128 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11728             : 
   11729         128 :                     n->setstmt = $4;
   11730         128 :                     $$ = (Node *) n;
   11731             :                 }
   11732             :             | ALTER SYSTEM_P RESET generic_reset
   11733             :                 {
   11734          56 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11735             : 
   11736          56 :                     n->setstmt = $4;
   11737          56 :                     $$ = (Node *) n;
   11738             :                 }
   11739             :         ;
   11740             : 
   11741             : 
   11742             : /*****************************************************************************
   11743             :  *
   11744             :  * Manipulate a domain
   11745             :  *
   11746             :  *****************************************************************************/
   11747             : 
   11748             : CreateDomainStmt:
   11749             :             CREATE DOMAIN_P any_name opt_as Typename ColQualList
   11750             :                 {
   11751        1464 :                     CreateDomainStmt *n = makeNode(CreateDomainStmt);
   11752             : 
   11753        1464 :                     n->domainname = $3;
   11754        1464 :                     n->typeName = $5;
   11755        1464 :                     SplitColQualList($6, &n->constraints, &n->collClause,
   11756             :                                      yyscanner);
   11757        1464 :                     $$ = (Node *) n;
   11758             :                 }
   11759             :         ;
   11760             : 
   11761             : AlterDomainStmt:
   11762             :             /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
   11763             :             ALTER DOMAIN_P any_name alter_column_default
   11764             :                 {
   11765          14 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11766             : 
   11767          14 :                     n->subtype = AD_AlterDefault;
   11768          14 :                     n->typeName = $3;
   11769          14 :                     n->def = $4;
   11770          14 :                     $$ = (Node *) n;
   11771             :                 }
   11772             :             /* ALTER DOMAIN <domain> DROP NOT NULL */
   11773             :             | ALTER DOMAIN_P any_name DROP NOT NULL_P
   11774             :                 {
   11775          12 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11776             : 
   11777          12 :                     n->subtype = AD_DropNotNull;
   11778          12 :                     n->typeName = $3;
   11779          12 :                     $$ = (Node *) n;
   11780             :                 }
   11781             :             /* ALTER DOMAIN <domain> SET NOT NULL */
   11782             :             | ALTER DOMAIN_P any_name SET NOT NULL_P
   11783             :                 {
   11784          24 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11785             : 
   11786          24 :                     n->subtype = AD_SetNotNull;
   11787          24 :                     n->typeName = $3;
   11788          24 :                     $$ = (Node *) n;
   11789             :                 }
   11790             :             /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
   11791             :             | ALTER DOMAIN_P any_name ADD_P DomainConstraint
   11792             :                 {
   11793         182 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11794             : 
   11795         182 :                     n->subtype = AD_AddConstraint;
   11796         182 :                     n->typeName = $3;
   11797         182 :                     n->def = $5;
   11798         182 :                     $$ = (Node *) n;
   11799             :                 }
   11800             :             /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
   11801             :             | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
   11802             :                 {
   11803          54 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11804             : 
   11805          54 :                     n->subtype = AD_DropConstraint;
   11806          54 :                     n->typeName = $3;
   11807          54 :                     n->name = $6;
   11808          54 :                     n->behavior = $7;
   11809          54 :                     n->missing_ok = false;
   11810          54 :                     $$ = (Node *) n;
   11811             :                 }
   11812             :             /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
   11813             :             | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
   11814             :                 {
   11815           6 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11816             : 
   11817           6 :                     n->subtype = AD_DropConstraint;
   11818           6 :                     n->typeName = $3;
   11819           6 :                     n->name = $8;
   11820           6 :                     n->behavior = $9;
   11821           6 :                     n->missing_ok = true;
   11822           6 :                     $$ = (Node *) n;
   11823             :                 }
   11824             :             /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
   11825             :             | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
   11826             :                 {
   11827          12 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11828             : 
   11829          12 :                     n->subtype = AD_ValidateConstraint;
   11830          12 :                     n->typeName = $3;
   11831          12 :                     n->name = $6;
   11832          12 :                     $$ = (Node *) n;
   11833             :                 }
   11834             :             ;
   11835             : 
   11836             : opt_as:     AS
   11837             :             | /* EMPTY */
   11838             :         ;
   11839             : 
   11840             : 
   11841             : /*****************************************************************************
   11842             :  *
   11843             :  * Manipulate a text search dictionary or configuration
   11844             :  *
   11845             :  *****************************************************************************/
   11846             : 
   11847             : AlterTSDictionaryStmt:
   11848             :             ALTER TEXT_P SEARCH DICTIONARY any_name definition
   11849             :                 {
   11850          40 :                     AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
   11851             : 
   11852          40 :                     n->dictname = $5;
   11853          40 :                     n->options = $6;
   11854          40 :                     $$ = (Node *) n;
   11855             :                 }
   11856             :         ;
   11857             : 
   11858             : AlterTSConfigurationStmt:
   11859             :             ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
   11860             :                 {
   11861        8518 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11862             : 
   11863        8518 :                     n->kind = ALTER_TSCONFIG_ADD_MAPPING;
   11864        8518 :                     n->cfgname = $5;
   11865        8518 :                     n->tokentype = $9;
   11866        8518 :                     n->dicts = $11;
   11867        8518 :                     n->override = false;
   11868        8518 :                     n->replace = false;
   11869        8518 :                     $$ = (Node *) n;
   11870             :                 }
   11871             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
   11872             :                 {
   11873          26 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11874             : 
   11875          26 :                     n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
   11876          26 :                     n->cfgname = $5;
   11877          26 :                     n->tokentype = $9;
   11878          26 :                     n->dicts = $11;
   11879          26 :                     n->override = true;
   11880          26 :                     n->replace = false;
   11881          26 :                     $$ = (Node *) n;
   11882             :                 }
   11883             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
   11884             :                 {
   11885          18 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11886             : 
   11887          18 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT;
   11888          18 :                     n->cfgname = $5;
   11889          18 :                     n->tokentype = NIL;
   11890          18 :                     n->dicts = list_make2($9,$11);
   11891          18 :                     n->override = false;
   11892          18 :                     n->replace = true;
   11893          18 :                     $$ = (Node *) n;
   11894             :                 }
   11895             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
   11896             :                 {
   11897           0 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11898             : 
   11899           0 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN;
   11900           0 :                     n->cfgname = $5;
   11901           0 :                     n->tokentype = $9;
   11902           0 :                     n->dicts = list_make2($11,$13);
   11903           0 :                     n->override = false;
   11904           0 :                     n->replace = true;
   11905           0 :                     $$ = (Node *) n;
   11906             :                 }
   11907             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
   11908             :                 {
   11909          18 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11910             : 
   11911          18 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   11912          18 :                     n->cfgname = $5;
   11913          18 :                     n->tokentype = $9;
   11914          18 :                     n->missing_ok = false;
   11915          18 :                     $$ = (Node *) n;
   11916             :                 }
   11917             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
   11918             :                 {
   11919          12 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11920             : 
   11921          12 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   11922          12 :                     n->cfgname = $5;
   11923          12 :                     n->tokentype = $11;
   11924          12 :                     n->missing_ok = true;
   11925          12 :                     $$ = (Node *) n;
   11926             :                 }
   11927             :         ;
   11928             : 
   11929             : /* Use this if TIME or ORDINALITY after WITH should be taken as an identifier */
   11930             : any_with:   WITH
   11931             :             | WITH_LA
   11932             :         ;
   11933             : 
   11934             : 
   11935             : /*****************************************************************************
   11936             :  *
   11937             :  * Manipulate a conversion
   11938             :  *
   11939             :  *      CREATE [DEFAULT] CONVERSION <conversion_name>
   11940             :  *      FOR <encoding_name> TO <encoding_name> FROM <func_name>
   11941             :  *
   11942             :  *****************************************************************************/
   11943             : 
   11944             : CreateConversionStmt:
   11945             :             CREATE opt_default CONVERSION_P any_name FOR Sconst
   11946             :             TO Sconst FROM any_name
   11947             :             {
   11948          64 :                 CreateConversionStmt *n = makeNode(CreateConversionStmt);
   11949             : 
   11950          64 :                 n->conversion_name = $4;
   11951          64 :                 n->for_encoding_name = $6;
   11952          64 :                 n->to_encoding_name = $8;
   11953          64 :                 n->func_name = $10;
   11954          64 :                 n->def = $2;
   11955          64 :                 $$ = (Node *) n;
   11956             :             }
   11957             :         ;
   11958             : 
   11959             : /*****************************************************************************
   11960             :  *
   11961             :  *      QUERY:
   11962             :  *              CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
   11963             :  *              CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
   11964             :  *              CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
   11965             :  *
   11966             :  *****************************************************************************/
   11967             : 
   11968             : ClusterStmt:
   11969             :             CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
   11970             :                 {
   11971           0 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11972             : 
   11973           0 :                     n->relation = $5;
   11974           0 :                     n->indexname = $6;
   11975           0 :                     n->params = $3;
   11976           0 :                     $$ = (Node *) n;
   11977             :                 }
   11978             :             | CLUSTER opt_utility_option_list
   11979             :                 {
   11980          16 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11981             : 
   11982          16 :                     n->relation = NULL;
   11983          16 :                     n->indexname = NULL;
   11984          16 :                     n->params = $2;
   11985          16 :                     $$ = (Node *) n;
   11986             :                 }
   11987             :             /* unparenthesized VERBOSE kept for pre-14 compatibility */
   11988             :             | CLUSTER opt_verbose qualified_name cluster_index_specification
   11989             :                 {
   11990         188 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11991             : 
   11992         188 :                     n->relation = $3;
   11993         188 :                     n->indexname = $4;
   11994         188 :                     if ($2)
   11995           0 :                         n->params = list_make1(makeDefElem("verbose", NULL, @2));
   11996         188 :                     $$ = (Node *) n;
   11997             :                 }
   11998             :             /* unparenthesized VERBOSE kept for pre-17 compatibility */
   11999             :             | CLUSTER VERBOSE
   12000             :                 {
   12001           4 :                     ClusterStmt *n = makeNode(ClusterStmt);
   12002             : 
   12003           4 :                     n->relation = NULL;
   12004           4 :                     n->indexname = NULL;
   12005           4 :                     n->params = list_make1(makeDefElem("verbose", NULL, @2));
   12006           4 :                     $$ = (Node *) n;
   12007             :                 }
   12008             :             /* kept for pre-8.3 compatibility */
   12009             :             | CLUSTER opt_verbose name ON qualified_name
   12010             :                 {
   12011          20 :                     ClusterStmt *n = makeNode(ClusterStmt);
   12012             : 
   12013          20 :                     n->relation = $5;
   12014          20 :                     n->indexname = $3;
   12015          20 :                     if ($2)
   12016           0 :                         n->params = list_make1(makeDefElem("verbose", NULL, @2));
   12017          20 :                     $$ = (Node *) n;
   12018             :                 }
   12019             :         ;
   12020             : 
   12021             : cluster_index_specification:
   12022         154 :             USING name              { $$ = $2; }
   12023          34 :             | /*EMPTY*/             { $$ = NULL; }
   12024             :         ;
   12025             : 
   12026             : 
   12027             : /*****************************************************************************
   12028             :  *
   12029             :  *      QUERY:
   12030             :  *              VACUUM
   12031             :  *              ANALYZE
   12032             :  *
   12033             :  *****************************************************************************/
   12034             : 
   12035             : VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relation_list
   12036             :                 {
   12037        1236 :                     VacuumStmt *n = makeNode(VacuumStmt);
   12038             : 
   12039        1236 :                     n->options = NIL;
   12040        1236 :                     if ($2)
   12041         152 :                         n->options = lappend(n->options,
   12042         152 :                                              makeDefElem("full", NULL, @2));
   12043        1236 :                     if ($3)
   12044         162 :                         n->options = lappend(n->options,
   12045         162 :                                              makeDefElem("freeze", NULL, @3));
   12046        1236 :                     if ($4)
   12047          16 :                         n->options = lappend(n->options,
   12048          16 :                                              makeDefElem("verbose", NULL, @4));
   12049        1236 :                     if ($5)
   12050         292 :                         n->options = lappend(n->options,
   12051         292 :                                              makeDefElem("analyze", NULL, @5));
   12052        1236 :                     n->rels = $6;
   12053        1236 :                     n->is_vacuumcmd = true;
   12054        1236 :                     $$ = (Node *) n;
   12055             :                 }
   12056             :             | VACUUM '(' utility_option_list ')' opt_vacuum_relation_list
   12057             :                 {
   12058        7618 :                     VacuumStmt *n = makeNode(VacuumStmt);
   12059             : 
   12060        7618 :                     n->options = $3;
   12061        7618 :                     n->rels = $5;
   12062        7618 :                     n->is_vacuumcmd = true;
   12063        7618 :                     $$ = (Node *) n;
   12064             :                 }
   12065             :         ;
   12066             : 
   12067             : AnalyzeStmt: analyze_keyword opt_utility_option_list opt_vacuum_relation_list
   12068             :                 {
   12069        4912 :                     VacuumStmt *n = makeNode(VacuumStmt);
   12070             : 
   12071        4912 :                     n->options = $2;
   12072        4912 :                     n->rels = $3;
   12073        4912 :                     n->is_vacuumcmd = false;
   12074        4912 :                     $$ = (Node *) n;
   12075             :                 }
   12076             :             | analyze_keyword VERBOSE opt_vacuum_relation_list
   12077             :                 {
   12078           0 :                     VacuumStmt *n = makeNode(VacuumStmt);
   12079             : 
   12080           0 :                     n->options = list_make1(makeDefElem("verbose", NULL, @2));
   12081           0 :                     n->rels = $3;
   12082           0 :                     n->is_vacuumcmd = false;
   12083           0 :                     $$ = (Node *) n;
   12084             :                 }
   12085             :         ;
   12086             : 
   12087             : analyze_keyword:
   12088             :             ANALYZE
   12089             :             | ANALYSE /* British */
   12090             :         ;
   12091             : 
   12092             : opt_analyze:
   12093         292 :             analyze_keyword                         { $$ = true; }
   12094         944 :             | /*EMPTY*/                             { $$ = false; }
   12095             :         ;
   12096             : 
   12097             : opt_verbose:
   12098          16 :             VERBOSE                                 { $$ = true; }
   12099        3744 :             | /*EMPTY*/                             { $$ = false; }
   12100             :         ;
   12101             : 
   12102         152 : opt_full:   FULL                                    { $$ = true; }
   12103        1084 :             | /*EMPTY*/                             { $$ = false; }
   12104             :         ;
   12105             : 
   12106         162 : opt_freeze: FREEZE                                  { $$ = true; }
   12107        1074 :             | /*EMPTY*/                             { $$ = false; }
   12108             :         ;
   12109             : 
   12110             : opt_name_list:
   12111        2866 :             '(' name_list ')'                       { $$ = $2; }
   12112       16072 :             | /*EMPTY*/                             { $$ = NIL; }
   12113             :         ;
   12114             : 
   12115             : vacuum_relation:
   12116             :             relation_expr opt_name_list
   12117             :                 {
   12118       13576 :                     $$ = (Node *) makeVacuumRelation($1, InvalidOid, $2);
   12119             :                 }
   12120             :         ;
   12121             : 
   12122             : vacuum_relation_list:
   12123             :             vacuum_relation
   12124       13412 :                     { $$ = list_make1($1); }
   12125             :             | vacuum_relation_list ',' vacuum_relation
   12126         164 :                     { $$ = lappend($1, $3); }
   12127             :         ;
   12128             : 
   12129             : opt_vacuum_relation_list:
   12130       13412 :             vacuum_relation_list                    { $$ = $1; }
   12131         354 :             | /*EMPTY*/                             { $$ = NIL; }
   12132             :         ;
   12133             : 
   12134             : 
   12135             : /*****************************************************************************
   12136             :  *
   12137             :  *      QUERY:
   12138             :  *              EXPLAIN [ANALYZE] [VERBOSE] query
   12139             :  *              EXPLAIN ( options ) query
   12140             :  *
   12141             :  *****************************************************************************/
   12142             : 
   12143             : ExplainStmt:
   12144             :         EXPLAIN ExplainableStmt
   12145             :                 {
   12146        7718 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12147             : 
   12148        7718 :                     n->query = $2;
   12149        7718 :                     n->options = NIL;
   12150        7718 :                     $$ = (Node *) n;
   12151             :                 }
   12152             :         | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
   12153             :                 {
   12154        2316 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12155             : 
   12156        2316 :                     n->query = $4;
   12157        2316 :                     n->options = list_make1(makeDefElem("analyze", NULL, @2));
   12158        2316 :                     if ($3)
   12159           0 :                         n->options = lappend(n->options,
   12160           0 :                                              makeDefElem("verbose", NULL, @3));
   12161        2316 :                     $$ = (Node *) n;
   12162             :                 }
   12163             :         | EXPLAIN VERBOSE ExplainableStmt
   12164             :                 {
   12165          12 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12166             : 
   12167          12 :                     n->query = $3;
   12168          12 :                     n->options = list_make1(makeDefElem("verbose", NULL, @2));
   12169          12 :                     $$ = (Node *) n;
   12170             :                 }
   12171             :         | EXPLAIN '(' utility_option_list ')' ExplainableStmt
   12172             :                 {
   12173       14344 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12174             : 
   12175       14344 :                     n->query = $5;
   12176       14344 :                     n->options = $3;
   12177       14344 :                     $$ = (Node *) n;
   12178             :                 }
   12179             :         ;
   12180             : 
   12181             : ExplainableStmt:
   12182             :             SelectStmt
   12183             :             | InsertStmt
   12184             :             | UpdateStmt
   12185             :             | DeleteStmt
   12186             :             | MergeStmt
   12187             :             | DeclareCursorStmt
   12188             :             | CreateAsStmt
   12189             :             | CreateMatViewStmt
   12190             :             | RefreshMatViewStmt
   12191             :             | ExecuteStmt                   /* by default all are $$=$1 */
   12192             :         ;
   12193             : 
   12194             : /*****************************************************************************
   12195             :  *
   12196             :  *      QUERY:
   12197             :  *              PREPARE <plan_name> [(args, ...)] AS <query>
   12198             :  *
   12199             :  *****************************************************************************/
   12200             : 
   12201             : PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
   12202             :                 {
   12203        1928 :                     PrepareStmt *n = makeNode(PrepareStmt);
   12204             : 
   12205        1928 :                     n->name = $2;
   12206        1928 :                     n->argtypes = $3;
   12207        1928 :                     n->query = $5;
   12208        1928 :                     $$ = (Node *) n;
   12209             :                 }
   12210             :         ;
   12211             : 
   12212        1612 : prep_type_clause: '(' type_list ')'         { $$ = $2; }
   12213         334 :                 | /* EMPTY */               { $$ = NIL; }
   12214             :         ;
   12215             : 
   12216             : PreparableStmt:
   12217             :             SelectStmt
   12218             :             | InsertStmt
   12219             :             | UpdateStmt
   12220             :             | DeleteStmt
   12221             :             | MergeStmt                     /* by default all are $$=$1 */
   12222             :         ;
   12223             : 
   12224             : /*****************************************************************************
   12225             :  *
   12226             :  * EXECUTE <plan_name> [(params, ...)]
   12227             :  * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
   12228             :  *
   12229             :  *****************************************************************************/
   12230             : 
   12231             : ExecuteStmt: EXECUTE name execute_param_clause
   12232             :                 {
   12233       16134 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12234             : 
   12235       16134 :                     n->name = $2;
   12236       16134 :                     n->params = $3;
   12237       16134 :                     $$ = (Node *) n;
   12238             :                 }
   12239             :             | CREATE OptTemp TABLE create_as_target AS
   12240             :                 EXECUTE name execute_param_clause opt_with_data
   12241             :                 {
   12242          76 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   12243          76 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12244             : 
   12245          76 :                     n->name = $7;
   12246          76 :                     n->params = $8;
   12247          76 :                     ctas->query = (Node *) n;
   12248          76 :                     ctas->into = $4;
   12249          76 :                     ctas->objtype = OBJECT_TABLE;
   12250          76 :                     ctas->is_select_into = false;
   12251          76 :                     ctas->if_not_exists = false;
   12252             :                     /* cram additional flags into the IntoClause */
   12253          76 :                     $4->rel->relpersistence = $2;
   12254          76 :                     $4->skipData = !($9);
   12255          76 :                     $$ = (Node *) ctas;
   12256             :                 }
   12257             :             | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS
   12258             :                 EXECUTE name execute_param_clause opt_with_data
   12259             :                 {
   12260          12 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   12261          12 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12262             : 
   12263          12 :                     n->name = $10;
   12264          12 :                     n->params = $11;
   12265          12 :                     ctas->query = (Node *) n;
   12266          12 :                     ctas->into = $7;
   12267          12 :                     ctas->objtype = OBJECT_TABLE;
   12268          12 :                     ctas->is_select_into = false;
   12269          12 :                     ctas->if_not_exists = true;
   12270             :                     /* cram additional flags into the IntoClause */
   12271          12 :                     $7->rel->relpersistence = $2;
   12272          12 :                     $7->skipData = !($12);
   12273          12 :                     $$ = (Node *) ctas;
   12274             :                 }
   12275             :         ;
   12276             : 
   12277       15078 : execute_param_clause: '(' expr_list ')'             { $$ = $2; }
   12278        1144 :                     | /* EMPTY */                   { $$ = NIL; }
   12279             :                     ;
   12280             : 
   12281             : /*****************************************************************************
   12282             :  *
   12283             :  *      QUERY:
   12284             :  *              DEALLOCATE [PREPARE] <plan_name>
   12285             :  *
   12286             :  *****************************************************************************/
   12287             : 
   12288             : DeallocateStmt: DEALLOCATE name
   12289             :                     {
   12290        3998 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12291             : 
   12292        3998 :                         n->name = $2;
   12293        3998 :                         n->isall = false;
   12294        3998 :                         n->location = @2;
   12295        3998 :                         $$ = (Node *) n;
   12296             :                     }
   12297             :                 | DEALLOCATE PREPARE name
   12298             :                     {
   12299          20 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12300             : 
   12301          20 :                         n->name = $3;
   12302          20 :                         n->isall = false;
   12303          20 :                         n->location = @3;
   12304          20 :                         $$ = (Node *) n;
   12305             :                     }
   12306             :                 | DEALLOCATE ALL
   12307             :                     {
   12308          70 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12309             : 
   12310          70 :                         n->name = NULL;
   12311          70 :                         n->isall = true;
   12312          70 :                         n->location = -1;
   12313          70 :                         $$ = (Node *) n;
   12314             :                     }
   12315             :                 | DEALLOCATE PREPARE ALL
   12316             :                     {
   12317           2 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12318             : 
   12319           2 :                         n->name = NULL;
   12320           2 :                         n->isall = true;
   12321           2 :                         n->location = -1;
   12322           2 :                         $$ = (Node *) n;
   12323             :                     }
   12324             :         ;
   12325             : 
   12326             : /*****************************************************************************
   12327             :  *
   12328             :  *      QUERY:
   12329             :  *              INSERT STATEMENTS
   12330             :  *
   12331             :  *****************************************************************************/
   12332             : 
   12333             : InsertStmt:
   12334             :             opt_with_clause INSERT INTO insert_target insert_rest
   12335             :             opt_on_conflict returning_clause
   12336             :                 {
   12337       68760 :                     $5->relation = $4;
   12338       68760 :                     $5->onConflictClause = $6;
   12339       68760 :                     $5->returningClause = $7;
   12340       68760 :                     $5->withClause = $1;
   12341       68760 :                     $$ = (Node *) $5;
   12342             :                 }
   12343             :         ;
   12344             : 
   12345             : /*
   12346             :  * Can't easily make AS optional here, because VALUES in insert_rest would
   12347             :  * have a shift/reduce conflict with VALUES as an optional alias.  We could
   12348             :  * easily allow unreserved_keywords as optional aliases, but that'd be an odd
   12349             :  * divergence from other places.  So just require AS for now.
   12350             :  */
   12351             : insert_target:
   12352             :             qualified_name
   12353             :                 {
   12354       68634 :                     $$ = $1;
   12355             :                 }
   12356             :             | qualified_name AS ColId
   12357             :                 {
   12358         132 :                     $1->alias = makeAlias($3, NIL);
   12359         132 :                     $$ = $1;
   12360             :                 }
   12361             :         ;
   12362             : 
   12363             : insert_rest:
   12364             :             SelectStmt
   12365             :                 {
   12366       43570 :                     $$ = makeNode(InsertStmt);
   12367       43570 :                     $$->cols = NIL;
   12368       43570 :                     $$->selectStmt = $1;
   12369             :                 }
   12370             :             | OVERRIDING override_kind VALUE_P SelectStmt
   12371             :                 {
   12372          96 :                     $$ = makeNode(InsertStmt);
   12373          96 :                     $$->cols = NIL;
   12374          96 :                     $$->override = $2;
   12375          96 :                     $$->selectStmt = $4;
   12376             :                 }
   12377             :             | '(' insert_column_list ')' SelectStmt
   12378             :                 {
   12379       14292 :                     $$ = makeNode(InsertStmt);
   12380       14292 :                     $$->cols = $2;
   12381       14292 :                     $$->selectStmt = $4;
   12382             :                 }
   12383             :             | '(' insert_column_list ')' OVERRIDING override_kind VALUE_P SelectStmt
   12384             :                 {
   12385           0 :                     $$ = makeNode(InsertStmt);
   12386           0 :                     $$->cols = $2;
   12387           0 :                     $$->override = $5;
   12388           0 :                     $$->selectStmt = $7;
   12389             :                 }
   12390             :             | DEFAULT VALUES
   12391             :                 {
   12392       10808 :                     $$ = makeNode(InsertStmt);
   12393       10808 :                     $$->cols = NIL;
   12394       10808 :                     $$->selectStmt = NULL;
   12395             :                 }
   12396             :         ;
   12397             : 
   12398             : override_kind:
   12399          66 :             USER        { $$ = OVERRIDING_USER_VALUE; }
   12400          60 :             | SYSTEM_P  { $$ = OVERRIDING_SYSTEM_VALUE; }
   12401             :         ;
   12402             : 
   12403             : insert_column_list:
   12404             :             insert_column_item
   12405       14626 :                     { $$ = list_make1($1); }
   12406             :             | insert_column_list ',' insert_column_item
   12407       16220 :                     { $$ = lappend($1, $3); }
   12408             :         ;
   12409             : 
   12410             : insert_column_item:
   12411             :             ColId opt_indirection
   12412             :                 {
   12413       30846 :                     $$ = makeNode(ResTarget);
   12414       30846 :                     $$->name = $1;
   12415       30846 :                     $$->indirection = check_indirection($2, yyscanner);
   12416       30846 :                     $$->val = NULL;
   12417       30846 :                     $$->location = @1;
   12418             :                 }
   12419             :         ;
   12420             : 
   12421             : opt_on_conflict:
   12422             :             ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
   12423             :                 {
   12424        1314 :                     $$ = makeNode(OnConflictClause);
   12425        1314 :                     $$->action = ONCONFLICT_UPDATE;
   12426        1314 :                     $$->infer = $3;
   12427        1314 :                     $$->targetList = $7;
   12428        1314 :                     $$->whereClause = $8;
   12429        1314 :                     $$->location = @1;
   12430             :                 }
   12431             :             |
   12432             :             ON CONFLICT opt_conf_expr DO NOTHING
   12433             :                 {
   12434         562 :                     $$ = makeNode(OnConflictClause);
   12435         562 :                     $$->action = ONCONFLICT_NOTHING;
   12436         562 :                     $$->infer = $3;
   12437         562 :                     $$->targetList = NIL;
   12438         562 :                     $$->whereClause = NULL;
   12439         562 :                     $$->location = @1;
   12440             :                 }
   12441             :             | /*EMPTY*/
   12442             :                 {
   12443       66890 :                     $$ = NULL;
   12444             :                 }
   12445             :         ;
   12446             : 
   12447             : opt_conf_expr:
   12448             :             '(' index_params ')' where_clause
   12449             :                 {
   12450        1438 :                     $$ = makeNode(InferClause);
   12451        1438 :                     $$->indexElems = $2;
   12452        1438 :                     $$->whereClause = $4;
   12453        1438 :                     $$->conname = NULL;
   12454        1438 :                     $$->location = @1;
   12455             :                 }
   12456             :             |
   12457             :             ON CONSTRAINT name
   12458             :                 {
   12459         192 :                     $$ = makeNode(InferClause);
   12460         192 :                     $$->indexElems = NIL;
   12461         192 :                     $$->whereClause = NULL;
   12462         192 :                     $$->conname = $3;
   12463         192 :                     $$->location = @1;
   12464             :                 }
   12465             :             | /*EMPTY*/
   12466             :                 {
   12467         246 :                     $$ = NULL;
   12468             :                 }
   12469             :         ;
   12470             : 
   12471             : returning_clause:
   12472             :             RETURNING returning_with_clause target_list
   12473             :                 {
   12474        3166 :                     ReturningClause *n = makeNode(ReturningClause);
   12475             : 
   12476        3166 :                     n->options = $2;
   12477        3166 :                     n->exprs = $3;
   12478        3166 :                     $$ = n;
   12479             :                 }
   12480             :             | /* EMPTY */
   12481             :                 {
   12482       86708 :                     $$ = NULL;
   12483             :                 }
   12484             :         ;
   12485             : 
   12486             : returning_with_clause:
   12487          72 :             WITH '(' returning_options ')'      { $$ = $3; }
   12488        3094 :             | /* EMPTY */                       { $$ = NIL; }
   12489             :         ;
   12490             : 
   12491             : returning_options:
   12492          72 :             returning_option                            { $$ = list_make1($1); }
   12493          54 :             | returning_options ',' returning_option    { $$ = lappend($1, $3); }
   12494             :         ;
   12495             : 
   12496             : returning_option:
   12497             :             returning_option_kind AS ColId
   12498             :                 {
   12499         126 :                     ReturningOption *n = makeNode(ReturningOption);
   12500             : 
   12501         126 :                     n->option = $1;
   12502         126 :                     n->value = $3;
   12503         126 :                     n->location = @1;
   12504         126 :                     $$ = (Node *) n;
   12505             :                 }
   12506             :         ;
   12507             : 
   12508             : returning_option_kind:
   12509          54 :             OLD         { $$ = RETURNING_OPTION_OLD; }
   12510          72 :             | NEW       { $$ = RETURNING_OPTION_NEW; }
   12511             :         ;
   12512             : 
   12513             : 
   12514             : /*****************************************************************************
   12515             :  *
   12516             :  *      QUERY:
   12517             :  *              DELETE STATEMENTS
   12518             :  *
   12519             :  *****************************************************************************/
   12520             : 
   12521             : DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
   12522             :             using_clause where_or_current_clause returning_clause
   12523             :                 {
   12524        4682 :                     DeleteStmt *n = makeNode(DeleteStmt);
   12525             : 
   12526        4682 :                     n->relation = $4;
   12527        4682 :                     n->usingClause = $5;
   12528        4682 :                     n->whereClause = $6;
   12529        4682 :                     n->returningClause = $7;
   12530        4682 :                     n->withClause = $1;
   12531        4682 :                     $$ = (Node *) n;
   12532             :                 }
   12533             :         ;
   12534             : 
   12535             : using_clause:
   12536         108 :                 USING from_list                     { $$ = $2; }
   12537        4574 :             | /*EMPTY*/                             { $$ = NIL; }
   12538             :         ;
   12539             : 
   12540             : 
   12541             : /*****************************************************************************
   12542             :  *
   12543             :  *      QUERY:
   12544             :  *              LOCK TABLE
   12545             :  *
   12546             :  *****************************************************************************/
   12547             : 
   12548             : LockStmt:   LOCK_P opt_table relation_expr_list opt_lock opt_nowait
   12549             :                 {
   12550        1046 :                     LockStmt   *n = makeNode(LockStmt);
   12551             : 
   12552        1046 :                     n->relations = $3;
   12553        1046 :                     n->mode = $4;
   12554        1046 :                     n->nowait = $5;
   12555        1046 :                     $$ = (Node *) n;
   12556             :                 }
   12557             :         ;
   12558             : 
   12559         938 : opt_lock:   IN_P lock_type MODE             { $$ = $2; }
   12560         108 :             | /*EMPTY*/                     { $$ = AccessExclusiveLock; }
   12561             :         ;
   12562             : 
   12563         448 : lock_type:  ACCESS SHARE                    { $$ = AccessShareLock; }
   12564          14 :             | ROW SHARE                     { $$ = RowShareLock; }
   12565          88 :             | ROW EXCLUSIVE                 { $$ = RowExclusiveLock; }
   12566          66 :             | SHARE UPDATE EXCLUSIVE        { $$ = ShareUpdateExclusiveLock; }
   12567          80 :             | SHARE                         { $$ = ShareLock; }
   12568          14 :             | SHARE ROW EXCLUSIVE           { $$ = ShareRowExclusiveLock; }
   12569         102 :             | EXCLUSIVE                     { $$ = ExclusiveLock; }
   12570         126 :             | ACCESS EXCLUSIVE              { $$ = AccessExclusiveLock; }
   12571             :         ;
   12572             : 
   12573         186 : opt_nowait: NOWAIT                          { $$ = true; }
   12574         890 :             | /*EMPTY*/                     { $$ = false; }
   12575             :         ;
   12576             : 
   12577             : opt_nowait_or_skip:
   12578          50 :             NOWAIT                          { $$ = LockWaitError; }
   12579         190 :             | SKIP LOCKED                   { $$ = LockWaitSkip; }
   12580        5128 :             | /*EMPTY*/                     { $$ = LockWaitBlock; }
   12581             :         ;
   12582             : 
   12583             : 
   12584             : /*****************************************************************************
   12585             :  *
   12586             :  *      QUERY:
   12587             :  *              UpdateStmt (UPDATE)
   12588             :  *
   12589             :  *****************************************************************************/
   12590             : 
   12591             : UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
   12592             :             SET set_clause_list
   12593             :             from_clause
   12594             :             where_or_current_clause
   12595             :             returning_clause
   12596             :                 {
   12597       14314 :                     UpdateStmt *n = makeNode(UpdateStmt);
   12598             : 
   12599       14314 :                     n->relation = $3;
   12600       14314 :                     n->targetList = $5;
   12601       14314 :                     n->fromClause = $6;
   12602       14314 :                     n->whereClause = $7;
   12603       14314 :                     n->returningClause = $8;
   12604       14314 :                     n->withClause = $1;
   12605       14314 :                     $$ = (Node *) n;
   12606             :                 }
   12607             :         ;
   12608             : 
   12609             : set_clause_list:
   12610       17226 :             set_clause                          { $$ = $1; }
   12611        4322 :             | set_clause_list ',' set_clause    { $$ = list_concat($1,$3); }
   12612             :         ;
   12613             : 
   12614             : set_clause:
   12615             :             set_target '=' a_expr
   12616             :                 {
   12617       21364 :                     $1->val = (Node *) $3;
   12618       21364 :                     $$ = list_make1($1);
   12619             :                 }
   12620             :             | '(' set_target_list ')' '=' a_expr
   12621             :                 {
   12622         184 :                     int         ncolumns = list_length($2);
   12623         184 :                     int         i = 1;
   12624             :                     ListCell   *col_cell;
   12625             : 
   12626             :                     /* Create a MultiAssignRef source for each target */
   12627         568 :                     foreach(col_cell, $2)
   12628             :                     {
   12629         384 :                         ResTarget  *res_col = (ResTarget *) lfirst(col_cell);
   12630         384 :                         MultiAssignRef *r = makeNode(MultiAssignRef);
   12631             : 
   12632         384 :                         r->source = (Node *) $5;
   12633         384 :                         r->colno = i;
   12634         384 :                         r->ncolumns = ncolumns;
   12635         384 :                         res_col->val = (Node *) r;
   12636         384 :                         i++;
   12637             :                     }
   12638             : 
   12639         184 :                     $$ = $2;
   12640             :                 }
   12641             :         ;
   12642             : 
   12643             : set_target:
   12644             :             ColId opt_indirection
   12645             :                 {
   12646       21754 :                     $$ = makeNode(ResTarget);
   12647       21754 :                     $$->name = $1;
   12648       21754 :                     $$->indirection = check_indirection($2, yyscanner);
   12649       21754 :                     $$->val = NULL;  /* upper production sets this */
   12650       21754 :                     $$->location = @1;
   12651             :                 }
   12652             :         ;
   12653             : 
   12654             : set_target_list:
   12655         190 :             set_target                              { $$ = list_make1($1); }
   12656         200 :             | set_target_list ',' set_target        { $$ = lappend($1,$3); }
   12657             :         ;
   12658             : 
   12659             : 
   12660             : /*****************************************************************************
   12661             :  *
   12662             :  *      QUERY:
   12663             :  *              MERGE
   12664             :  *
   12665             :  *****************************************************************************/
   12666             : 
   12667             : MergeStmt:
   12668             :             opt_with_clause MERGE INTO relation_expr_opt_alias
   12669             :             USING table_ref
   12670             :             ON a_expr
   12671             :             merge_when_list
   12672             :             returning_clause
   12673             :                 {
   12674        2118 :                     MergeStmt  *m = makeNode(MergeStmt);
   12675             : 
   12676        2118 :                     m->withClause = $1;
   12677        2118 :                     m->relation = $4;
   12678        2118 :                     m->sourceRelation = $6;
   12679        2118 :                     m->joinCondition = $8;
   12680        2118 :                     m->mergeWhenClauses = $9;
   12681        2118 :                     m->returningClause = $10;
   12682             : 
   12683        2118 :                     $$ = (Node *) m;
   12684             :                 }
   12685             :         ;
   12686             : 
   12687             : merge_when_list:
   12688        2118 :             merge_when_clause                       { $$ = list_make1($1); }
   12689        1200 :             | merge_when_list merge_when_clause     { $$ = lappend($1,$2); }
   12690             :         ;
   12691             : 
   12692             : /*
   12693             :  * A WHEN clause may be WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, or WHEN NOT
   12694             :  * MATCHED [BY TARGET]. The first two cases match target tuples, and support
   12695             :  * UPDATE/DELETE/DO NOTHING actions. The third case does not match target
   12696             :  * tuples, and only supports INSERT/DO NOTHING actions.
   12697             :  */
   12698             : merge_when_clause:
   12699             :             merge_when_tgt_matched opt_merge_when_condition THEN merge_update
   12700             :                 {
   12701        1598 :                     $4->matchKind = $1;
   12702        1598 :                     $4->condition = $2;
   12703             : 
   12704        1598 :                     $$ = (Node *) $4;
   12705             :                 }
   12706             :             | merge_when_tgt_matched opt_merge_when_condition THEN merge_delete
   12707             :                 {
   12708         530 :                     $4->matchKind = $1;
   12709         530 :                     $4->condition = $2;
   12710             : 
   12711         530 :                     $$ = (Node *) $4;
   12712             :                 }
   12713             :             | merge_when_tgt_not_matched opt_merge_when_condition THEN merge_insert
   12714             :                 {
   12715        1100 :                     $4->matchKind = $1;
   12716        1100 :                     $4->condition = $2;
   12717             : 
   12718        1100 :                     $$ = (Node *) $4;
   12719             :                 }
   12720             :             | merge_when_tgt_matched opt_merge_when_condition THEN DO NOTHING
   12721             :                 {
   12722          70 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12723             : 
   12724          70 :                     m->matchKind = $1;
   12725          70 :                     m->commandType = CMD_NOTHING;
   12726          70 :                     m->condition = $2;
   12727             : 
   12728          70 :                     $$ = (Node *) m;
   12729             :                 }
   12730             :             | merge_when_tgt_not_matched opt_merge_when_condition THEN DO NOTHING
   12731             :                 {
   12732          20 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12733             : 
   12734          20 :                     m->matchKind = $1;
   12735          20 :                     m->commandType = CMD_NOTHING;
   12736          20 :                     m->condition = $2;
   12737             : 
   12738          20 :                     $$ = (Node *) m;
   12739             :                 }
   12740             :         ;
   12741             : 
   12742             : merge_when_tgt_matched:
   12743        2036 :             WHEN MATCHED                    { $$ = MERGE_WHEN_MATCHED; }
   12744         180 :             | WHEN NOT MATCHED BY SOURCE    { $$ = MERGE_WHEN_NOT_MATCHED_BY_SOURCE; }
   12745             :         ;
   12746             : 
   12747             : merge_when_tgt_not_matched:
   12748        1126 :             WHEN NOT MATCHED                { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
   12749          18 :             | WHEN NOT MATCHED BY TARGET    { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
   12750             :         ;
   12751             : 
   12752             : opt_merge_when_condition:
   12753         850 :             AND a_expr              { $$ = $2; }
   12754        2510 :             |                       { $$ = NULL; }
   12755             :         ;
   12756             : 
   12757             : merge_update:
   12758             :             UPDATE SET set_clause_list
   12759             :                 {
   12760        1598 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12761        1598 :                     n->commandType = CMD_UPDATE;
   12762        1598 :                     n->override = OVERRIDING_NOT_SET;
   12763        1598 :                     n->targetList = $3;
   12764        1598 :                     n->values = NIL;
   12765             : 
   12766        1598 :                     $$ = n;
   12767             :                 }
   12768             :         ;
   12769             : 
   12770             : merge_delete:
   12771             :             DELETE_P
   12772             :                 {
   12773         530 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12774         530 :                     n->commandType = CMD_DELETE;
   12775         530 :                     n->override = OVERRIDING_NOT_SET;
   12776         530 :                     n->targetList = NIL;
   12777         530 :                     n->values = NIL;
   12778             : 
   12779         530 :                     $$ = n;
   12780             :                 }
   12781             :         ;
   12782             : 
   12783             : merge_insert:
   12784             :             INSERT merge_values_clause
   12785             :                 {
   12786         730 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12787         730 :                     n->commandType = CMD_INSERT;
   12788         730 :                     n->override = OVERRIDING_NOT_SET;
   12789         730 :                     n->targetList = NIL;
   12790         730 :                     n->values = $2;
   12791         730 :                     $$ = n;
   12792             :                 }
   12793             :             | INSERT OVERRIDING override_kind VALUE_P merge_values_clause
   12794             :                 {
   12795           0 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12796           0 :                     n->commandType = CMD_INSERT;
   12797           0 :                     n->override = $3;
   12798           0 :                     n->targetList = NIL;
   12799           0 :                     n->values = $5;
   12800           0 :                     $$ = n;
   12801             :                 }
   12802             :             | INSERT '(' insert_column_list ')' merge_values_clause
   12803             :                 {
   12804         304 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12805         304 :                     n->commandType = CMD_INSERT;
   12806         304 :                     n->override = OVERRIDING_NOT_SET;
   12807         304 :                     n->targetList = $3;
   12808         304 :                     n->values = $5;
   12809         304 :                     $$ = n;
   12810             :                 }
   12811             :             | INSERT '(' insert_column_list ')' OVERRIDING override_kind VALUE_P merge_values_clause
   12812             :                 {
   12813          30 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12814          30 :                     n->commandType = CMD_INSERT;
   12815          30 :                     n->override = $6;
   12816          30 :                     n->targetList = $3;
   12817          30 :                     n->values = $8;
   12818          30 :                     $$ = n;
   12819             :                 }
   12820             :             | INSERT DEFAULT VALUES
   12821             :                 {
   12822          36 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12823          36 :                     n->commandType = CMD_INSERT;
   12824          36 :                     n->override = OVERRIDING_NOT_SET;
   12825          36 :                     n->targetList = NIL;
   12826          36 :                     n->values = NIL;
   12827          36 :                     $$ = n;
   12828             :                 }
   12829             :         ;
   12830             : 
   12831             : merge_values_clause:
   12832             :             VALUES '(' expr_list ')'
   12833             :                 {
   12834        1064 :                     $$ = $3;
   12835             :                 }
   12836             :         ;
   12837             : 
   12838             : /*****************************************************************************
   12839             :  *
   12840             :  *      QUERY:
   12841             :  *              CURSOR STATEMENTS
   12842             :  *
   12843             :  *****************************************************************************/
   12844             : DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
   12845             :                 {
   12846        4606 :                     DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
   12847             : 
   12848        4606 :                     n->portalname = $2;
   12849             :                     /* currently we always set FAST_PLAN option */
   12850        4606 :                     n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
   12851        4606 :                     n->query = $7;
   12852        4606 :                     $$ = (Node *) n;
   12853             :                 }
   12854             :         ;
   12855             : 
   12856       14806 : cursor_name:    name                        { $$ = $1; }
   12857             :         ;
   12858             : 
   12859        4606 : cursor_options: /*EMPTY*/                   { $$ = 0; }
   12860          28 :             | cursor_options NO SCROLL      { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
   12861         240 :             | cursor_options SCROLL         { $$ = $1 | CURSOR_OPT_SCROLL; }
   12862          14 :             | cursor_options BINARY         { $$ = $1 | CURSOR_OPT_BINARY; }
   12863           0 :             | cursor_options ASENSITIVE     { $$ = $1 | CURSOR_OPT_ASENSITIVE; }
   12864           6 :             | cursor_options INSENSITIVE    { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
   12865             :         ;
   12866             : 
   12867        4508 : opt_hold: /* EMPTY */                       { $$ = 0; }
   12868          92 :             | WITH HOLD                     { $$ = CURSOR_OPT_HOLD; }
   12869           6 :             | WITHOUT HOLD                  { $$ = 0; }
   12870             :         ;
   12871             : 
   12872             : /*****************************************************************************
   12873             :  *
   12874             :  *      QUERY:
   12875             :  *              SELECT STATEMENTS
   12876             :  *
   12877             :  *****************************************************************************/
   12878             : 
   12879             : /* A complete SELECT statement looks like this.
   12880             :  *
   12881             :  * The rule returns either a single SelectStmt node or a tree of them,
   12882             :  * representing a set-operation tree.
   12883             :  *
   12884             :  * There is an ambiguity when a sub-SELECT is within an a_expr and there
   12885             :  * are excess parentheses: do the parentheses belong to the sub-SELECT or
   12886             :  * to the surrounding a_expr?  We don't really care, but bison wants to know.
   12887             :  * To resolve the ambiguity, we are careful to define the grammar so that
   12888             :  * the decision is staved off as long as possible: as long as we can keep
   12889             :  * absorbing parentheses into the sub-SELECT, we will do so, and only when
   12890             :  * it's no longer possible to do that will we decide that parens belong to
   12891             :  * the expression.  For example, in "SELECT (((SELECT 2)) + 3)" the extra
   12892             :  * parentheses are treated as part of the sub-select.  The necessity of doing
   12893             :  * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)".    Had we
   12894             :  * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
   12895             :  * SELECT viewpoint when we see the UNION.
   12896             :  *
   12897             :  * This approach is implemented by defining a nonterminal select_with_parens,
   12898             :  * which represents a SELECT with at least one outer layer of parentheses,
   12899             :  * and being careful to use select_with_parens, never '(' SelectStmt ')',
   12900             :  * in the expression grammar.  We will then have shift-reduce conflicts
   12901             :  * which we can resolve in favor of always treating '(' <select> ')' as
   12902             :  * a select_with_parens.  To resolve the conflicts, the productions that
   12903             :  * conflict with the select_with_parens productions are manually given
   12904             :  * precedences lower than the precedence of ')', thereby ensuring that we
   12905             :  * shift ')' (and then reduce to select_with_parens) rather than trying to
   12906             :  * reduce the inner <select> nonterminal to something else.  We use UMINUS
   12907             :  * precedence for this, which is a fairly arbitrary choice.
   12908             :  *
   12909             :  * To be able to define select_with_parens itself without ambiguity, we need
   12910             :  * a nonterminal select_no_parens that represents a SELECT structure with no
   12911             :  * outermost parentheses.  This is a little bit tedious, but it works.
   12912             :  *
   12913             :  * In non-expression contexts, we use SelectStmt which can represent a SELECT
   12914             :  * with or without outer parentheses.
   12915             :  */
   12916             : 
   12917             : SelectStmt: select_no_parens            %prec UMINUS
   12918             :             | select_with_parens        %prec UMINUS
   12919             :         ;
   12920             : 
   12921             : select_with_parens:
   12922       65024 :             '(' select_no_parens ')'                { $$ = $2; }
   12923         156 :             | '(' select_with_parens ')'            { $$ = $2; }
   12924             :         ;
   12925             : 
   12926             : /*
   12927             :  * This rule parses the equivalent of the standard's <query expression>.
   12928             :  * The duplicative productions are annoying, but hard to get rid of without
   12929             :  * creating shift/reduce conflicts.
   12930             :  *
   12931             :  *  The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
   12932             :  *  In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
   12933             :  *  We now support both orderings, but prefer LIMIT/OFFSET before the locking
   12934             :  * clause.
   12935             :  *  2002-08-28 bjm
   12936             :  */
   12937             : select_no_parens:
   12938      390830 :             simple_select                       { $$ = $1; }
   12939             :             | select_clause sort_clause
   12940             :                 {
   12941       70788 :                     insertSelectOptions((SelectStmt *) $1, $2, NIL,
   12942             :                                         NULL, NULL,
   12943             :                                         yyscanner);
   12944       70788 :                     $$ = $1;
   12945             :                 }
   12946             :             | select_clause opt_sort_clause for_locking_clause opt_select_limit
   12947             :                 {
   12948        4920 :                     insertSelectOptions((SelectStmt *) $1, $2, $3,
   12949        4920 :                                         $4,
   12950             :                                         NULL,
   12951             :                                         yyscanner);
   12952        4920 :                     $$ = $1;
   12953             :                 }
   12954             :             | select_clause opt_sort_clause select_limit opt_for_locking_clause
   12955             :                 {
   12956        4912 :                     insertSelectOptions((SelectStmt *) $1, $2, $4,
   12957        4912 :                                         $3,
   12958             :                                         NULL,
   12959             :                                         yyscanner);
   12960        4900 :                     $$ = $1;
   12961             :                 }
   12962             :             | with_clause select_clause
   12963             :                 {
   12964        2204 :                     insertSelectOptions((SelectStmt *) $2, NULL, NIL,
   12965             :                                         NULL,
   12966        2204 :                                         $1,
   12967             :                                         yyscanner);
   12968        2204 :                     $$ = $2;
   12969             :                 }
   12970             :             | with_clause select_clause sort_clause
   12971             :                 {
   12972         608 :                     insertSelectOptions((SelectStmt *) $2, $3, NIL,
   12973             :                                         NULL,
   12974         608 :                                         $1,
   12975             :                                         yyscanner);
   12976         608 :                     $$ = $2;
   12977             :                 }
   12978             :             | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
   12979             :                 {
   12980           6 :                     insertSelectOptions((SelectStmt *) $2, $3, $4,
   12981           6 :                                         $5,
   12982           6 :                                         $1,
   12983             :                                         yyscanner);
   12984           6 :                     $$ = $2;
   12985             :                 }
   12986             :             | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
   12987             :                 {
   12988          64 :                     insertSelectOptions((SelectStmt *) $2, $3, $5,
   12989          64 :                                         $4,
   12990          64 :                                         $1,
   12991             :                                         yyscanner);
   12992          64 :                     $$ = $2;
   12993             :                 }
   12994             :         ;
   12995             : 
   12996             : select_clause:
   12997      122350 :             simple_select                           { $$ = $1; }
   12998         588 :             | select_with_parens                    { $$ = $1; }
   12999             :         ;
   13000             : 
   13001             : /*
   13002             :  * This rule parses SELECT statements that can appear within set operations,
   13003             :  * including UNION, INTERSECT and EXCEPT.  '(' and ')' can be used to specify
   13004             :  * the ordering of the set operations.  Without '(' and ')' we want the
   13005             :  * operations to be ordered per the precedence specs at the head of this file.
   13006             :  *
   13007             :  * As with select_no_parens, simple_select cannot have outer parentheses,
   13008             :  * but can have parenthesized subclauses.
   13009             :  *
   13010             :  * It might appear that we could fold the first two alternatives into one
   13011             :  * by using opt_distinct_clause.  However, that causes a shift/reduce conflict
   13012             :  * against INSERT ... SELECT ... ON CONFLICT.  We avoid the ambiguity by
   13013             :  * requiring SELECT DISTINCT [ON] to be followed by a non-empty target_list.
   13014             :  *
   13015             :  * Note that sort clauses cannot be included at this level --- SQL requires
   13016             :  *      SELECT foo UNION SELECT bar ORDER BY baz
   13017             :  * to be parsed as
   13018             :  *      (SELECT foo UNION SELECT bar) ORDER BY baz
   13019             :  * not
   13020             :  *      SELECT foo UNION (SELECT bar ORDER BY baz)
   13021             :  * Likewise for WITH, FOR UPDATE and LIMIT.  Therefore, those clauses are
   13022             :  * described as part of the select_no_parens production, not simple_select.
   13023             :  * This does not limit functionality, because you can reintroduce these
   13024             :  * clauses inside parentheses.
   13025             :  *
   13026             :  * NOTE: only the leftmost component SelectStmt should have INTO.
   13027             :  * However, this is not checked by the grammar; parse analysis must check it.
   13028             :  */
   13029             : simple_select:
   13030             :             SELECT opt_all_clause opt_target_list
   13031             :             into_clause from_clause where_clause
   13032             :             group_clause having_clause window_clause
   13033             :                 {
   13034      430062 :                     SelectStmt *n = makeNode(SelectStmt);
   13035             : 
   13036      430062 :                     n->targetList = $3;
   13037      430062 :                     n->intoClause = $4;
   13038      430062 :                     n->fromClause = $5;
   13039      430062 :                     n->whereClause = $6;
   13040      430062 :                     n->groupClause = ($7)->list;
   13041      430062 :                     n->groupDistinct = ($7)->distinct;
   13042      430062 :                     n->groupByAll = ($7)->all;
   13043      430062 :                     n->havingClause = $8;
   13044      430062 :                     n->windowClause = $9;
   13045      430062 :                     $$ = (Node *) n;
   13046             :                 }
   13047             :             | SELECT distinct_clause target_list
   13048             :             into_clause from_clause where_clause
   13049             :             group_clause having_clause window_clause
   13050             :                 {
   13051        3998 :                     SelectStmt *n = makeNode(SelectStmt);
   13052             : 
   13053        3998 :                     n->distinctClause = $2;
   13054        3998 :                     n->targetList = $3;
   13055        3998 :                     n->intoClause = $4;
   13056        3998 :                     n->fromClause = $5;
   13057        3998 :                     n->whereClause = $6;
   13058        3998 :                     n->groupClause = ($7)->list;
   13059        3998 :                     n->groupDistinct = ($7)->distinct;
   13060        3998 :                     n->groupByAll = ($7)->all;
   13061        3998 :                     n->havingClause = $8;
   13062        3998 :                     n->windowClause = $9;
   13063        3998 :                     $$ = (Node *) n;
   13064             :                 }
   13065       59100 :             | values_clause                         { $$ = $1; }
   13066             :             | TABLE relation_expr
   13067             :                 {
   13068             :                     /* same as SELECT * FROM relation_expr */
   13069         308 :                     ColumnRef  *cr = makeNode(ColumnRef);
   13070         308 :                     ResTarget  *rt = makeNode(ResTarget);
   13071         308 :                     SelectStmt *n = makeNode(SelectStmt);
   13072             : 
   13073         308 :                     cr->fields = list_make1(makeNode(A_Star));
   13074         308 :                     cr->location = -1;
   13075             : 
   13076         308 :                     rt->name = NULL;
   13077         308 :                     rt->indirection = NIL;
   13078         308 :                     rt->val = (Node *) cr;
   13079         308 :                     rt->location = -1;
   13080             : 
   13081         308 :                     n->targetList = list_make1(rt);
   13082         308 :                     n->fromClause = list_make1($2);
   13083         308 :                     $$ = (Node *) n;
   13084             :                 }
   13085             :             | select_clause UNION set_quantifier select_clause
   13086             :                 {
   13087       18948 :                     $$ = makeSetOp(SETOP_UNION, $3 == SET_QUANTIFIER_ALL, $1, $4);
   13088             :                 }
   13089             :             | select_clause INTERSECT set_quantifier select_clause
   13090             :                 {
   13091         276 :                     $$ = makeSetOp(SETOP_INTERSECT, $3 == SET_QUANTIFIER_ALL, $1, $4);
   13092             :                 }
   13093             :             | select_clause EXCEPT set_quantifier select_clause
   13094             :                 {
   13095         488 :                     $$ = makeSetOp(SETOP_EXCEPT, $3 == SET_QUANTIFIER_ALL, $1, $4);
   13096             :                 }
   13097             :         ;
   13098             : 
   13099             : /*
   13100             :  * SQL standard WITH clause looks like:
   13101             :  *
   13102             :  * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
   13103             :  *      AS (query) [ SEARCH or CYCLE clause ]
   13104             :  *
   13105             :  * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
   13106             :  */
   13107             : with_clause:
   13108             :         WITH cte_list
   13109             :             {
   13110        2080 :                 $$ = makeNode(WithClause);
   13111        2080 :                 $$->ctes = $2;
   13112        2080 :                 $$->recursive = false;
   13113        2080 :                 $$->location = @1;
   13114             :             }
   13115             :         | WITH_LA cte_list
   13116             :             {
   13117           6 :                 $$ = makeNode(WithClause);
   13118           6 :                 $$->ctes = $2;
   13119           6 :                 $$->recursive = false;
   13120           6 :                 $$->location = @1;
   13121             :             }
   13122             :         | WITH RECURSIVE cte_list
   13123             :             {
   13124        1246 :                 $$ = makeNode(WithClause);
   13125        1246 :                 $$->ctes = $3;
   13126        1246 :                 $$->recursive = true;
   13127        1246 :                 $$->location = @1;
   13128             :             }
   13129             :         ;
   13130             : 
   13131             : cte_list:
   13132        3332 :         common_table_expr                       { $$ = list_make1($1); }
   13133        1252 :         | cte_list ',' common_table_expr        { $$ = lappend($1, $3); }
   13134             :         ;
   13135             : 
   13136             : common_table_expr:  name opt_name_list AS opt_materialized '(' PreparableStmt ')' opt_search_clause opt_cycle_clause
   13137             :             {
   13138        4584 :                 CommonTableExpr *n = makeNode(CommonTableExpr);
   13139             : 
   13140        4584 :                 n->ctename = $1;
   13141        4584 :                 n->aliascolnames = $2;
   13142        4584 :                 n->ctematerialized = $4;
   13143        4584 :                 n->ctequery = $6;
   13144        4584 :                 n->search_clause = castNode(CTESearchClause, $8);
   13145        4584 :                 n->cycle_clause = castNode(CTECycleClause, $9);
   13146        4584 :                 n->location = @1;
   13147        4584 :                 $$ = (Node *) n;
   13148             :             }
   13149             :         ;
   13150             : 
   13151             : opt_materialized:
   13152         178 :         MATERIALIZED                            { $$ = CTEMaterializeAlways; }
   13153          48 :         | NOT MATERIALIZED                      { $$ = CTEMaterializeNever; }
   13154        4358 :         | /*EMPTY*/                             { $$ = CTEMaterializeDefault; }
   13155             :         ;
   13156             : 
   13157             : opt_search_clause:
   13158             :         SEARCH DEPTH FIRST_P BY columnList SET ColId
   13159             :             {
   13160          90 :                 CTESearchClause *n = makeNode(CTESearchClause);
   13161             : 
   13162          90 :                 n->search_col_list = $5;
   13163          90 :                 n->search_breadth_first = false;
   13164          90 :                 n->search_seq_column = $7;
   13165          90 :                 n->location = @1;
   13166          90 :                 $$ = (Node *) n;
   13167             :             }
   13168             :         | SEARCH BREADTH FIRST_P BY columnList SET ColId
   13169             :             {
   13170          36 :                 CTESearchClause *n = makeNode(CTESearchClause);
   13171             : 
   13172          36 :                 n->search_col_list = $5;
   13173          36 :                 n->search_breadth_first = true;
   13174          36 :                 n->search_seq_column = $7;
   13175          36 :                 n->location = @1;
   13176          36 :                 $$ = (Node *) n;
   13177             :             }
   13178             :         | /*EMPTY*/
   13179             :             {
   13180        4458 :                 $$ = NULL;
   13181             :             }
   13182             :         ;
   13183             : 
   13184             : opt_cycle_clause:
   13185             :         CYCLE columnList SET ColId TO AexprConst DEFAULT AexprConst USING ColId
   13186             :             {
   13187          66 :                 CTECycleClause *n = makeNode(CTECycleClause);
   13188             : 
   13189          66 :                 n->cycle_col_list = $2;
   13190          66 :                 n->cycle_mark_column = $4;
   13191          66 :                 n->cycle_mark_value = $6;
   13192          66 :                 n->cycle_mark_default = $8;
   13193          66 :                 n->cycle_path_column = $10;
   13194          66 :                 n->location = @1;
   13195          66 :                 $$ = (Node *) n;
   13196             :             }
   13197             :         | CYCLE columnList SET ColId USING ColId
   13198             :             {
   13199          60 :                 CTECycleClause *n = makeNode(CTECycleClause);
   13200             : 
   13201          60 :                 n->cycle_col_list = $2;
   13202          60 :                 n->cycle_mark_column = $4;
   13203          60 :                 n->cycle_mark_value = makeBoolAConst(true, -1);
   13204          60 :                 n->cycle_mark_default = makeBoolAConst(false, -1);
   13205          60 :                 n->cycle_path_column = $6;
   13206          60 :                 n->location = @1;
   13207          60 :                 $$ = (Node *) n;
   13208             :             }
   13209             :         | /*EMPTY*/
   13210             :             {
   13211        4458 :                 $$ = NULL;
   13212             :             }
   13213             :         ;
   13214             : 
   13215             : opt_with_clause:
   13216         450 :         with_clause                             { $$ = $1; }
   13217       89540 :         | /*EMPTY*/                             { $$ = NULL; }
   13218             :         ;
   13219             : 
   13220             : into_clause:
   13221             :             INTO OptTempTableName
   13222             :                 {
   13223         138 :                     $$ = makeNode(IntoClause);
   13224         138 :                     $$->rel = $2;
   13225         138 :                     $$->colNames = NIL;
   13226         138 :                     $$->options = NIL;
   13227         138 :                     $$->onCommit = ONCOMMIT_NOOP;
   13228         138 :                     $$->tableSpaceName = NULL;
   13229         138 :                     $$->viewQuery = NULL;
   13230         138 :                     $$->skipData = false;
   13231             :                 }
   13232             :             | /*EMPTY*/
   13233      433952 :                 { $$ = NULL; }
   13234             :         ;
   13235             : 
   13236             : /*
   13237             :  * Redundancy here is needed to avoid shift/reduce conflicts,
   13238             :  * since TEMP is not a reserved word.  See also OptTemp.
   13239             :  */
   13240             : OptTempTableName:
   13241             :             TEMPORARY opt_table qualified_name
   13242             :                 {
   13243           0 :                     $$ = $3;
   13244           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13245             :                 }
   13246             :             | TEMP opt_table qualified_name
   13247             :                 {
   13248           6 :                     $$ = $3;
   13249           6 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13250             :                 }
   13251             :             | LOCAL TEMPORARY opt_table qualified_name
   13252             :                 {
   13253           0 :                     $$ = $4;
   13254           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13255             :                 }
   13256             :             | LOCAL TEMP opt_table qualified_name
   13257             :                 {
   13258           0 :                     $$ = $4;
   13259           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13260             :                 }
   13261             :             | GLOBAL TEMPORARY opt_table qualified_name
   13262             :                 {
   13263           0 :                     ereport(WARNING,
   13264             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   13265             :                              parser_errposition(@1)));
   13266           0 :                     $$ = $4;
   13267           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13268             :                 }
   13269             :             | GLOBAL TEMP opt_table qualified_name
   13270             :                 {
   13271           0 :                     ereport(WARNING,
   13272             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   13273             :                              parser_errposition(@1)));
   13274           0 :                     $$ = $4;
   13275           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13276             :                 }
   13277             :             | UNLOGGED opt_table qualified_name
   13278             :                 {
   13279           0 :                     $$ = $3;
   13280           0 :                     $$->relpersistence = RELPERSISTENCE_UNLOGGED;
   13281             :                 }
   13282             :             | TABLE qualified_name
   13283             :                 {
   13284          30 :                     $$ = $2;
   13285          30 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   13286             :                 }
   13287             :             | qualified_name
   13288             :                 {
   13289         102 :                     $$ = $1;
   13290         102 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   13291             :                 }
   13292             :         ;
   13293             : 
   13294             : opt_table:  TABLE
   13295             :             | /*EMPTY*/
   13296             :         ;
   13297             : 
   13298             : set_quantifier:
   13299       11072 :             ALL                                     { $$ = SET_QUANTIFIER_ALL; }
   13300          32 :             | DISTINCT                              { $$ = SET_QUANTIFIER_DISTINCT; }
   13301       13526 :             | /*EMPTY*/                             { $$ = SET_QUANTIFIER_DEFAULT; }
   13302             :         ;
   13303             : 
   13304             : /* We use (NIL) as a placeholder to indicate that all target expressions
   13305             :  * should be placed in the DISTINCT list during parsetree analysis.
   13306             :  */
   13307             : distinct_clause:
   13308        3744 :             DISTINCT                                { $$ = list_make1(NIL); }
   13309         260 :             | DISTINCT ON '(' expr_list ')'         { $$ = $4; }
   13310             :         ;
   13311             : 
   13312             : opt_all_clause:
   13313             :             ALL
   13314             :             | /*EMPTY*/
   13315             :         ;
   13316             : 
   13317             : opt_distinct_clause:
   13318           0 :             distinct_clause                         { $$ = $1; }
   13319       40414 :             | opt_all_clause                        { $$ = NIL; }
   13320             :         ;
   13321             : 
   13322             : opt_sort_clause:
   13323        7502 :             sort_clause                             { $$ = $1; }
   13324      365212 :             | /*EMPTY*/                             { $$ = NIL; }
   13325             :         ;
   13326             : 
   13327             : sort_clause:
   13328       79246 :             ORDER BY sortby_list                    { $$ = $3; }
   13329             :         ;
   13330             : 
   13331             : sortby_list:
   13332       79264 :             sortby                                  { $$ = list_make1($1); }
   13333       28688 :             | sortby_list ',' sortby                { $$ = lappend($1, $3); }
   13334             :         ;
   13335             : 
   13336             : sortby:     a_expr USING qual_all_Op opt_nulls_order
   13337             :                 {
   13338         220 :                     $$ = makeNode(SortBy);
   13339         220 :                     $$->node = $1;
   13340         220 :                     $$->sortby_dir = SORTBY_USING;
   13341         220 :                     $$->sortby_nulls = $4;
   13342         220 :                     $$->useOp = $3;
   13343         220 :                     $$->location = @3;
   13344             :                 }
   13345             :             | a_expr opt_asc_desc opt_nulls_order
   13346             :                 {
   13347      107732 :                     $$ = makeNode(SortBy);
   13348      107732 :                     $$->node = $1;
   13349      107732 :                     $$->sortby_dir = $2;
   13350      107732 :                     $$->sortby_nulls = $3;
   13351      107732 :                     $$->useOp = NIL;
   13352      107732 :                     $$->location = -1;       /* no operator */
   13353             :                 }
   13354             :         ;
   13355             : 
   13356             : 
   13357             : select_limit:
   13358             :             limit_clause offset_clause
   13359             :                 {
   13360         172 :                     $$ = $1;
   13361         172 :                     ($$)->limitOffset = $2;
   13362         172 :                     ($$)->offsetLoc = @2;
   13363             :                 }
   13364             :             | offset_clause limit_clause
   13365             :                 {
   13366         222 :                     $$ = $2;
   13367         222 :                     ($$)->limitOffset = $1;
   13368         222 :                     ($$)->offsetLoc = @1;
   13369             :                 }
   13370             :             | limit_clause
   13371             :                 {
   13372        4306 :                     $$ = $1;
   13373             :                 }
   13374             :             | offset_clause
   13375             :                 {
   13376         466 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13377             : 
   13378         466 :                     n->limitOffset = $1;
   13379         466 :                     n->limitCount = NULL;
   13380         466 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13381         466 :                     n->offsetLoc = @1;
   13382         466 :                     n->countLoc = -1;
   13383         466 :                     n->optionLoc = -1;
   13384         466 :                     $$ = n;
   13385             :                 }
   13386             :         ;
   13387             : 
   13388             : opt_select_limit:
   13389         190 :             select_limit                        { $$ = $1; }
   13390       45150 :             | /* EMPTY */                       { $$ = NULL; }
   13391             :         ;
   13392             : 
   13393             : limit_clause:
   13394             :             LIMIT select_limit_value
   13395             :                 {
   13396        4604 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13397             : 
   13398        4604 :                     n->limitOffset = NULL;
   13399        4604 :                     n->limitCount = $2;
   13400        4604 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13401        4604 :                     n->offsetLoc = -1;
   13402        4604 :                     n->countLoc = @1;
   13403        4604 :                     n->optionLoc = -1;
   13404        4604 :                     $$ = n;
   13405             :                 }
   13406             :             | LIMIT select_limit_value ',' select_offset_value
   13407             :                 {
   13408             :                     /* Disabled because it was too confusing, bjm 2002-02-18 */
   13409           0 :                     ereport(ERROR,
   13410             :                             (errcode(ERRCODE_SYNTAX_ERROR),
   13411             :                              errmsg("LIMIT #,# syntax is not supported"),
   13412             :                              errhint("Use separate LIMIT and OFFSET clauses."),
   13413             :                              parser_errposition(@1)));
   13414             :                 }
   13415             :             /* SQL:2008 syntax */
   13416             :             /* to avoid shift/reduce conflicts, handle the optional value with
   13417             :              * a separate production rather than an opt_ expression.  The fact
   13418             :              * that ONLY is fully reserved means that this way, we defer any
   13419             :              * decision about what rule reduces ROW or ROWS to the point where
   13420             :              * we can see the ONLY token in the lookahead slot.
   13421             :              */
   13422             :             | FETCH first_or_next select_fetch_first_value row_or_rows ONLY
   13423             :                 {
   13424          24 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13425             : 
   13426          24 :                     n->limitOffset = NULL;
   13427          24 :                     n->limitCount = $3;
   13428          24 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13429          24 :                     n->offsetLoc = -1;
   13430          24 :                     n->countLoc = @1;
   13431          24 :                     n->optionLoc = -1;
   13432          24 :                     $$ = n;
   13433             :                 }
   13434             :             | FETCH first_or_next select_fetch_first_value row_or_rows WITH TIES
   13435             :                 {
   13436          66 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13437             : 
   13438          66 :                     n->limitOffset = NULL;
   13439          66 :                     n->limitCount = $3;
   13440          66 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13441          66 :                     n->offsetLoc = -1;
   13442          66 :                     n->countLoc = @1;
   13443          66 :                     n->optionLoc = @5;
   13444          66 :                     $$ = n;
   13445             :                 }
   13446             :             | FETCH first_or_next row_or_rows ONLY
   13447             :                 {
   13448           0 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13449             : 
   13450           0 :                     n->limitOffset = NULL;
   13451           0 :                     n->limitCount = makeIntConst(1, -1);
   13452           0 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13453           0 :                     n->offsetLoc = -1;
   13454           0 :                     n->countLoc = @1;
   13455           0 :                     n->optionLoc = -1;
   13456           0 :                     $$ = n;
   13457             :                 }
   13458             :             | FETCH first_or_next row_or_rows WITH TIES
   13459             :                 {
   13460           6 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13461             : 
   13462           6 :                     n->limitOffset = NULL;
   13463           6 :                     n->limitCount = makeIntConst(1, -1);
   13464           6 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13465           6 :                     n->offsetLoc = -1;
   13466           6 :                     n->countLoc = @1;
   13467           6 :                     n->optionLoc = @4;
   13468           6 :                     $$ = n;
   13469             :                 }
   13470             :         ;
   13471             : 
   13472             : offset_clause:
   13473             :             OFFSET select_offset_value
   13474         860 :                 { $$ = $2; }
   13475             :             /* SQL:2008 syntax */
   13476             :             | OFFSET select_fetch_first_value row_or_rows
   13477           0 :                 { $$ = $2; }
   13478             :         ;
   13479             : 
   13480             : select_limit_value:
   13481        4602 :             a_expr                                  { $$ = $1; }
   13482             :             | ALL
   13483             :                 {
   13484             :                     /* LIMIT ALL is represented as a NULL constant */
   13485           2 :                     $$ = makeNullAConst(@1);
   13486             :                 }
   13487             :         ;
   13488             : 
   13489             : select_offset_value:
   13490         860 :             a_expr                                  { $$ = $1; }
   13491             :         ;
   13492             : 
   13493             : /*
   13494             :  * Allowing full expressions without parentheses causes various parsing
   13495             :  * problems with the trailing ROW/ROWS key words.  SQL spec only calls for
   13496             :  * <simple value specification>, which is either a literal or a parameter (but
   13497             :  * an <SQL parameter reference> could be an identifier, bringing up conflicts
   13498             :  * with ROW/ROWS). We solve this by leveraging the presence of ONLY (see above)
   13499             :  * to determine whether the expression is missing rather than trying to make it
   13500             :  * optional in this rule.
   13501             :  *
   13502             :  * c_expr covers almost all the spec-required cases (and more), but it doesn't
   13503             :  * cover signed numeric literals, which are allowed by the spec. So we include
   13504             :  * those here explicitly. We need FCONST as well as ICONST because values that
   13505             :  * don't fit in the platform's "long", but do fit in bigint, should still be
   13506             :  * accepted here. (This is possible in 64-bit Windows as well as all 32-bit
   13507             :  * builds.)
   13508             :  */
   13509             : select_fetch_first_value:
   13510          90 :             c_expr                                  { $$ = $1; }
   13511             :             | '+' I_or_F_const
   13512           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   13513             :             | '-' I_or_F_const
   13514           0 :                 { $$ = doNegate($2, @1); }
   13515             :         ;
   13516             : 
   13517             : I_or_F_const:
   13518           0 :             Iconst                                  { $$ = makeIntConst($1,@1); }
   13519           0 :             | FCONST                                { $$ = makeFloatConst($1,@1); }
   13520             :         ;
   13521             : 
   13522             : /* noise words */
   13523          36 : row_or_rows: ROW                                    { $$ = 0; }
   13524          60 :             | ROWS                                  { $$ = 0; }
   13525             :         ;
   13526             : 
   13527          96 : first_or_next: FIRST_P                              { $$ = 0; }
   13528           0 :             | NEXT                                  { $$ = 0; }
   13529             :         ;
   13530             : 
   13531             : 
   13532             : /*
   13533             :  * This syntax for group_clause tries to follow the spec quite closely.
   13534             :  * However, the spec allows only column references, not expressions,
   13535             :  * which introduces an ambiguity between implicit row constructors
   13536             :  * (a,b) and lists of column references.
   13537             :  *
   13538             :  * We handle this by using the a_expr production for what the spec calls
   13539             :  * <ordinary grouping set>, which in the spec represents either one column
   13540             :  * reference or a parenthesized list of column references. Then, we check the
   13541             :  * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
   13542             :  * grab and use the list, discarding the node. (this is done in parse analysis,
   13543             :  * not here)
   13544             :  *
   13545             :  * (we abuse the row_format field of RowExpr to distinguish implicit and
   13546             :  * explicit row constructors; it's debatable if anyone sanely wants to use them
   13547             :  * in a group clause, but if they have a reason to, we make it possible.)
   13548             :  *
   13549             :  * Each item in the group_clause list is either an expression tree or a
   13550             :  * GroupingSet node of some type.
   13551             :  */
   13552             : group_clause:
   13553             :             GROUP_P BY set_quantifier group_by_list
   13554             :                 {
   13555        4906 :                     GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
   13556             : 
   13557        4906 :                     n->distinct = $3 == SET_QUANTIFIER_DISTINCT;
   13558        4906 :                     n->all = false;
   13559        4906 :                     n->list = $4;
   13560        4906 :                     $$ = n;
   13561             :                 }
   13562             :             | GROUP_P BY ALL
   13563             :                 {
   13564          66 :                     GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
   13565          66 :                     n->distinct = false;
   13566          66 :                     n->all = true;
   13567          66 :                     n->list = NIL;
   13568          66 :                     $$ = n;
   13569             :                 }
   13570             :             | /*EMPTY*/
   13571             :                 {
   13572      469502 :                     GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
   13573             : 
   13574      469502 :                     n->distinct = false;
   13575      469502 :                     n->all = false;
   13576      469502 :                     n->list = NIL;
   13577      469502 :                     $$ = n;
   13578             :                 }
   13579             :         ;
   13580             : 
   13581             : group_by_list:
   13582        5540 :             group_by_item                           { $$ = list_make1($1); }
   13583        3062 :             | group_by_list ',' group_by_item       { $$ = lappend($1,$3); }
   13584             :         ;
   13585             : 
   13586             : group_by_item:
   13587        7240 :             a_expr                                  { $$ = $1; }
   13588         246 :             | empty_grouping_set                    { $$ = $1; }
   13589         184 :             | cube_clause                           { $$ = $1; }
   13590         298 :             | rollup_clause                         { $$ = $1; }
   13591         634 :             | grouping_sets_clause                  { $$ = $1; }
   13592             :         ;
   13593             : 
   13594             : empty_grouping_set:
   13595             :             '(' ')'
   13596             :                 {
   13597         246 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, @1);
   13598             :                 }
   13599             :         ;
   13600             : 
   13601             : /*
   13602             :  * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
   13603             :  * so that they shift in these rules rather than reducing the conflicting
   13604             :  * unreserved_keyword rule.
   13605             :  */
   13606             : 
   13607             : rollup_clause:
   13608             :             ROLLUP '(' expr_list ')'
   13609             :                 {
   13610         298 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_ROLLUP, $3, @1);
   13611             :                 }
   13612             :         ;
   13613             : 
   13614             : cube_clause:
   13615             :             CUBE '(' expr_list ')'
   13616             :                 {
   13617         184 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_CUBE, $3, @1);
   13618             :                 }
   13619             :         ;
   13620             : 
   13621             : grouping_sets_clause:
   13622             :             GROUPING SETS '(' group_by_list ')'
   13623             :                 {
   13624         634 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_SETS, $4, @1);
   13625             :                 }
   13626             :         ;
   13627             : 
   13628             : having_clause:
   13629         780 :             HAVING a_expr                           { $$ = $2; }
   13630      473694 :             | /*EMPTY*/                             { $$ = NULL; }
   13631             :         ;
   13632             : 
   13633             : for_locking_clause:
   13634        5266 :             for_locking_items                       { $$ = $1; }
   13635           0 :             | FOR READ ONLY                         { $$ = NIL; }
   13636             :         ;
   13637             : 
   13638             : opt_for_locking_clause:
   13639         340 :             for_locking_clause                      { $$ = $1; }
   13640       45050 :             | /* EMPTY */                           { $$ = NIL; }
   13641             :         ;
   13642             : 
   13643             : for_locking_items:
   13644        5266 :             for_locking_item                        { $$ = list_make1($1); }
   13645         102 :             | for_locking_items for_locking_item    { $$ = lappend($1, $2); }
   13646             :         ;
   13647             : 
   13648             : for_locking_item:
   13649             :             for_locking_strength locked_rels_list opt_nowait_or_skip
   13650             :                 {
   13651        5368 :                     LockingClause *n = makeNode(LockingClause);
   13652             : 
   13653        5368 :                     n->lockedRels = $2;
   13654        5368 :                     n->strength = $1;
   13655        5368 :                     n->waitPolicy = $3;
   13656        5368 :                     $$ = (Node *) n;
   13657             :                 }
   13658             :         ;
   13659             : 
   13660             : for_locking_strength:
   13661        1538 :             FOR UPDATE                          { $$ = LCS_FORUPDATE; }
   13662          76 :             | FOR NO KEY UPDATE                 { $$ = LCS_FORNOKEYUPDATE; }
   13663         214 :             | FOR SHARE                         { $$ = LCS_FORSHARE; }
   13664        3540 :             | FOR KEY SHARE                     { $$ = LCS_FORKEYSHARE; }
   13665             :         ;
   13666             : 
   13667             : locked_rels_list:
   13668        3566 :             OF qualified_name_list                  { $$ = $2; }
   13669        1802 :             | /* EMPTY */                           { $$ = NIL; }
   13670             :         ;
   13671             : 
   13672             : 
   13673             : /*
   13674             :  * We should allow ROW '(' expr_list ')' too, but that seems to require
   13675             :  * making VALUES a fully reserved word, which will probably break more apps
   13676             :  * than allowing the noise-word is worth.
   13677             :  */
   13678             : values_clause:
   13679             :             VALUES '(' expr_list ')'
   13680             :                 {
   13681       59100 :                     SelectStmt *n = makeNode(SelectStmt);
   13682             : 
   13683       59100 :                     n->valuesLists = list_make1($3);
   13684       59100 :                     $$ = (Node *) n;
   13685             :                 }
   13686             :             | values_clause ',' '(' expr_list ')'
   13687             :                 {
   13688       25212 :                     SelectStmt *n = (SelectStmt *) $1;
   13689             : 
   13690       25212 :                     n->valuesLists = lappend(n->valuesLists, $4);
   13691       25212 :                     $$ = (Node *) n;
   13692             :                 }
   13693             :         ;
   13694             : 
   13695             : 
   13696             : /*****************************************************************************
   13697             :  *
   13698             :  *  clauses common to all Optimizable Stmts:
   13699             :  *      from_clause     - allow list of both JOIN expressions and table names
   13700             :  *      where_clause    - qualifications for joins or restrictions
   13701             :  *
   13702             :  *****************************************************************************/
   13703             : 
   13704             : from_clause:
   13705      314894 :             FROM from_list                          { $$ = $2; }
   13706      173894 :             | /*EMPTY*/                             { $$ = NIL; }
   13707             :         ;
   13708             : 
   13709             : from_list:
   13710      315750 :             table_ref                               { $$ = list_make1($1); }
   13711       61350 :             | from_list ',' table_ref               { $$ = lappend($1, $3); }
   13712             :         ;
   13713             : 
   13714             : /*
   13715             :  * table_ref is where an alias clause can be attached.
   13716             :  */
   13717             : table_ref:  relation_expr opt_alias_clause
   13718             :                 {
   13719      397922 :                     $1->alias = $2;
   13720      397922 :                     $$ = (Node *) $1;
   13721             :                 }
   13722             :             | relation_expr opt_alias_clause tablesample_clause
   13723             :                 {
   13724         266 :                     RangeTableSample *n = (RangeTableSample *) $3;
   13725             : 
   13726         266 :                     $1->alias = $2;
   13727             :                     /* relation_expr goes inside the RangeTableSample node */
   13728         266 :                     n->relation = (Node *) $1;
   13729         266 :                     $$ = (Node *) n;
   13730             :                 }
   13731             :             | func_table func_alias_clause
   13732             :                 {
   13733       46568 :                     RangeFunction *n = (RangeFunction *) $1;
   13734             : 
   13735       46568 :                     n->alias = linitial($2);
   13736       46568 :                     n->coldeflist = lsecond($2);
   13737       46568 :                     $$ = (Node *) n;
   13738             :                 }
   13739             :             | LATERAL_P func_table func_alias_clause
   13740             :                 {
   13741        1282 :                     RangeFunction *n = (RangeFunction *) $2;
   13742             : 
   13743        1282 :                     n->lateral = true;
   13744        1282 :                     n->alias = linitial($3);
   13745        1282 :                     n->coldeflist = lsecond($3);
   13746        1282 :                     $$ = (Node *) n;
   13747             :                 }
   13748             :             | xmltable opt_alias_clause
   13749             :                 {
   13750          86 :                     RangeTableFunc *n = (RangeTableFunc *) $1;
   13751             : 
   13752          86 :                     n->alias = $2;
   13753          86 :                     $$ = (Node *) n;
   13754             :                 }
   13755             :             | LATERAL_P xmltable opt_alias_clause
   13756             :                 {
   13757         140 :                     RangeTableFunc *n = (RangeTableFunc *) $2;
   13758             : 
   13759         140 :                     n->lateral = true;
   13760         140 :                     n->alias = $3;
   13761         140 :                     $$ = (Node *) n;
   13762             :                 }
   13763             :             | select_with_parens opt_alias_clause
   13764             :                 {
   13765       14170 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13766             : 
   13767       14170 :                     n->lateral = false;
   13768       14170 :                     n->subquery = $1;
   13769       14170 :                     n->alias = $2;
   13770       14170 :                     $$ = (Node *) n;
   13771             :                 }
   13772             :             | LATERAL_P select_with_parens opt_alias_clause
   13773             :                 {
   13774        1900 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13775             : 
   13776        1900 :                     n->lateral = true;
   13777        1900 :                     n->subquery = $2;
   13778        1900 :                     n->alias = $3;
   13779        1900 :                     $$ = (Node *) n;
   13780             :                 }
   13781             :             | joined_table
   13782             :                 {
   13783       83430 :                     $$ = (Node *) $1;
   13784             :                 }
   13785             :             | '(' joined_table ')' alias_clause
   13786             :                 {
   13787         174 :                     $2->alias = $4;
   13788         174 :                     $$ = (Node *) $2;
   13789             :                 }
   13790             :             | json_table opt_alias_clause
   13791             :                 {
   13792         530 :                     JsonTable  *jt = castNode(JsonTable, $1);
   13793             : 
   13794         530 :                     jt->alias = $2;
   13795         530 :                     $$ = (Node *) jt;
   13796             :                 }
   13797             :             | LATERAL_P json_table opt_alias_clause
   13798             :                 {
   13799           0 :                     JsonTable  *jt = castNode(JsonTable, $2);
   13800             : 
   13801           0 :                     jt->alias = $3;
   13802           0 :                     jt->lateral = true;
   13803           0 :                     $$ = (Node *) jt;
   13804             :                 }
   13805             :         ;
   13806             : 
   13807             : 
   13808             : /*
   13809             :  * It may seem silly to separate joined_table from table_ref, but there is
   13810             :  * method in SQL's madness: if you don't do it this way you get reduce-
   13811             :  * reduce conflicts, because it's not clear to the parser generator whether
   13812             :  * to expect alias_clause after ')' or not.  For the same reason we must
   13813             :  * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
   13814             :  * join_type to expand to empty; if we try it, the parser generator can't
   13815             :  * figure out when to reduce an empty join_type right after table_ref.
   13816             :  *
   13817             :  * Note that a CROSS JOIN is the same as an unqualified
   13818             :  * INNER JOIN, and an INNER JOIN/ON has the same shape
   13819             :  * but a qualification expression to limit membership.
   13820             :  * A NATURAL JOIN implicitly matches column names between
   13821             :  * tables and the shape is determined by which columns are
   13822             :  * in common. We'll collect columns during the later transformations.
   13823             :  */
   13824             : 
   13825             : joined_table:
   13826             :             '(' joined_table ')'
   13827             :                 {
   13828        3966 :                     $$ = $2;
   13829             :                 }
   13830             :             | table_ref CROSS JOIN table_ref
   13831             :                 {
   13832             :                     /* CROSS JOIN is same as unqualified inner join */
   13833         508 :                     JoinExpr   *n = makeNode(JoinExpr);
   13834             : 
   13835         508 :                     n->jointype = JOIN_INNER;
   13836         508 :                     n->isNatural = false;
   13837         508 :                     n->larg = $1;
   13838         508 :                     n->rarg = $4;
   13839         508 :                     n->usingClause = NIL;
   13840         508 :                     n->join_using_alias = NULL;
   13841         508 :                     n->quals = NULL;
   13842         508 :                     $$ = n;
   13843             :                 }
   13844             :             | table_ref join_type JOIN table_ref join_qual
   13845             :                 {
   13846       47130 :                     JoinExpr   *n = makeNode(JoinExpr);
   13847             : 
   13848       47130 :                     n->jointype = $2;
   13849       47130 :                     n->isNatural = false;
   13850       47130 :                     n->larg = $1;
   13851       47130 :                     n->rarg = $4;
   13852       47130 :                     if ($5 != NULL && IsA($5, List))
   13853             :                     {
   13854             :                          /* USING clause */
   13855         498 :                         n->usingClause = linitial_node(List, castNode(List, $5));
   13856         498 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $5));
   13857             :                     }
   13858             :                     else
   13859             :                     {
   13860             :                         /* ON clause */
   13861       46632 :                         n->quals = $5;
   13862             :                     }
   13863       47130 :                     $$ = n;
   13864             :                 }
   13865             :             | table_ref JOIN table_ref join_qual
   13866             :                 {
   13867             :                     /* letting join_type reduce to empty doesn't work */
   13868       35702 :                     JoinExpr   *n = makeNode(JoinExpr);
   13869             : 
   13870       35702 :                     n->jointype = JOIN_INNER;
   13871       35702 :                     n->isNatural = false;
   13872       35702 :                     n->larg = $1;
   13873       35702 :                     n->rarg = $3;
   13874       35702 :                     if ($4 != NULL && IsA($4, List))
   13875             :                     {
   13876             :                         /* USING clause */
   13877         744 :                         n->usingClause = linitial_node(List, castNode(List, $4));
   13878         744 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $4));
   13879             :                     }
   13880             :                     else
   13881             :                     {
   13882             :                         /* ON clause */
   13883       34958 :                         n->quals = $4;
   13884             :                     }
   13885       35702 :                     $$ = n;
   13886             :                 }
   13887             :             | table_ref NATURAL join_type JOIN table_ref
   13888             :                 {
   13889          78 :                     JoinExpr   *n = makeNode(JoinExpr);
   13890             : 
   13891          78 :                     n->jointype = $3;
   13892          78 :                     n->isNatural = true;
   13893          78 :                     n->larg = $1;
   13894          78 :                     n->rarg = $5;
   13895          78 :                     n->usingClause = NIL; /* figure out which columns later... */
   13896          78 :                     n->join_using_alias = NULL;
   13897          78 :                     n->quals = NULL; /* fill later */
   13898          78 :                     $$ = n;
   13899             :                 }
   13900             :             | table_ref NATURAL JOIN table_ref
   13901             :                 {
   13902             :                     /* letting join_type reduce to empty doesn't work */
   13903         186 :                     JoinExpr   *n = makeNode(JoinExpr);
   13904             : 
   13905         186 :                     n->jointype = JOIN_INNER;
   13906         186 :                     n->isNatural = true;
   13907         186 :                     n->larg = $1;
   13908         186 :                     n->rarg = $4;
   13909         186 :                     n->usingClause = NIL; /* figure out which columns later... */
   13910         186 :                     n->join_using_alias = NULL;
   13911         186 :                     n->quals = NULL; /* fill later */
   13912         186 :                     $$ = n;
   13913             :                 }
   13914             :         ;
   13915             : 
   13916             : alias_clause:
   13917             :             AS ColId '(' name_list ')'
   13918             :                 {
   13919        6658 :                     $$ = makeNode(Alias);
   13920        6658 :                     $$->aliasname = $2;
   13921        6658 :                     $$->colnames = $4;
   13922             :                 }
   13923             :             | AS ColId
   13924             :                 {
   13925       10892 :                     $$ = makeNode(Alias);
   13926       10892 :                     $$->aliasname = $2;
   13927             :                 }
   13928             :             | ColId '(' name_list ')'
   13929             :                 {
   13930        5870 :                     $$ = makeNode(Alias);
   13931        5870 :                     $$->aliasname = $1;
   13932        5870 :                     $$->colnames = $3;
   13933             :                 }
   13934             :             | ColId
   13935             :                 {
   13936      263830 :                     $$ = makeNode(Alias);
   13937      263830 :                     $$->aliasname = $1;
   13938             :                 }
   13939             :         ;
   13940             : 
   13941      258238 : opt_alias_clause: alias_clause                      { $$ = $1; }
   13942      156776 :             | /*EMPTY*/                             { $$ = NULL; }
   13943             :         ;
   13944             : 
   13945             : /*
   13946             :  * The alias clause after JOIN ... USING only accepts the AS ColId spelling,
   13947             :  * per SQL standard.  (The grammar could parse the other variants, but they
   13948             :  * don't seem to be useful, and it might lead to parser problems in the
   13949             :  * future.)
   13950             :  */
   13951             : opt_alias_clause_for_join_using:
   13952             :             AS ColId
   13953             :                 {
   13954          84 :                     $$ = makeNode(Alias);
   13955          84 :                     $$->aliasname = $2;
   13956             :                     /* the column name list will be inserted later */
   13957             :                 }
   13958        1158 :             | /*EMPTY*/                             { $$ = NULL; }
   13959             :         ;
   13960             : 
   13961             : /*
   13962             :  * func_alias_clause can include both an Alias and a coldeflist, so we make it
   13963             :  * return a 2-element list that gets disassembled by calling production.
   13964             :  */
   13965             : func_alias_clause:
   13966             :             alias_clause
   13967             :                 {
   13968       28838 :                     $$ = list_make2($1, NIL);
   13969             :                 }
   13970             :             | AS '(' TableFuncElementList ')'
   13971             :                 {
   13972         114 :                     $$ = list_make2(NULL, $3);
   13973             :                 }
   13974             :             | AS ColId '(' TableFuncElementList ')'
   13975             :                 {
   13976         596 :                     Alias      *a = makeNode(Alias);
   13977             : 
   13978         596 :                     a->aliasname = $2;
   13979         596 :                     $$ = list_make2(a, $4);
   13980             :                 }
   13981             :             | ColId '(' TableFuncElementList ')'
   13982             :                 {
   13983          50 :                     Alias      *a = makeNode(Alias);
   13984             : 
   13985          50 :                     a->aliasname = $1;
   13986          50 :                     $$ = list_make2(a, $3);
   13987             :                 }
   13988             :             | /*EMPTY*/
   13989             :                 {
   13990       18252 :                     $$ = list_make2(NULL, NIL);
   13991             :                 }
   13992             :         ;
   13993             : 
   13994        1042 : join_type:  FULL opt_outer                          { $$ = JOIN_FULL; }
   13995       41774 :             | LEFT opt_outer                        { $$ = JOIN_LEFT; }
   13996         390 :             | RIGHT opt_outer                       { $$ = JOIN_RIGHT; }
   13997        4002 :             | INNER_P                               { $$ = JOIN_INNER; }
   13998             :         ;
   13999             : 
   14000             : /* OUTER is just noise... */
   14001             : opt_outer: OUTER_P
   14002             :             | /*EMPTY*/
   14003             :         ;
   14004             : 
   14005             : /* JOIN qualification clauses
   14006             :  * Possibilities are:
   14007             :  *  USING ( column list ) [ AS alias ]
   14008             :  *                        allows only unqualified column names,
   14009             :  *                        which must match between tables.
   14010             :  *  ON expr allows more general qualifications.
   14011             :  *
   14012             :  * We return USING as a two-element List (the first item being a sub-List
   14013             :  * of the common column names, and the second either an Alias item or NULL).
   14014             :  * An ON-expr will not be a List, so it can be told apart that way.
   14015             :  */
   14016             : 
   14017             : join_qual: USING '(' name_list ')' opt_alias_clause_for_join_using
   14018             :                 {
   14019        1242 :                     $$ = (Node *) list_make2($3, $5);
   14020             :                 }
   14021             :             | ON a_expr
   14022             :                 {
   14023       81590 :                     $$ = $2;
   14024             :                 }
   14025             :         ;
   14026             : 
   14027             : 
   14028             : relation_expr:
   14029             :             qualified_name
   14030             :                 {
   14031             :                     /* inheritance query, implicitly */
   14032      478718 :                     $$ = $1;
   14033      478718 :                     $$->inh = true;
   14034      478718 :                     $$->alias = NULL;
   14035             :                 }
   14036             :             | extended_relation_expr
   14037             :                 {
   14038        7296 :                     $$ = $1;
   14039             :                 }
   14040             :         ;
   14041             : 
   14042             : extended_relation_expr:
   14043             :             qualified_name '*'
   14044             :                 {
   14045             :                     /* inheritance query, explicitly */
   14046         204 :                     $$ = $1;
   14047         204 :                     $$->inh = true;
   14048         204 :                     $$->alias = NULL;
   14049             :                 }
   14050             :             | ONLY qualified_name
   14051             :                 {
   14052             :                     /* no inheritance */
   14053        7098 :                     $$ = $2;
   14054        7098 :                     $$->inh = false;
   14055        7098 :                     $$->alias = NULL;
   14056             :                 }
   14057             :             | ONLY '(' qualified_name ')'
   14058             :                 {
   14059             :                     /* no inheritance, SQL99-style syntax */
   14060           0 :                     $$ = $3;
   14061           0 :                     $$->inh = false;
   14062           0 :                     $$->alias = NULL;
   14063             :                 }
   14064             :         ;
   14065             : 
   14066             : 
   14067             : relation_expr_list:
   14068        2826 :             relation_expr                           { $$ = list_make1($1); }
   14069       11198 :             | relation_expr_list ',' relation_expr  { $$ = lappend($1, $3); }
   14070             :         ;
   14071             : 
   14072             : 
   14073             : /*
   14074             :  * Given "UPDATE foo set set ...", we have to decide without looking any
   14075             :  * further ahead whether the first "set" is an alias or the UPDATE's SET
   14076             :  * keyword.  Since "set" is allowed as a column name both interpretations
   14077             :  * are feasible.  We resolve the shift/reduce conflict by giving the first
   14078             :  * relation_expr_opt_alias production a higher precedence than the SET token
   14079             :  * has, causing the parser to prefer to reduce, in effect assuming that the
   14080             :  * SET is not an alias.
   14081             :  */
   14082             : relation_expr_opt_alias: relation_expr                  %prec UMINUS
   14083             :                 {
   14084       18828 :                     $$ = $1;
   14085             :                 }
   14086             :             | relation_expr ColId
   14087             :                 {
   14088        2250 :                     Alias      *alias = makeNode(Alias);
   14089             : 
   14090        2250 :                     alias->aliasname = $2;
   14091        2250 :                     $1->alias = alias;
   14092        2250 :                     $$ = $1;
   14093             :                 }
   14094             :             | relation_expr AS ColId
   14095             :                 {
   14096          90 :                     Alias      *alias = makeNode(Alias);
   14097             : 
   14098          90 :                     alias->aliasname = $3;
   14099          90 :                     $1->alias = alias;
   14100          90 :                     $$ = $1;
   14101             :                 }
   14102             :         ;
   14103             : 
   14104             : /*
   14105             :  * TABLESAMPLE decoration in a FROM item
   14106             :  */
   14107             : tablesample_clause:
   14108             :             TABLESAMPLE func_name '(' expr_list ')' opt_repeatable_clause
   14109             :                 {
   14110         266 :                     RangeTableSample *n = makeNode(RangeTableSample);
   14111             : 
   14112             :                     /* n->relation will be filled in later */
   14113         266 :                     n->method = $2;
   14114         266 :                     n->args = $4;
   14115         266 :                     n->repeatable = $6;
   14116         266 :                     n->location = @2;
   14117         266 :                     $$ = (Node *) n;
   14118             :                 }
   14119             :         ;
   14120             : 
   14121             : opt_repeatable_clause:
   14122         108 :             REPEATABLE '(' a_expr ')'   { $$ = (Node *) $3; }
   14123         158 :             | /*EMPTY*/                 { $$ = NULL; }
   14124             :         ;
   14125             : 
   14126             : /*
   14127             :  * func_table represents a function invocation in a FROM list. It can be
   14128             :  * a plain function call, like "foo(...)", or a ROWS FROM expression with
   14129             :  * one or more function calls, "ROWS FROM (foo(...), bar(...))",
   14130             :  * optionally with WITH ORDINALITY attached.
   14131             :  * In the ROWS FROM syntax, a column definition list can be given for each
   14132             :  * function, for example:
   14133             :  *     ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
   14134             :  *                bar() AS (bar_res_a text, bar_res_b text))
   14135             :  * It's also possible to attach a column definition list to the RangeFunction
   14136             :  * as a whole, but that's handled by the table_ref production.
   14137             :  */
   14138             : func_table: func_expr_windowless opt_ordinality
   14139             :                 {
   14140       47724 :                     RangeFunction *n = makeNode(RangeFunction);
   14141             : 
   14142       47724 :                     n->lateral = false;
   14143       47724 :                     n->ordinality = $2;
   14144       47724 :                     n->is_rowsfrom = false;
   14145       47724 :                     n->functions = list_make1(list_make2($1, NIL));
   14146             :                     /* alias and coldeflist are set by table_ref production */
   14147       47724 :                     $$ = (Node *) n;
   14148             :                 }
   14149             :             | ROWS FROM '(' rowsfrom_list ')' opt_ordinality
   14150             :                 {
   14151         132 :                     RangeFunction *n = makeNode(RangeFunction);
   14152             : 
   14153         132 :                     n->lateral = false;
   14154         132 :                     n->ordinality = $6;
   14155         132 :                     n->is_rowsfrom = true;
   14156         132 :                     n->functions = $4;
   14157             :                     /* alias and coldeflist are set by table_ref production */
   14158         132 :                     $$ = (Node *) n;
   14159             :                 }
   14160             :         ;
   14161             : 
   14162             : rowsfrom_item: func_expr_windowless opt_col_def_list
   14163         318 :                 { $$ = list_make2($1, $2); }
   14164             :         ;
   14165             : 
   14166             : rowsfrom_list:
   14167         132 :             rowsfrom_item                       { $$ = list_make1($1); }
   14168         186 :             | rowsfrom_list ',' rowsfrom_item   { $$ = lappend($1, $3); }
   14169             :         ;
   14170             : 
   14171          54 : opt_col_def_list: AS '(' TableFuncElementList ')'   { $$ = $3; }
   14172         264 :             | /*EMPTY*/                             { $$ = NIL; }
   14173             :         ;
   14174             : 
   14175         922 : opt_ordinality: WITH_LA ORDINALITY                  { $$ = true; }
   14176       46934 :             | /*EMPTY*/                             { $$ = false; }
   14177             :         ;
   14178             : 
   14179             : 
   14180             : where_clause:
   14181      211806 :             WHERE a_expr                            { $$ = $2; }
   14182      283874 :             | /*EMPTY*/                             { $$ = NULL; }
   14183             :         ;
   14184             : 
   14185             : /* variant for UPDATE and DELETE */
   14186             : where_or_current_clause:
   14187       13660 :             WHERE a_expr                            { $$ = $2; }
   14188             :             | WHERE CURRENT_P OF cursor_name
   14189             :                 {
   14190         266 :                     CurrentOfExpr *n = makeNode(CurrentOfExpr);
   14191             : 
   14192             :                     /* cvarno is filled in by parse analysis */
   14193         266 :                     n->cursor_name = $4;
   14194         266 :                     n->cursor_param = 0;
   14195         266 :                     $$ = (Node *) n;
   14196             :                 }
   14197        5070 :             | /*EMPTY*/                             { $$ = NULL; }
   14198             :         ;
   14199             : 
   14200             : 
   14201             : OptTableFuncElementList:
   14202         716 :             TableFuncElementList                { $$ = $1; }
   14203        3786 :             | /*EMPTY*/                         { $$ = NIL; }
   14204             :         ;
   14205             : 
   14206             : TableFuncElementList:
   14207             :             TableFuncElement
   14208             :                 {
   14209        1530 :                     $$ = list_make1($1);
   14210             :                 }
   14211             :             | TableFuncElementList ',' TableFuncElement
   14212             :                 {
   14213        2058 :                     $$ = lappend($1, $3);
   14214             :                 }
   14215             :         ;
   14216             : 
   14217             : TableFuncElement:   ColId Typename opt_collate_clause
   14218             :                 {
   14219        3652 :                     ColumnDef *n = makeNode(ColumnDef);
   14220             : 
   14221        3652 :                     n->colname = $1;
   14222        3652 :                     n->typeName = $2;
   14223        3652 :                     n->inhcount = 0;
   14224        3652 :                     n->is_local = true;
   14225        3652 :                     n->is_not_null = false;
   14226        3652 :                     n->is_from_type = false;
   14227        3652 :                     n->storage = 0;
   14228        3652 :                     n->raw_default = NULL;
   14229        3652 :                     n->cooked_default = NULL;
   14230        3652 :                     n->collClause = (CollateClause *) $3;
   14231        3652 :                     n->collOid = InvalidOid;
   14232        3652 :                     n->constraints = NIL;
   14233        3652 :                     n->location = @1;
   14234        3652 :                     $$ = (Node *) n;
   14235             :                 }
   14236             :         ;
   14237             : 
   14238             : /*
   14239             :  * XMLTABLE
   14240             :  */
   14241             : xmltable:
   14242             :             XMLTABLE '(' c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   14243             :                 {
   14244         206 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   14245             : 
   14246         206 :                     n->rowexpr = $3;
   14247         206 :                     n->docexpr = $4;
   14248         206 :                     n->columns = $6;
   14249         206 :                     n->namespaces = NIL;
   14250         206 :                     n->location = @1;
   14251         206 :                     $$ = (Node *) n;
   14252             :                 }
   14253             :             | XMLTABLE '(' XMLNAMESPACES '(' xml_namespace_list ')' ','
   14254             :                 c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   14255             :                 {
   14256          20 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   14257             : 
   14258          20 :                     n->rowexpr = $8;
   14259          20 :                     n->docexpr = $9;
   14260          20 :                     n->columns = $11;
   14261          20 :                     n->namespaces = $5;
   14262          20 :                     n->location = @1;
   14263          20 :                     $$ = (Node *) n;
   14264             :                 }
   14265             :         ;
   14266             : 
   14267         226 : xmltable_column_list: xmltable_column_el                    { $$ = list_make1($1); }
   14268         530 :             | xmltable_column_list ',' xmltable_column_el   { $$ = lappend($1, $3); }
   14269             :         ;
   14270             : 
   14271             : xmltable_column_el:
   14272             :             ColId Typename
   14273             :                 {
   14274         204 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14275             : 
   14276         204 :                     fc->colname = $1;
   14277         204 :                     fc->for_ordinality = false;
   14278         204 :                     fc->typeName = $2;
   14279         204 :                     fc->is_not_null = false;
   14280         204 :                     fc->colexpr = NULL;
   14281         204 :                     fc->coldefexpr = NULL;
   14282         204 :                     fc->location = @1;
   14283             : 
   14284         204 :                     $$ = (Node *) fc;
   14285             :                 }
   14286             :             | ColId Typename xmltable_column_option_list
   14287             :                 {
   14288         490 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14289             :                     ListCell   *option;
   14290         490 :                     bool        nullability_seen = false;
   14291             : 
   14292         490 :                     fc->colname = $1;
   14293         490 :                     fc->typeName = $2;
   14294         490 :                     fc->for_ordinality = false;
   14295         490 :                     fc->is_not_null = false;
   14296         490 :                     fc->colexpr = NULL;
   14297         490 :                     fc->coldefexpr = NULL;
   14298         490 :                     fc->location = @1;
   14299             : 
   14300        1092 :                     foreach(option, $3)
   14301             :                     {
   14302         602 :                         DefElem   *defel = (DefElem *) lfirst(option);
   14303             : 
   14304         602 :                         if (strcmp(defel->defname, "default") == 0)
   14305             :                         {
   14306          56 :                             if (fc->coldefexpr != NULL)
   14307           0 :                                 ereport(ERROR,
   14308             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14309             :                                          errmsg("only one DEFAULT value is allowed"),
   14310             :                                          parser_errposition(defel->location)));
   14311          56 :                             fc->coldefexpr = defel->arg;
   14312             :                         }
   14313         546 :                         else if (strcmp(defel->defname, "path") == 0)
   14314             :                         {
   14315         490 :                             if (fc->colexpr != NULL)
   14316           0 :                                 ereport(ERROR,
   14317             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14318             :                                          errmsg("only one PATH value per column is allowed"),
   14319             :                                          parser_errposition(defel->location)));
   14320         490 :                             fc->colexpr = defel->arg;
   14321             :                         }
   14322          56 :                         else if (strcmp(defel->defname, "__pg__is_not_null") == 0)
   14323             :                         {
   14324          56 :                             if (nullability_seen)
   14325           0 :                                 ereport(ERROR,
   14326             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14327             :                                          errmsg("conflicting or redundant NULL / NOT NULL declarations for column \"%s\"", fc->colname),
   14328             :                                          parser_errposition(defel->location)));
   14329          56 :                             fc->is_not_null = boolVal(defel->arg);
   14330          56 :                             nullability_seen = true;
   14331             :                         }
   14332             :                         else
   14333             :                         {
   14334           0 :                             ereport(ERROR,
   14335             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   14336             :                                      errmsg("unrecognized column option \"%s\"",
   14337             :                                             defel->defname),
   14338             :                                      parser_errposition(defel->location)));
   14339             :                         }
   14340             :                     }
   14341         490 :                     $$ = (Node *) fc;
   14342             :                 }
   14343             :             | ColId FOR ORDINALITY
   14344             :                 {
   14345          62 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14346             : 
   14347          62 :                     fc->colname = $1;
   14348          62 :                     fc->for_ordinality = true;
   14349             :                     /* other fields are ignored, initialized by makeNode */
   14350          62 :                     fc->location = @1;
   14351             : 
   14352          62 :                     $$ = (Node *) fc;
   14353             :                 }
   14354             :         ;
   14355             : 
   14356             : xmltable_column_option_list:
   14357             :             xmltable_column_option_el
   14358         490 :                 { $$ = list_make1($1); }
   14359             :             | xmltable_column_option_list xmltable_column_option_el
   14360         112 :                 { $$ = lappend($1, $2); }
   14361             :         ;
   14362             : 
   14363             : xmltable_column_option_el:
   14364             :             IDENT b_expr
   14365             :                 {
   14366           6 :                     if (strcmp($1, "__pg__is_not_null") == 0)
   14367           6 :                         ereport(ERROR,
   14368             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   14369             :                                  errmsg("option name \"%s\" cannot be used in XMLTABLE", $1),
   14370             :                                  parser_errposition(@1)));
   14371           0 :                     $$ = makeDefElem($1, $2, @1);
   14372             :                 }
   14373             :             | DEFAULT b_expr
   14374          56 :                 { $$ = makeDefElem("default", $2, @1); }
   14375             :             | NOT NULL_P
   14376          56 :                 { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(true), @1); }
   14377             :             | NULL_P
   14378           0 :                 { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(false), @1); }
   14379             :             | PATH b_expr
   14380         490 :                 { $$ = makeDefElem("path", $2, @1); }
   14381             :         ;
   14382             : 
   14383             : xml_namespace_list:
   14384             :             xml_namespace_el
   14385          20 :                 { $$ = list_make1($1); }
   14386             :             | xml_namespace_list ',' xml_namespace_el
   14387           0 :                 { $$ = lappend($1, $3); }
   14388             :         ;
   14389             : 
   14390             : xml_namespace_el:
   14391             :             b_expr AS ColLabel
   14392             :                 {
   14393          14 :                     $$ = makeNode(ResTarget);
   14394          14 :                     $$->name = $3;
   14395          14 :                     $$->indirection = NIL;
   14396          14 :                     $$->val = $1;
   14397          14 :                     $$->location = @1;
   14398             :                 }
   14399             :             | DEFAULT b_expr
   14400             :                 {
   14401           6 :                     $$ = makeNode(ResTarget);
   14402           6 :                     $$->name = NULL;
   14403           6 :                     $$->indirection = NIL;
   14404           6 :                     $$->val = $2;
   14405           6 :                     $$->location = @1;
   14406             :                 }
   14407             :         ;
   14408             : 
   14409             : json_table:
   14410             :             JSON_TABLE '('
   14411             :                 json_value_expr ',' a_expr json_table_path_name_opt
   14412             :                 json_passing_clause_opt
   14413             :                 COLUMNS '(' json_table_column_definition_list ')'
   14414             :                 json_on_error_clause_opt
   14415             :             ')'
   14416             :                 {
   14417         536 :                     JsonTable *n = makeNode(JsonTable);
   14418             :                     char      *pathstring;
   14419             : 
   14420         536 :                     n->context_item = (JsonValueExpr *) $3;
   14421         536 :                     if (!IsA($5, A_Const) ||
   14422         530 :                         castNode(A_Const, $5)->val.node.type != T_String)
   14423           6 :                         ereport(ERROR,
   14424             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   14425             :                                 errmsg("only string constants are supported in JSON_TABLE path specification"),
   14426             :                                 parser_errposition(@5));
   14427         530 :                     pathstring = castNode(A_Const, $5)->val.sval.sval;
   14428         530 :                     n->pathspec = makeJsonTablePathSpec(pathstring, $6, @5, @6);
   14429         530 :                     n->passing = $7;
   14430         530 :                     n->columns = $10;
   14431         530 :                     n->on_error = (JsonBehavior *) $12;
   14432         530 :                     n->location = @1;
   14433         530 :                     $$ = (Node *) n;
   14434             :                 }
   14435             :         ;
   14436             : 
   14437             : json_table_path_name_opt:
   14438          62 :             AS name         { $$ = $2; }
   14439         486 :             | /* empty */   { $$ = NULL; }
   14440             :         ;
   14441             : 
   14442             : json_table_column_definition_list:
   14443             :             json_table_column_definition
   14444         826 :                 { $$ = list_make1($1); }
   14445             :             | json_table_column_definition_list ',' json_table_column_definition
   14446         528 :                 { $$ = lappend($1, $3); }
   14447             :         ;
   14448             : 
   14449             : json_table_column_definition:
   14450             :             ColId FOR ORDINALITY
   14451             :                 {
   14452          84 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14453             : 
   14454          84 :                     n->coltype = JTC_FOR_ORDINALITY;
   14455          84 :                     n->name = $1;
   14456          84 :                     n->location = @1;
   14457          84 :                     $$ = (Node *) n;
   14458             :                 }
   14459             :             | ColId Typename
   14460             :                 json_table_column_path_clause_opt
   14461             :                 json_wrapper_behavior
   14462             :                 json_quotes_clause_opt
   14463             :                 json_behavior_clause_opt
   14464             :                 {
   14465         734 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14466             : 
   14467         734 :                     n->coltype = JTC_REGULAR;
   14468         734 :                     n->name = $1;
   14469         734 :                     n->typeName = $2;
   14470         734 :                     n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   14471         734 :                     n->pathspec = (JsonTablePathSpec *) $3;
   14472         734 :                     n->wrapper = $4;
   14473         734 :                     n->quotes = $5;
   14474         734 :                     n->on_empty = (JsonBehavior *) linitial($6);
   14475         734 :                     n->on_error = (JsonBehavior *) lsecond($6);
   14476         734 :                     n->location = @1;
   14477         734 :                     $$ = (Node *) n;
   14478             :                 }
   14479             :             | ColId Typename json_format_clause
   14480             :                 json_table_column_path_clause_opt
   14481             :                 json_wrapper_behavior
   14482             :                 json_quotes_clause_opt
   14483             :                 json_behavior_clause_opt
   14484             :                 {
   14485         108 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14486             : 
   14487         108 :                     n->coltype = JTC_FORMATTED;
   14488         108 :                     n->name = $1;
   14489         108 :                     n->typeName = $2;
   14490         108 :                     n->format = (JsonFormat *) $3;
   14491         108 :                     n->pathspec = (JsonTablePathSpec *) $4;
   14492         108 :                     n->wrapper = $5;
   14493         108 :                     n->quotes = $6;
   14494         108 :                     n->on_empty = (JsonBehavior *) linitial($7);
   14495         108 :                     n->on_error = (JsonBehavior *) lsecond($7);
   14496         108 :                     n->location = @1;
   14497         108 :                     $$ = (Node *) n;
   14498             :                 }
   14499             :             | ColId Typename
   14500             :                 EXISTS json_table_column_path_clause_opt
   14501             :                 json_on_error_clause_opt
   14502             :                 {
   14503         138 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14504             : 
   14505         138 :                     n->coltype = JTC_EXISTS;
   14506         138 :                     n->name = $1;
   14507         138 :                     n->typeName = $2;
   14508         138 :                     n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   14509         138 :                     n->wrapper = JSW_NONE;
   14510         138 :                     n->quotes = JS_QUOTES_UNSPEC;
   14511         138 :                     n->pathspec = (JsonTablePathSpec *) $4;
   14512         138 :                     n->on_empty = NULL;
   14513         138 :                     n->on_error = (JsonBehavior *) $5;
   14514         138 :                     n->location = @1;
   14515         138 :                     $$ = (Node *) n;
   14516             :                 }
   14517             :             | NESTED path_opt Sconst
   14518             :                 COLUMNS '(' json_table_column_definition_list ')'
   14519             :                 {
   14520         144 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14521             : 
   14522         144 :                     n->coltype = JTC_NESTED;
   14523         288 :                     n->pathspec = (JsonTablePathSpec *)
   14524         144 :                         makeJsonTablePathSpec($3, NULL, @3, -1);
   14525         144 :                     n->columns = $6;
   14526         144 :                     n->location = @1;
   14527         144 :                     $$ = (Node *) n;
   14528             :                 }
   14529             :             | NESTED path_opt Sconst AS name
   14530             :                 COLUMNS '(' json_table_column_definition_list ')'
   14531             :                 {
   14532         146 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14533             : 
   14534         146 :                     n->coltype = JTC_NESTED;
   14535         292 :                     n->pathspec = (JsonTablePathSpec *)
   14536         146 :                         makeJsonTablePathSpec($3, $5, @3, @5);
   14537         146 :                     n->columns = $8;
   14538         146 :                     n->location = @1;
   14539         146 :                     $$ = (Node *) n;
   14540             :                 }
   14541             :         ;
   14542             : 
   14543             : path_opt:
   14544             :             PATH
   14545             :             | /* EMPTY */
   14546             :         ;
   14547             : 
   14548             : json_table_column_path_clause_opt:
   14549             :             PATH Sconst
   14550         828 :                 { $$ = (Node *) makeJsonTablePathSpec($2, NULL, @2, -1); }
   14551             :             | /* EMPTY */
   14552         158 :                 { $$ = NULL; }
   14553             :         ;
   14554             : 
   14555             : /*****************************************************************************
   14556             :  *
   14557             :  *  Type syntax
   14558             :  *      SQL introduces a large amount of type-specific syntax.
   14559             :  *      Define individual clauses to handle these cases, and use
   14560             :  *       the generic case to handle regular type-extensible Postgres syntax.
   14561             :  *      - thomas 1997-10-10
   14562             :  *
   14563             :  *****************************************************************************/
   14564             : 
   14565             : Typename:   SimpleTypename opt_array_bounds
   14566             :                 {
   14567      521492 :                     $$ = $1;
   14568      521492 :                     $$->arrayBounds = $2;
   14569             :                 }
   14570             :             | SETOF SimpleTypename opt_array_bounds
   14571             :                 {
   14572        2360 :                     $$ = $2;
   14573        2360 :                     $$->arrayBounds = $3;
   14574        2360 :                     $$->setof = true;
   14575             :                 }
   14576             :             /* SQL standard syntax, currently only one-dimensional */
   14577             :             | SimpleTypename ARRAY '[' Iconst ']'
   14578             :                 {
   14579           6 :                     $$ = $1;
   14580           6 :                     $$->arrayBounds = list_make1(makeInteger($4));
   14581             :                 }
   14582             :             | SETOF SimpleTypename ARRAY '[' Iconst ']'
   14583             :                 {
   14584           0 :                     $$ = $2;
   14585           0 :                     $$->arrayBounds = list_make1(makeInteger($5));
   14586           0 :                     $$->setof = true;
   14587             :                 }
   14588             :             | SimpleTypename ARRAY
   14589             :                 {
   14590           0 :                     $$ = $1;
   14591           0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   14592             :                 }
   14593             :             | SETOF SimpleTypename ARRAY
   14594             :                 {
   14595           0 :                     $$ = $2;
   14596           0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   14597           0 :                     $$->setof = true;
   14598             :                 }
   14599             :         ;
   14600             : 
   14601             : opt_array_bounds:
   14602             :             opt_array_bounds '[' ']'
   14603       14572 :                     {  $$ = lappend($1, makeInteger(-1)); }
   14604             :             | opt_array_bounds '[' Iconst ']'
   14605          62 :                     {  $$ = lappend($1, makeInteger($3)); }
   14606             :             | /*EMPTY*/
   14607      523852 :                     {  $$ = NIL; }
   14608             :         ;
   14609             : 
   14610             : SimpleTypename:
   14611      410008 :             GenericType                             { $$ = $1; }
   14612       98110 :             | Numeric                               { $$ = $1; }
   14613        1972 :             | Bit                                   { $$ = $1; }
   14614        3014 :             | Character                             { $$ = $1; }
   14615        5406 :             | ConstDatetime                         { $$ = $1; }
   14616             :             | ConstInterval opt_interval
   14617             :                 {
   14618        3866 :                     $$ = $1;
   14619        3866 :                     $$->typmods = $2;
   14620             :                 }
   14621             :             | ConstInterval '(' Iconst ')'
   14622             :                 {
   14623           0 :                     $$ = $1;
   14624           0 :                     $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   14625             :                                              makeIntConst($3, @3));
   14626             :                 }
   14627        1890 :             | JsonType                              { $$ = $1; }
   14628             :         ;
   14629             : 
   14630             : /* We have a separate ConstTypename to allow defaulting fixed-length
   14631             :  * types such as CHAR() and BIT() to an unspecified length.
   14632             :  * SQL9x requires that these default to a length of one, but this
   14633             :  * makes no sense for constructs like CHAR 'hi' and BIT '0101',
   14634             :  * where there is an obvious better choice to make.
   14635             :  * Note that ConstInterval is not included here since it must
   14636             :  * be pushed up higher in the rules to accommodate the postfix
   14637             :  * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
   14638             :  * the generic-type-name case in AexprConst to avoid premature
   14639             :  * reduce/reduce conflicts against function names.
   14640             :  */
   14641             : ConstTypename:
   14642          78 :             Numeric                                 { $$ = $1; }
   14643           0 :             | ConstBit                              { $$ = $1; }
   14644          34 :             | ConstCharacter                        { $$ = $1; }
   14645        2798 :             | ConstDatetime                         { $$ = $1; }
   14646         264 :             | JsonType                              { $$ = $1; }
   14647             :         ;
   14648             : 
   14649             : /*
   14650             :  * GenericType covers all type names that don't have special syntax mandated
   14651             :  * by the standard, including qualified names.  We also allow type modifiers.
   14652             :  * To avoid parsing conflicts against function invocations, the modifiers
   14653             :  * have to be shown as expr_list here, but parse analysis will only accept
   14654             :  * constants for them.
   14655             :  */
   14656             : GenericType:
   14657             :             type_function_name opt_type_modifiers
   14658             :                 {
   14659      293786 :                     $$ = makeTypeName($1);
   14660      293786 :                     $$->typmods = $2;
   14661      293786 :                     $$->location = @1;
   14662             :                 }
   14663             :             | type_function_name attrs opt_type_modifiers
   14664             :                 {
   14665      116222 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
   14666      116222 :                     $$->typmods = $3;
   14667      116222 :                     $$->location = @1;
   14668             :                 }
   14669             :         ;
   14670             : 
   14671        1350 : opt_type_modifiers: '(' expr_list ')'               { $$ = $2; }
   14672      414932 :                     | /* EMPTY */                   { $$ = NIL; }
   14673             :         ;
   14674             : 
   14675             : /*
   14676             :  * SQL numeric data types
   14677             :  */
   14678             : Numeric:    INT_P
   14679             :                 {
   14680       39034 :                     $$ = SystemTypeName("int4");
   14681       39034 :                     $$->location = @1;
   14682             :                 }
   14683             :             | INTEGER
   14684             :                 {
   14685       25354 :                     $$ = SystemTypeName("int4");
   14686       25354 :                     $$->location = @1;
   14687             :                 }
   14688             :             | SMALLINT
   14689             :                 {
   14690        1422 :                     $$ = SystemTypeName("int2");
   14691        1422 :                     $$->location = @1;
   14692             :                 }
   14693             :             | BIGINT
   14694             :                 {
   14695        5172 :                     $$ = SystemTypeName("int8");
   14696        5172 :                     $$->location = @1;
   14697             :                 }
   14698             :             | REAL
   14699             :                 {
   14700        6924 :                     $$ = SystemTypeName("float4");
   14701        6924 :                     $$->location = @1;
   14702             :                 }
   14703             :             | FLOAT_P opt_float
   14704             :                 {
   14705         538 :                     $$ = $2;
   14706         538 :                     $$->location = @1;
   14707             :                 }
   14708             :             | DOUBLE_P PRECISION
   14709             :                 {
   14710         784 :                     $$ = SystemTypeName("float8");
   14711         784 :                     $$->location = @1;
   14712             :                 }
   14713             :             | DECIMAL_P opt_type_modifiers
   14714             :                 {
   14715          36 :                     $$ = SystemTypeName("numeric");
   14716          36 :                     $$->typmods = $2;
   14717          36 :                     $$->location = @1;
   14718             :                 }
   14719             :             | DEC opt_type_modifiers
   14720             :                 {
   14721           0 :                     $$ = SystemTypeName("numeric");
   14722           0 :                     $$->typmods = $2;
   14723           0 :                     $$->location = @1;
   14724             :                 }
   14725             :             | NUMERIC opt_type_modifiers
   14726             :                 {
   14727        6238 :                     $$ = SystemTypeName("numeric");
   14728        6238 :                     $$->typmods = $2;
   14729        6238 :                     $$->location = @1;
   14730             :                 }
   14731             :             | BOOLEAN_P
   14732             :                 {
   14733       12686 :                     $$ = SystemTypeName("bool");
   14734       12686 :                     $$->location = @1;
   14735             :                 }
   14736             :         ;
   14737             : 
   14738             : opt_float:  '(' Iconst ')'
   14739             :                 {
   14740             :                     /*
   14741             :                      * Check FLOAT() precision limits assuming IEEE floating
   14742             :                      * types - thomas 1997-09-18
   14743             :                      */
   14744           2 :                     if ($2 < 1)
   14745           0 :                         ereport(ERROR,
   14746             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   14747             :                                  errmsg("precision for type float must be at least 1 bit"),
   14748             :                                  parser_errposition(@2)));
   14749           2 :                     else if ($2 <= 24)
   14750           2 :                         $$ = SystemTypeName("float4");
   14751           0 :                     else if ($2 <= 53)
   14752           0 :                         $$ = SystemTypeName("float8");
   14753             :                     else
   14754           0 :                         ereport(ERROR,
   14755             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   14756             :                                  errmsg("precision for type float must be less than 54 bits"),
   14757             :                                  parser_errposition(@2)));
   14758             :                 }
   14759             :             | /*EMPTY*/
   14760             :                 {
   14761         536 :                     $$ = SystemTypeName("float8");
   14762             :                 }
   14763             :         ;
   14764             : 
   14765             : /*
   14766             :  * SQL bit-field data types
   14767             :  * The following implements BIT() and BIT VARYING().
   14768             :  */
   14769             : Bit:        BitWithLength
   14770             :                 {
   14771        1696 :                     $$ = $1;
   14772             :                 }
   14773             :             | BitWithoutLength
   14774             :                 {
   14775         276 :                     $$ = $1;
   14776             :                 }
   14777             :         ;
   14778             : 
   14779             : /* ConstBit is like Bit except "BIT" defaults to unspecified length */
   14780             : /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
   14781             : ConstBit:   BitWithLength
   14782             :                 {
   14783           0 :                     $$ = $1;
   14784             :                 }
   14785             :             | BitWithoutLength
   14786             :                 {
   14787           0 :                     $$ = $1;
   14788           0 :                     $$->typmods = NIL;
   14789             :                 }
   14790             :         ;
   14791             : 
   14792             : BitWithLength:
   14793             :             BIT opt_varying '(' expr_list ')'
   14794             :                 {
   14795             :                     char *typname;
   14796             : 
   14797        1696 :                     typname = $2 ? "varbit" : "bit";
   14798        1696 :                     $$ = SystemTypeName(typname);
   14799        1696 :                     $$->typmods = $4;
   14800        1696 :                     $$->location = @1;
   14801             :                 }
   14802             :         ;
   14803             : 
   14804             : BitWithoutLength:
   14805             :             BIT opt_varying
   14806             :                 {
   14807             :                     /* bit defaults to bit(1), varbit to no limit */
   14808         276 :                     if ($2)
   14809             :                     {
   14810          20 :                         $$ = SystemTypeName("varbit");
   14811             :                     }
   14812             :                     else
   14813             :                     {
   14814         256 :                         $$ = SystemTypeName("bit");
   14815         256 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   14816             :                     }
   14817         276 :                     $$->location = @1;
   14818             :                 }
   14819             :         ;
   14820             : 
   14821             : 
   14822             : /*
   14823             :  * SQL character data types
   14824             :  * The following implements CHAR() and VARCHAR().
   14825             :  */
   14826             : Character:  CharacterWithLength
   14827             :                 {
   14828        1724 :                     $$ = $1;
   14829             :                 }
   14830             :             | CharacterWithoutLength
   14831             :                 {
   14832        1290 :                     $$ = $1;
   14833             :                 }
   14834             :         ;
   14835             : 
   14836             : ConstCharacter:  CharacterWithLength
   14837             :                 {
   14838          12 :                     $$ = $1;
   14839             :                 }
   14840             :             | CharacterWithoutLength
   14841             :                 {
   14842             :                     /* Length was not specified so allow to be unrestricted.
   14843             :                      * This handles problems with fixed-length (bpchar) strings
   14844             :                      * which in column definitions must default to a length
   14845             :                      * of one, but should not be constrained if the length
   14846             :                      * was not specified.
   14847             :                      */
   14848          22 :                     $$ = $1;
   14849          22 :                     $$->typmods = NIL;
   14850             :                 }
   14851             :         ;
   14852             : 
   14853             : CharacterWithLength:  character '(' Iconst ')'
   14854             :                 {
   14855        1736 :                     $$ = SystemTypeName($1);
   14856        1736 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14857        1736 :                     $$->location = @1;
   14858             :                 }
   14859             :         ;
   14860             : 
   14861             : CharacterWithoutLength:  character
   14862             :                 {
   14863        1312 :                     $$ = SystemTypeName($1);
   14864             :                     /* char defaults to char(1), varchar to no limit */
   14865        1312 :                     if (strcmp($1, "bpchar") == 0)
   14866         256 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   14867        1312 :                     $$->location = @1;
   14868             :                 }
   14869             :         ;
   14870             : 
   14871             : character:  CHARACTER opt_varying
   14872         566 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14873             :             | CHAR_P opt_varying
   14874        1172 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14875             :             | VARCHAR
   14876        1306 :                                         { $$ = "varchar"; }
   14877             :             | NATIONAL CHARACTER opt_varying
   14878           0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   14879             :             | NATIONAL CHAR_P opt_varying
   14880           0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   14881             :             | NCHAR opt_varying
   14882           4 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14883             :         ;
   14884             : 
   14885             : opt_varying:
   14886         458 :             VARYING                                 { $$ = true; }
   14887        3256 :             | /*EMPTY*/                             { $$ = false; }
   14888             :         ;
   14889             : 
   14890             : /*
   14891             :  * SQL date/time types
   14892             :  */
   14893             : ConstDatetime:
   14894             :             TIMESTAMP '(' Iconst ')' opt_timezone
   14895             :                 {
   14896         134 :                     if ($5)
   14897         110 :                         $$ = SystemTypeName("timestamptz");
   14898             :                     else
   14899          24 :                         $$ = SystemTypeName("timestamp");
   14900         134 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14901         134 :                     $$->location = @1;
   14902             :                 }
   14903             :             | TIMESTAMP opt_timezone
   14904             :                 {
   14905        5456 :                     if ($2)
   14906        1456 :                         $$ = SystemTypeName("timestamptz");
   14907             :                     else
   14908        4000 :                         $$ = SystemTypeName("timestamp");
   14909        5456 :                     $$->location = @1;
   14910             :                 }
   14911             :             | TIME '(' Iconst ')' opt_timezone
   14912             :                 {
   14913          22 :                     if ($5)
   14914           8 :                         $$ = SystemTypeName("timetz");
   14915             :                     else
   14916          14 :                         $$ = SystemTypeName("time");
   14917          22 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14918          22 :                     $$->location = @1;
   14919             :                 }
   14920             :             | TIME opt_timezone
   14921             :                 {
   14922        2592 :                     if ($2)
   14923         348 :                         $$ = SystemTypeName("timetz");
   14924             :                     else
   14925        2244 :                         $$ = SystemTypeName("time");
   14926        2592 :                     $$->location = @1;
   14927             :                 }
   14928             :         ;
   14929             : 
   14930             : ConstInterval:
   14931             :             INTERVAL
   14932             :                 {
   14933        7176 :                     $$ = SystemTypeName("interval");
   14934        7176 :                     $$->location = @1;
   14935             :                 }
   14936             :         ;
   14937             : 
   14938             : opt_timezone:
   14939        1922 :             WITH_LA TIME ZONE                       { $$ = true; }
   14940         624 :             | WITHOUT_LA TIME ZONE                  { $$ = false; }
   14941        5658 :             | /*EMPTY*/                             { $$ = false; }
   14942             :         ;
   14943             : 
   14944             : opt_interval:
   14945             :             YEAR_P
   14946          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
   14947             :             | MONTH_P
   14948          18 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
   14949             :             | DAY_P
   14950          18 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
   14951             :             | HOUR_P
   14952          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
   14953             :             | MINUTE_P
   14954          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
   14955             :             | interval_second
   14956          36 :                 { $$ = $1; }
   14957             :             | YEAR_P TO MONTH_P
   14958             :                 {
   14959          18 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
   14960             :                                                  INTERVAL_MASK(MONTH), @1));
   14961             :                 }
   14962             :             | DAY_P TO HOUR_P
   14963             :                 {
   14964          24 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   14965             :                                                  INTERVAL_MASK(HOUR), @1));
   14966             :                 }
   14967             :             | DAY_P TO MINUTE_P
   14968             :                 {
   14969          24 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   14970             :                                                  INTERVAL_MASK(HOUR) |
   14971             :                                                  INTERVAL_MASK(MINUTE), @1));
   14972             :                 }
   14973             :             | DAY_P TO interval_second
   14974             :                 {
   14975          48 :                     $$ = $3;
   14976          48 :                     linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
   14977             :                                                 INTERVAL_MASK(HOUR) |
   14978             :                                                 INTERVAL_MASK(MINUTE) |
   14979          48 :                                                 INTERVAL_MASK(SECOND), @1);
   14980             :                 }
   14981             :             | HOUR_P TO MINUTE_P
   14982             :                 {
   14983          18 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
   14984             :                                                  INTERVAL_MASK(MINUTE), @1));
   14985             :                 }
   14986             :             | HOUR_P TO interval_second
   14987             :                 {
   14988          36 :                     $$ = $3;
   14989          36 :                     linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
   14990             :                                                 INTERVAL_MASK(MINUTE) |
   14991          36 :                                                 INTERVAL_MASK(SECOND), @1);
   14992             :                 }
   14993             :             | MINUTE_P TO interval_second
   14994             :                 {
   14995          66 :                     $$ = $3;
   14996          66 :                     linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
   14997          66 :                                                 INTERVAL_MASK(SECOND), @1);
   14998             :                 }
   14999             :             | /*EMPTY*/
   15000        6822 :                 { $$ = NIL; }
   15001             :         ;
   15002             : 
   15003             : interval_second:
   15004             :             SECOND_P
   15005             :                 {
   15006         102 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
   15007             :                 }
   15008             :             | SECOND_P '(' Iconst ')'
   15009             :                 {
   15010          84 :                     $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
   15011             :                                     makeIntConst($3, @3));
   15012             :                 }
   15013             :         ;
   15014             : 
   15015             : JsonType:
   15016             :             JSON
   15017             :                 {
   15018        2154 :                     $$ = SystemTypeName("json");
   15019        2154 :                     $$->location = @1;
   15020             :                 }
   15021             :         ;
   15022             : 
   15023             : /*****************************************************************************
   15024             :  *
   15025             :  *  expression grammar
   15026             :  *
   15027             :  *****************************************************************************/
   15028             : 
   15029             : /*
   15030             :  * General expressions
   15031             :  * This is the heart of the expression syntax.
   15032             :  *
   15033             :  * We have two expression types: a_expr is the unrestricted kind, and
   15034             :  * b_expr is a subset that must be used in some places to avoid shift/reduce
   15035             :  * conflicts.  For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
   15036             :  * because that use of AND conflicts with AND as a boolean operator.  So,
   15037             :  * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
   15038             :  *
   15039             :  * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
   15040             :  * always be used by surrounding it with parens.
   15041             :  *
   15042             :  * c_expr is all the productions that are common to a_expr and b_expr;
   15043             :  * it's factored out just to eliminate redundant coding.
   15044             :  *
   15045             :  * Be careful of productions involving more than one terminal token.
   15046             :  * By default, bison will assign such productions the precedence of their
   15047             :  * last terminal, but in nearly all cases you want it to be the precedence
   15048             :  * of the first terminal instead; otherwise you will not get the behavior
   15049             :  * you expect!  So we use %prec annotations freely to set precedences.
   15050             :  */
   15051     3666508 : a_expr:     c_expr                                  { $$ = $1; }
   15052             :             | a_expr TYPECAST Typename
   15053      235136 :                     { $$ = makeTypeCast($1, $3, @2); }
   15054             :             | a_expr COLLATE any_name
   15055             :                 {
   15056        9070 :                     CollateClause *n = makeNode(CollateClause);
   15057             : 
   15058        9070 :                     n->arg = $1;
   15059        9070 :                     n->collname = $3;
   15060        9070 :                     n->location = @2;
   15061        9070 :                     $$ = (Node *) n;
   15062             :                 }
   15063             :             | a_expr AT TIME ZONE a_expr            %prec AT
   15064             :                 {
   15065         408 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   15066         408 :                                                list_make2($5, $1),
   15067             :                                                COERCE_SQL_SYNTAX,
   15068         408 :                                                @2);
   15069             :                 }
   15070             :             | a_expr AT LOCAL                       %prec AT
   15071             :                 {
   15072          42 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   15073          42 :                                                list_make1($1),
   15074             :                                                COERCE_SQL_SYNTAX,
   15075             :                                                -1);
   15076             :                 }
   15077             :         /*
   15078             :          * These operators must be called out explicitly in order to make use
   15079             :          * of bison's automatic operator-precedence handling.  All other
   15080             :          * operator names are handled by the generic productions using "Op",
   15081             :          * below; and all those operators will have the same precedence.
   15082             :          *
   15083             :          * If you add more explicitly-known operators, be sure to add them
   15084             :          * also to b_expr and to the MathOp list below.
   15085             :          */
   15086             :             | '+' a_expr                    %prec UMINUS
   15087          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   15088             :             | '-' a_expr                    %prec UMINUS
   15089        9192 :                 { $$ = doNegate($2, @1); }
   15090             :             | a_expr '+' a_expr
   15091       14368 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   15092             :             | a_expr '-' a_expr
   15093        4534 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   15094             :             | a_expr '*' a_expr
   15095        6348 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   15096             :             | a_expr '/' a_expr
   15097        3478 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   15098             :             | a_expr '%' a_expr
   15099        2952 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   15100             :             | a_expr '^' a_expr
   15101         476 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   15102             :             | a_expr '<' a_expr
   15103       10606 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   15104             :             | a_expr '>' a_expr
   15105       16686 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   15106             :             | a_expr '=' a_expr
   15107      389302 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   15108             :             | a_expr LESS_EQUALS a_expr
   15109        5212 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   15110             :             | a_expr GREATER_EQUALS a_expr
   15111        7144 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   15112             :             | a_expr NOT_EQUALS a_expr
   15113       39700 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   15114             : 
   15115             :             | a_expr qual_Op a_expr             %prec Op
   15116       59350 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   15117             :             | qual_Op a_expr                    %prec Op
   15118         246 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   15119             : 
   15120             :             | a_expr AND a_expr
   15121      232398 :                 { $$ = makeAndExpr($1, $3, @2); }
   15122             :             | a_expr OR a_expr
   15123       16048 :                 { $$ = makeOrExpr($1, $3, @2); }
   15124             :             | NOT a_expr
   15125       16106 :                 { $$ = makeNotExpr($2, @1); }
   15126             :             | NOT_LA a_expr                     %prec NOT
   15127           0 :                 { $$ = makeNotExpr($2, @1); }
   15128             : 
   15129             :             | a_expr LIKE a_expr
   15130             :                 {
   15131        1964 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   15132        1964 :                                                    $1, $3, @2);
   15133             :                 }
   15134             :             | a_expr LIKE a_expr ESCAPE a_expr                  %prec LIKE
   15135             :                 {
   15136          96 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15137          96 :                                                  list_make2($3, $5),
   15138             :                                                  COERCE_EXPLICIT_CALL,
   15139          96 :                                                  @2);
   15140          96 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   15141          96 :                                                    $1, (Node *) n, @2);
   15142             :                 }
   15143             :             | a_expr NOT_LA LIKE a_expr                         %prec NOT_LA
   15144             :                 {
   15145         198 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   15146         198 :                                                    $1, $4, @2);
   15147             :                 }
   15148             :             | a_expr NOT_LA LIKE a_expr ESCAPE a_expr           %prec NOT_LA
   15149             :                 {
   15150          96 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15151          96 :                                                  list_make2($4, $6),
   15152             :                                                  COERCE_EXPLICIT_CALL,
   15153          96 :                                                  @2);
   15154          96 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   15155          96 :                                                    $1, (Node *) n, @2);
   15156             :                 }
   15157             :             | a_expr ILIKE a_expr
   15158             :                 {
   15159         172 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   15160         172 :                                                    $1, $3, @2);
   15161             :                 }
   15162             :             | a_expr ILIKE a_expr ESCAPE a_expr                 %prec ILIKE
   15163             :                 {
   15164           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15165           0 :                                                  list_make2($3, $5),
   15166             :                                                  COERCE_EXPLICIT_CALL,
   15167           0 :                                                  @2);
   15168           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   15169           0 :                                                    $1, (Node *) n, @2);
   15170             :                 }
   15171             :             | a_expr NOT_LA ILIKE a_expr                        %prec NOT_LA
   15172             :                 {
   15173          30 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   15174          30 :                                                    $1, $4, @2);
   15175             :                 }
   15176             :             | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr          %prec NOT_LA
   15177             :                 {
   15178           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15179           0 :                                                  list_make2($4, $6),
   15180             :                                                  COERCE_EXPLICIT_CALL,
   15181           0 :                                                  @2);
   15182           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   15183           0 :                                                    $1, (Node *) n, @2);
   15184             :                 }
   15185             : 
   15186             :             | a_expr SIMILAR TO a_expr                          %prec SIMILAR
   15187             :                 {
   15188          88 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15189          88 :                                                  list_make1($4),
   15190             :                                                  COERCE_EXPLICIT_CALL,
   15191          88 :                                                  @2);
   15192          88 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   15193          88 :                                                    $1, (Node *) n, @2);
   15194             :                 }
   15195             :             | a_expr SIMILAR TO a_expr ESCAPE a_expr            %prec SIMILAR
   15196             :                 {
   15197          36 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15198          36 :                                                  list_make2($4, $6),
   15199             :                                                  COERCE_EXPLICIT_CALL,
   15200          36 :                                                  @2);
   15201          36 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   15202          36 :                                                    $1, (Node *) n, @2);
   15203             :                 }
   15204             :             | a_expr NOT_LA SIMILAR TO a_expr                   %prec NOT_LA
   15205             :                 {
   15206           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15207           0 :                                                  list_make1($5),
   15208             :                                                  COERCE_EXPLICIT_CALL,
   15209           0 :                                                  @2);
   15210           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   15211           0 :                                                    $1, (Node *) n, @2);
   15212             :                 }
   15213             :             | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr     %prec NOT_LA
   15214             :                 {
   15215           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15216           0 :                                                  list_make2($5, $7),
   15217             :                                                  COERCE_EXPLICIT_CALL,
   15218           0 :                                                  @2);
   15219           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   15220           0 :                                                    $1, (Node *) n, @2);
   15221             :                 }
   15222             : 
   15223             :             /* NullTest clause
   15224             :              * Define SQL-style Null test clause.
   15225             :              * Allow two forms described in the standard:
   15226             :              *  a IS NULL
   15227             :              *  a IS NOT NULL
   15228             :              * Allow two SQL extensions
   15229             :              *  a ISNULL
   15230             :              *  a NOTNULL
   15231             :              */
   15232             :             | a_expr IS NULL_P                          %prec IS
   15233             :                 {
   15234        5266 :                     NullTest   *n = makeNode(NullTest);
   15235             : 
   15236        5266 :                     n->arg = (Expr *) $1;
   15237        5266 :                     n->nulltesttype = IS_NULL;
   15238        5266 :                     n->location = @2;
   15239        5266 :                     $$ = (Node *) n;
   15240             :                 }
   15241             :             | a_expr ISNULL
   15242             :                 {
   15243          96 :                     NullTest   *n = makeNode(NullTest);
   15244             : 
   15245          96 :                     n->arg = (Expr *) $1;
   15246          96 :                     n->nulltesttype = IS_NULL;
   15247          96 :                     n->location = @2;
   15248          96 :                     $$ = (Node *) n;
   15249             :                 }
   15250             :             | a_expr IS NOT NULL_P                      %prec IS
   15251             :                 {
   15252       12948 :                     NullTest   *n = makeNode(NullTest);
   15253             : 
   15254       12948 :                     n->arg = (Expr *) $1;
   15255       12948 :                     n->nulltesttype = IS_NOT_NULL;
   15256       12948 :                     n->location = @2;
   15257       12948 :                     $$ = (Node *) n;
   15258             :                 }
   15259             :             | a_expr NOTNULL
   15260             :                 {
   15261           6 :                     NullTest   *n = makeNode(NullTest);
   15262             : 
   15263           6 :                     n->arg = (Expr *) $1;
   15264           6 :                     n->nulltesttype = IS_NOT_NULL;
   15265           6 :                     n->location = @2;
   15266           6 :                     $$ = (Node *) n;
   15267             :                 }
   15268             :             | row OVERLAPS row
   15269             :                 {
   15270         966 :                     if (list_length($1) != 2)
   15271           0 :                         ereport(ERROR,
   15272             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   15273             :                                  errmsg("wrong number of parameters on left side of OVERLAPS expression"),
   15274             :                                  parser_errposition(@1)));
   15275         966 :                     if (list_length($3) != 2)
   15276           0 :                         ereport(ERROR,
   15277             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   15278             :                                  errmsg("wrong number of parameters on right side of OVERLAPS expression"),
   15279             :                                  parser_errposition(@3)));
   15280         966 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
   15281         966 :                                                list_concat($1, $3),
   15282             :                                                COERCE_SQL_SYNTAX,
   15283         966 :                                                @2);
   15284             :                 }
   15285             :             | a_expr IS TRUE_P                          %prec IS
   15286             :                 {
   15287         434 :                     BooleanTest *b = makeNode(BooleanTest);
   15288             : 
   15289         434 :                     b->arg = (Expr *) $1;
   15290         434 :                     b->booltesttype = IS_TRUE;
   15291         434 :                     b->location = @2;
   15292         434 :                     $$ = (Node *) b;
   15293             :                 }
   15294             :             | a_expr IS NOT TRUE_P                      %prec IS
   15295             :                 {
   15296         140 :                     BooleanTest *b = makeNode(BooleanTest);
   15297             : 
   15298         140 :                     b->arg = (Expr *) $1;
   15299         140 :                     b->booltesttype = IS_NOT_TRUE;
   15300         140 :                     b->location = @2;
   15301         140 :                     $$ = (Node *) b;
   15302             :                 }
   15303             :             | a_expr IS FALSE_P                         %prec IS
   15304             :                 {
   15305         154 :                     BooleanTest *b = makeNode(BooleanTest);
   15306             : 
   15307         154 :                     b->arg = (Expr *) $1;
   15308         154 :                     b->booltesttype = IS_FALSE;
   15309         154 :                     b->location = @2;
   15310         154 :                     $$ = (Node *) b;
   15311             :                 }
   15312             :             | a_expr IS NOT FALSE_P                     %prec IS
   15313             :                 {
   15314          92 :                     BooleanTest *b = makeNode(BooleanTest);
   15315             : 
   15316          92 :                     b->arg = (Expr *) $1;
   15317          92 :                     b->booltesttype = IS_NOT_FALSE;
   15318          92 :                     b->location = @2;
   15319          92 :                     $$ = (Node *) b;
   15320             :                 }
   15321             :             | a_expr IS UNKNOWN                         %prec IS
   15322             :                 {
   15323          52 :                     BooleanTest *b = makeNode(BooleanTest);
   15324             : 
   15325          52 :                     b->arg = (Expr *) $1;
   15326          52 :                     b->booltesttype = IS_UNKNOWN;
   15327          52 :                     b->location = @2;
   15328          52 :                     $$ = (Node *) b;
   15329             :                 }
   15330             :             | a_expr IS NOT UNKNOWN                     %prec IS
   15331             :                 {
   15332          48 :                     BooleanTest *b = makeNode(BooleanTest);
   15333             : 
   15334          48 :                     b->arg = (Expr *) $1;
   15335          48 :                     b->booltesttype = IS_NOT_UNKNOWN;
   15336          48 :                     b->location = @2;
   15337          48 :                     $$ = (Node *) b;
   15338             :                 }
   15339             :             | a_expr IS DISTINCT FROM a_expr            %prec IS
   15340             :                 {
   15341        1078 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   15342             :                 }
   15343             :             | a_expr IS NOT DISTINCT FROM a_expr        %prec IS
   15344             :                 {
   15345          68 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   15346             :                 }
   15347             :             | a_expr BETWEEN opt_asymmetric b_expr AND a_expr       %prec BETWEEN
   15348             :                 {
   15349         470 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN,
   15350             :                                                    "BETWEEN",
   15351         470 :                                                    $1,
   15352         470 :                                                    (Node *) list_make2($4, $6),
   15353         470 :                                                    @2);
   15354             :                 }
   15355             :             | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
   15356             :                 {
   15357          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN,
   15358             :                                                    "NOT BETWEEN",
   15359          12 :                                                    $1,
   15360          12 :                                                    (Node *) list_make2($5, $7),
   15361          12 :                                                    @2);
   15362             :                 }
   15363             :             | a_expr BETWEEN SYMMETRIC b_expr AND a_expr            %prec BETWEEN
   15364             :                 {
   15365          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN_SYM,
   15366             :                                                    "BETWEEN SYMMETRIC",
   15367          12 :                                                    $1,
   15368          12 :                                                    (Node *) list_make2($4, $6),
   15369          12 :                                                    @2);
   15370             :                 }
   15371             :             | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr     %prec NOT_LA
   15372             :                 {
   15373          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN_SYM,
   15374             :                                                    "NOT BETWEEN SYMMETRIC",
   15375          12 :                                                    $1,
   15376          12 :                                                    (Node *) list_make2($5, $7),
   15377          12 :                                                    @2);
   15378             :                 }
   15379             :             | a_expr IN_P select_with_parens
   15380             :                 {
   15381             :                     /* generate foo = ANY (subquery) */
   15382        5572 :                     SubLink    *n = makeNode(SubLink);
   15383             : 
   15384        5572 :                     n->subselect = $3;
   15385        5572 :                     n->subLinkType = ANY_SUBLINK;
   15386        5572 :                     n->subLinkId = 0;
   15387        5572 :                     n->testexpr = $1;
   15388        5572 :                     n->operName = NIL;       /* show it's IN not = ANY */
   15389        5572 :                     n->location = @2;
   15390        5572 :                     $$ = (Node *) n;
   15391             :                 }
   15392             :             | a_expr IN_P '(' expr_list ')'
   15393             :                 {
   15394             :                     /* generate scalar IN expression */
   15395       18920 :                     A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "=", $1, (Node *) $4, @2);
   15396             : 
   15397       18920 :                     n->rexpr_list_start = @3;
   15398       18920 :                     n->rexpr_list_end = @5;
   15399       18920 :                     $$ = (Node *) n;
   15400             :                 }
   15401             :             | a_expr NOT_LA IN_P select_with_parens         %prec NOT_LA
   15402             :                 {
   15403             :                     /* generate NOT (foo = ANY (subquery)) */
   15404         120 :                     SubLink    *n = makeNode(SubLink);
   15405             : 
   15406         120 :                     n->subselect = $4;
   15407         120 :                     n->subLinkType = ANY_SUBLINK;
   15408         120 :                     n->subLinkId = 0;
   15409         120 :                     n->testexpr = $1;
   15410         120 :                     n->operName = NIL;       /* show it's IN not = ANY */
   15411         120 :                     n->location = @2;
   15412             :                     /* Stick a NOT on top; must have same parse location */
   15413         120 :                     $$ = makeNotExpr((Node *) n, @2);
   15414             :                 }
   15415             :             | a_expr NOT_LA IN_P '(' expr_list ')'
   15416             :                 {
   15417             :                     /* generate scalar NOT IN expression */
   15418        2690 :                     A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "<>", $1, (Node *) $5, @2);
   15419             : 
   15420        2690 :                     n->rexpr_list_start = @4;
   15421        2690 :                     n->rexpr_list_end = @6;
   15422        2690 :                     $$ = (Node *) n;
   15423             :                 }
   15424             :             | a_expr subquery_Op sub_type select_with_parens    %prec Op
   15425             :                 {
   15426         180 :                     SubLink    *n = makeNode(SubLink);
   15427             : 
   15428         180 :                     n->subLinkType = $3;
   15429         180 :                     n->subLinkId = 0;
   15430         180 :                     n->testexpr = $1;
   15431         180 :                     n->operName = $2;
   15432         180 :                     n->subselect = $4;
   15433         180 :                     n->location = @2;
   15434         180 :                     $$ = (Node *) n;
   15435             :                 }
   15436             :             | a_expr subquery_Op sub_type '(' a_expr ')'        %prec Op
   15437             :                 {
   15438       16826 :                     if ($3 == ANY_SUBLINK)
   15439       16526 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
   15440             :                     else
   15441         300 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
   15442             :                 }
   15443             :             | UNIQUE opt_unique_null_treatment select_with_parens
   15444             :                 {
   15445             :                     /* Not sure how to get rid of the parentheses
   15446             :                      * but there are lots of shift/reduce errors without them.
   15447             :                      *
   15448             :                      * Should be able to implement this by plopping the entire
   15449             :                      * select into a node, then transforming the target expressions
   15450             :                      * from whatever they are into count(*), and testing the
   15451             :                      * entire result equal to one.
   15452             :                      * But, will probably implement a separate node in the executor.
   15453             :                      */
   15454           0 :                     ereport(ERROR,
   15455             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   15456             :                              errmsg("UNIQUE predicate is not yet implemented"),
   15457             :                              parser_errposition(@1)));
   15458             :                 }
   15459             :             | a_expr IS DOCUMENT_P                  %prec IS
   15460             :                 {
   15461          18 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15462          18 :                                      list_make1($1), @2);
   15463             :                 }
   15464             :             | a_expr IS NOT DOCUMENT_P              %prec IS
   15465             :                 {
   15466          18 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15467          18 :                                                  list_make1($1), @2),
   15468          18 :                                      @2);
   15469             :                 }
   15470             :             | a_expr IS NORMALIZED                              %prec IS
   15471             :                 {
   15472          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15473          12 :                                                list_make1($1),
   15474             :                                                COERCE_SQL_SYNTAX,
   15475          12 :                                                @2);
   15476             :                 }
   15477             :             | a_expr IS unicode_normal_form NORMALIZED          %prec IS
   15478             :                 {
   15479          36 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15480          36 :                                                list_make2($1, makeStringConst($3, @3)),
   15481             :                                                COERCE_SQL_SYNTAX,
   15482          36 :                                                @2);
   15483             :                 }
   15484             :             | a_expr IS NOT NORMALIZED                          %prec IS
   15485             :                 {
   15486           0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15487           0 :                                                            list_make1($1),
   15488             :                                                            COERCE_SQL_SYNTAX,
   15489           0 :                                                            @2),
   15490           0 :                                      @2);
   15491             :                 }
   15492             :             | a_expr IS NOT unicode_normal_form NORMALIZED      %prec IS
   15493             :                 {
   15494           0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15495           0 :                                                            list_make2($1, makeStringConst($4, @4)),
   15496             :                                                            COERCE_SQL_SYNTAX,
   15497           0 :                                                            @2),
   15498           0 :                                      @2);
   15499             :                 }
   15500             :             | a_expr IS json_predicate_type_constraint
   15501             :                     json_key_uniqueness_constraint_opt      %prec IS
   15502             :                 {
   15503         304 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   15504             : 
   15505         304 :                     $$ = makeJsonIsPredicate($1, format, $3, $4, @1);
   15506             :                 }
   15507             :             /*
   15508             :              * Required by SQL/JSON, but there are conflicts
   15509             :             | a_expr
   15510             :                 json_format_clause
   15511             :                 IS  json_predicate_type_constraint
   15512             :                     json_key_uniqueness_constraint_opt      %prec IS
   15513             :                 {
   15514             :                     $$ = makeJsonIsPredicate($1, $2, $4, $5, @1);
   15515             :                 }
   15516             :             */
   15517             :             | a_expr IS NOT
   15518             :                     json_predicate_type_constraint
   15519             :                     json_key_uniqueness_constraint_opt      %prec IS
   15520             :                 {
   15521          46 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   15522             : 
   15523          46 :                     $$ = makeNotExpr(makeJsonIsPredicate($1, format, $4, $5, @1), @1);
   15524             :                 }
   15525             :             /*
   15526             :              * Required by SQL/JSON, but there are conflicts
   15527             :             | a_expr
   15528             :                 json_format_clause
   15529             :                 IS NOT
   15530             :                     json_predicate_type_constraint
   15531             :                     json_key_uniqueness_constraint_opt      %prec IS
   15532             :                 {
   15533             :                     $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, @1), @1);
   15534             :                 }
   15535             :             */
   15536             :             | DEFAULT
   15537             :                 {
   15538             :                     /*
   15539             :                      * The SQL spec only allows DEFAULT in "contextually typed
   15540             :                      * expressions", but for us, it's easier to allow it in
   15541             :                      * any a_expr and then throw error during parse analysis
   15542             :                      * if it's in an inappropriate context.  This way also
   15543             :                      * lets us say something smarter than "syntax error".
   15544             :                      */
   15545        1524 :                     SetToDefault *n = makeNode(SetToDefault);
   15546             : 
   15547             :                     /* parse analysis will fill in the rest */
   15548        1524 :                     n->location = @1;
   15549        1524 :                     $$ = (Node *) n;
   15550             :                 }
   15551             :         ;
   15552             : 
   15553             : /*
   15554             :  * Restricted expressions
   15555             :  *
   15556             :  * b_expr is a subset of the complete expression syntax defined by a_expr.
   15557             :  *
   15558             :  * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
   15559             :  * cause trouble in the places where b_expr is used.  For simplicity, we
   15560             :  * just eliminate all the boolean-keyword-operator productions from b_expr.
   15561             :  */
   15562             : b_expr:     c_expr
   15563        3806 :                 { $$ = $1; }
   15564             :             | b_expr TYPECAST Typename
   15565         212 :                 { $$ = makeTypeCast($1, $3, @2); }
   15566             :             | '+' b_expr                    %prec UMINUS
   15567           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   15568             :             | '-' b_expr                    %prec UMINUS
   15569          66 :                 { $$ = doNegate($2, @1); }
   15570             :             | b_expr '+' b_expr
   15571          36 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   15572             :             | b_expr '-' b_expr
   15573          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   15574             :             | b_expr '*' b_expr
   15575          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   15576             :             | b_expr '/' b_expr
   15577           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   15578             :             | b_expr '%' b_expr
   15579           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   15580             :             | b_expr '^' b_expr
   15581           6 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   15582             :             | b_expr '<' b_expr
   15583           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   15584             :             | b_expr '>' b_expr
   15585           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   15586             :             | b_expr '=' b_expr
   15587           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   15588             :             | b_expr LESS_EQUALS b_expr
   15589           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   15590             :             | b_expr GREATER_EQUALS b_expr
   15591           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   15592             :             | b_expr NOT_EQUALS b_expr
   15593           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   15594             :             | b_expr qual_Op b_expr             %prec Op
   15595          12 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   15596             :             | qual_Op b_expr                    %prec Op
   15597           0 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   15598             :             | b_expr IS DISTINCT FROM b_expr        %prec IS
   15599             :                 {
   15600           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   15601             :                 }
   15602             :             | b_expr IS NOT DISTINCT FROM b_expr    %prec IS
   15603             :                 {
   15604           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   15605             :                 }
   15606             :             | b_expr IS DOCUMENT_P                  %prec IS
   15607             :                 {
   15608           0 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15609           0 :                                      list_make1($1), @2);
   15610             :                 }
   15611             :             | b_expr IS NOT DOCUMENT_P              %prec IS
   15612             :                 {
   15613           0 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15614           0 :                                                  list_make1($1), @2),
   15615           0 :                                      @2);
   15616             :                 }
   15617             :         ;
   15618             : 
   15619             : /*
   15620             :  * Productions that can be used in both a_expr and b_expr.
   15621             :  *
   15622             :  * Note: productions that refer recursively to a_expr or b_expr mostly
   15623             :  * cannot appear here.  However, it's OK to refer to a_exprs that occur
   15624             :  * inside parentheses, such as function arguments; that cannot introduce
   15625             :  * ambiguity to the b_expr syntax.
   15626             :  */
   15627     1808114 : c_expr:     columnref                               { $$ = $1; }
   15628     1238590 :             | AexprConst                            { $$ = $1; }
   15629             :             | PARAM opt_indirection
   15630             :                 {
   15631       46266 :                     ParamRef   *p = makeNode(ParamRef);
   15632             : 
   15633       46266 :                     p->number = $1;
   15634       46266 :                     p->location = @1;
   15635       46266 :                     if ($2)
   15636             :                     {
   15637        1084 :                         A_Indirection *n = makeNode(A_Indirection);
   15638             : 
   15639        1084 :                         n->arg = (Node *) p;
   15640        1084 :                         n->indirection = check_indirection($2, yyscanner);
   15641        1084 :                         $$ = (Node *) n;
   15642             :                     }
   15643             :                     else
   15644       45182 :                         $$ = (Node *) p;
   15645             :                 }
   15646             :             | '(' a_expr ')' opt_indirection
   15647             :                 {
   15648       89980 :                     if ($4)
   15649             :                     {
   15650       12348 :                         A_Indirection *n = makeNode(A_Indirection);
   15651             : 
   15652       12348 :                         n->arg = $2;
   15653       12348 :                         n->indirection = check_indirection($4, yyscanner);
   15654       12348 :                         $$ = (Node *) n;
   15655             :                     }
   15656             :                     else
   15657       77632 :                         $$ = $2;
   15658             :                 }
   15659             :             | case_expr
   15660       39110 :                 { $$ = $1; }
   15661             :             | func_expr
   15662      392468 :                 { $$ = $1; }
   15663             :             | select_with_parens            %prec UMINUS
   15664             :                 {
   15665       27484 :                     SubLink    *n = makeNode(SubLink);
   15666             : 
   15667       27484 :                     n->subLinkType = EXPR_SUBLINK;
   15668       27484 :                     n->subLinkId = 0;
   15669       27484 :                     n->testexpr = NULL;
   15670       27484 :                     n->operName = NIL;
   15671       27484 :                     n->subselect = $1;
   15672       27484 :                     n->location = @1;
   15673       27484 :                     $$ = (Node *) n;
   15674             :                 }
   15675             :             | select_with_parens indirection
   15676             :                 {
   15677             :                     /*
   15678             :                      * Because the select_with_parens nonterminal is designed
   15679             :                      * to "eat" as many levels of parens as possible, the
   15680             :                      * '(' a_expr ')' opt_indirection production above will
   15681             :                      * fail to match a sub-SELECT with indirection decoration;
   15682             :                      * the sub-SELECT won't be regarded as an a_expr as long
   15683             :                      * as there are parens around it.  To support applying
   15684             :                      * subscripting or field selection to a sub-SELECT result,
   15685             :                      * we need this redundant-looking production.
   15686             :                      */
   15687          18 :                     SubLink    *n = makeNode(SubLink);
   15688          18 :                     A_Indirection *a = makeNode(A_Indirection);
   15689             : 
   15690          18 :                     n->subLinkType = EXPR_SUBLINK;
   15691          18 :                     n->subLinkId = 0;
   15692          18 :                     n->testexpr = NULL;
   15693          18 :                     n->operName = NIL;
   15694          18 :                     n->subselect = $1;
   15695          18 :                     n->location = @1;
   15696          18 :                     a->arg = (Node *) n;
   15697          18 :                     a->indirection = check_indirection($2, yyscanner);
   15698          18 :                     $$ = (Node *) a;
   15699             :                 }
   15700             :             | EXISTS select_with_parens
   15701             :                 {
   15702        6178 :                     SubLink    *n = makeNode(SubLink);
   15703             : 
   15704        6178 :                     n->subLinkType = EXISTS_SUBLINK;
   15705        6178 :                     n->subLinkId = 0;
   15706        6178 :                     n->testexpr = NULL;
   15707        6178 :                     n->operName = NIL;
   15708        6178 :                     n->subselect = $2;
   15709        6178 :                     n->location = @1;
   15710        6178 :                     $$ = (Node *) n;
   15711             :                 }
   15712             :             | ARRAY select_with_parens
   15713             :                 {
   15714        8432 :                     SubLink    *n = makeNode(SubLink);
   15715             : 
   15716        8432 :                     n->subLinkType = ARRAY_SUBLINK;
   15717        8432 :                     n->subLinkId = 0;
   15718        8432 :                     n->testexpr = NULL;
   15719        8432 :                     n->operName = NIL;
   15720        8432 :                     n->subselect = $2;
   15721        8432 :                     n->location = @1;
   15722        8432 :                     $$ = (Node *) n;
   15723             :                 }
   15724             :             | ARRAY array_expr
   15725             :                 {
   15726        7464 :                     A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
   15727             : 
   15728             :                     /* point outermost A_ArrayExpr to the ARRAY keyword */
   15729        7464 :                     n->location = @1;
   15730        7464 :                     $$ = (Node *) n;
   15731             :                 }
   15732             :             | explicit_row
   15733             :                 {
   15734        3828 :                     RowExpr    *r = makeNode(RowExpr);
   15735             : 
   15736        3828 :                     r->args = $1;
   15737        3828 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15738        3828 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15739        3828 :                     r->row_format = COERCE_EXPLICIT_CALL; /* abuse */
   15740        3828 :                     r->location = @1;
   15741        3828 :                     $$ = (Node *) r;
   15742             :                 }
   15743             :             | implicit_row
   15744             :                 {
   15745        2706 :                     RowExpr    *r = makeNode(RowExpr);
   15746             : 
   15747        2706 :                     r->args = $1;
   15748        2706 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15749        2706 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15750        2706 :                     r->row_format = COERCE_IMPLICIT_CAST; /* abuse */
   15751        2706 :                     r->location = @1;
   15752        2706 :                     $$ = (Node *) r;
   15753             :                 }
   15754             :             | GROUPING '(' expr_list ')'
   15755             :               {
   15756         362 :                   GroupingFunc *g = makeNode(GroupingFunc);
   15757             : 
   15758         362 :                   g->args = $3;
   15759         362 :                   g->location = @1;
   15760         362 :                   $$ = (Node *) g;
   15761             :               }
   15762             :         ;
   15763             : 
   15764             : func_application: func_name '(' ')'
   15765             :                 {
   15766       32910 :                     $$ = (Node *) makeFuncCall($1, NIL,
   15767             :                                                COERCE_EXPLICIT_CALL,
   15768       32910 :                                                @1);
   15769             :                 }
   15770             :             | func_name '(' func_arg_list opt_sort_clause ')'
   15771             :                 {
   15772      317666 :                     FuncCall   *n = makeFuncCall($1, $3,
   15773             :                                                  COERCE_EXPLICIT_CALL,
   15774      317666 :                                                  @1);
   15775             : 
   15776      317666 :                     n->agg_order = $4;
   15777      317666 :                     $$ = (Node *) n;
   15778             :                 }
   15779             :             | func_name '(' VARIADIC func_arg_expr opt_sort_clause ')'
   15780             :                 {
   15781         624 :                     FuncCall   *n = makeFuncCall($1, list_make1($4),
   15782             :                                                  COERCE_EXPLICIT_CALL,
   15783         624 :                                                  @1);
   15784             : 
   15785         624 :                     n->func_variadic = true;
   15786         624 :                     n->agg_order = $5;
   15787         624 :                     $$ = (Node *) n;
   15788             :                 }
   15789             :             | func_name '(' func_arg_list ',' VARIADIC func_arg_expr opt_sort_clause ')'
   15790             :                 {
   15791         168 :                     FuncCall   *n = makeFuncCall($1, lappend($3, $6),
   15792             :                                                  COERCE_EXPLICIT_CALL,
   15793         168 :                                                  @1);
   15794             : 
   15795         168 :                     n->func_variadic = true;
   15796         168 :                     n->agg_order = $7;
   15797         168 :                     $$ = (Node *) n;
   15798             :                 }
   15799             :             | func_name '(' ALL func_arg_list opt_sort_clause ')'
   15800             :                 {
   15801           0 :                     FuncCall   *n = makeFuncCall($1, $4,
   15802             :                                                  COERCE_EXPLICIT_CALL,
   15803           0 :                                                  @1);
   15804             : 
   15805           0 :                     n->agg_order = $5;
   15806             :                     /* Ideally we'd mark the FuncCall node to indicate
   15807             :                      * "must be an aggregate", but there's no provision
   15808             :                      * for that in FuncCall at the moment.
   15809             :                      */
   15810           0 :                     $$ = (Node *) n;
   15811             :                 }
   15812             :             | func_name '(' DISTINCT func_arg_list opt_sort_clause ')'
   15813             :                 {
   15814         550 :                     FuncCall   *n = makeFuncCall($1, $4,
   15815             :                                                  COERCE_EXPLICIT_CALL,
   15816         550 :                                                  @1);
   15817             : 
   15818         550 :                     n->agg_order = $5;
   15819         550 :                     n->agg_distinct = true;
   15820         550 :                     $$ = (Node *) n;
   15821             :                 }
   15822             :             | func_name '(' '*' ')'
   15823             :                 {
   15824             :                     /*
   15825             :                      * We consider AGGREGATE(*) to invoke a parameterless
   15826             :                      * aggregate.  This does the right thing for COUNT(*),
   15827             :                      * and there are no other aggregates in SQL that accept
   15828             :                      * '*' as parameter.
   15829             :                      *
   15830             :                      * The FuncCall node is also marked agg_star = true,
   15831             :                      * so that later processing can detect what the argument
   15832             :                      * really was.
   15833             :                      */
   15834       12862 :                     FuncCall   *n = makeFuncCall($1, NIL,
   15835             :                                                  COERCE_EXPLICIT_CALL,
   15836       12862 :                                                  @1);
   15837             : 
   15838       12860 :                     n->agg_star = true;
   15839       12860 :                     $$ = (Node *) n;
   15840             :                 }
   15841             :         ;
   15842             : 
   15843             : 
   15844             : /*
   15845             :  * func_expr and its cousin func_expr_windowless are split out from c_expr just
   15846             :  * so that we have classifications for "everything that is a function call or
   15847             :  * looks like one".  This isn't very important, but it saves us having to
   15848             :  * document which variants are legal in places like "FROM function()" or the
   15849             :  * backwards-compatible functional-index syntax for CREATE INDEX.
   15850             :  * (Note that many of the special SQL functions wouldn't actually make any
   15851             :  * sense as functional index entries, but we ignore that consideration here.)
   15852             :  */
   15853             : func_expr: func_application within_group_clause filter_clause null_treatment over_clause
   15854             :                 {
   15855      315728 :                     FuncCall   *n = (FuncCall *) $1;
   15856             : 
   15857             :                     /*
   15858             :                      * The order clause for WITHIN GROUP and the one for
   15859             :                      * plain-aggregate ORDER BY share a field, so we have to
   15860             :                      * check here that at most one is present.  We also check
   15861             :                      * for DISTINCT and VARIADIC here to give a better error
   15862             :                      * location.  Other consistency checks are deferred to
   15863             :                      * parse analysis.
   15864             :                      */
   15865      315728 :                     if ($2 != NIL)
   15866             :                     {
   15867         348 :                         if (n->agg_order != NIL)
   15868           6 :                             ereport(ERROR,
   15869             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15870             :                                      errmsg("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
   15871             :                                      parser_errposition(@2)));
   15872         342 :                         if (n->agg_distinct)
   15873           0 :                             ereport(ERROR,
   15874             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15875             :                                      errmsg("cannot use DISTINCT with WITHIN GROUP"),
   15876             :                                      parser_errposition(@2)));
   15877         342 :                         if (n->func_variadic)
   15878           0 :                             ereport(ERROR,
   15879             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15880             :                                      errmsg("cannot use VARIADIC with WITHIN GROUP"),
   15881             :                                      parser_errposition(@2)));
   15882         342 :                         n->agg_order = $2;
   15883         342 :                         n->agg_within_group = true;
   15884             :                     }
   15885      315722 :                     n->agg_filter = $3;
   15886      315722 :                     n->ignore_nulls = $4;
   15887      315722 :                     n->over = $5;
   15888      315722 :                     $$ = (Node *) n;
   15889             :                 }
   15890             :             | json_aggregate_func filter_clause over_clause
   15891             :                 {
   15892         720 :                     JsonAggConstructor *n = IsA($1, JsonObjectAgg) ?
   15893         360 :                         ((JsonObjectAgg *) $1)->constructor :
   15894         156 :                         ((JsonArrayAgg *) $1)->constructor;
   15895             : 
   15896         360 :                     n->agg_filter = $2;
   15897         360 :                     n->over = $3;
   15898         360 :                     $$ = (Node *) $1;
   15899             :                 }
   15900             :             | func_expr_common_subexpr
   15901       76386 :                 { $$ = $1; }
   15902             :         ;
   15903             : 
   15904             : /*
   15905             :  * Like func_expr but does not accept WINDOW functions directly
   15906             :  * (but they can still be contained in arguments for functions etc).
   15907             :  * Use this when window expressions are not allowed, where needed to
   15908             :  * disambiguate the grammar (e.g. in CREATE INDEX).
   15909             :  */
   15910             : func_expr_windowless:
   15911       48418 :             func_application                        { $$ = $1; }
   15912         402 :             | func_expr_common_subexpr              { $$ = $1; }
   15913           0 :             | json_aggregate_func                   { $$ = $1; }
   15914             :         ;
   15915             : 
   15916             : /*
   15917             :  * Special expressions that are considered to be functions.
   15918             :  */
   15919             : func_expr_common_subexpr:
   15920             :             COLLATION FOR '(' a_expr ')'
   15921             :                 {
   15922          30 :                     $$ = (Node *) makeFuncCall(SystemFuncName("pg_collation_for"),
   15923          30 :                                                list_make1($4),
   15924             :                                                COERCE_SQL_SYNTAX,
   15925          30 :                                                @1);
   15926             :                 }
   15927             :             | CURRENT_DATE
   15928             :                 {
   15929         308 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_DATE, -1, @1);
   15930             :                 }
   15931             :             | CURRENT_TIME
   15932             :                 {
   15933          24 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME, -1, @1);
   15934             :                 }
   15935             :             | CURRENT_TIME '(' Iconst ')'
   15936             :                 {
   15937          24 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME_N, $3, @1);
   15938             :                 }
   15939             :             | CURRENT_TIMESTAMP
   15940             :                 {
   15941         284 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP, -1, @1);
   15942             :                 }
   15943             :             | CURRENT_TIMESTAMP '(' Iconst ')'
   15944             :                 {
   15945         174 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP_N, $3, @1);
   15946             :                 }
   15947             :             | LOCALTIME
   15948             :                 {
   15949          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIME, -1, @1);
   15950             :                 }
   15951             :             | LOCALTIME '(' Iconst ')'
   15952             :                 {
   15953          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIME_N, $3, @1);
   15954             :                 }
   15955             :             | LOCALTIMESTAMP
   15956             :                 {
   15957          36 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP, -1, @1);
   15958             :                 }
   15959             :             | LOCALTIMESTAMP '(' Iconst ')'
   15960             :                 {
   15961          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP_N, $3, @1);
   15962             :                 }
   15963             :             | CURRENT_ROLE
   15964             :                 {
   15965          68 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_ROLE, -1, @1);
   15966             :                 }
   15967             :             | CURRENT_USER
   15968             :                 {
   15969        1060 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_USER, -1, @1);
   15970             :                 }
   15971             :             | SESSION_USER
   15972             :                 {
   15973         582 :                     $$ = makeSQLValueFunction(SVFOP_SESSION_USER, -1, @1);
   15974             :                 }
   15975             :             | SYSTEM_USER
   15976             :                 {
   15977          20 :                     $$ = (Node *) makeFuncCall(SystemFuncName("system_user"),
   15978             :                                                NIL,
   15979             :                                                COERCE_SQL_SYNTAX,
   15980             :                                                @1);
   15981             :                 }
   15982             :             | USER
   15983             :                 {
   15984          24 :                     $$ = makeSQLValueFunction(SVFOP_USER, -1, @1);
   15985             :                 }
   15986             :             | CURRENT_CATALOG
   15987             :                 {
   15988          60 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_CATALOG, -1, @1);
   15989             :                 }
   15990             :             | CURRENT_SCHEMA
   15991             :                 {
   15992          30 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_SCHEMA, -1, @1);
   15993             :                 }
   15994             :             | CAST '(' a_expr AS Typename ')'
   15995       62472 :                 { $$ = makeTypeCast($3, $5, @1); }
   15996             :             | EXTRACT '(' extract_list ')'
   15997             :                 {
   15998        1382 :                     $$ = (Node *) makeFuncCall(SystemFuncName("extract"),
   15999        1382 :                                                $3,
   16000             :                                                COERCE_SQL_SYNTAX,
   16001        1382 :                                                @1);
   16002             :                 }
   16003             :             | NORMALIZE '(' a_expr ')'
   16004             :                 {
   16005          18 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   16006          18 :                                                list_make1($3),
   16007             :                                                COERCE_SQL_SYNTAX,
   16008          18 :                                                @1);
   16009             :                 }
   16010             :             | NORMALIZE '(' a_expr ',' unicode_normal_form ')'
   16011             :                 {
   16012          42 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   16013          42 :                                                list_make2($3, makeStringConst($5, @5)),
   16014             :                                                COERCE_SQL_SYNTAX,
   16015          42 :                                                @1);
   16016             :                 }
   16017             :             | OVERLAY '(' overlay_list ')'
   16018             :                 {
   16019          82 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlay"),
   16020          82 :                                                $3,
   16021             :                                                COERCE_SQL_SYNTAX,
   16022          82 :                                                @1);
   16023             :                 }
   16024             :             | OVERLAY '(' func_arg_list_opt ')'
   16025             :                 {
   16026             :                     /*
   16027             :                      * allow functions named overlay() to be called without
   16028             :                      * special syntax
   16029             :                      */
   16030           0 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("overlay")),
   16031           0 :                                                $3,
   16032             :                                                COERCE_EXPLICIT_CALL,
   16033           0 :                                                @1);
   16034             :                 }
   16035             :             | POSITION '(' position_list ')'
   16036             :                 {
   16037             :                     /*
   16038             :                      * position(A in B) is converted to position(B, A)
   16039             :                      *
   16040             :                      * We deliberately don't offer a "plain syntax" option
   16041             :                      * for position(), because the reversal of the arguments
   16042             :                      * creates too much risk of confusion.
   16043             :                      */
   16044         400 :                     $$ = (Node *) makeFuncCall(SystemFuncName("position"),
   16045         400 :                                                $3,
   16046             :                                                COERCE_SQL_SYNTAX,
   16047         400 :                                                @1);
   16048             :                 }
   16049             :             | SUBSTRING '(' substr_list ')'
   16050             :                 {
   16051             :                     /* substring(A from B for C) is converted to
   16052             :                      * substring(A, B, C) - thomas 2000-11-28
   16053             :                      */
   16054         710 :                     $$ = (Node *) makeFuncCall(SystemFuncName("substring"),
   16055         710 :                                                $3,
   16056             :                                                COERCE_SQL_SYNTAX,
   16057         710 :                                                @1);
   16058             :                 }
   16059             :             | SUBSTRING '(' func_arg_list_opt ')'
   16060             :                 {
   16061             :                     /*
   16062             :                      * allow functions named substring() to be called without
   16063             :                      * special syntax
   16064             :                      */
   16065         252 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("substring")),
   16066         252 :                                                $3,
   16067             :                                                COERCE_EXPLICIT_CALL,
   16068         252 :                                                @1);
   16069             :                 }
   16070             :             | TREAT '(' a_expr AS Typename ')'
   16071             :                 {
   16072             :                     /* TREAT(expr AS target) converts expr of a particular type to target,
   16073             :                      * which is defined to be a subtype of the original expression.
   16074             :                      * In SQL99, this is intended for use with structured UDTs,
   16075             :                      * but let's make this a generally useful form allowing stronger
   16076             :                      * coercions than are handled by implicit casting.
   16077             :                      *
   16078             :                      * Convert SystemTypeName() to SystemFuncName() even though
   16079             :                      * at the moment they result in the same thing.
   16080             :                      */
   16081           0 :                     $$ = (Node *) makeFuncCall(SystemFuncName(strVal(llast($5->names))),
   16082           0 :                                                list_make1($3),
   16083             :                                                COERCE_EXPLICIT_CALL,
   16084           0 :                                                @1);
   16085             :                 }
   16086             :             | TRIM '(' BOTH trim_list ')'
   16087             :                 {
   16088             :                     /* various trim expressions are defined in SQL
   16089             :                      * - thomas 1997-07-19
   16090             :                      */
   16091          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   16092          12 :                                                $4,
   16093             :                                                COERCE_SQL_SYNTAX,
   16094          12 :                                                @1);
   16095             :                 }
   16096             :             | TRIM '(' LEADING trim_list ')'
   16097             :                 {
   16098          24 :                     $$ = (Node *) makeFuncCall(SystemFuncName("ltrim"),
   16099          24 :                                                $4,
   16100             :                                                COERCE_SQL_SYNTAX,
   16101          24 :                                                @1);
   16102             :                 }
   16103             :             | TRIM '(' TRAILING trim_list ')'
   16104             :                 {
   16105         582 :                     $$ = (Node *) makeFuncCall(SystemFuncName("rtrim"),
   16106         582 :                                                $4,
   16107             :                                                COERCE_SQL_SYNTAX,
   16108         582 :                                                @1);
   16109             :                 }
   16110             :             | TRIM '(' trim_list ')'
   16111             :                 {
   16112          98 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   16113          98 :                                                $3,
   16114             :                                                COERCE_SQL_SYNTAX,
   16115          98 :                                                @1);
   16116             :                 }
   16117             :             | NULLIF '(' a_expr ',' a_expr ')'
   16118             :                 {
   16119         386 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
   16120             :                 }
   16121             :             | COALESCE '(' expr_list ')'
   16122             :                 {
   16123        3240 :                     CoalesceExpr *c = makeNode(CoalesceExpr);
   16124             : 
   16125        3240 :                     c->args = $3;
   16126        3240 :                     c->location = @1;
   16127        3240 :                     $$ = (Node *) c;
   16128             :                 }
   16129             :             | GREATEST '(' expr_list ')'
   16130             :                 {
   16131         146 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   16132             : 
   16133         146 :                     v->args = $3;
   16134         146 :                     v->op = IS_GREATEST;
   16135         146 :                     v->location = @1;
   16136         146 :                     $$ = (Node *) v;
   16137             :                 }
   16138             :             | LEAST '(' expr_list ')'
   16139             :                 {
   16140         148 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   16141             : 
   16142         148 :                     v->args = $3;
   16143         148 :                     v->op = IS_LEAST;
   16144         148 :                     v->location = @1;
   16145         148 :                     $$ = (Node *) v;
   16146             :                 }
   16147             :             | XMLCONCAT '(' expr_list ')'
   16148             :                 {
   16149          62 :                     $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
   16150             :                 }
   16151             :             | XMLELEMENT '(' NAME_P ColLabel ')'
   16152             :                 {
   16153           6 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
   16154             :                 }
   16155             :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
   16156             :                 {
   16157          36 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
   16158             :                 }
   16159             :             | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
   16160             :                 {
   16161         116 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
   16162             :                 }
   16163             :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
   16164             :                 {
   16165          20 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
   16166             :                 }
   16167             :             | XMLEXISTS '(' c_expr xmlexists_argument ')'
   16168             :                 {
   16169             :                     /* xmlexists(A PASSING [BY REF] B [BY REF]) is
   16170             :                      * converted to xmlexists(A, B)*/
   16171          54 :                     $$ = (Node *) makeFuncCall(SystemFuncName("xmlexists"),
   16172          54 :                                                list_make2($3, $4),
   16173             :                                                COERCE_SQL_SYNTAX,
   16174          54 :                                                @1);
   16175             :                 }
   16176             :             | XMLFOREST '(' xml_attribute_list ')'
   16177             :                 {
   16178          32 :                     $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
   16179             :                 }
   16180             :             | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
   16181             :                 {
   16182             :                     XmlExpr *x = (XmlExpr *)
   16183         140 :                         makeXmlExpr(IS_XMLPARSE, NULL, NIL,
   16184         140 :                                     list_make2($4, makeBoolAConst($5, -1)),
   16185         140 :                                     @1);
   16186             : 
   16187         140 :                     x->xmloption = $3;
   16188         140 :                     $$ = (Node *) x;
   16189             :                 }
   16190             :             | XMLPI '(' NAME_P ColLabel ')'
   16191             :                 {
   16192          30 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
   16193             :                 }
   16194             :             | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
   16195             :                 {
   16196          50 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
   16197             :                 }
   16198             :             | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
   16199             :                 {
   16200          68 :                     $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
   16201          68 :                                      list_make3($3, $5, $6), @1);
   16202             :                 }
   16203             :             | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename xml_indent_option ')'
   16204             :                 {
   16205         218 :                     XmlSerialize *n = makeNode(XmlSerialize);
   16206             : 
   16207         218 :                     n->xmloption = $3;
   16208         218 :                     n->expr = $4;
   16209         218 :                     n->typeName = $6;
   16210         218 :                     n->indent = $7;
   16211         218 :                     n->location = @1;
   16212         218 :                     $$ = (Node *) n;
   16213             :                 }
   16214             :             | JSON_OBJECT '(' func_arg_list ')'
   16215             :                 {
   16216             :                     /* Support for legacy (non-standard) json_object() */
   16217          90 :                     $$ = (Node *) makeFuncCall(SystemFuncName("json_object"),
   16218          90 :                                                $3, COERCE_EXPLICIT_CALL, @1);
   16219             :                 }
   16220             :             | JSON_OBJECT '(' json_name_and_value_list
   16221             :                 json_object_constructor_null_clause_opt
   16222             :                 json_key_uniqueness_constraint_opt
   16223             :                 json_returning_clause_opt ')'
   16224             :                 {
   16225         348 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   16226             : 
   16227         348 :                     n->exprs = $3;
   16228         348 :                     n->absent_on_null = $4;
   16229         348 :                     n->unique = $5;
   16230         348 :                     n->output = (JsonOutput *) $6;
   16231         348 :                     n->location = @1;
   16232         348 :                     $$ = (Node *) n;
   16233             :                 }
   16234             :             | JSON_OBJECT '(' json_returning_clause_opt ')'
   16235             :                 {
   16236          92 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   16237             : 
   16238          92 :                     n->exprs = NULL;
   16239          92 :                     n->absent_on_null = false;
   16240          92 :                     n->unique = false;
   16241          92 :                     n->output = (JsonOutput *) $3;
   16242          92 :                     n->location = @1;
   16243          92 :                     $$ = (Node *) n;
   16244             :                 }
   16245             :             | JSON_ARRAY '('
   16246             :                 json_value_expr_list
   16247             :                 json_array_constructor_null_clause_opt
   16248             :                 json_returning_clause_opt
   16249             :             ')'
   16250             :                 {
   16251         120 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   16252             : 
   16253         120 :                     n->exprs = $3;
   16254         120 :                     n->absent_on_null = $4;
   16255         120 :                     n->output = (JsonOutput *) $5;
   16256         120 :                     n->location = @1;
   16257         120 :                     $$ = (Node *) n;
   16258             :                 }
   16259             :             | JSON_ARRAY '('
   16260             :                 select_no_parens
   16261             :                 json_format_clause_opt
   16262             :                 /* json_array_constructor_null_clause_opt */
   16263             :                 json_returning_clause_opt
   16264             :             ')'
   16265             :                 {
   16266          60 :                     JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
   16267             : 
   16268          60 :                     n->query = $3;
   16269          60 :                     n->format = (JsonFormat *) $4;
   16270          60 :                     n->absent_on_null = true;    /* XXX */
   16271          60 :                     n->output = (JsonOutput *) $5;
   16272          60 :                     n->location = @1;
   16273          60 :                     $$ = (Node *) n;
   16274             :                 }
   16275             :             | JSON_ARRAY '('
   16276             :                 json_returning_clause_opt
   16277             :             ')'
   16278             :                 {
   16279          86 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   16280             : 
   16281          86 :                     n->exprs = NIL;
   16282          86 :                     n->absent_on_null = true;
   16283          86 :                     n->output = (JsonOutput *) $3;
   16284          86 :                     n->location = @1;
   16285          86 :                     $$ = (Node *) n;
   16286             :                 }
   16287             :             | JSON '(' json_value_expr json_key_uniqueness_constraint_opt ')'
   16288             :                 {
   16289         164 :                     JsonParseExpr *n = makeNode(JsonParseExpr);
   16290             : 
   16291         164 :                     n->expr = (JsonValueExpr *) $3;
   16292         164 :                     n->unique_keys = $4;
   16293         164 :                     n->output = NULL;
   16294         164 :                     n->location = @1;
   16295         164 :                     $$ = (Node *) n;
   16296             :                 }
   16297             :             | JSON_SCALAR '(' a_expr ')'
   16298             :                 {
   16299         112 :                     JsonScalarExpr *n = makeNode(JsonScalarExpr);
   16300             : 
   16301         112 :                     n->expr = (Expr *) $3;
   16302         112 :                     n->output = NULL;
   16303         112 :                     n->location = @1;
   16304         112 :                     $$ = (Node *) n;
   16305             :                 }
   16306             :             | JSON_SERIALIZE '(' json_value_expr json_returning_clause_opt ')'
   16307             :                 {
   16308         108 :                     JsonSerializeExpr *n = makeNode(JsonSerializeExpr);
   16309             : 
   16310         108 :                     n->expr = (JsonValueExpr *) $3;
   16311         108 :                     n->output = (JsonOutput *) $4;
   16312         108 :                     n->location = @1;
   16313         108 :                     $$ = (Node *) n;
   16314             :                 }
   16315             :             | MERGE_ACTION '(' ')'
   16316             :                 {
   16317         210 :                     MergeSupportFunc *m = makeNode(MergeSupportFunc);
   16318             : 
   16319         210 :                     m->msftype = TEXTOID;
   16320         210 :                     m->location = @1;
   16321         210 :                     $$ = (Node *) m;
   16322             :                 }
   16323             :             | JSON_QUERY '('
   16324             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16325             :                 json_returning_clause_opt
   16326             :                 json_wrapper_behavior
   16327             :                 json_quotes_clause_opt
   16328             :                 json_behavior_clause_opt
   16329             :             ')'
   16330             :                 {
   16331         984 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16332             : 
   16333         984 :                     n->op = JSON_QUERY_OP;
   16334         984 :                     n->context_item = (JsonValueExpr *) $3;
   16335         984 :                     n->pathspec = $5;
   16336         984 :                     n->passing = $6;
   16337         984 :                     n->output = (JsonOutput *) $7;
   16338         984 :                     n->wrapper = $8;
   16339         984 :                     n->quotes = $9;
   16340         984 :                     n->on_empty = (JsonBehavior *) linitial($10);
   16341         984 :                     n->on_error = (JsonBehavior *) lsecond($10);
   16342         984 :                     n->location = @1;
   16343         984 :                     $$ = (Node *) n;
   16344             :                 }
   16345             :             | JSON_EXISTS '('
   16346             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16347             :                 json_on_error_clause_opt
   16348             :             ')'
   16349             :                 {
   16350         168 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16351             : 
   16352         168 :                     n->op = JSON_EXISTS_OP;
   16353         168 :                     n->context_item = (JsonValueExpr *) $3;
   16354         168 :                     n->pathspec = $5;
   16355         168 :                     n->passing = $6;
   16356         168 :                     n->output = NULL;
   16357         168 :                     n->on_error = (JsonBehavior *) $7;
   16358         168 :                     n->location = @1;
   16359         168 :                     $$ = (Node *) n;
   16360             :                 }
   16361             :             | JSON_VALUE '('
   16362             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16363             :                 json_returning_clause_opt
   16364             :                 json_behavior_clause_opt
   16365             :             ')'
   16366             :                 {
   16367         624 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16368             : 
   16369         624 :                     n->op = JSON_VALUE_OP;
   16370         624 :                     n->context_item = (JsonValueExpr *) $3;
   16371         624 :                     n->pathspec = $5;
   16372         624 :                     n->passing = $6;
   16373         624 :                     n->output = (JsonOutput *) $7;
   16374         624 :                     n->on_empty = (JsonBehavior *) linitial($8);
   16375         624 :                     n->on_error = (JsonBehavior *) lsecond($8);
   16376         624 :                     n->location = @1;
   16377         624 :                     $$ = (Node *) n;
   16378             :                 }
   16379             :             ;
   16380             : 
   16381             : 
   16382             : /*
   16383             :  * SQL/XML support
   16384             :  */
   16385             : xml_root_version: VERSION_P a_expr
   16386          24 :                 { $$ = $2; }
   16387             :             | VERSION_P NO VALUE_P
   16388          44 :                 { $$ = makeNullAConst(-1); }
   16389             :         ;
   16390             : 
   16391             : opt_xml_root_standalone: ',' STANDALONE_P YES_P
   16392          26 :                 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
   16393             :             | ',' STANDALONE_P NO
   16394          12 :                 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
   16395             :             | ',' STANDALONE_P NO VALUE_P
   16396          12 :                 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
   16397             :             | /*EMPTY*/
   16398          18 :                 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
   16399             :         ;
   16400             : 
   16401          56 : xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')'    { $$ = $3; }
   16402             :         ;
   16403             : 
   16404          88 : xml_attribute_list: xml_attribute_el                    { $$ = list_make1($1); }
   16405         144 :             | xml_attribute_list ',' xml_attribute_el   { $$ = lappend($1, $3); }
   16406             :         ;
   16407             : 
   16408             : xml_attribute_el: a_expr AS ColLabel
   16409             :                 {
   16410         106 :                     $$ = makeNode(ResTarget);
   16411         106 :                     $$->name = $3;
   16412         106 :                     $$->indirection = NIL;
   16413         106 :                     $$->val = (Node *) $1;
   16414         106 :                     $$->location = @1;
   16415             :                 }
   16416             :             | a_expr
   16417             :                 {
   16418         126 :                     $$ = makeNode(ResTarget);
   16419         126 :                     $$->name = NULL;
   16420         126 :                     $$->indirection = NIL;
   16421         126 :                     $$->val = (Node *) $1;
   16422         126 :                     $$->location = @1;
   16423             :                 }
   16424             :         ;
   16425             : 
   16426         186 : document_or_content: DOCUMENT_P                     { $$ = XMLOPTION_DOCUMENT; }
   16427         188 :             | CONTENT_P                             { $$ = XMLOPTION_CONTENT; }
   16428             :         ;
   16429             : 
   16430         140 : xml_indent_option: INDENT                           { $$ = true; }
   16431          36 :             | NO INDENT                             { $$ = false; }
   16432          42 :             | /*EMPTY*/                             { $$ = false; }
   16433             :         ;
   16434             : 
   16435           0 : xml_whitespace_option: PRESERVE WHITESPACE_P        { $$ = true; }
   16436           2 :             | STRIP_P WHITESPACE_P                  { $$ = false; }
   16437         138 :             | /*EMPTY*/                             { $$ = false; }
   16438             :         ;
   16439             : 
   16440             : /* We allow several variants for SQL and other compatibility. */
   16441             : xmlexists_argument:
   16442             :             PASSING c_expr
   16443             :                 {
   16444         238 :                     $$ = $2;
   16445             :                 }
   16446             :             | PASSING c_expr xml_passing_mech
   16447             :                 {
   16448           0 :                     $$ = $2;
   16449             :                 }
   16450             :             | PASSING xml_passing_mech c_expr
   16451             :                 {
   16452          42 :                     $$ = $3;
   16453             :                 }
   16454             :             | PASSING xml_passing_mech c_expr xml_passing_mech
   16455             :                 {
   16456           6 :                     $$ = $3;
   16457             :                 }
   16458             :         ;
   16459             : 
   16460             : xml_passing_mech:
   16461             :             BY REF_P
   16462             :             | BY VALUE_P
   16463             :         ;
   16464             : 
   16465             : 
   16466             : /*
   16467             :  * Aggregate decoration clauses
   16468             :  */
   16469             : within_group_clause:
   16470         348 :             WITHIN GROUP_P '(' sort_clause ')'      { $$ = $4; }
   16471      315386 :             | /*EMPTY*/                             { $$ = NIL; }
   16472             :         ;
   16473             : 
   16474             : filter_clause:
   16475         862 :             FILTER '(' WHERE a_expr ')'             { $$ = $4; }
   16476      315232 :             | /*EMPTY*/                             { $$ = NULL; }
   16477             :         ;
   16478             : 
   16479             : 
   16480             : /*
   16481             :  * Window Definitions
   16482             :  */
   16483             : null_treatment:
   16484         198 :             IGNORE_P NULLS_P                        { $$ = PARSER_IGNORE_NULLS; }
   16485          96 :             | RESPECT_P NULLS_P                     { $$ = PARSER_RESPECT_NULLS; }
   16486      315440 :             | /*EMPTY*/                             { $$ = NO_NULLTREATMENT; }
   16487             :         ;
   16488             : 
   16489             : window_clause:
   16490         606 :             WINDOW window_definition_list           { $$ = $2; }
   16491      473868 :             | /*EMPTY*/                             { $$ = NIL; }
   16492             :         ;
   16493             : 
   16494             : window_definition_list:
   16495         606 :             window_definition                       { $$ = list_make1($1); }
   16496             :             | window_definition_list ',' window_definition
   16497          30 :                                                     { $$ = lappend($1, $3); }
   16498             :         ;
   16499             : 
   16500             : window_definition:
   16501             :             ColId AS window_specification
   16502             :                 {
   16503         636 :                     WindowDef  *n = $3;
   16504             : 
   16505         636 :                     n->name = $1;
   16506         636 :                     $$ = n;
   16507             :                 }
   16508             :         ;
   16509             : 
   16510             : over_clause: OVER window_specification
   16511        2754 :                 { $$ = $2; }
   16512             :             | OVER ColId
   16513             :                 {
   16514        1182 :                     WindowDef  *n = makeNode(WindowDef);
   16515             : 
   16516        1182 :                     n->name = $2;
   16517        1182 :                     n->refname = NULL;
   16518        1182 :                     n->partitionClause = NIL;
   16519        1182 :                     n->orderClause = NIL;
   16520        1182 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   16521        1182 :                     n->startOffset = NULL;
   16522        1182 :                     n->endOffset = NULL;
   16523        1182 :                     n->location = @2;
   16524        1182 :                     $$ = n;
   16525             :                 }
   16526             :             | /*EMPTY*/
   16527      312152 :                 { $$ = NULL; }
   16528             :         ;
   16529             : 
   16530             : window_specification: '(' opt_existing_window_name opt_partition_clause
   16531             :                         opt_sort_clause opt_frame_clause ')'
   16532             :                 {
   16533        3390 :                     WindowDef  *n = makeNode(WindowDef);
   16534             : 
   16535        3390 :                     n->name = NULL;
   16536        3390 :                     n->refname = $2;
   16537        3390 :                     n->partitionClause = $3;
   16538        3390 :                     n->orderClause = $4;
   16539             :                     /* copy relevant fields of opt_frame_clause */
   16540        3390 :                     n->frameOptions = $5->frameOptions;
   16541        3390 :                     n->startOffset = $5->startOffset;
   16542        3390 :                     n->endOffset = $5->endOffset;
   16543        3390 :                     n->location = @1;
   16544        3390 :                     $$ = n;
   16545             :                 }
   16546             :         ;
   16547             : 
   16548             : /*
   16549             :  * If we see PARTITION, RANGE, ROWS or GROUPS as the first token after the '('
   16550             :  * of a window_specification, we want the assumption to be that there is
   16551             :  * no existing_window_name; but those keywords are unreserved and so could
   16552             :  * be ColIds.  We fix this by making them have the same precedence as IDENT
   16553             :  * and giving the empty production here a slightly higher precedence, so
   16554             :  * that the shift/reduce conflict is resolved in favor of reducing the rule.
   16555             :  * These keywords are thus precluded from being an existing_window_name but
   16556             :  * are not reserved for any other purpose.
   16557             :  */
   16558          54 : opt_existing_window_name: ColId                     { $$ = $1; }
   16559        3342 :             | /*EMPTY*/             %prec Op        { $$ = NULL; }
   16560             :         ;
   16561             : 
   16562         932 : opt_partition_clause: PARTITION BY expr_list        { $$ = $3; }
   16563        2458 :             | /*EMPTY*/                             { $$ = NIL; }
   16564             :         ;
   16565             : 
   16566             : /*
   16567             :  * For frame clauses, we return a WindowDef, but only some fields are used:
   16568             :  * frameOptions, startOffset, and endOffset.
   16569             :  */
   16570             : opt_frame_clause:
   16571             :             RANGE frame_extent opt_window_exclusion_clause
   16572             :                 {
   16573         796 :                     WindowDef  *n = $2;
   16574             : 
   16575         796 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
   16576         796 :                     n->frameOptions |= $3;
   16577         796 :                     $$ = n;
   16578             :                 }
   16579             :             | ROWS frame_extent opt_window_exclusion_clause
   16580             :                 {
   16581         690 :                     WindowDef  *n = $2;
   16582             : 
   16583         690 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
   16584         690 :                     n->frameOptions |= $3;
   16585         690 :                     $$ = n;
   16586             :                 }
   16587             :             | GROUPS frame_extent opt_window_exclusion_clause
   16588             :                 {
   16589         204 :                     WindowDef  *n = $2;
   16590             : 
   16591         204 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_GROUPS;
   16592         204 :                     n->frameOptions |= $3;
   16593         204 :                     $$ = n;
   16594             :                 }
   16595             :             | /*EMPTY*/
   16596             :                 {
   16597        1700 :                     WindowDef  *n = makeNode(WindowDef);
   16598             : 
   16599        1700 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   16600        1700 :                     n->startOffset = NULL;
   16601        1700 :                     n->endOffset = NULL;
   16602        1700 :                     $$ = n;
   16603             :                 }
   16604             :         ;
   16605             : 
   16606             : frame_extent: frame_bound
   16607             :                 {
   16608          12 :                     WindowDef  *n = $1;
   16609             : 
   16610             :                     /* reject invalid cases */
   16611          12 :                     if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   16612           0 :                         ereport(ERROR,
   16613             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16614             :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   16615             :                                  parser_errposition(@1)));
   16616          12 :                     if (n->frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING)
   16617           0 :                         ereport(ERROR,
   16618             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16619             :                                  errmsg("frame starting from following row cannot end with current row"),
   16620             :                                  parser_errposition(@1)));
   16621          12 :                     n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
   16622          12 :                     $$ = n;
   16623             :                 }
   16624             :             | BETWEEN frame_bound AND frame_bound
   16625             :                 {
   16626        1678 :                     WindowDef  *n1 = $2;
   16627        1678 :                     WindowDef  *n2 = $4;
   16628             : 
   16629             :                     /* form merged options */
   16630        1678 :                     int     frameOptions = n1->frameOptions;
   16631             :                     /* shift converts START_ options to END_ options */
   16632        1678 :                     frameOptions |= n2->frameOptions << 1;
   16633        1678 :                     frameOptions |= FRAMEOPTION_BETWEEN;
   16634             :                     /* reject invalid cases */
   16635        1678 :                     if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   16636           0 :                         ereport(ERROR,
   16637             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16638             :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   16639             :                                  parser_errposition(@2)));
   16640        1678 :                     if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
   16641           0 :                         ereport(ERROR,
   16642             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16643             :                                  errmsg("frame end cannot be UNBOUNDED PRECEDING"),
   16644             :                                  parser_errposition(@4)));
   16645        1678 :                     if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
   16646         460 :                         (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING))
   16647           0 :                         ereport(ERROR,
   16648             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16649             :                                  errmsg("frame starting from current row cannot have preceding rows"),
   16650             :                                  parser_errposition(@4)));
   16651        1678 :                     if ((frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING) &&
   16652         168 :                         (frameOptions & (FRAMEOPTION_END_OFFSET_PRECEDING |
   16653             :                                          FRAMEOPTION_END_CURRENT_ROW)))
   16654           0 :                         ereport(ERROR,
   16655             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16656             :                                  errmsg("frame starting from following row cannot have preceding rows"),
   16657             :                                  parser_errposition(@4)));
   16658        1678 :                     n1->frameOptions = frameOptions;
   16659        1678 :                     n1->endOffset = n2->startOffset;
   16660        1678 :                     $$ = n1;
   16661             :                 }
   16662             :         ;
   16663             : 
   16664             : /*
   16665             :  * This is used for both frame start and frame end, with output set up on
   16666             :  * the assumption it's frame start; the frame_extent productions must reject
   16667             :  * invalid cases.
   16668             :  */
   16669             : frame_bound:
   16670             :             UNBOUNDED PRECEDING
   16671             :                 {
   16672         216 :                     WindowDef  *n = makeNode(WindowDef);
   16673             : 
   16674         216 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
   16675         216 :                     n->startOffset = NULL;
   16676         216 :                     n->endOffset = NULL;
   16677         216 :                     $$ = n;
   16678             :                 }
   16679             :             | UNBOUNDED FOLLOWING
   16680             :                 {
   16681         394 :                     WindowDef  *n = makeNode(WindowDef);
   16682             : 
   16683         394 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
   16684         394 :                     n->startOffset = NULL;
   16685         394 :                     n->endOffset = NULL;
   16686         394 :                     $$ = n;
   16687             :                 }
   16688             :             | CURRENT_P ROW
   16689             :                 {
   16690         604 :                     WindowDef  *n = makeNode(WindowDef);
   16691             : 
   16692         604 :                     n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
   16693         604 :                     n->startOffset = NULL;
   16694         604 :                     n->endOffset = NULL;
   16695         604 :                     $$ = n;
   16696             :                 }
   16697             :             | a_expr PRECEDING
   16698             :                 {
   16699         954 :                     WindowDef  *n = makeNode(WindowDef);
   16700             : 
   16701         954 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_PRECEDING;
   16702         954 :                     n->startOffset = $1;
   16703         954 :                     n->endOffset = NULL;
   16704         954 :                     $$ = n;
   16705             :                 }
   16706             :             | a_expr FOLLOWING
   16707             :                 {
   16708        1200 :                     WindowDef  *n = makeNode(WindowDef);
   16709             : 
   16710        1200 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_FOLLOWING;
   16711        1200 :                     n->startOffset = $1;
   16712        1200 :                     n->endOffset = NULL;
   16713        1200 :                     $$ = n;
   16714             :                 }
   16715             :         ;
   16716             : 
   16717             : opt_window_exclusion_clause:
   16718          96 :             EXCLUDE CURRENT_P ROW   { $$ = FRAMEOPTION_EXCLUDE_CURRENT_ROW; }
   16719          96 :             | EXCLUDE GROUP_P       { $$ = FRAMEOPTION_EXCLUDE_GROUP; }
   16720         150 :             | EXCLUDE TIES          { $$ = FRAMEOPTION_EXCLUDE_TIES; }
   16721          18 :             | EXCLUDE NO OTHERS     { $$ = 0; }
   16722        1330 :             | /*EMPTY*/             { $$ = 0; }
   16723             :         ;
   16724             : 
   16725             : 
   16726             : /*
   16727             :  * Supporting nonterminals for expressions.
   16728             :  */
   16729             : 
   16730             : /* Explicit row production.
   16731             :  *
   16732             :  * SQL99 allows an optional ROW keyword, so we can now do single-element rows
   16733             :  * without conflicting with the parenthesized a_expr production.  Without the
   16734             :  * ROW keyword, there must be more than one a_expr inside the parens.
   16735             :  */
   16736           0 : row:        ROW '(' expr_list ')'                   { $$ = $3; }
   16737           0 :             | ROW '(' ')'                           { $$ = NIL; }
   16738        1932 :             | '(' expr_list ',' a_expr ')'          { $$ = lappend($2, $4); }
   16739             :         ;
   16740             : 
   16741        3792 : explicit_row:   ROW '(' expr_list ')'               { $$ = $3; }
   16742          36 :             | ROW '(' ')'                           { $$ = NIL; }
   16743             :         ;
   16744             : 
   16745        2706 : implicit_row:   '(' expr_list ',' a_expr ')'        { $$ = lappend($2, $4); }
   16746             :         ;
   16747             : 
   16748       16682 : sub_type:   ANY                                     { $$ = ANY_SUBLINK; }
   16749           0 :             | SOME                                  { $$ = ANY_SUBLINK; }
   16750         324 :             | ALL                                   { $$ = ALL_SUBLINK; }
   16751             :         ;
   16752             : 
   16753       11408 : all_Op:     Op                                      { $$ = $1; }
   16754       29206 :             | MathOp                                { $$ = $1; }
   16755             :         ;
   16756             : 
   16757          40 : MathOp:      '+'                                    { $$ = "+"; }
   16758          66 :             | '-'                                   { $$ = "-"; }
   16759         150 :             | '*'                                   { $$ = "*"; }
   16760           0 :             | '/'                                   { $$ = "/"; }
   16761           8 :             | '%'                                   { $$ = "%"; }
   16762           0 :             | '^'                                   { $$ = "^"; }
   16763         978 :             | '<'                                    { $$ = "<"; }
   16764         880 :             | '>'                                    { $$ = ">"; }
   16765       24620 :             | '='                                   { $$ = "="; }
   16766         844 :             | LESS_EQUALS                           { $$ = "<="; }
   16767         836 :             | GREATER_EQUALS                        { $$ = ">="; }
   16768         784 :             | NOT_EQUALS                            { $$ = "<>"; }
   16769             :         ;
   16770             : 
   16771             : qual_Op:    Op
   16772       43816 :                     { $$ = list_make1(makeString($1)); }
   16773             :             | OPERATOR '(' any_operator ')'
   16774       15798 :                     { $$ = $3; }
   16775             :         ;
   16776             : 
   16777             : qual_all_Op:
   16778             :             all_Op
   16779        1416 :                     { $$ = list_make1(makeString($1)); }
   16780             :             | OPERATOR '(' any_operator ')'
   16781          34 :                     { $$ = $3; }
   16782             :         ;
   16783             : 
   16784             : subquery_Op:
   16785             :             all_Op
   16786       16702 :                     { $$ = list_make1(makeString($1)); }
   16787             :             | OPERATOR '(' any_operator ')'
   16788         272 :                     { $$ = $3; }
   16789             :             | LIKE
   16790          24 :                     { $$ = list_make1(makeString("~~")); }
   16791             :             | NOT_LA LIKE
   16792          12 :                     { $$ = list_make1(makeString("!~~")); }
   16793             :             | ILIKE
   16794          12 :                     { $$ = list_make1(makeString("~~*")); }
   16795             :             | NOT_LA ILIKE
   16796           0 :                     { $$ = list_make1(makeString("!~~*")); }
   16797             : /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
   16798             :  * the regular expression is preprocessed by a function (similar_to_escape),
   16799             :  * and the ~ operator for posix regular expressions is used.
   16800             :  *        x SIMILAR TO y     ->    x ~ similar_to_escape(y)
   16801             :  * this transformation is made on the fly by the parser upwards.
   16802             :  * however the SubLink structure which handles any/some/all stuff
   16803             :  * is not ready for such a thing.
   16804             :  */
   16805             :             ;
   16806             : 
   16807             : expr_list:  a_expr
   16808             :                 {
   16809      161648 :                     $$ = list_make1($1);
   16810             :                 }
   16811             :             | expr_list ',' a_expr
   16812             :                 {
   16813      146320 :                     $$ = lappend($1, $3);
   16814             :                 }
   16815             :         ;
   16816             : 
   16817             : /* function arguments can have names */
   16818             : func_arg_list:  func_arg_expr
   16819             :                 {
   16820      318726 :                     $$ = list_make1($1);
   16821             :                 }
   16822             :             | func_arg_list ',' func_arg_expr
   16823             :                 {
   16824      280790 :                     $$ = lappend($1, $3);
   16825             :                 }
   16826             :         ;
   16827             : 
   16828             : func_arg_expr:  a_expr
   16829             :                 {
   16830      553108 :                     $$ = $1;
   16831             :                 }
   16832             :             | param_name COLON_EQUALS a_expr
   16833             :                 {
   16834       45504 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   16835             : 
   16836       45504 :                     na->name = $1;
   16837       45504 :                     na->arg = (Expr *) $3;
   16838       45504 :                     na->argnumber = -1;      /* until determined */
   16839       45504 :                     na->location = @1;
   16840       45504 :                     $$ = (Node *) na;
   16841             :                 }
   16842             :             | param_name EQUALS_GREATER a_expr
   16843             :                 {
   16844        1696 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   16845             : 
   16846        1696 :                     na->name = $1;
   16847        1696 :                     na->arg = (Expr *) $3;
   16848        1696 :                     na->argnumber = -1;      /* until determined */
   16849        1696 :                     na->location = @1;
   16850        1696 :                     $$ = (Node *) na;
   16851             :                 }
   16852             :         ;
   16853             : 
   16854         252 : func_arg_list_opt:  func_arg_list                   { $$ = $1; }
   16855           0 :             | /*EMPTY*/                             { $$ = NIL; }
   16856             :         ;
   16857             : 
   16858        2296 : type_list:  Typename                                { $$ = list_make1($1); }
   16859         944 :             | type_list ',' Typename                { $$ = lappend($1, $3); }
   16860             :         ;
   16861             : 
   16862             : array_expr: '[' expr_list ']'
   16863             :                 {
   16864        7708 :                     $$ = makeAArrayExpr($2, @1, @3);
   16865             :                 }
   16866             :             | '[' array_expr_list ']'
   16867             :                 {
   16868         412 :                     $$ = makeAArrayExpr($2, @1, @3);
   16869             :                 }
   16870             :             | '[' ']'
   16871             :                 {
   16872          98 :                     $$ = makeAArrayExpr(NIL, @1, @2);
   16873             :                 }
   16874             :         ;
   16875             : 
   16876         412 : array_expr_list: array_expr                         { $$ = list_make1($1); }
   16877         342 :             | array_expr_list ',' array_expr        { $$ = lappend($1, $3); }
   16878             :         ;
   16879             : 
   16880             : 
   16881             : extract_list:
   16882             :             extract_arg FROM a_expr
   16883             :                 {
   16884        1382 :                     $$ = list_make2(makeStringConst($1, @1), $3);
   16885             :                 }
   16886             :         ;
   16887             : 
   16888             : /* Allow delimited string Sconst in extract_arg as an SQL extension.
   16889             :  * - thomas 2001-04-12
   16890             :  */
   16891             : extract_arg:
   16892        1124 :             IDENT                                   { $$ = $1; }
   16893          72 :             | YEAR_P                                { $$ = "year"; }
   16894          42 :             | MONTH_P                               { $$ = "month"; }
   16895          54 :             | DAY_P                                 { $$ = "day"; }
   16896          30 :             | HOUR_P                                { $$ = "hour"; }
   16897          30 :             | MINUTE_P                              { $$ = "minute"; }
   16898          30 :             | SECOND_P                              { $$ = "second"; }
   16899           0 :             | Sconst                                { $$ = $1; }
   16900             :         ;
   16901             : 
   16902             : unicode_normal_form:
   16903          24 :             NFC                                     { $$ = "NFC"; }
   16904          18 :             | NFD                                   { $$ = "NFD"; }
   16905          18 :             | NFKC                                  { $$ = "NFKC"; }
   16906          18 :             | NFKD                                  { $$ = "NFKD"; }
   16907             :         ;
   16908             : 
   16909             : /* OVERLAY() arguments */
   16910             : overlay_list:
   16911             :             a_expr PLACING a_expr FROM a_expr FOR a_expr
   16912             :                 {
   16913             :                     /* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D) */
   16914          34 :                     $$ = list_make4($1, $3, $5, $7);
   16915             :                 }
   16916             :             | a_expr PLACING a_expr FROM a_expr
   16917             :                 {
   16918             :                     /* overlay(A PLACING B FROM C) is converted to overlay(A, B, C) */
   16919          48 :                     $$ = list_make3($1, $3, $5);
   16920             :                 }
   16921             :         ;
   16922             : 
   16923             : /* position_list uses b_expr not a_expr to avoid conflict with general IN */
   16924             : position_list:
   16925         400 :             b_expr IN_P b_expr                      { $$ = list_make2($3, $1); }
   16926             :         ;
   16927             : 
   16928             : /*
   16929             :  * SUBSTRING() arguments
   16930             :  *
   16931             :  * Note that SQL:1999 has both
   16932             :  *     text FROM int FOR int
   16933             :  * and
   16934             :  *     text FROM pattern FOR escape
   16935             :  *
   16936             :  * In the parser we map them both to a call to the substring() function and
   16937             :  * rely on type resolution to pick the right one.
   16938             :  *
   16939             :  * In SQL:2003, the second variant was changed to
   16940             :  *     text SIMILAR pattern ESCAPE escape
   16941             :  * We could in theory map that to a different function internally, but
   16942             :  * since we still support the SQL:1999 version, we don't.  However,
   16943             :  * ruleutils.c will reverse-list the call in the newer style.
   16944             :  */
   16945             : substr_list:
   16946             :             a_expr FROM a_expr FOR a_expr
   16947             :                 {
   16948         122 :                     $$ = list_make3($1, $3, $5);
   16949             :                 }
   16950             :             | a_expr FOR a_expr FROM a_expr
   16951             :                 {
   16952             :                     /* not legal per SQL, but might as well allow it */
   16953           0 :                     $$ = list_make3($1, $5, $3);
   16954             :                 }
   16955             :             | a_expr FROM a_expr
   16956             :                 {
   16957             :                     /*
   16958             :                      * Because we aren't restricting data types here, this
   16959             :                      * syntax can end up resolving to textregexsubstr().
   16960             :                      * We've historically allowed that to happen, so continue
   16961             :                      * to accept it.  However, ruleutils.c will reverse-list
   16962             :                      * such a call in regular function call syntax.
   16963             :                      */
   16964         370 :                     $$ = list_make2($1, $3);
   16965             :                 }
   16966             :             | a_expr FOR a_expr
   16967             :                 {
   16968             :                     /* not legal per SQL */
   16969             : 
   16970             :                     /*
   16971             :                      * Since there are no cases where this syntax allows
   16972             :                      * a textual FOR value, we forcibly cast the argument
   16973             :                      * to int4.  The possible matches in pg_proc are
   16974             :                      * substring(text,int4) and substring(text,text),
   16975             :                      * and we don't want the parser to choose the latter,
   16976             :                      * which it is likely to do if the second argument
   16977             :                      * is unknown or doesn't have an implicit cast to int4.
   16978             :                      */
   16979          36 :                     $$ = list_make3($1, makeIntConst(1, -1),
   16980             :                                     makeTypeCast($3,
   16981             :                                                  SystemTypeName("int4"), -1));
   16982             :                 }
   16983             :             | a_expr SIMILAR a_expr ESCAPE a_expr
   16984             :                 {
   16985         182 :                     $$ = list_make3($1, $3, $5);
   16986             :                 }
   16987             :         ;
   16988             : 
   16989         606 : trim_list:  a_expr FROM expr_list                   { $$ = lappend($3, $1); }
   16990          24 :             | FROM expr_list                        { $$ = $2; }
   16991          86 :             | expr_list                             { $$ = $1; }
   16992             :         ;
   16993             : 
   16994             : /*
   16995             :  * Define SQL-style CASE clause.
   16996             :  * - Full specification
   16997             :  *  CASE WHEN a = b THEN c ... ELSE d END
   16998             :  * - Implicit argument
   16999             :  *  CASE a WHEN b THEN c ... ELSE d END
   17000             :  */
   17001             : case_expr:  CASE case_arg when_clause_list case_default END_P
   17002             :                 {
   17003       39110 :                     CaseExpr   *c = makeNode(CaseExpr);
   17004             : 
   17005       39110 :                     c->casetype = InvalidOid; /* not analyzed yet */
   17006       39110 :                     c->arg = (Expr *) $2;
   17007       39110 :                     c->args = $3;
   17008       39110 :                     c->defresult = (Expr *) $4;
   17009       39110 :                     c->location = @1;
   17010       39110 :                     $$ = (Node *) c;
   17011             :                 }
   17012             :         ;
   17013             : 
   17014             : when_clause_list:
   17015             :             /* There must be at least one */
   17016       39110 :             when_clause                             { $$ = list_make1($1); }
   17017       29034 :             | when_clause_list when_clause          { $$ = lappend($1, $2); }
   17018             :         ;
   17019             : 
   17020             : when_clause:
   17021             :             WHEN a_expr THEN a_expr
   17022             :                 {
   17023       68144 :                     CaseWhen   *w = makeNode(CaseWhen);
   17024             : 
   17025       68144 :                     w->expr = (Expr *) $2;
   17026       68144 :                     w->result = (Expr *) $4;
   17027       68144 :                     w->location = @1;
   17028       68144 :                     $$ = (Node *) w;
   17029             :                 }
   17030             :         ;
   17031             : 
   17032             : case_default:
   17033       29382 :             ELSE a_expr                             { $$ = $2; }
   17034        9728 :             | /*EMPTY*/                             { $$ = NULL; }
   17035             :         ;
   17036             : 
   17037        6758 : case_arg:   a_expr                                  { $$ = $1; }
   17038       32352 :             | /*EMPTY*/                             { $$ = NULL; }
   17039             :         ;
   17040             : 
   17041             : columnref:  ColId
   17042             :                 {
   17043      747352 :                     $$ = makeColumnRef($1, NIL, @1, yyscanner);
   17044             :                 }
   17045             :             | ColId indirection
   17046             :                 {
   17047     1060762 :                     $$ = makeColumnRef($1, $2, @1, yyscanner);
   17048             :                 }
   17049             :         ;
   17050             : 
   17051             : indirection_el:
   17052             :             '.' attr_name
   17053             :                 {
   17054     1430440 :                     $$ = (Node *) makeString($2);
   17055             :                 }
   17056             :             | '.' '*'
   17057             :                 {
   17058        6976 :                     $$ = (Node *) makeNode(A_Star);
   17059             :                 }
   17060             :             | '[' a_expr ']'
   17061             :                 {
   17062       12904 :                     A_Indices *ai = makeNode(A_Indices);
   17063             : 
   17064       12904 :                     ai->is_slice = false;
   17065       12904 :                     ai->lidx = NULL;
   17066       12904 :                     ai->uidx = $2;
   17067       12904 :                     $$ = (Node *) ai;
   17068             :                 }
   17069             :             | '[' opt_slice_bound ':' opt_slice_bound ']'
   17070             :                 {
   17071         588 :                     A_Indices *ai = makeNode(A_Indices);
   17072             : 
   17073         588 :                     ai->is_slice = true;
   17074         588 :                     ai->lidx = $2;
   17075         588 :                     ai->uidx = $4;
   17076         588 :                     $$ = (Node *) ai;
   17077             :                 }
   17078             :         ;
   17079             : 
   17080             : opt_slice_bound:
   17081         996 :             a_expr                                  { $$ = $1; }
   17082         180 :             | /*EMPTY*/                             { $$ = NULL; }
   17083             :         ;
   17084             : 
   17085             : indirection:
   17086     1430420 :             indirection_el                          { $$ = list_make1($1); }
   17087        3084 :             | indirection indirection_el            { $$ = lappend($1, $2); }
   17088             :         ;
   17089             : 
   17090             : opt_indirection:
   17091      195890 :             /*EMPTY*/                               { $$ = NIL; }
   17092       17404 :             | opt_indirection indirection_el        { $$ = lappend($1, $2); }
   17093             :         ;
   17094             : 
   17095             : opt_asymmetric: ASYMMETRIC
   17096             :             | /*EMPTY*/
   17097             :         ;
   17098             : 
   17099             : /* SQL/JSON support */
   17100             : json_passing_clause_opt:
   17101         336 :             PASSING json_arguments                  { $$ = $2; }
   17102        1988 :             | /*EMPTY*/                             { $$ = NIL; }
   17103             :         ;
   17104             : 
   17105             : json_arguments:
   17106         336 :             json_argument                           { $$ = list_make1($1); }
   17107         126 :             | json_arguments ',' json_argument      { $$ = lappend($1, $3); }
   17108             :         ;
   17109             : 
   17110             : json_argument:
   17111             :             json_value_expr AS ColLabel
   17112             :             {
   17113         462 :                 JsonArgument *n = makeNode(JsonArgument);
   17114             : 
   17115         462 :                 n->val = (JsonValueExpr *) $1;
   17116         462 :                 n->name = $3;
   17117         462 :                 $$ = (Node *) n;
   17118             :             }
   17119             :         ;
   17120             : 
   17121             : /* ARRAY is a noise word */
   17122             : json_wrapper_behavior:
   17123          42 :               WITHOUT WRAPPER                   { $$ = JSW_NONE; }
   17124           0 :             | WITHOUT ARRAY WRAPPER             { $$ = JSW_NONE; }
   17125          78 :             | WITH WRAPPER                      { $$ = JSW_UNCONDITIONAL; }
   17126          12 :             | WITH ARRAY WRAPPER                { $$ = JSW_UNCONDITIONAL; }
   17127           0 :             | WITH CONDITIONAL ARRAY WRAPPER    { $$ = JSW_CONDITIONAL; }
   17128          12 :             | WITH UNCONDITIONAL ARRAY WRAPPER  { $$ = JSW_UNCONDITIONAL; }
   17129          36 :             | WITH CONDITIONAL WRAPPER          { $$ = JSW_CONDITIONAL; }
   17130           6 :             | WITH UNCONDITIONAL WRAPPER        { $$ = JSW_UNCONDITIONAL; }
   17131        1640 :             | /* empty */                       { $$ = JSW_UNSPEC; }
   17132             :         ;
   17133             : 
   17134             : json_behavior:
   17135             :             DEFAULT a_expr
   17136         432 :                 { $$ = (Node *) makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); }
   17137             :             | json_behavior_type
   17138         702 :                 { $$ = (Node *) makeJsonBehavior($1, NULL, @1); }
   17139             :         ;
   17140             : 
   17141             : json_behavior_type:
   17142         492 :             ERROR_P     { $$ = JSON_BEHAVIOR_ERROR; }
   17143          30 :             | NULL_P    { $$ = JSON_BEHAVIOR_NULL; }
   17144          30 :             | TRUE_P    { $$ = JSON_BEHAVIOR_TRUE; }
   17145          12 :             | FALSE_P   { $$ = JSON_BEHAVIOR_FALSE; }
   17146          12 :             | UNKNOWN   { $$ = JSON_BEHAVIOR_UNKNOWN; }
   17147          30 :             | EMPTY_P ARRAY { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
   17148          72 :             | EMPTY_P OBJECT_P  { $$ = JSON_BEHAVIOR_EMPTY_OBJECT; }
   17149             :             /* non-standard, for Oracle compatibility only */
   17150          24 :             | EMPTY_P   { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
   17151             :         ;
   17152             : 
   17153             : json_behavior_clause_opt:
   17154             :             json_behavior ON EMPTY_P
   17155         222 :                 { $$ = list_make2($1, NULL); }
   17156             :             | json_behavior ON ERROR_P
   17157         552 :                 { $$ = list_make2(NULL, $1); }
   17158             :             | json_behavior ON EMPTY_P json_behavior ON ERROR_P
   17159         102 :                 { $$ = list_make2($1, $4); }
   17160             :             | /* EMPTY */
   17161        1574 :                 { $$ = list_make2(NULL, NULL); }
   17162             :         ;
   17163             : 
   17164             : json_on_error_clause_opt:
   17165             :             json_behavior ON ERROR_P
   17166         150 :                 { $$ = $1; }
   17167             :             | /* EMPTY */
   17168         692 :                 { $$ = NULL; }
   17169             :         ;
   17170             : 
   17171             : json_value_expr:
   17172             :             a_expr json_format_clause_opt
   17173             :             {
   17174             :                 /* formatted_expr will be set during parse-analysis. */
   17175        4280 :                 $$ = (Node *) makeJsonValueExpr((Expr *) $1, NULL,
   17176        4280 :                                                 castNode(JsonFormat, $2));
   17177             :             }
   17178             :         ;
   17179             : 
   17180             : json_format_clause:
   17181             :             FORMAT_LA JSON ENCODING name
   17182             :                 {
   17183             :                     int     encoding;
   17184             : 
   17185         100 :                     if (!pg_strcasecmp($4, "utf8"))
   17186          64 :                         encoding = JS_ENC_UTF8;
   17187          36 :                     else if (!pg_strcasecmp($4, "utf16"))
   17188          12 :                         encoding = JS_ENC_UTF16;
   17189          24 :                     else if (!pg_strcasecmp($4, "utf32"))
   17190          12 :                         encoding = JS_ENC_UTF32;
   17191             :                     else
   17192          12 :                         ereport(ERROR,
   17193             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   17194             :                                  errmsg("unrecognized JSON encoding: %s", $4),
   17195             :                                  parser_errposition(@4)));
   17196             : 
   17197          88 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
   17198             :                 }
   17199             :             | FORMAT_LA JSON
   17200             :                 {
   17201         412 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
   17202             :                 }
   17203             :         ;
   17204             : 
   17205             : json_format_clause_opt:
   17206             :             json_format_clause
   17207             :                 {
   17208         392 :                     $$ = $1;
   17209             :                 }
   17210             :             | /* EMPTY */
   17211             :                 {
   17212        5440 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   17213             :                 }
   17214             :         ;
   17215             : 
   17216             : json_quotes_clause_opt:
   17217          12 :             KEEP QUOTES ON SCALAR STRING_P      { $$ = JS_QUOTES_KEEP; }
   17218          90 :             | KEEP QUOTES                       { $$ = JS_QUOTES_KEEP; }
   17219          12 :             | OMIT QUOTES ON SCALAR STRING_P    { $$ = JS_QUOTES_OMIT; }
   17220         168 :             | OMIT QUOTES                       { $$ = JS_QUOTES_OMIT; }
   17221        1544 :             | /* EMPTY */                       { $$ = JS_QUOTES_UNSPEC; }
   17222             :         ;
   17223             : 
   17224             : json_returning_clause_opt:
   17225             :             RETURNING Typename json_format_clause_opt
   17226             :                 {
   17227        1492 :                     JsonOutput *n = makeNode(JsonOutput);
   17228             : 
   17229        1492 :                     n->typeName = $2;
   17230        1492 :                     n->returning = makeNode(JsonReturning);
   17231        1492 :                     n->returning->format = (JsonFormat *) $3;
   17232        1492 :                     $$ = (Node *) n;
   17233             :                 }
   17234        1290 :             | /* EMPTY */                           { $$ = NULL; }
   17235             :         ;
   17236             : 
   17237             : /*
   17238             :  * We must assign the only-JSON production a precedence less than IDENT in
   17239             :  * order to favor shifting over reduction when JSON is followed by VALUE_P,
   17240             :  * OBJECT_P, or SCALAR.  (ARRAY doesn't need that treatment, because it's a
   17241             :  * fully reserved word.)  Because json_predicate_type_constraint is always
   17242             :  * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
   17243             :  * production to have precedence less than WITH and WITHOUT.  UNBOUNDED isn't
   17244             :  * really related to this syntax, but it's a convenient choice because it
   17245             :  * already has a precedence less than IDENT for other reasons.
   17246             :  */
   17247             : json_predicate_type_constraint:
   17248         202 :             JSON                    %prec UNBOUNDED { $$ = JS_TYPE_ANY; }
   17249          28 :             | JSON VALUE_P                          { $$ = JS_TYPE_ANY; }
   17250          40 :             | JSON ARRAY                            { $$ = JS_TYPE_ARRAY; }
   17251          40 :             | JSON OBJECT_P                         { $$ = JS_TYPE_OBJECT; }
   17252          40 :             | JSON SCALAR                           { $$ = JS_TYPE_SCALAR; }
   17253             :         ;
   17254             : 
   17255             : /*
   17256             :  * KEYS is a noise word here.  To avoid shift/reduce conflicts, assign the
   17257             :  * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
   17258             :  * This prevents reducing them when the next token is KEYS.
   17259             :  */
   17260             : json_key_uniqueness_constraint_opt:
   17261         108 :             WITH UNIQUE KEYS                            { $$ = true; }
   17262         100 :             | WITH UNIQUE               %prec UNBOUNDED { $$ = true; }
   17263          44 :             | WITHOUT UNIQUE KEYS                       { $$ = false; }
   17264          16 :             | WITHOUT UNIQUE            %prec UNBOUNDED { $$ = false; }
   17265         798 :             | /* EMPTY */               %prec UNBOUNDED { $$ = false; }
   17266             :         ;
   17267             : 
   17268             : json_name_and_value_list:
   17269             :             json_name_and_value
   17270         348 :                 { $$ = list_make1($1); }
   17271             :             | json_name_and_value_list ',' json_name_and_value
   17272         256 :                 { $$ = lappend($1, $3); }
   17273             :         ;
   17274             : 
   17275             : json_name_and_value:
   17276             : /* Supporting this syntax seems to require major surgery
   17277             :             KEY c_expr VALUE_P json_value_expr
   17278             :                 { $$ = makeJsonKeyValue($2, $4); }
   17279             :             |
   17280             : */
   17281             :             c_expr VALUE_P json_value_expr
   17282          24 :                 { $$ = makeJsonKeyValue($1, $3); }
   17283             :             |
   17284             :             a_expr ':' json_value_expr
   17285         784 :                 { $$ = makeJsonKeyValue($1, $3); }
   17286             :         ;
   17287             : 
   17288             : /* empty means false for objects, true for arrays */
   17289             : json_object_constructor_null_clause_opt:
   17290          30 :             NULL_P ON NULL_P                    { $$ = false; }
   17291         110 :             | ABSENT ON NULL_P                  { $$ = true; }
   17292         412 :             | /* EMPTY */                       { $$ = false; }
   17293             :         ;
   17294             : 
   17295             : json_array_constructor_null_clause_opt:
   17296          60 :             NULL_P ON NULL_P                        { $$ = false; }
   17297          36 :             | ABSENT ON NULL_P                      { $$ = true; }
   17298         180 :             | /* EMPTY */                           { $$ = true; }
   17299             :         ;
   17300             : 
   17301             : json_value_expr_list:
   17302         120 :             json_value_expr                             { $$ = list_make1($1); }
   17303         138 :             | json_value_expr_list ',' json_value_expr  { $$ = lappend($1, $3);}
   17304             :         ;
   17305             : 
   17306             : json_aggregate_func:
   17307             :             JSON_OBJECTAGG '('
   17308             :                 json_name_and_value
   17309             :                 json_object_constructor_null_clause_opt
   17310             :                 json_key_uniqueness_constraint_opt
   17311             :                 json_returning_clause_opt
   17312             :             ')'
   17313             :                 {
   17314         204 :                     JsonObjectAgg *n = makeNode(JsonObjectAgg);
   17315             : 
   17316         204 :                     n->arg = (JsonKeyValue *) $3;
   17317         204 :                     n->absent_on_null = $4;
   17318         204 :                     n->unique = $5;
   17319         204 :                     n->constructor = makeNode(JsonAggConstructor);
   17320         204 :                     n->constructor->output = (JsonOutput *) $6;
   17321         204 :                     n->constructor->agg_order = NULL;
   17322         204 :                     n->constructor->location = @1;
   17323         204 :                     $$ = (Node *) n;
   17324             :                 }
   17325             :             | JSON_ARRAYAGG '('
   17326             :                 json_value_expr
   17327             :                 json_array_aggregate_order_by_clause_opt
   17328             :                 json_array_constructor_null_clause_opt
   17329             :                 json_returning_clause_opt
   17330             :             ')'
   17331             :                 {
   17332         156 :                     JsonArrayAgg *n = makeNode(JsonArrayAgg);
   17333             : 
   17334         156 :                     n->arg = (JsonValueExpr *) $3;
   17335         156 :                     n->absent_on_null = $5;
   17336         156 :                     n->constructor = makeNode(JsonAggConstructor);
   17337         156 :                     n->constructor->agg_order = $4;
   17338         156 :                     n->constructor->output = (JsonOutput *) $6;
   17339         156 :                     n->constructor->location = @1;
   17340         156 :                     $$ = (Node *) n;
   17341             :                 }
   17342             :         ;
   17343             : 
   17344             : json_array_aggregate_order_by_clause_opt:
   17345          18 :             ORDER BY sortby_list                    { $$ = $3; }
   17346         138 :             | /* EMPTY */                           { $$ = NIL; }
   17347             :         ;
   17348             : 
   17349             : /*****************************************************************************
   17350             :  *
   17351             :  *  target list for SELECT
   17352             :  *
   17353             :  *****************************************************************************/
   17354             : 
   17355      469954 : opt_target_list: target_list                        { $$ = $1; }
   17356         552 :             | /* EMPTY */                           { $$ = NIL; }
   17357             :         ;
   17358             : 
   17359             : target_list:
   17360      477124 :             target_el                               { $$ = list_make1($1); }
   17361      677330 :             | target_list ',' target_el             { $$ = lappend($1, $3); }
   17362             :         ;
   17363             : 
   17364             : target_el:  a_expr AS ColLabel
   17365             :                 {
   17366      236978 :                     $$ = makeNode(ResTarget);
   17367      236978 :                     $$->name = $3;
   17368      236978 :                     $$->indirection = NIL;
   17369      236978 :                     $$->val = (Node *) $1;
   17370      236978 :                     $$->location = @1;
   17371             :                 }
   17372             :             | a_expr BareColLabel
   17373             :                 {
   17374        3568 :                     $$ = makeNode(ResTarget);
   17375        3568 :                     $$->name = $2;
   17376        3568 :                     $$->indirection = NIL;
   17377        3568 :                     $$->val = (Node *) $1;
   17378        3568 :                     $$->location = @1;
   17379             :                 }
   17380             :             | a_expr
   17381             :                 {
   17382      857520 :                     $$ = makeNode(ResTarget);
   17383      857518 :                     $$->name = NULL;
   17384      857518 :                     $$->indirection = NIL;
   17385      857518 :                     $$->val = (Node *) $1;
   17386      857518 :                     $$->location = @1;
   17387             :                 }
   17388             :             | '*'
   17389             :                 {
   17390       56388 :                     ColumnRef  *n = makeNode(ColumnRef);
   17391             : 
   17392       56388 :                     n->fields = list_make1(makeNode(A_Star));
   17393       56388 :                     n->location = @1;
   17394             : 
   17395       56388 :                     $$ = makeNode(ResTarget);
   17396       56388 :                     $$->name = NULL;
   17397       56388 :                     $$->indirection = NIL;
   17398       56388 :                     $$->val = (Node *) n;
   17399       56388 :                     $$->location = @1;
   17400             :                 }
   17401             :         ;
   17402             : 
   17403             : 
   17404             : /*****************************************************************************
   17405             :  *
   17406             :  *  Names and constants
   17407             :  *
   17408             :  *****************************************************************************/
   17409             : 
   17410             : qualified_name_list:
   17411       17450 :             qualified_name                          { $$ = list_make1($1); }
   17412         454 :             | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
   17413             :         ;
   17414             : 
   17415             : /*
   17416             :  * The production for a qualified relation name has to exactly match the
   17417             :  * production for a qualified func_name, because in a FROM clause we cannot
   17418             :  * tell which we are parsing until we see what comes after it ('(' for a
   17419             :  * func_name, something else for a relation). Therefore we allow 'indirection'
   17420             :  * which may contain subscripts, and reject that case in the C code.
   17421             :  */
   17422             : qualified_name:
   17423             :             ColId
   17424             :                 {
   17425      422630 :                     $$ = makeRangeVar(NULL, $1, @1);
   17426             :                 }
   17427             :             | ColId indirection
   17428             :                 {
   17429      243280 :                     $$ = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   17430             :                 }
   17431             :         ;
   17432             : 
   17433             : name_list:  name
   17434       28366 :                     { $$ = list_make1(makeString($1)); }
   17435             :             | name_list ',' name
   17436       61570 :                     { $$ = lappend($1, makeString($3)); }
   17437             :         ;
   17438             : 
   17439             : 
   17440      176480 : name:       ColId                                   { $$ = $1; };
   17441             : 
   17442     1555740 : attr_name:  ColLabel                                { $$ = $1; };
   17443             : 
   17444          64 : file_name:  Sconst                                  { $$ = $1; };
   17445             : 
   17446             : /*
   17447             :  * The production for a qualified func_name has to exactly match the
   17448             :  * production for a qualified columnref, because we cannot tell which we
   17449             :  * are parsing until we see what comes after it ('(' or Sconst for a func_name,
   17450             :  * anything else for a columnref).  Therefore we allow 'indirection' which
   17451             :  * may contain subscripts, and reject that case in the C code.  (If we
   17452             :  * ever implement SQL99-like methods, such syntax may actually become legal!)
   17453             :  */
   17454             : func_name:  type_function_name
   17455      297046 :                     { $$ = list_make1(makeString($1)); }
   17456             :             | ColId indirection
   17457             :                     {
   17458      126300 :                         $$ = check_func_name(lcons(makeString($1), $2),
   17459             :                                              yyscanner);
   17460             :                     }
   17461             :         ;
   17462             : 
   17463             : 
   17464             : /*
   17465             :  * Constants
   17466             :  */
   17467             : AexprConst: Iconst
   17468             :                 {
   17469      378388 :                     $$ = makeIntConst($1, @1);
   17470             :                 }
   17471             :             | FCONST
   17472             :                 {
   17473       11714 :                     $$ = makeFloatConst($1, @1);
   17474             :                 }
   17475             :             | Sconst
   17476             :                 {
   17477      693804 :                     $$ = makeStringConst($1, @1);
   17478             :                 }
   17479             :             | BCONST
   17480             :                 {
   17481         754 :                     $$ = makeBitStringConst($1, @1);
   17482             :                 }
   17483             :             | XCONST
   17484             :                 {
   17485             :                     /* This is a bit constant per SQL99:
   17486             :                      * Without Feature F511, "BIT data type",
   17487             :                      * a <general literal> shall not be a
   17488             :                      * <bit string literal> or a <hex string literal>.
   17489             :                      */
   17490        3302 :                     $$ = makeBitStringConst($1, @1);
   17491             :                 }
   17492             :             | func_name Sconst
   17493             :                 {
   17494             :                     /* generic type 'literal' syntax */
   17495        9842 :                     TypeName   *t = makeTypeNameFromNameList($1);
   17496             : 
   17497        9842 :                     t->location = @1;
   17498        9842 :                     $$ = makeStringConstCast($2, @2, t);
   17499             :                 }
   17500             :             | func_name '(' func_arg_list opt_sort_clause ')' Sconst
   17501             :                 {
   17502             :                     /* generic syntax with a type modifier */
   17503           0 :                     TypeName   *t = makeTypeNameFromNameList($1);
   17504             :                     ListCell   *lc;
   17505             : 
   17506             :                     /*
   17507             :                      * We must use func_arg_list and opt_sort_clause in the
   17508             :                      * production to avoid reduce/reduce conflicts, but we
   17509             :                      * don't actually wish to allow NamedArgExpr in this
   17510             :                      * context, nor ORDER BY.
   17511             :                      */
   17512           0 :                     foreach(lc, $3)
   17513             :                     {
   17514           0 :                         NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
   17515             : 
   17516           0 :                         if (IsA(arg, NamedArgExpr))
   17517           0 :                             ereport(ERROR,
   17518             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17519             :                                      errmsg("type modifier cannot have parameter name"),
   17520             :                                      parser_errposition(arg->location)));
   17521             :                     }
   17522           0 :                     if ($4 != NIL)
   17523           0 :                             ereport(ERROR,
   17524             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17525             :                                      errmsg("type modifier cannot have ORDER BY"),
   17526             :                                      parser_errposition(@4)));
   17527             : 
   17528           0 :                     t->typmods = $3;
   17529           0 :                     t->location = @1;
   17530           0 :                     $$ = makeStringConstCast($6, @6, t);
   17531             :                 }
   17532             :             | ConstTypename Sconst
   17533             :                 {
   17534        3174 :                     $$ = makeStringConstCast($2, @2, $1);
   17535             :                 }
   17536             :             | ConstInterval Sconst opt_interval
   17537             :                 {
   17538        3298 :                     TypeName   *t = $1;
   17539             : 
   17540        3298 :                     t->typmods = $3;
   17541        3298 :                     $$ = makeStringConstCast($2, @2, t);
   17542             :                 }
   17543             :             | ConstInterval '(' Iconst ')' Sconst
   17544             :                 {
   17545          12 :                     TypeName   *t = $1;
   17546             : 
   17547          12 :                     t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   17548             :                                             makeIntConst($3, @3));
   17549          12 :                     $$ = makeStringConstCast($5, @5, t);
   17550             :                 }
   17551             :             | TRUE_P
   17552             :                 {
   17553       31094 :                     $$ = makeBoolAConst(true, @1);
   17554             :                 }
   17555             :             | FALSE_P
   17556             :                 {
   17557       35876 :                     $$ = makeBoolAConst(false, @1);
   17558             :                 }
   17559             :             | NULL_P
   17560             :                 {
   17561       67464 :                     $$ = makeNullAConst(@1);
   17562             :                 }
   17563             :         ;
   17564             : 
   17565      406668 : Iconst:     ICONST                                  { $$ = $1; };
   17566      767252 : Sconst:     SCONST                                  { $$ = $1; };
   17567             : 
   17568       17520 : SignedIconst: Iconst                                { $$ = $1; }
   17569           0 :             | '+' Iconst                            { $$ = + $2; }
   17570         288 :             | '-' Iconst                            { $$ = - $2; }
   17571             :         ;
   17572             : 
   17573             : /* Role specifications */
   17574             : RoleId:     RoleSpec
   17575             :                 {
   17576        1940 :                     RoleSpec   *spc = (RoleSpec *) $1;
   17577             : 
   17578        1940 :                     switch (spc->roletype)
   17579             :                     {
   17580        1930 :                         case ROLESPEC_CSTRING:
   17581        1930 :                             $$ = spc->rolename;
   17582        1930 :                             break;
   17583           4 :                         case ROLESPEC_PUBLIC:
   17584           4 :                             ereport(ERROR,
   17585             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17586             :                                      errmsg("role name \"%s\" is reserved",
   17587             :                                             "public"),
   17588             :                                      parser_errposition(@1)));
   17589             :                             break;
   17590           2 :                         case ROLESPEC_SESSION_USER:
   17591           2 :                             ereport(ERROR,
   17592             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17593             :                                      errmsg("%s cannot be used as a role name here",
   17594             :                                             "SESSION_USER"),
   17595             :                                      parser_errposition(@1)));
   17596             :                             break;
   17597           2 :                         case ROLESPEC_CURRENT_USER:
   17598           2 :                             ereport(ERROR,
   17599             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17600             :                                      errmsg("%s cannot be used as a role name here",
   17601             :                                             "CURRENT_USER"),
   17602             :                                      parser_errposition(@1)));
   17603             :                             break;
   17604           2 :                         case ROLESPEC_CURRENT_ROLE:
   17605           2 :                             ereport(ERROR,
   17606             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17607             :                                      errmsg("%s cannot be used as a role name here",
   17608             :                                             "CURRENT_ROLE"),
   17609             :                                      parser_errposition(@1)));
   17610             :                             break;
   17611             :                     }
   17612             :                 }
   17613             :             ;
   17614             : 
   17615             : RoleSpec:   NonReservedWord
   17616             :                 {
   17617             :                     /*
   17618             :                      * "public" and "none" are not keywords, but they must
   17619             :                      * be treated specially here.
   17620             :                      */
   17621             :                     RoleSpec   *n;
   17622             : 
   17623       32418 :                     if (strcmp($1, "public") == 0)
   17624             :                     {
   17625       17532 :                         n = (RoleSpec *) makeRoleSpec(ROLESPEC_PUBLIC, @1);
   17626       17532 :                         n->roletype = ROLESPEC_PUBLIC;
   17627             :                     }
   17628       14886 :                     else if (strcmp($1, "none") == 0)
   17629             :                     {
   17630          26 :                         ereport(ERROR,
   17631             :                                 (errcode(ERRCODE_RESERVED_NAME),
   17632             :                                  errmsg("role name \"%s\" is reserved",
   17633             :                                         "none"),
   17634             :                                  parser_errposition(@1)));
   17635             :                     }
   17636             :                     else
   17637             :                     {
   17638       14860 :                         n = makeRoleSpec(ROLESPEC_CSTRING, @1);
   17639       14860 :                         n->rolename = pstrdup($1);
   17640             :                     }
   17641       32392 :                     $$ = n;
   17642             :                 }
   17643             :             | CURRENT_ROLE
   17644             :                 {
   17645         130 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_ROLE, @1);
   17646             :                 }
   17647             :             | CURRENT_USER
   17648             :                 {
   17649         228 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
   17650             :                 }
   17651             :             | SESSION_USER
   17652             :                 {
   17653          36 :                     $$ = makeRoleSpec(ROLESPEC_SESSION_USER, @1);
   17654             :                 }
   17655             :         ;
   17656             : 
   17657             : role_list:  RoleSpec
   17658        3246 :                 { $$ = list_make1($1); }
   17659             :             | role_list ',' RoleSpec
   17660         270 :                 { $$ = lappend($1, $3); }
   17661             :         ;
   17662             : 
   17663             : 
   17664             : /*****************************************************************************
   17665             :  *
   17666             :  * PL/pgSQL extensions
   17667             :  *
   17668             :  * You'd think a PL/pgSQL "expression" should be just an a_expr, but
   17669             :  * historically it can include just about anything that can follow SELECT.
   17670             :  * Therefore the returned struct is a SelectStmt.
   17671             :  *****************************************************************************/
   17672             : 
   17673             : PLpgSQL_Expr: opt_distinct_clause opt_target_list
   17674             :             from_clause where_clause
   17675             :             group_clause having_clause window_clause
   17676             :             opt_sort_clause opt_select_limit opt_for_locking_clause
   17677             :                 {
   17678       40414 :                     SelectStmt *n = makeNode(SelectStmt);
   17679             : 
   17680       40414 :                     n->distinctClause = $1;
   17681       40414 :                     n->targetList = $2;
   17682       40414 :                     n->fromClause = $3;
   17683       40414 :                     n->whereClause = $4;
   17684       40414 :                     n->groupClause = ($5)->list;
   17685       40414 :                     n->groupDistinct = ($5)->distinct;
   17686       40414 :                     n->groupByAll = ($5)->all;
   17687       40414 :                     n->havingClause = $6;
   17688       40414 :                     n->windowClause = $7;
   17689       40414 :                     n->sortClause = $8;
   17690       40414 :                     if ($9)
   17691             :                     {
   17692           4 :                         n->limitOffset = $9->limitOffset;
   17693           4 :                         n->limitCount = $9->limitCount;
   17694           4 :                         if (!n->sortClause &&
   17695           4 :                             $9->limitOption == LIMIT_OPTION_WITH_TIES)
   17696           0 :                             ereport(ERROR,
   17697             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17698             :                                      errmsg("WITH TIES cannot be specified without ORDER BY clause"),
   17699             :                                      parser_errposition($9->optionLoc)));
   17700           4 :                         n->limitOption = $9->limitOption;
   17701             :                     }
   17702       40414 :                     n->lockingClause = $10;
   17703       40414 :                     $$ = (Node *) n;
   17704             :                 }
   17705             :         ;
   17706             : 
   17707             : /*
   17708             :  * PL/pgSQL Assignment statement: name opt_indirection := PLpgSQL_Expr
   17709             :  */
   17710             : 
   17711             : PLAssignStmt: plassign_target opt_indirection plassign_equals PLpgSQL_Expr
   17712             :                 {
   17713        7044 :                     PLAssignStmt *n = makeNode(PLAssignStmt);
   17714             : 
   17715        7044 :                     n->name = $1;
   17716        7044 :                     n->indirection = check_indirection($2, yyscanner);
   17717             :                     /* nnames will be filled by calling production */
   17718        6914 :                     n->val = (SelectStmt *) $4;
   17719        6914 :                     n->location = @1;
   17720        6914 :                     $$ = (Node *) n;
   17721             :                 }
   17722             :         ;
   17723             : 
   17724        7020 : plassign_target: ColId                          { $$ = $1; }
   17725          24 :             | PARAM                             { $$ = psprintf("$%d", $1); }
   17726             :         ;
   17727             : 
   17728             : plassign_equals: COLON_EQUALS
   17729             :             | '='
   17730             :         ;
   17731             : 
   17732             : 
   17733             : /*
   17734             :  * Name classification hierarchy.
   17735             :  *
   17736             :  * IDENT is the lexeme returned by the lexer for identifiers that match
   17737             :  * no known keyword.  In most cases, we can accept certain keywords as
   17738             :  * names, not only IDENTs.  We prefer to accept as many such keywords
   17739             :  * as possible to minimize the impact of "reserved words" on programmers.
   17740             :  * So, we divide names into several possible classes.  The classification
   17741             :  * is chosen in part to make keywords acceptable as names wherever possible.
   17742             :  */
   17743             : 
   17744             : /* Column identifier --- names that can be column, table, etc names.
   17745             :  */
   17746     3367950 : ColId:      IDENT                                   { $$ = $1; }
   17747       57900 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17748        6174 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17749             :         ;
   17750             : 
   17751             : /* Type/function identifier --- names that can be type or function names.
   17752             :  */
   17753      713228 : type_function_name: IDENT                           { $$ = $1; }
   17754       74740 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17755          66 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17756             :         ;
   17757             : 
   17758             : /* Any not-fully-reserved word --- these names can be, eg, role names.
   17759             :  */
   17760       83638 : NonReservedWord:    IDENT                           { $$ = $1; }
   17761       30664 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17762         178 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17763        5436 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17764             :         ;
   17765             : 
   17766             : /* Column label --- allowed labels in "AS" clauses.
   17767             :  * This presently includes *all* Postgres keywords.
   17768             :  */
   17769     1776712 : ColLabel:   IDENT                                   { $$ = $1; }
   17770       39864 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17771         284 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17772        1772 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17773        7530 :             | reserved_keyword                      { $$ = pstrdup($1); }
   17774             :         ;
   17775             : 
   17776             : /* Bare column label --- names that can be column labels without writing "AS".
   17777             :  * This classification is orthogonal to the other keyword categories.
   17778             :  */
   17779        3554 : BareColLabel:   IDENT                               { $$ = $1; }
   17780          14 :             | bare_label_keyword                    { $$ = pstrdup($1); }
   17781             :         ;
   17782             : 
   17783             : 
   17784             : /*
   17785             :  * Keyword category lists.  Generally, every keyword present in
   17786             :  * the Postgres grammar should appear in exactly one of these lists.
   17787             :  *
   17788             :  * Put a new keyword into the first list that it can go into without causing
   17789             :  * shift or reduce conflicts.  The earlier lists define "less reserved"
   17790             :  * categories of keywords.
   17791             :  *
   17792             :  * Make sure that each keyword's category in kwlist.h matches where
   17793             :  * it is listed here.  (Someday we may be able to generate these lists and
   17794             :  * kwlist.h's table from one source of truth.)
   17795             :  */
   17796             : 
   17797             : /* "Unreserved" keywords --- available for use as any kind of name.
   17798             :  */
   17799             : unreserved_keyword:
   17800             :               ABORT_P
   17801             :             | ABSENT
   17802             :             | ABSOLUTE_P
   17803             :             | ACCESS
   17804             :             | ACTION
   17805             :             | ADD_P
   17806             :             | ADMIN
   17807             :             | AFTER
   17808             :             | AGGREGATE
   17809             :             | ALSO
   17810             :             | ALTER
   17811             :             | ALWAYS
   17812             :             | ASENSITIVE
   17813             :             | ASSERTION
   17814             :             | ASSIGNMENT
   17815             :             | AT
   17816             :             | ATOMIC
   17817             :             | ATTACH
   17818             :             | ATTRIBUTE
   17819             :             | BACKWARD
   17820             :             | BEFORE
   17821             :             | BEGIN_P
   17822             :             | BREADTH
   17823             :             | BY
   17824             :             | CACHE
   17825             :             | CALL
   17826             :             | CALLED
   17827             :             | CASCADE
   17828             :             | CASCADED
   17829             :             | CATALOG_P
   17830             :             | CHAIN
   17831             :             | CHARACTERISTICS
   17832             :             | CHECKPOINT
   17833             :             | CLASS
   17834             :             | CLOSE
   17835             :             | CLUSTER
   17836             :             | COLUMNS
   17837             :             | COMMENT
   17838             :             | COMMENTS
   17839             :             | COMMIT
   17840             :             | COMMITTED
   17841             :             | COMPRESSION
   17842             :             | CONDITIONAL
   17843             :             | CONFIGURATION
   17844             :             | CONFLICT
   17845             :             | CONNECTION
   17846             :             | CONSTRAINTS
   17847             :             | CONTENT_P
   17848             :             | CONTINUE_P
   17849             :             | CONVERSION_P
   17850             :             | COPY
   17851             :             | COST
   17852             :             | CSV
   17853             :             | CUBE
   17854             :             | CURRENT_P
   17855             :             | CURSOR
   17856             :             | CYCLE
   17857             :             | DATA_P
   17858             :             | DATABASE
   17859             :             | DAY_P
   17860             :             | DEALLOCATE
   17861             :             | DECLARE
   17862             :             | DEFAULTS
   17863             :             | DEFERRED
   17864             :             | DEFINER
   17865             :             | DELETE_P
   17866             :             | DELIMITER
   17867             :             | DELIMITERS
   17868             :             | DEPENDS
   17869             :             | DEPTH
   17870             :             | DETACH
   17871             :             | DICTIONARY
   17872             :             | DISABLE_P
   17873             :             | DISCARD
   17874             :             | DOCUMENT_P
   17875             :             | DOMAIN_P
   17876             :             | DOUBLE_P
   17877             :             | DROP
   17878             :             | EACH
   17879             :             | EMPTY_P
   17880             :             | ENABLE_P
   17881             :             | ENCODING
   17882             :             | ENCRYPTED
   17883             :             | ENFORCED
   17884             :             | ENUM_P
   17885             :             | ERROR_P
   17886             :             | ESCAPE
   17887             :             | EVENT
   17888             :             | EXCLUDE
   17889             :             | EXCLUDING
   17890             :             | EXCLUSIVE
   17891             :             | EXECUTE
   17892             :             | EXPLAIN
   17893             :             | EXPRESSION
   17894             :             | EXTENSION
   17895             :             | EXTERNAL
   17896             :             | FAMILY
   17897             :             | FILTER
   17898             :             | FINALIZE
   17899             :             | FIRST_P
   17900             :             | FOLLOWING
   17901             :             | FORCE
   17902             :             | FORMAT
   17903             :             | FORWARD
   17904             :             | FUNCTION
   17905             :             | FUNCTIONS
   17906             :             | GENERATED
   17907             :             | GLOBAL
   17908             :             | GRANTED
   17909             :             | GROUPS
   17910             :             | HANDLER
   17911             :             | HEADER_P
   17912             :             | HOLD
   17913             :             | HOUR_P
   17914             :             | IDENTITY_P
   17915             :             | IF_P
   17916             :             | IGNORE_P
   17917             :             | IMMEDIATE
   17918             :             | IMMUTABLE
   17919             :             | IMPLICIT_P
   17920             :             | IMPORT_P
   17921             :             | INCLUDE
   17922             :             | INCLUDING
   17923             :             | INCREMENT
   17924             :             | INDENT
   17925             :             | INDEX
   17926             :             | INDEXES
   17927             :             | INHERIT
   17928             :             | INHERITS
   17929             :             | INLINE_P
   17930             :             | INPUT_P
   17931             :             | INSENSITIVE
   17932             :             | INSERT
   17933             :             | INSTEAD
   17934             :             | INVOKER
   17935             :             | ISOLATION
   17936             :             | KEEP
   17937             :             | KEY
   17938             :             | KEYS
   17939             :             | LABEL
   17940             :             | LANGUAGE
   17941             :             | LARGE_P
   17942             :             | LAST_P
   17943             :             | LEAKPROOF
   17944             :             | LEVEL
   17945             :             | LISTEN
   17946             :             | LOAD
   17947             :             | LOCAL
   17948             :             | LOCATION
   17949             :             | LOCK_P
   17950             :             | LOCKED
   17951             :             | LOGGED
   17952             :             | MAPPING
   17953             :             | MATCH
   17954             :             | MATCHED
   17955             :             | MATERIALIZED
   17956             :             | MAXVALUE
   17957             :             | MERGE
   17958             :             | METHOD
   17959             :             | MINUTE_P
   17960             :             | MINVALUE
   17961             :             | MODE
   17962             :             | MONTH_P
   17963             :             | MOVE
   17964             :             | NAME_P
   17965             :             | NAMES
   17966             :             | NESTED
   17967             :             | NEW
   17968             :             | NEXT
   17969             :             | NFC
   17970             :             | NFD
   17971             :             | NFKC
   17972             :             | NFKD
   17973             :             | NO
   17974             :             | NORMALIZED
   17975             :             | NOTHING
   17976             :             | NOTIFY
   17977             :             | NOWAIT
   17978             :             | NULLS_P
   17979             :             | OBJECT_P
   17980             :             | OBJECTS_P
   17981             :             | OF
   17982             :             | OFF
   17983             :             | OIDS
   17984             :             | OLD
   17985             :             | OMIT
   17986             :             | OPERATOR
   17987             :             | OPTION
   17988             :             | OPTIONS
   17989             :             | ORDINALITY
   17990             :             | OTHERS
   17991             :             | OVER
   17992             :             | OVERRIDING
   17993             :             | OWNED
   17994             :             | OWNER
   17995             :             | PARALLEL
   17996             :             | PARAMETER
   17997             :             | PARSER
   17998             :             | PARTIAL
   17999             :             | PARTITION
   18000             :             | PASSING
   18001             :             | PASSWORD
   18002             :             | PATH
   18003             :             | PERIOD
   18004             :             | PLAN
   18005             :             | PLANS
   18006             :             | POLICY
   18007             :             | PRECEDING
   18008             :             | PREPARE
   18009             :             | PREPARED
   18010             :             | PRESERVE
   18011             :             | PRIOR
   18012             :             | PRIVILEGES
   18013             :             | PROCEDURAL
   18014             :             | PROCEDURE
   18015             :             | PROCEDURES
   18016             :             | PROGRAM
   18017             :             | PUBLICATION
   18018             :             | QUOTE
   18019             :             | QUOTES
   18020             :             | RANGE
   18021             :             | READ
   18022             :             | REASSIGN
   18023             :             | RECURSIVE
   18024             :             | REF_P
   18025             :             | REFERENCING
   18026             :             | REFRESH
   18027             :             | REINDEX
   18028             :             | RELATIVE_P
   18029             :             | RELEASE
   18030             :             | RENAME
   18031             :             | REPEATABLE
   18032             :             | REPLACE
   18033             :             | REPLICA
   18034             :             | RESET
   18035             :             | RESPECT_P
   18036             :             | RESTART
   18037             :             | RESTRICT
   18038             :             | RETURN
   18039             :             | RETURNS
   18040             :             | REVOKE
   18041             :             | ROLE
   18042             :             | ROLLBACK
   18043             :             | ROLLUP
   18044             :             | ROUTINE
   18045             :             | ROUTINES
   18046             :             | ROWS
   18047             :             | RULE
   18048             :             | SAVEPOINT
   18049             :             | SCALAR
   18050             :             | SCHEMA
   18051             :             | SCHEMAS
   18052             :             | SCROLL
   18053             :             | SEARCH
   18054             :             | SECOND_P
   18055             :             | SECURITY
   18056             :             | SEQUENCE
   18057             :             | SEQUENCES
   18058             :             | SERIALIZABLE
   18059             :             | SERVER
   18060             :             | SESSION
   18061             :             | SET
   18062             :             | SETS
   18063             :             | SHARE
   18064             :             | SHOW
   18065             :             | SIMPLE
   18066             :             | SKIP
   18067             :             | SNAPSHOT
   18068             :             | SOURCE
   18069             :             | SQL_P
   18070             :             | STABLE
   18071             :             | STANDALONE_P
   18072             :             | START
   18073             :             | STATEMENT
   18074             :             | STATISTICS
   18075             :             | STDIN
   18076             :             | STDOUT
   18077             :             | STORAGE
   18078             :             | STORED
   18079             :             | STRICT_P
   18080             :             | STRING_P
   18081             :             | STRIP_P
   18082             :             | SUBSCRIPTION
   18083             :             | SUPPORT
   18084             :             | SYSID
   18085             :             | SYSTEM_P
   18086             :             | TABLES
   18087             :             | TABLESPACE
   18088             :             | TARGET
   18089             :             | TEMP
   18090             :             | TEMPLATE
   18091             :             | TEMPORARY
   18092             :             | TEXT_P
   18093             :             | TIES
   18094             :             | TRANSACTION
   18095             :             | TRANSFORM
   18096             :             | TRIGGER
   18097             :             | TRUNCATE
   18098             :             | TRUSTED
   18099             :             | TYPE_P
   18100             :             | TYPES_P
   18101             :             | UESCAPE
   18102             :             | UNBOUNDED
   18103             :             | UNCOMMITTED
   18104             :             | UNCONDITIONAL
   18105             :             | UNENCRYPTED
   18106             :             | UNKNOWN
   18107             :             | UNLISTEN
   18108             :             | UNLOGGED
   18109             :             | UNTIL
   18110             :             | UPDATE
   18111             :             | VACUUM
   18112             :             | VALID
   18113             :             | VALIDATE
   18114             :             | VALIDATOR
   18115             :             | VALUE_P
   18116             :             | VARYING
   18117             :             | VERSION_P
   18118             :             | VIEW
   18119             :             | VIEWS
   18120             :             | VIRTUAL
   18121             :             | VOLATILE
   18122             :             | WHITESPACE_P
   18123             :             | WITHIN
   18124             :             | WITHOUT
   18125             :             | WORK
   18126             :             | WRAPPER
   18127             :             | WRITE
   18128             :             | XML_P
   18129             :             | YEAR_P
   18130             :             | YES_P
   18131             :             | ZONE
   18132             :         ;
   18133             : 
   18134             : /* Column identifier --- keywords that can be column, table, etc names.
   18135             :  *
   18136             :  * Many of these keywords will in fact be recognized as type or function
   18137             :  * names too; but they have special productions for the purpose, and so
   18138             :  * can't be treated as "generic" type or function names.
   18139             :  *
   18140             :  * The type names appearing here are not usable as function names
   18141             :  * because they can be followed by '(' in typename productions, which
   18142             :  * looks too much like a function call for an LR(1) parser.
   18143             :  */
   18144             : col_name_keyword:
   18145             :               BETWEEN
   18146             :             | BIGINT
   18147             :             | BIT
   18148             :             | BOOLEAN_P
   18149             :             | CHAR_P
   18150             :             | CHARACTER
   18151             :             | COALESCE
   18152             :             | DEC
   18153             :             | DECIMAL_P
   18154             :             | EXISTS
   18155             :             | EXTRACT
   18156             :             | FLOAT_P
   18157             :             | GREATEST
   18158             :             | GROUPING
   18159             :             | INOUT
   18160             :             | INT_P
   18161             :             | INTEGER
   18162             :             | INTERVAL
   18163             :             | JSON
   18164             :             | JSON_ARRAY
   18165             :             | JSON_ARRAYAGG
   18166             :             | JSON_EXISTS
   18167             :             | JSON_OBJECT
   18168             :             | JSON_OBJECTAGG
   18169             :             | JSON_QUERY
   18170             :             | JSON_SCALAR
   18171             :             | JSON_SERIALIZE
   18172             :             | JSON_TABLE
   18173             :             | JSON_VALUE
   18174             :             | LEAST
   18175             :             | MERGE_ACTION
   18176             :             | NATIONAL
   18177             :             | NCHAR
   18178             :             | NONE
   18179             :             | NORMALIZE
   18180             :             | NULLIF
   18181             :             | NUMERIC
   18182             :             | OUT_P
   18183             :             | OVERLAY
   18184             :             | POSITION
   18185             :             | PRECISION
   18186             :             | REAL
   18187             :             | ROW
   18188             :             | SETOF
   18189             :             | SMALLINT
   18190             :             | SUBSTRING
   18191             :             | TIME
   18192             :             | TIMESTAMP
   18193             :             | TREAT
   18194             :             | TRIM
   18195             :             | VALUES
   18196             :             | VARCHAR
   18197             :             | XMLATTRIBUTES
   18198             :             | XMLCONCAT
   18199             :             | XMLELEMENT
   18200             :             | XMLEXISTS
   18201             :             | XMLFOREST
   18202             :             | XMLNAMESPACES
   18203             :             | XMLPARSE
   18204             :             | XMLPI
   18205             :             | XMLROOT
   18206             :             | XMLSERIALIZE
   18207             :             | XMLTABLE
   18208             :         ;
   18209             : 
   18210             : /* Type/function identifier --- keywords that can be type or function names.
   18211             :  *
   18212             :  * Most of these are keywords that are used as operators in expressions;
   18213             :  * in general such keywords can't be column names because they would be
   18214             :  * ambiguous with variables, but they are unambiguous as function identifiers.
   18215             :  *
   18216             :  * Do not include POSITION, SUBSTRING, etc here since they have explicit
   18217             :  * productions in a_expr to support the goofy SQL9x argument syntax.
   18218             :  * - thomas 2000-11-28
   18219             :  */
   18220             : type_func_name_keyword:
   18221             :               AUTHORIZATION
   18222             :             | BINARY
   18223             :             | COLLATION
   18224             :             | CONCURRENTLY
   18225             :             | CROSS
   18226             :             | CURRENT_SCHEMA
   18227             :             | FREEZE
   18228             :             | FULL
   18229             :             | ILIKE
   18230             :             | INNER_P
   18231             :             | IS
   18232             :             | ISNULL
   18233             :             | JOIN
   18234             :             | LEFT
   18235             :             | LIKE
   18236             :             | NATURAL
   18237             :             | NOTNULL
   18238             :             | OUTER_P
   18239             :             | OVERLAPS
   18240             :             | RIGHT
   18241             :             | SIMILAR
   18242             :             | TABLESAMPLE
   18243             :             | VERBOSE
   18244             :         ;
   18245             : 
   18246             : /* Reserved keyword --- these keywords are usable only as a ColLabel.
   18247             :  *
   18248             :  * Keywords appear here if they could not be distinguished from variable,
   18249             :  * type, or function names in some contexts.  Don't put things here unless
   18250             :  * forced to.
   18251             :  */
   18252             : reserved_keyword:
   18253             :               ALL
   18254             :             | ANALYSE
   18255             :             | ANALYZE
   18256             :             | AND
   18257             :             | ANY
   18258             :             | ARRAY
   18259             :             | AS
   18260             :             | ASC
   18261             :             | ASYMMETRIC
   18262             :             | BOTH
   18263             :             | CASE
   18264             :             | CAST
   18265             :             | CHECK
   18266             :             | COLLATE
   18267             :             | COLUMN
   18268             :             | CONSTRAINT
   18269             :             | CREATE
   18270             :             | CURRENT_CATALOG
   18271             :             | CURRENT_DATE
   18272             :             | CURRENT_ROLE
   18273             :             | CURRENT_TIME
   18274             :             | CURRENT_TIMESTAMP
   18275             :             | CURRENT_USER
   18276             :             | DEFAULT
   18277             :             | DEFERRABLE
   18278             :             | DESC
   18279             :             | DISTINCT
   18280             :             | DO
   18281             :             | ELSE
   18282             :             | END_P
   18283             :             | EXCEPT
   18284             :             | FALSE_P
   18285             :             | FETCH
   18286             :             | FOR
   18287             :             | FOREIGN
   18288             :             | FROM
   18289             :             | GRANT
   18290             :             | GROUP_P
   18291             :             | HAVING
   18292             :             | IN_P
   18293             :             | INITIALLY
   18294             :             | INTERSECT
   18295             :             | INTO
   18296             :             | LATERAL_P
   18297             :             | LEADING
   18298             :             | LIMIT
   18299             :             | LOCALTIME
   18300             :             | LOCALTIMESTAMP
   18301             :             | NOT
   18302             :             | NULL_P
   18303             :             | OFFSET
   18304             :             | ON
   18305             :             | ONLY
   18306             :             | OR
   18307             :             | ORDER
   18308             :             | PLACING
   18309             :             | PRIMARY
   18310             :             | REFERENCES
   18311             :             | RETURNING
   18312             :             | SELECT
   18313             :             | SESSION_USER
   18314             :             | SOME
   18315             :             | SYMMETRIC
   18316             :             | SYSTEM_USER
   18317             :             | TABLE
   18318             :             | THEN
   18319             :             | TO
   18320             :             | TRAILING
   18321             :             | TRUE_P
   18322             :             | UNION
   18323             :             | UNIQUE
   18324             :             | USER
   18325             :             | USING
   18326             :             | VARIADIC
   18327             :             | WHEN
   18328             :             | WHERE
   18329             :             | WINDOW
   18330             :             | WITH
   18331             :         ;
   18332             : 
   18333             : /*
   18334             :  * While all keywords can be used as column labels when preceded by AS,
   18335             :  * not all of them can be used as a "bare" column label without AS.
   18336             :  * Those that can be used as a bare label must be listed here,
   18337             :  * in addition to appearing in one of the category lists above.
   18338             :  *
   18339             :  * Always add a new keyword to this list if possible.  Mark it BARE_LABEL
   18340             :  * in kwlist.h if it is included here, or AS_LABEL if it is not.
   18341             :  */
   18342             : bare_label_keyword:
   18343             :               ABORT_P
   18344             :             | ABSENT
   18345             :             | ABSOLUTE_P
   18346             :             | ACCESS
   18347             :             | ACTION
   18348             :             | ADD_P
   18349             :             | ADMIN
   18350             :             | AFTER
   18351             :             | AGGREGATE
   18352             :             | ALL
   18353             :             | ALSO
   18354             :             | ALTER
   18355             :             | ALWAYS
   18356             :             | ANALYSE
   18357             :             | ANALYZE
   18358             :             | AND
   18359             :             | ANY
   18360             :             | ASC
   18361             :             | ASENSITIVE
   18362             :             | ASSERTION
   18363             :             | ASSIGNMENT
   18364             :             | ASYMMETRIC
   18365             :             | AT
   18366             :             | ATOMIC
   18367             :             | ATTACH
   18368             :             | ATTRIBUTE
   18369             :             | AUTHORIZATION
   18370             :             | BACKWARD
   18371             :             | BEFORE
   18372             :             | BEGIN_P
   18373             :             | BETWEEN
   18374             :             | BIGINT
   18375             :             | BINARY
   18376             :             | BIT
   18377             :             | BOOLEAN_P
   18378             :             | BOTH
   18379             :             | BREADTH
   18380             :             | BY
   18381             :             | CACHE
   18382             :             | CALL
   18383             :             | CALLED
   18384             :             | CASCADE
   18385             :             | CASCADED
   18386             :             | CASE
   18387             :             | CAST
   18388             :             | CATALOG_P
   18389             :             | CHAIN
   18390             :             | CHARACTERISTICS
   18391             :             | CHECK
   18392             :             | CHECKPOINT
   18393             :             | CLASS
   18394             :             | CLOSE
   18395             :             | CLUSTER
   18396             :             | COALESCE
   18397             :             | COLLATE
   18398             :             | COLLATION
   18399             :             | COLUMN
   18400             :             | COLUMNS
   18401             :             | COMMENT
   18402             :             | COMMENTS
   18403             :             | COMMIT
   18404             :             | COMMITTED
   18405             :             | COMPRESSION
   18406             :             | CONCURRENTLY
   18407             :             | CONDITIONAL
   18408             :             | CONFIGURATION
   18409             :             | CONFLICT
   18410             :             | CONNECTION
   18411             :             | CONSTRAINT
   18412             :             | CONSTRAINTS
   18413             :             | CONTENT_P
   18414             :             | CONTINUE_P
   18415             :             | CONVERSION_P
   18416             :             | COPY
   18417             :             | COST
   18418             :             | CROSS
   18419             :             | CSV
   18420             :             | CUBE
   18421             :             | CURRENT_P
   18422             :             | CURRENT_CATALOG
   18423             :             | CURRENT_DATE
   18424             :             | CURRENT_ROLE
   18425             :             | CURRENT_SCHEMA
   18426             :             | CURRENT_TIME
   18427             :             | CURRENT_TIMESTAMP
   18428             :             | CURRENT_USER
   18429             :             | CURSOR
   18430             :             | CYCLE
   18431             :             | DATA_P
   18432             :             | DATABASE
   18433             :             | DEALLOCATE
   18434             :             | DEC
   18435             :             | DECIMAL_P
   18436             :             | DECLARE
   18437             :             | DEFAULT
   18438             :             | DEFAULTS
   18439             :             | DEFERRABLE
   18440             :             | DEFERRED
   18441             :             | DEFINER
   18442             :             | DELETE_P
   18443             :             | DELIMITER
   18444             :             | DELIMITERS
   18445             :             | DEPENDS
   18446             :             | DEPTH
   18447             :             | DESC
   18448             :             | DETACH
   18449             :             | DICTIONARY
   18450             :             | DISABLE_P
   18451             :             | DISCARD
   18452             :             | DISTINCT
   18453             :             | DO
   18454             :             | DOCUMENT_P
   18455             :             | DOMAIN_P
   18456             :             | DOUBLE_P
   18457             :             | DROP
   18458             :             | EACH
   18459             :             | ELSE
   18460             :             | EMPTY_P
   18461             :             | ENABLE_P
   18462             :             | ENCODING
   18463             :             | ENCRYPTED
   18464             :             | END_P
   18465             :             | ENFORCED
   18466             :             | ENUM_P
   18467             :             | ERROR_P
   18468             :             | ESCAPE
   18469             :             | EVENT
   18470             :             | EXCLUDE
   18471             :             | EXCLUDING
   18472             :             | EXCLUSIVE
   18473             :             | EXECUTE
   18474             :             | EXISTS
   18475             :             | EXPLAIN
   18476             :             | EXPRESSION
   18477             :             | EXTENSION
   18478             :             | EXTERNAL
   18479             :             | EXTRACT
   18480             :             | FALSE_P
   18481             :             | FAMILY
   18482             :             | FINALIZE
   18483             :             | FIRST_P
   18484             :             | FLOAT_P
   18485             :             | FOLLOWING
   18486             :             | FORCE
   18487             :             | FOREIGN
   18488             :             | FORMAT
   18489             :             | FORWARD
   18490             :             | FREEZE
   18491             :             | FULL
   18492             :             | FUNCTION
   18493             :             | FUNCTIONS
   18494             :             | GENERATED
   18495             :             | GLOBAL
   18496             :             | GRANTED
   18497             :             | GREATEST
   18498             :             | GROUPING
   18499             :             | GROUPS
   18500             :             | HANDLER
   18501             :             | HEADER_P
   18502             :             | HOLD
   18503             :             | IDENTITY_P
   18504             :             | IF_P
   18505             :             | ILIKE
   18506             :             | IMMEDIATE
   18507             :             | IMMUTABLE
   18508             :             | IMPLICIT_P
   18509             :             | IMPORT_P
   18510             :             | IN_P
   18511             :             | INCLUDE
   18512             :             | INCLUDING
   18513             :             | INCREMENT
   18514             :             | INDENT
   18515             :             | INDEX
   18516             :             | INDEXES
   18517             :             | INHERIT
   18518             :             | INHERITS
   18519             :             | INITIALLY
   18520             :             | INLINE_P
   18521             :             | INNER_P
   18522             :             | INOUT
   18523             :             | INPUT_P
   18524             :             | INSENSITIVE
   18525             :             | INSERT
   18526             :             | INSTEAD
   18527             :             | INT_P
   18528             :             | INTEGER
   18529             :             | INTERVAL
   18530             :             | INVOKER
   18531             :             | IS
   18532             :             | ISOLATION
   18533             :             | JOIN
   18534             :             | JSON
   18535             :             | JSON_ARRAY
   18536             :             | JSON_ARRAYAGG
   18537             :             | JSON_EXISTS
   18538             :             | JSON_OBJECT
   18539             :             | JSON_OBJECTAGG
   18540             :             | JSON_QUERY
   18541             :             | JSON_SCALAR
   18542             :             | JSON_SERIALIZE
   18543             :             | JSON_TABLE
   18544             :             | JSON_VALUE
   18545             :             | KEEP
   18546             :             | KEY
   18547             :             | KEYS
   18548             :             | LABEL
   18549             :             | LANGUAGE
   18550             :             | LARGE_P
   18551             :             | LAST_P
   18552             :             | LATERAL_P
   18553             :             | LEADING
   18554             :             | LEAKPROOF
   18555             :             | LEAST
   18556             :             | LEFT
   18557             :             | LEVEL
   18558             :             | LIKE
   18559             :             | LISTEN
   18560             :             | LOAD
   18561             :             | LOCAL
   18562             :             | LOCALTIME
   18563             :             | LOCALTIMESTAMP
   18564             :             | LOCATION
   18565             :             | LOCK_P
   18566             :             | LOCKED
   18567             :             | LOGGED
   18568             :             | MAPPING
   18569             :             | MATCH
   18570             :             | MATCHED
   18571             :             | MATERIALIZED
   18572             :             | MAXVALUE
   18573             :             | MERGE
   18574             :             | MERGE_ACTION
   18575             :             | METHOD
   18576             :             | MINVALUE
   18577             :             | MODE
   18578             :             | MOVE
   18579             :             | NAME_P
   18580             :             | NAMES
   18581             :             | NATIONAL
   18582             :             | NATURAL
   18583             :             | NCHAR
   18584             :             | NESTED
   18585             :             | NEW
   18586             :             | NEXT
   18587             :             | NFC
   18588             :             | NFD
   18589             :             | NFKC
   18590             :             | NFKD
   18591             :             | NO
   18592             :             | NONE
   18593             :             | NORMALIZE
   18594             :             | NORMALIZED
   18595             :             | NOT
   18596             :             | NOTHING
   18597             :             | NOTIFY
   18598             :             | NOWAIT
   18599             :             | NULL_P
   18600             :             | NULLIF
   18601             :             | NULLS_P
   18602             :             | NUMERIC
   18603             :             | OBJECT_P
   18604             :             | OBJECTS_P
   18605             :             | OF
   18606             :             | OFF
   18607             :             | OIDS
   18608             :             | OLD
   18609             :             | OMIT
   18610             :             | ONLY
   18611             :             | OPERATOR
   18612             :             | OPTION
   18613             :             | OPTIONS
   18614             :             | OR
   18615             :             | ORDINALITY
   18616             :             | OTHERS
   18617             :             | OUT_P
   18618             :             | OUTER_P
   18619             :             | OVERLAY
   18620             :             | OVERRIDING
   18621             :             | OWNED
   18622             :             | OWNER
   18623             :             | PARALLEL
   18624             :             | PARAMETER
   18625             :             | PARSER
   18626             :             | PARTIAL
   18627             :             | PARTITION
   18628             :             | PASSING
   18629             :             | PASSWORD
   18630             :             | PATH
   18631             :             | PERIOD
   18632             :             | PLACING
   18633             :             | PLAN
   18634             :             | PLANS
   18635             :             | POLICY
   18636             :             | POSITION
   18637             :             | PRECEDING
   18638             :             | PREPARE
   18639             :             | PREPARED
   18640             :             | PRESERVE
   18641             :             | PRIMARY
   18642             :             | PRIOR
   18643             :             | PRIVILEGES
   18644             :             | PROCEDURAL
   18645             :             | PROCEDURE
   18646             :             | PROCEDURES
   18647             :             | PROGRAM
   18648             :             | PUBLICATION
   18649             :             | QUOTE
   18650             :             | QUOTES
   18651             :             | RANGE
   18652             :             | READ
   18653             :             | REAL
   18654             :             | REASSIGN
   18655             :             | RECURSIVE
   18656             :             | REF_P
   18657             :             | REFERENCES
   18658             :             | REFERENCING
   18659             :             | REFRESH
   18660             :             | REINDEX
   18661             :             | RELATIVE_P
   18662             :             | RELEASE
   18663             :             | RENAME
   18664             :             | REPEATABLE
   18665             :             | REPLACE
   18666             :             | REPLICA
   18667             :             | RESET
   18668             :             | RESTART
   18669             :             | RESTRICT
   18670             :             | RETURN
   18671             :             | RETURNS
   18672             :             | REVOKE
   18673             :             | RIGHT
   18674             :             | ROLE
   18675             :             | ROLLBACK
   18676             :             | ROLLUP
   18677             :             | ROUTINE
   18678             :             | ROUTINES
   18679             :             | ROW
   18680             :             | ROWS
   18681             :             | RULE
   18682             :             | SAVEPOINT
   18683             :             | SCALAR
   18684             :             | SCHEMA
   18685             :             | SCHEMAS
   18686             :             | SCROLL
   18687             :             | SEARCH
   18688             :             | SECURITY
   18689             :             | SELECT
   18690             :             | SEQUENCE
   18691             :             | SEQUENCES
   18692             :             | SERIALIZABLE
   18693             :             | SERVER
   18694             :             | SESSION
   18695             :             | SESSION_USER
   18696             :             | SET
   18697             :             | SETOF
   18698             :             | SETS
   18699             :             | SHARE
   18700             :             | SHOW
   18701             :             | SIMILAR
   18702             :             | SIMPLE
   18703             :             | SKIP
   18704             :             | SMALLINT
   18705             :             | SNAPSHOT
   18706             :             | SOME
   18707             :             | SOURCE
   18708             :             | SQL_P
   18709             :             | STABLE
   18710             :             | STANDALONE_P
   18711             :             | START
   18712             :             | STATEMENT
   18713             :             | STATISTICS
   18714             :             | STDIN
   18715             :             | STDOUT
   18716             :             | STORAGE
   18717             :             | STORED
   18718             :             | STRICT_P
   18719             :             | STRING_P
   18720             :             | STRIP_P
   18721             :             | SUBSCRIPTION
   18722             :             | SUBSTRING
   18723             :             | SUPPORT
   18724             :             | SYMMETRIC
   18725             :             | SYSID
   18726             :             | SYSTEM_P
   18727             :             | SYSTEM_USER
   18728             :             | TABLE
   18729             :             | TABLES
   18730             :             | TABLESAMPLE
   18731             :             | TABLESPACE
   18732             :             | TARGET
   18733             :             | TEMP
   18734             :             | TEMPLATE
   18735             :             | TEMPORARY
   18736             :             | TEXT_P
   18737             :             | THEN
   18738             :             | TIES
   18739             :             | TIME
   18740             :             | TIMESTAMP
   18741             :             | TRAILING
   18742             :             | TRANSACTION
   18743             :             | TRANSFORM
   18744             :             | TREAT
   18745             :             | TRIGGER
   18746             :             | TRIM
   18747             :             | TRUE_P
   18748             :             | TRUNCATE
   18749             :             | TRUSTED
   18750             :             | TYPE_P
   18751             :             | TYPES_P
   18752             :             | UESCAPE
   18753             :             | UNBOUNDED
   18754             :             | UNCOMMITTED
   18755             :             | UNCONDITIONAL
   18756             :             | UNENCRYPTED
   18757             :             | UNIQUE
   18758             :             | UNKNOWN
   18759             :             | UNLISTEN
   18760             :             | UNLOGGED
   18761             :             | UNTIL
   18762             :             | UPDATE
   18763             :             | USER
   18764             :             | USING
   18765             :             | VACUUM
   18766             :             | VALID
   18767             :             | VALIDATE
   18768             :             | VALIDATOR
   18769             :             | VALUE_P
   18770             :             | VALUES
   18771             :             | VARCHAR
   18772             :             | VARIADIC
   18773             :             | VERBOSE
   18774             :             | VERSION_P
   18775             :             | VIEW
   18776             :             | VIEWS
   18777             :             | VIRTUAL
   18778             :             | VOLATILE
   18779             :             | WHEN
   18780             :             | WHITESPACE_P
   18781             :             | WORK
   18782             :             | WRAPPER
   18783             :             | WRITE
   18784             :             | XML_P
   18785             :             | XMLATTRIBUTES
   18786             :             | XMLCONCAT
   18787             :             | XMLELEMENT
   18788             :             | XMLEXISTS
   18789             :             | XMLFOREST
   18790             :             | XMLNAMESPACES
   18791             :             | XMLPARSE
   18792             :             | XMLPI
   18793             :             | XMLROOT
   18794             :             | XMLSERIALIZE
   18795             :             | XMLTABLE
   18796             :             | YES_P
   18797             :             | ZONE
   18798             :         ;
   18799             : 
   18800             : %%
   18801             : 
   18802             : /*
   18803             :  * The signature of this function is required by bison.  However, we
   18804             :  * ignore the passed yylloc and instead use the last token position
   18805             :  * available from the scanner.
   18806             :  */
   18807             : static void
   18808         696 : base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
   18809             : {
   18810         696 :     parser_yyerror(msg);
   18811             : }
   18812             : 
   18813             : static RawStmt *
   18814      813120 : makeRawStmt(Node *stmt, int stmt_location)
   18815             : {
   18816      813120 :     RawStmt    *rs = makeNode(RawStmt);
   18817             : 
   18818      813120 :     rs->stmt = stmt;
   18819      813120 :     rs->stmt_location = stmt_location;
   18820      813120 :     rs->stmt_len = 0;            /* might get changed later */
   18821      813120 :     return rs;
   18822             : }
   18823             : 
   18824             : /* Adjust a RawStmt to reflect that it doesn't run to the end of the string */
   18825             : static void
   18826      583676 : updateRawStmtEnd(RawStmt *rs, int end_location)
   18827             : {
   18828             :     /*
   18829             :      * If we already set the length, don't change it.  This is for situations
   18830             :      * like "select foo ;; select bar" where the same statement will be last
   18831             :      * in the string for more than one semicolon.
   18832             :      */
   18833      583676 :     if (rs->stmt_len > 0)
   18834         642 :         return;
   18835             : 
   18836             :     /* OK, update length of RawStmt */
   18837      583034 :     rs->stmt_len = end_location - rs->stmt_location;
   18838             : }
   18839             : 
   18840             : static Node *
   18841     1808128 : makeColumnRef(char *colname, List *indirection,
   18842             :               int location, core_yyscan_t yyscanner)
   18843             : {
   18844             :     /*
   18845             :      * Generate a ColumnRef node, with an A_Indirection node added if there is
   18846             :      * any subscripting in the specified indirection list.  However, any field
   18847             :      * selection at the start of the indirection list must be transposed into
   18848             :      * the "fields" part of the ColumnRef node.
   18849             :      */
   18850     1808128 :     ColumnRef  *c = makeNode(ColumnRef);
   18851     1808128 :     int         nfields = 0;
   18852             :     ListCell   *l;
   18853             : 
   18854     1808128 :     c->location = location;
   18855     2861766 :     foreach(l, indirection)
   18856             :     {
   18857     1063566 :         if (IsA(lfirst(l), A_Indices))
   18858             :         {
   18859        9928 :             A_Indirection *i = makeNode(A_Indirection);
   18860             : 
   18861        9928 :             if (nfields == 0)
   18862             :             {
   18863             :                 /* easy case - all indirection goes to A_Indirection */
   18864        7210 :                 c->fields = list_make1(makeString(colname));
   18865        7210 :                 i->indirection = check_indirection(indirection, yyscanner);
   18866             :             }
   18867             :             else
   18868             :             {
   18869             :                 /* got to split the list in two */
   18870        2718 :                 i->indirection = check_indirection(list_copy_tail(indirection,
   18871             :                                                                   nfields),
   18872             :                                                    yyscanner);
   18873        2718 :                 indirection = list_truncate(indirection, nfields);
   18874        2718 :                 c->fields = lcons(makeString(colname), indirection);
   18875             :             }
   18876        9928 :             i->arg = (Node *) c;
   18877        9928 :             return (Node *) i;
   18878             :         }
   18879     1053638 :         else if (IsA(lfirst(l), A_Star))
   18880             :         {
   18881             :             /* We only allow '*' at the end of a ColumnRef */
   18882        5514 :             if (lnext(indirection, l) != NULL)
   18883           0 :                 parser_yyerror("improper use of \"*\"");
   18884             :         }
   18885     1053638 :         nfields++;
   18886             :     }
   18887             :     /* No subscripting, so all indirection gets added to field list */
   18888     1798200 :     c->fields = lcons(makeString(colname), indirection);
   18889     1798200 :     return (Node *) c;
   18890             : }
   18891             : 
   18892             : static Node *
   18893      314182 : makeTypeCast(Node *arg, TypeName *typename, int location)
   18894             : {
   18895      314182 :     TypeCast   *n = makeNode(TypeCast);
   18896             : 
   18897      314182 :     n->arg = arg;
   18898      314182 :     n->typeName = typename;
   18899      314182 :     n->location = location;
   18900      314182 :     return (Node *) n;
   18901             : }
   18902             : 
   18903             : static Node *
   18904       16326 : makeStringConstCast(char *str, int location, TypeName *typename)
   18905             : {
   18906       16326 :     Node       *s = makeStringConst(str, location);
   18907             : 
   18908       16326 :     return makeTypeCast(s, typename, -1);
   18909             : }
   18910             : 
   18911             : static Node *
   18912      388186 : makeIntConst(int val, int location)
   18913             : {
   18914      388186 :     A_Const    *n = makeNode(A_Const);
   18915             : 
   18916      388186 :     n->val.ival.type = T_Integer;
   18917      388186 :     n->val.ival.ival = val;
   18918      388186 :     n->location = location;
   18919             : 
   18920      388186 :     return (Node *) n;
   18921             : }
   18922             : 
   18923             : static Node *
   18924       11932 : makeFloatConst(char *str, int location)
   18925             : {
   18926       11932 :     A_Const    *n = makeNode(A_Const);
   18927             : 
   18928       11932 :     n->val.fval.type = T_Float;
   18929       11932 :     n->val.fval.fval = str;
   18930       11932 :     n->location = location;
   18931             : 
   18932       11932 :     return (Node *) n;
   18933             : }
   18934             : 
   18935             : static Node *
   18936       67230 : makeBoolAConst(bool state, int location)
   18937             : {
   18938       67230 :     A_Const    *n = makeNode(A_Const);
   18939             : 
   18940       67230 :     n->val.boolval.type = T_Boolean;
   18941       67230 :     n->val.boolval.boolval = state;
   18942       67230 :     n->location = location;
   18943             : 
   18944       67230 :     return (Node *) n;
   18945             : }
   18946             : 
   18947             : static Node *
   18948        4056 : makeBitStringConst(char *str, int location)
   18949             : {
   18950        4056 :     A_Const    *n = makeNode(A_Const);
   18951             : 
   18952        4056 :     n->val.bsval.type = T_BitString;
   18953        4056 :     n->val.bsval.bsval = str;
   18954        4056 :     n->location = location;
   18955             : 
   18956        4056 :     return (Node *) n;
   18957             : }
   18958             : 
   18959             : static Node *
   18960       67510 : makeNullAConst(int location)
   18961             : {
   18962       67510 :     A_Const    *n = makeNode(A_Const);
   18963             : 
   18964       67510 :     n->isnull = true;
   18965       67510 :     n->location = location;
   18966             : 
   18967       67510 :     return (Node *) n;
   18968             : }
   18969             : 
   18970             : static Node *
   18971        5348 : makeAConst(Node *v, int location)
   18972             : {
   18973             :     Node       *n;
   18974             : 
   18975        5348 :     switch (v->type)
   18976             :     {
   18977         218 :         case T_Float:
   18978         218 :             n = makeFloatConst(castNode(Float, v)->fval, location);
   18979         218 :             break;
   18980             : 
   18981        5130 :         case T_Integer:
   18982        5130 :             n = makeIntConst(castNode(Integer, v)->ival, location);
   18983        5130 :             break;
   18984             : 
   18985           0 :         default:
   18986             :             /* currently not used */
   18987             :             Assert(false);
   18988           0 :             n = NULL;
   18989             :     }
   18990             : 
   18991        5348 :     return n;
   18992             : }
   18993             : 
   18994             : /* makeRoleSpec
   18995             :  * Create a RoleSpec with the given type
   18996             :  */
   18997             : static RoleSpec *
   18998       33438 : makeRoleSpec(RoleSpecType type, int location)
   18999             : {
   19000       33438 :     RoleSpec   *spec = makeNode(RoleSpec);
   19001             : 
   19002       33438 :     spec->roletype = type;
   19003       33438 :     spec->location = location;
   19004             : 
   19005       33438 :     return spec;
   19006             : }
   19007             : 
   19008             : /* check_qualified_name --- check the result of qualified_name production
   19009             :  *
   19010             :  * It's easiest to let the grammar production for qualified_name allow
   19011             :  * subscripts and '*', which we then must reject here.
   19012             :  */
   19013             : static void
   19014      243312 : check_qualified_name(List *names, core_yyscan_t yyscanner)
   19015             : {
   19016             :     ListCell   *i;
   19017             : 
   19018      486624 :     foreach(i, names)
   19019             :     {
   19020      243312 :         if (!IsA(lfirst(i), String))
   19021           0 :             parser_yyerror("syntax error");
   19022             :     }
   19023      243312 : }
   19024             : 
   19025             : /* check_func_name --- check the result of func_name production
   19026             :  *
   19027             :  * It's easiest to let the grammar production for func_name allow subscripts
   19028             :  * and '*', which we then must reject here.
   19029             :  */
   19030             : static List *
   19031      126328 : check_func_name(List *names, core_yyscan_t yyscanner)
   19032             : {
   19033             :     ListCell   *i;
   19034             : 
   19035      378984 :     foreach(i, names)
   19036             :     {
   19037      252656 :         if (!IsA(lfirst(i), String))
   19038           0 :             parser_yyerror("syntax error");
   19039             :     }
   19040      126328 :     return names;
   19041             : }
   19042             : 
   19043             : /* check_indirection --- check the result of indirection production
   19044             :  *
   19045             :  * We only allow '*' at the end of the list, but it's hard to enforce that
   19046             :  * in the grammar, so do it here.
   19047             :  */
   19048             : static List *
   19049       83022 : check_indirection(List *indirection, core_yyscan_t yyscanner)
   19050             : {
   19051             :     ListCell   *l;
   19052             : 
   19053      110652 :     foreach(l, indirection)
   19054             :     {
   19055       27630 :         if (IsA(lfirst(l), A_Star))
   19056             :         {
   19057        1462 :             if (lnext(indirection, l) != NULL)
   19058           0 :                 parser_yyerror("improper use of \"*\"");
   19059             :         }
   19060             :     }
   19061       83022 :     return indirection;
   19062             : }
   19063             : 
   19064             : /* extractArgTypes()
   19065             :  * Given a list of FunctionParameter nodes, extract a list of just the
   19066             :  * argument types (TypeNames) for input parameters only.  This is what
   19067             :  * is needed to look up an existing function, which is what is wanted by
   19068             :  * the productions that use this call.
   19069             :  */
   19070             : static List *
   19071       18400 : extractArgTypes(List *parameters)
   19072             : {
   19073       18400 :     List       *result = NIL;
   19074             :     ListCell   *i;
   19075             : 
   19076       42268 :     foreach(i, parameters)
   19077             :     {
   19078       23868 :         FunctionParameter *p = (FunctionParameter *) lfirst(i);
   19079             : 
   19080       23868 :         if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
   19081       23712 :             result = lappend(result, p->argType);
   19082             :     }
   19083       18400 :     return result;
   19084             : }
   19085             : 
   19086             : /* extractAggrArgTypes()
   19087             :  * As above, but work from the output of the aggr_args production.
   19088             :  */
   19089             : static List *
   19090         362 : extractAggrArgTypes(List *aggrargs)
   19091             : {
   19092             :     Assert(list_length(aggrargs) == 2);
   19093         362 :     return extractArgTypes((List *) linitial(aggrargs));
   19094             : }
   19095             : 
   19096             : /* makeOrderedSetArgs()
   19097             :  * Build the result of the aggr_args production (which see the comments for).
   19098             :  * This handles only the case where both given lists are nonempty, so that
   19099             :  * we have to deal with multiple VARIADIC arguments.
   19100             :  */
   19101             : static List *
   19102          32 : makeOrderedSetArgs(List *directargs, List *orderedargs,
   19103             :                    core_yyscan_t yyscanner)
   19104             : {
   19105          32 :     FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
   19106             :     Integer    *ndirectargs;
   19107             : 
   19108             :     /* No restriction unless last direct arg is VARIADIC */
   19109          32 :     if (lastd->mode == FUNC_PARAM_VARIADIC)
   19110             :     {
   19111          16 :         FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
   19112             : 
   19113             :         /*
   19114             :          * We ignore the names, though the aggr_arg production allows them; it
   19115             :          * doesn't allow default values, so those need not be checked.
   19116             :          */
   19117          16 :         if (list_length(orderedargs) != 1 ||
   19118          16 :             firsto->mode != FUNC_PARAM_VARIADIC ||
   19119          16 :             !equal(lastd->argType, firsto->argType))
   19120           0 :             ereport(ERROR,
   19121             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19122             :                      errmsg("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
   19123             :                      parser_errposition(firsto->location)));
   19124             : 
   19125             :         /* OK, drop the duplicate VARIADIC argument from the internal form */
   19126          16 :         orderedargs = NIL;
   19127             :     }
   19128             : 
   19129             :     /* don't merge into the next line, as list_concat changes directargs */
   19130          32 :     ndirectargs = makeInteger(list_length(directargs));
   19131             : 
   19132          32 :     return list_make2(list_concat(directargs, orderedargs),
   19133             :                       ndirectargs);
   19134             : }
   19135             : 
   19136             : /* insertSelectOptions()
   19137             :  * Insert ORDER BY, etc into an already-constructed SelectStmt.
   19138             :  *
   19139             :  * This routine is just to avoid duplicating code in SelectStmt productions.
   19140             :  */
   19141             : static void
   19142       83502 : insertSelectOptions(SelectStmt *stmt,
   19143             :                     List *sortClause, List *lockingClause,
   19144             :                     SelectLimit *limitClause,
   19145             :                     WithClause *withClause,
   19146             :                     core_yyscan_t yyscanner)
   19147             : {
   19148             :     Assert(IsA(stmt, SelectStmt));
   19149             : 
   19150             :     /*
   19151             :      * Tests here are to reject constructs like
   19152             :      *  (SELECT foo ORDER BY bar) ORDER BY baz
   19153             :      */
   19154       83502 :     if (sortClause)
   19155             :     {
   19156       73996 :         if (stmt->sortClause)
   19157           0 :             ereport(ERROR,
   19158             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19159             :                      errmsg("multiple ORDER BY clauses not allowed"),
   19160             :                      parser_errposition(exprLocation((Node *) sortClause))));
   19161       73996 :         stmt->sortClause = sortClause;
   19162             :     }
   19163             :     /* We can handle multiple locking clauses, though */
   19164       83502 :     stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
   19165       83502 :     if (limitClause && limitClause->limitOffset)
   19166             :     {
   19167         860 :         if (stmt->limitOffset)
   19168           0 :             ereport(ERROR,
   19169             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19170             :                      errmsg("multiple OFFSET clauses not allowed"),
   19171             :                      parser_errposition(limitClause->offsetLoc)));
   19172         860 :         stmt->limitOffset = limitClause->limitOffset;
   19173             :     }
   19174       83502 :     if (limitClause && limitClause->limitCount)
   19175             :     {
   19176        4696 :         if (stmt->limitCount)
   19177           0 :             ereport(ERROR,
   19178             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19179             :                      errmsg("multiple LIMIT clauses not allowed"),
   19180             :                      parser_errposition(limitClause->countLoc)));
   19181        4696 :         stmt->limitCount = limitClause->limitCount;
   19182             :     }
   19183       83502 :     if (limitClause)
   19184             :     {
   19185             :         /* If there was a conflict, we must have detected it above */
   19186             :         Assert(!stmt->limitOption);
   19187        5162 :         if (!stmt->sortClause && limitClause->limitOption == LIMIT_OPTION_WITH_TIES)
   19188           6 :             ereport(ERROR,
   19189             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19190             :                      errmsg("WITH TIES cannot be specified without ORDER BY clause"),
   19191             :                      parser_errposition(limitClause->optionLoc)));
   19192        5156 :         if (limitClause->limitOption == LIMIT_OPTION_WITH_TIES && stmt->lockingClause)
   19193             :         {
   19194             :             ListCell   *lc;
   19195             : 
   19196           6 :             foreach(lc, stmt->lockingClause)
   19197             :             {
   19198           6 :                 LockingClause *lock = lfirst_node(LockingClause, lc);
   19199             : 
   19200           6 :                 if (lock->waitPolicy == LockWaitSkip)
   19201           6 :                     ereport(ERROR,
   19202             :                             (errcode(ERRCODE_SYNTAX_ERROR),
   19203             :                              errmsg("%s and %s options cannot be used together",
   19204             :                                     "SKIP LOCKED", "WITH TIES"),
   19205             :                              parser_errposition(limitClause->optionLoc)));
   19206             :             }
   19207             :         }
   19208        5150 :         stmt->limitOption = limitClause->limitOption;
   19209             :     }
   19210       83490 :     if (withClause)
   19211             :     {
   19212        2882 :         if (stmt->withClause)
   19213           0 :             ereport(ERROR,
   19214             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19215             :                      errmsg("multiple WITH clauses not allowed"),
   19216             :                      parser_errposition(exprLocation((Node *) withClause))));
   19217        2882 :         stmt->withClause = withClause;
   19218             :     }
   19219       83490 : }
   19220             : 
   19221             : static Node *
   19222       19712 : makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
   19223             : {
   19224       19712 :     SelectStmt *n = makeNode(SelectStmt);
   19225             : 
   19226       19712 :     n->op = op;
   19227       19712 :     n->all = all;
   19228       19712 :     n->larg = (SelectStmt *) larg;
   19229       19712 :     n->rarg = (SelectStmt *) rarg;
   19230       19712 :     return (Node *) n;
   19231             : }
   19232             : 
   19233             : /* SystemFuncName()
   19234             :  * Build a properly-qualified reference to a built-in function.
   19235             :  */
   19236             : List *
   19237       19386 : SystemFuncName(char *name)
   19238             : {
   19239       19386 :     return list_make2(makeString("pg_catalog"), makeString(name));
   19240             : }
   19241             : 
   19242             : /* SystemTypeName()
   19243             :  * Build a properly-qualified reference to a built-in type.
   19244             :  *
   19245             :  * typmod is defaulted, but may be changed afterwards by caller.
   19246             :  * Likewise for the location.
   19247             :  */
   19248             : TypeName *
   19249      121770 : SystemTypeName(char *name)
   19250             : {
   19251      121770 :     return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
   19252             :                                                makeString(name)));
   19253             : }
   19254             : 
   19255             : /* doNegate()
   19256             :  * Handle negation of a numeric constant.
   19257             :  *
   19258             :  * Formerly, we did this here because the optimizer couldn't cope with
   19259             :  * indexquals that looked like "var = -4" --- it wants "var = const"
   19260             :  * and a unary minus operator applied to a constant didn't qualify.
   19261             :  * As of Postgres 7.0, that problem doesn't exist anymore because there
   19262             :  * is a constant-subexpression simplifier in the optimizer.  However,
   19263             :  * there's still a good reason for doing this here, which is that we can
   19264             :  * postpone committing to a particular internal representation for simple
   19265             :  * negative constants.  It's better to leave "-123.456" in string form
   19266             :  * until we know what the desired type is.
   19267             :  */
   19268             : static Node *
   19269        9258 : doNegate(Node *n, int location)
   19270             : {
   19271        9258 :     if (IsA(n, A_Const))
   19272             :     {
   19273        8248 :         A_Const    *con = (A_Const *) n;
   19274             : 
   19275             :         /* report the constant's location as that of the '-' sign */
   19276        8248 :         con->location = location;
   19277             : 
   19278        8248 :         if (IsA(&con->val, Integer))
   19279             :         {
   19280        7290 :             con->val.ival.ival = -con->val.ival.ival;
   19281        7290 :             return n;
   19282             :         }
   19283         958 :         if (IsA(&con->val, Float))
   19284             :         {
   19285         958 :             doNegateFloat(&con->val.fval);
   19286         958 :             return n;
   19287             :         }
   19288             :     }
   19289             : 
   19290        1010 :     return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
   19291             : }
   19292             : 
   19293             : static void
   19294         978 : doNegateFloat(Float *v)
   19295             : {
   19296         978 :     char       *oldval = v->fval;
   19297             : 
   19298         978 :     if (*oldval == '+')
   19299           0 :         oldval++;
   19300         978 :     if (*oldval == '-')
   19301           0 :         v->fval = oldval + 1;    /* just strip the '-' */
   19302             :     else
   19303         978 :         v->fval = psprintf("-%s", oldval);
   19304         978 : }
   19305             : 
   19306             : static Node *
   19307      232398 : makeAndExpr(Node *lexpr, Node *rexpr, int location)
   19308             : {
   19309             :     /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
   19310      232398 :     if (IsA(lexpr, BoolExpr))
   19311             :     {
   19312      110430 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   19313             : 
   19314      110430 :         if (blexpr->boolop == AND_EXPR)
   19315             :         {
   19316      107902 :             blexpr->args = lappend(blexpr->args, rexpr);
   19317      107902 :             return (Node *) blexpr;
   19318             :         }
   19319             :     }
   19320      124496 :     return (Node *) makeBoolExpr(AND_EXPR, list_make2(lexpr, rexpr), location);
   19321             : }
   19322             : 
   19323             : static Node *
   19324       16048 : makeOrExpr(Node *lexpr, Node *rexpr, int location)
   19325             : {
   19326             :     /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
   19327       16048 :     if (IsA(lexpr, BoolExpr))
   19328             :     {
   19329        5650 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   19330             : 
   19331        5650 :         if (blexpr->boolop == OR_EXPR)
   19332             :         {
   19333        4138 :             blexpr->args = lappend(blexpr->args, rexpr);
   19334        4138 :             return (Node *) blexpr;
   19335             :         }
   19336             :     }
   19337       11910 :     return (Node *) makeBoolExpr(OR_EXPR, list_make2(lexpr, rexpr), location);
   19338             : }
   19339             : 
   19340             : static Node *
   19341       16290 : makeNotExpr(Node *expr, int location)
   19342             : {
   19343       16290 :     return (Node *) makeBoolExpr(NOT_EXPR, list_make1(expr), location);
   19344             : }
   19345             : 
   19346             : static Node *
   19347        8218 : makeAArrayExpr(List *elements, int location, int location_end)
   19348             : {
   19349        8218 :     A_ArrayExpr *n = makeNode(A_ArrayExpr);
   19350             : 
   19351        8218 :     n->elements = elements;
   19352        8218 :     n->location = location;
   19353        8218 :     n->list_start = location;
   19354        8218 :     n->list_end = location_end;
   19355        8218 :     return (Node *) n;
   19356             : }
   19357             : 
   19358             : static Node *
   19359        2746 : makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod, int location)
   19360             : {
   19361        2746 :     SQLValueFunction *svf = makeNode(SQLValueFunction);
   19362             : 
   19363        2746 :     svf->op = op;
   19364             :     /* svf->type will be filled during parse analysis */
   19365        2746 :     svf->typmod = typmod;
   19366        2746 :     svf->location = location;
   19367        2746 :     return (Node *) svf;
   19368             : }
   19369             : 
   19370             : static Node *
   19371         596 : makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
   19372             :             int location)
   19373             : {
   19374         596 :     XmlExpr    *x = makeNode(XmlExpr);
   19375             : 
   19376         596 :     x->op = op;
   19377         596 :     x->name = name;
   19378             : 
   19379             :     /*
   19380             :      * named_args is a list of ResTarget; it'll be split apart into separate
   19381             :      * expression and name lists in transformXmlExpr().
   19382             :      */
   19383         596 :     x->named_args = named_args;
   19384         596 :     x->arg_names = NIL;
   19385         596 :     x->args = args;
   19386             :     /* xmloption, if relevant, must be filled in by caller */
   19387             :     /* type and typmod will be filled in during parse analysis */
   19388         596 :     x->type = InvalidOid;        /* marks the node as not analyzed */
   19389         596 :     x->location = location;
   19390         596 :     return (Node *) x;
   19391             : }
   19392             : 
   19393             : /*
   19394             :  * Merge the input and output parameters of a table function.
   19395             :  */
   19396             : static List *
   19397         194 : mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner)
   19398             : {
   19399             :     ListCell   *lc;
   19400             : 
   19401             :     /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
   19402         394 :     foreach(lc, func_args)
   19403             :     {
   19404         200 :         FunctionParameter *p = (FunctionParameter *) lfirst(lc);
   19405             : 
   19406         200 :         if (p->mode != FUNC_PARAM_DEFAULT &&
   19407           0 :             p->mode != FUNC_PARAM_IN &&
   19408           0 :             p->mode != FUNC_PARAM_VARIADIC)
   19409           0 :             ereport(ERROR,
   19410             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19411             :                      errmsg("OUT and INOUT arguments aren't allowed in TABLE functions"),
   19412             :                      parser_errposition(p->location)));
   19413             :     }
   19414             : 
   19415         194 :     return list_concat(func_args, columns);
   19416             : }
   19417             : 
   19418             : /*
   19419             :  * Determine return type of a TABLE function.  A single result column
   19420             :  * returns setof that column's type; otherwise return setof record.
   19421             :  */
   19422             : static TypeName *
   19423         194 : TableFuncTypeName(List *columns)
   19424             : {
   19425             :     TypeName   *result;
   19426             : 
   19427         194 :     if (list_length(columns) == 1)
   19428             :     {
   19429          62 :         FunctionParameter *p = (FunctionParameter *) linitial(columns);
   19430             : 
   19431          62 :         result = copyObject(p->argType);
   19432             :     }
   19433             :     else
   19434         132 :         result = SystemTypeName("record");
   19435             : 
   19436         194 :     result->setof = true;
   19437             : 
   19438         194 :     return result;
   19439             : }
   19440             : 
   19441             : /*
   19442             :  * Convert a list of (dotted) names to a RangeVar (like
   19443             :  * makeRangeVarFromNameList, but with position support).  The
   19444             :  * "AnyName" refers to the any_name production in the grammar.
   19445             :  */
   19446             : static RangeVar *
   19447        4736 : makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
   19448             : {
   19449        4736 :     RangeVar   *r = makeNode(RangeVar);
   19450             : 
   19451        4736 :     switch (list_length(names))
   19452             :     {
   19453        4646 :         case 1:
   19454        4646 :             r->catalogname = NULL;
   19455        4646 :             r->schemaname = NULL;
   19456        4646 :             r->relname = strVal(linitial(names));
   19457        4646 :             break;
   19458          90 :         case 2:
   19459          90 :             r->catalogname = NULL;
   19460          90 :             r->schemaname = strVal(linitial(names));
   19461          90 :             r->relname = strVal(lsecond(names));
   19462          90 :             break;
   19463           0 :         case 3:
   19464           0 :             r->catalogname = strVal(linitial(names));
   19465           0 :             r->schemaname = strVal(lsecond(names));
   19466           0 :             r->relname = strVal(lthird(names));
   19467           0 :             break;
   19468           0 :         default:
   19469           0 :             ereport(ERROR,
   19470             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19471             :                      errmsg("improper qualified name (too many dotted names): %s",
   19472             :                             NameListToString(names)),
   19473             :                      parser_errposition(position)));
   19474             :             break;
   19475             :     }
   19476             : 
   19477        4736 :     r->relpersistence = RELPERSISTENCE_PERMANENT;
   19478        4736 :     r->location = position;
   19479             : 
   19480        4736 :     return r;
   19481             : }
   19482             : 
   19483             : /*
   19484             :  * Convert a relation_name with name and namelist to a RangeVar using
   19485             :  * makeRangeVar.
   19486             :  */
   19487             : static RangeVar *
   19488      243312 : makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
   19489             :                               core_yyscan_t yyscanner)
   19490             : {
   19491             :     RangeVar   *r;
   19492             : 
   19493      243312 :     check_qualified_name(namelist, yyscanner);
   19494      243312 :     r = makeRangeVar(NULL, NULL, location);
   19495             : 
   19496      243312 :     switch (list_length(namelist))
   19497             :     {
   19498      243312 :         case 1:
   19499      243312 :             r->catalogname = NULL;
   19500      243312 :             r->schemaname = name;
   19501      243312 :             r->relname = strVal(linitial(namelist));
   19502      243312 :             break;
   19503           0 :         case 2:
   19504           0 :             r->catalogname = name;
   19505           0 :             r->schemaname = strVal(linitial(namelist));
   19506           0 :             r->relname = strVal(lsecond(namelist));
   19507           0 :             break;
   19508           0 :         default:
   19509           0 :             ereport(ERROR,
   19510             :                     errcode(ERRCODE_SYNTAX_ERROR),
   19511             :                     errmsg("improper qualified name (too many dotted names): %s",
   19512             :                            NameListToString(lcons(makeString(name), namelist))),
   19513             :                     parser_errposition(location));
   19514             :             break;
   19515             :     }
   19516             : 
   19517      243312 :     return r;
   19518             : }
   19519             : 
   19520             : /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
   19521             : static void
   19522       70128 : SplitColQualList(List *qualList,
   19523             :                  List **constraintList, CollateClause **collClause,
   19524             :                  core_yyscan_t yyscanner)
   19525             : {
   19526             :     ListCell   *cell;
   19527             : 
   19528       70128 :     *collClause = NULL;
   19529       90292 :     foreach(cell, qualList)
   19530             :     {
   19531       20164 :         Node       *n = (Node *) lfirst(cell);
   19532             : 
   19533       20164 :         if (IsA(n, Constraint))
   19534             :         {
   19535             :             /* keep it in list */
   19536       19390 :             continue;
   19537             :         }
   19538         774 :         if (IsA(n, CollateClause))
   19539             :         {
   19540         774 :             CollateClause *c = (CollateClause *) n;
   19541             : 
   19542         774 :             if (*collClause)
   19543           0 :                 ereport(ERROR,
   19544             :                         (errcode(ERRCODE_SYNTAX_ERROR),
   19545             :                          errmsg("multiple COLLATE clauses not allowed"),
   19546             :                          parser_errposition(c->location)));
   19547         774 :             *collClause = c;
   19548             :         }
   19549             :         else
   19550           0 :             elog(ERROR, "unexpected node type %d", (int) n->type);
   19551             :         /* remove non-Constraint nodes from qualList */
   19552         774 :         qualList = foreach_delete_current(qualList, cell);
   19553             :     }
   19554       70128 :     *constraintList = qualList;
   19555       70128 : }
   19556             : 
   19557             : /*
   19558             :  * Process result of ConstraintAttributeSpec, and set appropriate bool flags
   19559             :  * in the output command node.  Pass NULL for any flags the particular
   19560             :  * command doesn't support.
   19561             :  */
   19562             : static void
   19563       17866 : processCASbits(int cas_bits, int location, const char *constrType,
   19564             :                bool *deferrable, bool *initdeferred, bool *is_enforced,
   19565             :                bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner)
   19566             : {
   19567             :     /* defaults */
   19568       17866 :     if (deferrable)
   19569       15806 :         *deferrable = false;
   19570       17866 :     if (initdeferred)
   19571       15806 :         *initdeferred = false;
   19572       17866 :     if (not_valid)
   19573        3874 :         *not_valid = false;
   19574       17866 :     if (is_enforced)
   19575        3402 :         *is_enforced = true;
   19576             : 
   19577       17866 :     if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
   19578             :     {
   19579         230 :         if (deferrable)
   19580         230 :             *deferrable = true;
   19581             :         else
   19582           0 :             ereport(ERROR,
   19583             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19584             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19585             :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   19586             :                             constrType),
   19587             :                      parser_errposition(location)));
   19588             :     }
   19589             : 
   19590       17866 :     if (cas_bits & CAS_INITIALLY_DEFERRED)
   19591             :     {
   19592         146 :         if (initdeferred)
   19593         146 :             *initdeferred = true;
   19594             :         else
   19595           0 :             ereport(ERROR,
   19596             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19597             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19598             :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   19599             :                             constrType),
   19600             :                      parser_errposition(location)));
   19601             :     }
   19602             : 
   19603       17866 :     if (cas_bits & CAS_NOT_VALID)
   19604             :     {
   19605         714 :         if (not_valid)
   19606         714 :             *not_valid = true;
   19607             :         else
   19608           0 :             ereport(ERROR,
   19609             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19610             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19611             :                      errmsg("%s constraints cannot be marked NOT VALID",
   19612             :                             constrType),
   19613             :                      parser_errposition(location)));
   19614             :     }
   19615             : 
   19616       17866 :     if (cas_bits & CAS_NO_INHERIT)
   19617             :     {
   19618         244 :         if (no_inherit)
   19619         244 :             *no_inherit = true;
   19620             :         else
   19621           0 :             ereport(ERROR,
   19622             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19623             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19624             :                      errmsg("%s constraints cannot be marked NO INHERIT",
   19625             :                             constrType),
   19626             :                      parser_errposition(location)));
   19627             :     }
   19628             : 
   19629       17866 :     if (cas_bits & CAS_NOT_ENFORCED)
   19630             :     {
   19631         156 :         if (is_enforced)
   19632         150 :             *is_enforced = false;
   19633             :         else
   19634           6 :             ereport(ERROR,
   19635             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19636             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19637             :                      errmsg("%s constraints cannot be marked NOT ENFORCED",
   19638             :                             constrType),
   19639             :                      parser_errposition(location)));
   19640             : 
   19641             :         /*
   19642             :          * NB: The validated status is irrelevant when the constraint is set to
   19643             :          * NOT ENFORCED, but for consistency, it should be set accordingly.
   19644             :          * This ensures that if the constraint is later changed to ENFORCED, it
   19645             :          * will automatically be in the correct NOT VALIDATED state.
   19646             :          */
   19647         150 :         if (not_valid)
   19648         114 :             *not_valid = true;
   19649             :     }
   19650             : 
   19651       17860 :     if (cas_bits & CAS_ENFORCED)
   19652             :     {
   19653         102 :         if (is_enforced)
   19654          96 :             *is_enforced = true;
   19655             :         else
   19656           6 :             ereport(ERROR,
   19657             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19658             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19659             :                      errmsg("%s constraints cannot be marked ENFORCED",
   19660             :                             constrType),
   19661             :                      parser_errposition(location)));
   19662             :     }
   19663       17854 : }
   19664             : 
   19665             : /*
   19666             :  * Parse a user-supplied partition strategy string into parse node
   19667             :  * PartitionStrategy representation, or die trying.
   19668             :  */
   19669             : static PartitionStrategy
   19670        5112 : parsePartitionStrategy(char *strategy, int location, core_yyscan_t yyscanner)
   19671             : {
   19672        5112 :     if (pg_strcasecmp(strategy, "list") == 0)
   19673        2564 :         return PARTITION_STRATEGY_LIST;
   19674        2548 :     else if (pg_strcasecmp(strategy, "range") == 0)
   19675        2276 :         return PARTITION_STRATEGY_RANGE;
   19676         272 :     else if (pg_strcasecmp(strategy, "hash") == 0)
   19677         266 :         return PARTITION_STRATEGY_HASH;
   19678             : 
   19679           6 :     ereport(ERROR,
   19680             :             (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   19681             :              errmsg("unrecognized partitioning strategy \"%s\"", strategy),
   19682             :              parser_errposition(location)));
   19683             :     return PARTITION_STRATEGY_LIST; /* keep compiler quiet */
   19684             : 
   19685             : }
   19686             : 
   19687             : /*
   19688             :  * Process all_objects_list to set all_tables and/or all_sequences.
   19689             :  * Also, checks if the pub_object_type has been specified more than once.
   19690             :  */
   19691             : static void
   19692         148 : preprocess_pub_all_objtype_list(List *all_objects_list, bool *all_tables,
   19693             :                                 bool *all_sequences, core_yyscan_t yyscanner)
   19694             : {
   19695         148 :     if (!all_objects_list)
   19696           0 :         return;
   19697             : 
   19698         148 :     *all_tables = false;
   19699         148 :     *all_sequences = false;
   19700             : 
   19701         458 :     foreach_ptr(PublicationAllObjSpec, obj, all_objects_list)
   19702             :     {
   19703         186 :         if (obj->pubobjtype == PUBLICATION_ALL_TABLES)
   19704             :         {
   19705         132 :             if (*all_tables)
   19706           6 :                 ereport(ERROR,
   19707             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19708             :                         errmsg("invalid publication object list"),
   19709             :                         errdetail("ALL TABLES can be specified only once."),
   19710             :                         parser_errposition(obj->location));
   19711             : 
   19712         126 :             *all_tables = true;
   19713             :         }
   19714          54 :         else if (obj->pubobjtype == PUBLICATION_ALL_SEQUENCES)
   19715             :         {
   19716          54 :             if (*all_sequences)
   19717           6 :                 ereport(ERROR,
   19718             :                     errcode(ERRCODE_SYNTAX_ERROR),
   19719             :                         errmsg("invalid publication object list"),
   19720             :                         errdetail("ALL SEQUENCES can be specified only once."),
   19721             :                         parser_errposition(obj->location));
   19722             : 
   19723          48 :             *all_sequences = true;
   19724             :         }
   19725             :     }
   19726             : }
   19727             : 
   19728             : /*
   19729             :  * Process pubobjspec_list to check for errors in any of the objects and
   19730             :  * convert PUBLICATIONOBJ_CONTINUATION into appropriate PublicationObjSpecType.
   19731             :  */
   19732             : static void
   19733        1648 : preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
   19734             : {
   19735             :     ListCell   *cell;
   19736             :     PublicationObjSpec *pubobj;
   19737        1648 :     PublicationObjSpecType prevobjtype = PUBLICATIONOBJ_CONTINUATION;
   19738             : 
   19739        1648 :     if (!pubobjspec_list)
   19740           0 :         return;
   19741             : 
   19742        1648 :     pubobj = (PublicationObjSpec *) linitial(pubobjspec_list);
   19743        1648 :     if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   19744          12 :         ereport(ERROR,
   19745             :                 errcode(ERRCODE_SYNTAX_ERROR),
   19746             :                 errmsg("invalid publication object list"),
   19747             :                 errdetail("One of TABLE or TABLES IN SCHEMA must be specified before a standalone table or schema name."),
   19748             :                 parser_errposition(pubobj->location));
   19749             : 
   19750        3502 :     foreach(cell, pubobjspec_list)
   19751             :     {
   19752        1890 :         pubobj = (PublicationObjSpec *) lfirst(cell);
   19753             : 
   19754        1890 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   19755         174 :             pubobj->pubobjtype = prevobjtype;
   19756             : 
   19757        1890 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE)
   19758             :         {
   19759             :             /* relation name or pubtable must be set for this type of object */
   19760        1446 :             if (!pubobj->name && !pubobj->pubtable)
   19761           6 :                 ereport(ERROR,
   19762             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19763             :                         errmsg("invalid table name"),
   19764             :                         parser_errposition(pubobj->location));
   19765             : 
   19766        1440 :             if (pubobj->name)
   19767             :             {
   19768             :                 /* convert it to PublicationTable */
   19769          58 :                 PublicationTable *pubtable = makeNode(PublicationTable);
   19770             : 
   19771          58 :                 pubtable->relation =
   19772          58 :                     makeRangeVar(NULL, pubobj->name, pubobj->location);
   19773          58 :                 pubobj->pubtable = pubtable;
   19774          58 :                 pubobj->name = NULL;
   19775             :             }
   19776             :         }
   19777         444 :         else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
   19778          24 :                  pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA)
   19779             :         {
   19780             :             /* WHERE clause is not allowed on a schema object */
   19781         444 :             if (pubobj->pubtable && pubobj->pubtable->whereClause)
   19782           6 :                 ereport(ERROR,
   19783             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19784             :                         errmsg("WHERE clause not allowed for schema"),
   19785             :                         parser_errposition(pubobj->location));
   19786             : 
   19787             :             /* Column list is not allowed on a schema object */
   19788         438 :             if (pubobj->pubtable && pubobj->pubtable->columns)
   19789           6 :                 ereport(ERROR,
   19790             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19791             :                         errmsg("column specification not allowed for schema"),
   19792             :                         parser_errposition(pubobj->location));
   19793             : 
   19794             :             /*
   19795             :              * We can distinguish between the different type of schema objects
   19796             :              * based on whether name and pubtable is set.
   19797             :              */
   19798         432 :             if (pubobj->name)
   19799         402 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   19800          30 :             else if (!pubobj->name && !pubobj->pubtable)
   19801          24 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   19802             :             else
   19803           6 :                 ereport(ERROR,
   19804             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19805             :                         errmsg("invalid schema name"),
   19806             :                         parser_errposition(pubobj->location));
   19807             :         }
   19808             : 
   19809        1866 :         prevobjtype = pubobj->pubobjtype;
   19810             :     }
   19811             : }
   19812             : 
   19813             : /*----------
   19814             :  * Recursive view transformation
   19815             :  *
   19816             :  * Convert
   19817             :  *
   19818             :  *     CREATE RECURSIVE VIEW relname (aliases) AS query
   19819             :  *
   19820             :  * to
   19821             :  *
   19822             :  *     CREATE VIEW relname (aliases) AS
   19823             :  *         WITH RECURSIVE relname (aliases) AS (query)
   19824             :  *         SELECT aliases FROM relname
   19825             :  *
   19826             :  * Actually, just the WITH ... part, which is then inserted into the original
   19827             :  * view definition as the query.
   19828             :  * ----------
   19829             :  */
   19830             : static Node *
   19831          14 : makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
   19832             : {
   19833          14 :     SelectStmt *s = makeNode(SelectStmt);
   19834          14 :     WithClause *w = makeNode(WithClause);
   19835          14 :     CommonTableExpr *cte = makeNode(CommonTableExpr);
   19836          14 :     List       *tl = NIL;
   19837             :     ListCell   *lc;
   19838             : 
   19839             :     /* create common table expression */
   19840          14 :     cte->ctename = relname;
   19841          14 :     cte->aliascolnames = aliases;
   19842          14 :     cte->ctematerialized = CTEMaterializeDefault;
   19843          14 :     cte->ctequery = query;
   19844          14 :     cte->location = -1;
   19845             : 
   19846             :     /* create WITH clause and attach CTE */
   19847          14 :     w->recursive = true;
   19848          14 :     w->ctes = list_make1(cte);
   19849          14 :     w->location = -1;
   19850             : 
   19851             :     /*
   19852             :      * create target list for the new SELECT from the alias list of the
   19853             :      * recursive view specification
   19854             :      */
   19855          28 :     foreach(lc, aliases)
   19856             :     {
   19857          14 :         ResTarget  *rt = makeNode(ResTarget);
   19858             : 
   19859          14 :         rt->name = NULL;
   19860          14 :         rt->indirection = NIL;
   19861          14 :         rt->val = makeColumnRef(strVal(lfirst(lc)), NIL, -1, 0);
   19862          14 :         rt->location = -1;
   19863             : 
   19864          14 :         tl = lappend(tl, rt);
   19865             :     }
   19866             : 
   19867             :     /*
   19868             :      * create new SELECT combining WITH clause, target list, and fake FROM
   19869             :      * clause
   19870             :      */
   19871          14 :     s->withClause = w;
   19872          14 :     s->targetList = tl;
   19873          14 :     s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));
   19874             : 
   19875          14 :     return (Node *) s;
   19876             : }
   19877             : 
   19878             : /* parser_init()
   19879             :  * Initialize to parse one query string
   19880             :  */
   19881             : void
   19882      766044 : parser_init(base_yy_extra_type *yyext)
   19883             : {
   19884      766044 :     yyext->parsetree = NIL;      /* in case grammar forgets to set it */
   19885      766044 : }

Generated by: LCOV version 1.16