LCOV - code coverage report
Current view: top level - src/backend/parser - gram.y (source / functions) Hit Total Coverage
Test: PostgreSQL 19devel Lines: 6788 7497 90.5 %
Date: 2025-07-06 20:17:10 Functions: 41 41 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : %{
       2             : 
       3             : /*#define YYDEBUG 1*/
       4             : /*-------------------------------------------------------------------------
       5             :  *
       6             :  * gram.y
       7             :  *    POSTGRESQL BISON rules/actions
       8             :  *
       9             :  * Portions Copyright (c) 1996-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             :     List       *list;
     124             : } GroupClause;
     125             : 
     126             : /* Private structs for the result of key_actions and key_action productions */
     127             : typedef struct KeyAction
     128             : {
     129             :     char        action;
     130             :     List       *cols;
     131             : } KeyAction;
     132             : 
     133             : typedef struct KeyActions
     134             : {
     135             :     KeyAction *updateAction;
     136             :     KeyAction *deleteAction;
     137             : } KeyActions;
     138             : 
     139             : /* ConstraintAttributeSpec yields an integer bitmask of these flags: */
     140             : #define CAS_NOT_DEFERRABLE          0x01
     141             : #define CAS_DEFERRABLE              0x02
     142             : #define CAS_INITIALLY_IMMEDIATE     0x04
     143             : #define CAS_INITIALLY_DEFERRED      0x08
     144             : #define CAS_NOT_VALID               0x10
     145             : #define CAS_NO_INHERIT              0x20
     146             : #define CAS_NOT_ENFORCED            0x40
     147             : #define CAS_ENFORCED                0x80
     148             : 
     149             : 
     150             : #define parser_yyerror(msg)  scanner_yyerror(msg, yyscanner)
     151             : #define parser_errposition(pos)  scanner_errposition(pos, yyscanner)
     152             : 
     153             : static void base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner,
     154             :                          const char *msg);
     155             : static RawStmt *makeRawStmt(Node *stmt, int stmt_location);
     156             : static void updateRawStmtEnd(RawStmt *rs, int end_location);
     157             : static Node *makeColumnRef(char *colname, List *indirection,
     158             :                            int location, core_yyscan_t yyscanner);
     159             : static Node *makeTypeCast(Node *arg, TypeName *typename, int location);
     160             : static Node *makeStringConstCast(char *str, int location, TypeName *typename);
     161             : static Node *makeIntConst(int val, int location);
     162             : static Node *makeFloatConst(char *str, int location);
     163             : static Node *makeBoolAConst(bool state, int location);
     164             : static Node *makeBitStringConst(char *str, int location);
     165             : static Node *makeNullAConst(int location);
     166             : static Node *makeAConst(Node *v, int location);
     167             : static RoleSpec *makeRoleSpec(RoleSpecType type, int location);
     168             : static void check_qualified_name(List *names, core_yyscan_t yyscanner);
     169             : static List *check_func_name(List *names, core_yyscan_t yyscanner);
     170             : static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
     171             : static List *extractArgTypes(List *parameters);
     172             : static List *extractAggrArgTypes(List *aggrargs);
     173             : static List *makeOrderedSetArgs(List *directargs, List *orderedargs,
     174             :                                 core_yyscan_t yyscanner);
     175             : static void insertSelectOptions(SelectStmt *stmt,
     176             :                                 List *sortClause, List *lockingClause,
     177             :                                 SelectLimit *limitClause,
     178             :                                 WithClause *withClause,
     179             :                                 core_yyscan_t yyscanner);
     180             : static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
     181             : static Node *doNegate(Node *n, int location);
     182             : static void doNegateFloat(Float *v);
     183             : static Node *makeAndExpr(Node *lexpr, Node *rexpr, int location);
     184             : static Node *makeOrExpr(Node *lexpr, Node *rexpr, int location);
     185             : static Node *makeNotExpr(Node *expr, int location);
     186             : static Node *makeAArrayExpr(List *elements, int location, int end_location);
     187             : static Node *makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod,
     188             :                                   int location);
     189             : static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
     190             :                          List *args, int location);
     191             : static List *mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner);
     192             : static TypeName *TableFuncTypeName(List *columns);
     193             : static RangeVar *makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner);
     194             : static RangeVar *makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
     195             :                                                core_yyscan_t yyscanner);
     196             : static void SplitColQualList(List *qualList,
     197             :                              List **constraintList, CollateClause **collClause,
     198             :                              core_yyscan_t yyscanner);
     199             : static void processCASbits(int cas_bits, int location, const char *constrType,
     200             :                bool *deferrable, bool *initdeferred, bool *is_enforced,
     201             :                bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner);
     202             : static PartitionStrategy parsePartitionStrategy(char *strategy, int location,
     203             :                                                 core_yyscan_t yyscanner);
     204             : static void preprocess_pubobj_list(List *pubobjspec_list,
     205             :                                    core_yyscan_t yyscanner);
     206             : static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
     207             : 
     208             : %}
     209             : 
     210             : %pure-parser
     211             : %expect 0
     212             : %name-prefix="base_yy"
     213             : %locations
     214             : 
     215             : %parse-param {core_yyscan_t yyscanner}
     216             : %lex-param   {core_yyscan_t yyscanner}
     217             : 
     218             : %union
     219             : {
     220             :     core_YYSTYPE core_yystype;
     221             :     /* these fields must match core_YYSTYPE: */
     222             :     int         ival;
     223             :     char       *str;
     224             :     const char *keyword;
     225             : 
     226             :     char        chr;
     227             :     bool        boolean;
     228             :     JoinType    jtype;
     229             :     DropBehavior dbehavior;
     230             :     OnCommitAction oncommit;
     231             :     List       *list;
     232             :     Node       *node;
     233             :     ObjectType  objtype;
     234             :     TypeName   *typnam;
     235             :     FunctionParameter *fun_param;
     236             :     FunctionParameterMode fun_param_mode;
     237             :     ObjectWithArgs *objwithargs;
     238             :     DefElem    *defelt;
     239             :     SortBy     *sortby;
     240             :     WindowDef  *windef;
     241             :     JoinExpr   *jexpr;
     242             :     IndexElem  *ielem;
     243             :     StatsElem  *selem;
     244             :     Alias      *alias;
     245             :     RangeVar   *range;
     246             :     IntoClause *into;
     247             :     WithClause *with;
     248             :     InferClause *infer;
     249             :     OnConflictClause *onconflict;
     250             :     A_Indices  *aind;
     251             :     ResTarget  *target;
     252             :     struct PrivTarget *privtarget;
     253             :     AccessPriv *accesspriv;
     254             :     struct ImportQual *importqual;
     255             :     InsertStmt *istmt;
     256             :     VariableSetStmt *vsetstmt;
     257             :     PartitionElem *partelem;
     258             :     PartitionSpec *partspec;
     259             :     PartitionBoundSpec *partboundspec;
     260             :     RoleSpec   *rolespec;
     261             :     PublicationObjSpec *publicationobjectspec;
     262             :     struct SelectLimit *selectlimit;
     263             :     SetQuantifier setquantifier;
     264             :     struct GroupClause *groupclause;
     265             :     MergeMatchKind mergematch;
     266             :     MergeWhenClause *mergewhen;
     267             :     struct KeyActions *keyactions;
     268             :     struct KeyAction *keyaction;
     269             :     ReturningClause *retclause;
     270             :     ReturningOptionKind retoptionkind;
     271             : }
     272             : 
     273             : %type <node>  stmt toplevel_stmt schema_stmt routine_body_stmt
     274             :         AlterEventTrigStmt AlterCollationStmt
     275             :         AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt
     276             :         AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
     277             :         AlterObjectDependsStmt AlterObjectSchemaStmt AlterOwnerStmt
     278             :         AlterOperatorStmt AlterTypeStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
     279             :         AlterTblSpcStmt AlterExtensionStmt AlterExtensionContentsStmt
     280             :         AlterCompositeTypeStmt AlterUserMappingStmt
     281             :         AlterRoleStmt AlterRoleSetStmt AlterPolicyStmt AlterStatsStmt
     282             :         AlterDefaultPrivilegesStmt DefACLAction
     283             :         AnalyzeStmt CallStmt ClosePortalStmt ClusterStmt CommentStmt
     284             :         ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
     285             :         CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt
     286             :         CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
     287             :         CreateSchemaStmt CreateSeqStmt CreateStmt CreateStatsStmt CreateTableSpaceStmt
     288             :         CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt
     289             :         CreateAssertionStmt CreateTransformStmt CreateTrigStmt CreateEventTrigStmt
     290             :         CreateUserStmt CreateUserMappingStmt CreateRoleStmt CreatePolicyStmt
     291             :         CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
     292             :         DropOpClassStmt DropOpFamilyStmt DropStmt
     293             :         DropCastStmt DropRoleStmt
     294             :         DropdbStmt DropTableSpaceStmt
     295             :         DropTransformStmt
     296             :         DropUserMappingStmt ExplainStmt FetchStmt
     297             :         GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
     298             :         ListenStmt LoadStmt LockStmt MergeStmt NotifyStmt ExplainableStmt PreparableStmt
     299             :         CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
     300             :         RemoveFuncStmt RemoveOperStmt RenameStmt ReturnStmt RevokeStmt RevokeRoleStmt
     301             :         RuleActionStmt RuleActionStmtOrEmpty RuleStmt
     302             :         SecLabelStmt SelectStmt TransactionStmt TransactionStmtLegacy TruncateStmt
     303             :         UnlistenStmt UpdateStmt VacuumStmt
     304             :         VariableResetStmt VariableSetStmt VariableShowStmt
     305             :         ViewStmt CheckPointStmt CreateConversionStmt
     306             :         DeallocateStmt PrepareStmt ExecuteStmt
     307             :         DropOwnedStmt ReassignOwnedStmt
     308             :         AlterTSConfigurationStmt AlterTSDictionaryStmt
     309             :         CreateMatViewStmt RefreshMatViewStmt CreateAmStmt
     310             :         CreatePublicationStmt AlterPublicationStmt
     311             :         CreateSubscriptionStmt AlterSubscriptionStmt DropSubscriptionStmt
     312             : 
     313             : %type <node>  select_no_parens select_with_parens select_clause
     314             :                 simple_select values_clause
     315             :                 PLpgSQL_Expr PLAssignStmt
     316             : 
     317             : %type <str>           opt_single_name
     318             : %type <list>      opt_qualified_name
     319             : %type <boolean>       opt_concurrently
     320             : %type <dbehavior> opt_drop_behavior
     321             : 
     322             : %type <node>  alter_column_default opclass_item opclass_drop alter_using
     323             : %type <ival>  add_drop opt_asc_desc opt_nulls_order
     324             : 
     325             : %type <node>  alter_table_cmd alter_type_cmd opt_collate_clause
     326             :        replica_identity partition_cmd index_partition_cmd
     327             : %type <list>  alter_table_cmds alter_type_cmds
     328             : %type <list>    alter_identity_column_option_list
     329             : %type <defelt>  alter_identity_column_option
     330             : %type <node>  set_statistics_value
     331             : %type <str>       set_access_method_name
     332             : 
     333             : %type <list>  createdb_opt_list createdb_opt_items copy_opt_list
     334             :                 transaction_mode_list
     335             :                 create_extension_opt_list alter_extension_opt_list
     336             : %type <defelt>    createdb_opt_item copy_opt_item
     337             :                 transaction_mode_item
     338             :                 create_extension_opt_item alter_extension_opt_item
     339             : 
     340             : %type <ival>  opt_lock lock_type cast_context
     341             : %type <str>       utility_option_name
     342             : %type <defelt>    utility_option_elem
     343             : %type <list>  utility_option_list
     344             : %type <node>  utility_option_arg
     345             : %type <defelt>    drop_option
     346             : %type <boolean>   opt_or_replace opt_no
     347             :                 opt_grant_grant_option
     348             :                 opt_nowait opt_if_exists opt_with_data
     349             :                 opt_transaction_chain
     350             : %type <list>  grant_role_opt_list
     351             : %type <defelt>    grant_role_opt
     352             : %type <node>  grant_role_opt_value
     353             : %type <ival>  opt_nowait_or_skip
     354             : 
     355             : %type <list>  OptRoleList AlterOptRoleList
     356             : %type <defelt>    CreateOptRoleElem AlterOptRoleElem
     357             : 
     358             : %type <str>       opt_type
     359             : %type <str>       foreign_server_version opt_foreign_server_version
     360             : %type <str>       opt_in_database
     361             : 
     362             : %type <str>       parameter_name
     363             : %type <list>  OptSchemaEltList parameter_name_list
     364             : 
     365             : %type <chr>       am_type
     366             : 
     367             : %type <boolean> TriggerForSpec TriggerForType
     368             : %type <ival>  TriggerActionTime
     369             : %type <list>  TriggerEvents TriggerOneEvent
     370             : %type <node>  TriggerFuncArg
     371             : %type <node>  TriggerWhen
     372             : %type <str>       TransitionRelName
     373             : %type <boolean>   TransitionRowOrTable TransitionOldOrNew
     374             : %type <node>  TriggerTransition
     375             : 
     376             : %type <list>  event_trigger_when_list event_trigger_value_list
     377             : %type <defelt>    event_trigger_when_item
     378             : %type <chr>       enable_trigger
     379             : 
     380             : %type <str>       copy_file_name
     381             :                 access_method_clause attr_name
     382             :                 table_access_method_clause name cursor_name file_name
     383             :                 cluster_index_specification
     384             : 
     385             : %type <list>  func_name handler_name qual_Op qual_all_Op subquery_Op
     386             :                 opt_inline_handler opt_validator validator_clause
     387             :                 opt_collate
     388             : 
     389             : %type <range> qualified_name insert_target OptConstrFromTable
     390             : 
     391             : %type <str>       all_Op MathOp
     392             : 
     393             : %type <str>       row_security_cmd RowSecurityDefaultForCmd
     394             : %type <boolean> RowSecurityDefaultPermissive
     395             : %type <node>  RowSecurityOptionalWithCheck RowSecurityOptionalExpr
     396             : %type <list>  RowSecurityDefaultToRole RowSecurityOptionalToRole
     397             : 
     398             : %type <str>       iso_level opt_encoding
     399             : %type <rolespec> grantee
     400             : %type <list>  grantee_list
     401             : %type <accesspriv> privilege
     402             : %type <list>  privileges privilege_list
     403             : %type <privtarget> privilege_target
     404             : %type <objwithargs> function_with_argtypes aggregate_with_argtypes operator_with_argtypes
     405             : %type <list>  function_with_argtypes_list aggregate_with_argtypes_list operator_with_argtypes_list
     406             : %type <ival>  defacl_privilege_target
     407             : %type <defelt>    DefACLOption
     408             : %type <list>  DefACLOptionList
     409             : %type <ival>  import_qualification_type
     410             : %type <importqual> import_qualification
     411             : %type <node>  vacuum_relation
     412             : %type <selectlimit> opt_select_limit select_limit limit_clause
     413             : 
     414             : %type <list>  parse_toplevel stmtmulti routine_body_stmt_list
     415             :                 OptTableElementList TableElementList OptInherit definition
     416             :                 OptTypedTableElementList TypedTableElementList
     417             :                 reloptions opt_reloptions
     418             :                 OptWith opt_definition func_args func_args_list
     419             :                 func_args_with_defaults func_args_with_defaults_list
     420             :                 aggr_args aggr_args_list
     421             :                 func_as createfunc_opt_list opt_createfunc_opt_list alterfunc_opt_list
     422             :                 old_aggr_definition old_aggr_list
     423             :                 oper_argtypes RuleActionList RuleActionMulti
     424             :                 opt_column_list columnList opt_name_list
     425             :                 sort_clause opt_sort_clause sortby_list index_params
     426             :                 stats_params
     427             :                 opt_include opt_c_include index_including_params
     428             :                 name_list role_list from_clause from_list opt_array_bounds
     429             :                 qualified_name_list any_name any_name_list type_name_list
     430             :                 any_operator expr_list attrs
     431             :                 distinct_clause opt_distinct_clause
     432             :                 target_list opt_target_list insert_column_list set_target_list
     433             :                 merge_values_clause
     434             :                 set_clause_list set_clause
     435             :                 def_list operator_def_list indirection opt_indirection
     436             :                 reloption_list TriggerFuncArgs opclass_item_list opclass_drop_list
     437             :                 opclass_purpose opt_opfamily transaction_mode_list_or_empty
     438             :                 OptTableFuncElementList TableFuncElementList opt_type_modifiers
     439             :                 prep_type_clause
     440             :                 execute_param_clause using_clause
     441             :                 returning_with_clause returning_options
     442             :                 opt_enum_val_list enum_val_list table_func_column_list
     443             :                 create_generic_options alter_generic_options
     444             :                 relation_expr_list dostmt_opt_list
     445             :                 transform_element_list transform_type_list
     446             :                 TriggerTransitions TriggerReferencing
     447             :                 vacuum_relation_list opt_vacuum_relation_list
     448             :                 drop_option_list pub_obj_list
     449             : 
     450             : %type <retclause> returning_clause
     451             : %type <node>  returning_option
     452             : %type <retoptionkind> returning_option_kind
     453             : %type <node>  opt_routine_body
     454             : %type <groupclause> group_clause
     455             : %type <list>  group_by_list
     456             : %type <node>  group_by_item empty_grouping_set rollup_clause cube_clause
     457             : %type <node>  grouping_sets_clause
     458             : 
     459             : %type <list>  opt_fdw_options fdw_options
     460             : %type <defelt>    fdw_option
     461             : 
     462             : %type <range> OptTempTableName
     463             : %type <into>  into_clause create_as_target create_mv_target
     464             : 
     465             : %type <defelt>    createfunc_opt_item common_func_opt_item dostmt_opt_item
     466             : %type <fun_param> func_arg func_arg_with_default table_func_column aggr_arg
     467             : %type <fun_param_mode> arg_class
     468             : %type <typnam>    func_return func_type
     469             : 
     470             : %type <boolean>  opt_trusted opt_restart_seqs
     471             : %type <ival>   OptTemp
     472             : %type <ival>   OptNoLog
     473             : %type <oncommit> OnCommitOption
     474             : 
     475             : %type <ival>  for_locking_strength
     476             : %type <node>  for_locking_item
     477             : %type <list>  for_locking_clause opt_for_locking_clause for_locking_items
     478             : %type <list>  locked_rels_list
     479             : %type <setquantifier> set_quantifier
     480             : 
     481             : %type <node>  join_qual
     482             : %type <jtype> join_type
     483             : 
     484             : %type <list>  extract_list overlay_list position_list
     485             : %type <list>  substr_list trim_list
     486             : %type <list>  opt_interval interval_second
     487             : %type <str>       unicode_normal_form
     488             : 
     489             : %type <boolean> opt_instead
     490             : %type <boolean> opt_unique opt_verbose opt_full
     491             : %type <boolean> opt_freeze opt_analyze opt_default
     492             : %type <defelt>    opt_binary copy_delimiter
     493             : 
     494             : %type <boolean> copy_from opt_program
     495             : 
     496             : %type <ival>  event cursor_options opt_hold opt_set_data
     497             : %type <objtype>   object_type_any_name object_type_name object_type_name_on_any_name
     498             :                 drop_type_name
     499             : 
     500             : %type <node>  fetch_args select_limit_value
     501             :                 offset_clause select_offset_value
     502             :                 select_fetch_first_value I_or_F_const
     503             : %type <ival>  row_or_rows first_or_next
     504             : 
     505             : %type <list>  OptSeqOptList SeqOptList OptParenthesizedSeqOptList
     506             : %type <defelt>    SeqOptElem
     507             : 
     508             : %type <istmt> insert_rest
     509             : %type <infer> opt_conf_expr
     510             : %type <onconflict> opt_on_conflict
     511             : %type <mergewhen> merge_insert merge_update merge_delete
     512             : 
     513             : %type <mergematch> merge_when_tgt_matched merge_when_tgt_not_matched
     514             : %type <node>  merge_when_clause opt_merge_when_condition
     515             : %type <list>  merge_when_list
     516             : 
     517             : %type <vsetstmt> generic_set set_rest set_rest_more generic_reset reset_rest
     518             :                  SetResetClause FunctionSetResetClause
     519             : 
     520             : %type <node>  TableElement TypedTableElement ConstraintElem DomainConstraintElem TableFuncElement
     521             : %type <node>  columnDef columnOptions optionalPeriodName
     522             : %type <defelt>    def_elem reloption_elem old_aggr_elem operator_def_elem
     523             : %type <node>  def_arg columnElem where_clause where_or_current_clause
     524             :                 a_expr b_expr c_expr AexprConst indirection_el opt_slice_bound
     525             :                 columnref having_clause func_table xmltable array_expr
     526             :                 OptWhereClause operator_def_arg
     527             : %type <list>  opt_column_and_period_list
     528             : %type <list>  rowsfrom_item rowsfrom_list opt_col_def_list
     529             : %type <boolean> opt_ordinality opt_without_overlaps
     530             : %type <list>  ExclusionConstraintList ExclusionConstraintElem
     531             : %type <list>  func_arg_list func_arg_list_opt
     532             : %type <node>  func_arg_expr
     533             : %type <list>  row explicit_row implicit_row type_list array_expr_list
     534             : %type <node>  case_expr case_arg when_clause case_default
     535             : %type <list>  when_clause_list
     536             : %type <node>  opt_search_clause opt_cycle_clause
     537             : %type <ival>  sub_type opt_materialized
     538             : %type <node>  NumericOnly
     539             : %type <list>  NumericOnly_list
     540             : %type <alias> alias_clause opt_alias_clause opt_alias_clause_for_join_using
     541             : %type <list>  func_alias_clause
     542             : %type <sortby>    sortby
     543             : %type <ielem> index_elem index_elem_options
     544             : %type <selem> stats_param
     545             : %type <node>  table_ref
     546             : %type <jexpr> joined_table
     547             : %type <range> relation_expr
     548             : %type <range> extended_relation_expr
     549             : %type <range> relation_expr_opt_alias
     550             : %type <node>  tablesample_clause opt_repeatable_clause
     551             : %type <target>    target_el set_target insert_column_item
     552             : 
     553             : %type <str>       generic_option_name
     554             : %type <node>  generic_option_arg
     555             : %type <defelt>    generic_option_elem alter_generic_option_elem
     556             : %type <list>  generic_option_list alter_generic_option_list
     557             : 
     558             : %type <ival>  reindex_target_relation reindex_target_all
     559             : %type <list>  opt_reindex_option_list
     560             : 
     561             : %type <node>  copy_generic_opt_arg copy_generic_opt_arg_list_item
     562             : %type <defelt>    copy_generic_opt_elem
     563             : %type <list>  copy_generic_opt_list copy_generic_opt_arg_list
     564             : %type <list>  copy_options
     565             : 
     566             : %type <typnam>    Typename SimpleTypename ConstTypename
     567             :                 GenericType Numeric opt_float JsonType
     568             :                 Character ConstCharacter
     569             :                 CharacterWithLength CharacterWithoutLength
     570             :                 ConstDatetime ConstInterval
     571             :                 Bit ConstBit BitWithLength BitWithoutLength
     572             : %type <str>       character
     573             : %type <str>       extract_arg
     574             : %type <boolean> opt_varying opt_timezone opt_no_inherit
     575             : 
     576             : %type <ival>  Iconst SignedIconst
     577             : %type <str>       Sconst comment_text notify_payload
     578             : %type <str>       RoleId opt_boolean_or_string
     579             : %type <list>  var_list
     580             : %type <str>       ColId ColLabel BareColLabel
     581             : %type <str>       NonReservedWord NonReservedWord_or_Sconst
     582             : %type <str>       var_name type_function_name param_name
     583             : %type <str>       createdb_opt_name plassign_target
     584             : %type <node>  var_value zone_value
     585             : %type <rolespec> auth_ident RoleSpec opt_granted_by
     586             : %type <publicationobjectspec> PublicationObjSpec
     587             : 
     588             : %type <keyword> unreserved_keyword type_func_name_keyword
     589             : %type <keyword> col_name_keyword reserved_keyword
     590             : %type <keyword> bare_label_keyword
     591             : 
     592             : %type <node>  DomainConstraint TableConstraint TableLikeClause
     593             : %type <ival>  TableLikeOptionList TableLikeOption
     594             : %type <str>       column_compression opt_column_compression column_storage opt_column_storage
     595             : %type <list>  ColQualList
     596             : %type <node>  ColConstraint ColConstraintElem ConstraintAttr
     597             : %type <ival>  key_match
     598             : %type <keyaction> key_delete key_update key_action
     599             : %type <keyactions> key_actions
     600             : %type <ival>  ConstraintAttributeSpec ConstraintAttributeElem
     601             : %type <str>       ExistingIndex
     602             : 
     603             : %type <list>  constraints_set_list
     604             : %type <boolean> constraints_set_mode
     605             : %type <str>       OptTableSpace OptConsTableSpace
     606             : %type <rolespec> OptTableSpaceOwner
     607             : %type <ival>  opt_check_option
     608             : 
     609             : %type <str>       opt_provider security_label
     610             : 
     611             : %type <target>    xml_attribute_el
     612             : %type <list>  xml_attribute_list xml_attributes
     613             : %type <node>  xml_root_version opt_xml_root_standalone
     614             : %type <node>  xmlexists_argument
     615             : %type <ival>  document_or_content
     616             : %type <boolean>   xml_indent_option xml_whitespace_option
     617             : %type <list>  xmltable_column_list xmltable_column_option_list
     618             : %type <node>  xmltable_column_el
     619             : %type <defelt>    xmltable_column_option_el
     620             : %type <list>  xml_namespace_list
     621             : %type <target>    xml_namespace_el
     622             : 
     623             : %type <node>  func_application func_expr_common_subexpr
     624             : %type <node>  func_expr func_expr_windowless
     625             : %type <node>  common_table_expr
     626             : %type <with>  with_clause opt_with_clause
     627             : %type <list>  cte_list
     628             : 
     629             : %type <list>  within_group_clause
     630             : %type <node>  filter_clause
     631             : %type <list>  window_clause window_definition_list opt_partition_clause
     632             : %type <windef>    window_definition over_clause window_specification
     633             :                 opt_frame_clause frame_extent frame_bound
     634             : %type <ival>  opt_window_exclusion_clause
     635             : %type <str>       opt_existing_window_name
     636             : %type <boolean> opt_if_not_exists
     637             : %type <boolean> opt_unique_null_treatment
     638             : %type <ival>  generated_when override_kind opt_virtual_or_stored
     639             : %type <partspec>  PartitionSpec OptPartitionSpec
     640             : %type <partelem>  part_elem
     641             : %type <list>      part_params
     642             : %type <partboundspec> PartitionBoundSpec
     643             : %type <list>      hash_partbound
     644             : %type <defelt>        hash_partbound_elem
     645             : 
     646             : %type <node>  json_format_clause
     647             :                 json_format_clause_opt
     648             :                 json_value_expr
     649             :                 json_returning_clause_opt
     650             :                 json_name_and_value
     651             :                 json_aggregate_func
     652             :                 json_argument
     653             :                 json_behavior
     654             :                 json_on_error_clause_opt
     655             :                 json_table
     656             :                 json_table_column_definition
     657             :                 json_table_column_path_clause_opt
     658             : %type <list>  json_name_and_value_list
     659             :                 json_value_expr_list
     660             :                 json_array_aggregate_order_by_clause_opt
     661             :                 json_arguments
     662             :                 json_behavior_clause_opt
     663             :                 json_passing_clause_opt
     664             :                 json_table_column_definition_list
     665             : %type <str>       json_table_path_name_opt
     666             : %type <ival>  json_behavior_type
     667             :                 json_predicate_type_constraint
     668             :                 json_quotes_clause_opt
     669             :                 json_wrapper_behavior
     670             : %type <boolean>   json_key_uniqueness_constraint_opt
     671             :                 json_object_constructor_null_clause_opt
     672             :                 json_array_constructor_null_clause_opt
     673             : 
     674             : 
     675             : /*
     676             :  * Non-keyword token types.  These are hard-wired into the "flex" lexer.
     677             :  * They must be listed first so that their numeric codes do not depend on
     678             :  * the set of keywords.  PL/pgSQL depends on this so that it can share the
     679             :  * same lexer.  If you add/change tokens here, fix PL/pgSQL to match!
     680             :  *
     681             :  * UIDENT and USCONST are reduced to IDENT and SCONST in parser.c, so that
     682             :  * they need no productions here; but we must assign token codes to them.
     683             :  *
     684             :  * DOT_DOT is unused in the core SQL grammar, and so will always provoke
     685             :  * parse errors.  It is needed by PL/pgSQL.
     686             :  */
     687             : %token <str>  IDENT UIDENT FCONST SCONST USCONST BCONST XCONST Op
     688             : %token <ival> ICONST PARAM
     689             : %token          TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
     690             : %token          LESS_EQUALS GREATER_EQUALS NOT_EQUALS
     691             : 
     692             : /*
     693             :  * If you want to make any keyword changes, update the keyword table in
     694             :  * src/include/parser/kwlist.h and add new keywords to the appropriate one
     695             :  * of the reserved-or-not-so-reserved keyword lists, below; search
     696             :  * this file for "Keyword category lists".
     697             :  */
     698             : 
     699             : /* ordinary key words in alphabetical order */
     700             : %token <keyword> ABORT_P ABSENT ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
     701             :     AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
     702             :     ASENSITIVE ASSERTION ASSIGNMENT ASYMMETRIC ATOMIC AT ATTACH ATTRIBUTE AUTHORIZATION
     703             : 
     704             :     BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
     705             :     BOOLEAN_P BOTH BREADTH BY
     706             : 
     707             :     CACHE CALL CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
     708             :     CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
     709             :     CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
     710             :     COMMITTED COMPRESSION CONCURRENTLY CONDITIONAL CONFIGURATION CONFLICT
     711             :     CONNECTION CONSTRAINT CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY
     712             :     COST CREATE CROSS CSV CUBE CURRENT_P
     713             :     CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
     714             :     CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
     715             : 
     716             :     DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
     717             :     DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DEPENDS DEPTH DESC
     718             :     DETACH DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P
     719             :     DOUBLE_P DROP
     720             : 
     721             :     EACH ELSE EMPTY_P ENABLE_P ENCODING ENCRYPTED END_P ENFORCED ENUM_P ERROR_P
     722             :     ESCAPE EVENT EXCEPT EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN
     723             :     EXPRESSION EXTENSION EXTERNAL EXTRACT
     724             : 
     725             :     FALSE_P FAMILY FETCH FILTER FINALIZE FIRST_P FLOAT_P FOLLOWING FOR
     726             :     FORCE FOREIGN FORMAT FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
     727             : 
     728             :     GENERATED GLOBAL GRANT GRANTED GREATEST GROUP_P GROUPING GROUPS
     729             : 
     730             :     HANDLER HAVING HEADER_P HOLD HOUR_P
     731             : 
     732             :     IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P INCLUDE
     733             :     INCLUDING INCREMENT INDENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
     734             :     INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
     735             :     INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
     736             : 
     737             :     JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_EXISTS JSON_OBJECT JSON_OBJECTAGG
     738             :     JSON_QUERY JSON_SCALAR JSON_SERIALIZE JSON_TABLE JSON_VALUE
     739             : 
     740             :     KEEP KEY KEYS
     741             : 
     742             :     LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
     743             :     LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
     744             :     LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED
     745             : 
     746             :     MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE MERGE_ACTION METHOD
     747             :     MINUTE_P MINVALUE MODE MONTH_P MOVE
     748             : 
     749             :     NAME_P NAMES NATIONAL NATURAL NCHAR NESTED NEW NEXT NFC NFD NFKC NFKD NO
     750             :     NONE NORMALIZE NORMALIZED
     751             :     NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
     752             :     NULLS_P NUMERIC
     753             : 
     754             :     OBJECT_P OBJECTS_P OF OFF OFFSET OIDS OLD OMIT ON ONLY OPERATOR OPTION OPTIONS OR
     755             :     ORDER ORDINALITY OTHERS OUT_P OUTER_P
     756             :     OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
     757             : 
     758             :     PARALLEL PARAMETER PARSER PARTIAL PARTITION PASSING PASSWORD PATH
     759             :     PERIOD PLACING PLAN PLANS POLICY
     760             :     POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
     761             :     PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PUBLICATION
     762             : 
     763             :     QUOTE QUOTES
     764             : 
     765             :     RANGE READ REAL REASSIGN RECURSIVE REF_P REFERENCES REFERENCING
     766             :     REFRESH REINDEX RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
     767             :     RESET RESTART RESTRICT RETURN RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
     768             :     ROUTINE ROUTINES ROW ROWS RULE
     769             : 
     770             :     SAVEPOINT SCALAR SCHEMA SCHEMAS SCROLL SEARCH SECOND_P SECURITY SELECT
     771             :     SEQUENCE SEQUENCES
     772             :     SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
     773             :     SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SOURCE SQL_P STABLE STANDALONE_P
     774             :     START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRING_P STRIP_P
     775             :     SUBSCRIPTION SUBSTRING SUPPORT SYMMETRIC SYSID SYSTEM_P SYSTEM_USER
     776             : 
     777             :     TABLE TABLES TABLESAMPLE TABLESPACE TARGET TEMP TEMPLATE TEMPORARY TEXT_P THEN
     778             :     TIES TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM
     779             :     TREAT TRIGGER TRIM TRUE_P
     780             :     TRUNCATE TRUSTED TYPE_P TYPES_P
     781             : 
     782             :     UESCAPE UNBOUNDED UNCONDITIONAL UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
     783             :     UNLISTEN UNLOGGED UNTIL UPDATE USER USING
     784             : 
     785             :     VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
     786             :     VERBOSE VERSION_P VIEW VIEWS VIRTUAL VOLATILE
     787             : 
     788             :     WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
     789             : 
     790             :     XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLNAMESPACES
     791             :     XMLPARSE XMLPI XMLROOT XMLSERIALIZE XMLTABLE
     792             : 
     793             :     YEAR_P YES_P
     794             : 
     795             :     ZONE
     796             : 
     797             : /*
     798             :  * The grammar thinks these are keywords, but they are not in the kwlist.h
     799             :  * list and so can never be entered directly.  The filter in parser.c
     800             :  * creates these tokens when required (based on looking one token ahead).
     801             :  *
     802             :  * NOT_LA exists so that productions such as NOT LIKE can be given the same
     803             :  * precedence as LIKE; otherwise they'd effectively have the same precedence
     804             :  * as NOT, at least with respect to their left-hand subexpression.
     805             :  * FORMAT_LA, NULLS_LA, WITH_LA, and WITHOUT_LA are needed to make the grammar
     806             :  * LALR(1).
     807             :  */
     808             : %token      FORMAT_LA NOT_LA NULLS_LA WITH_LA WITHOUT_LA
     809             : 
     810             : /*
     811             :  * The grammar likewise thinks these tokens are keywords, but they are never
     812             :  * generated by the scanner.  Rather, they can be injected by parser.c as
     813             :  * the initial token of the string (using the lookahead-token mechanism
     814             :  * implemented there).  This provides a way to tell the grammar to parse
     815             :  * something other than the usual list of SQL commands.
     816             :  */
     817             : %token      MODE_TYPE_NAME
     818             : %token      MODE_PLPGSQL_EXPR
     819             : %token      MODE_PLPGSQL_ASSIGN1
     820             : %token      MODE_PLPGSQL_ASSIGN2
     821             : %token      MODE_PLPGSQL_ASSIGN3
     822             : 
     823             : 
     824             : /* Precedence: lowest to highest */
     825             : %left       UNION EXCEPT
     826             : %left       INTERSECT
     827             : %left       OR
     828             : %left       AND
     829             : %right      NOT
     830             : %nonassoc   IS ISNULL NOTNULL   /* IS sets precedence for IS NULL, etc */
     831             : %nonassoc   '<' '>' '=' LESS_EQUALS GREATER_EQUALS NOT_EQUALS
     832             : %nonassoc   BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
     833             : %nonassoc   ESCAPE          /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
     834             : 
     835             : /*
     836             :  * Sometimes it is necessary to assign precedence to keywords that are not
     837             :  * really part of the operator hierarchy, in order to resolve grammar
     838             :  * ambiguities.  It's best to avoid doing so whenever possible, because such
     839             :  * assignments have global effect and may hide ambiguities besides the one
     840             :  * you intended to solve.  (Attaching a precedence to a single rule with
     841             :  * %prec is far safer and should be preferred.)  If you must give precedence
     842             :  * to a new keyword, try very hard to give it the same precedence as IDENT.
     843             :  * If the keyword has IDENT's precedence then it clearly acts the same as
     844             :  * non-keywords and other similar keywords, thus reducing the risk of
     845             :  * unexpected precedence effects.
     846             :  *
     847             :  * We used to need to assign IDENT an explicit precedence just less than Op,
     848             :  * to support target_el without AS.  While that's not really necessary since
     849             :  * we removed postfix operators, we continue to do so because it provides a
     850             :  * reference point for a precedence level that we can assign to other
     851             :  * keywords that lack a natural precedence level.
     852             :  *
     853             :  * We need to do this for PARTITION, RANGE, ROWS, and GROUPS to support
     854             :  * opt_existing_window_name (see comment there).
     855             :  *
     856             :  * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
     857             :  * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
     858             :  * there is no principled way to distinguish these from the productions
     859             :  * a_expr PRECEDING/FOLLOWING.  We hack this up by giving UNBOUNDED slightly
     860             :  * lower precedence than PRECEDING and FOLLOWING.  At present this doesn't
     861             :  * appear to cause UNBOUNDED to be treated differently from other unreserved
     862             :  * keywords anywhere else in the grammar, but it's definitely risky.  We can
     863             :  * blame any funny behavior of UNBOUNDED on the SQL standard, though.
     864             :  *
     865             :  * To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
     866             :  * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
     867             :  * rather than reducing a conflicting rule that takes CUBE as a function name.
     868             :  * Using the same precedence as IDENT seems right for the reasons given above.
     869             :  *
     870             :  * SET is likewise assigned the same precedence as IDENT, to support the
     871             :  * relation_expr_opt_alias production (see comment there).
     872             :  *
     873             :  * KEYS, OBJECT_P, SCALAR, VALUE_P, WITH, and WITHOUT are similarly assigned
     874             :  * the same precedence as IDENT.  This allows resolving conflicts in the
     875             :  * json_predicate_type_constraint and json_key_uniqueness_constraint_opt
     876             :  * productions (see comments there).
     877             :  *
     878             :  * Like the UNBOUNDED PRECEDING/FOLLOWING case, NESTED is assigned a lower
     879             :  * precedence than PATH to fix ambiguity in the json_table production.
     880             :  */
     881             : %nonassoc   UNBOUNDED NESTED /* ideally would have same precedence as IDENT */
     882             : %nonassoc   IDENT PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
     883             :             SET KEYS OBJECT_P SCALAR VALUE_P WITH WITHOUT PATH
     884             : %left       Op OPERATOR     /* multi-character ops and user-defined operators */
     885             : %left       '+' '-'
     886             : %left       '*' '/' '%'
     887             : %left       '^'
     888             : /* Unary Operators */
     889             : %left       AT              /* sets precedence for AT TIME ZONE, AT LOCAL */
     890             : %left       COLLATE
     891             : %right      UMINUS
     892             : %left       '[' ']'
     893             : %left       '(' ')'
     894             : %left       TYPECAST
     895             : %left       '.'
     896             : /*
     897             :  * These might seem to be low-precedence, but actually they are not part
     898             :  * of the arithmetic hierarchy at all in their use as JOIN operators.
     899             :  * We make them high-precedence to support their use as function names.
     900             :  * They wouldn't be given a precedence at all, were it not that we need
     901             :  * left-associativity among the JOIN rules themselves.
     902             :  */
     903             : %left       JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
     904             : 
     905             : %%
     906             : 
     907             : /*
     908             :  *  The target production for the whole parse.
     909             :  *
     910             :  * Ordinarily we parse a list of statements, but if we see one of the
     911             :  * special MODE_XXX symbols as first token, we parse something else.
     912             :  * The options here correspond to enum RawParseMode, which see for details.
     913             :  */
     914             : parse_toplevel:
     915             :             stmtmulti
     916             :             {
     917      738360 :                 pg_yyget_extra(yyscanner)->parsetree = $1;
     918             :                 (void) yynerrs;     /* suppress compiler warning */
     919             :             }
     920             :             | MODE_TYPE_NAME Typename
     921             :             {
     922        9650 :                 pg_yyget_extra(yyscanner)->parsetree = list_make1($2);
     923             :             }
     924             :             | MODE_PLPGSQL_EXPR PLpgSQL_Expr
     925             :             {
     926       33256 :                 pg_yyget_extra(yyscanner)->parsetree =
     927       33256 :                     list_make1(makeRawStmt($2, @2));
     928             :             }
     929             :             | MODE_PLPGSQL_ASSIGN1 PLAssignStmt
     930             :             {
     931        6342 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     932             : 
     933        6342 :                 n->nnames = 1;
     934        6342 :                 pg_yyget_extra(yyscanner)->parsetree =
     935        6342 :                     list_make1(makeRawStmt((Node *) n, @2));
     936             :             }
     937             :             | MODE_PLPGSQL_ASSIGN2 PLAssignStmt
     938             :             {
     939         674 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     940             : 
     941         674 :                 n->nnames = 2;
     942         674 :                 pg_yyget_extra(yyscanner)->parsetree =
     943         674 :                     list_make1(makeRawStmt((Node *) n, @2));
     944             :             }
     945             :             | MODE_PLPGSQL_ASSIGN3 PLAssignStmt
     946             :             {
     947          28 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     948             : 
     949          28 :                 n->nnames = 3;
     950          28 :                 pg_yyget_extra(yyscanner)->parsetree =
     951          28 :                     list_make1(makeRawStmt((Node *) n, @2));
     952             :             }
     953             :         ;
     954             : 
     955             : /*
     956             :  * At top level, we wrap each stmt with a RawStmt node carrying start location
     957             :  * and length of the stmt's text.
     958             :  * We also take care to discard empty statements entirely (which among other
     959             :  * things dodges the problem of assigning them a location).
     960             :  */
     961             : stmtmulti:  stmtmulti ';' toplevel_stmt
     962             :                 {
     963      588174 :                     if ($1 != NIL)
     964             :                     {
     965             :                         /* update length of previous stmt */
     966      587610 :                         updateRawStmtEnd(llast_node(RawStmt, $1), @2);
     967             :                     }
     968      588174 :                     if ($3 != NULL)
     969       55400 :                         $$ = lappend($1, makeRawStmt($3, @3));
     970             :                     else
     971      532774 :                         $$ = $1;
     972             :                 }
     973             :             | toplevel_stmt
     974             :                 {
     975      738368 :                     if ($1 != NULL)
     976      737104 :                         $$ = list_make1(makeRawStmt($1, @1));
     977             :                     else
     978        1264 :                         $$ = NIL;
     979             :                 }
     980             :         ;
     981             : 
     982             : /*
     983             :  * toplevel_stmt includes BEGIN and END.  stmt does not include them, because
     984             :  * those words have different meanings in function bodies.
     985             :  */
     986             : toplevel_stmt:
     987             :             stmt
     988             :             | TransactionStmtLegacy
     989             :         ;
     990             : 
     991             : stmt:
     992             :             AlterEventTrigStmt
     993             :             | AlterCollationStmt
     994             :             | AlterDatabaseStmt
     995             :             | AlterDatabaseSetStmt
     996             :             | AlterDefaultPrivilegesStmt
     997             :             | AlterDomainStmt
     998             :             | AlterEnumStmt
     999             :             | AlterExtensionStmt
    1000             :             | AlterExtensionContentsStmt
    1001             :             | AlterFdwStmt
    1002             :             | AlterForeignServerStmt
    1003             :             | AlterFunctionStmt
    1004             :             | AlterGroupStmt
    1005             :             | AlterObjectDependsStmt
    1006             :             | AlterObjectSchemaStmt
    1007             :             | AlterOwnerStmt
    1008             :             | AlterOperatorStmt
    1009             :             | AlterTypeStmt
    1010             :             | AlterPolicyStmt
    1011             :             | AlterSeqStmt
    1012             :             | AlterSystemStmt
    1013             :             | AlterTableStmt
    1014             :             | AlterTblSpcStmt
    1015             :             | AlterCompositeTypeStmt
    1016             :             | AlterPublicationStmt
    1017             :             | AlterRoleSetStmt
    1018             :             | AlterRoleStmt
    1019             :             | AlterSubscriptionStmt
    1020             :             | AlterStatsStmt
    1021             :             | AlterTSConfigurationStmt
    1022             :             | AlterTSDictionaryStmt
    1023             :             | AlterUserMappingStmt
    1024             :             | AnalyzeStmt
    1025             :             | CallStmt
    1026             :             | CheckPointStmt
    1027             :             | ClosePortalStmt
    1028             :             | ClusterStmt
    1029             :             | CommentStmt
    1030             :             | ConstraintsSetStmt
    1031             :             | CopyStmt
    1032             :             | CreateAmStmt
    1033             :             | CreateAsStmt
    1034             :             | CreateAssertionStmt
    1035             :             | CreateCastStmt
    1036             :             | CreateConversionStmt
    1037             :             | CreateDomainStmt
    1038             :             | CreateExtensionStmt
    1039             :             | CreateFdwStmt
    1040             :             | CreateForeignServerStmt
    1041             :             | CreateForeignTableStmt
    1042             :             | CreateFunctionStmt
    1043             :             | CreateGroupStmt
    1044             :             | CreateMatViewStmt
    1045             :             | CreateOpClassStmt
    1046             :             | CreateOpFamilyStmt
    1047             :             | CreatePublicationStmt
    1048             :             | AlterOpFamilyStmt
    1049             :             | CreatePolicyStmt
    1050             :             | CreatePLangStmt
    1051             :             | CreateSchemaStmt
    1052             :             | CreateSeqStmt
    1053             :             | CreateStmt
    1054             :             | CreateSubscriptionStmt
    1055             :             | CreateStatsStmt
    1056             :             | CreateTableSpaceStmt
    1057             :             | CreateTransformStmt
    1058             :             | CreateTrigStmt
    1059             :             | CreateEventTrigStmt
    1060             :             | CreateRoleStmt
    1061             :             | CreateUserStmt
    1062             :             | CreateUserMappingStmt
    1063             :             | CreatedbStmt
    1064             :             | DeallocateStmt
    1065             :             | DeclareCursorStmt
    1066             :             | DefineStmt
    1067             :             | DeleteStmt
    1068             :             | DiscardStmt
    1069             :             | DoStmt
    1070             :             | DropCastStmt
    1071             :             | DropOpClassStmt
    1072             :             | DropOpFamilyStmt
    1073             :             | DropOwnedStmt
    1074             :             | DropStmt
    1075             :             | DropSubscriptionStmt
    1076             :             | DropTableSpaceStmt
    1077             :             | DropTransformStmt
    1078             :             | DropRoleStmt
    1079             :             | DropUserMappingStmt
    1080             :             | DropdbStmt
    1081             :             | ExecuteStmt
    1082             :             | ExplainStmt
    1083             :             | FetchStmt
    1084             :             | GrantStmt
    1085             :             | GrantRoleStmt
    1086             :             | ImportForeignSchemaStmt
    1087             :             | IndexStmt
    1088             :             | InsertStmt
    1089             :             | ListenStmt
    1090             :             | RefreshMatViewStmt
    1091             :             | LoadStmt
    1092             :             | LockStmt
    1093             :             | MergeStmt
    1094             :             | NotifyStmt
    1095             :             | PrepareStmt
    1096             :             | ReassignOwnedStmt
    1097             :             | ReindexStmt
    1098             :             | RemoveAggrStmt
    1099             :             | RemoveFuncStmt
    1100             :             | RemoveOperStmt
    1101             :             | RenameStmt
    1102             :             | RevokeStmt
    1103             :             | RevokeRoleStmt
    1104             :             | RuleStmt
    1105             :             | SecLabelStmt
    1106             :             | SelectStmt
    1107             :             | TransactionStmt
    1108             :             | TruncateStmt
    1109             :             | UnlistenStmt
    1110             :             | UpdateStmt
    1111             :             | VacuumStmt
    1112             :             | VariableResetStmt
    1113             :             | VariableSetStmt
    1114             :             | VariableShowStmt
    1115             :             | ViewStmt
    1116             :             | /*EMPTY*/
    1117      534056 :                 { $$ = NULL; }
    1118             :         ;
    1119             : 
    1120             : /*
    1121             :  * Generic supporting productions for DDL
    1122             :  */
    1123             : opt_single_name:
    1124        5632 :             ColId                           { $$ = $1; }
    1125        1518 :             | /* EMPTY */                   { $$ = NULL; }
    1126             :         ;
    1127             : 
    1128             : opt_qualified_name:
    1129        1930 :             any_name                        { $$ = $1; }
    1130       15688 :             | /*EMPTY*/                     { $$ = NIL; }
    1131             :         ;
    1132             : 
    1133             : opt_concurrently:
    1134        1034 :             CONCURRENTLY                    { $$ = true; }
    1135        7874 :             | /*EMPTY*/                     { $$ = false; }
    1136             :         ;
    1137             : 
    1138             : opt_drop_behavior:
    1139        1960 :             CASCADE                         { $$ = DROP_CASCADE; }
    1140         170 :             | RESTRICT                      { $$ = DROP_RESTRICT; }
    1141       40046 :             | /* EMPTY */                   { $$ = DROP_RESTRICT; /* default */ }
    1142             :         ;
    1143             : 
    1144             : /*****************************************************************************
    1145             :  *
    1146             :  * CALL statement
    1147             :  *
    1148             :  *****************************************************************************/
    1149             : 
    1150             : CallStmt:   CALL func_application
    1151             :                 {
    1152         620 :                     CallStmt   *n = makeNode(CallStmt);
    1153             : 
    1154         620 :                     n->funccall = castNode(FuncCall, $2);
    1155         620 :                     $$ = (Node *) n;
    1156             :                 }
    1157             :         ;
    1158             : 
    1159             : /*****************************************************************************
    1160             :  *
    1161             :  * Create a new Postgres DBMS role
    1162             :  *
    1163             :  *****************************************************************************/
    1164             : 
    1165             : CreateRoleStmt:
    1166             :             CREATE ROLE RoleId opt_with OptRoleList
    1167             :                 {
    1168        1364 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1169             : 
    1170        1364 :                     n->stmt_type = ROLESTMT_ROLE;
    1171        1364 :                     n->role = $3;
    1172        1364 :                     n->options = $5;
    1173        1364 :                     $$ = (Node *) n;
    1174             :                 }
    1175             :         ;
    1176             : 
    1177             : 
    1178             : opt_with:   WITH
    1179             :             | WITH_LA
    1180             :             | /*EMPTY*/
    1181             :         ;
    1182             : 
    1183             : /*
    1184             :  * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
    1185             :  * for backwards compatibility).  Note: the only option required by SQL99
    1186             :  * is "WITH ADMIN name".
    1187             :  */
    1188             : OptRoleList:
    1189        1182 :             OptRoleList CreateOptRoleElem           { $$ = lappend($1, $2); }
    1190        1844 :             | /* EMPTY */                           { $$ = NIL; }
    1191             :         ;
    1192             : 
    1193             : AlterOptRoleList:
    1194         658 :             AlterOptRoleList AlterOptRoleElem       { $$ = lappend($1, $2); }
    1195         418 :             | /* EMPTY */                           { $$ = NIL; }
    1196             :         ;
    1197             : 
    1198             : AlterOptRoleElem:
    1199             :             PASSWORD Sconst
    1200             :                 {
    1201         188 :                     $$ = makeDefElem("password",
    1202         188 :                                      (Node *) makeString($2), @1);
    1203             :                 }
    1204             :             | PASSWORD NULL_P
    1205             :                 {
    1206          12 :                     $$ = makeDefElem("password", NULL, @1);
    1207             :                 }
    1208             :             | ENCRYPTED PASSWORD Sconst
    1209             :                 {
    1210             :                     /*
    1211             :                      * These days, passwords are always stored in encrypted
    1212             :                      * form, so there is no difference between PASSWORD and
    1213             :                      * ENCRYPTED PASSWORD.
    1214             :                      */
    1215          18 :                     $$ = makeDefElem("password",
    1216          18 :                                      (Node *) makeString($3), @1);
    1217             :                 }
    1218             :             | UNENCRYPTED PASSWORD Sconst
    1219             :                 {
    1220           0 :                     ereport(ERROR,
    1221             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1222             :                              errmsg("UNENCRYPTED PASSWORD is no longer supported"),
    1223             :                              errhint("Remove UNENCRYPTED to store the password in encrypted form instead."),
    1224             :                              parser_errposition(@1)));
    1225             :                 }
    1226             :             | INHERIT
    1227             :                 {
    1228          94 :                     $$ = makeDefElem("inherit", (Node *) makeBoolean(true), @1);
    1229             :                 }
    1230             :             | CONNECTION LIMIT SignedIconst
    1231             :                 {
    1232          26 :                     $$ = makeDefElem("connectionlimit", (Node *) makeInteger($3), @1);
    1233             :                 }
    1234             :             | VALID UNTIL Sconst
    1235             :                 {
    1236           2 :                     $$ = makeDefElem("validUntil", (Node *) makeString($3), @1);
    1237             :                 }
    1238             :         /*  Supported but not documented for roles, for use by ALTER GROUP. */
    1239             :             | USER role_list
    1240             :                 {
    1241           6 :                     $$ = makeDefElem("rolemembers", (Node *) $2, @1);
    1242             :                 }
    1243             :             | IDENT
    1244             :                 {
    1245             :                     /*
    1246             :                      * We handle identifiers that aren't parser keywords with
    1247             :                      * the following special-case codes, to avoid bloating the
    1248             :                      * size of the main parser.
    1249             :                      */
    1250        1344 :                     if (strcmp($1, "superuser") == 0)
    1251         194 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(true), @1);
    1252        1150 :                     else if (strcmp($1, "nosuperuser") == 0)
    1253          98 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(false), @1);
    1254        1052 :                     else if (strcmp($1, "createrole") == 0)
    1255         102 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(true), @1);
    1256         950 :                     else if (strcmp($1, "nocreaterole") == 0)
    1257          36 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(false), @1);
    1258         914 :                     else if (strcmp($1, "replication") == 0)
    1259         132 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(true), @1);
    1260         782 :                     else if (strcmp($1, "noreplication") == 0)
    1261          94 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(false), @1);
    1262         688 :                     else if (strcmp($1, "createdb") == 0)
    1263          92 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(true), @1);
    1264         596 :                     else if (strcmp($1, "nocreatedb") == 0)
    1265          44 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(false), @1);
    1266         552 :                     else if (strcmp($1, "login") == 0)
    1267         282 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(true), @1);
    1268         270 :                     else if (strcmp($1, "nologin") == 0)
    1269          86 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(false), @1);
    1270         184 :                     else if (strcmp($1, "bypassrls") == 0)
    1271          82 :                         $$ = makeDefElem("bypassrls", (Node *) makeBoolean(true), @1);
    1272         102 :                     else if (strcmp($1, "nobypassrls") == 0)
    1273          66 :                         $$ = makeDefElem("bypassrls", (Node *) makeBoolean(false), @1);
    1274          36 :                     else if (strcmp($1, "noinherit") == 0)
    1275             :                     {
    1276             :                         /*
    1277             :                          * Note that INHERIT is a keyword, so it's handled by main parser, but
    1278             :                          * NOINHERIT is handled here.
    1279             :                          */
    1280          36 :                         $$ = makeDefElem("inherit", (Node *) makeBoolean(false), @1);
    1281             :                     }
    1282             :                     else
    1283           0 :                         ereport(ERROR,
    1284             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    1285             :                                  errmsg("unrecognized role option \"%s\"", $1),
    1286             :                                      parser_errposition(@1)));
    1287             :                 }
    1288             :         ;
    1289             : 
    1290             : CreateOptRoleElem:
    1291        1032 :             AlterOptRoleElem            { $$ = $1; }
    1292             :             /* The following are not supported by ALTER ROLE/USER/GROUP */
    1293             :             | SYSID Iconst
    1294             :                 {
    1295           6 :                     $$ = makeDefElem("sysid", (Node *) makeInteger($2), @1);
    1296             :                 }
    1297             :             | ADMIN role_list
    1298             :                 {
    1299          22 :                     $$ = makeDefElem("adminmembers", (Node *) $2, @1);
    1300             :                 }
    1301             :             | ROLE role_list
    1302             :                 {
    1303          22 :                     $$ = makeDefElem("rolemembers", (Node *) $2, @1);
    1304             :                 }
    1305             :             | IN_P ROLE role_list
    1306             :                 {
    1307         100 :                     $$ = makeDefElem("addroleto", (Node *) $3, @1);
    1308             :                 }
    1309             :             | IN_P GROUP_P role_list
    1310             :                 {
    1311           0 :                     $$ = makeDefElem("addroleto", (Node *) $3, @1);
    1312             :                 }
    1313             :         ;
    1314             : 
    1315             : 
    1316             : /*****************************************************************************
    1317             :  *
    1318             :  * Create a new Postgres DBMS user (role with implied login ability)
    1319             :  *
    1320             :  *****************************************************************************/
    1321             : 
    1322             : CreateUserStmt:
    1323             :             CREATE USER RoleId opt_with OptRoleList
    1324             :                 {
    1325         456 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1326             : 
    1327         456 :                     n->stmt_type = ROLESTMT_USER;
    1328         456 :                     n->role = $3;
    1329         456 :                     n->options = $5;
    1330         456 :                     $$ = (Node *) n;
    1331             :                 }
    1332             :         ;
    1333             : 
    1334             : 
    1335             : /*****************************************************************************
    1336             :  *
    1337             :  * Alter a postgresql DBMS role
    1338             :  *
    1339             :  *****************************************************************************/
    1340             : 
    1341             : AlterRoleStmt:
    1342             :             ALTER ROLE RoleSpec opt_with AlterOptRoleList
    1343             :                  {
    1344         326 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1345             : 
    1346         326 :                     n->role = $3;
    1347         326 :                     n->action = +1;  /* add, if there are members */
    1348         326 :                     n->options = $5;
    1349         326 :                     $$ = (Node *) n;
    1350             :                  }
    1351             :             | ALTER USER RoleSpec opt_with AlterOptRoleList
    1352             :                  {
    1353          92 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1354             : 
    1355          92 :                     n->role = $3;
    1356          92 :                     n->action = +1;  /* add, if there are members */
    1357          92 :                     n->options = $5;
    1358          92 :                     $$ = (Node *) n;
    1359             :                  }
    1360             :         ;
    1361             : 
    1362             : opt_in_database:
    1363          86 :                /* EMPTY */                  { $$ = NULL; }
    1364           0 :             | IN_P DATABASE name    { $$ = $3; }
    1365             :         ;
    1366             : 
    1367             : AlterRoleSetStmt:
    1368             :             ALTER ROLE RoleSpec opt_in_database SetResetClause
    1369             :                 {
    1370          48 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1371             : 
    1372          48 :                     n->role = $3;
    1373          48 :                     n->database = $4;
    1374          48 :                     n->setstmt = $5;
    1375          48 :                     $$ = (Node *) n;
    1376             :                 }
    1377             :             | ALTER ROLE ALL opt_in_database SetResetClause
    1378             :                 {
    1379           4 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1380             : 
    1381           4 :                     n->role = NULL;
    1382           4 :                     n->database = $4;
    1383           4 :                     n->setstmt = $5;
    1384           4 :                     $$ = (Node *) n;
    1385             :                 }
    1386             :             | ALTER USER RoleSpec opt_in_database SetResetClause
    1387             :                 {
    1388          26 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1389             : 
    1390          26 :                     n->role = $3;
    1391          26 :                     n->database = $4;
    1392          26 :                     n->setstmt = $5;
    1393          26 :                     $$ = (Node *) n;
    1394             :                 }
    1395             :             | ALTER USER ALL opt_in_database SetResetClause
    1396             :                 {
    1397           4 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1398             : 
    1399           4 :                     n->role = NULL;
    1400           4 :                     n->database = $4;
    1401           4 :                     n->setstmt = $5;
    1402           4 :                     $$ = (Node *) n;
    1403             :                 }
    1404             :         ;
    1405             : 
    1406             : 
    1407             : /*****************************************************************************
    1408             :  *
    1409             :  * Drop a postgresql DBMS role
    1410             :  *
    1411             :  * XXX Ideally this would have CASCADE/RESTRICT options, but a role
    1412             :  * might own objects in multiple databases, and there is presently no way to
    1413             :  * implement cascading to other databases.  So we always behave as RESTRICT.
    1414             :  *****************************************************************************/
    1415             : 
    1416             : DropRoleStmt:
    1417             :             DROP ROLE role_list
    1418             :                 {
    1419        1098 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1420             : 
    1421        1098 :                     n->missing_ok = false;
    1422        1098 :                     n->roles = $3;
    1423        1098 :                     $$ = (Node *) n;
    1424             :                 }
    1425             :             | DROP ROLE IF_P EXISTS role_list
    1426             :                 {
    1427         134 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1428             : 
    1429         134 :                     n->missing_ok = true;
    1430         134 :                     n->roles = $5;
    1431         134 :                     $$ = (Node *) n;
    1432             :                 }
    1433             :             | DROP USER role_list
    1434             :                 {
    1435         404 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1436             : 
    1437         404 :                     n->missing_ok = false;
    1438         404 :                     n->roles = $3;
    1439         404 :                     $$ = (Node *) n;
    1440             :                 }
    1441             :             | DROP USER IF_P EXISTS role_list
    1442             :                 {
    1443          36 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1444             : 
    1445          36 :                     n->roles = $5;
    1446          36 :                     n->missing_ok = true;
    1447          36 :                     $$ = (Node *) n;
    1448             :                 }
    1449             :             | DROP GROUP_P role_list
    1450             :                 {
    1451          36 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1452             : 
    1453          36 :                     n->missing_ok = false;
    1454          36 :                     n->roles = $3;
    1455          36 :                     $$ = (Node *) n;
    1456             :                 }
    1457             :             | DROP GROUP_P IF_P EXISTS role_list
    1458             :                 {
    1459           6 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1460             : 
    1461           6 :                     n->missing_ok = true;
    1462           6 :                     n->roles = $5;
    1463           6 :                     $$ = (Node *) n;
    1464             :                 }
    1465             :             ;
    1466             : 
    1467             : 
    1468             : /*****************************************************************************
    1469             :  *
    1470             :  * Create a postgresql group (role without login ability)
    1471             :  *
    1472             :  *****************************************************************************/
    1473             : 
    1474             : CreateGroupStmt:
    1475             :             CREATE GROUP_P RoleId opt_with OptRoleList
    1476             :                 {
    1477          24 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1478             : 
    1479          24 :                     n->stmt_type = ROLESTMT_GROUP;
    1480          24 :                     n->role = $3;
    1481          24 :                     n->options = $5;
    1482          24 :                     $$ = (Node *) n;
    1483             :                 }
    1484             :         ;
    1485             : 
    1486             : 
    1487             : /*****************************************************************************
    1488             :  *
    1489             :  * Alter a postgresql group
    1490             :  *
    1491             :  *****************************************************************************/
    1492             : 
    1493             : AlterGroupStmt:
    1494             :             ALTER GROUP_P RoleSpec add_drop USER role_list
    1495             :                 {
    1496          42 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1497             : 
    1498          42 :                     n->role = $3;
    1499          42 :                     n->action = $4;
    1500          42 :                     n->options = list_make1(makeDefElem("rolemembers",
    1501             :                                                         (Node *) $6, @6));
    1502          42 :                     $$ = (Node *) n;
    1503             :                 }
    1504             :         ;
    1505             : 
    1506          86 : add_drop:   ADD_P                                   { $$ = +1; }
    1507         198 :             | DROP                                  { $$ = -1; }
    1508             :         ;
    1509             : 
    1510             : 
    1511             : /*****************************************************************************
    1512             :  *
    1513             :  * Manipulate a schema
    1514             :  *
    1515             :  *****************************************************************************/
    1516             : 
    1517             : CreateSchemaStmt:
    1518             :             CREATE SCHEMA opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
    1519             :                 {
    1520         158 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1521             : 
    1522             :                     /* One can omit the schema name or the authorization id. */
    1523         158 :                     n->schemaname = $3;
    1524         158 :                     n->authrole = $5;
    1525         158 :                     n->schemaElts = $6;
    1526         158 :                     n->if_not_exists = false;
    1527         158 :                     $$ = (Node *) n;
    1528             :                 }
    1529             :             | CREATE SCHEMA ColId OptSchemaEltList
    1530             :                 {
    1531         868 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1532             : 
    1533             :                     /* ...but not both */
    1534         868 :                     n->schemaname = $3;
    1535         868 :                     n->authrole = NULL;
    1536         868 :                     n->schemaElts = $4;
    1537         868 :                     n->if_not_exists = false;
    1538         868 :                     $$ = (Node *) n;
    1539             :                 }
    1540             :             | CREATE SCHEMA IF_P NOT EXISTS opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
    1541             :                 {
    1542          18 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1543             : 
    1544             :                     /* schema name can be omitted here, too */
    1545          18 :                     n->schemaname = $6;
    1546          18 :                     n->authrole = $8;
    1547          18 :                     if ($9 != NIL)
    1548           0 :                         ereport(ERROR,
    1549             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1550             :                                  errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
    1551             :                                  parser_errposition(@9)));
    1552          18 :                     n->schemaElts = $9;
    1553          18 :                     n->if_not_exists = true;
    1554          18 :                     $$ = (Node *) n;
    1555             :                 }
    1556             :             | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
    1557             :                 {
    1558          34 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1559             : 
    1560             :                     /* ...but not here */
    1561          34 :                     n->schemaname = $6;
    1562          34 :                     n->authrole = NULL;
    1563          34 :                     if ($7 != NIL)
    1564           6 :                         ereport(ERROR,
    1565             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1566             :                                  errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
    1567             :                                  parser_errposition(@7)));
    1568          28 :                     n->schemaElts = $7;
    1569          28 :                     n->if_not_exists = true;
    1570          28 :                     $$ = (Node *) n;
    1571             :                 }
    1572             :         ;
    1573             : 
    1574             : OptSchemaEltList:
    1575             :             OptSchemaEltList schema_stmt
    1576             :                 {
    1577         546 :                     $$ = lappend($1, $2);
    1578             :                 }
    1579             :             | /* EMPTY */
    1580        1078 :                 { $$ = NIL; }
    1581             :         ;
    1582             : 
    1583             : /*
    1584             :  *  schema_stmt are the ones that can show up inside a CREATE SCHEMA
    1585             :  *  statement (in addition to by themselves).
    1586             :  */
    1587             : schema_stmt:
    1588             :             CreateStmt
    1589             :             | IndexStmt
    1590             :             | CreateSeqStmt
    1591             :             | CreateTrigStmt
    1592             :             | GrantStmt
    1593             :             | ViewStmt
    1594             :         ;
    1595             : 
    1596             : 
    1597             : /*****************************************************************************
    1598             :  *
    1599             :  * Set PG internal variable
    1600             :  *    SET name TO 'var_value'
    1601             :  * Include SQL syntax (thomas 1997-10-22):
    1602             :  *    SET TIME ZONE 'var_value'
    1603             :  *
    1604             :  *****************************************************************************/
    1605             : 
    1606             : VariableSetStmt:
    1607             :             SET set_rest
    1608             :                 {
    1609       22238 :                     VariableSetStmt *n = $2;
    1610             : 
    1611       22238 :                     n->is_local = false;
    1612       22238 :                     $$ = (Node *) n;
    1613             :                 }
    1614             :             | SET LOCAL set_rest
    1615             :                 {
    1616        1236 :                     VariableSetStmt *n = $3;
    1617             : 
    1618        1236 :                     n->is_local = true;
    1619        1236 :                     $$ = (Node *) n;
    1620             :                 }
    1621             :             | SET SESSION set_rest
    1622             :                 {
    1623          84 :                     VariableSetStmt *n = $3;
    1624             : 
    1625          84 :                     n->is_local = false;
    1626          84 :                     $$ = (Node *) n;
    1627             :                 }
    1628             :         ;
    1629             : 
    1630             : set_rest:
    1631             :             TRANSACTION transaction_mode_list
    1632             :                 {
    1633         682 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1634             : 
    1635         682 :                     n->kind = VAR_SET_MULTI;
    1636         682 :                     n->name = "TRANSACTION";
    1637         682 :                     n->args = $2;
    1638         682 :                     n->jumble_args = true;
    1639         682 :                     n->location = -1;
    1640         682 :                     $$ = n;
    1641             :                 }
    1642             :             | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
    1643             :                 {
    1644          18 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1645             : 
    1646          18 :                     n->kind = VAR_SET_MULTI;
    1647          18 :                     n->name = "SESSION CHARACTERISTICS";
    1648          18 :                     n->args = $5;
    1649          18 :                     n->jumble_args = true;
    1650          18 :                     n->location = -1;
    1651          18 :                     $$ = n;
    1652             :                 }
    1653             :             | set_rest_more
    1654             :             ;
    1655             : 
    1656             : generic_set:
    1657             :             var_name TO var_list
    1658             :                 {
    1659        5236 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1660             : 
    1661        5236 :                     n->kind = VAR_SET_VALUE;
    1662        5236 :                     n->name = $1;
    1663        5236 :                     n->args = $3;
    1664        5236 :                     n->location = @3;
    1665        5236 :                     $$ = n;
    1666             :                 }
    1667             :             | var_name '=' var_list
    1668             :                 {
    1669       15296 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1670             : 
    1671       15296 :                     n->kind = VAR_SET_VALUE;
    1672       15296 :                     n->name = $1;
    1673       15296 :                     n->args = $3;
    1674       15296 :                     n->location = @3;
    1675       15296 :                     $$ = n;
    1676             :                 }
    1677             :             | var_name TO DEFAULT
    1678             :                 {
    1679         136 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1680             : 
    1681         136 :                     n->kind = VAR_SET_DEFAULT;
    1682         136 :                     n->name = $1;
    1683         136 :                     n->location = -1;
    1684         136 :                     $$ = n;
    1685             :                 }
    1686             :             | var_name '=' DEFAULT
    1687             :                 {
    1688          10 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1689             : 
    1690          10 :                     n->kind = VAR_SET_DEFAULT;
    1691          10 :                     n->name = $1;
    1692          10 :                     n->location = -1;
    1693          10 :                     $$ = n;
    1694             :                 }
    1695             :         ;
    1696             : 
    1697             : set_rest_more:  /* Generic SET syntaxes: */
    1698       20550 :             generic_set                         {$$ = $1;}
    1699             :             | var_name FROM CURRENT_P
    1700             :                 {
    1701           4 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1702             : 
    1703           4 :                     n->kind = VAR_SET_CURRENT;
    1704           4 :                     n->name = $1;
    1705           4 :                     n->location = -1;
    1706           4 :                     $$ = n;
    1707             :                 }
    1708             :             /* Special syntaxes mandated by SQL standard: */
    1709             :             | TIME ZONE zone_value
    1710             :                 {
    1711         104 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1712             : 
    1713         104 :                     n->kind = VAR_SET_VALUE;
    1714         104 :                     n->name = "timezone";
    1715         104 :                     n->location = -1;
    1716         104 :                     n->jumble_args = true;
    1717         104 :                     if ($3 != NULL)
    1718          88 :                         n->args = list_make1($3);
    1719             :                     else
    1720          16 :                         n->kind = VAR_SET_DEFAULT;
    1721         104 :                     $$ = n;
    1722             :                 }
    1723             :             | CATALOG_P Sconst
    1724             :                 {
    1725           0 :                     ereport(ERROR,
    1726             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1727             :                              errmsg("current database cannot be changed"),
    1728             :                              parser_errposition(@2)));
    1729             :                     $$ = NULL; /*not reached*/
    1730             :                 }
    1731             :             | SCHEMA Sconst
    1732             :                 {
    1733           4 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1734             : 
    1735           4 :                     n->kind = VAR_SET_VALUE;
    1736           4 :                     n->name = "search_path";
    1737           4 :                     n->args = list_make1(makeStringConst($2, @2));
    1738           4 :                     n->location = @2;
    1739           4 :                     $$ = n;
    1740             :                 }
    1741             :             | NAMES opt_encoding
    1742             :                 {
    1743           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1744             : 
    1745           0 :                     n->kind = VAR_SET_VALUE;
    1746           0 :                     n->name = "client_encoding";
    1747           0 :                     n->location = @2;
    1748           0 :                     if ($2 != NULL)
    1749           0 :                         n->args = list_make1(makeStringConst($2, @2));
    1750             :                     else
    1751           0 :                         n->kind = VAR_SET_DEFAULT;
    1752           0 :                     $$ = n;
    1753             :                 }
    1754             :             | ROLE NonReservedWord_or_Sconst
    1755             :                 {
    1756         962 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1757             : 
    1758         962 :                     n->kind = VAR_SET_VALUE;
    1759         962 :                     n->name = "role";
    1760         962 :                     n->args = list_make1(makeStringConst($2, @2));
    1761         962 :                     n->location = @2;
    1762         962 :                     $$ = n;
    1763             :                 }
    1764             :             | SESSION AUTHORIZATION NonReservedWord_or_Sconst
    1765             :                 {
    1766        2550 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1767             : 
    1768        2550 :                     n->kind = VAR_SET_VALUE;
    1769        2550 :                     n->name = "session_authorization";
    1770        2550 :                     n->args = list_make1(makeStringConst($3, @3));
    1771        2550 :                     n->location = @3;
    1772        2550 :                     $$ = n;
    1773             :                 }
    1774             :             | SESSION AUTHORIZATION DEFAULT
    1775             :                 {
    1776           4 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1777             : 
    1778           4 :                     n->kind = VAR_SET_DEFAULT;
    1779           4 :                     n->name = "session_authorization";
    1780           4 :                     n->location = -1;
    1781           4 :                     $$ = n;
    1782             :                 }
    1783             :             | XML_P OPTION document_or_content
    1784             :                 {
    1785          16 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1786             : 
    1787          16 :                     n->kind = VAR_SET_VALUE;
    1788          16 :                     n->name = "xmloption";
    1789          16 :                     n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
    1790          16 :                     n->jumble_args = true;
    1791          16 :                     n->location = -1;
    1792          16 :                     $$ = n;
    1793             :                 }
    1794             :             /* Special syntaxes invented by PostgreSQL: */
    1795             :             | TRANSACTION SNAPSHOT Sconst
    1796             :                 {
    1797          48 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1798             : 
    1799          48 :                     n->kind = VAR_SET_MULTI;
    1800          48 :                     n->name = "TRANSACTION SNAPSHOT";
    1801          48 :                     n->args = list_make1(makeStringConst($3, @3));
    1802          48 :                     n->location = @3;
    1803          48 :                     $$ = n;
    1804             :                 }
    1805             :         ;
    1806             : 
    1807       25298 : var_name:   ColId                               { $$ = $1; }
    1808             :             | var_name '.' ColId
    1809         470 :                 { $$ = psprintf("%s.%s", $1, $3); }
    1810             :         ;
    1811             : 
    1812       20532 : var_list:   var_value                               { $$ = list_make1($1); }
    1813         176 :             | var_list ',' var_value                { $$ = lappend($1, $3); }
    1814             :         ;
    1815             : 
    1816             : var_value:  opt_boolean_or_string
    1817       15036 :                 { $$ = makeStringConst($1, @1); }
    1818             :             | NumericOnly
    1819        5672 :                 { $$ = makeAConst($1, @1); }
    1820             :         ;
    1821             : 
    1822           0 : iso_level:  READ UNCOMMITTED                        { $$ = "read uncommitted"; }
    1823         908 :             | READ COMMITTED                        { $$ = "read committed"; }
    1824        2676 :             | REPEATABLE READ                       { $$ = "repeatable read"; }
    1825        3196 :             | SERIALIZABLE                          { $$ = "serializable"; }
    1826             :         ;
    1827             : 
    1828             : opt_boolean_or_string:
    1829         682 :             TRUE_P                                  { $$ = "true"; }
    1830        1452 :             | FALSE_P                               { $$ = "false"; }
    1831        2212 :             | ON                                    { $$ = "on"; }
    1832             :             /*
    1833             :              * OFF is also accepted as a boolean value, but is handled by
    1834             :              * the NonReservedWord rule.  The action for booleans and strings
    1835             :              * is the same, so we don't need to distinguish them here.
    1836             :              */
    1837       30354 :             | NonReservedWord_or_Sconst             { $$ = $1; }
    1838             :         ;
    1839             : 
    1840             : /* Timezone values can be:
    1841             :  * - a string such as 'pst8pdt'
    1842             :  * - an identifier such as "pst8pdt"
    1843             :  * - an integer or floating point number
    1844             :  * - a time interval per SQL99
    1845             :  * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
    1846             :  * so use IDENT (meaning we reject anything that is a key word).
    1847             :  */
    1848             : zone_value:
    1849             :             Sconst
    1850             :                 {
    1851          60 :                     $$ = makeStringConst($1, @1);
    1852             :                 }
    1853             :             | IDENT
    1854             :                 {
    1855           4 :                     $$ = makeStringConst($1, @1);
    1856             :                 }
    1857             :             | ConstInterval Sconst opt_interval
    1858             :                 {
    1859           0 :                     TypeName   *t = $1;
    1860             : 
    1861           0 :                     if ($3 != NIL)
    1862             :                     {
    1863           0 :                         A_Const    *n = (A_Const *) linitial($3);
    1864             : 
    1865           0 :                         if ((n->val.ival.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
    1866           0 :                             ereport(ERROR,
    1867             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    1868             :                                      errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
    1869             :                                      parser_errposition(@3)));
    1870             :                     }
    1871           0 :                     t->typmods = $3;
    1872           0 :                     $$ = makeStringConstCast($2, @2, t);
    1873             :                 }
    1874             :             | ConstInterval '(' Iconst ')' Sconst
    1875             :                 {
    1876           0 :                     TypeName   *t = $1;
    1877             : 
    1878           0 :                     t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
    1879             :                                             makeIntConst($3, @3));
    1880           0 :                     $$ = makeStringConstCast($5, @5, t);
    1881             :                 }
    1882          24 :             | NumericOnly                           { $$ = makeAConst($1, @1); }
    1883          14 :             | DEFAULT                               { $$ = NULL; }
    1884           2 :             | LOCAL                                 { $$ = NULL; }
    1885             :         ;
    1886             : 
    1887             : opt_encoding:
    1888           0 :             Sconst                                  { $$ = $1; }
    1889           0 :             | DEFAULT                               { $$ = NULL; }
    1890           0 :             | /*EMPTY*/                             { $$ = NULL; }
    1891             :         ;
    1892             : 
    1893             : NonReservedWord_or_Sconst:
    1894       53532 :             NonReservedWord                         { $$ = $1; }
    1895        5502 :             | Sconst                                { $$ = $1; }
    1896             :         ;
    1897             : 
    1898             : VariableResetStmt:
    1899        4496 :             RESET reset_rest                        { $$ = (Node *) $2; }
    1900             :         ;
    1901             : 
    1902             : reset_rest:
    1903        3716 :             generic_reset                           { $$ = $1; }
    1904             :             | TIME ZONE
    1905             :                 {
    1906          14 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1907             : 
    1908          14 :                     n->kind = VAR_RESET;
    1909          14 :                     n->name = "timezone";
    1910          14 :                     n->location = -1;
    1911          14 :                     $$ = n;
    1912             :                 }
    1913             :             | TRANSACTION ISOLATION LEVEL
    1914             :                 {
    1915           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1916             : 
    1917           0 :                     n->kind = VAR_RESET;
    1918           0 :                     n->name = "transaction_isolation";
    1919           0 :                     n->location = -1;
    1920           0 :                     $$ = n;
    1921             :                 }
    1922             :             | SESSION AUTHORIZATION
    1923             :                 {
    1924         766 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1925             : 
    1926         766 :                     n->kind = VAR_RESET;
    1927         766 :                     n->name = "session_authorization";
    1928         766 :                     n->location = -1;
    1929         766 :                     $$ = n;
    1930             :                 }
    1931             :         ;
    1932             : 
    1933             : generic_reset:
    1934             :             var_name
    1935             :                 {
    1936        3752 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1937             : 
    1938        3752 :                     n->kind = VAR_RESET;
    1939        3752 :                     n->name = $1;
    1940        3752 :                     n->location = -1;
    1941        3752 :                     $$ = n;
    1942             :                 }
    1943             :             | ALL
    1944             :                 {
    1945          18 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1946             : 
    1947          18 :                     n->kind = VAR_RESET_ALL;
    1948          18 :                     n->location = -1;
    1949          18 :                     $$ = n;
    1950             :                 }
    1951             :         ;
    1952             : 
    1953             : /* SetResetClause allows SET or RESET without LOCAL */
    1954             : SetResetClause:
    1955        1236 :             SET set_rest                    { $$ = $2; }
    1956          44 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    1957             :         ;
    1958             : 
    1959             : /* SetResetClause allows SET or RESET without LOCAL */
    1960             : FunctionSetResetClause:
    1961         148 :             SET set_rest_more               { $$ = $2; }
    1962          12 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    1963             :         ;
    1964             : 
    1965             : 
    1966             : VariableShowStmt:
    1967             :             SHOW var_name
    1968             :                 {
    1969         864 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1970             : 
    1971         864 :                     n->name = $2;
    1972         864 :                     $$ = (Node *) n;
    1973             :                 }
    1974             :             | SHOW TIME ZONE
    1975             :                 {
    1976          10 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1977             : 
    1978          10 :                     n->name = "timezone";
    1979          10 :                     $$ = (Node *) n;
    1980             :                 }
    1981             :             | SHOW TRANSACTION ISOLATION LEVEL
    1982             :                 {
    1983           4 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1984             : 
    1985           4 :                     n->name = "transaction_isolation";
    1986           4 :                     $$ = (Node *) n;
    1987             :                 }
    1988             :             | SHOW SESSION AUTHORIZATION
    1989             :                 {
    1990           0 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1991             : 
    1992           0 :                     n->name = "session_authorization";
    1993           0 :                     $$ = (Node *) n;
    1994             :                 }
    1995             :             | SHOW ALL
    1996             :                 {
    1997           0 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1998             : 
    1999           0 :                     n->name = "all";
    2000           0 :                     $$ = (Node *) n;
    2001             :                 }
    2002             :         ;
    2003             : 
    2004             : 
    2005             : ConstraintsSetStmt:
    2006             :             SET CONSTRAINTS constraints_set_list constraints_set_mode
    2007             :                 {
    2008         104 :                     ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
    2009             : 
    2010         104 :                     n->constraints = $3;
    2011         104 :                     n->deferred = $4;
    2012         104 :                     $$ = (Node *) n;
    2013             :                 }
    2014             :         ;
    2015             : 
    2016             : constraints_set_list:
    2017          56 :             ALL                                     { $$ = NIL; }
    2018          48 :             | qualified_name_list                   { $$ = $1; }
    2019             :         ;
    2020             : 
    2021             : constraints_set_mode:
    2022          68 :             DEFERRED                                { $$ = true; }
    2023          36 :             | IMMEDIATE                             { $$ = false; }
    2024             :         ;
    2025             : 
    2026             : 
    2027             : /*
    2028             :  * Checkpoint statement
    2029             :  */
    2030             : CheckPointStmt:
    2031             :             CHECKPOINT
    2032             :                 {
    2033         224 :                     CheckPointStmt *n = makeNode(CheckPointStmt);
    2034             : 
    2035         224 :                     $$ = (Node *) n;
    2036             :                 }
    2037             :         ;
    2038             : 
    2039             : 
    2040             : /*****************************************************************************
    2041             :  *
    2042             :  * DISCARD { ALL | TEMP | PLANS | SEQUENCES }
    2043             :  *
    2044             :  *****************************************************************************/
    2045             : 
    2046             : DiscardStmt:
    2047             :             DISCARD ALL
    2048             :                 {
    2049           6 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2050             : 
    2051           6 :                     n->target = DISCARD_ALL;
    2052           6 :                     $$ = (Node *) n;
    2053             :                 }
    2054             :             | DISCARD TEMP
    2055             :                 {
    2056           8 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2057             : 
    2058           8 :                     n->target = DISCARD_TEMP;
    2059           8 :                     $$ = (Node *) n;
    2060             :                 }
    2061             :             | DISCARD TEMPORARY
    2062             :                 {
    2063           0 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2064             : 
    2065           0 :                     n->target = DISCARD_TEMP;
    2066           0 :                     $$ = (Node *) n;
    2067             :                 }
    2068             :             | DISCARD PLANS
    2069             :                 {
    2070           4 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2071             : 
    2072           4 :                     n->target = DISCARD_PLANS;
    2073           4 :                     $$ = (Node *) n;
    2074             :                 }
    2075             :             | DISCARD SEQUENCES
    2076             :                 {
    2077          12 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2078             : 
    2079          12 :                     n->target = DISCARD_SEQUENCES;
    2080          12 :                     $$ = (Node *) n;
    2081             :                 }
    2082             : 
    2083             :         ;
    2084             : 
    2085             : 
    2086             : /*****************************************************************************
    2087             :  *
    2088             :  *  ALTER [ TABLE | INDEX | SEQUENCE | VIEW | MATERIALIZED VIEW | FOREIGN TABLE ] variations
    2089             :  *
    2090             :  * Note: we accept all subcommands for each of the variants, and sort
    2091             :  * out what's really legal at execution time.
    2092             :  *****************************************************************************/
    2093             : 
    2094             : AlterTableStmt:
    2095             :             ALTER TABLE relation_expr alter_table_cmds
    2096             :                 {
    2097       28320 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2098             : 
    2099       28320 :                     n->relation = $3;
    2100       28320 :                     n->cmds = $4;
    2101       28320 :                     n->objtype = OBJECT_TABLE;
    2102       28320 :                     n->missing_ok = false;
    2103       28320 :                     $$ = (Node *) n;
    2104             :                 }
    2105             :         |   ALTER TABLE IF_P EXISTS relation_expr alter_table_cmds
    2106             :                 {
    2107          54 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2108             : 
    2109          54 :                     n->relation = $5;
    2110          54 :                     n->cmds = $6;
    2111          54 :                     n->objtype = OBJECT_TABLE;
    2112          54 :                     n->missing_ok = true;
    2113          54 :                     $$ = (Node *) n;
    2114             :                 }
    2115             :         |   ALTER TABLE relation_expr partition_cmd
    2116             :                 {
    2117        3446 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2118             : 
    2119        3446 :                     n->relation = $3;
    2120        3446 :                     n->cmds = list_make1($4);
    2121        3446 :                     n->objtype = OBJECT_TABLE;
    2122        3446 :                     n->missing_ok = false;
    2123        3446 :                     $$ = (Node *) n;
    2124             :                 }
    2125             :         |   ALTER TABLE IF_P EXISTS relation_expr partition_cmd
    2126             :                 {
    2127           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2128             : 
    2129           0 :                     n->relation = $5;
    2130           0 :                     n->cmds = list_make1($6);
    2131           0 :                     n->objtype = OBJECT_TABLE;
    2132           0 :                     n->missing_ok = true;
    2133           0 :                     $$ = (Node *) n;
    2134             :                 }
    2135             :         |   ALTER TABLE ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2136             :                 {
    2137             :                     AlterTableMoveAllStmt *n =
    2138          12 :                         makeNode(AlterTableMoveAllStmt);
    2139             : 
    2140          12 :                     n->orig_tablespacename = $6;
    2141          12 :                     n->objtype = OBJECT_TABLE;
    2142          12 :                     n->roles = NIL;
    2143          12 :                     n->new_tablespacename = $9;
    2144          12 :                     n->nowait = $10;
    2145          12 :                     $$ = (Node *) n;
    2146             :                 }
    2147             :         |   ALTER TABLE ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2148             :                 {
    2149             :                     AlterTableMoveAllStmt *n =
    2150           0 :                         makeNode(AlterTableMoveAllStmt);
    2151             : 
    2152           0 :                     n->orig_tablespacename = $6;
    2153           0 :                     n->objtype = OBJECT_TABLE;
    2154           0 :                     n->roles = $9;
    2155           0 :                     n->new_tablespacename = $12;
    2156           0 :                     n->nowait = $13;
    2157           0 :                     $$ = (Node *) n;
    2158             :                 }
    2159             :         |   ALTER INDEX qualified_name alter_table_cmds
    2160             :                 {
    2161         228 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2162             : 
    2163         228 :                     n->relation = $3;
    2164         228 :                     n->cmds = $4;
    2165         228 :                     n->objtype = OBJECT_INDEX;
    2166         228 :                     n->missing_ok = false;
    2167         228 :                     $$ = (Node *) n;
    2168             :                 }
    2169             :         |   ALTER INDEX IF_P EXISTS qualified_name alter_table_cmds
    2170             :                 {
    2171           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2172             : 
    2173           0 :                     n->relation = $5;
    2174           0 :                     n->cmds = $6;
    2175           0 :                     n->objtype = OBJECT_INDEX;
    2176           0 :                     n->missing_ok = true;
    2177           0 :                     $$ = (Node *) n;
    2178             :                 }
    2179             :         |   ALTER INDEX qualified_name index_partition_cmd
    2180             :                 {
    2181         482 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2182             : 
    2183         482 :                     n->relation = $3;
    2184         482 :                     n->cmds = list_make1($4);
    2185         482 :                     n->objtype = OBJECT_INDEX;
    2186         482 :                     n->missing_ok = false;
    2187         482 :                     $$ = (Node *) n;
    2188             :                 }
    2189             :         |   ALTER INDEX ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2190             :                 {
    2191             :                     AlterTableMoveAllStmt *n =
    2192           6 :                         makeNode(AlterTableMoveAllStmt);
    2193             : 
    2194           6 :                     n->orig_tablespacename = $6;
    2195           6 :                     n->objtype = OBJECT_INDEX;
    2196           6 :                     n->roles = NIL;
    2197           6 :                     n->new_tablespacename = $9;
    2198           6 :                     n->nowait = $10;
    2199           6 :                     $$ = (Node *) n;
    2200             :                 }
    2201             :         |   ALTER INDEX ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2202             :                 {
    2203             :                     AlterTableMoveAllStmt *n =
    2204           0 :                         makeNode(AlterTableMoveAllStmt);
    2205             : 
    2206           0 :                     n->orig_tablespacename = $6;
    2207           0 :                     n->objtype = OBJECT_INDEX;
    2208           0 :                     n->roles = $9;
    2209           0 :                     n->new_tablespacename = $12;
    2210           0 :                     n->nowait = $13;
    2211           0 :                     $$ = (Node *) n;
    2212             :                 }
    2213             :         |   ALTER SEQUENCE qualified_name alter_table_cmds
    2214             :                 {
    2215         156 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2216             : 
    2217         156 :                     n->relation = $3;
    2218         156 :                     n->cmds = $4;
    2219         156 :                     n->objtype = OBJECT_SEQUENCE;
    2220         156 :                     n->missing_ok = false;
    2221         156 :                     $$ = (Node *) n;
    2222             :                 }
    2223             :         |   ALTER SEQUENCE IF_P EXISTS qualified_name alter_table_cmds
    2224             :                 {
    2225           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2226             : 
    2227           0 :                     n->relation = $5;
    2228           0 :                     n->cmds = $6;
    2229           0 :                     n->objtype = OBJECT_SEQUENCE;
    2230           0 :                     n->missing_ok = true;
    2231           0 :                     $$ = (Node *) n;
    2232             :                 }
    2233             :         |   ALTER VIEW qualified_name alter_table_cmds
    2234             :                 {
    2235         356 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2236             : 
    2237         356 :                     n->relation = $3;
    2238         356 :                     n->cmds = $4;
    2239         356 :                     n->objtype = OBJECT_VIEW;
    2240         356 :                     n->missing_ok = false;
    2241         356 :                     $$ = (Node *) n;
    2242             :                 }
    2243             :         |   ALTER VIEW IF_P EXISTS qualified_name alter_table_cmds
    2244             :                 {
    2245           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2246             : 
    2247           0 :                     n->relation = $5;
    2248           0 :                     n->cmds = $6;
    2249           0 :                     n->objtype = OBJECT_VIEW;
    2250           0 :                     n->missing_ok = true;
    2251           0 :                     $$ = (Node *) n;
    2252             :                 }
    2253             :         |   ALTER MATERIALIZED VIEW qualified_name alter_table_cmds
    2254             :                 {
    2255          64 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2256             : 
    2257          64 :                     n->relation = $4;
    2258          64 :                     n->cmds = $5;
    2259          64 :                     n->objtype = OBJECT_MATVIEW;
    2260          64 :                     n->missing_ok = false;
    2261          64 :                     $$ = (Node *) n;
    2262             :                 }
    2263             :         |   ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name alter_table_cmds
    2264             :                 {
    2265           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2266             : 
    2267           0 :                     n->relation = $6;
    2268           0 :                     n->cmds = $7;
    2269           0 :                     n->objtype = OBJECT_MATVIEW;
    2270           0 :                     n->missing_ok = true;
    2271           0 :                     $$ = (Node *) n;
    2272             :                 }
    2273             :         |   ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2274             :                 {
    2275             :                     AlterTableMoveAllStmt *n =
    2276          12 :                         makeNode(AlterTableMoveAllStmt);
    2277             : 
    2278          12 :                     n->orig_tablespacename = $7;
    2279          12 :                     n->objtype = OBJECT_MATVIEW;
    2280          12 :                     n->roles = NIL;
    2281          12 :                     n->new_tablespacename = $10;
    2282          12 :                     n->nowait = $11;
    2283          12 :                     $$ = (Node *) n;
    2284             :                 }
    2285             :         |   ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2286             :                 {
    2287             :                     AlterTableMoveAllStmt *n =
    2288           0 :                         makeNode(AlterTableMoveAllStmt);
    2289             : 
    2290           0 :                     n->orig_tablespacename = $7;
    2291           0 :                     n->objtype = OBJECT_MATVIEW;
    2292           0 :                     n->roles = $10;
    2293           0 :                     n->new_tablespacename = $13;
    2294           0 :                     n->nowait = $14;
    2295           0 :                     $$ = (Node *) n;
    2296             :                 }
    2297             :         |   ALTER FOREIGN TABLE relation_expr alter_table_cmds
    2298             :                 {
    2299         374 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2300             : 
    2301         374 :                     n->relation = $4;
    2302         374 :                     n->cmds = $5;
    2303         374 :                     n->objtype = OBJECT_FOREIGN_TABLE;
    2304         374 :                     n->missing_ok = false;
    2305         374 :                     $$ = (Node *) n;
    2306             :                 }
    2307             :         |   ALTER FOREIGN TABLE IF_P EXISTS relation_expr alter_table_cmds
    2308             :                 {
    2309         108 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2310             : 
    2311         108 :                     n->relation = $6;
    2312         108 :                     n->cmds = $7;
    2313         108 :                     n->objtype = OBJECT_FOREIGN_TABLE;
    2314         108 :                     n->missing_ok = true;
    2315         108 :                     $$ = (Node *) n;
    2316             :                 }
    2317             :         ;
    2318             : 
    2319             : alter_table_cmds:
    2320       29660 :             alter_table_cmd                         { $$ = list_make1($1); }
    2321        1020 :             | alter_table_cmds ',' alter_table_cmd  { $$ = lappend($1, $3); }
    2322             :         ;
    2323             : 
    2324             : partition_cmd:
    2325             :             /* ALTER TABLE <name> ATTACH PARTITION <table_name> FOR VALUES */
    2326             :             ATTACH PARTITION qualified_name PartitionBoundSpec
    2327             :                 {
    2328        2832 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2329        2832 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2330             : 
    2331        2832 :                     n->subtype = AT_AttachPartition;
    2332        2832 :                     cmd->name = $3;
    2333        2832 :                     cmd->bound = $4;
    2334        2832 :                     cmd->concurrent = false;
    2335        2832 :                     n->def = (Node *) cmd;
    2336             : 
    2337        2832 :                     $$ = (Node *) n;
    2338             :                 }
    2339             :             /* ALTER TABLE <name> DETACH PARTITION <partition_name> [CONCURRENTLY] */
    2340             :             | DETACH PARTITION qualified_name opt_concurrently
    2341             :                 {
    2342         594 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2343         594 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2344             : 
    2345         594 :                     n->subtype = AT_DetachPartition;
    2346         594 :                     cmd->name = $3;
    2347         594 :                     cmd->bound = NULL;
    2348         594 :                     cmd->concurrent = $4;
    2349         594 :                     n->def = (Node *) cmd;
    2350             : 
    2351         594 :                     $$ = (Node *) n;
    2352             :                 }
    2353             :             | DETACH PARTITION qualified_name FINALIZE
    2354             :                 {
    2355          20 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2356          20 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2357             : 
    2358          20 :                     n->subtype = AT_DetachPartitionFinalize;
    2359          20 :                     cmd->name = $3;
    2360          20 :                     cmd->bound = NULL;
    2361          20 :                     cmd->concurrent = false;
    2362          20 :                     n->def = (Node *) cmd;
    2363          20 :                     $$ = (Node *) n;
    2364             :                 }
    2365             :         ;
    2366             : 
    2367             : index_partition_cmd:
    2368             :             /* ALTER INDEX <name> ATTACH PARTITION <index_name> */
    2369             :             ATTACH PARTITION qualified_name
    2370             :                 {
    2371         482 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2372         482 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2373             : 
    2374         482 :                     n->subtype = AT_AttachPartition;
    2375         482 :                     cmd->name = $3;
    2376         482 :                     cmd->bound = NULL;
    2377         482 :                     cmd->concurrent = false;
    2378         482 :                     n->def = (Node *) cmd;
    2379             : 
    2380         482 :                     $$ = (Node *) n;
    2381             :                 }
    2382             :         ;
    2383             : 
    2384             : alter_table_cmd:
    2385             :             /* ALTER TABLE <name> ADD <coldef> */
    2386             :             ADD_P columnDef
    2387             :                 {
    2388         192 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2389             : 
    2390         192 :                     n->subtype = AT_AddColumn;
    2391         192 :                     n->def = $2;
    2392         192 :                     n->missing_ok = false;
    2393         192 :                     $$ = (Node *) n;
    2394             :                 }
    2395             :             /* ALTER TABLE <name> ADD IF NOT EXISTS <coldef> */
    2396             :             | ADD_P IF_P NOT EXISTS columnDef
    2397             :                 {
    2398           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2399             : 
    2400           0 :                     n->subtype = AT_AddColumn;
    2401           0 :                     n->def = $5;
    2402           0 :                     n->missing_ok = true;
    2403           0 :                     $$ = (Node *) n;
    2404             :                 }
    2405             :             /* ALTER TABLE <name> ADD COLUMN <coldef> */
    2406             :             | ADD_P COLUMN columnDef
    2407             :                 {
    2408        1896 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2409             : 
    2410        1896 :                     n->subtype = AT_AddColumn;
    2411        1896 :                     n->def = $3;
    2412        1896 :                     n->missing_ok = false;
    2413        1896 :                     $$ = (Node *) n;
    2414             :                 }
    2415             :             /* ALTER TABLE <name> ADD COLUMN IF NOT EXISTS <coldef> */
    2416             :             | ADD_P COLUMN IF_P NOT EXISTS columnDef
    2417             :                 {
    2418          60 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2419             : 
    2420          60 :                     n->subtype = AT_AddColumn;
    2421          60 :                     n->def = $6;
    2422          60 :                     n->missing_ok = true;
    2423          60 :                     $$ = (Node *) n;
    2424             :                 }
    2425             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
    2426             :             | ALTER opt_column ColId alter_column_default
    2427             :                 {
    2428         578 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2429             : 
    2430         578 :                     n->subtype = AT_ColumnDefault;
    2431         578 :                     n->name = $3;
    2432         578 :                     n->def = $4;
    2433         578 :                     $$ = (Node *) n;
    2434             :                 }
    2435             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
    2436             :             | ALTER opt_column ColId DROP NOT NULL_P
    2437             :                 {
    2438         294 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2439             : 
    2440         294 :                     n->subtype = AT_DropNotNull;
    2441         294 :                     n->name = $3;
    2442         294 :                     $$ = (Node *) n;
    2443             :                 }
    2444             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
    2445             :             | ALTER opt_column ColId SET NOT NULL_P
    2446             :                 {
    2447         434 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2448             : 
    2449         434 :                     n->subtype = AT_SetNotNull;
    2450         434 :                     n->name = $3;
    2451         434 :                     $$ = (Node *) n;
    2452             :                 }
    2453             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET EXPRESSION AS <expr> */
    2454             :             | ALTER opt_column ColId SET EXPRESSION AS '(' a_expr ')'
    2455             :                 {
    2456         168 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2457             : 
    2458         168 :                     n->subtype = AT_SetExpression;
    2459         168 :                     n->name = $3;
    2460         168 :                     n->def = $8;
    2461         168 :                     $$ = (Node *) n;
    2462             :                 }
    2463             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
    2464             :             | ALTER opt_column ColId DROP EXPRESSION
    2465             :                 {
    2466          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2467             : 
    2468          62 :                     n->subtype = AT_DropExpression;
    2469          62 :                     n->name = $3;
    2470          62 :                     $$ = (Node *) n;
    2471             :                 }
    2472             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION IF EXISTS */
    2473             :             | ALTER opt_column ColId DROP EXPRESSION IF_P EXISTS
    2474             :                 {
    2475          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2476             : 
    2477          12 :                     n->subtype = AT_DropExpression;
    2478          12 :                     n->name = $3;
    2479          12 :                     n->missing_ok = true;
    2480          12 :                     $$ = (Node *) n;
    2481             :                 }
    2482             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS */
    2483             :             | ALTER opt_column ColId SET STATISTICS set_statistics_value
    2484             :                 {
    2485          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2486             : 
    2487          62 :                     n->subtype = AT_SetStatistics;
    2488          62 :                     n->name = $3;
    2489          62 :                     n->def = $6;
    2490          62 :                     $$ = (Node *) n;
    2491             :                 }
    2492             :             /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS */
    2493             :             | ALTER opt_column Iconst SET STATISTICS set_statistics_value
    2494             :                 {
    2495          70 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2496             : 
    2497          70 :                     if ($3 <= 0 || $3 > PG_INT16_MAX)
    2498           6 :                         ereport(ERROR,
    2499             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
    2500             :                                  errmsg("column number must be in range from 1 to %d", PG_INT16_MAX),
    2501             :                                  parser_errposition(@3)));
    2502             : 
    2503          64 :                     n->subtype = AT_SetStatistics;
    2504          64 :                     n->num = (int16) $3;
    2505          64 :                     n->def = $6;
    2506          64 :                     $$ = (Node *) n;
    2507             :                 }
    2508             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
    2509             :             | ALTER opt_column ColId SET reloptions
    2510             :                 {
    2511          38 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2512             : 
    2513          38 :                     n->subtype = AT_SetOptions;
    2514          38 :                     n->name = $3;
    2515          38 :                     n->def = (Node *) $5;
    2516          38 :                     $$ = (Node *) n;
    2517             :                 }
    2518             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> RESET ( column_parameter [, ... ] ) */
    2519             :             | ALTER opt_column ColId RESET reloptions
    2520             :                 {
    2521           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2522             : 
    2523           6 :                     n->subtype = AT_ResetOptions;
    2524           6 :                     n->name = $3;
    2525           6 :                     n->def = (Node *) $5;
    2526           6 :                     $$ = (Node *) n;
    2527             :                 }
    2528             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
    2529             :             | ALTER opt_column ColId SET column_storage
    2530             :                 {
    2531         224 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2532             : 
    2533         224 :                     n->subtype = AT_SetStorage;
    2534         224 :                     n->name = $3;
    2535         224 :                     n->def = (Node *) makeString($5);
    2536         224 :                     $$ = (Node *) n;
    2537             :                 }
    2538             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET COMPRESSION <cm> */
    2539             :             | ALTER opt_column ColId SET column_compression
    2540             :                 {
    2541          90 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2542             : 
    2543          90 :                     n->subtype = AT_SetCompression;
    2544          90 :                     n->name = $3;
    2545          90 :                     n->def = (Node *) makeString($5);
    2546          90 :                     $$ = (Node *) n;
    2547             :                 }
    2548             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> ADD GENERATED ... AS IDENTITY ... */
    2549             :             | ALTER opt_column ColId ADD_P GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    2550             :                 {
    2551         210 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2552         210 :                     Constraint *c = makeNode(Constraint);
    2553             : 
    2554         210 :                     c->contype = CONSTR_IDENTITY;
    2555         210 :                     c->generated_when = $6;
    2556         210 :                     c->options = $9;
    2557         210 :                     c->location = @5;
    2558             : 
    2559         210 :                     n->subtype = AT_AddIdentity;
    2560         210 :                     n->name = $3;
    2561         210 :                     n->def = (Node *) c;
    2562             : 
    2563         210 :                     $$ = (Node *) n;
    2564             :                 }
    2565             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET <sequence options>/RESET */
    2566             :             | ALTER opt_column ColId alter_identity_column_option_list
    2567             :                 {
    2568          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2569             : 
    2570          62 :                     n->subtype = AT_SetIdentity;
    2571          62 :                     n->name = $3;
    2572          62 :                     n->def = (Node *) $4;
    2573          62 :                     $$ = (Node *) n;
    2574             :                 }
    2575             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY */
    2576             :             | ALTER opt_column ColId DROP IDENTITY_P
    2577             :                 {
    2578          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2579             : 
    2580          50 :                     n->subtype = AT_DropIdentity;
    2581          50 :                     n->name = $3;
    2582          50 :                     n->missing_ok = false;
    2583          50 :                     $$ = (Node *) n;
    2584             :                 }
    2585             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY IF EXISTS */
    2586             :             | ALTER opt_column ColId DROP IDENTITY_P IF_P EXISTS
    2587             :                 {
    2588           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2589             : 
    2590           6 :                     n->subtype = AT_DropIdentity;
    2591           6 :                     n->name = $3;
    2592           6 :                     n->missing_ok = true;
    2593           6 :                     $$ = (Node *) n;
    2594             :                 }
    2595             :             /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
    2596             :             | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
    2597             :                 {
    2598          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2599             : 
    2600          18 :                     n->subtype = AT_DropColumn;
    2601          18 :                     n->name = $5;
    2602          18 :                     n->behavior = $6;
    2603          18 :                     n->missing_ok = true;
    2604          18 :                     $$ = (Node *) n;
    2605             :                 }
    2606             :             /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
    2607             :             | DROP opt_column ColId opt_drop_behavior
    2608             :                 {
    2609        1574 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2610             : 
    2611        1574 :                     n->subtype = AT_DropColumn;
    2612        1574 :                     n->name = $3;
    2613        1574 :                     n->behavior = $4;
    2614        1574 :                     n->missing_ok = false;
    2615        1574 :                     $$ = (Node *) n;
    2616             :                 }
    2617             :             /*
    2618             :              * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
    2619             :              *      [ USING <expression> ]
    2620             :              */
    2621             :             | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using
    2622             :                 {
    2623        1024 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2624        1024 :                     ColumnDef *def = makeNode(ColumnDef);
    2625             : 
    2626        1024 :                     n->subtype = AT_AlterColumnType;
    2627        1024 :                     n->name = $3;
    2628        1024 :                     n->def = (Node *) def;
    2629             :                     /* We only use these fields of the ColumnDef node */
    2630        1024 :                     def->typeName = $6;
    2631        1024 :                     def->collClause = (CollateClause *) $7;
    2632        1024 :                     def->raw_default = $8;
    2633        1024 :                     def->location = @3;
    2634        1024 :                     $$ = (Node *) n;
    2635             :                 }
    2636             :             /* ALTER FOREIGN TABLE <name> ALTER [COLUMN] <colname> OPTIONS */
    2637             :             | ALTER opt_column ColId alter_generic_options
    2638             :                 {
    2639          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2640             : 
    2641          50 :                     n->subtype = AT_AlterColumnGenericOptions;
    2642          50 :                     n->name = $3;
    2643          50 :                     n->def = (Node *) $4;
    2644          50 :                     $$ = (Node *) n;
    2645             :                 }
    2646             :             /* ALTER TABLE <name> ADD CONSTRAINT ... */
    2647             :             | ADD_P TableConstraint
    2648             :                 {
    2649       15108 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2650             : 
    2651       15108 :                     n->subtype = AT_AddConstraint;
    2652       15108 :                     n->def = $2;
    2653       15108 :                     $$ = (Node *) n;
    2654             :                 }
    2655             :             /* ALTER TABLE <name> ALTER CONSTRAINT ... */
    2656             :             | ALTER CONSTRAINT name ConstraintAttributeSpec
    2657             :                 {
    2658         240 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2659         240 :                     ATAlterConstraint *c = makeNode(ATAlterConstraint);
    2660             : 
    2661         240 :                     n->subtype = AT_AlterConstraint;
    2662         240 :                     n->def = (Node *) c;
    2663         240 :                     c->conname = $3;
    2664         240 :                     if ($4 & (CAS_NOT_ENFORCED | CAS_ENFORCED))
    2665          84 :                         c->alterEnforceability = true;
    2666         240 :                     if ($4 & (CAS_DEFERRABLE | CAS_NOT_DEFERRABLE |
    2667             :                               CAS_INITIALLY_DEFERRED | CAS_INITIALLY_IMMEDIATE))
    2668         120 :                         c->alterDeferrability = true;
    2669         240 :                     if ($4 & CAS_NO_INHERIT)
    2670          30 :                         c->alterInheritability = true;
    2671             :                     /* handle unsupported case with specific error message */
    2672         240 :                     if ($4 & CAS_NOT_VALID)
    2673          12 :                         ereport(ERROR,
    2674             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    2675             :                                 errmsg("constraints cannot be altered to be NOT VALID"),
    2676             :                                 parser_errposition(@4));
    2677         228 :                     processCASbits($4, @4, "FOREIGN KEY",
    2678             :                                     &c->deferrable,
    2679             :                                     &c->initdeferred,
    2680             :                                     &c->is_enforced,
    2681             :                                     NULL,
    2682             :                                     &c->noinherit,
    2683             :                                     yyscanner);
    2684         228 :                     $$ = (Node *) n;
    2685             :                 }
    2686             :             /* ALTER TABLE <name> ALTER CONSTRAINT INHERIT */
    2687             :             | ALTER CONSTRAINT name INHERIT
    2688             :                 {
    2689          66 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2690          66 :                     ATAlterConstraint *c = makeNode(ATAlterConstraint);
    2691             : 
    2692          66 :                     n->subtype = AT_AlterConstraint;
    2693          66 :                     n->def = (Node *) c;
    2694          66 :                     c->conname = $3;
    2695          66 :                     c->alterInheritability = true;
    2696          66 :                     c->noinherit = false;
    2697             : 
    2698          66 :                     $$ = (Node *) n;
    2699             :                 }
    2700             :             /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
    2701             :             | VALIDATE CONSTRAINT name
    2702             :                 {
    2703         476 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2704             : 
    2705         476 :                     n->subtype = AT_ValidateConstraint;
    2706         476 :                     n->name = $3;
    2707         476 :                     $$ = (Node *) n;
    2708             :                 }
    2709             :             /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
    2710             :             | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
    2711             :                 {
    2712          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2713             : 
    2714          18 :                     n->subtype = AT_DropConstraint;
    2715          18 :                     n->name = $5;
    2716          18 :                     n->behavior = $6;
    2717          18 :                     n->missing_ok = true;
    2718          18 :                     $$ = (Node *) n;
    2719             :                 }
    2720             :             /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
    2721             :             | DROP CONSTRAINT name opt_drop_behavior
    2722             :                 {
    2723         816 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2724             : 
    2725         816 :                     n->subtype = AT_DropConstraint;
    2726         816 :                     n->name = $3;
    2727         816 :                     n->behavior = $4;
    2728         816 :                     n->missing_ok = false;
    2729         816 :                     $$ = (Node *) n;
    2730             :                 }
    2731             :             /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat */
    2732             :             | SET WITHOUT OIDS
    2733             :                 {
    2734           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2735             : 
    2736           6 :                     n->subtype = AT_DropOids;
    2737           6 :                     $$ = (Node *) n;
    2738             :                 }
    2739             :             /* ALTER TABLE <name> CLUSTER ON <indexname> */
    2740             :             | CLUSTER ON name
    2741             :                 {
    2742          46 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2743             : 
    2744          46 :                     n->subtype = AT_ClusterOn;
    2745          46 :                     n->name = $3;
    2746          46 :                     $$ = (Node *) n;
    2747             :                 }
    2748             :             /* ALTER TABLE <name> SET WITHOUT CLUSTER */
    2749             :             | SET WITHOUT CLUSTER
    2750             :                 {
    2751          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2752             : 
    2753          18 :                     n->subtype = AT_DropCluster;
    2754          18 :                     n->name = NULL;
    2755          18 :                     $$ = (Node *) n;
    2756             :                 }
    2757             :             /* ALTER TABLE <name> SET LOGGED */
    2758             :             | SET LOGGED
    2759             :                 {
    2760          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2761             : 
    2762          50 :                     n->subtype = AT_SetLogged;
    2763          50 :                     $$ = (Node *) n;
    2764             :                 }
    2765             :             /* ALTER TABLE <name> SET UNLOGGED */
    2766             :             | SET UNLOGGED
    2767             :                 {
    2768          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2769             : 
    2770          62 :                     n->subtype = AT_SetUnLogged;
    2771          62 :                     $$ = (Node *) n;
    2772             :                 }
    2773             :             /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
    2774             :             | ENABLE_P TRIGGER name
    2775             :                 {
    2776         122 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2777             : 
    2778         122 :                     n->subtype = AT_EnableTrig;
    2779         122 :                     n->name = $3;
    2780         122 :                     $$ = (Node *) n;
    2781             :                 }
    2782             :             /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
    2783             :             | ENABLE_P ALWAYS TRIGGER name
    2784             :                 {
    2785          44 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2786             : 
    2787          44 :                     n->subtype = AT_EnableAlwaysTrig;
    2788          44 :                     n->name = $4;
    2789          44 :                     $$ = (Node *) n;
    2790             :                 }
    2791             :             /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
    2792             :             | ENABLE_P REPLICA TRIGGER name
    2793             :                 {
    2794          16 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2795             : 
    2796          16 :                     n->subtype = AT_EnableReplicaTrig;
    2797          16 :                     n->name = $4;
    2798          16 :                     $$ = (Node *) n;
    2799             :                 }
    2800             :             /* ALTER TABLE <name> ENABLE TRIGGER ALL */
    2801             :             | ENABLE_P TRIGGER ALL
    2802             :                 {
    2803           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2804             : 
    2805           0 :                     n->subtype = AT_EnableTrigAll;
    2806           0 :                     $$ = (Node *) n;
    2807             :                 }
    2808             :             /* ALTER TABLE <name> ENABLE TRIGGER USER */
    2809             :             | ENABLE_P TRIGGER USER
    2810             :                 {
    2811           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2812             : 
    2813           0 :                     n->subtype = AT_EnableTrigUser;
    2814           0 :                     $$ = (Node *) n;
    2815             :                 }
    2816             :             /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
    2817             :             | DISABLE_P TRIGGER name
    2818             :                 {
    2819         140 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2820             : 
    2821         140 :                     n->subtype = AT_DisableTrig;
    2822         140 :                     n->name = $3;
    2823         140 :                     $$ = (Node *) n;
    2824             :                 }
    2825             :             /* ALTER TABLE <name> DISABLE TRIGGER ALL */
    2826             :             | DISABLE_P TRIGGER ALL
    2827             :                 {
    2828          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2829             : 
    2830          12 :                     n->subtype = AT_DisableTrigAll;
    2831          12 :                     $$ = (Node *) n;
    2832             :                 }
    2833             :             /* ALTER TABLE <name> DISABLE TRIGGER USER */
    2834             :             | DISABLE_P TRIGGER USER
    2835             :                 {
    2836          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2837             : 
    2838          12 :                     n->subtype = AT_DisableTrigUser;
    2839          12 :                     $$ = (Node *) n;
    2840             :                 }
    2841             :             /* ALTER TABLE <name> ENABLE RULE <rule> */
    2842             :             | ENABLE_P RULE name
    2843             :                 {
    2844           8 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2845             : 
    2846           8 :                     n->subtype = AT_EnableRule;
    2847           8 :                     n->name = $3;
    2848           8 :                     $$ = (Node *) n;
    2849             :                 }
    2850             :             /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
    2851             :             | ENABLE_P ALWAYS RULE name
    2852             :                 {
    2853           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2854             : 
    2855           0 :                     n->subtype = AT_EnableAlwaysRule;
    2856           0 :                     n->name = $4;
    2857           0 :                     $$ = (Node *) n;
    2858             :                 }
    2859             :             /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
    2860             :             | ENABLE_P REPLICA RULE name
    2861             :                 {
    2862           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2863             : 
    2864           6 :                     n->subtype = AT_EnableReplicaRule;
    2865           6 :                     n->name = $4;
    2866           6 :                     $$ = (Node *) n;
    2867             :                 }
    2868             :             /* ALTER TABLE <name> DISABLE RULE <rule> */
    2869             :             | DISABLE_P RULE name
    2870             :                 {
    2871          38 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2872             : 
    2873          38 :                     n->subtype = AT_DisableRule;
    2874          38 :                     n->name = $3;
    2875          38 :                     $$ = (Node *) n;
    2876             :                 }
    2877             :             /* ALTER TABLE <name> INHERIT <parent> */
    2878             :             | INHERIT qualified_name
    2879             :                 {
    2880         444 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2881             : 
    2882         444 :                     n->subtype = AT_AddInherit;
    2883         444 :                     n->def = (Node *) $2;
    2884         444 :                     $$ = (Node *) n;
    2885             :                 }
    2886             :             /* ALTER TABLE <name> NO INHERIT <parent> */
    2887             :             | NO INHERIT qualified_name
    2888             :                 {
    2889          86 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2890             : 
    2891          86 :                     n->subtype = AT_DropInherit;
    2892          86 :                     n->def = (Node *) $3;
    2893          86 :                     $$ = (Node *) n;
    2894             :                 }
    2895             :             /* ALTER TABLE <name> OF <type_name> */
    2896             :             | OF any_name
    2897             :                 {
    2898          66 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2899          66 :                     TypeName   *def = makeTypeNameFromNameList($2);
    2900             : 
    2901          66 :                     def->location = @2;
    2902          66 :                     n->subtype = AT_AddOf;
    2903          66 :                     n->def = (Node *) def;
    2904          66 :                     $$ = (Node *) n;
    2905             :                 }
    2906             :             /* ALTER TABLE <name> NOT OF */
    2907             :             | NOT OF
    2908             :                 {
    2909           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2910             : 
    2911           6 :                     n->subtype = AT_DropOf;
    2912           6 :                     $$ = (Node *) n;
    2913             :                 }
    2914             :             /* ALTER TABLE <name> OWNER TO RoleSpec */
    2915             :             | OWNER TO RoleSpec
    2916             :                 {
    2917        3610 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2918             : 
    2919        3610 :                     n->subtype = AT_ChangeOwner;
    2920        3610 :                     n->newowner = $3;
    2921        3610 :                     $$ = (Node *) n;
    2922             :                 }
    2923             :             /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
    2924             :             | SET ACCESS METHOD set_access_method_name
    2925             :                 {
    2926         128 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2927             : 
    2928         128 :                     n->subtype = AT_SetAccessMethod;
    2929         128 :                     n->name = $4;
    2930         128 :                     $$ = (Node *) n;
    2931             :                 }
    2932             :             /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
    2933             :             | SET TABLESPACE name
    2934             :                 {
    2935         104 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2936             : 
    2937         104 :                     n->subtype = AT_SetTableSpace;
    2938         104 :                     n->name = $3;
    2939         104 :                     $$ = (Node *) n;
    2940             :                 }
    2941             :             /* ALTER TABLE <name> SET (...) */
    2942             :             | SET reloptions
    2943             :                 {
    2944         594 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2945             : 
    2946         594 :                     n->subtype = AT_SetRelOptions;
    2947         594 :                     n->def = (Node *) $2;
    2948         594 :                     $$ = (Node *) n;
    2949             :                 }
    2950             :             /* ALTER TABLE <name> RESET (...) */
    2951             :             | RESET reloptions
    2952             :                 {
    2953         170 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2954             : 
    2955         170 :                     n->subtype = AT_ResetRelOptions;
    2956         170 :                     n->def = (Node *) $2;
    2957         170 :                     $$ = (Node *) n;
    2958             :                 }
    2959             :             /* ALTER TABLE <name> REPLICA IDENTITY */
    2960             :             | REPLICA IDENTITY_P replica_identity
    2961             :                 {
    2962         490 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2963             : 
    2964         490 :                     n->subtype = AT_ReplicaIdentity;
    2965         490 :                     n->def = $3;
    2966         490 :                     $$ = (Node *) n;
    2967             :                 }
    2968             :             /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
    2969             :             | ENABLE_P ROW LEVEL SECURITY
    2970             :                 {
    2971         308 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2972             : 
    2973         308 :                     n->subtype = AT_EnableRowSecurity;
    2974         308 :                     $$ = (Node *) n;
    2975             :                 }
    2976             :             /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
    2977             :             | DISABLE_P ROW LEVEL SECURITY
    2978             :                 {
    2979          10 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2980             : 
    2981          10 :                     n->subtype = AT_DisableRowSecurity;
    2982          10 :                     $$ = (Node *) n;
    2983             :                 }
    2984             :             /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
    2985             :             | FORCE ROW LEVEL SECURITY
    2986             :                 {
    2987         102 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2988             : 
    2989         102 :                     n->subtype = AT_ForceRowSecurity;
    2990         102 :                     $$ = (Node *) n;
    2991             :                 }
    2992             :             /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
    2993             :             | NO FORCE ROW LEVEL SECURITY
    2994             :                 {
    2995          32 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2996             : 
    2997          32 :                     n->subtype = AT_NoForceRowSecurity;
    2998          32 :                     $$ = (Node *) n;
    2999             :                 }
    3000             :             | alter_generic_options
    3001             :                 {
    3002          64 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3003             : 
    3004          64 :                     n->subtype = AT_GenericOptions;
    3005          64 :                     n->def = (Node *) $1;
    3006          64 :                     $$ = (Node *) n;
    3007             :                 }
    3008             :         ;
    3009             : 
    3010             : alter_column_default:
    3011         406 :             SET DEFAULT a_expr          { $$ = $3; }
    3012         186 :             | DROP DEFAULT              { $$ = NULL; }
    3013             :         ;
    3014             : 
    3015             : opt_collate_clause:
    3016             :             COLLATE any_name
    3017             :                 {
    3018          18 :                     CollateClause *n = makeNode(CollateClause);
    3019             : 
    3020          18 :                     n->arg = NULL;
    3021          18 :                     n->collname = $2;
    3022          18 :                     n->location = @1;
    3023          18 :                     $$ = (Node *) n;
    3024             :                 }
    3025        4808 :             | /* EMPTY */               { $$ = NULL; }
    3026             :         ;
    3027             : 
    3028             : alter_using:
    3029         180 :             USING a_expr                { $$ = $2; }
    3030         844 :             | /* EMPTY */               { $$ = NULL; }
    3031             :         ;
    3032             : 
    3033             : replica_identity:
    3034             :             NOTHING
    3035             :                 {
    3036          48 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3037             : 
    3038          48 :                     n->identity_type = REPLICA_IDENTITY_NOTHING;
    3039          48 :                     n->name = NULL;
    3040          48 :                     $$ = (Node *) n;
    3041             :                 }
    3042             :             | FULL
    3043             :                 {
    3044         166 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3045             : 
    3046         166 :                     n->identity_type = REPLICA_IDENTITY_FULL;
    3047         166 :                     n->name = NULL;
    3048         166 :                     $$ = (Node *) n;
    3049             :                 }
    3050             :             | DEFAULT
    3051             :                 {
    3052           6 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3053             : 
    3054           6 :                     n->identity_type = REPLICA_IDENTITY_DEFAULT;
    3055           6 :                     n->name = NULL;
    3056           6 :                     $$ = (Node *) n;
    3057             :                 }
    3058             :             | USING INDEX name
    3059             :                 {
    3060         270 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3061             : 
    3062         270 :                     n->identity_type = REPLICA_IDENTITY_INDEX;
    3063         270 :                     n->name = $3;
    3064         270 :                     $$ = (Node *) n;
    3065             :                 }
    3066             : ;
    3067             : 
    3068             : reloptions:
    3069        2794 :             '(' reloption_list ')'                  { $$ = $2; }
    3070             :         ;
    3071             : 
    3072        1022 : opt_reloptions:     WITH reloptions                 { $$ = $2; }
    3073       23858 :              |      /* EMPTY */                     { $$ = NIL; }
    3074             :         ;
    3075             : 
    3076             : reloption_list:
    3077        2794 :             reloption_elem                          { $$ = list_make1($1); }
    3078         266 :             | reloption_list ',' reloption_elem     { $$ = lappend($1, $3); }
    3079             :         ;
    3080             : 
    3081             : /* This should match def_elem and also allow qualified names */
    3082             : reloption_elem:
    3083             :             ColLabel '=' def_arg
    3084             :                 {
    3085        2390 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    3086             :                 }
    3087             :             | ColLabel
    3088             :                 {
    3089         590 :                     $$ = makeDefElem($1, NULL, @1);
    3090             :                 }
    3091             :             | ColLabel '.' ColLabel '=' def_arg
    3092             :                 {
    3093          74 :                     $$ = makeDefElemExtended($1, $3, (Node *) $5,
    3094          74 :                                              DEFELEM_UNSPEC, @1);
    3095             :                 }
    3096             :             | ColLabel '.' ColLabel
    3097             :                 {
    3098           6 :                     $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC, @1);
    3099             :                 }
    3100             :         ;
    3101             : 
    3102             : alter_identity_column_option_list:
    3103             :             alter_identity_column_option
    3104          62 :                 { $$ = list_make1($1); }
    3105             :             | alter_identity_column_option_list alter_identity_column_option
    3106          60 :                 { $$ = lappend($1, $2); }
    3107             :         ;
    3108             : 
    3109             : alter_identity_column_option:
    3110             :             RESTART
    3111             :                 {
    3112          24 :                     $$ = makeDefElem("restart", NULL, @1);
    3113             :                 }
    3114             :             | RESTART opt_with NumericOnly
    3115             :                 {
    3116           0 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    3117             :                 }
    3118             :             | SET SeqOptElem
    3119             :                 {
    3120          54 :                     if (strcmp($2->defname, "as") == 0 ||
    3121          54 :                         strcmp($2->defname, "restart") == 0 ||
    3122          54 :                         strcmp($2->defname, "owned_by") == 0)
    3123           0 :                         ereport(ERROR,
    3124             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3125             :                                  errmsg("sequence option \"%s\" not supported here", $2->defname),
    3126             :                                  parser_errposition(@2)));
    3127          54 :                     $$ = $2;
    3128             :                 }
    3129             :             | SET GENERATED generated_when
    3130             :                 {
    3131          44 :                     $$ = makeDefElem("generated", (Node *) makeInteger($3), @1);
    3132             :                 }
    3133             :         ;
    3134             : 
    3135             : set_statistics_value:
    3136         158 :             SignedIconst                    { $$ = (Node *) makeInteger($1); }
    3137           0 :             | DEFAULT                       { $$ = NULL; }
    3138             :         ;
    3139             : 
    3140             : set_access_method_name:
    3141          92 :             ColId                           { $$ = $1; }
    3142          36 :             | DEFAULT                       { $$ = NULL; }
    3143             :         ;
    3144             : 
    3145             : PartitionBoundSpec:
    3146             :             /* a HASH partition */
    3147             :             FOR VALUES WITH '(' hash_partbound ')'
    3148             :                 {
    3149             :                     ListCell   *lc;
    3150         738 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3151             : 
    3152         738 :                     n->strategy = PARTITION_STRATEGY_HASH;
    3153         738 :                     n->modulus = n->remainder = -1;
    3154             : 
    3155        2214 :                     foreach (lc, $5)
    3156             :                     {
    3157        1476 :                         DefElem    *opt = lfirst_node(DefElem, lc);
    3158             : 
    3159        1476 :                         if (strcmp(opt->defname, "modulus") == 0)
    3160             :                         {
    3161         738 :                             if (n->modulus != -1)
    3162           0 :                                 ereport(ERROR,
    3163             :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    3164             :                                          errmsg("modulus for hash partition provided more than once"),
    3165             :                                          parser_errposition(opt->location)));
    3166         738 :                             n->modulus = defGetInt32(opt);
    3167             :                         }
    3168         738 :                         else if (strcmp(opt->defname, "remainder") == 0)
    3169             :                         {
    3170         738 :                             if (n->remainder != -1)
    3171           0 :                                 ereport(ERROR,
    3172             :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    3173             :                                          errmsg("remainder for hash partition provided more than once"),
    3174             :                                          parser_errposition(opt->location)));
    3175         738 :                             n->remainder = defGetInt32(opt);
    3176             :                         }
    3177             :                         else
    3178           0 :                             ereport(ERROR,
    3179             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    3180             :                                      errmsg("unrecognized hash partition bound specification \"%s\"",
    3181             :                                             opt->defname),
    3182             :                                      parser_errposition(opt->location)));
    3183             :                     }
    3184             : 
    3185         738 :                     if (n->modulus == -1)
    3186           0 :                         ereport(ERROR,
    3187             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3188             :                                  errmsg("modulus for hash partition must be specified"),
    3189             :                                  parser_errposition(@3)));
    3190         738 :                     if (n->remainder == -1)
    3191           0 :                         ereport(ERROR,
    3192             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3193             :                                  errmsg("remainder for hash partition must be specified"),
    3194             :                                  parser_errposition(@3)));
    3195             : 
    3196         738 :                     n->location = @3;
    3197             : 
    3198         738 :                     $$ = n;
    3199             :                 }
    3200             : 
    3201             :             /* a LIST partition */
    3202             :             | FOR VALUES IN_P '(' expr_list ')'
    3203             :                 {
    3204        5068 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3205             : 
    3206        5068 :                     n->strategy = PARTITION_STRATEGY_LIST;
    3207        5068 :                     n->is_default = false;
    3208        5068 :                     n->listdatums = $5;
    3209        5068 :                     n->location = @3;
    3210             : 
    3211        5068 :                     $$ = n;
    3212             :                 }
    3213             : 
    3214             :             /* a RANGE partition */
    3215             :             | FOR VALUES FROM '(' expr_list ')' TO '(' expr_list ')'
    3216             :                 {
    3217        4380 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3218             : 
    3219        4380 :                     n->strategy = PARTITION_STRATEGY_RANGE;
    3220        4380 :                     n->is_default = false;
    3221        4380 :                     n->lowerdatums = $5;
    3222        4380 :                     n->upperdatums = $9;
    3223        4380 :                     n->location = @3;
    3224             : 
    3225        4380 :                     $$ = n;
    3226             :                 }
    3227             : 
    3228             :             /* a DEFAULT partition */
    3229             :             | DEFAULT
    3230             :                 {
    3231         622 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3232             : 
    3233         622 :                     n->is_default = true;
    3234         622 :                     n->location = @1;
    3235             : 
    3236         622 :                     $$ = n;
    3237             :                 }
    3238             :         ;
    3239             : 
    3240             : hash_partbound_elem:
    3241             :         NonReservedWord Iconst
    3242             :             {
    3243        1476 :                 $$ = makeDefElem($1, (Node *) makeInteger($2), @1);
    3244             :             }
    3245             :         ;
    3246             : 
    3247             : hash_partbound:
    3248             :         hash_partbound_elem
    3249             :             {
    3250         738 :                 $$ = list_make1($1);
    3251             :             }
    3252             :         | hash_partbound ',' hash_partbound_elem
    3253             :             {
    3254         738 :                 $$ = lappend($1, $3);
    3255             :             }
    3256             :         ;
    3257             : 
    3258             : /*****************************************************************************
    3259             :  *
    3260             :  *  ALTER TYPE
    3261             :  *
    3262             :  * really variants of the ALTER TABLE subcommands with different spellings
    3263             :  *****************************************************************************/
    3264             : 
    3265             : AlterCompositeTypeStmt:
    3266             :             ALTER TYPE_P any_name alter_type_cmds
    3267             :                 {
    3268         210 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    3269             : 
    3270             :                     /* can't use qualified_name, sigh */
    3271         210 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
    3272         210 :                     n->cmds = $4;
    3273         210 :                     n->objtype = OBJECT_TYPE;
    3274         210 :                     $$ = (Node *) n;
    3275             :                 }
    3276             :             ;
    3277             : 
    3278             : alter_type_cmds:
    3279         210 :             alter_type_cmd                          { $$ = list_make1($1); }
    3280          12 :             | alter_type_cmds ',' alter_type_cmd    { $$ = lappend($1, $3); }
    3281             :         ;
    3282             : 
    3283             : alter_type_cmd:
    3284             :             /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
    3285             :             ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
    3286             :                 {
    3287          64 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3288             : 
    3289          64 :                     n->subtype = AT_AddColumn;
    3290          64 :                     n->def = $3;
    3291          64 :                     n->behavior = $4;
    3292          64 :                     $$ = (Node *) n;
    3293             :                 }
    3294             :             /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
    3295             :             | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
    3296             :                 {
    3297           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3298             : 
    3299           6 :                     n->subtype = AT_DropColumn;
    3300           6 :                     n->name = $5;
    3301           6 :                     n->behavior = $6;
    3302           6 :                     n->missing_ok = true;
    3303           6 :                     $$ = (Node *) n;
    3304             :                 }
    3305             :             /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
    3306             :             | DROP ATTRIBUTE ColId opt_drop_behavior
    3307             :                 {
    3308          78 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3309             : 
    3310          78 :                     n->subtype = AT_DropColumn;
    3311          78 :                     n->name = $3;
    3312          78 :                     n->behavior = $4;
    3313          78 :                     n->missing_ok = false;
    3314          78 :                     $$ = (Node *) n;
    3315             :                 }
    3316             :             /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
    3317             :             | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
    3318             :                 {
    3319          74 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3320          74 :                     ColumnDef *def = makeNode(ColumnDef);
    3321             : 
    3322          74 :                     n->subtype = AT_AlterColumnType;
    3323          74 :                     n->name = $3;
    3324          74 :                     n->def = (Node *) def;
    3325          74 :                     n->behavior = $8;
    3326             :                     /* We only use these fields of the ColumnDef node */
    3327          74 :                     def->typeName = $6;
    3328          74 :                     def->collClause = (CollateClause *) $7;
    3329          74 :                     def->raw_default = NULL;
    3330          74 :                     def->location = @3;
    3331          74 :                     $$ = (Node *) n;
    3332             :                 }
    3333             :         ;
    3334             : 
    3335             : 
    3336             : /*****************************************************************************
    3337             :  *
    3338             :  *      QUERY :
    3339             :  *              close <portalname>
    3340             :  *
    3341             :  *****************************************************************************/
    3342             : 
    3343             : ClosePortalStmt:
    3344             :             CLOSE cursor_name
    3345             :                 {
    3346        2210 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3347             : 
    3348        2210 :                     n->portalname = $2;
    3349        2210 :                     $$ = (Node *) n;
    3350             :                 }
    3351             :             | CLOSE ALL
    3352             :                 {
    3353          12 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3354             : 
    3355          12 :                     n->portalname = NULL;
    3356          12 :                     $$ = (Node *) n;
    3357             :                 }
    3358             :         ;
    3359             : 
    3360             : 
    3361             : /*****************************************************************************
    3362             :  *
    3363             :  *      QUERY :
    3364             :  *              COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
    3365             :  *              COPY ( query ) TO file  [WITH] [(options)]
    3366             :  *
    3367             :  *              where 'query' can be one of:
    3368             :  *              { SELECT | UPDATE | INSERT | DELETE }
    3369             :  *
    3370             :  *              and 'file' can be one of:
    3371             :  *              { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
    3372             :  *
    3373             :  *              In the preferred syntax the options are comma-separated
    3374             :  *              and use generic identifiers instead of keywords.  The pre-9.0
    3375             :  *              syntax had a hard-wired, space-separated set of options.
    3376             :  *
    3377             :  *              Really old syntax, from versions 7.2 and prior:
    3378             :  *              COPY [ BINARY ] table FROM/TO file
    3379             :  *                  [ [ USING ] DELIMITERS 'delimiter' ] ]
    3380             :  *                  [ WITH NULL AS 'null string' ]
    3381             :  *              This option placement is not supported with COPY (query...).
    3382             :  *
    3383             :  *****************************************************************************/
    3384             : 
    3385             : CopyStmt:   COPY opt_binary qualified_name opt_column_list
    3386             :             copy_from opt_program copy_file_name copy_delimiter opt_with
    3387             :             copy_options where_clause
    3388             :                 {
    3389       15934 :                     CopyStmt *n = makeNode(CopyStmt);
    3390             : 
    3391       15934 :                     n->relation = $3;
    3392       15934 :                     n->query = NULL;
    3393       15934 :                     n->attlist = $4;
    3394       15934 :                     n->is_from = $5;
    3395       15934 :                     n->is_program = $6;
    3396       15934 :                     n->filename = $7;
    3397       15934 :                     n->whereClause = $11;
    3398             : 
    3399       15934 :                     if (n->is_program && n->filename == NULL)
    3400           0 :                         ereport(ERROR,
    3401             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3402             :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3403             :                                  parser_errposition(@8)));
    3404             : 
    3405       15934 :                     if (!n->is_from && n->whereClause != NULL)
    3406           6 :                         ereport(ERROR,
    3407             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3408             :                                  errmsg("WHERE clause not allowed with COPY TO"),
    3409             :                                  parser_errposition(@11)));
    3410             : 
    3411       15928 :                     n->options = NIL;
    3412             :                     /* Concatenate user-supplied flags */
    3413       15928 :                     if ($2)
    3414          12 :                         n->options = lappend(n->options, $2);
    3415       15928 :                     if ($8)
    3416           0 :                         n->options = lappend(n->options, $8);
    3417       15928 :                     if ($10)
    3418         968 :                         n->options = list_concat(n->options, $10);
    3419       15928 :                     $$ = (Node *) n;
    3420             :                 }
    3421             :             | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
    3422             :                 {
    3423         464 :                     CopyStmt *n = makeNode(CopyStmt);
    3424             : 
    3425         464 :                     n->relation = NULL;
    3426         464 :                     n->query = $3;
    3427         464 :                     n->attlist = NIL;
    3428         464 :                     n->is_from = false;
    3429         464 :                     n->is_program = $6;
    3430         464 :                     n->filename = $7;
    3431         464 :                     n->options = $9;
    3432             : 
    3433         464 :                     if (n->is_program && n->filename == NULL)
    3434           0 :                         ereport(ERROR,
    3435             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3436             :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3437             :                                  parser_errposition(@5)));
    3438             : 
    3439         464 :                     $$ = (Node *) n;
    3440             :                 }
    3441             :         ;
    3442             : 
    3443             : copy_from:
    3444        3004 :             FROM                                    { $$ = true; }
    3445       12930 :             | TO                                    { $$ = false; }
    3446             :         ;
    3447             : 
    3448             : opt_program:
    3449           0 :             PROGRAM                                 { $$ = true; }
    3450       16398 :             | /* EMPTY */                           { $$ = false; }
    3451             :         ;
    3452             : 
    3453             : /*
    3454             :  * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
    3455             :  * used depends on the direction. (It really doesn't make sense to copy from
    3456             :  * stdout. We silently correct the "typo".)        - AY 9/94
    3457             :  */
    3458             : copy_file_name:
    3459         454 :             Sconst                                  { $$ = $1; }
    3460        2614 :             | STDIN                                 { $$ = NULL; }
    3461       13330 :             | STDOUT                                { $$ = NULL; }
    3462             :         ;
    3463             : 
    3464       15700 : copy_options: copy_opt_list                         { $$ = $1; }
    3465         698 :             | '(' copy_generic_opt_list ')'         { $$ = $2; }
    3466             :         ;
    3467             : 
    3468             : /* old COPY option syntax */
    3469             : copy_opt_list:
    3470         504 :             copy_opt_list copy_opt_item             { $$ = lappend($1, $2); }
    3471       15700 :             | /* EMPTY */                           { $$ = NIL; }
    3472             :         ;
    3473             : 
    3474             : copy_opt_item:
    3475             :             BINARY
    3476             :                 {
    3477           0 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3478             :                 }
    3479             :             | FREEZE
    3480             :                 {
    3481          50 :                     $$ = makeDefElem("freeze", (Node *) makeBoolean(true), @1);
    3482             :                 }
    3483             :             | DELIMITER opt_as Sconst
    3484             :                 {
    3485         172 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @1);
    3486             :                 }
    3487             :             | NULL_P opt_as Sconst
    3488             :                 {
    3489          48 :                     $$ = makeDefElem("null", (Node *) makeString($3), @1);
    3490             :                 }
    3491             :             | CSV
    3492             :                 {
    3493         150 :                     $$ = makeDefElem("format", (Node *) makeString("csv"), @1);
    3494             :                 }
    3495             :             | HEADER_P
    3496             :                 {
    3497          18 :                     $$ = makeDefElem("header", (Node *) makeBoolean(true), @1);
    3498             :                 }
    3499             :             | QUOTE opt_as Sconst
    3500             :                 {
    3501          18 :                     $$ = makeDefElem("quote", (Node *) makeString($3), @1);
    3502             :                 }
    3503             :             | ESCAPE opt_as Sconst
    3504             :                 {
    3505          18 :                     $$ = makeDefElem("escape", (Node *) makeString($3), @1);
    3506             :                 }
    3507             :             | FORCE QUOTE columnList
    3508             :                 {
    3509          12 :                     $$ = makeDefElem("force_quote", (Node *) $3, @1);
    3510             :                 }
    3511             :             | FORCE QUOTE '*'
    3512             :                 {
    3513           6 :                     $$ = makeDefElem("force_quote", (Node *) makeNode(A_Star), @1);
    3514             :                 }
    3515             :             | FORCE NOT NULL_P columnList
    3516             :                 {
    3517           0 :                     $$ = makeDefElem("force_not_null", (Node *) $4, @1);
    3518             :                 }
    3519             :             | FORCE NOT NULL_P '*'
    3520             :                 {
    3521           0 :                     $$ = makeDefElem("force_not_null", (Node *) makeNode(A_Star), @1);
    3522             :                 }
    3523             :             | FORCE NULL_P columnList
    3524             :                 {
    3525           0 :                     $$ = makeDefElem("force_null", (Node *) $3, @1);
    3526             :                 }
    3527             :             | FORCE NULL_P '*'
    3528             :                 {
    3529           0 :                     $$ = makeDefElem("force_null", (Node *) makeNode(A_Star), @1);
    3530             :                 }
    3531             :             | ENCODING Sconst
    3532             :                 {
    3533          12 :                     $$ = makeDefElem("encoding", (Node *) makeString($2), @1);
    3534             :                 }
    3535             :         ;
    3536             : 
    3537             : /* The following exist for backward compatibility with very old versions */
    3538             : 
    3539             : opt_binary:
    3540             :             BINARY
    3541             :                 {
    3542          12 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3543             :                 }
    3544       15922 :             | /*EMPTY*/                             { $$ = NULL; }
    3545             :         ;
    3546             : 
    3547             : copy_delimiter:
    3548             :             opt_using DELIMITERS Sconst
    3549             :                 {
    3550           0 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @2);
    3551             :                 }
    3552       15934 :             | /*EMPTY*/                             { $$ = NULL; }
    3553             :         ;
    3554             : 
    3555             : opt_using:
    3556             :             USING
    3557             :             | /*EMPTY*/
    3558             :         ;
    3559             : 
    3560             : /* new COPY option syntax */
    3561             : copy_generic_opt_list:
    3562             :             copy_generic_opt_elem
    3563             :                 {
    3564         698 :                     $$ = list_make1($1);
    3565             :                 }
    3566             :             | copy_generic_opt_list ',' copy_generic_opt_elem
    3567             :                 {
    3568         468 :                     $$ = lappend($1, $3);
    3569             :                 }
    3570             :         ;
    3571             : 
    3572             : copy_generic_opt_elem:
    3573             :             ColLabel copy_generic_opt_arg
    3574             :                 {
    3575        1166 :                     $$ = makeDefElem($1, $2, @1);
    3576             :                 }
    3577             :         ;
    3578             : 
    3579             : copy_generic_opt_arg:
    3580         818 :             opt_boolean_or_string           { $$ = (Node *) makeString($1); }
    3581          60 :             | NumericOnly                   { $$ = (Node *) $1; }
    3582          90 :             | '*'                           { $$ = (Node *) makeNode(A_Star); }
    3583           6 :             | DEFAULT                       { $$ = (Node *) makeString("default"); }
    3584         150 :             | '(' copy_generic_opt_arg_list ')'     { $$ = (Node *) $2; }
    3585          42 :             | /* EMPTY */                   { $$ = NULL; }
    3586             :         ;
    3587             : 
    3588             : copy_generic_opt_arg_list:
    3589             :               copy_generic_opt_arg_list_item
    3590             :                 {
    3591         150 :                     $$ = list_make1($1);
    3592             :                 }
    3593             :             | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
    3594             :                 {
    3595          12 :                     $$ = lappend($1, $3);
    3596             :                 }
    3597             :         ;
    3598             : 
    3599             : /* beware of emitting non-string list elements here; see commands/define.c */
    3600             : copy_generic_opt_arg_list_item:
    3601         162 :             opt_boolean_or_string   { $$ = (Node *) makeString($1); }
    3602             :         ;
    3603             : 
    3604             : 
    3605             : /*****************************************************************************
    3606             :  *
    3607             :  *      QUERY :
    3608             :  *              CREATE TABLE relname
    3609             :  *
    3610             :  *****************************************************************************/
    3611             : 
    3612             : CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
    3613             :             OptInherit OptPartitionSpec table_access_method_clause OptWith
    3614             :             OnCommitOption OptTableSpace
    3615             :                 {
    3616       30816 :                     CreateStmt *n = makeNode(CreateStmt);
    3617             : 
    3618       30816 :                     $4->relpersistence = $2;
    3619       30816 :                     n->relation = $4;
    3620       30816 :                     n->tableElts = $6;
    3621       30816 :                     n->inhRelations = $8;
    3622       30816 :                     n->partspec = $9;
    3623       30816 :                     n->ofTypename = NULL;
    3624       30816 :                     n->constraints = NIL;
    3625       30816 :                     n->accessMethod = $10;
    3626       30816 :                     n->options = $11;
    3627       30816 :                     n->oncommit = $12;
    3628       30816 :                     n->tablespacename = $13;
    3629       30816 :                     n->if_not_exists = false;
    3630       30816 :                     $$ = (Node *) n;
    3631             :                 }
    3632             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
    3633             :             OptTableElementList ')' OptInherit OptPartitionSpec table_access_method_clause
    3634             :             OptWith OnCommitOption OptTableSpace
    3635             :                 {
    3636          30 :                     CreateStmt *n = makeNode(CreateStmt);
    3637             : 
    3638          30 :                     $7->relpersistence = $2;
    3639          30 :                     n->relation = $7;
    3640          30 :                     n->tableElts = $9;
    3641          30 :                     n->inhRelations = $11;
    3642          30 :                     n->partspec = $12;
    3643          30 :                     n->ofTypename = NULL;
    3644          30 :                     n->constraints = NIL;
    3645          30 :                     n->accessMethod = $13;
    3646          30 :                     n->options = $14;
    3647          30 :                     n->oncommit = $15;
    3648          30 :                     n->tablespacename = $16;
    3649          30 :                     n->if_not_exists = true;
    3650          30 :                     $$ = (Node *) n;
    3651             :                 }
    3652             :         | CREATE OptTemp TABLE qualified_name OF any_name
    3653             :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3654             :             OptWith OnCommitOption OptTableSpace
    3655             :                 {
    3656         134 :                     CreateStmt *n = makeNode(CreateStmt);
    3657             : 
    3658         134 :                     $4->relpersistence = $2;
    3659         134 :                     n->relation = $4;
    3660         134 :                     n->tableElts = $7;
    3661         134 :                     n->inhRelations = NIL;
    3662         134 :                     n->partspec = $8;
    3663         134 :                     n->ofTypename = makeTypeNameFromNameList($6);
    3664         134 :                     n->ofTypename->location = @6;
    3665         134 :                     n->constraints = NIL;
    3666         134 :                     n->accessMethod = $9;
    3667         134 :                     n->options = $10;
    3668         134 :                     n->oncommit = $11;
    3669         134 :                     n->tablespacename = $12;
    3670         134 :                     n->if_not_exists = false;
    3671         134 :                     $$ = (Node *) n;
    3672             :                 }
    3673             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
    3674             :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3675             :             OptWith OnCommitOption OptTableSpace
    3676             :                 {
    3677           6 :                     CreateStmt *n = makeNode(CreateStmt);
    3678             : 
    3679           6 :                     $7->relpersistence = $2;
    3680           6 :                     n->relation = $7;
    3681           6 :                     n->tableElts = $10;
    3682           6 :                     n->inhRelations = NIL;
    3683           6 :                     n->partspec = $11;
    3684           6 :                     n->ofTypename = makeTypeNameFromNameList($9);
    3685           6 :                     n->ofTypename->location = @9;
    3686           6 :                     n->constraints = NIL;
    3687           6 :                     n->accessMethod = $12;
    3688           6 :                     n->options = $13;
    3689           6 :                     n->oncommit = $14;
    3690           6 :                     n->tablespacename = $15;
    3691           6 :                     n->if_not_exists = true;
    3692           6 :                     $$ = (Node *) n;
    3693             :                 }
    3694             :         | CREATE OptTemp TABLE qualified_name PARTITION OF qualified_name
    3695             :             OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3696             :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3697             :                 {
    3698        7886 :                     CreateStmt *n = makeNode(CreateStmt);
    3699             : 
    3700        7886 :                     $4->relpersistence = $2;
    3701        7886 :                     n->relation = $4;
    3702        7886 :                     n->tableElts = $8;
    3703        7886 :                     n->inhRelations = list_make1($7);
    3704        7886 :                     n->partbound = $9;
    3705        7886 :                     n->partspec = $10;
    3706        7886 :                     n->ofTypename = NULL;
    3707        7886 :                     n->constraints = NIL;
    3708        7886 :                     n->accessMethod = $11;
    3709        7886 :                     n->options = $12;
    3710        7886 :                     n->oncommit = $13;
    3711        7886 :                     n->tablespacename = $14;
    3712        7886 :                     n->if_not_exists = false;
    3713        7886 :                     $$ = (Node *) n;
    3714             :                 }
    3715             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name PARTITION OF
    3716             :             qualified_name OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3717             :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3718             :                 {
    3719           0 :                     CreateStmt *n = makeNode(CreateStmt);
    3720             : 
    3721           0 :                     $7->relpersistence = $2;
    3722           0 :                     n->relation = $7;
    3723           0 :                     n->tableElts = $11;
    3724           0 :                     n->inhRelations = list_make1($10);
    3725           0 :                     n->partbound = $12;
    3726           0 :                     n->partspec = $13;
    3727           0 :                     n->ofTypename = NULL;
    3728           0 :                     n->constraints = NIL;
    3729           0 :                     n->accessMethod = $14;
    3730           0 :                     n->options = $15;
    3731           0 :                     n->oncommit = $16;
    3732           0 :                     n->tablespacename = $17;
    3733           0 :                     n->if_not_exists = true;
    3734           0 :                     $$ = (Node *) n;
    3735             :                 }
    3736             :         ;
    3737             : 
    3738             : /*
    3739             :  * Redundancy here is needed to avoid shift/reduce conflicts,
    3740             :  * since TEMP is not a reserved word.  See also OptTempTableName.
    3741             :  *
    3742             :  * NOTE: we accept both GLOBAL and LOCAL options.  They currently do nothing,
    3743             :  * but future versions might consider GLOBAL to request SQL-spec-compliant
    3744             :  * temp table behavior, so warn about that.  Since we have no modules the
    3745             :  * LOCAL keyword is really meaningless; furthermore, some other products
    3746             :  * implement LOCAL as meaning the same as our default temp table behavior,
    3747             :  * so we'll probably continue to treat LOCAL as a noise word.
    3748             :  */
    3749         336 : OptTemp:    TEMPORARY                   { $$ = RELPERSISTENCE_TEMP; }
    3750        2732 :             | TEMP                      { $$ = RELPERSISTENCE_TEMP; }
    3751           0 :             | LOCAL TEMPORARY           { $$ = RELPERSISTENCE_TEMP; }
    3752           0 :             | LOCAL TEMP                { $$ = RELPERSISTENCE_TEMP; }
    3753             :             | GLOBAL TEMPORARY
    3754             :                 {
    3755           0 :                     ereport(WARNING,
    3756             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3757             :                              parser_errposition(@1)));
    3758           0 :                     $$ = RELPERSISTENCE_TEMP;
    3759             :                 }
    3760             :             | GLOBAL TEMP
    3761             :                 {
    3762           0 :                     ereport(WARNING,
    3763             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3764             :                              parser_errposition(@1)));
    3765           0 :                     $$ = RELPERSISTENCE_TEMP;
    3766             :                 }
    3767         170 :             | UNLOGGED                  { $$ = RELPERSISTENCE_UNLOGGED; }
    3768       55078 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    3769             :         ;
    3770             : 
    3771             : OptTableElementList:
    3772       29636 :             TableElementList                    { $$ = $1; }
    3773        1646 :             | /*EMPTY*/                         { $$ = NIL; }
    3774             :         ;
    3775             : 
    3776             : OptTypedTableElementList:
    3777         354 :             '(' TypedTableElementList ')'       { $$ = $2; }
    3778        7768 :             | /*EMPTY*/                         { $$ = NIL; }
    3779             :         ;
    3780             : 
    3781             : TableElementList:
    3782             :             TableElement
    3783             :                 {
    3784       29690 :                     $$ = list_make1($1);
    3785             :                 }
    3786             :             | TableElementList ',' TableElement
    3787             :                 {
    3788       44420 :                     $$ = lappend($1, $3);
    3789             :                 }
    3790             :         ;
    3791             : 
    3792             : TypedTableElementList:
    3793             :             TypedTableElement
    3794             :                 {
    3795         354 :                     $$ = list_make1($1);
    3796             :                 }
    3797             :             | TypedTableElementList ',' TypedTableElement
    3798             :                 {
    3799          70 :                     $$ = lappend($1, $3);
    3800             :                 }
    3801             :         ;
    3802             : 
    3803             : TableElement:
    3804       70580 :             columnDef                           { $$ = $1; }
    3805         774 :             | TableLikeClause                   { $$ = $1; }
    3806        2756 :             | TableConstraint                   { $$ = $1; }
    3807             :         ;
    3808             : 
    3809             : TypedTableElement:
    3810         354 :             columnOptions                       { $$ = $1; }
    3811          70 :             | TableConstraint                   { $$ = $1; }
    3812             :         ;
    3813             : 
    3814             : columnDef:  ColId Typename opt_column_storage opt_column_compression create_generic_options ColQualList
    3815             :                 {
    3816       72728 :                     ColumnDef *n = makeNode(ColumnDef);
    3817             : 
    3818       72728 :                     n->colname = $1;
    3819       72728 :                     n->typeName = $2;
    3820       72728 :                     n->storage_name = $3;
    3821       72728 :                     n->compression = $4;
    3822       72728 :                     n->inhcount = 0;
    3823       72728 :                     n->is_local = true;
    3824       72728 :                     n->is_not_null = false;
    3825       72728 :                     n->is_from_type = false;
    3826       72728 :                     n->storage = 0;
    3827       72728 :                     n->raw_default = NULL;
    3828       72728 :                     n->cooked_default = NULL;
    3829       72728 :                     n->collOid = InvalidOid;
    3830       72728 :                     n->fdwoptions = $5;
    3831       72728 :                     SplitColQualList($6, &n->constraints, &n->collClause,
    3832             :                                      yyscanner);
    3833       72728 :                     n->location = @1;
    3834       72728 :                     $$ = (Node *) n;
    3835             :                 }
    3836             :         ;
    3837             : 
    3838             : columnOptions:  ColId ColQualList
    3839             :                 {
    3840         146 :                     ColumnDef *n = makeNode(ColumnDef);
    3841             : 
    3842         146 :                     n->colname = $1;
    3843         146 :                     n->typeName = NULL;
    3844         146 :                     n->inhcount = 0;
    3845         146 :                     n->is_local = true;
    3846         146 :                     n->is_not_null = false;
    3847         146 :                     n->is_from_type = false;
    3848         146 :                     n->storage = 0;
    3849         146 :                     n->raw_default = NULL;
    3850         146 :                     n->cooked_default = NULL;
    3851         146 :                     n->collOid = InvalidOid;
    3852         146 :                     SplitColQualList($2, &n->constraints, &n->collClause,
    3853             :                                      yyscanner);
    3854         146 :                     n->location = @1;
    3855         146 :                     $$ = (Node *) n;
    3856             :                 }
    3857             :                 | ColId WITH OPTIONS ColQualList
    3858             :                 {
    3859         208 :                     ColumnDef *n = makeNode(ColumnDef);
    3860             : 
    3861         208 :                     n->colname = $1;
    3862         208 :                     n->typeName = NULL;
    3863         208 :                     n->inhcount = 0;
    3864         208 :                     n->is_local = true;
    3865         208 :                     n->is_not_null = false;
    3866         208 :                     n->is_from_type = false;
    3867         208 :                     n->storage = 0;
    3868         208 :                     n->raw_default = NULL;
    3869         208 :                     n->cooked_default = NULL;
    3870         208 :                     n->collOid = InvalidOid;
    3871         208 :                     SplitColQualList($4, &n->constraints, &n->collClause,
    3872             :                                      yyscanner);
    3873         208 :                     n->location = @1;
    3874         208 :                     $$ = (Node *) n;
    3875             :                 }
    3876             :         ;
    3877             : 
    3878             : column_compression:
    3879         166 :             COMPRESSION ColId                       { $$ = $2; }
    3880           6 :             | COMPRESSION DEFAULT                   { $$ = pstrdup("default"); }
    3881             :         ;
    3882             : 
    3883             : opt_column_compression:
    3884          82 :             column_compression                      { $$ = $1; }
    3885       72712 :             | /*EMPTY*/                             { $$ = NULL; }
    3886             :         ;
    3887             : 
    3888             : column_storage:
    3889         238 :             STORAGE ColId                           { $$ = $2; }
    3890           6 :             | STORAGE DEFAULT                       { $$ = pstrdup("default"); }
    3891             :         ;
    3892             : 
    3893             : opt_column_storage:
    3894          20 :             column_storage                          { $$ = $1; }
    3895       72774 :             | /*EMPTY*/                             { $$ = NULL; }
    3896             :         ;
    3897             : 
    3898             : ColQualList:
    3899       20478 :             ColQualList ColConstraint               { $$ = lappend($1, $2); }
    3900       74648 :             | /*EMPTY*/                             { $$ = NIL; }
    3901             :         ;
    3902             : 
    3903             : ColConstraint:
    3904             :             CONSTRAINT name ColConstraintElem
    3905             :                 {
    3906         958 :                     Constraint *n = castNode(Constraint, $3);
    3907             : 
    3908         958 :                     n->conname = $2;
    3909         958 :                     n->location = @1;
    3910         958 :                     $$ = (Node *) n;
    3911             :                 }
    3912       18458 :             | ColConstraintElem                     { $$ = $1; }
    3913         294 :             | ConstraintAttr                        { $$ = $1; }
    3914             :             | COLLATE any_name
    3915             :                 {
    3916             :                     /*
    3917             :                      * Note: the CollateClause is momentarily included in
    3918             :                      * the list built by ColQualList, but we split it out
    3919             :                      * again in SplitColQualList.
    3920             :                      */
    3921         768 :                     CollateClause *n = makeNode(CollateClause);
    3922             : 
    3923         768 :                     n->arg = NULL;
    3924         768 :                     n->collname = $2;
    3925         768 :                     n->location = @1;
    3926         768 :                     $$ = (Node *) n;
    3927             :                 }
    3928             :         ;
    3929             : 
    3930             : /* DEFAULT NULL is already the default for Postgres.
    3931             :  * But define it here and carry it forward into the system
    3932             :  * to make it explicit.
    3933             :  * - thomas 1998-09-13
    3934             :  *
    3935             :  * WITH NULL and NULL are not SQL-standard syntax elements,
    3936             :  * so leave them out. Use DEFAULT NULL to explicitly indicate
    3937             :  * that a column may have that value. WITH NULL leads to
    3938             :  * shift/reduce conflicts with WITH TIME ZONE anyway.
    3939             :  * - thomas 1999-01-08
    3940             :  *
    3941             :  * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
    3942             :  * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
    3943             :  * or be part of a_expr NOT LIKE or similar constructs).
    3944             :  */
    3945             : ColConstraintElem:
    3946             :             NOT NULL_P opt_no_inherit
    3947             :                 {
    3948        7152 :                     Constraint *n = makeNode(Constraint);
    3949             : 
    3950        7152 :                     n->contype = CONSTR_NOTNULL;
    3951        7152 :                     n->location = @1;
    3952        7152 :                     n->is_no_inherit = $3;
    3953        7152 :                     n->is_enforced = true;
    3954        7152 :                     n->skip_validation = false;
    3955        7152 :                     n->initially_valid = true;
    3956        7152 :                     $$ = (Node *) n;
    3957             :                 }
    3958             :             | NULL_P
    3959             :                 {
    3960          30 :                     Constraint *n = makeNode(Constraint);
    3961             : 
    3962          30 :                     n->contype = CONSTR_NULL;
    3963          30 :                     n->location = @1;
    3964          30 :                     $$ = (Node *) n;
    3965             :                 }
    3966             :             | UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace
    3967             :                 {
    3968         446 :                     Constraint *n = makeNode(Constraint);
    3969             : 
    3970         446 :                     n->contype = CONSTR_UNIQUE;
    3971         446 :                     n->location = @1;
    3972         446 :                     n->nulls_not_distinct = !$2;
    3973         446 :                     n->keys = NULL;
    3974         446 :                     n->options = $3;
    3975         446 :                     n->indexname = NULL;
    3976         446 :                     n->indexspace = $4;
    3977         446 :                     $$ = (Node *) n;
    3978             :                 }
    3979             :             | PRIMARY KEY opt_definition OptConsTableSpace
    3980             :                 {
    3981        5772 :                     Constraint *n = makeNode(Constraint);
    3982             : 
    3983        5772 :                     n->contype = CONSTR_PRIMARY;
    3984        5772 :                     n->location = @1;
    3985        5772 :                     n->keys = NULL;
    3986        5772 :                     n->options = $3;
    3987        5772 :                     n->indexname = NULL;
    3988        5772 :                     n->indexspace = $4;
    3989        5772 :                     $$ = (Node *) n;
    3990             :                 }
    3991             :             | CHECK '(' a_expr ')' opt_no_inherit
    3992             :                 {
    3993        1118 :                     Constraint *n = makeNode(Constraint);
    3994             : 
    3995        1118 :                     n->contype = CONSTR_CHECK;
    3996        1118 :                     n->location = @1;
    3997        1118 :                     n->is_no_inherit = $5;
    3998        1118 :                     n->raw_expr = $3;
    3999        1118 :                     n->cooked_expr = NULL;
    4000        1118 :                     n->is_enforced = true;
    4001        1118 :                     n->skip_validation = false;
    4002        1118 :                     n->initially_valid = true;
    4003        1118 :                     $$ = (Node *) n;
    4004             :                 }
    4005             :             | DEFAULT b_expr
    4006             :                 {
    4007        1898 :                     Constraint *n = makeNode(Constraint);
    4008             : 
    4009        1898 :                     n->contype = CONSTR_DEFAULT;
    4010        1898 :                     n->location = @1;
    4011        1898 :                     n->raw_expr = $2;
    4012        1898 :                     n->cooked_expr = NULL;
    4013        1898 :                     $$ = (Node *) n;
    4014             :                 }
    4015             :             | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    4016             :                 {
    4017         332 :                     Constraint *n = makeNode(Constraint);
    4018             : 
    4019         332 :                     n->contype = CONSTR_IDENTITY;
    4020         332 :                     n->generated_when = $2;
    4021         332 :                     n->options = $5;
    4022         332 :                     n->location = @1;
    4023         332 :                     $$ = (Node *) n;
    4024             :                 }
    4025             :             | GENERATED generated_when AS '(' a_expr ')' opt_virtual_or_stored
    4026             :                 {
    4027        1852 :                     Constraint *n = makeNode(Constraint);
    4028             : 
    4029        1852 :                     n->contype = CONSTR_GENERATED;
    4030        1852 :                     n->generated_when = $2;
    4031        1852 :                     n->raw_expr = $5;
    4032        1852 :                     n->cooked_expr = NULL;
    4033        1852 :                     n->generated_kind = $7;
    4034        1852 :                     n->location = @1;
    4035             : 
    4036             :                     /*
    4037             :                      * Can't do this in the grammar because of shift/reduce
    4038             :                      * conflicts.  (IDENTITY allows both ALWAYS and BY
    4039             :                      * DEFAULT, but generated columns only allow ALWAYS.)  We
    4040             :                      * can also give a more useful error message and location.
    4041             :                      */
    4042        1852 :                     if ($2 != ATTRIBUTE_IDENTITY_ALWAYS)
    4043          12 :                         ereport(ERROR,
    4044             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    4045             :                                  errmsg("for a generated column, GENERATED ALWAYS must be specified"),
    4046             :                                  parser_errposition(@2)));
    4047             : 
    4048        1840 :                     $$ = (Node *) n;
    4049             :                 }
    4050             :             | REFERENCES qualified_name opt_column_list key_match key_actions
    4051             :                 {
    4052         828 :                     Constraint *n = makeNode(Constraint);
    4053             : 
    4054         828 :                     n->contype = CONSTR_FOREIGN;
    4055         828 :                     n->location = @1;
    4056         828 :                     n->pktable = $2;
    4057         828 :                     n->fk_attrs = NIL;
    4058         828 :                     n->pk_attrs = $3;
    4059         828 :                     n->fk_matchtype = $4;
    4060         828 :                     n->fk_upd_action = ($5)->updateAction->action;
    4061         828 :                     n->fk_del_action = ($5)->deleteAction->action;
    4062         828 :                     n->fk_del_set_cols = ($5)->deleteAction->cols;
    4063         828 :                     n->is_enforced = true;
    4064         828 :                     n->skip_validation = false;
    4065         828 :                     n->initially_valid = true;
    4066         828 :                     $$ = (Node *) n;
    4067             :                 }
    4068             :         ;
    4069             : 
    4070             : opt_unique_null_treatment:
    4071          12 :             NULLS_P DISTINCT        { $$ = true; }
    4072          36 :             | NULLS_P NOT DISTINCT  { $$ = false; }
    4073        7930 :             | /*EMPTY*/             { $$ = true; }
    4074             :         ;
    4075             : 
    4076             : generated_when:
    4077        2240 :             ALWAYS          { $$ = ATTRIBUTE_IDENTITY_ALWAYS; }
    4078         198 :             | BY DEFAULT    { $$ = ATTRIBUTE_IDENTITY_BY_DEFAULT; }
    4079             :         ;
    4080             : 
    4081             : opt_virtual_or_stored:
    4082        1038 :             STORED          { $$ = ATTRIBUTE_GENERATED_STORED; }
    4083         634 :             | VIRTUAL       { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
    4084         180 :             | /*EMPTY*/     { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
    4085             :         ;
    4086             : 
    4087             : /*
    4088             :  * ConstraintAttr represents constraint attributes, which we parse as if
    4089             :  * they were independent constraint clauses, in order to avoid shift/reduce
    4090             :  * conflicts (since NOT might start either an independent NOT NULL clause
    4091             :  * or an attribute).  parse_utilcmd.c is responsible for attaching the
    4092             :  * attribute information to the preceding "real" constraint node, and for
    4093             :  * complaining if attribute clauses appear in the wrong place or wrong
    4094             :  * combinations.
    4095             :  *
    4096             :  * See also ConstraintAttributeSpec, which can be used in places where
    4097             :  * there is no parsing conflict.  (Note: currently, NOT VALID and NO INHERIT
    4098             :  * are allowed clauses in ConstraintAttributeSpec, but not here.  Someday we
    4099             :  * might need to allow them here too, but for the moment it doesn't seem
    4100             :  * useful in the statements that use ConstraintAttr.)
    4101             :  */
    4102             : ConstraintAttr:
    4103             :             DEFERRABLE
    4104             :                 {
    4105         102 :                     Constraint *n = makeNode(Constraint);
    4106             : 
    4107         102 :                     n->contype = CONSTR_ATTR_DEFERRABLE;
    4108         102 :                     n->location = @1;
    4109         102 :                     $$ = (Node *) n;
    4110             :                 }
    4111             :             | NOT DEFERRABLE
    4112             :                 {
    4113           0 :                     Constraint *n = makeNode(Constraint);
    4114             : 
    4115           0 :                     n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
    4116           0 :                     n->location = @1;
    4117           0 :                     $$ = (Node *) n;
    4118             :                 }
    4119             :             | INITIALLY DEFERRED
    4120             :                 {
    4121          78 :                     Constraint *n = makeNode(Constraint);
    4122             : 
    4123          78 :                     n->contype = CONSTR_ATTR_DEFERRED;
    4124          78 :                     n->location = @1;
    4125          78 :                     $$ = (Node *) n;
    4126             :                 }
    4127             :             | INITIALLY IMMEDIATE
    4128             :                 {
    4129           6 :                     Constraint *n = makeNode(Constraint);
    4130             : 
    4131           6 :                     n->contype = CONSTR_ATTR_IMMEDIATE;
    4132           6 :                     n->location = @1;
    4133           6 :                     $$ = (Node *) n;
    4134             :                 }
    4135             :             | ENFORCED
    4136             :                 {
    4137          42 :                     Constraint *n = makeNode(Constraint);
    4138             : 
    4139          42 :                     n->contype = CONSTR_ATTR_ENFORCED;
    4140          42 :                     n->location = @1;
    4141          42 :                     $$ = (Node *) n;
    4142             :                 }
    4143             :             | NOT ENFORCED
    4144             :                 {
    4145          66 :                     Constraint *n = makeNode(Constraint);
    4146             : 
    4147          66 :                     n->contype = CONSTR_ATTR_NOT_ENFORCED;
    4148          66 :                     n->location = @1;
    4149          66 :                     $$ = (Node *) n;
    4150             :                 }
    4151             :         ;
    4152             : 
    4153             : 
    4154             : TableLikeClause:
    4155             :             LIKE qualified_name TableLikeOptionList
    4156             :                 {
    4157         774 :                     TableLikeClause *n = makeNode(TableLikeClause);
    4158             : 
    4159         774 :                     n->relation = $2;
    4160         774 :                     n->options = $3;
    4161         774 :                     n->relationOid = InvalidOid;
    4162         774 :                     $$ = (Node *) n;
    4163             :                 }
    4164             :         ;
    4165             : 
    4166             : TableLikeOptionList:
    4167         288 :                 TableLikeOptionList INCLUDING TableLikeOption   { $$ = $1 | $3; }
    4168           8 :                 | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
    4169         774 :                 | /* EMPTY */                       { $$ = 0; }
    4170             :         ;
    4171             : 
    4172             : TableLikeOption:
    4173          30 :                 COMMENTS            { $$ = CREATE_TABLE_LIKE_COMMENTS; }
    4174           6 :                 | COMPRESSION       { $$ = CREATE_TABLE_LIKE_COMPRESSION; }
    4175          54 :                 | CONSTRAINTS       { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
    4176          20 :                 | DEFAULTS          { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
    4177          12 :                 | IDENTITY_P        { $$ = CREATE_TABLE_LIKE_IDENTITY; }
    4178          30 :                 | GENERATED         { $$ = CREATE_TABLE_LIKE_GENERATED; }
    4179          50 :                 | INDEXES           { $$ = CREATE_TABLE_LIKE_INDEXES; }
    4180           0 :                 | STATISTICS        { $$ = CREATE_TABLE_LIKE_STATISTICS; }
    4181          26 :                 | STORAGE           { $$ = CREATE_TABLE_LIKE_STORAGE; }
    4182          68 :                 | ALL               { $$ = CREATE_TABLE_LIKE_ALL; }
    4183             :         ;
    4184             : 
    4185             : 
    4186             : /* ConstraintElem specifies constraint syntax which is not embedded into
    4187             :  *  a column definition. ColConstraintElem specifies the embedded form.
    4188             :  * - thomas 1997-12-03
    4189             :  */
    4190             : TableConstraint:
    4191             :             CONSTRAINT name ConstraintElem
    4192             :                 {
    4193        4506 :                     Constraint *n = castNode(Constraint, $3);
    4194             : 
    4195        4506 :                     n->conname = $2;
    4196        4506 :                     n->location = @1;
    4197        4506 :                     $$ = (Node *) n;
    4198             :                 }
    4199       13428 :             | ConstraintElem                        { $$ = $1; }
    4200             :         ;
    4201             : 
    4202             : ConstraintElem:
    4203             :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    4204             :                 {
    4205        1344 :                     Constraint *n = makeNode(Constraint);
    4206             : 
    4207        1344 :                     n->contype = CONSTR_CHECK;
    4208        1344 :                     n->location = @1;
    4209        1344 :                     n->raw_expr = $3;
    4210        1344 :                     n->cooked_expr = NULL;
    4211        1344 :                     processCASbits($5, @5, "CHECK",
    4212             :                                    NULL, NULL, &n->is_enforced, &n->skip_validation,
    4213             :                                    &n->is_no_inherit, yyscanner);
    4214        1344 :                     n->initially_valid = !n->skip_validation;
    4215        1344 :                     $$ = (Node *) n;
    4216             :                 }
    4217             :             | NOT NULL_P ColId ConstraintAttributeSpec
    4218             :                 {
    4219         622 :                     Constraint *n = makeNode(Constraint);
    4220             : 
    4221         622 :                     n->contype = CONSTR_NOTNULL;
    4222         622 :                     n->location = @1;
    4223         622 :                     n->keys = list_make1(makeString($3));
    4224         622 :                     processCASbits($4, @4, "NOT NULL",
    4225             :                                    NULL, NULL, NULL, &n->skip_validation,
    4226             :                                    &n->is_no_inherit, yyscanner);
    4227         622 :                     n->initially_valid = !n->skip_validation;
    4228         622 :                     $$ = (Node *) n;
    4229             :                 }
    4230             :             | UNIQUE opt_unique_null_treatment '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
    4231             :                 ConstraintAttributeSpec
    4232             :                 {
    4233         612 :                     Constraint *n = makeNode(Constraint);
    4234             : 
    4235         612 :                     n->contype = CONSTR_UNIQUE;
    4236         612 :                     n->location = @1;
    4237         612 :                     n->nulls_not_distinct = !$2;
    4238         612 :                     n->keys = $4;
    4239         612 :                     n->without_overlaps = $5;
    4240         612 :                     n->including = $7;
    4241         612 :                     n->options = $8;
    4242         612 :                     n->indexname = NULL;
    4243         612 :                     n->indexspace = $9;
    4244         612 :                     processCASbits($10, @10, "UNIQUE",
    4245             :                                    &n->deferrable, &n->initdeferred, NULL,
    4246             :                                    NULL, NULL, yyscanner);
    4247         612 :                     $$ = (Node *) n;
    4248             :                 }
    4249             :             | UNIQUE ExistingIndex ConstraintAttributeSpec
    4250             :                 {
    4251        4744 :                     Constraint *n = makeNode(Constraint);
    4252             : 
    4253        4744 :                     n->contype = CONSTR_UNIQUE;
    4254        4744 :                     n->location = @1;
    4255        4744 :                     n->keys = NIL;
    4256        4744 :                     n->including = NIL;
    4257        4744 :                     n->options = NIL;
    4258        4744 :                     n->indexname = $2;
    4259        4744 :                     n->indexspace = NULL;
    4260        4744 :                     processCASbits($3, @3, "UNIQUE",
    4261             :                                    &n->deferrable, &n->initdeferred, NULL,
    4262             :                                    NULL, NULL, yyscanner);
    4263        4744 :                     $$ = (Node *) n;
    4264             :                 }
    4265             :             | PRIMARY KEY '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
    4266             :                 ConstraintAttributeSpec
    4267             :                 {
    4268        2386 :                     Constraint *n = makeNode(Constraint);
    4269             : 
    4270        2386 :                     n->contype = CONSTR_PRIMARY;
    4271        2386 :                     n->location = @1;
    4272        2386 :                     n->keys = $4;
    4273        2386 :                     n->without_overlaps = $5;
    4274        2386 :                     n->including = $7;
    4275        2386 :                     n->options = $8;
    4276        2386 :                     n->indexname = NULL;
    4277        2386 :                     n->indexspace = $9;
    4278        2386 :                     processCASbits($10, @10, "PRIMARY KEY",
    4279             :                                    &n->deferrable, &n->initdeferred, NULL,
    4280             :                                    NULL, NULL, yyscanner);
    4281        2386 :                     $$ = (Node *) n;
    4282             :                 }
    4283             :             | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
    4284             :                 {
    4285        6142 :                     Constraint *n = makeNode(Constraint);
    4286             : 
    4287        6142 :                     n->contype = CONSTR_PRIMARY;
    4288        6142 :                     n->location = @1;
    4289        6142 :                     n->keys = NIL;
    4290        6142 :                     n->including = NIL;
    4291        6142 :                     n->options = NIL;
    4292        6142 :                     n->indexname = $3;
    4293        6142 :                     n->indexspace = NULL;
    4294        6142 :                     processCASbits($4, @4, "PRIMARY KEY",
    4295             :                                    &n->deferrable, &n->initdeferred, NULL,
    4296             :                                    NULL, NULL, yyscanner);
    4297        6142 :                     $$ = (Node *) n;
    4298             :                 }
    4299             :             | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
    4300             :                 opt_c_include opt_definition OptConsTableSpace OptWhereClause
    4301             :                 ConstraintAttributeSpec
    4302             :                 {
    4303         238 :                     Constraint *n = makeNode(Constraint);
    4304             : 
    4305         238 :                     n->contype = CONSTR_EXCLUSION;
    4306         238 :                     n->location = @1;
    4307         238 :                     n->access_method = $2;
    4308         238 :                     n->exclusions = $4;
    4309         238 :                     n->including = $6;
    4310         238 :                     n->options = $7;
    4311         238 :                     n->indexname = NULL;
    4312         238 :                     n->indexspace = $8;
    4313         238 :                     n->where_clause = $9;
    4314         238 :                     processCASbits($10, @10, "EXCLUDE",
    4315             :                                    &n->deferrable, &n->initdeferred, NULL,
    4316             :                                    NULL, NULL, yyscanner);
    4317         238 :                     $$ = (Node *) n;
    4318             :                 }
    4319             :             | FOREIGN KEY '(' columnList optionalPeriodName ')' REFERENCES qualified_name
    4320             :                 opt_column_and_period_list key_match key_actions ConstraintAttributeSpec
    4321             :                 {
    4322        1846 :                     Constraint *n = makeNode(Constraint);
    4323             : 
    4324        1846 :                     n->contype = CONSTR_FOREIGN;
    4325        1846 :                     n->location = @1;
    4326        1846 :                     n->pktable = $8;
    4327        1846 :                     n->fk_attrs = $4;
    4328        1846 :                     if ($5)
    4329             :                     {
    4330         296 :                         n->fk_attrs = lappend(n->fk_attrs, $5);
    4331         296 :                         n->fk_with_period = true;
    4332             :                     }
    4333        1846 :                     n->pk_attrs = linitial($9);
    4334        1846 :                     if (lsecond($9))
    4335             :                     {
    4336         176 :                         n->pk_attrs = lappend(n->pk_attrs, lsecond($9));
    4337         176 :                         n->pk_with_period = true;
    4338             :                     }
    4339        1846 :                     n->fk_matchtype = $10;
    4340        1846 :                     n->fk_upd_action = ($11)->updateAction->action;
    4341        1846 :                     n->fk_del_action = ($11)->deleteAction->action;
    4342        1846 :                     n->fk_del_set_cols = ($11)->deleteAction->cols;
    4343        1846 :                     processCASbits($12, @12, "FOREIGN KEY",
    4344             :                                    &n->deferrable, &n->initdeferred,
    4345             :                                    &n->is_enforced, &n->skip_validation, NULL,
    4346             :                                    yyscanner);
    4347        1846 :                     n->initially_valid = !n->skip_validation;
    4348        1846 :                     $$ = (Node *) n;
    4349             :                 }
    4350             :         ;
    4351             : 
    4352             : /*
    4353             :  * DomainConstraint is separate from TableConstraint because the syntax for
    4354             :  * NOT NULL constraints is different.  For table constraints, we need to
    4355             :  * accept a column name, but for domain constraints, we don't.  (We could
    4356             :  * accept something like NOT NULL VALUE, but that seems weird.)  CREATE DOMAIN
    4357             :  * (which uses ColQualList) has for a long time accepted NOT NULL without a
    4358             :  * column name, so it makes sense that ALTER DOMAIN (which uses
    4359             :  * DomainConstraint) does as well.  None of these syntaxes are per SQL
    4360             :  * standard; we are just living with the bits of inconsistency that have built
    4361             :  * up over time.
    4362             :  */
    4363             : DomainConstraint:
    4364             :             CONSTRAINT name DomainConstraintElem
    4365             :                 {
    4366         156 :                     Constraint *n = castNode(Constraint, $3);
    4367             : 
    4368         156 :                     n->conname = $2;
    4369         156 :                     n->location = @1;
    4370         156 :                     $$ = (Node *) n;
    4371             :                 }
    4372          18 :             | DomainConstraintElem                  { $$ = $1; }
    4373             :         ;
    4374             : 
    4375             : DomainConstraintElem:
    4376             :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    4377             :                 {
    4378         156 :                     Constraint *n = makeNode(Constraint);
    4379             : 
    4380         156 :                     n->contype = CONSTR_CHECK;
    4381         156 :                     n->location = @1;
    4382         156 :                     n->raw_expr = $3;
    4383         156 :                     n->cooked_expr = NULL;
    4384         156 :                     processCASbits($5, @5, "CHECK",
    4385             :                                    NULL, NULL, NULL, &n->skip_validation,
    4386             :                                    &n->is_no_inherit, yyscanner);
    4387         144 :                     n->is_enforced = true;
    4388         144 :                     n->initially_valid = !n->skip_validation;
    4389         144 :                     $$ = (Node *) n;
    4390             :                 }
    4391             :             | NOT NULL_P ConstraintAttributeSpec
    4392             :                 {
    4393          30 :                     Constraint *n = makeNode(Constraint);
    4394             : 
    4395          30 :                     n->contype = CONSTR_NOTNULL;
    4396          30 :                     n->location = @1;
    4397          30 :                     n->keys = list_make1(makeString("value"));
    4398             :                     /* no NOT VALID, NO INHERIT support */
    4399          30 :                     processCASbits($3, @3, "NOT NULL",
    4400             :                                    NULL, NULL, NULL,
    4401             :                                    NULL, NULL, yyscanner);
    4402          30 :                     n->initially_valid = true;
    4403          30 :                     $$ = (Node *) n;
    4404             :                 }
    4405             :         ;
    4406             : 
    4407         138 : opt_no_inherit: NO INHERIT                          {  $$ = true; }
    4408        8132 :             | /* EMPTY */                           {  $$ = false; }
    4409             :         ;
    4410             : 
    4411             : opt_without_overlaps:
    4412         570 :             WITHOUT OVERLAPS                        { $$ = true; }
    4413        2428 :             | /*EMPTY*/                             { $$ = false; }
    4414             :     ;
    4415             : 
    4416             : opt_column_list:
    4417       15440 :             '(' columnList ')'                      { $$ = $2; }
    4418       43270 :             | /*EMPTY*/                             { $$ = NIL; }
    4419             :         ;
    4420             : 
    4421             : columnList:
    4422       22032 :             columnElem                              { $$ = list_make1($1); }
    4423       44224 :             | columnList ',' columnElem             { $$ = lappend($1, $3); }
    4424             :         ;
    4425             : 
    4426             : optionalPeriodName:
    4427         472 :             ',' PERIOD columnElem { $$ = $3; }
    4428        2542 :             | /*EMPTY*/               { $$ = NULL; }
    4429             :     ;
    4430             : 
    4431             : opt_column_and_period_list:
    4432        1162 :             '(' columnList optionalPeriodName ')'           { $$ = list_make2($2, $3); }
    4433         690 :             | /*EMPTY*/                             { $$ = list_make2(NIL, NULL); }
    4434             :         ;
    4435             : 
    4436             : columnElem: ColId
    4437             :                 {
    4438       66728 :                     $$ = (Node *) makeString($1);
    4439             :                 }
    4440             :         ;
    4441             : 
    4442         176 : opt_c_include:  INCLUDE '(' columnList ')'          { $$ = $3; }
    4443        3060 :              |      /* EMPTY */                     { $$ = NIL; }
    4444             :         ;
    4445             : 
    4446             : key_match:  MATCH FULL
    4447             :             {
    4448         100 :                 $$ = FKCONSTR_MATCH_FULL;
    4449             :             }
    4450             :         | MATCH PARTIAL
    4451             :             {
    4452           0 :                 ereport(ERROR,
    4453             :                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4454             :                          errmsg("MATCH PARTIAL not yet implemented"),
    4455             :                          parser_errposition(@1)));
    4456             :                 $$ = FKCONSTR_MATCH_PARTIAL;
    4457             :             }
    4458             :         | MATCH SIMPLE
    4459             :             {
    4460           6 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4461             :             }
    4462             :         | /*EMPTY*/
    4463             :             {
    4464        2574 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4465             :             }
    4466             :         ;
    4467             : 
    4468             : ExclusionConstraintList:
    4469         238 :             ExclusionConstraintElem                 { $$ = list_make1($1); }
    4470             :             | ExclusionConstraintList ',' ExclusionConstraintElem
    4471         110 :                                                     { $$ = lappend($1, $3); }
    4472             :         ;
    4473             : 
    4474             : ExclusionConstraintElem: index_elem WITH any_operator
    4475             :             {
    4476         348 :                 $$ = list_make2($1, $3);
    4477             :             }
    4478             :             /* allow OPERATOR() decoration for the benefit of ruleutils.c */
    4479             :             | index_elem WITH OPERATOR '(' any_operator ')'
    4480             :             {
    4481           0 :                 $$ = list_make2($1, $5);
    4482             :             }
    4483             :         ;
    4484             : 
    4485             : OptWhereClause:
    4486         440 :             WHERE '(' a_expr ')'                    { $$ = $3; }
    4487        1244 :             | /*EMPTY*/                             { $$ = NULL; }
    4488             :         ;
    4489             : 
    4490             : key_actions:
    4491             :             key_update
    4492             :                 {
    4493          76 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4494             : 
    4495          76 :                     n->updateAction = $1;
    4496          76 :                     n->deleteAction = palloc(sizeof(KeyAction));
    4497          76 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4498          76 :                     n->deleteAction->cols = NIL;
    4499          76 :                     $$ = n;
    4500             :                 }
    4501             :             | key_delete
    4502             :                 {
    4503         150 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4504             : 
    4505         150 :                     n->updateAction = palloc(sizeof(KeyAction));
    4506         150 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4507         150 :                     n->updateAction->cols = NIL;
    4508         150 :                     n->deleteAction = $1;
    4509         150 :                     $$ = n;
    4510             :                 }
    4511             :             | key_update key_delete
    4512             :                 {
    4513         162 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4514             : 
    4515         162 :                     n->updateAction = $1;
    4516         162 :                     n->deleteAction = $2;
    4517         162 :                     $$ = n;
    4518             :                 }
    4519             :             | key_delete key_update
    4520             :                 {
    4521         150 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4522             : 
    4523         150 :                     n->updateAction = $2;
    4524         150 :                     n->deleteAction = $1;
    4525         150 :                     $$ = n;
    4526             :                 }
    4527             :             | /*EMPTY*/
    4528             :                 {
    4529        2136 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4530             : 
    4531        2136 :                     n->updateAction = palloc(sizeof(KeyAction));
    4532        2136 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4533        2136 :                     n->updateAction->cols = NIL;
    4534        2136 :                     n->deleteAction = palloc(sizeof(KeyAction));
    4535        2136 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4536        2136 :                     n->deleteAction->cols = NIL;
    4537        2136 :                     $$ = n;
    4538             :                 }
    4539             :         ;
    4540             : 
    4541             : key_update: ON UPDATE key_action
    4542             :                 {
    4543         394 :                     if (($3)->cols)
    4544           6 :                         ereport(ERROR,
    4545             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4546             :                                  errmsg("a column list with %s is only supported for ON DELETE actions",
    4547             :                                         ($3)->action == FKCONSTR_ACTION_SETNULL ? "SET NULL" : "SET DEFAULT"),
    4548             :                                  parser_errposition(@1)));
    4549         388 :                     $$ = $3;
    4550             :                 }
    4551             :         ;
    4552             : 
    4553             : key_delete: ON DELETE_P key_action
    4554             :                 {
    4555         462 :                     $$ = $3;
    4556             :                 }
    4557             :         ;
    4558             : 
    4559             : key_action:
    4560             :             NO ACTION
    4561             :                 {
    4562          80 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4563             : 
    4564          80 :                     n->action = FKCONSTR_ACTION_NOACTION;
    4565          80 :                     n->cols = NIL;
    4566          80 :                     $$ = n;
    4567             :                 }
    4568             :             | RESTRICT
    4569             :                 {
    4570          48 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4571             : 
    4572          48 :                     n->action = FKCONSTR_ACTION_RESTRICT;
    4573          48 :                     n->cols = NIL;
    4574          48 :                     $$ = n;
    4575             :                 }
    4576             :             | CASCADE
    4577             :                 {
    4578         434 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4579             : 
    4580         434 :                     n->action = FKCONSTR_ACTION_CASCADE;
    4581         434 :                     n->cols = NIL;
    4582         434 :                     $$ = n;
    4583             :                 }
    4584             :             | SET NULL_P opt_column_list
    4585             :                 {
    4586         192 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4587             : 
    4588         192 :                     n->action = FKCONSTR_ACTION_SETNULL;
    4589         192 :                     n->cols = $3;
    4590         192 :                     $$ = n;
    4591             :                 }
    4592             :             | SET DEFAULT opt_column_list
    4593             :                 {
    4594         102 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4595             : 
    4596         102 :                     n->action = FKCONSTR_ACTION_SETDEFAULT;
    4597         102 :                     n->cols = $3;
    4598         102 :                     $$ = n;
    4599             :                 }
    4600             :         ;
    4601             : 
    4602        2190 : OptInherit: INHERITS '(' qualified_name_list ')'    { $$ = $3; }
    4603       29074 :             | /*EMPTY*/                             { $$ = NIL; }
    4604             :         ;
    4605             : 
    4606             : /* Optional partition key specification */
    4607        5146 : OptPartitionSpec: PartitionSpec { $$ = $1; }
    4608       33738 :             | /*EMPTY*/         { $$ = NULL; }
    4609             :         ;
    4610             : 
    4611             : PartitionSpec: PARTITION BY ColId '(' part_params ')'
    4612             :                 {
    4613        5152 :                     PartitionSpec *n = makeNode(PartitionSpec);
    4614             : 
    4615        5152 :                     n->strategy = parsePartitionStrategy($3, @3, yyscanner);
    4616        5146 :                     n->partParams = $5;
    4617        5146 :                     n->location = @1;
    4618             : 
    4619        5146 :                     $$ = n;
    4620             :                 }
    4621             :         ;
    4622             : 
    4623        5152 : part_params:    part_elem                       { $$ = list_make1($1); }
    4624         466 :             | part_params ',' part_elem         { $$ = lappend($1, $3); }
    4625             :         ;
    4626             : 
    4627             : part_elem: ColId opt_collate opt_qualified_name
    4628             :                 {
    4629        5298 :                     PartitionElem *n = makeNode(PartitionElem);
    4630             : 
    4631        5298 :                     n->name = $1;
    4632        5298 :                     n->expr = NULL;
    4633        5298 :                     n->collation = $2;
    4634        5298 :                     n->opclass = $3;
    4635        5298 :                     n->location = @1;
    4636        5298 :                     $$ = n;
    4637             :                 }
    4638             :             | func_expr_windowless opt_collate opt_qualified_name
    4639             :                 {
    4640         134 :                     PartitionElem *n = makeNode(PartitionElem);
    4641             : 
    4642         134 :                     n->name = NULL;
    4643         134 :                     n->expr = $1;
    4644         134 :                     n->collation = $2;
    4645         134 :                     n->opclass = $3;
    4646         134 :                     n->location = @1;
    4647         134 :                     $$ = n;
    4648             :                 }
    4649             :             | '(' a_expr ')' opt_collate opt_qualified_name
    4650             :                 {
    4651         186 :                     PartitionElem *n = makeNode(PartitionElem);
    4652             : 
    4653         186 :                     n->name = NULL;
    4654         186 :                     n->expr = $2;
    4655         186 :                     n->collation = $4;
    4656         186 :                     n->opclass = $5;
    4657         186 :                     n->location = @1;
    4658         186 :                     $$ = n;
    4659             :                 }
    4660             :         ;
    4661             : 
    4662             : table_access_method_clause:
    4663         122 :             USING name                          { $$ = $2; }
    4664       40682 :             | /*EMPTY*/                         { $$ = NULL; }
    4665             :         ;
    4666             : 
    4667             : /* WITHOUT OIDS is legacy only */
    4668             : OptWith:
    4669         798 :             WITH reloptions             { $$ = $2; }
    4670          24 :             | WITHOUT OIDS              { $$ = NIL; }
    4671       39378 :             | /*EMPTY*/                 { $$ = NIL; }
    4672             :         ;
    4673             : 
    4674          60 : OnCommitOption:  ON COMMIT DROP             { $$ = ONCOMMIT_DROP; }
    4675         104 :             | ON COMMIT DELETE_P ROWS       { $$ = ONCOMMIT_DELETE_ROWS; }
    4676          24 :             | ON COMMIT PRESERVE ROWS       { $$ = ONCOMMIT_PRESERVE_ROWS; }
    4677       40012 :             | /*EMPTY*/                     { $$ = ONCOMMIT_NOOP; }
    4678             :         ;
    4679             : 
    4680         206 : OptTableSpace:   TABLESPACE name                    { $$ = $2; }
    4681       47512 :             | /*EMPTY*/                             { $$ = NULL; }
    4682             :         ;
    4683             : 
    4684          66 : OptConsTableSpace:   USING INDEX TABLESPACE name    { $$ = $4; }
    4685        9388 :             | /*EMPTY*/                             { $$ = NULL; }
    4686             :         ;
    4687             : 
    4688       10886 : ExistingIndex:   USING INDEX name                   { $$ = $3; }
    4689             :         ;
    4690             : 
    4691             : /*****************************************************************************
    4692             :  *
    4693             :  *      QUERY :
    4694             :  *              CREATE STATISTICS [[IF NOT EXISTS] stats_name] [(stat types)]
    4695             :  *                  ON expression-list FROM from_list
    4696             :  *
    4697             :  * Note: the expectation here is that the clauses after ON are a subset of
    4698             :  * SELECT syntax, allowing for expressions and joined tables, and probably
    4699             :  * someday a WHERE clause.  Much less than that is currently implemented,
    4700             :  * but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
    4701             :  * errors as necessary at execution.
    4702             :  *
    4703             :  * Statistics name is optional unless IF NOT EXISTS is specified.
    4704             :  *
    4705             :  *****************************************************************************/
    4706             : 
    4707             : CreateStatsStmt:
    4708             :             CREATE STATISTICS opt_qualified_name
    4709             :             opt_name_list ON stats_params FROM from_list
    4710             :                 {
    4711         690 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4712             : 
    4713         690 :                     n->defnames = $3;
    4714         690 :                     n->stat_types = $4;
    4715         690 :                     n->exprs = $6;
    4716         690 :                     n->relations = $8;
    4717         690 :                     n->stxcomment = NULL;
    4718         690 :                     n->if_not_exists = false;
    4719         690 :                     $$ = (Node *) n;
    4720             :                 }
    4721             :             | CREATE STATISTICS IF_P NOT EXISTS any_name
    4722             :             opt_name_list ON stats_params FROM from_list
    4723             :                 {
    4724          12 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4725             : 
    4726          12 :                     n->defnames = $6;
    4727          12 :                     n->stat_types = $7;
    4728          12 :                     n->exprs = $9;
    4729          12 :                     n->relations = $11;
    4730          12 :                     n->stxcomment = NULL;
    4731          12 :                     n->if_not_exists = true;
    4732          12 :                     $$ = (Node *) n;
    4733             :                 }
    4734             :             ;
    4735             : 
    4736             : /*
    4737             :  * Statistics attributes can be either simple column references, or arbitrary
    4738             :  * expressions in parens.  For compatibility with index attributes permitted
    4739             :  * in CREATE INDEX, we allow an expression that's just a function call to be
    4740             :  * written without parens.
    4741             :  */
    4742             : 
    4743         714 : stats_params:   stats_param                         { $$ = list_make1($1); }
    4744         988 :             | stats_params ',' stats_param          { $$ = lappend($1, $3); }
    4745             :         ;
    4746             : 
    4747             : stats_param:    ColId
    4748             :                 {
    4749        1192 :                     $$ = makeNode(StatsElem);
    4750        1192 :                     $$->name = $1;
    4751        1192 :                     $$->expr = NULL;
    4752             :                 }
    4753             :             | func_expr_windowless
    4754             :                 {
    4755          34 :                     $$ = makeNode(StatsElem);
    4756          34 :                     $$->name = NULL;
    4757          34 :                     $$->expr = $1;
    4758             :                 }
    4759             :             | '(' a_expr ')'
    4760             :                 {
    4761         476 :                     $$ = makeNode(StatsElem);
    4762         476 :                     $$->name = NULL;
    4763         476 :                     $$->expr = $2;
    4764             :                 }
    4765             :         ;
    4766             : 
    4767             : /*****************************************************************************
    4768             :  *
    4769             :  *      QUERY :
    4770             :  *              ALTER STATISTICS [IF EXISTS] stats_name
    4771             :  *                  SET STATISTICS  <SignedIconst>
    4772             :  *
    4773             :  *****************************************************************************/
    4774             : 
    4775             : AlterStatsStmt:
    4776             :             ALTER STATISTICS any_name SET STATISTICS set_statistics_value
    4777             :                 {
    4778          20 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4779             : 
    4780          20 :                     n->defnames = $3;
    4781          20 :                     n->missing_ok = false;
    4782          20 :                     n->stxstattarget = $6;
    4783          20 :                     $$ = (Node *) n;
    4784             :                 }
    4785             :             | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
    4786             :                 {
    4787           6 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4788             : 
    4789           6 :                     n->defnames = $5;
    4790           6 :                     n->missing_ok = true;
    4791           6 :                     n->stxstattarget = $8;
    4792           6 :                     $$ = (Node *) n;
    4793             :                 }
    4794             :             ;
    4795             : 
    4796             : /*****************************************************************************
    4797             :  *
    4798             :  *      QUERY :
    4799             :  *              CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
    4800             :  *
    4801             :  *
    4802             :  * Note: SELECT ... INTO is a now-deprecated alternative for this.
    4803             :  *
    4804             :  *****************************************************************************/
    4805             : 
    4806             : CreateAsStmt:
    4807             :         CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
    4808             :                 {
    4809        1188 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4810             : 
    4811        1188 :                     ctas->query = $6;
    4812        1188 :                     ctas->into = $4;
    4813        1188 :                     ctas->objtype = OBJECT_TABLE;
    4814        1188 :                     ctas->is_select_into = false;
    4815        1188 :                     ctas->if_not_exists = false;
    4816             :                     /* cram additional flags into the IntoClause */
    4817        1188 :                     $4->rel->relpersistence = $2;
    4818        1188 :                     $4->skipData = !($7);
    4819        1188 :                     $$ = (Node *) ctas;
    4820             :                 }
    4821             :         | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
    4822             :                 {
    4823          52 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4824             : 
    4825          52 :                     ctas->query = $9;
    4826          52 :                     ctas->into = $7;
    4827          52 :                     ctas->objtype = OBJECT_TABLE;
    4828          52 :                     ctas->is_select_into = false;
    4829          52 :                     ctas->if_not_exists = true;
    4830             :                     /* cram additional flags into the IntoClause */
    4831          52 :                     $7->rel->relpersistence = $2;
    4832          52 :                     $7->skipData = !($10);
    4833          52 :                     $$ = (Node *) ctas;
    4834             :                 }
    4835             :         ;
    4836             : 
    4837             : create_as_target:
    4838             :             qualified_name opt_column_list table_access_method_clause
    4839             :             OptWith OnCommitOption OptTableSpace
    4840             :                 {
    4841        1328 :                     $$ = makeNode(IntoClause);
    4842        1328 :                     $$->rel = $1;
    4843        1328 :                     $$->colNames = $2;
    4844        1328 :                     $$->accessMethod = $3;
    4845        1328 :                     $$->options = $4;
    4846        1328 :                     $$->onCommit = $5;
    4847        1328 :                     $$->tableSpaceName = $6;
    4848        1328 :                     $$->viewQuery = NULL;
    4849        1328 :                     $$->skipData = false;        /* might get changed later */
    4850             :                 }
    4851             :         ;
    4852             : 
    4853             : opt_with_data:
    4854          36 :             WITH DATA_P                             { $$ = true; }
    4855         234 :             | WITH NO DATA_P                        { $$ = false; }
    4856        1940 :             | /*EMPTY*/                             { $$ = true; }
    4857             :         ;
    4858             : 
    4859             : 
    4860             : /*****************************************************************************
    4861             :  *
    4862             :  *      QUERY :
    4863             :  *              CREATE MATERIALIZED VIEW relname AS SelectStmt
    4864             :  *
    4865             :  *****************************************************************************/
    4866             : 
    4867             : CreateMatViewStmt:
    4868             :         CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
    4869             :                 {
    4870         550 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4871             : 
    4872         550 :                     ctas->query = $7;
    4873         550 :                     ctas->into = $5;
    4874         550 :                     ctas->objtype = OBJECT_MATVIEW;
    4875         550 :                     ctas->is_select_into = false;
    4876         550 :                     ctas->if_not_exists = false;
    4877             :                     /* cram additional flags into the IntoClause */
    4878         550 :                     $5->rel->relpersistence = $2;
    4879         550 :                     $5->skipData = !($8);
    4880         550 :                     $$ = (Node *) ctas;
    4881             :                 }
    4882             :         | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
    4883             :                 {
    4884          48 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4885             : 
    4886          48 :                     ctas->query = $10;
    4887          48 :                     ctas->into = $8;
    4888          48 :                     ctas->objtype = OBJECT_MATVIEW;
    4889          48 :                     ctas->is_select_into = false;
    4890          48 :                     ctas->if_not_exists = true;
    4891             :                     /* cram additional flags into the IntoClause */
    4892          48 :                     $8->rel->relpersistence = $2;
    4893          48 :                     $8->skipData = !($11);
    4894          48 :                     $$ = (Node *) ctas;
    4895             :                 }
    4896             :         ;
    4897             : 
    4898             : create_mv_target:
    4899             :             qualified_name opt_column_list table_access_method_clause opt_reloptions OptTableSpace
    4900             :                 {
    4901         598 :                     $$ = makeNode(IntoClause);
    4902         598 :                     $$->rel = $1;
    4903         598 :                     $$->colNames = $2;
    4904         598 :                     $$->accessMethod = $3;
    4905         598 :                     $$->options = $4;
    4906         598 :                     $$->onCommit = ONCOMMIT_NOOP;
    4907         598 :                     $$->tableSpaceName = $5;
    4908         598 :                     $$->viewQuery = NULL;        /* filled at analysis time */
    4909         598 :                     $$->skipData = false;        /* might get changed later */
    4910             :                 }
    4911             :         ;
    4912             : 
    4913           0 : OptNoLog:   UNLOGGED                    { $$ = RELPERSISTENCE_UNLOGGED; }
    4914         598 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    4915             :         ;
    4916             : 
    4917             : 
    4918             : /*****************************************************************************
    4919             :  *
    4920             :  *      QUERY :
    4921             :  *              REFRESH MATERIALIZED VIEW qualified_name
    4922             :  *
    4923             :  *****************************************************************************/
    4924             : 
    4925             : RefreshMatViewStmt:
    4926             :             REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
    4927             :                 {
    4928         284 :                     RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
    4929             : 
    4930         284 :                     n->concurrent = $4;
    4931         284 :                     n->relation = $5;
    4932         284 :                     n->skipData = !($6);
    4933         284 :                     $$ = (Node *) n;
    4934             :                 }
    4935             :         ;
    4936             : 
    4937             : 
    4938             : /*****************************************************************************
    4939             :  *
    4940             :  *      QUERY :
    4941             :  *              CREATE SEQUENCE seqname
    4942             :  *              ALTER SEQUENCE seqname
    4943             :  *
    4944             :  *****************************************************************************/
    4945             : 
    4946             : CreateSeqStmt:
    4947             :             CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
    4948             :                 {
    4949         720 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    4950             : 
    4951         720 :                     $4->relpersistence = $2;
    4952         720 :                     n->sequence = $4;
    4953         720 :                     n->options = $5;
    4954         720 :                     n->ownerId = InvalidOid;
    4955         720 :                     n->if_not_exists = false;
    4956         720 :                     $$ = (Node *) n;
    4957             :                 }
    4958             :             | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
    4959             :                 {
    4960          24 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    4961             : 
    4962          24 :                     $7->relpersistence = $2;
    4963          24 :                     n->sequence = $7;
    4964          24 :                     n->options = $8;
    4965          24 :                     n->ownerId = InvalidOid;
    4966          24 :                     n->if_not_exists = true;
    4967          24 :                     $$ = (Node *) n;
    4968             :                 }
    4969             :         ;
    4970             : 
    4971             : AlterSeqStmt:
    4972             :             ALTER SEQUENCE qualified_name SeqOptList
    4973             :                 {
    4974         212 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    4975             : 
    4976         212 :                     n->sequence = $3;
    4977         212 :                     n->options = $4;
    4978         212 :                     n->missing_ok = false;
    4979         212 :                     $$ = (Node *) n;
    4980             :                 }
    4981             :             | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
    4982             :                 {
    4983          12 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    4984             : 
    4985          12 :                     n->sequence = $5;
    4986          12 :                     n->options = $6;
    4987          12 :                     n->missing_ok = true;
    4988          12 :                     $$ = (Node *) n;
    4989             :                 }
    4990             : 
    4991             :         ;
    4992             : 
    4993         326 : OptSeqOptList: SeqOptList                           { $$ = $1; }
    4994         418 :             | /*EMPTY*/                             { $$ = NIL; }
    4995             :         ;
    4996             : 
    4997         118 : OptParenthesizedSeqOptList: '(' SeqOptList ')'      { $$ = $2; }
    4998         424 :             | /*EMPTY*/                             { $$ = NIL; }
    4999             :         ;
    5000             : 
    5001         668 : SeqOptList: SeqOptElem                              { $$ = list_make1($1); }
    5002        1322 :             | SeqOptList SeqOptElem                 { $$ = lappend($1, $2); }
    5003             :         ;
    5004             : 
    5005             : SeqOptElem: AS SimpleTypename
    5006             :                 {
    5007         236 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    5008             :                 }
    5009             :             | CACHE NumericOnly
    5010             :                 {
    5011         236 :                     $$ = makeDefElem("cache", (Node *) $2, @1);
    5012             :                 }
    5013             :             | CYCLE
    5014             :                 {
    5015          36 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(true), @1);
    5016             :                 }
    5017             :             | NO CYCLE
    5018             :                 {
    5019          14 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(false), @1);
    5020             :                 }
    5021             :             | INCREMENT opt_by NumericOnly
    5022             :                 {
    5023         352 :                     $$ = makeDefElem("increment", (Node *) $3, @1);
    5024             :                 }
    5025             :             | LOGGED
    5026             :                 {
    5027           4 :                     $$ = makeDefElem("logged", NULL, @1);
    5028             :                 }
    5029             :             | MAXVALUE NumericOnly
    5030             :                 {
    5031          74 :                     $$ = makeDefElem("maxvalue", (Node *) $2, @1);
    5032             :                 }
    5033             :             | MINVALUE NumericOnly
    5034             :                 {
    5035          74 :                     $$ = makeDefElem("minvalue", (Node *) $2, @1);
    5036             :                 }
    5037             :             | NO MAXVALUE
    5038             :                 {
    5039         208 :                     $$ = makeDefElem("maxvalue", NULL, @1);
    5040             :                 }
    5041             :             | NO MINVALUE
    5042             :                 {
    5043         208 :                     $$ = makeDefElem("minvalue", NULL, @1);
    5044             :                 }
    5045             :             | OWNED BY any_name
    5046             :                 {
    5047         100 :                     $$ = makeDefElem("owned_by", (Node *) $3, @1);
    5048             :                 }
    5049             :             | SEQUENCE NAME_P any_name
    5050             :                 {
    5051          88 :                     $$ = makeDefElem("sequence_name", (Node *) $3, @1);
    5052             :                 }
    5053             :             | START opt_with NumericOnly
    5054             :                 {
    5055         344 :                     $$ = makeDefElem("start", (Node *) $3, @1);
    5056             :                 }
    5057             :             | RESTART
    5058             :                 {
    5059           6 :                     $$ = makeDefElem("restart", NULL, @1);
    5060             :                 }
    5061             :             | RESTART opt_with NumericOnly
    5062             :                 {
    5063          60 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    5064             :                 }
    5065             :             | UNLOGGED
    5066             :                 {
    5067           4 :                     $$ = makeDefElem("unlogged", NULL, @1);
    5068             :                 }
    5069             :         ;
    5070             : 
    5071             : opt_by:     BY
    5072             :             | /* EMPTY */
    5073             :       ;
    5074             : 
    5075             : NumericOnly:
    5076         328 :             FCONST                              { $$ = (Node *) makeFloat($1); }
    5077           0 :             | '+' FCONST                        { $$ = (Node *) makeFloat($2); }
    5078             :             | '-' FCONST
    5079             :                 {
    5080          22 :                     Float      *f = makeFloat($2);
    5081             : 
    5082          22 :                     doNegateFloat(f);
    5083          22 :                     $$ = (Node *) f;
    5084             :                 }
    5085       13690 :             | SignedIconst                      { $$ = (Node *) makeInteger($1); }
    5086             :         ;
    5087             : 
    5088          80 : NumericOnly_list:   NumericOnly                     { $$ = list_make1($1); }
    5089           6 :                 | NumericOnly_list ',' NumericOnly  { $$ = lappend($1, $3); }
    5090             :         ;
    5091             : 
    5092             : /*****************************************************************************
    5093             :  *
    5094             :  *      QUERIES :
    5095             :  *              CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
    5096             :  *              DROP [PROCEDURAL] LANGUAGE ...
    5097             :  *
    5098             :  *****************************************************************************/
    5099             : 
    5100             : CreatePLangStmt:
    5101             :             CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
    5102             :             {
    5103             :                 /*
    5104             :                  * We now interpret parameterless CREATE LANGUAGE as
    5105             :                  * CREATE EXTENSION.  "OR REPLACE" is silently translated
    5106             :                  * to "IF NOT EXISTS", which isn't quite the same, but
    5107             :                  * seems more useful than throwing an error.  We just
    5108             :                  * ignore TRUSTED, as the previous code would have too.
    5109             :                  */
    5110           0 :                 CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5111             : 
    5112           0 :                 n->if_not_exists = $2;
    5113           0 :                 n->extname = $6;
    5114           0 :                 n->options = NIL;
    5115           0 :                 $$ = (Node *) n;
    5116             :             }
    5117             :             | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
    5118             :               HANDLER handler_name opt_inline_handler opt_validator
    5119             :             {
    5120         144 :                 CreatePLangStmt *n = makeNode(CreatePLangStmt);
    5121             : 
    5122         144 :                 n->replace = $2;
    5123         144 :                 n->plname = $6;
    5124         144 :                 n->plhandler = $8;
    5125         144 :                 n->plinline = $9;
    5126         144 :                 n->plvalidator = $10;
    5127         144 :                 n->pltrusted = $3;
    5128         144 :                 $$ = (Node *) n;
    5129             :             }
    5130             :         ;
    5131             : 
    5132             : opt_trusted:
    5133         114 :             TRUSTED                                 { $$ = true; }
    5134          38 :             | /*EMPTY*/                             { $$ = false; }
    5135             :         ;
    5136             : 
    5137             : /* This ought to be just func_name, but that causes reduce/reduce conflicts
    5138             :  * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
    5139             :  * Work around by using simple names, instead.
    5140             :  */
    5141             : handler_name:
    5142         562 :             name                        { $$ = list_make1(makeString($1)); }
    5143           2 :             | name attrs                { $$ = lcons(makeString($1), $2); }
    5144             :         ;
    5145             : 
    5146             : opt_inline_handler:
    5147         126 :             INLINE_P handler_name                   { $$ = $2; }
    5148          18 :             | /*EMPTY*/                             { $$ = NIL; }
    5149             :         ;
    5150             : 
    5151             : validator_clause:
    5152         126 :             VALIDATOR handler_name                  { $$ = $2; }
    5153           0 :             | NO VALIDATOR                          { $$ = NIL; }
    5154             :         ;
    5155             : 
    5156             : opt_validator:
    5157         126 :             validator_clause                        { $$ = $1; }
    5158          18 :             | /*EMPTY*/                             { $$ = NIL; }
    5159             :         ;
    5160             : 
    5161             : opt_procedural:
    5162             :             PROCEDURAL
    5163             :             | /*EMPTY*/
    5164             :         ;
    5165             : 
    5166             : /*****************************************************************************
    5167             :  *
    5168             :  *      QUERY:
    5169             :  *             CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
    5170             :  *
    5171             :  *****************************************************************************/
    5172             : 
    5173             : CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
    5174             :                 {
    5175         116 :                     CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
    5176             : 
    5177         116 :                     n->tablespacename = $3;
    5178         116 :                     n->owner = $4;
    5179         116 :                     n->location = $6;
    5180         116 :                     n->options = $7;
    5181         116 :                     $$ = (Node *) n;
    5182             :                 }
    5183             :         ;
    5184             : 
    5185           6 : OptTableSpaceOwner: OWNER RoleSpec      { $$ = $2; }
    5186         110 :             | /*EMPTY */                { $$ = NULL; }
    5187             :         ;
    5188             : 
    5189             : /*****************************************************************************
    5190             :  *
    5191             :  *      QUERY :
    5192             :  *              DROP TABLESPACE <tablespace>
    5193             :  *
    5194             :  *      No need for drop behaviour as we cannot implement dependencies for
    5195             :  *      objects in other databases; we can only support RESTRICT.
    5196             :  *
    5197             :  ****************************************************************************/
    5198             : 
    5199             : DropTableSpaceStmt: DROP TABLESPACE name
    5200             :                 {
    5201          64 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    5202             : 
    5203          64 :                     n->tablespacename = $3;
    5204          64 :                     n->missing_ok = false;
    5205          64 :                     $$ = (Node *) n;
    5206             :                 }
    5207             :                 |  DROP TABLESPACE IF_P EXISTS name
    5208             :                 {
    5209           0 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    5210             : 
    5211           0 :                     n->tablespacename = $5;
    5212           0 :                     n->missing_ok = true;
    5213           0 :                     $$ = (Node *) n;
    5214             :                 }
    5215             :         ;
    5216             : 
    5217             : /*****************************************************************************
    5218             :  *
    5219             :  *      QUERY:
    5220             :  *             CREATE EXTENSION extension
    5221             :  *             [ WITH ] [ SCHEMA schema ] [ VERSION version ]
    5222             :  *
    5223             :  *****************************************************************************/
    5224             : 
    5225             : CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
    5226             :                 {
    5227         516 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5228             : 
    5229         516 :                     n->extname = $3;
    5230         516 :                     n->if_not_exists = false;
    5231         516 :                     n->options = $5;
    5232         516 :                     $$ = (Node *) n;
    5233             :                 }
    5234             :                 | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
    5235             :                 {
    5236          18 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5237             : 
    5238          18 :                     n->extname = $6;
    5239          18 :                     n->if_not_exists = true;
    5240          18 :                     n->options = $8;
    5241          18 :                     $$ = (Node *) n;
    5242             :                 }
    5243             :         ;
    5244             : 
    5245             : create_extension_opt_list:
    5246             :             create_extension_opt_list create_extension_opt_item
    5247          98 :                 { $$ = lappend($1, $2); }
    5248             :             | /* EMPTY */
    5249         534 :                 { $$ = NIL; }
    5250             :         ;
    5251             : 
    5252             : create_extension_opt_item:
    5253             :             SCHEMA name
    5254             :                 {
    5255          46 :                     $$ = makeDefElem("schema", (Node *) makeString($2), @1);
    5256             :                 }
    5257             :             | VERSION_P NonReservedWord_or_Sconst
    5258             :                 {
    5259          12 :                     $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
    5260             :                 }
    5261             :             | FROM NonReservedWord_or_Sconst
    5262             :                 {
    5263           0 :                     ereport(ERROR,
    5264             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    5265             :                              errmsg("CREATE EXTENSION ... FROM is no longer supported"),
    5266             :                              parser_errposition(@1)));
    5267             :                 }
    5268             :             | CASCADE
    5269             :                 {
    5270          40 :                     $$ = makeDefElem("cascade", (Node *) makeBoolean(true), @1);
    5271             :                 }
    5272             :         ;
    5273             : 
    5274             : /*****************************************************************************
    5275             :  *
    5276             :  * ALTER EXTENSION name UPDATE [ TO version ]
    5277             :  *
    5278             :  *****************************************************************************/
    5279             : 
    5280             : AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
    5281             :                 {
    5282          38 :                     AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
    5283             : 
    5284          38 :                     n->extname = $3;
    5285          38 :                     n->options = $5;
    5286          38 :                     $$ = (Node *) n;
    5287             :                 }
    5288             :         ;
    5289             : 
    5290             : alter_extension_opt_list:
    5291             :             alter_extension_opt_list alter_extension_opt_item
    5292          38 :                 { $$ = lappend($1, $2); }
    5293             :             | /* EMPTY */
    5294          38 :                 { $$ = NIL; }
    5295             :         ;
    5296             : 
    5297             : alter_extension_opt_item:
    5298             :             TO NonReservedWord_or_Sconst
    5299             :                 {
    5300          38 :                     $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
    5301             :                 }
    5302             :         ;
    5303             : 
    5304             : /*****************************************************************************
    5305             :  *
    5306             :  * ALTER EXTENSION name ADD/DROP object-identifier
    5307             :  *
    5308             :  *****************************************************************************/
    5309             : 
    5310             : AlterExtensionContentsStmt:
    5311             :             ALTER EXTENSION name add_drop object_type_name name
    5312             :                 {
    5313          18 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5314             : 
    5315          18 :                     n->extname = $3;
    5316          18 :                     n->action = $4;
    5317          18 :                     n->objtype = $5;
    5318          18 :                     n->object = (Node *) makeString($6);
    5319          18 :                     $$ = (Node *) n;
    5320             :                 }
    5321             :             | ALTER EXTENSION name add_drop object_type_any_name any_name
    5322             :                 {
    5323          76 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5324             : 
    5325          76 :                     n->extname = $3;
    5326          76 :                     n->action = $4;
    5327          76 :                     n->objtype = $5;
    5328          76 :                     n->object = (Node *) $6;
    5329          76 :                     $$ = (Node *) n;
    5330             :                 }
    5331             :             | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
    5332             :                 {
    5333           8 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5334             : 
    5335           8 :                     n->extname = $3;
    5336           8 :                     n->action = $4;
    5337           8 :                     n->objtype = OBJECT_AGGREGATE;
    5338           8 :                     n->object = (Node *) $6;
    5339           8 :                     $$ = (Node *) n;
    5340             :                 }
    5341             :             | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
    5342             :                 {
    5343           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5344             : 
    5345           4 :                     n->extname = $3;
    5346           4 :                     n->action = $4;
    5347           4 :                     n->objtype = OBJECT_CAST;
    5348           4 :                     n->object = (Node *) list_make2($7, $9);
    5349           4 :                     $$ = (Node *) n;
    5350             :                 }
    5351             :             | ALTER EXTENSION name add_drop DOMAIN_P Typename
    5352             :                 {
    5353           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5354             : 
    5355           0 :                     n->extname = $3;
    5356           0 :                     n->action = $4;
    5357           0 :                     n->objtype = OBJECT_DOMAIN;
    5358           0 :                     n->object = (Node *) $6;
    5359           0 :                     $$ = (Node *) n;
    5360             :                 }
    5361             :             | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
    5362             :                 {
    5363          98 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5364             : 
    5365          98 :                     n->extname = $3;
    5366          98 :                     n->action = $4;
    5367          98 :                     n->objtype = OBJECT_FUNCTION;
    5368          98 :                     n->object = (Node *) $6;
    5369          98 :                     $$ = (Node *) n;
    5370             :                 }
    5371             :             | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
    5372             :                 {
    5373          18 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5374             : 
    5375          18 :                     n->extname = $3;
    5376          18 :                     n->action = $4;
    5377          18 :                     n->objtype = OBJECT_OPERATOR;
    5378          18 :                     n->object = (Node *) $6;
    5379          18 :                     $$ = (Node *) n;
    5380             :                 }
    5381             :             | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING name
    5382             :                 {
    5383           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5384             : 
    5385           4 :                     n->extname = $3;
    5386           4 :                     n->action = $4;
    5387           4 :                     n->objtype = OBJECT_OPCLASS;
    5388           4 :                     n->object = (Node *) lcons(makeString($9), $7);
    5389           4 :                     $$ = (Node *) n;
    5390             :                 }
    5391             :             | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING name
    5392             :                 {
    5393           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5394             : 
    5395           4 :                     n->extname = $3;
    5396           4 :                     n->action = $4;
    5397           4 :                     n->objtype = OBJECT_OPFAMILY;
    5398           4 :                     n->object = (Node *) lcons(makeString($9), $7);
    5399           4 :                     $$ = (Node *) n;
    5400             :                 }
    5401             :             | ALTER EXTENSION name add_drop PROCEDURE function_with_argtypes
    5402             :                 {
    5403           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5404             : 
    5405           0 :                     n->extname = $3;
    5406           0 :                     n->action = $4;
    5407           0 :                     n->objtype = OBJECT_PROCEDURE;
    5408           0 :                     n->object = (Node *) $6;
    5409           0 :                     $$ = (Node *) n;
    5410             :                 }
    5411             :             | ALTER EXTENSION name add_drop ROUTINE function_with_argtypes
    5412             :                 {
    5413           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5414             : 
    5415           0 :                     n->extname = $3;
    5416           0 :                     n->action = $4;
    5417           0 :                     n->objtype = OBJECT_ROUTINE;
    5418           0 :                     n->object = (Node *) $6;
    5419           0 :                     $$ = (Node *) n;
    5420             :                 }
    5421             :             | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
    5422             :                 {
    5423           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5424             : 
    5425           4 :                     n->extname = $3;
    5426           4 :                     n->action = $4;
    5427           4 :                     n->objtype = OBJECT_TRANSFORM;
    5428           4 :                     n->object = (Node *) list_make2($7, makeString($9));
    5429           4 :                     $$ = (Node *) n;
    5430             :                 }
    5431             :             | ALTER EXTENSION name add_drop TYPE_P Typename
    5432             :                 {
    5433           8 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5434             : 
    5435           8 :                     n->extname = $3;
    5436           8 :                     n->action = $4;
    5437           8 :                     n->objtype = OBJECT_TYPE;
    5438           8 :                     n->object = (Node *) $6;
    5439           8 :                     $$ = (Node *) n;
    5440             :                 }
    5441             :         ;
    5442             : 
    5443             : /*****************************************************************************
    5444             :  *
    5445             :  *      QUERY:
    5446             :  *             CREATE FOREIGN DATA WRAPPER name options
    5447             :  *
    5448             :  *****************************************************************************/
    5449             : 
    5450             : CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
    5451             :                 {
    5452         208 :                     CreateFdwStmt *n = makeNode(CreateFdwStmt);
    5453             : 
    5454         208 :                     n->fdwname = $5;
    5455         208 :                     n->func_options = $6;
    5456         208 :                     n->options = $7;
    5457         208 :                     $$ = (Node *) n;
    5458             :                 }
    5459             :         ;
    5460             : 
    5461             : fdw_option:
    5462          56 :             HANDLER handler_name                { $$ = makeDefElem("handler", (Node *) $2, @1); }
    5463           0 :             | NO HANDLER                        { $$ = makeDefElem("handler", NULL, @1); }
    5464          48 :             | VALIDATOR handler_name            { $$ = makeDefElem("validator", (Node *) $2, @1); }
    5465           6 :             | NO VALIDATOR                      { $$ = makeDefElem("validator", NULL, @1); }
    5466             :         ;
    5467             : 
    5468             : fdw_options:
    5469          90 :             fdw_option                          { $$ = list_make1($1); }
    5470          20 :             | fdw_options fdw_option            { $$ = lappend($1, $2); }
    5471             :         ;
    5472             : 
    5473             : opt_fdw_options:
    5474          54 :             fdw_options                         { $$ = $1; }
    5475         246 :             | /*EMPTY*/                         { $$ = NIL; }
    5476             :         ;
    5477             : 
    5478             : /*****************************************************************************
    5479             :  *
    5480             :  *      QUERY :
    5481             :  *              ALTER FOREIGN DATA WRAPPER name options
    5482             :  *
    5483             :  ****************************************************************************/
    5484             : 
    5485             : AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
    5486             :                 {
    5487          86 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5488             : 
    5489          86 :                     n->fdwname = $5;
    5490          86 :                     n->func_options = $6;
    5491          86 :                     n->options = $7;
    5492          86 :                     $$ = (Node *) n;
    5493             :                 }
    5494             :             | ALTER FOREIGN DATA_P WRAPPER name fdw_options
    5495             :                 {
    5496          36 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5497             : 
    5498          36 :                     n->fdwname = $5;
    5499          36 :                     n->func_options = $6;
    5500          36 :                     n->options = NIL;
    5501          36 :                     $$ = (Node *) n;
    5502             :                 }
    5503             :         ;
    5504             : 
    5505             : /* Options definition for CREATE FDW, SERVER and USER MAPPING */
    5506             : create_generic_options:
    5507         738 :             OPTIONS '(' generic_option_list ')'         { $$ = $3; }
    5508       73346 :             | /*EMPTY*/                                 { $$ = NIL; }
    5509             :         ;
    5510             : 
    5511             : generic_option_list:
    5512             :             generic_option_elem
    5513             :                 {
    5514         738 :                     $$ = list_make1($1);
    5515             :                 }
    5516             :             | generic_option_list ',' generic_option_elem
    5517             :                 {
    5518         480 :                     $$ = lappend($1, $3);
    5519             :                 }
    5520             :         ;
    5521             : 
    5522             : /* Options definition for ALTER FDW, SERVER and USER MAPPING */
    5523             : alter_generic_options:
    5524         504 :             OPTIONS '(' alter_generic_option_list ')'       { $$ = $3; }
    5525             :         ;
    5526             : 
    5527             : alter_generic_option_list:
    5528             :             alter_generic_option_elem
    5529             :                 {
    5530         504 :                     $$ = list_make1($1);
    5531             :                 }
    5532             :             | alter_generic_option_list ',' alter_generic_option_elem
    5533             :                 {
    5534         168 :                     $$ = lappend($1, $3);
    5535             :                 }
    5536             :         ;
    5537             : 
    5538             : alter_generic_option_elem:
    5539             :             generic_option_elem
    5540             :                 {
    5541         200 :                     $$ = $1;
    5542             :                 }
    5543             :             | SET generic_option_elem
    5544             :                 {
    5545         128 :                     $$ = $2;
    5546         128 :                     $$->defaction = DEFELEM_SET;
    5547             :                 }
    5548             :             | ADD_P generic_option_elem
    5549             :                 {
    5550         218 :                     $$ = $2;
    5551         218 :                     $$->defaction = DEFELEM_ADD;
    5552             :                 }
    5553             :             | DROP generic_option_name
    5554             :                 {
    5555         126 :                     $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP, @2);
    5556             :                 }
    5557             :         ;
    5558             : 
    5559             : generic_option_elem:
    5560             :             generic_option_name generic_option_arg
    5561             :                 {
    5562        1764 :                     $$ = makeDefElem($1, $2, @1);
    5563             :                 }
    5564             :         ;
    5565             : 
    5566             : generic_option_name:
    5567        1890 :                 ColLabel            { $$ = $1; }
    5568             :         ;
    5569             : 
    5570             : /* We could use def_arg here, but the spec only requires string literals */
    5571             : generic_option_arg:
    5572        1764 :                 Sconst              { $$ = (Node *) makeString($1); }
    5573             :         ;
    5574             : 
    5575             : /*****************************************************************************
    5576             :  *
    5577             :  *      QUERY:
    5578             :  *             CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
    5579             :  *
    5580             :  *****************************************************************************/
    5581             : 
    5582             : CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
    5583             :                          FOREIGN DATA_P WRAPPER name create_generic_options
    5584             :                 {
    5585         274 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5586             : 
    5587         274 :                     n->servername = $3;
    5588         274 :                     n->servertype = $4;
    5589         274 :                     n->version = $5;
    5590         274 :                     n->fdwname = $9;
    5591         274 :                     n->options = $10;
    5592         274 :                     n->if_not_exists = false;
    5593         274 :                     $$ = (Node *) n;
    5594             :                 }
    5595             :                 | CREATE SERVER IF_P NOT EXISTS name opt_type opt_foreign_server_version
    5596             :                          FOREIGN DATA_P WRAPPER name create_generic_options
    5597             :                 {
    5598          24 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5599             : 
    5600          24 :                     n->servername = $6;
    5601          24 :                     n->servertype = $7;
    5602          24 :                     n->version = $8;
    5603          24 :                     n->fdwname = $12;
    5604          24 :                     n->options = $13;
    5605          24 :                     n->if_not_exists = true;
    5606          24 :                     $$ = (Node *) n;
    5607             :                 }
    5608             :         ;
    5609             : 
    5610             : opt_type:
    5611          18 :             TYPE_P Sconst           { $$ = $2; }
    5612         280 :             | /*EMPTY*/             { $$ = NULL; }
    5613             :         ;
    5614             : 
    5615             : 
    5616             : foreign_server_version:
    5617          66 :             VERSION_P Sconst        { $$ = $2; }
    5618           0 :         |   VERSION_P NULL_P        { $$ = NULL; }
    5619             :         ;
    5620             : 
    5621             : opt_foreign_server_version:
    5622          18 :             foreign_server_version  { $$ = $1; }
    5623         280 :             | /*EMPTY*/             { $$ = NULL; }
    5624             :         ;
    5625             : 
    5626             : /*****************************************************************************
    5627             :  *
    5628             :  *      QUERY :
    5629             :  *              ALTER SERVER name [VERSION] [OPTIONS]
    5630             :  *
    5631             :  ****************************************************************************/
    5632             : 
    5633             : AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
    5634             :                 {
    5635           6 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5636             : 
    5637           6 :                     n->servername = $3;
    5638           6 :                     n->version = $4;
    5639           6 :                     n->options = $5;
    5640           6 :                     n->has_version = true;
    5641           6 :                     $$ = (Node *) n;
    5642             :                 }
    5643             :             | ALTER SERVER name foreign_server_version
    5644             :                 {
    5645          42 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5646             : 
    5647          42 :                     n->servername = $3;
    5648          42 :                     n->version = $4;
    5649          42 :                     n->has_version = true;
    5650          42 :                     $$ = (Node *) n;
    5651             :                 }
    5652             :             | ALTER SERVER name alter_generic_options
    5653             :                 {
    5654         180 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5655             : 
    5656         180 :                     n->servername = $3;
    5657         180 :                     n->options = $4;
    5658         180 :                     $$ = (Node *) n;
    5659             :                 }
    5660             :         ;
    5661             : 
    5662             : /*****************************************************************************
    5663             :  *
    5664             :  *      QUERY:
    5665             :  *             CREATE FOREIGN TABLE relname (...) SERVER name (...)
    5666             :  *
    5667             :  *****************************************************************************/
    5668             : 
    5669             : CreateForeignTableStmt:
    5670             :         CREATE FOREIGN TABLE qualified_name
    5671             :             '(' OptTableElementList ')'
    5672             :             OptInherit SERVER name create_generic_options
    5673             :                 {
    5674         394 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5675             : 
    5676         394 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5677         394 :                     n->base.relation = $4;
    5678         394 :                     n->base.tableElts = $6;
    5679         394 :                     n->base.inhRelations = $8;
    5680         394 :                     n->base.ofTypename = NULL;
    5681         394 :                     n->base.constraints = NIL;
    5682         394 :                     n->base.options = NIL;
    5683         394 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5684         394 :                     n->base.tablespacename = NULL;
    5685         394 :                     n->base.if_not_exists = false;
    5686             :                     /* FDW-specific data */
    5687         394 :                     n->servername = $10;
    5688         394 :                     n->options = $11;
    5689         394 :                     $$ = (Node *) n;
    5690             :                 }
    5691             :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5692             :             '(' OptTableElementList ')'
    5693             :             OptInherit SERVER name create_generic_options
    5694             :                 {
    5695           0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5696             : 
    5697           0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5698           0 :                     n->base.relation = $7;
    5699           0 :                     n->base.tableElts = $9;
    5700           0 :                     n->base.inhRelations = $11;
    5701           0 :                     n->base.ofTypename = NULL;
    5702           0 :                     n->base.constraints = NIL;
    5703           0 :                     n->base.options = NIL;
    5704           0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5705           0 :                     n->base.tablespacename = NULL;
    5706           0 :                     n->base.if_not_exists = true;
    5707             :                     /* FDW-specific data */
    5708           0 :                     n->servername = $13;
    5709           0 :                     n->options = $14;
    5710           0 :                     $$ = (Node *) n;
    5711             :                 }
    5712             :         | CREATE FOREIGN TABLE qualified_name
    5713             :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5714             :             SERVER name create_generic_options
    5715             :                 {
    5716          90 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5717             : 
    5718          90 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5719          90 :                     n->base.relation = $4;
    5720          90 :                     n->base.inhRelations = list_make1($7);
    5721          90 :                     n->base.tableElts = $8;
    5722          90 :                     n->base.partbound = $9;
    5723          90 :                     n->base.ofTypename = NULL;
    5724          90 :                     n->base.constraints = NIL;
    5725          90 :                     n->base.options = NIL;
    5726          90 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5727          90 :                     n->base.tablespacename = NULL;
    5728          90 :                     n->base.if_not_exists = false;
    5729             :                     /* FDW-specific data */
    5730          90 :                     n->servername = $11;
    5731          90 :                     n->options = $12;
    5732          90 :                     $$ = (Node *) n;
    5733             :                 }
    5734             :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5735             :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5736             :             SERVER name create_generic_options
    5737             :                 {
    5738           0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5739             : 
    5740           0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5741           0 :                     n->base.relation = $7;
    5742           0 :                     n->base.inhRelations = list_make1($10);
    5743           0 :                     n->base.tableElts = $11;
    5744           0 :                     n->base.partbound = $12;
    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 = $14;
    5753           0 :                     n->options = $15;
    5754           0 :                     $$ = (Node *) n;
    5755             :                 }
    5756             :         ;
    5757             : 
    5758             : /*****************************************************************************
    5759             :  *
    5760             :  *      QUERY:
    5761             :  *              IMPORT FOREIGN SCHEMA remote_schema
    5762             :  *              [ { LIMIT TO | EXCEPT } ( table_list ) ]
    5763             :  *              FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
    5764             :  *
    5765             :  ****************************************************************************/
    5766             : 
    5767             : ImportForeignSchemaStmt:
    5768             :         IMPORT_P FOREIGN SCHEMA name import_qualification
    5769             :           FROM SERVER name INTO name create_generic_options
    5770             :             {
    5771          48 :                 ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
    5772             : 
    5773          48 :                 n->server_name = $8;
    5774          48 :                 n->remote_schema = $4;
    5775          48 :                 n->local_schema = $10;
    5776          48 :                 n->list_type = $5->type;
    5777          48 :                 n->table_list = $5->table_names;
    5778          48 :                 n->options = $11;
    5779          48 :                 $$ = (Node *) n;
    5780             :             }
    5781             :         ;
    5782             : 
    5783             : import_qualification_type:
    5784          14 :         LIMIT TO                { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
    5785          14 :         | EXCEPT                { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
    5786             :         ;
    5787             : 
    5788             : import_qualification:
    5789             :         import_qualification_type '(' relation_expr_list ')'
    5790             :             {
    5791          28 :                 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
    5792             : 
    5793          28 :                 n->type = $1;
    5794          28 :                 n->table_names = $3;
    5795          28 :                 $$ = n;
    5796             :             }
    5797             :         | /*EMPTY*/
    5798             :             {
    5799          20 :                 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
    5800          20 :                 n->type = FDW_IMPORT_SCHEMA_ALL;
    5801          20 :                 n->table_names = NIL;
    5802          20 :                 $$ = n;
    5803             :             }
    5804             :         ;
    5805             : 
    5806             : /*****************************************************************************
    5807             :  *
    5808             :  *      QUERY:
    5809             :  *             CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
    5810             :  *
    5811             :  *****************************************************************************/
    5812             : 
    5813             : CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
    5814             :                 {
    5815         246 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5816             : 
    5817         246 :                     n->user = $5;
    5818         246 :                     n->servername = $7;
    5819         246 :                     n->options = $8;
    5820         246 :                     n->if_not_exists = false;
    5821         246 :                     $$ = (Node *) n;
    5822             :                 }
    5823             :                 | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
    5824             :                 {
    5825           6 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5826             : 
    5827           6 :                     n->user = $8;
    5828           6 :                     n->servername = $10;
    5829           6 :                     n->options = $11;
    5830           6 :                     n->if_not_exists = true;
    5831           6 :                     $$ = (Node *) n;
    5832             :                 }
    5833             :         ;
    5834             : 
    5835             : /* User mapping authorization identifier */
    5836         450 : auth_ident: RoleSpec            { $$ = $1; }
    5837          46 :             | USER              { $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1); }
    5838             :         ;
    5839             : 
    5840             : /*****************************************************************************
    5841             :  *
    5842             :  *      QUERY :
    5843             :  *              DROP USER MAPPING FOR auth_ident SERVER name
    5844             :  *
    5845             :  * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
    5846             :  * only pro forma; but the SQL standard doesn't show one.
    5847             :  ****************************************************************************/
    5848             : 
    5849             : DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
    5850             :                 {
    5851          88 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5852             : 
    5853          88 :                     n->user = $5;
    5854          88 :                     n->servername = $7;
    5855          88 :                     n->missing_ok = false;
    5856          88 :                     $$ = (Node *) n;
    5857             :                 }
    5858             :                 |  DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
    5859             :                 {
    5860          38 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5861             : 
    5862          38 :                     n->user = $7;
    5863          38 :                     n->servername = $9;
    5864          38 :                     n->missing_ok = true;
    5865          38 :                     $$ = (Node *) n;
    5866             :                 }
    5867             :         ;
    5868             : 
    5869             : /*****************************************************************************
    5870             :  *
    5871             :  *      QUERY :
    5872             :  *              ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
    5873             :  *
    5874             :  ****************************************************************************/
    5875             : 
    5876             : AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
    5877             :                 {
    5878         118 :                     AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
    5879             : 
    5880         118 :                     n->user = $5;
    5881         118 :                     n->servername = $7;
    5882         118 :                     n->options = $8;
    5883         118 :                     $$ = (Node *) n;
    5884             :                 }
    5885             :         ;
    5886             : 
    5887             : /*****************************************************************************
    5888             :  *
    5889             :  *      QUERIES:
    5890             :  *              CREATE POLICY name ON table
    5891             :  *                  [AS { PERMISSIVE | RESTRICTIVE } ]
    5892             :  *                  [FOR { SELECT | INSERT | UPDATE | DELETE } ]
    5893             :  *                  [TO role, ...]
    5894             :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    5895             :  *              ALTER POLICY name ON table [TO role, ...]
    5896             :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    5897             :  *
    5898             :  *****************************************************************************/
    5899             : 
    5900             : CreatePolicyStmt:
    5901             :             CREATE POLICY name ON qualified_name RowSecurityDefaultPermissive
    5902             :                 RowSecurityDefaultForCmd RowSecurityDefaultToRole
    5903             :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    5904             :                 {
    5905         706 :                     CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
    5906             : 
    5907         706 :                     n->policy_name = $3;
    5908         706 :                     n->table = $5;
    5909         706 :                     n->permissive = $6;
    5910         706 :                     n->cmd_name = $7;
    5911         706 :                     n->roles = $8;
    5912         706 :                     n->qual = $9;
    5913         706 :                     n->with_check = $10;
    5914         706 :                     $$ = (Node *) n;
    5915             :                 }
    5916             :         ;
    5917             : 
    5918             : AlterPolicyStmt:
    5919             :             ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
    5920             :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    5921             :                 {
    5922          84 :                     AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
    5923             : 
    5924          84 :                     n->policy_name = $3;
    5925          84 :                     n->table = $5;
    5926          84 :                     n->roles = $6;
    5927          84 :                     n->qual = $7;
    5928          84 :                     n->with_check = $8;
    5929          84 :                     $$ = (Node *) n;
    5930             :                 }
    5931             :         ;
    5932             : 
    5933             : RowSecurityOptionalExpr:
    5934         732 :             USING '(' a_expr ')'    { $$ = $3; }
    5935          58 :             | /* EMPTY */           { $$ = NULL; }
    5936             :         ;
    5937             : 
    5938             : RowSecurityOptionalWithCheck:
    5939         128 :             WITH CHECK '(' a_expr ')'       { $$ = $4; }
    5940         662 :             | /* EMPTY */                   { $$ = NULL; }
    5941             :         ;
    5942             : 
    5943             : RowSecurityDefaultToRole:
    5944         130 :             TO role_list            { $$ = $2; }
    5945         576 :             | /* EMPTY */           { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
    5946             :         ;
    5947             : 
    5948             : RowSecurityOptionalToRole:
    5949          12 :             TO role_list            { $$ = $2; }
    5950          72 :             | /* EMPTY */           { $$ = NULL; }
    5951             :         ;
    5952             : 
    5953             : RowSecurityDefaultPermissive:
    5954             :             AS IDENT
    5955             :                 {
    5956          98 :                     if (strcmp($2, "permissive") == 0)
    5957          24 :                         $$ = true;
    5958          74 :                     else if (strcmp($2, "restrictive") == 0)
    5959          68 :                         $$ = false;
    5960             :                     else
    5961           6 :                         ereport(ERROR,
    5962             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    5963             :                                  errmsg("unrecognized row security option \"%s\"", $2),
    5964             :                                  errhint("Only PERMISSIVE or RESTRICTIVE policies are supported currently."),
    5965             :                                  parser_errposition(@2)));
    5966             : 
    5967             :                 }
    5968         614 :             | /* EMPTY */           { $$ = true; }
    5969             :         ;
    5970             : 
    5971             : RowSecurityDefaultForCmd:
    5972         332 :             FOR row_security_cmd    { $$ = $2; }
    5973         374 :             | /* EMPTY */           { $$ = "all"; }
    5974             :         ;
    5975             : 
    5976             : row_security_cmd:
    5977          44 :             ALL             { $$ = "all"; }
    5978         116 :         |   SELECT          { $$ = "select"; }
    5979          44 :         |   INSERT          { $$ = "insert"; }
    5980          82 :         |   UPDATE          { $$ = "update"; }
    5981          46 :         |   DELETE_P        { $$ = "delete"; }
    5982             :         ;
    5983             : 
    5984             : /*****************************************************************************
    5985             :  *
    5986             :  *      QUERY:
    5987             :  *             CREATE ACCESS METHOD name HANDLER handler_name
    5988             :  *
    5989             :  *****************************************************************************/
    5990             : 
    5991             : CreateAmStmt: CREATE ACCESS METHOD name TYPE_P am_type HANDLER handler_name
    5992             :                 {
    5993          64 :                     CreateAmStmt *n = makeNode(CreateAmStmt);
    5994             : 
    5995          64 :                     n->amname = $4;
    5996          64 :                     n->handler_name = $8;
    5997          64 :                     n->amtype = $6;
    5998          64 :                     $$ = (Node *) n;
    5999             :                 }
    6000             :         ;
    6001             : 
    6002             : am_type:
    6003          34 :             INDEX           { $$ = AMTYPE_INDEX; }
    6004          30 :         |   TABLE           { $$ = AMTYPE_TABLE; }
    6005             :         ;
    6006             : 
    6007             : /*****************************************************************************
    6008             :  *
    6009             :  *      QUERIES :
    6010             :  *              CREATE TRIGGER ...
    6011             :  *
    6012             :  *****************************************************************************/
    6013             : 
    6014             : CreateTrigStmt:
    6015             :             CREATE opt_or_replace TRIGGER name TriggerActionTime TriggerEvents ON
    6016             :             qualified_name TriggerReferencing TriggerForSpec TriggerWhen
    6017             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    6018             :                 {
    6019        3260 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    6020             : 
    6021        3260 :                     n->replace = $2;
    6022        3260 :                     n->isconstraint = false;
    6023        3260 :                     n->trigname = $4;
    6024        3260 :                     n->relation = $8;
    6025        3260 :                     n->funcname = $14;
    6026        3260 :                     n->args = $16;
    6027        3260 :                     n->row = $10;
    6028        3260 :                     n->timing = $5;
    6029        3260 :                     n->events = intVal(linitial($6));
    6030        3260 :                     n->columns = (List *) lsecond($6);
    6031        3260 :                     n->whenClause = $11;
    6032        3260 :                     n->transitionRels = $9;
    6033        3260 :                     n->deferrable = false;
    6034        3260 :                     n->initdeferred = false;
    6035        3260 :                     n->constrrel = NULL;
    6036        3260 :                     $$ = (Node *) n;
    6037             :                 }
    6038             :           | CREATE opt_or_replace CONSTRAINT TRIGGER name AFTER TriggerEvents ON
    6039             :             qualified_name OptConstrFromTable ConstraintAttributeSpec
    6040             :             FOR EACH ROW TriggerWhen
    6041             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    6042             :                 {
    6043          80 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    6044             :                     bool        dummy;
    6045             : 
    6046          80 :                     if (($11 & CAS_NOT_VALID) != 0)
    6047           6 :                         ereport(ERROR,
    6048             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6049             :                                 errmsg("constraint triggers cannot be marked %s",
    6050             :                                        "NOT VALID"),
    6051             :                                 parser_errposition(@11));
    6052          74 :                     if (($11 & CAS_NO_INHERIT) != 0)
    6053           6 :                         ereport(ERROR,
    6054             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6055             :                                 errmsg("constraint triggers cannot be marked %s",
    6056             :                                        "NO INHERIT"),
    6057             :                                 parser_errposition(@11));
    6058          68 :                     if (($11 & CAS_NOT_ENFORCED) != 0)
    6059           6 :                         ereport(ERROR,
    6060             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6061             :                                 errmsg("constraint triggers cannot be marked %s",
    6062             :                                        "NOT ENFORCED"),
    6063             :                                 parser_errposition(@11));
    6064             : 
    6065          62 :                     n->replace = $2;
    6066          62 :                     if (n->replace) /* not supported, see CreateTrigger */
    6067           0 :                         ereport(ERROR,
    6068             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6069             :                                  errmsg("CREATE OR REPLACE CONSTRAINT TRIGGER is not supported"),
    6070             :                                  parser_errposition(@1)));
    6071          62 :                     n->isconstraint = true;
    6072          62 :                     n->trigname = $5;
    6073          62 :                     n->relation = $9;
    6074          62 :                     n->funcname = $18;
    6075          62 :                     n->args = $20;
    6076          62 :                     n->row = true;
    6077          62 :                     n->timing = TRIGGER_TYPE_AFTER;
    6078          62 :                     n->events = intVal(linitial($7));
    6079          62 :                     n->columns = (List *) lsecond($7);
    6080          62 :                     n->whenClause = $15;
    6081          62 :                     n->transitionRels = NIL;
    6082          62 :                     processCASbits($11, @11, "TRIGGER",
    6083             :                                    &n->deferrable, &n->initdeferred, &dummy,
    6084             :                                    NULL, NULL, yyscanner);
    6085          62 :                     n->constrrel = $10;
    6086          62 :                     $$ = (Node *) n;
    6087             :                 }
    6088             :         ;
    6089             : 
    6090             : TriggerActionTime:
    6091        1478 :             BEFORE                              { $$ = TRIGGER_TYPE_BEFORE; }
    6092        1650 :             | AFTER                             { $$ = TRIGGER_TYPE_AFTER; }
    6093         144 :             | INSTEAD OF                        { $$ = TRIGGER_TYPE_INSTEAD; }
    6094             :         ;
    6095             : 
    6096             : TriggerEvents:
    6097             :             TriggerOneEvent
    6098        3352 :                 { $$ = $1; }
    6099             :             | TriggerEvents OR TriggerOneEvent
    6100             :                 {
    6101        1212 :                     int         events1 = intVal(linitial($1));
    6102        1212 :                     int         events2 = intVal(linitial($3));
    6103        1212 :                     List       *columns1 = (List *) lsecond($1);
    6104        1212 :                     List       *columns2 = (List *) lsecond($3);
    6105             : 
    6106        1212 :                     if (events1 & events2)
    6107           6 :                         parser_yyerror("duplicate trigger events specified");
    6108             :                     /*
    6109             :                      * concat'ing the columns lists loses information about
    6110             :                      * which columns went with which event, but so long as
    6111             :                      * only UPDATE carries columns and we disallow multiple
    6112             :                      * UPDATE items, it doesn't matter.  Command execution
    6113             :                      * should just ignore the columns for non-UPDATE events.
    6114             :                      */
    6115        1206 :                     $$ = list_make2(makeInteger(events1 | events2),
    6116             :                                     list_concat(columns1, columns2));
    6117             :                 }
    6118             :         ;
    6119             : 
    6120             : TriggerOneEvent:
    6121             :             INSERT
    6122        1728 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
    6123             :             | DELETE_P
    6124         896 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
    6125             :             | UPDATE
    6126        1794 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
    6127             :             | UPDATE OF columnList
    6128         108 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
    6129             :             | TRUNCATE
    6130          38 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
    6131             :         ;
    6132             : 
    6133             : TriggerReferencing:
    6134         470 :             REFERENCING TriggerTransitions          { $$ = $2; }
    6135        2790 :             | /*EMPTY*/                             { $$ = NIL; }
    6136             :         ;
    6137             : 
    6138             : TriggerTransitions:
    6139         470 :             TriggerTransition                       { $$ = list_make1($1); }
    6140         144 :             | TriggerTransitions TriggerTransition  { $$ = lappend($1, $2); }
    6141             :         ;
    6142             : 
    6143             : TriggerTransition:
    6144             :             TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
    6145             :                 {
    6146         614 :                     TriggerTransition *n = makeNode(TriggerTransition);
    6147             : 
    6148         614 :                     n->name = $4;
    6149         614 :                     n->isNew = $1;
    6150         614 :                     n->isTable = $2;
    6151         614 :                     $$ = (Node *) n;
    6152             :                 }
    6153             :         ;
    6154             : 
    6155             : TransitionOldOrNew:
    6156         336 :             NEW                                     { $$ = true; }
    6157         278 :             | OLD                                   { $$ = false; }
    6158             :         ;
    6159             : 
    6160             : TransitionRowOrTable:
    6161         614 :             TABLE                                   { $$ = true; }
    6162             :             /*
    6163             :              * According to the standard, lack of a keyword here implies ROW.
    6164             :              * Support for that would require prohibiting ROW entirely here,
    6165             :              * reserving the keyword ROW, and/or requiring AS (instead of
    6166             :              * allowing it to be optional, as the standard specifies) as the
    6167             :              * next token.  Requiring ROW seems cleanest and easiest to
    6168             :              * explain.
    6169             :              */
    6170           0 :             | ROW                                   { $$ = false; }
    6171             :         ;
    6172             : 
    6173             : TransitionRelName:
    6174         614 :             ColId                                   { $$ = $1; }
    6175             :         ;
    6176             : 
    6177             : TriggerForSpec:
    6178             :             FOR TriggerForOptEach TriggerForType
    6179             :                 {
    6180        3032 :                     $$ = $3;
    6181             :                 }
    6182             :             | /* EMPTY */
    6183             :                 {
    6184             :                     /*
    6185             :                      * If ROW/STATEMENT not specified, default to
    6186             :                      * STATEMENT, per SQL
    6187             :                      */
    6188         228 :                     $$ = false;
    6189             :                 }
    6190             :         ;
    6191             : 
    6192             : TriggerForOptEach:
    6193             :             EACH
    6194             :             | /*EMPTY*/
    6195             :         ;
    6196             : 
    6197             : TriggerForType:
    6198        2196 :             ROW                                     { $$ = true; }
    6199         836 :             | STATEMENT                             { $$ = false; }
    6200             :         ;
    6201             : 
    6202             : TriggerWhen:
    6203         194 :             WHEN '(' a_expr ')'                     { $$ = $3; }
    6204        3146 :             | /*EMPTY*/                             { $$ = NULL; }
    6205             :         ;
    6206             : 
    6207             : FUNCTION_or_PROCEDURE:
    6208             :             FUNCTION
    6209             :         |   PROCEDURE
    6210             :         ;
    6211             : 
    6212             : TriggerFuncArgs:
    6213         588 :             TriggerFuncArg                          { $$ = list_make1($1); }
    6214         166 :             | TriggerFuncArgs ',' TriggerFuncArg    { $$ = lappend($1, $3); }
    6215        2752 :             | /*EMPTY*/                             { $$ = NIL; }
    6216             :         ;
    6217             : 
    6218             : TriggerFuncArg:
    6219             :             Iconst
    6220             :                 {
    6221          94 :                     $$ = (Node *) makeString(psprintf("%d", $1));
    6222             :                 }
    6223           0 :             | FCONST                                { $$ = (Node *) makeString($1); }
    6224         638 :             | Sconst                                { $$ = (Node *) makeString($1); }
    6225          22 :             | ColLabel                              { $$ = (Node *) makeString($1); }
    6226             :         ;
    6227             : 
    6228             : OptConstrFromTable:
    6229          12 :             FROM qualified_name                     { $$ = $2; }
    6230          68 :             | /*EMPTY*/                             { $$ = NULL; }
    6231             :         ;
    6232             : 
    6233             : ConstraintAttributeSpec:
    6234             :             /*EMPTY*/
    6235       18452 :                 { $$ = 0; }
    6236             :             | ConstraintAttributeSpec ConstraintAttributeElem
    6237             :                 {
    6238             :                     /*
    6239             :                      * We must complain about conflicting options.
    6240             :                      * We could, but choose not to, complain about redundant
    6241             :                      * options (ie, where $2's bit is already set in $1).
    6242             :                      */
    6243        1718 :                     int     newspec = $1 | $2;
    6244             : 
    6245             :                     /* special message for this case */
    6246        1718 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
    6247           6 :                         ereport(ERROR,
    6248             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6249             :                                  errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
    6250             :                                  parser_errposition(@2)));
    6251             :                     /* generic message for other conflicts */
    6252        1712 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
    6253        1712 :                         (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED) ||
    6254        1712 :                         (newspec & (CAS_NOT_ENFORCED | CAS_ENFORCED)) == (CAS_NOT_ENFORCED | CAS_ENFORCED))
    6255           6 :                         ereport(ERROR,
    6256             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6257             :                                  errmsg("conflicting constraint properties"),
    6258             :                                  parser_errposition(@2)));
    6259        1706 :                     $$ = newspec;
    6260             :                 }
    6261             :         ;
    6262             : 
    6263             : ConstraintAttributeElem:
    6264          42 :             NOT DEFERRABLE                  { $$ = CAS_NOT_DEFERRABLE; }
    6265         212 :             | DEFERRABLE                    { $$ = CAS_DEFERRABLE; }
    6266          30 :             | INITIALLY IMMEDIATE           { $$ = CAS_INITIALLY_IMMEDIATE; }
    6267         158 :             | INITIALLY DEFERRED            { $$ = CAS_INITIALLY_DEFERRED; }
    6268         740 :             | NOT VALID                     { $$ = CAS_NOT_VALID; }
    6269         254 :             | NO INHERIT                    { $$ = CAS_NO_INHERIT; }
    6270         174 :             | NOT ENFORCED                  { $$ = CAS_NOT_ENFORCED; }
    6271         108 :             | ENFORCED                      { $$ = CAS_ENFORCED; }
    6272             :         ;
    6273             : 
    6274             : 
    6275             : /*****************************************************************************
    6276             :  *
    6277             :  *      QUERIES :
    6278             :  *              CREATE EVENT TRIGGER ...
    6279             :  *              ALTER EVENT TRIGGER ...
    6280             :  *
    6281             :  *****************************************************************************/
    6282             : 
    6283             : CreateEventTrigStmt:
    6284             :             CREATE EVENT TRIGGER name ON ColLabel
    6285             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    6286             :                 {
    6287          98 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6288             : 
    6289          98 :                     n->trigname = $4;
    6290          98 :                     n->eventname = $6;
    6291          98 :                     n->whenclause = NULL;
    6292          98 :                     n->funcname = $9;
    6293          98 :                     $$ = (Node *) n;
    6294             :                 }
    6295             :           | CREATE EVENT TRIGGER name ON ColLabel
    6296             :             WHEN event_trigger_when_list
    6297             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    6298             :                 {
    6299         100 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6300             : 
    6301         100 :                     n->trigname = $4;
    6302         100 :                     n->eventname = $6;
    6303         100 :                     n->whenclause = $8;
    6304         100 :                     n->funcname = $11;
    6305         100 :                     $$ = (Node *) n;
    6306             :                 }
    6307             :         ;
    6308             : 
    6309             : event_trigger_when_list:
    6310             :           event_trigger_when_item
    6311         100 :             { $$ = list_make1($1); }
    6312             :         | event_trigger_when_list AND event_trigger_when_item
    6313           6 :             { $$ = lappend($1, $3); }
    6314             :         ;
    6315             : 
    6316             : event_trigger_when_item:
    6317             :         ColId IN_P '(' event_trigger_value_list ')'
    6318         106 :             { $$ = makeDefElem($1, (Node *) $4, @1); }
    6319             :         ;
    6320             : 
    6321             : event_trigger_value_list:
    6322             :           SCONST
    6323         106 :             { $$ = list_make1(makeString($1)); }
    6324             :         | event_trigger_value_list ',' SCONST
    6325          66 :             { $$ = lappend($1, makeString($3)); }
    6326             :         ;
    6327             : 
    6328             : AlterEventTrigStmt:
    6329             :             ALTER EVENT TRIGGER name enable_trigger
    6330             :                 {
    6331          48 :                     AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
    6332             : 
    6333          48 :                     n->trigname = $4;
    6334          48 :                     n->tgenabled = $5;
    6335          48 :                     $$ = (Node *) n;
    6336             :                 }
    6337             :         ;
    6338             : 
    6339             : enable_trigger:
    6340           6 :             ENABLE_P                    { $$ = TRIGGER_FIRES_ON_ORIGIN; }
    6341           6 :             | ENABLE_P REPLICA          { $$ = TRIGGER_FIRES_ON_REPLICA; }
    6342          16 :             | ENABLE_P ALWAYS           { $$ = TRIGGER_FIRES_ALWAYS; }
    6343          20 :             | DISABLE_P                 { $$ = TRIGGER_DISABLED; }
    6344             :         ;
    6345             : 
    6346             : /*****************************************************************************
    6347             :  *
    6348             :  *      QUERY :
    6349             :  *              CREATE ASSERTION ...
    6350             :  *
    6351             :  *****************************************************************************/
    6352             : 
    6353             : CreateAssertionStmt:
    6354             :             CREATE ASSERTION any_name CHECK '(' a_expr ')' ConstraintAttributeSpec
    6355             :                 {
    6356           0 :                     ereport(ERROR,
    6357             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6358             :                              errmsg("CREATE ASSERTION is not yet implemented"),
    6359             :                              parser_errposition(@1)));
    6360             : 
    6361             :                     $$ = NULL;
    6362             :                 }
    6363             :         ;
    6364             : 
    6365             : 
    6366             : /*****************************************************************************
    6367             :  *
    6368             :  *      QUERY :
    6369             :  *              define (aggregate,operator,type)
    6370             :  *
    6371             :  *****************************************************************************/
    6372             : 
    6373             : DefineStmt:
    6374             :             CREATE opt_or_replace AGGREGATE func_name aggr_args definition
    6375             :                 {
    6376         638 :                     DefineStmt *n = makeNode(DefineStmt);
    6377             : 
    6378         638 :                     n->kind = OBJECT_AGGREGATE;
    6379         638 :                     n->oldstyle = false;
    6380         638 :                     n->replace = $2;
    6381         638 :                     n->defnames = $4;
    6382         638 :                     n->args = $5;
    6383         638 :                     n->definition = $6;
    6384         638 :                     $$ = (Node *) n;
    6385             :                 }
    6386             :             | CREATE opt_or_replace AGGREGATE func_name old_aggr_definition
    6387             :                 {
    6388             :                     /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
    6389         362 :                     DefineStmt *n = makeNode(DefineStmt);
    6390             : 
    6391         362 :                     n->kind = OBJECT_AGGREGATE;
    6392         362 :                     n->oldstyle = true;
    6393         362 :                     n->replace = $2;
    6394         362 :                     n->defnames = $4;
    6395         362 :                     n->args = NIL;
    6396         362 :                     n->definition = $5;
    6397         362 :                     $$ = (Node *) n;
    6398             :                 }
    6399             :             | CREATE OPERATOR any_operator definition
    6400             :                 {
    6401        1610 :                     DefineStmt *n = makeNode(DefineStmt);
    6402             : 
    6403        1610 :                     n->kind = OBJECT_OPERATOR;
    6404        1610 :                     n->oldstyle = false;
    6405        1610 :                     n->defnames = $3;
    6406        1610 :                     n->args = NIL;
    6407        1610 :                     n->definition = $4;
    6408        1610 :                     $$ = (Node *) n;
    6409             :                 }
    6410             :             | CREATE TYPE_P any_name definition
    6411             :                 {
    6412         230 :                     DefineStmt *n = makeNode(DefineStmt);
    6413             : 
    6414         230 :                     n->kind = OBJECT_TYPE;
    6415         230 :                     n->oldstyle = false;
    6416         230 :                     n->defnames = $3;
    6417         230 :                     n->args = NIL;
    6418         230 :                     n->definition = $4;
    6419         230 :                     $$ = (Node *) n;
    6420             :                 }
    6421             :             | CREATE TYPE_P any_name
    6422             :                 {
    6423             :                     /* Shell type (identified by lack of definition) */
    6424         172 :                     DefineStmt *n = makeNode(DefineStmt);
    6425             : 
    6426         172 :                     n->kind = OBJECT_TYPE;
    6427         172 :                     n->oldstyle = false;
    6428         172 :                     n->defnames = $3;
    6429         172 :                     n->args = NIL;
    6430         172 :                     n->definition = NIL;
    6431         172 :                     $$ = (Node *) n;
    6432             :                 }
    6433             :             | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
    6434             :                 {
    6435        4534 :                     CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
    6436             : 
    6437             :                     /* can't use qualified_name, sigh */
    6438        4534 :                     n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
    6439        4534 :                     n->coldeflist = $6;
    6440        4534 :                     $$ = (Node *) n;
    6441             :                 }
    6442             :             | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
    6443             :                 {
    6444         208 :                     CreateEnumStmt *n = makeNode(CreateEnumStmt);
    6445             : 
    6446         208 :                     n->typeName = $3;
    6447         208 :                     n->vals = $7;
    6448         208 :                     $$ = (Node *) n;
    6449             :                 }
    6450             :             | CREATE TYPE_P any_name AS RANGE definition
    6451             :                 {
    6452         196 :                     CreateRangeStmt *n = makeNode(CreateRangeStmt);
    6453             : 
    6454         196 :                     n->typeName = $3;
    6455         196 :                     n->params = $6;
    6456         196 :                     $$ = (Node *) n;
    6457             :                 }
    6458             :             | CREATE TEXT_P SEARCH PARSER any_name definition
    6459             :                 {
    6460          40 :                     DefineStmt *n = makeNode(DefineStmt);
    6461             : 
    6462          40 :                     n->kind = OBJECT_TSPARSER;
    6463          40 :                     n->args = NIL;
    6464          40 :                     n->defnames = $5;
    6465          40 :                     n->definition = $6;
    6466          40 :                     $$ = (Node *) n;
    6467             :                 }
    6468             :             | CREATE TEXT_P SEARCH DICTIONARY any_name definition
    6469             :                 {
    6470        3006 :                     DefineStmt *n = makeNode(DefineStmt);
    6471             : 
    6472        3006 :                     n->kind = OBJECT_TSDICTIONARY;
    6473        3006 :                     n->args = NIL;
    6474        3006 :                     n->defnames = $5;
    6475        3006 :                     n->definition = $6;
    6476        3006 :                     $$ = (Node *) n;
    6477             :                 }
    6478             :             | CREATE TEXT_P SEARCH TEMPLATE any_name definition
    6479             :                 {
    6480         142 :                     DefineStmt *n = makeNode(DefineStmt);
    6481             : 
    6482         142 :                     n->kind = OBJECT_TSTEMPLATE;
    6483         142 :                     n->args = NIL;
    6484         142 :                     n->defnames = $5;
    6485         142 :                     n->definition = $6;
    6486         142 :                     $$ = (Node *) n;
    6487             :                 }
    6488             :             | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
    6489             :                 {
    6490        2938 :                     DefineStmt *n = makeNode(DefineStmt);
    6491             : 
    6492        2938 :                     n->kind = OBJECT_TSCONFIGURATION;
    6493        2938 :                     n->args = NIL;
    6494        2938 :                     n->defnames = $5;
    6495        2938 :                     n->definition = $6;
    6496        2938 :                     $$ = (Node *) n;
    6497             :                 }
    6498             :             | CREATE COLLATION any_name definition
    6499             :                 {
    6500         298 :                     DefineStmt *n = makeNode(DefineStmt);
    6501             : 
    6502         298 :                     n->kind = OBJECT_COLLATION;
    6503         298 :                     n->args = NIL;
    6504         298 :                     n->defnames = $3;
    6505         298 :                     n->definition = $4;
    6506         298 :                     $$ = (Node *) n;
    6507             :                 }
    6508             :             | CREATE COLLATION IF_P NOT EXISTS any_name definition
    6509             :                 {
    6510          18 :                     DefineStmt *n = makeNode(DefineStmt);
    6511             : 
    6512          18 :                     n->kind = OBJECT_COLLATION;
    6513          18 :                     n->args = NIL;
    6514          18 :                     n->defnames = $6;
    6515          18 :                     n->definition = $7;
    6516          18 :                     n->if_not_exists = true;
    6517          18 :                     $$ = (Node *) n;
    6518             :                 }
    6519             :             | CREATE COLLATION any_name FROM any_name
    6520             :                 {
    6521          54 :                     DefineStmt *n = makeNode(DefineStmt);
    6522             : 
    6523          54 :                     n->kind = OBJECT_COLLATION;
    6524          54 :                     n->args = NIL;
    6525          54 :                     n->defnames = $3;
    6526          54 :                     n->definition = list_make1(makeDefElem("from", (Node *) $5, @5));
    6527          54 :                     $$ = (Node *) n;
    6528             :                 }
    6529             :             | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
    6530             :                 {
    6531           0 :                     DefineStmt *n = makeNode(DefineStmt);
    6532             : 
    6533           0 :                     n->kind = OBJECT_COLLATION;
    6534           0 :                     n->args = NIL;
    6535           0 :                     n->defnames = $6;
    6536           0 :                     n->definition = list_make1(makeDefElem("from", (Node *) $8, @8));
    6537           0 :                     n->if_not_exists = true;
    6538           0 :                     $$ = (Node *) n;
    6539             :                 }
    6540             :         ;
    6541             : 
    6542       10088 : definition: '(' def_list ')'                        { $$ = $2; }
    6543             :         ;
    6544             : 
    6545       10088 : def_list:   def_elem                                { $$ = list_make1($1); }
    6546       15114 :             | def_list ',' def_elem                 { $$ = lappend($1, $3); }
    6547             :         ;
    6548             : 
    6549             : def_elem:   ColLabel '=' def_arg
    6550             :                 {
    6551       24844 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6552             :                 }
    6553             :             | ColLabel
    6554             :                 {
    6555         358 :                     $$ = makeDefElem($1, NULL, @1);
    6556             :                 }
    6557             :         ;
    6558             : 
    6559             : /* Note: any simple identifier will be returned as a type name! */
    6560       20130 : def_arg:    func_type                       { $$ = (Node *) $1; }
    6561        4128 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
    6562        1186 :             | qual_all_Op                   { $$ = (Node *) $1; }
    6563        1306 :             | NumericOnly                   { $$ = (Node *) $1; }
    6564        2048 :             | Sconst                        { $$ = (Node *) makeString($1); }
    6565         164 :             | NONE                          { $$ = (Node *) makeString(pstrdup($1)); }
    6566             :         ;
    6567             : 
    6568         362 : old_aggr_definition: '(' old_aggr_list ')'          { $$ = $2; }
    6569             :         ;
    6570             : 
    6571         362 : old_aggr_list: old_aggr_elem                        { $$ = list_make1($1); }
    6572        1292 :             | old_aggr_list ',' old_aggr_elem       { $$ = lappend($1, $3); }
    6573             :         ;
    6574             : 
    6575             : /*
    6576             :  * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
    6577             :  * the item names needed in old aggregate definitions are likely to become
    6578             :  * SQL keywords.
    6579             :  */
    6580             : old_aggr_elem:  IDENT '=' def_arg
    6581             :                 {
    6582        1654 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6583             :                 }
    6584             :         ;
    6585             : 
    6586             : opt_enum_val_list:
    6587         200 :         enum_val_list                           { $$ = $1; }
    6588           8 :         | /*EMPTY*/                             { $$ = NIL; }
    6589             :         ;
    6590             : 
    6591             : enum_val_list:  Sconst
    6592         200 :                 { $$ = list_make1(makeString($1)); }
    6593             :             | enum_val_list ',' Sconst
    6594       10496 :                 { $$ = lappend($1, makeString($3)); }
    6595             :         ;
    6596             : 
    6597             : /*****************************************************************************
    6598             :  *
    6599             :  *  ALTER TYPE enumtype ADD ...
    6600             :  *
    6601             :  *****************************************************************************/
    6602             : 
    6603             : AlterEnumStmt:
    6604             :         ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
    6605             :             {
    6606         154 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6607             : 
    6608         154 :                 n->typeName = $3;
    6609         154 :                 n->oldVal = NULL;
    6610         154 :                 n->newVal = $7;
    6611         154 :                 n->newValNeighbor = NULL;
    6612         154 :                 n->newValIsAfter = true;
    6613         154 :                 n->skipIfNewValExists = $6;
    6614         154 :                 $$ = (Node *) n;
    6615             :             }
    6616             :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
    6617             :             {
    6618         196 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6619             : 
    6620         196 :                 n->typeName = $3;
    6621         196 :                 n->oldVal = NULL;
    6622         196 :                 n->newVal = $7;
    6623         196 :                 n->newValNeighbor = $9;
    6624         196 :                 n->newValIsAfter = false;
    6625         196 :                 n->skipIfNewValExists = $6;
    6626         196 :                 $$ = (Node *) n;
    6627             :             }
    6628             :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
    6629             :             {
    6630          22 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6631             : 
    6632          22 :                 n->typeName = $3;
    6633          22 :                 n->oldVal = NULL;
    6634          22 :                 n->newVal = $7;
    6635          22 :                 n->newValNeighbor = $9;
    6636          22 :                 n->newValIsAfter = true;
    6637          22 :                 n->skipIfNewValExists = $6;
    6638          22 :                 $$ = (Node *) n;
    6639             :             }
    6640             :          | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
    6641             :             {
    6642          24 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6643             : 
    6644          24 :                 n->typeName = $3;
    6645          24 :                 n->oldVal = $6;
    6646          24 :                 n->newVal = $8;
    6647          24 :                 n->newValNeighbor = NULL;
    6648          24 :                 n->newValIsAfter = false;
    6649          24 :                 n->skipIfNewValExists = false;
    6650          24 :                 $$ = (Node *) n;
    6651             :             }
    6652             :          | ALTER TYPE_P any_name DROP VALUE_P Sconst
    6653             :             {
    6654             :                 /*
    6655             :                  * The following problems must be solved before this can be
    6656             :                  * implemented:
    6657             :                  *
    6658             :                  * - There must be no instance of the target value in
    6659             :                  *   any table.
    6660             :                  *
    6661             :                  * - The value must not appear in any catalog metadata,
    6662             :                  *   such as stored view expressions or column defaults.
    6663             :                  *
    6664             :                  * - The value must not appear in any non-leaf page of a
    6665             :                  *   btree (and similar issues with other index types).
    6666             :                  *   This is problematic because a value could persist
    6667             :                  *   there long after it's gone from user-visible data.
    6668             :                  *
    6669             :                  * - Concurrent sessions must not be able to insert the
    6670             :                  *   value while the preceding conditions are being checked.
    6671             :                  *
    6672             :                  * - Possibly more...
    6673             :                  */
    6674           0 :                 ereport(ERROR,
    6675             :                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6676             :                          errmsg("dropping an enum value is not implemented"),
    6677             :                          parser_errposition(@4)));
    6678             :             }
    6679             :          ;
    6680             : 
    6681          12 : opt_if_not_exists: IF_P NOT EXISTS              { $$ = true; }
    6682         360 :         | /* EMPTY */                          { $$ = false; }
    6683             :         ;
    6684             : 
    6685             : 
    6686             : /*****************************************************************************
    6687             :  *
    6688             :  *      QUERIES :
    6689             :  *              CREATE OPERATOR CLASS ...
    6690             :  *              CREATE OPERATOR FAMILY ...
    6691             :  *              ALTER OPERATOR FAMILY ...
    6692             :  *              DROP OPERATOR CLASS ...
    6693             :  *              DROP OPERATOR FAMILY ...
    6694             :  *
    6695             :  *****************************************************************************/
    6696             : 
    6697             : CreateOpClassStmt:
    6698             :             CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
    6699             :             USING name opt_opfamily AS opclass_item_list
    6700             :                 {
    6701         394 :                     CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
    6702             : 
    6703         394 :                     n->opclassname = $4;
    6704         394 :                     n->isDefault = $5;
    6705         394 :                     n->datatype = $8;
    6706         394 :                     n->amname = $10;
    6707         394 :                     n->opfamilyname = $11;
    6708         394 :                     n->items = $13;
    6709         394 :                     $$ = (Node *) n;
    6710             :                 }
    6711             :         ;
    6712             : 
    6713             : opclass_item_list:
    6714         928 :             opclass_item                            { $$ = list_make1($1); }
    6715        3228 :             | opclass_item_list ',' opclass_item    { $$ = lappend($1, $3); }
    6716             :         ;
    6717             : 
    6718             : opclass_item:
    6719             :             OPERATOR Iconst any_operator opclass_purpose
    6720             :                 {
    6721        1092 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6722        1092 :                     ObjectWithArgs *owa = makeNode(ObjectWithArgs);
    6723             : 
    6724        1092 :                     owa->objname = $3;
    6725        1092 :                     owa->objargs = NIL;
    6726        1092 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6727        1092 :                     n->name = owa;
    6728        1092 :                     n->number = $2;
    6729        1092 :                     n->order_family = $4;
    6730        1092 :                     $$ = (Node *) n;
    6731             :                 }
    6732             :             | OPERATOR Iconst operator_with_argtypes opclass_purpose
    6733             :                 {
    6734        1226 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6735             : 
    6736        1226 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6737        1226 :                     n->name = $3;
    6738        1226 :                     n->number = $2;
    6739        1226 :                     n->order_family = $4;
    6740        1226 :                     $$ = (Node *) n;
    6741             :                 }
    6742             :             | FUNCTION Iconst function_with_argtypes
    6743             :                 {
    6744        1386 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6745             : 
    6746        1386 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6747        1386 :                     n->name = $3;
    6748        1386 :                     n->number = $2;
    6749        1386 :                     $$ = (Node *) n;
    6750             :                 }
    6751             :             | FUNCTION Iconst '(' type_list ')' function_with_argtypes
    6752             :                 {
    6753         252 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6754             : 
    6755         252 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6756         252 :                     n->name = $6;
    6757         252 :                     n->number = $2;
    6758         252 :                     n->class_args = $4;
    6759         252 :                     $$ = (Node *) n;
    6760             :                 }
    6761             :             | STORAGE Typename
    6762             :                 {
    6763         200 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6764             : 
    6765         200 :                     n->itemtype = OPCLASS_ITEM_STORAGETYPE;
    6766         200 :                     n->storedtype = $2;
    6767         200 :                     $$ = (Node *) n;
    6768             :                 }
    6769             :         ;
    6770             : 
    6771         290 : opt_default:    DEFAULT                     { $$ = true; }
    6772         168 :             | /*EMPTY*/                     { $$ = false; }
    6773             :         ;
    6774             : 
    6775          50 : opt_opfamily:   FAMILY any_name             { $$ = $2; }
    6776         344 :             | /*EMPTY*/                     { $$ = NIL; }
    6777             :         ;
    6778             : 
    6779           0 : opclass_purpose: FOR SEARCH                 { $$ = NIL; }
    6780          72 :             | FOR ORDER BY any_name         { $$ = $4; }
    6781        2246 :             | /*EMPTY*/                     { $$ = NIL; }
    6782             :         ;
    6783             : 
    6784             : 
    6785             : CreateOpFamilyStmt:
    6786             :             CREATE OPERATOR FAMILY any_name USING name
    6787             :                 {
    6788         162 :                     CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
    6789             : 
    6790         162 :                     n->opfamilyname = $4;
    6791         162 :                     n->amname = $6;
    6792         162 :                     $$ = (Node *) n;
    6793             :                 }
    6794             :         ;
    6795             : 
    6796             : AlterOpFamilyStmt:
    6797             :             ALTER OPERATOR FAMILY any_name USING name ADD_P opclass_item_list
    6798             :                 {
    6799         534 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6800             : 
    6801         534 :                     n->opfamilyname = $4;
    6802         534 :                     n->amname = $6;
    6803         534 :                     n->isDrop = false;
    6804         534 :                     n->items = $8;
    6805         534 :                     $$ = (Node *) n;
    6806             :                 }
    6807             :             | ALTER OPERATOR FAMILY any_name USING name DROP opclass_drop_list
    6808             :                 {
    6809          64 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6810             : 
    6811          64 :                     n->opfamilyname = $4;
    6812          64 :                     n->amname = $6;
    6813          64 :                     n->isDrop = true;
    6814          64 :                     n->items = $8;
    6815          64 :                     $$ = (Node *) n;
    6816             :                 }
    6817             :         ;
    6818             : 
    6819             : opclass_drop_list:
    6820          64 :             opclass_drop                            { $$ = list_make1($1); }
    6821          30 :             | opclass_drop_list ',' opclass_drop    { $$ = lappend($1, $3); }
    6822             :         ;
    6823             : 
    6824             : opclass_drop:
    6825             :             OPERATOR Iconst '(' type_list ')'
    6826             :                 {
    6827          56 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6828             : 
    6829          56 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6830          56 :                     n->number = $2;
    6831          56 :                     n->class_args = $4;
    6832          56 :                     $$ = (Node *) n;
    6833             :                 }
    6834             :             | FUNCTION Iconst '(' type_list ')'
    6835             :                 {
    6836          38 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6837             : 
    6838          38 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6839          38 :                     n->number = $2;
    6840          38 :                     n->class_args = $4;
    6841          38 :                     $$ = (Node *) n;
    6842             :                 }
    6843             :         ;
    6844             : 
    6845             : 
    6846             : DropOpClassStmt:
    6847             :             DROP OPERATOR CLASS any_name USING name opt_drop_behavior
    6848             :                 {
    6849          38 :                     DropStmt *n = makeNode(DropStmt);
    6850             : 
    6851          38 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6852          38 :                     n->removeType = OBJECT_OPCLASS;
    6853          38 :                     n->behavior = $7;
    6854          38 :                     n->missing_ok = false;
    6855          38 :                     n->concurrent = false;
    6856          38 :                     $$ = (Node *) n;
    6857             :                 }
    6858             :             | DROP OPERATOR CLASS IF_P EXISTS any_name USING name opt_drop_behavior
    6859             :                 {
    6860          18 :                     DropStmt *n = makeNode(DropStmt);
    6861             : 
    6862          18 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6863          18 :                     n->removeType = OBJECT_OPCLASS;
    6864          18 :                     n->behavior = $9;
    6865          18 :                     n->missing_ok = true;
    6866          18 :                     n->concurrent = false;
    6867          18 :                     $$ = (Node *) n;
    6868             :                 }
    6869             :         ;
    6870             : 
    6871             : DropOpFamilyStmt:
    6872             :             DROP OPERATOR FAMILY any_name USING name opt_drop_behavior
    6873             :                 {
    6874         110 :                     DropStmt *n = makeNode(DropStmt);
    6875             : 
    6876         110 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6877         110 :                     n->removeType = OBJECT_OPFAMILY;
    6878         110 :                     n->behavior = $7;
    6879         110 :                     n->missing_ok = false;
    6880         110 :                     n->concurrent = false;
    6881         110 :                     $$ = (Node *) n;
    6882             :                 }
    6883             :             | DROP OPERATOR FAMILY IF_P EXISTS any_name USING name opt_drop_behavior
    6884             :                 {
    6885          18 :                     DropStmt *n = makeNode(DropStmt);
    6886             : 
    6887          18 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6888          18 :                     n->removeType = OBJECT_OPFAMILY;
    6889          18 :                     n->behavior = $9;
    6890          18 :                     n->missing_ok = true;
    6891          18 :                     n->concurrent = false;
    6892          18 :                     $$ = (Node *) n;
    6893             :                 }
    6894             :         ;
    6895             : 
    6896             : 
    6897             : /*****************************************************************************
    6898             :  *
    6899             :  *      QUERY:
    6900             :  *
    6901             :  *      DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
    6902             :  *      REASSIGN OWNED BY username [, username ...] TO username
    6903             :  *
    6904             :  *****************************************************************************/
    6905             : DropOwnedStmt:
    6906             :             DROP OWNED BY role_list opt_drop_behavior
    6907             :                 {
    6908         152 :                     DropOwnedStmt *n = makeNode(DropOwnedStmt);
    6909             : 
    6910         152 :                     n->roles = $4;
    6911         152 :                     n->behavior = $5;
    6912         152 :                     $$ = (Node *) n;
    6913             :                 }
    6914             :         ;
    6915             : 
    6916             : ReassignOwnedStmt:
    6917             :             REASSIGN OWNED BY role_list TO RoleSpec
    6918             :                 {
    6919          52 :                     ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
    6920             : 
    6921          52 :                     n->roles = $4;
    6922          52 :                     n->newrole = $6;
    6923          52 :                     $$ = (Node *) n;
    6924             :                 }
    6925             :         ;
    6926             : 
    6927             : /*****************************************************************************
    6928             :  *
    6929             :  *      QUERY:
    6930             :  *
    6931             :  *      DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
    6932             :  *           [ RESTRICT | CASCADE ]
    6933             :  *
    6934             :  *****************************************************************************/
    6935             : 
    6936             : DropStmt:   DROP object_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
    6937             :                 {
    6938        1334 :                     DropStmt *n = makeNode(DropStmt);
    6939             : 
    6940        1334 :                     n->removeType = $2;
    6941        1334 :                     n->missing_ok = true;
    6942        1334 :                     n->objects = $5;
    6943        1334 :                     n->behavior = $6;
    6944        1334 :                     n->concurrent = false;
    6945        1334 :                     $$ = (Node *) n;
    6946             :                 }
    6947             :             | DROP object_type_any_name any_name_list opt_drop_behavior
    6948             :                 {
    6949       15990 :                     DropStmt *n = makeNode(DropStmt);
    6950             : 
    6951       15990 :                     n->removeType = $2;
    6952       15990 :                     n->missing_ok = false;
    6953       15990 :                     n->objects = $3;
    6954       15990 :                     n->behavior = $4;
    6955       15990 :                     n->concurrent = false;
    6956       15990 :                     $$ = (Node *) n;
    6957             :                 }
    6958             :             | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
    6959             :                 {
    6960          78 :                     DropStmt *n = makeNode(DropStmt);
    6961             : 
    6962          78 :                     n->removeType = $2;
    6963          78 :                     n->missing_ok = true;
    6964          78 :                     n->objects = $5;
    6965          78 :                     n->behavior = $6;
    6966          78 :                     n->concurrent = false;
    6967          78 :                     $$ = (Node *) n;
    6968             :                 }
    6969             :             | DROP drop_type_name name_list opt_drop_behavior
    6970             :                 {
    6971        1412 :                     DropStmt *n = makeNode(DropStmt);
    6972             : 
    6973        1412 :                     n->removeType = $2;
    6974        1412 :                     n->missing_ok = false;
    6975        1412 :                     n->objects = $3;
    6976        1412 :                     n->behavior = $4;
    6977        1412 :                     n->concurrent = false;
    6978        1412 :                     $$ = (Node *) n;
    6979             :                 }
    6980             :             | DROP object_type_name_on_any_name name ON any_name opt_drop_behavior
    6981             :                 {
    6982        1130 :                     DropStmt *n = makeNode(DropStmt);
    6983             : 
    6984        1130 :                     n->removeType = $2;
    6985        1130 :                     n->objects = list_make1(lappend($5, makeString($3)));
    6986        1130 :                     n->behavior = $6;
    6987        1130 :                     n->missing_ok = false;
    6988        1130 :                     n->concurrent = false;
    6989        1130 :                     $$ = (Node *) n;
    6990             :                 }
    6991             :             | DROP object_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
    6992             :                 {
    6993          48 :                     DropStmt *n = makeNode(DropStmt);
    6994             : 
    6995          48 :                     n->removeType = $2;
    6996          48 :                     n->objects = list_make1(lappend($7, makeString($5)));
    6997          48 :                     n->behavior = $8;
    6998          48 :                     n->missing_ok = true;
    6999          48 :                     n->concurrent = false;
    7000          48 :                     $$ = (Node *) n;
    7001             :                 }
    7002             :             | DROP TYPE_P type_name_list opt_drop_behavior
    7003             :                 {
    7004         560 :                     DropStmt *n = makeNode(DropStmt);
    7005             : 
    7006         560 :                     n->removeType = OBJECT_TYPE;
    7007         560 :                     n->missing_ok = false;
    7008         560 :                     n->objects = $3;
    7009         560 :                     n->behavior = $4;
    7010         560 :                     n->concurrent = false;
    7011         560 :                     $$ = (Node *) n;
    7012             :                 }
    7013             :             | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
    7014             :                 {
    7015          26 :                     DropStmt *n = makeNode(DropStmt);
    7016             : 
    7017          26 :                     n->removeType = OBJECT_TYPE;
    7018          26 :                     n->missing_ok = true;
    7019          26 :                     n->objects = $5;
    7020          26 :                     n->behavior = $6;
    7021          26 :                     n->concurrent = false;
    7022          26 :                     $$ = (Node *) n;
    7023             :                 }
    7024             :             | DROP DOMAIN_P type_name_list opt_drop_behavior
    7025             :                 {
    7026         464 :                     DropStmt *n = makeNode(DropStmt);
    7027             : 
    7028         464 :                     n->removeType = OBJECT_DOMAIN;
    7029         464 :                     n->missing_ok = false;
    7030         464 :                     n->objects = $3;
    7031         464 :                     n->behavior = $4;
    7032         464 :                     n->concurrent = false;
    7033         464 :                     $$ = (Node *) n;
    7034             :                 }
    7035             :             | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
    7036             :                 {
    7037          18 :                     DropStmt *n = makeNode(DropStmt);
    7038             : 
    7039          18 :                     n->removeType = OBJECT_DOMAIN;
    7040          18 :                     n->missing_ok = true;
    7041          18 :                     n->objects = $5;
    7042          18 :                     n->behavior = $6;
    7043          18 :                     n->concurrent = false;
    7044          18 :                     $$ = (Node *) n;
    7045             :                 }
    7046             :             | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
    7047             :                 {
    7048         150 :                     DropStmt *n = makeNode(DropStmt);
    7049             : 
    7050         150 :                     n->removeType = OBJECT_INDEX;
    7051         150 :                     n->missing_ok = false;
    7052         150 :                     n->objects = $4;
    7053         150 :                     n->behavior = $5;
    7054         150 :                     n->concurrent = true;
    7055         150 :                     $$ = (Node *) n;
    7056             :                 }
    7057             :             | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
    7058             :                 {
    7059          12 :                     DropStmt *n = makeNode(DropStmt);
    7060             : 
    7061          12 :                     n->removeType = OBJECT_INDEX;
    7062          12 :                     n->missing_ok = true;
    7063          12 :                     n->objects = $6;
    7064          12 :                     n->behavior = $7;
    7065          12 :                     n->concurrent = true;
    7066          12 :                     $$ = (Node *) n;
    7067             :                 }
    7068             :         ;
    7069             : 
    7070             : /* object types taking any_name/any_name_list */
    7071             : object_type_any_name:
    7072       14940 :             TABLE                                   { $$ = OBJECT_TABLE; }
    7073         192 :             | SEQUENCE                              { $$ = OBJECT_SEQUENCE; }
    7074        1010 :             | VIEW                                  { $$ = OBJECT_VIEW; }
    7075         130 :             | MATERIALIZED VIEW                     { $$ = OBJECT_MATVIEW; }
    7076         784 :             | INDEX                                 { $$ = OBJECT_INDEX; }
    7077         184 :             | FOREIGN TABLE                         { $$ = OBJECT_FOREIGN_TABLE; }
    7078          96 :             | COLLATION                             { $$ = OBJECT_COLLATION; }
    7079          56 :             | CONVERSION_P                          { $$ = OBJECT_CONVERSION; }
    7080         210 :             | STATISTICS                            { $$ = OBJECT_STATISTIC_EXT; }
    7081          20 :             | TEXT_P SEARCH PARSER                  { $$ = OBJECT_TSPARSER; }
    7082        2872 :             | TEXT_P SEARCH DICTIONARY              { $$ = OBJECT_TSDICTIONARY; }
    7083         118 :             | TEXT_P SEARCH TEMPLATE                { $$ = OBJECT_TSTEMPLATE; }
    7084        2876 :             | TEXT_P SEARCH CONFIGURATION           { $$ = OBJECT_TSCONFIGURATION; }
    7085             :         ;
    7086             : 
    7087             : /*
    7088             :  * object types taking name/name_list
    7089             :  *
    7090             :  * DROP handles some of them separately
    7091             :  */
    7092             : 
    7093             : object_type_name:
    7094         234 :             drop_type_name                          { $$ = $1; }
    7095         242 :             | DATABASE                              { $$ = OBJECT_DATABASE; }
    7096          52 :             | ROLE                                  { $$ = OBJECT_ROLE; }
    7097          10 :             | SUBSCRIPTION                          { $$ = OBJECT_SUBSCRIPTION; }
    7098           0 :             | TABLESPACE                            { $$ = OBJECT_TABLESPACE; }
    7099             :         ;
    7100             : 
    7101             : drop_type_name:
    7102          46 :             ACCESS METHOD                           { $$ = OBJECT_ACCESS_METHOD; }
    7103         124 :             | EVENT TRIGGER                         { $$ = OBJECT_EVENT_TRIGGER; }
    7104         150 :             | EXTENSION                             { $$ = OBJECT_EXTENSION; }
    7105         154 :             | FOREIGN DATA_P WRAPPER                { $$ = OBJECT_FDW; }
    7106         156 :             | opt_procedural LANGUAGE               { $$ = OBJECT_LANGUAGE; }
    7107         382 :             | PUBLICATION                           { $$ = OBJECT_PUBLICATION; }
    7108         582 :             | SCHEMA                                { $$ = OBJECT_SCHEMA; }
    7109         130 :             | SERVER                                { $$ = OBJECT_FOREIGN_SERVER; }
    7110             :         ;
    7111             : 
    7112             : /* object types attached to a table */
    7113             : object_type_name_on_any_name:
    7114         164 :             POLICY                                  { $$ = OBJECT_POLICY; }
    7115         268 :             | RULE                                  { $$ = OBJECT_RULE; }
    7116         798 :             | TRIGGER                               { $$ = OBJECT_TRIGGER; }
    7117             :         ;
    7118             : 
    7119             : any_name_list:
    7120       26494 :             any_name                                { $$ = list_make1($1); }
    7121        4240 :             | any_name_list ',' any_name            { $$ = lappend($1, $3); }
    7122             :         ;
    7123             : 
    7124       67424 : any_name:   ColId                       { $$ = list_make1(makeString($1)); }
    7125        9584 :             | ColId attrs               { $$ = lcons(makeString($1), $2); }
    7126             :         ;
    7127             : 
    7128             : attrs:      '.' attr_name
    7129      129898 :                     { $$ = list_make1(makeString($2)); }
    7130             :             | attrs '.' attr_name
    7131          96 :                     { $$ = lappend($1, makeString($3)); }
    7132             :         ;
    7133             : 
    7134             : type_name_list:
    7135        1068 :             Typename                                { $$ = list_make1($1); }
    7136          96 :             | type_name_list ',' Typename           { $$ = lappend($1, $3); }
    7137             :         ;
    7138             : 
    7139             : /*****************************************************************************
    7140             :  *
    7141             :  *      QUERY:
    7142             :  *              truncate table relname1, relname2, ...
    7143             :  *
    7144             :  *****************************************************************************/
    7145             : 
    7146             : TruncateStmt:
    7147             :             TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
    7148             :                 {
    7149        2948 :                     TruncateStmt *n = makeNode(TruncateStmt);
    7150             : 
    7151        2948 :                     n->relations = $3;
    7152        2948 :                     n->restart_seqs = $4;
    7153        2948 :                     n->behavior = $5;
    7154        2948 :                     $$ = (Node *) n;
    7155             :                 }
    7156             :         ;
    7157             : 
    7158             : opt_restart_seqs:
    7159          24 :             CONTINUE_P IDENTITY_P       { $$ = false; }
    7160          22 :             | RESTART IDENTITY_P        { $$ = true; }
    7161        2902 :             | /* EMPTY */               { $$ = false; }
    7162             :         ;
    7163             : 
    7164             : /*****************************************************************************
    7165             :  *
    7166             :  * COMMENT ON <object> IS <text>
    7167             :  *
    7168             :  *****************************************************************************/
    7169             : 
    7170             : CommentStmt:
    7171             :             COMMENT ON object_type_any_name any_name IS comment_text
    7172             :                 {
    7173        6022 :                     CommentStmt *n = makeNode(CommentStmt);
    7174             : 
    7175        6022 :                     n->objtype = $3;
    7176        6022 :                     n->object = (Node *) $4;
    7177        6022 :                     n->comment = $6;
    7178        6022 :                     $$ = (Node *) n;
    7179             :                 }
    7180             :             | COMMENT ON COLUMN any_name IS comment_text
    7181             :                 {
    7182         118 :                     CommentStmt *n = makeNode(CommentStmt);
    7183             : 
    7184         118 :                     n->objtype = OBJECT_COLUMN;
    7185         118 :                     n->object = (Node *) $4;
    7186         118 :                     n->comment = $6;
    7187         118 :                     $$ = (Node *) n;
    7188             :                 }
    7189             :             | COMMENT ON object_type_name name IS comment_text
    7190             :                 {
    7191         476 :                     CommentStmt *n = makeNode(CommentStmt);
    7192             : 
    7193         476 :                     n->objtype = $3;
    7194         476 :                     n->object = (Node *) makeString($4);
    7195         476 :                     n->comment = $6;
    7196         476 :                     $$ = (Node *) n;
    7197             :                 }
    7198             :             | COMMENT ON TYPE_P Typename IS comment_text
    7199             :                 {
    7200          56 :                     CommentStmt *n = makeNode(CommentStmt);
    7201             : 
    7202          56 :                     n->objtype = OBJECT_TYPE;
    7203          56 :                     n->object = (Node *) $4;
    7204          56 :                     n->comment = $6;
    7205          56 :                     $$ = (Node *) n;
    7206             :                 }
    7207             :             | COMMENT ON DOMAIN_P Typename IS comment_text
    7208             :                 {
    7209           8 :                     CommentStmt *n = makeNode(CommentStmt);
    7210             : 
    7211           8 :                     n->objtype = OBJECT_DOMAIN;
    7212           8 :                     n->object = (Node *) $4;
    7213           8 :                     n->comment = $6;
    7214           8 :                     $$ = (Node *) n;
    7215             :                 }
    7216             :             | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
    7217             :                 {
    7218          44 :                     CommentStmt *n = makeNode(CommentStmt);
    7219             : 
    7220          44 :                     n->objtype = OBJECT_AGGREGATE;
    7221          44 :                     n->object = (Node *) $4;
    7222          44 :                     n->comment = $6;
    7223          44 :                     $$ = (Node *) n;
    7224             :                 }
    7225             :             | COMMENT ON FUNCTION function_with_argtypes IS comment_text
    7226             :                 {
    7227         170 :                     CommentStmt *n = makeNode(CommentStmt);
    7228             : 
    7229         170 :                     n->objtype = OBJECT_FUNCTION;
    7230         170 :                     n->object = (Node *) $4;
    7231         170 :                     n->comment = $6;
    7232         170 :                     $$ = (Node *) n;
    7233             :                 }
    7234             :             | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
    7235             :                 {
    7236          18 :                     CommentStmt *n = makeNode(CommentStmt);
    7237             : 
    7238          18 :                     n->objtype = OBJECT_OPERATOR;
    7239          18 :                     n->object = (Node *) $4;
    7240          18 :                     n->comment = $6;
    7241          18 :                     $$ = (Node *) n;
    7242             :                 }
    7243             :             | COMMENT ON CONSTRAINT name ON any_name IS comment_text
    7244             :                 {
    7245         162 :                     CommentStmt *n = makeNode(CommentStmt);
    7246             : 
    7247         162 :                     n->objtype = OBJECT_TABCONSTRAINT;
    7248         162 :                     n->object = (Node *) lappend($6, makeString($4));
    7249         162 :                     n->comment = $8;
    7250         162 :                     $$ = (Node *) n;
    7251             :                 }
    7252             :             | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
    7253             :                 {
    7254          38 :                     CommentStmt *n = makeNode(CommentStmt);
    7255             : 
    7256          38 :                     n->objtype = OBJECT_DOMCONSTRAINT;
    7257             :                     /*
    7258             :                      * should use Typename not any_name in the production, but
    7259             :                      * there's a shift/reduce conflict if we do that, so fix it
    7260             :                      * up here.
    7261             :                      */
    7262          38 :                     n->object = (Node *) list_make2(makeTypeNameFromNameList($7), makeString($4));
    7263          38 :                     n->comment = $9;
    7264          38 :                     $$ = (Node *) n;
    7265             :                 }
    7266             :             | COMMENT ON object_type_name_on_any_name name ON any_name IS comment_text
    7267             :                 {
    7268          40 :                     CommentStmt *n = makeNode(CommentStmt);
    7269             : 
    7270          40 :                     n->objtype = $3;
    7271          40 :                     n->object = (Node *) lappend($6, makeString($4));
    7272          40 :                     n->comment = $8;
    7273          40 :                     $$ = (Node *) n;
    7274             :                 }
    7275             :             | COMMENT ON PROCEDURE function_with_argtypes IS comment_text
    7276             :                 {
    7277           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7278             : 
    7279           0 :                     n->objtype = OBJECT_PROCEDURE;
    7280           0 :                     n->object = (Node *) $4;
    7281           0 :                     n->comment = $6;
    7282           0 :                     $$ = (Node *) n;
    7283             :                 }
    7284             :             | COMMENT ON ROUTINE function_with_argtypes IS comment_text
    7285             :                 {
    7286           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7287             : 
    7288           0 :                     n->objtype = OBJECT_ROUTINE;
    7289           0 :                     n->object = (Node *) $4;
    7290           0 :                     n->comment = $6;
    7291           0 :                     $$ = (Node *) n;
    7292             :                 }
    7293             :             | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
    7294             :                 {
    7295          14 :                     CommentStmt *n = makeNode(CommentStmt);
    7296             : 
    7297          14 :                     n->objtype = OBJECT_TRANSFORM;
    7298          14 :                     n->object = (Node *) list_make2($5, makeString($7));
    7299          14 :                     n->comment = $9;
    7300          14 :                     $$ = (Node *) n;
    7301             :                 }
    7302             :             | COMMENT ON OPERATOR CLASS any_name USING name IS comment_text
    7303             :                 {
    7304           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7305             : 
    7306           0 :                     n->objtype = OBJECT_OPCLASS;
    7307           0 :                     n->object = (Node *) lcons(makeString($7), $5);
    7308           0 :                     n->comment = $9;
    7309           0 :                     $$ = (Node *) n;
    7310             :                 }
    7311             :             | COMMENT ON OPERATOR FAMILY any_name USING name IS comment_text
    7312             :                 {
    7313           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7314             : 
    7315           0 :                     n->objtype = OBJECT_OPFAMILY;
    7316           0 :                     n->object = (Node *) lcons(makeString($7), $5);
    7317           0 :                     n->comment = $9;
    7318           0 :                     $$ = (Node *) n;
    7319             :                 }
    7320             :             | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
    7321             :                 {
    7322          28 :                     CommentStmt *n = makeNode(CommentStmt);
    7323             : 
    7324          28 :                     n->objtype = OBJECT_LARGEOBJECT;
    7325          28 :                     n->object = (Node *) $5;
    7326          28 :                     n->comment = $7;
    7327          28 :                     $$ = (Node *) n;
    7328             :                 }
    7329             :             | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
    7330             :                 {
    7331           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7332             : 
    7333           0 :                     n->objtype = OBJECT_CAST;
    7334           0 :                     n->object = (Node *) list_make2($5, $7);
    7335           0 :                     n->comment = $10;
    7336           0 :                     $$ = (Node *) n;
    7337             :                 }
    7338             :         ;
    7339             : 
    7340             : comment_text:
    7341        7090 :             Sconst                              { $$ = $1; }
    7342         104 :             | NULL_P                            { $$ = NULL; }
    7343             :         ;
    7344             : 
    7345             : 
    7346             : /*****************************************************************************
    7347             :  *
    7348             :  *  SECURITY LABEL [FOR <provider>] ON <object> IS <label>
    7349             :  *
    7350             :  *  As with COMMENT ON, <object> can refer to various types of database
    7351             :  *  objects (e.g. TABLE, COLUMN, etc.).
    7352             :  *
    7353             :  *****************************************************************************/
    7354             : 
    7355             : SecLabelStmt:
    7356             :             SECURITY LABEL opt_provider ON object_type_any_name any_name
    7357             :             IS security_label
    7358             :                 {
    7359          48 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7360             : 
    7361          48 :                     n->provider = $3;
    7362          48 :                     n->objtype = $5;
    7363          48 :                     n->object = (Node *) $6;
    7364          48 :                     n->label = $8;
    7365          48 :                     $$ = (Node *) n;
    7366             :                 }
    7367             :             | SECURITY LABEL opt_provider ON COLUMN any_name
    7368             :               IS security_label
    7369             :                 {
    7370           4 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7371             : 
    7372           4 :                     n->provider = $3;
    7373           4 :                     n->objtype = OBJECT_COLUMN;
    7374           4 :                     n->object = (Node *) $6;
    7375           4 :                     n->label = $8;
    7376           4 :                     $$ = (Node *) n;
    7377             :                 }
    7378             :             | SECURITY LABEL opt_provider ON object_type_name name
    7379             :               IS security_label
    7380             :                 {
    7381          44 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7382             : 
    7383          44 :                     n->provider = $3;
    7384          44 :                     n->objtype = $5;
    7385          44 :                     n->object = (Node *) makeString($6);
    7386          44 :                     n->label = $8;
    7387          44 :                     $$ = (Node *) n;
    7388             :                 }
    7389             :             | SECURITY LABEL opt_provider ON TYPE_P Typename
    7390             :               IS security_label
    7391             :                 {
    7392           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7393             : 
    7394           0 :                     n->provider = $3;
    7395           0 :                     n->objtype = OBJECT_TYPE;
    7396           0 :                     n->object = (Node *) $6;
    7397           0 :                     n->label = $8;
    7398           0 :                     $$ = (Node *) n;
    7399             :                 }
    7400             :             | SECURITY LABEL opt_provider ON DOMAIN_P Typename
    7401             :               IS security_label
    7402             :                 {
    7403           2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7404             : 
    7405           2 :                     n->provider = $3;
    7406           2 :                     n->objtype = OBJECT_DOMAIN;
    7407           2 :                     n->object = (Node *) $6;
    7408           2 :                     n->label = $8;
    7409           2 :                     $$ = (Node *) n;
    7410             :                 }
    7411             :             | SECURITY LABEL opt_provider ON AGGREGATE aggregate_with_argtypes
    7412             :               IS security_label
    7413             :                 {
    7414           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7415             : 
    7416           0 :                     n->provider = $3;
    7417           0 :                     n->objtype = OBJECT_AGGREGATE;
    7418           0 :                     n->object = (Node *) $6;
    7419           0 :                     n->label = $8;
    7420           0 :                     $$ = (Node *) n;
    7421             :                 }
    7422             :             | SECURITY LABEL opt_provider ON FUNCTION function_with_argtypes
    7423             :               IS security_label
    7424             :                 {
    7425           2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7426             : 
    7427           2 :                     n->provider = $3;
    7428           2 :                     n->objtype = OBJECT_FUNCTION;
    7429           2 :                     n->object = (Node *) $6;
    7430           2 :                     n->label = $8;
    7431           2 :                     $$ = (Node *) n;
    7432             :                 }
    7433             :             | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
    7434             :               IS security_label
    7435             :                 {
    7436           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7437             : 
    7438           0 :                     n->provider = $3;
    7439           0 :                     n->objtype = OBJECT_LARGEOBJECT;
    7440           0 :                     n->object = (Node *) $7;
    7441           0 :                     n->label = $9;
    7442           0 :                     $$ = (Node *) n;
    7443             :                 }
    7444             :             | SECURITY LABEL opt_provider ON PROCEDURE function_with_argtypes
    7445             :               IS security_label
    7446             :                 {
    7447           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7448             : 
    7449           0 :                     n->provider = $3;
    7450           0 :                     n->objtype = OBJECT_PROCEDURE;
    7451           0 :                     n->object = (Node *) $6;
    7452           0 :                     n->label = $8;
    7453           0 :                     $$ = (Node *) n;
    7454             :                 }
    7455             :             | SECURITY LABEL opt_provider ON ROUTINE function_with_argtypes
    7456             :               IS security_label
    7457             :                 {
    7458           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7459             : 
    7460           0 :                     n->provider = $3;
    7461           0 :                     n->objtype = OBJECT_ROUTINE;
    7462           0 :                     n->object = (Node *) $6;
    7463           0 :                     n->label = $8;
    7464           0 :                     $$ = (Node *) n;
    7465             :                 }
    7466             :         ;
    7467             : 
    7468          20 : opt_provider:   FOR NonReservedWord_or_Sconst   { $$ = $2; }
    7469          80 :                 | /* EMPTY */                   { $$ = NULL; }
    7470             :         ;
    7471             : 
    7472         100 : security_label: Sconst              { $$ = $1; }
    7473           0 :                 | NULL_P            { $$ = NULL; }
    7474             :         ;
    7475             : 
    7476             : /*****************************************************************************
    7477             :  *
    7478             :  *      QUERY:
    7479             :  *          fetch/move
    7480             :  *
    7481             :  *****************************************************************************/
    7482             : 
    7483             : FetchStmt:  FETCH fetch_args
    7484             :                 {
    7485        7516 :                     FetchStmt *n = (FetchStmt *) $2;
    7486             : 
    7487        7516 :                     n->ismove = false;
    7488        7516 :                     $$ = (Node *) n;
    7489             :                 }
    7490             :             | MOVE fetch_args
    7491             :                 {
    7492          68 :                     FetchStmt *n = (FetchStmt *) $2;
    7493             : 
    7494          68 :                     n->ismove = true;
    7495          68 :                     $$ = (Node *) n;
    7496             :                 }
    7497             :         ;
    7498             : 
    7499             : fetch_args: cursor_name
    7500             :                 {
    7501         272 :                     FetchStmt *n = makeNode(FetchStmt);
    7502             : 
    7503         272 :                     n->portalname = $1;
    7504         272 :                     n->direction = FETCH_FORWARD;
    7505         272 :                     n->howMany = 1;
    7506         272 :                     n->location = -1;
    7507         272 :                     n->direction_keyword = FETCH_KEYWORD_NONE;
    7508         272 :                     $$ = (Node *) n;
    7509             :                 }
    7510             :             | from_in cursor_name
    7511             :                 {
    7512         218 :                     FetchStmt *n = makeNode(FetchStmt);
    7513             : 
    7514         218 :                     n->portalname = $2;
    7515         218 :                     n->direction = FETCH_FORWARD;
    7516         218 :                     n->howMany = 1;
    7517         218 :                     n->location = -1;
    7518         218 :                     n->direction_keyword = FETCH_KEYWORD_NONE;
    7519         218 :                     $$ = (Node *) n;
    7520             :                 }
    7521             :             | SignedIconst opt_from_in cursor_name
    7522             :                 {
    7523        4150 :                     FetchStmt *n = makeNode(FetchStmt);
    7524             : 
    7525        4150 :                     n->portalname = $3;
    7526        4150 :                     n->direction = FETCH_FORWARD;
    7527        4150 :                     n->howMany = $1;
    7528        4150 :                     n->location = @1;
    7529        4150 :                     n->direction_keyword = FETCH_KEYWORD_NONE;
    7530        4150 :                     $$ = (Node *) n;
    7531             :                 }
    7532             :             | NEXT opt_from_in cursor_name
    7533             :                 {
    7534        2010 :                     FetchStmt *n = makeNode(FetchStmt);
    7535             : 
    7536        2010 :                     n->portalname = $3;
    7537        2010 :                     n->direction = FETCH_FORWARD;
    7538        2010 :                     n->howMany = 1;
    7539        2010 :                     n->location = -1;
    7540        2010 :                     n->direction_keyword = FETCH_KEYWORD_NEXT;
    7541        2010 :                     $$ = (Node *) n;
    7542             :                 }
    7543             :             | PRIOR opt_from_in cursor_name
    7544             :                 {
    7545          32 :                     FetchStmt *n = makeNode(FetchStmt);
    7546             : 
    7547          32 :                     n->portalname = $3;
    7548          32 :                     n->direction = FETCH_BACKWARD;
    7549          32 :                     n->howMany = 1;
    7550          32 :                     n->location = -1;
    7551          32 :                     n->direction_keyword = FETCH_KEYWORD_PRIOR;
    7552          32 :                     $$ = (Node *) n;
    7553             :                 }
    7554             :             | FIRST_P opt_from_in cursor_name
    7555             :                 {
    7556          26 :                     FetchStmt *n = makeNode(FetchStmt);
    7557             : 
    7558          26 :                     n->portalname = $3;
    7559          26 :                     n->direction = FETCH_ABSOLUTE;
    7560          26 :                     n->howMany = 1;
    7561          26 :                     n->location = -1;
    7562          26 :                     n->direction_keyword = FETCH_KEYWORD_FIRST;
    7563          26 :                     $$ = (Node *) n;
    7564             :                 }
    7565             :             | LAST_P opt_from_in cursor_name
    7566             :                 {
    7567          20 :                     FetchStmt *n = makeNode(FetchStmt);
    7568             : 
    7569          20 :                     n->portalname = $3;
    7570          20 :                     n->direction = FETCH_ABSOLUTE;
    7571          20 :                     n->howMany = -1;
    7572          20 :                     n->location = -1;
    7573          20 :                     n->direction_keyword = FETCH_KEYWORD_LAST;
    7574          20 :                     $$ = (Node *) n;
    7575             :                 }
    7576             :             | ABSOLUTE_P SignedIconst opt_from_in cursor_name
    7577             :                 {
    7578          94 :                     FetchStmt *n = makeNode(FetchStmt);
    7579             : 
    7580          94 :                     n->portalname = $4;
    7581          94 :                     n->direction = FETCH_ABSOLUTE;
    7582          94 :                     n->howMany = $2;
    7583          94 :                     n->location = @2;
    7584          94 :                     n->direction_keyword = FETCH_KEYWORD_ABSOLUTE;
    7585          94 :                     $$ = (Node *) n;
    7586             :                 }
    7587             :             | RELATIVE_P SignedIconst opt_from_in cursor_name
    7588             :                 {
    7589          36 :                     FetchStmt *n = makeNode(FetchStmt);
    7590             : 
    7591          36 :                     n->portalname = $4;
    7592          36 :                     n->direction = FETCH_RELATIVE;
    7593          36 :                     n->howMany = $2;
    7594          36 :                     n->location = @2;
    7595          36 :                     n->direction_keyword = FETCH_KEYWORD_RELATIVE;
    7596          36 :                     $$ = (Node *) n;
    7597             :                 }
    7598             :             | ALL opt_from_in cursor_name
    7599             :                 {
    7600         270 :                     FetchStmt *n = makeNode(FetchStmt);
    7601             : 
    7602         270 :                     n->portalname = $3;
    7603         270 :                     n->direction = FETCH_FORWARD;
    7604         270 :                     n->howMany = FETCH_ALL;
    7605         270 :                     n->location = -1;
    7606         270 :                     n->direction_keyword = FETCH_KEYWORD_ALL;
    7607         270 :                     $$ = (Node *) n;
    7608             :                 }
    7609             :             | FORWARD opt_from_in cursor_name
    7610             :                 {
    7611          30 :                     FetchStmt *n = makeNode(FetchStmt);
    7612             : 
    7613          30 :                     n->portalname = $3;
    7614          30 :                     n->direction = FETCH_FORWARD;
    7615          30 :                     n->howMany = 1;
    7616          30 :                     n->location = -1;
    7617          30 :                     n->direction_keyword = FETCH_KEYWORD_FORWARD;
    7618          30 :                     $$ = (Node *) n;
    7619             :                 }
    7620             :             | FORWARD SignedIconst opt_from_in cursor_name
    7621             :                 {
    7622          12 :                     FetchStmt *n = makeNode(FetchStmt);
    7623             : 
    7624          12 :                     n->portalname = $4;
    7625          12 :                     n->direction = FETCH_FORWARD;
    7626          12 :                     n->howMany = $2;
    7627          12 :                     n->location = @2;
    7628          12 :                     n->direction_keyword = FETCH_KEYWORD_FORWARD;
    7629          12 :                     $$ = (Node *) n;
    7630             :                 }
    7631             :             | FORWARD ALL opt_from_in cursor_name
    7632             :                 {
    7633          16 :                     FetchStmt *n = makeNode(FetchStmt);
    7634             : 
    7635          16 :                     n->portalname = $4;
    7636          16 :                     n->direction = FETCH_FORWARD;
    7637          16 :                     n->howMany = FETCH_ALL;
    7638          16 :                     n->location = -1;
    7639          16 :                     n->direction_keyword = FETCH_KEYWORD_FORWARD_ALL;
    7640          16 :                     $$ = (Node *) n;
    7641             :                 }
    7642             :             | BACKWARD opt_from_in cursor_name
    7643             :                 {
    7644          80 :                     FetchStmt *n = makeNode(FetchStmt);
    7645             : 
    7646          80 :                     n->portalname = $3;
    7647          80 :                     n->direction = FETCH_BACKWARD;
    7648          80 :                     n->howMany = 1;
    7649          80 :                     n->location = -1;
    7650          80 :                     n->direction_keyword = FETCH_KEYWORD_BACKWARD;
    7651          80 :                     $$ = (Node *) n;
    7652             :                 }
    7653             :             | BACKWARD SignedIconst opt_from_in cursor_name
    7654             :                 {
    7655         226 :                     FetchStmt *n = makeNode(FetchStmt);
    7656             : 
    7657         226 :                     n->portalname = $4;
    7658         226 :                     n->direction = FETCH_BACKWARD;
    7659         226 :                     n->howMany = $2;
    7660         226 :                     n->location = @2;
    7661         226 :                     n->direction_keyword = FETCH_KEYWORD_BACKWARD;
    7662         226 :                     $$ = (Node *) n;
    7663             :                 }
    7664             :             | BACKWARD ALL opt_from_in cursor_name
    7665             :                 {
    7666          92 :                     FetchStmt *n = makeNode(FetchStmt);
    7667             : 
    7668          92 :                     n->portalname = $4;
    7669          92 :                     n->direction = FETCH_BACKWARD;
    7670          92 :                     n->howMany = FETCH_ALL;
    7671          92 :                     n->location = -1;
    7672          92 :                     n->direction_keyword = FETCH_KEYWORD_BACKWARD_ALL;
    7673          92 :                     $$ = (Node *) n;
    7674             :                 }
    7675             :         ;
    7676             : 
    7677             : from_in:    FROM
    7678             :             | IN_P
    7679             :         ;
    7680             : 
    7681             : opt_from_in:    from_in
    7682             :             | /* EMPTY */
    7683             :         ;
    7684             : 
    7685             : 
    7686             : /*****************************************************************************
    7687             :  *
    7688             :  * GRANT and REVOKE statements
    7689             :  *
    7690             :  *****************************************************************************/
    7691             : 
    7692             : GrantStmt:  GRANT privileges ON privilege_target TO grantee_list
    7693             :             opt_grant_grant_option opt_granted_by
    7694             :                 {
    7695       11734 :                     GrantStmt *n = makeNode(GrantStmt);
    7696             : 
    7697       11734 :                     n->is_grant = true;
    7698       11734 :                     n->privileges = $2;
    7699       11734 :                     n->targtype = ($4)->targtype;
    7700       11734 :                     n->objtype = ($4)->objtype;
    7701       11734 :                     n->objects = ($4)->objs;
    7702       11734 :                     n->grantees = $6;
    7703       11734 :                     n->grant_option = $7;
    7704       11734 :                     n->grantor = $8;
    7705       11734 :                     $$ = (Node *) n;
    7706             :                 }
    7707             :         ;
    7708             : 
    7709             : RevokeStmt:
    7710             :             REVOKE privileges ON privilege_target
    7711             :             FROM grantee_list opt_granted_by opt_drop_behavior
    7712             :                 {
    7713       10392 :                     GrantStmt *n = makeNode(GrantStmt);
    7714             : 
    7715       10392 :                     n->is_grant = false;
    7716       10392 :                     n->grant_option = false;
    7717       10392 :                     n->privileges = $2;
    7718       10392 :                     n->targtype = ($4)->targtype;
    7719       10392 :                     n->objtype = ($4)->objtype;
    7720       10392 :                     n->objects = ($4)->objs;
    7721       10392 :                     n->grantees = $6;
    7722       10392 :                     n->grantor = $7;
    7723       10392 :                     n->behavior = $8;
    7724       10392 :                     $$ = (Node *) n;
    7725             :                 }
    7726             :             | REVOKE GRANT OPTION FOR privileges ON privilege_target
    7727             :             FROM grantee_list opt_granted_by opt_drop_behavior
    7728             :                 {
    7729          16 :                     GrantStmt *n = makeNode(GrantStmt);
    7730             : 
    7731          16 :                     n->is_grant = false;
    7732          16 :                     n->grant_option = true;
    7733          16 :                     n->privileges = $5;
    7734          16 :                     n->targtype = ($7)->targtype;
    7735          16 :                     n->objtype = ($7)->objtype;
    7736          16 :                     n->objects = ($7)->objs;
    7737          16 :                     n->grantees = $9;
    7738          16 :                     n->grantor = $10;
    7739          16 :                     n->behavior = $11;
    7740          16 :                     $$ = (Node *) n;
    7741             :                 }
    7742             :         ;
    7743             : 
    7744             : 
    7745             : /*
    7746             :  * Privilege names are represented as strings; the validity of the privilege
    7747             :  * names gets checked at execution.  This is a bit annoying but we have little
    7748             :  * choice because of the syntactic conflict with lists of role names in
    7749             :  * GRANT/REVOKE.  What's more, we have to call out in the "privilege"
    7750             :  * production any reserved keywords that need to be usable as privilege names.
    7751             :  */
    7752             : 
    7753             : /* either ALL [PRIVILEGES] or a list of individual privileges */
    7754             : privileges: privilege_list
    7755       19574 :                 { $$ = $1; }
    7756             :             | ALL
    7757        2630 :                 { $$ = NIL; }
    7758             :             | ALL PRIVILEGES
    7759         122 :                 { $$ = NIL; }
    7760             :             | ALL '(' columnList ')'
    7761             :                 {
    7762          18 :                     AccessPriv *n = makeNode(AccessPriv);
    7763             : 
    7764          18 :                     n->priv_name = NULL;
    7765          18 :                     n->cols = $3;
    7766          18 :                     $$ = list_make1(n);
    7767             :                 }
    7768             :             | ALL PRIVILEGES '(' columnList ')'
    7769             :                 {
    7770           0 :                     AccessPriv *n = makeNode(AccessPriv);
    7771             : 
    7772           0 :                     n->priv_name = NULL;
    7773           0 :                     n->cols = $4;
    7774           0 :                     $$ = list_make1(n);
    7775             :                 }
    7776             :         ;
    7777             : 
    7778       20504 : privilege_list: privilege                           { $$ = list_make1($1); }
    7779         570 :             | privilege_list ',' privilege          { $$ = lappend($1, $3); }
    7780             :         ;
    7781             : 
    7782             : privilege:  SELECT opt_column_list
    7783             :             {
    7784        9538 :                 AccessPriv *n = makeNode(AccessPriv);
    7785             : 
    7786        9538 :                 n->priv_name = pstrdup($1);
    7787        9538 :                 n->cols = $2;
    7788        9538 :                 $$ = n;
    7789             :             }
    7790             :         | REFERENCES opt_column_list
    7791             :             {
    7792          16 :                 AccessPriv *n = makeNode(AccessPriv);
    7793             : 
    7794          16 :                 n->priv_name = pstrdup($1);
    7795          16 :                 n->cols = $2;
    7796          16 :                 $$ = n;
    7797             :             }
    7798             :         | CREATE opt_column_list
    7799             :             {
    7800         298 :                 AccessPriv *n = makeNode(AccessPriv);
    7801             : 
    7802         298 :                 n->priv_name = pstrdup($1);
    7803         298 :                 n->cols = $2;
    7804         298 :                 $$ = n;
    7805             :             }
    7806             :         | ALTER SYSTEM_P
    7807             :             {
    7808          24 :                 AccessPriv *n = makeNode(AccessPriv);
    7809          24 :                 n->priv_name = pstrdup("alter system");
    7810          24 :                 n->cols = NIL;
    7811          24 :                 $$ = n;
    7812             :             }
    7813             :         | ColId opt_column_list
    7814             :             {
    7815       11198 :                 AccessPriv *n = makeNode(AccessPriv);
    7816             : 
    7817       11198 :                 n->priv_name = $1;
    7818       11198 :                 n->cols = $2;
    7819       11198 :                 $$ = n;
    7820             :             }
    7821             :         ;
    7822             : 
    7823             : parameter_name_list:
    7824             :         parameter_name
    7825             :             {
    7826          74 :                 $$ = list_make1(makeString($1));
    7827             :             }
    7828             :         | parameter_name_list ',' parameter_name
    7829             :             {
    7830          50 :                 $$ = lappend($1, makeString($3));
    7831             :             }
    7832             :         ;
    7833             : 
    7834             : parameter_name:
    7835             :         ColId
    7836             :             {
    7837         124 :                 $$ = $1;
    7838             :             }
    7839             :         | parameter_name '.' ColId
    7840             :             {
    7841          30 :                 $$ = psprintf("%s.%s", $1, $3);
    7842             :             }
    7843             :         ;
    7844             : 
    7845             : 
    7846             : /* Don't bother trying to fold the first two rules into one using
    7847             :  * opt_table.  You're going to get conflicts.
    7848             :  */
    7849             : privilege_target:
    7850             :             qualified_name_list
    7851             :                 {
    7852       11486 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7853             : 
    7854       11486 :                     n->targtype = ACL_TARGET_OBJECT;
    7855       11486 :                     n->objtype = OBJECT_TABLE;
    7856       11486 :                     n->objs = $1;
    7857       11486 :                     $$ = n;
    7858             :                 }
    7859             :             | TABLE qualified_name_list
    7860             :                 {
    7861         420 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7862             : 
    7863         420 :                     n->targtype = ACL_TARGET_OBJECT;
    7864         420 :                     n->objtype = OBJECT_TABLE;
    7865         420 :                     n->objs = $2;
    7866         420 :                     $$ = n;
    7867             :                 }
    7868             :             | SEQUENCE qualified_name_list
    7869             :                 {
    7870          24 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7871             : 
    7872          24 :                     n->targtype = ACL_TARGET_OBJECT;
    7873          24 :                     n->objtype = OBJECT_SEQUENCE;
    7874          24 :                     n->objs = $2;
    7875          24 :                     $$ = n;
    7876             :                 }
    7877             :             | FOREIGN DATA_P WRAPPER name_list
    7878             :                 {
    7879          92 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7880             : 
    7881          92 :                     n->targtype = ACL_TARGET_OBJECT;
    7882          92 :                     n->objtype = OBJECT_FDW;
    7883          92 :                     n->objs = $4;
    7884          92 :                     $$ = n;
    7885             :                 }
    7886             :             | FOREIGN SERVER name_list
    7887             :                 {
    7888          88 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7889             : 
    7890          88 :                     n->targtype = ACL_TARGET_OBJECT;
    7891          88 :                     n->objtype = OBJECT_FOREIGN_SERVER;
    7892          88 :                     n->objs = $3;
    7893          88 :                     $$ = n;
    7894             :                 }
    7895             :             | FUNCTION function_with_argtypes_list
    7896             :                 {
    7897        8904 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7898             : 
    7899        8904 :                     n->targtype = ACL_TARGET_OBJECT;
    7900        8904 :                     n->objtype = OBJECT_FUNCTION;
    7901        8904 :                     n->objs = $2;
    7902        8904 :                     $$ = n;
    7903             :                 }
    7904             :             | PROCEDURE function_with_argtypes_list
    7905             :                 {
    7906          42 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7907             : 
    7908          42 :                     n->targtype = ACL_TARGET_OBJECT;
    7909          42 :                     n->objtype = OBJECT_PROCEDURE;
    7910          42 :                     n->objs = $2;
    7911          42 :                     $$ = n;
    7912             :                 }
    7913             :             | ROUTINE function_with_argtypes_list
    7914             :                 {
    7915           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7916             : 
    7917           0 :                     n->targtype = ACL_TARGET_OBJECT;
    7918           0 :                     n->objtype = OBJECT_ROUTINE;
    7919           0 :                     n->objs = $2;
    7920           0 :                     $$ = n;
    7921             :                 }
    7922             :             | DATABASE name_list
    7923             :                 {
    7924         352 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7925             : 
    7926         352 :                     n->targtype = ACL_TARGET_OBJECT;
    7927         352 :                     n->objtype = OBJECT_DATABASE;
    7928         352 :                     n->objs = $2;
    7929         352 :                     $$ = n;
    7930             :                 }
    7931             :             | DOMAIN_P any_name_list
    7932             :                 {
    7933          26 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7934             : 
    7935          26 :                     n->targtype = ACL_TARGET_OBJECT;
    7936          26 :                     n->objtype = OBJECT_DOMAIN;
    7937          26 :                     n->objs = $2;
    7938          26 :                     $$ = n;
    7939             :                 }
    7940             :             | LANGUAGE name_list
    7941             :                 {
    7942          42 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7943             : 
    7944          42 :                     n->targtype = ACL_TARGET_OBJECT;
    7945          42 :                     n->objtype = OBJECT_LANGUAGE;
    7946          42 :                     n->objs = $2;
    7947          42 :                     $$ = n;
    7948             :                 }
    7949             :             | LARGE_P OBJECT_P NumericOnly_list
    7950             :                 {
    7951          80 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7952             : 
    7953          80 :                     n->targtype = ACL_TARGET_OBJECT;
    7954          80 :                     n->objtype = OBJECT_LARGEOBJECT;
    7955          80 :                     n->objs = $3;
    7956          80 :                     $$ = n;
    7957             :                 }
    7958             :             | PARAMETER parameter_name_list
    7959             :                 {
    7960          74 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7961          74 :                     n->targtype = ACL_TARGET_OBJECT;
    7962          74 :                     n->objtype = OBJECT_PARAMETER_ACL;
    7963          74 :                     n->objs = $2;
    7964          74 :                     $$ = n;
    7965             :                 }
    7966             :             | SCHEMA name_list
    7967             :                 {
    7968         376 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7969             : 
    7970         376 :                     n->targtype = ACL_TARGET_OBJECT;
    7971         376 :                     n->objtype = OBJECT_SCHEMA;
    7972         376 :                     n->objs = $2;
    7973         376 :                     $$ = n;
    7974             :                 }
    7975             :             | TABLESPACE name_list
    7976             :                 {
    7977           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7978             : 
    7979           6 :                     n->targtype = ACL_TARGET_OBJECT;
    7980           6 :                     n->objtype = OBJECT_TABLESPACE;
    7981           6 :                     n->objs = $2;
    7982           6 :                     $$ = n;
    7983             :                 }
    7984             :             | TYPE_P any_name_list
    7985             :                 {
    7986         112 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7987             : 
    7988         112 :                     n->targtype = ACL_TARGET_OBJECT;
    7989         112 :                     n->objtype = OBJECT_TYPE;
    7990         112 :                     n->objs = $2;
    7991         112 :                     $$ = n;
    7992             :                 }
    7993             :             | ALL TABLES IN_P SCHEMA name_list
    7994             :                 {
    7995          12 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7996             : 
    7997          12 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7998          12 :                     n->objtype = OBJECT_TABLE;
    7999          12 :                     n->objs = $5;
    8000          12 :                     $$ = n;
    8001             :                 }
    8002             :             | ALL SEQUENCES IN_P SCHEMA name_list
    8003             :                 {
    8004           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    8005             : 
    8006           0 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8007           0 :                     n->objtype = OBJECT_SEQUENCE;
    8008           0 :                     n->objs = $5;
    8009           0 :                     $$ = n;
    8010             :                 }
    8011             :             | ALL FUNCTIONS IN_P SCHEMA name_list
    8012             :                 {
    8013           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    8014             : 
    8015           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8016           6 :                     n->objtype = OBJECT_FUNCTION;
    8017           6 :                     n->objs = $5;
    8018           6 :                     $$ = n;
    8019             :                 }
    8020             :             | ALL PROCEDURES IN_P SCHEMA name_list
    8021             :                 {
    8022           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    8023             : 
    8024           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8025           6 :                     n->objtype = OBJECT_PROCEDURE;
    8026           6 :                     n->objs = $5;
    8027           6 :                     $$ = n;
    8028             :                 }
    8029             :             | ALL ROUTINES IN_P SCHEMA name_list
    8030             :                 {
    8031           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    8032             : 
    8033           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8034           6 :                     n->objtype = OBJECT_ROUTINE;
    8035           6 :                     n->objs = $5;
    8036           6 :                     $$ = n;
    8037             :                 }
    8038             :         ;
    8039             : 
    8040             : 
    8041             : grantee_list:
    8042       22332 :             grantee                                 { $$ = list_make1($1); }
    8043         108 :             | grantee_list ',' grantee              { $$ = lappend($1, $3); }
    8044             :         ;
    8045             : 
    8046             : grantee:
    8047       22416 :             RoleSpec                                { $$ = $1; }
    8048          24 :             | GROUP_P RoleSpec                      { $$ = $2; }
    8049             :         ;
    8050             : 
    8051             : 
    8052             : opt_grant_grant_option:
    8053         102 :             WITH GRANT OPTION { $$ = true; }
    8054       11756 :             | /*EMPTY*/ { $$ = false; }
    8055             :         ;
    8056             : 
    8057             : /*****************************************************************************
    8058             :  *
    8059             :  * GRANT and REVOKE ROLE statements
    8060             :  *
    8061             :  *****************************************************************************/
    8062             : 
    8063             : GrantRoleStmt:
    8064             :             GRANT privilege_list TO role_list opt_granted_by
    8065             :                 {
    8066         596 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8067             : 
    8068         596 :                     n->is_grant = true;
    8069         596 :                     n->granted_roles = $2;
    8070         596 :                     n->grantee_roles = $4;
    8071         596 :                     n->opt = NIL;
    8072         596 :                     n->grantor = $5;
    8073         596 :                     $$ = (Node *) n;
    8074             :                 }
    8075             :           | GRANT privilege_list TO role_list WITH grant_role_opt_list opt_granted_by
    8076             :                 {
    8077         178 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8078             : 
    8079         178 :                     n->is_grant = true;
    8080         178 :                     n->granted_roles = $2;
    8081         178 :                     n->grantee_roles = $4;
    8082         178 :                     n->opt = $6;
    8083         178 :                     n->grantor = $7;
    8084         178 :                     $$ = (Node *) n;
    8085             :                 }
    8086             :         ;
    8087             : 
    8088             : RevokeRoleStmt:
    8089             :             REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
    8090             :                 {
    8091          90 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8092             : 
    8093          90 :                     n->is_grant = false;
    8094          90 :                     n->opt = NIL;
    8095          90 :                     n->granted_roles = $2;
    8096          90 :                     n->grantee_roles = $4;
    8097          90 :                     n->grantor = $5;
    8098          90 :                     n->behavior = $6;
    8099          90 :                     $$ = (Node *) n;
    8100             :                 }
    8101             :             | REVOKE ColId OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
    8102             :                 {
    8103          66 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8104             :                     DefElem *opt;
    8105             : 
    8106          66 :                     opt = makeDefElem(pstrdup($2),
    8107          66 :                                       (Node *) makeBoolean(false), @2);
    8108          66 :                     n->is_grant = false;
    8109          66 :                     n->opt = list_make1(opt);
    8110          66 :                     n->granted_roles = $5;
    8111          66 :                     n->grantee_roles = $7;
    8112          66 :                     n->grantor = $8;
    8113          66 :                     n->behavior = $9;
    8114          66 :                     $$ = (Node *) n;
    8115             :                 }
    8116             :         ;
    8117             : 
    8118             : grant_role_opt_list:
    8119         120 :             grant_role_opt_list ',' grant_role_opt  { $$ = lappend($1, $3); }
    8120         178 :             | grant_role_opt                        { $$ = list_make1($1); }
    8121             :         ;
    8122             : 
    8123             : grant_role_opt:
    8124             :         ColLabel grant_role_opt_value
    8125             :             {
    8126         298 :                 $$ = makeDefElem(pstrdup($1), $2, @1);
    8127             :             }
    8128             :         ;
    8129             : 
    8130             : grant_role_opt_value:
    8131          72 :         OPTION          { $$ = (Node *) makeBoolean(true); }
    8132         112 :         | TRUE_P        { $$ = (Node *) makeBoolean(true); }
    8133         114 :         | FALSE_P       { $$ = (Node *) makeBoolean(false); }
    8134             :         ;
    8135             : 
    8136         138 : opt_granted_by: GRANTED BY RoleSpec                     { $$ = $3; }
    8137       22934 :             | /*EMPTY*/                                 { $$ = NULL; }
    8138             :         ;
    8139             : 
    8140             : /*****************************************************************************
    8141             :  *
    8142             :  * ALTER DEFAULT PRIVILEGES statement
    8143             :  *
    8144             :  *****************************************************************************/
    8145             : 
    8146             : AlterDefaultPrivilegesStmt:
    8147             :             ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
    8148             :                 {
    8149         190 :                     AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
    8150             : 
    8151         190 :                     n->options = $4;
    8152         190 :                     n->action = (GrantStmt *) $5;
    8153         190 :                     $$ = (Node *) n;
    8154             :                 }
    8155             :         ;
    8156             : 
    8157             : DefACLOptionList:
    8158         128 :             DefACLOptionList DefACLOption           { $$ = lappend($1, $2); }
    8159         190 :             | /* EMPTY */                           { $$ = NIL; }
    8160             :         ;
    8161             : 
    8162             : DefACLOption:
    8163             :             IN_P SCHEMA name_list
    8164             :                 {
    8165          60 :                     $$ = makeDefElem("schemas", (Node *) $3, @1);
    8166             :                 }
    8167             :             | FOR ROLE role_list
    8168             :                 {
    8169          68 :                     $$ = makeDefElem("roles", (Node *) $3, @1);
    8170             :                 }
    8171             :             | FOR USER role_list
    8172             :                 {
    8173           0 :                     $$ = makeDefElem("roles", (Node *) $3, @1);
    8174             :                 }
    8175             :         ;
    8176             : 
    8177             : /*
    8178             :  * This should match GRANT/REVOKE, except that individual target objects
    8179             :  * are not mentioned and we only allow a subset of object types.
    8180             :  */
    8181             : DefACLAction:
    8182             :             GRANT privileges ON defacl_privilege_target TO grantee_list
    8183             :             opt_grant_grant_option
    8184             :                 {
    8185         124 :                     GrantStmt *n = makeNode(GrantStmt);
    8186             : 
    8187         124 :                     n->is_grant = true;
    8188         124 :                     n->privileges = $2;
    8189         124 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8190         124 :                     n->objtype = $4;
    8191         124 :                     n->objects = NIL;
    8192         124 :                     n->grantees = $6;
    8193         124 :                     n->grant_option = $7;
    8194         124 :                     $$ = (Node *) n;
    8195             :                 }
    8196             :             | REVOKE privileges ON defacl_privilege_target
    8197             :             FROM grantee_list opt_drop_behavior
    8198             :                 {
    8199          66 :                     GrantStmt *n = makeNode(GrantStmt);
    8200             : 
    8201          66 :                     n->is_grant = false;
    8202          66 :                     n->grant_option = false;
    8203          66 :                     n->privileges = $2;
    8204          66 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8205          66 :                     n->objtype = $4;
    8206          66 :                     n->objects = NIL;
    8207          66 :                     n->grantees = $6;
    8208          66 :                     n->behavior = $7;
    8209          66 :                     $$ = (Node *) n;
    8210             :                 }
    8211             :             | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
    8212             :             FROM grantee_list opt_drop_behavior
    8213             :                 {
    8214           0 :                     GrantStmt *n = makeNode(GrantStmt);
    8215             : 
    8216           0 :                     n->is_grant = false;
    8217           0 :                     n->grant_option = true;
    8218           0 :                     n->privileges = $5;
    8219           0 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8220           0 :                     n->objtype = $7;
    8221           0 :                     n->objects = NIL;
    8222           0 :                     n->grantees = $9;
    8223           0 :                     n->behavior = $10;
    8224           0 :                     $$ = (Node *) n;
    8225             :                 }
    8226             :         ;
    8227             : 
    8228             : defacl_privilege_target:
    8229          78 :             TABLES          { $$ = OBJECT_TABLE; }
    8230          16 :             | FUNCTIONS     { $$ = OBJECT_FUNCTION; }
    8231           6 :             | ROUTINES      { $$ = OBJECT_FUNCTION; }
    8232           6 :             | SEQUENCES     { $$ = OBJECT_SEQUENCE; }
    8233          18 :             | TYPES_P       { $$ = OBJECT_TYPE; }
    8234          36 :             | SCHEMAS       { $$ = OBJECT_SCHEMA; }
    8235          30 :             | LARGE_P OBJECTS_P { $$ = OBJECT_LARGEOBJECT; }
    8236             :         ;
    8237             : 
    8238             : 
    8239             : /*****************************************************************************
    8240             :  *
    8241             :  *      QUERY: CREATE INDEX
    8242             :  *
    8243             :  * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
    8244             :  * willing to make TABLESPACE a fully reserved word.
    8245             :  *****************************************************************************/
    8246             : 
    8247             : IndexStmt:  CREATE opt_unique INDEX opt_concurrently opt_single_name
    8248             :             ON relation_expr access_method_clause '(' index_params ')'
    8249             :             opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
    8250             :                 {
    8251        6902 :                     IndexStmt *n = makeNode(IndexStmt);
    8252             : 
    8253        6902 :                     n->unique = $2;
    8254        6902 :                     n->concurrent = $4;
    8255        6902 :                     n->idxname = $5;
    8256        6902 :                     n->relation = $7;
    8257        6902 :                     n->accessMethod = $8;
    8258        6902 :                     n->indexParams = $10;
    8259        6902 :                     n->indexIncludingParams = $12;
    8260        6902 :                     n->nulls_not_distinct = !$13;
    8261        6902 :                     n->options = $14;
    8262        6902 :                     n->tableSpace = $15;
    8263        6902 :                     n->whereClause = $16;
    8264        6902 :                     n->excludeOpNames = NIL;
    8265        6902 :                     n->idxcomment = NULL;
    8266        6902 :                     n->indexOid = InvalidOid;
    8267        6902 :                     n->oldNumber = InvalidRelFileNumber;
    8268        6902 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8269        6902 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8270        6902 :                     n->primary = false;
    8271        6902 :                     n->isconstraint = false;
    8272        6902 :                     n->deferrable = false;
    8273        6902 :                     n->initdeferred = false;
    8274        6902 :                     n->transformed = false;
    8275        6902 :                     n->if_not_exists = false;
    8276        6902 :                     n->reset_default_tblspc = false;
    8277        6902 :                     $$ = (Node *) n;
    8278             :                 }
    8279             :             | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS name
    8280             :             ON relation_expr access_method_clause '(' index_params ')'
    8281             :             opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
    8282             :                 {
    8283          18 :                     IndexStmt *n = makeNode(IndexStmt);
    8284             : 
    8285          18 :                     n->unique = $2;
    8286          18 :                     n->concurrent = $4;
    8287          18 :                     n->idxname = $8;
    8288          18 :                     n->relation = $10;
    8289          18 :                     n->accessMethod = $11;
    8290          18 :                     n->indexParams = $13;
    8291          18 :                     n->indexIncludingParams = $15;
    8292          18 :                     n->nulls_not_distinct = !$16;
    8293          18 :                     n->options = $17;
    8294          18 :                     n->tableSpace = $18;
    8295          18 :                     n->whereClause = $19;
    8296          18 :                     n->excludeOpNames = NIL;
    8297          18 :                     n->idxcomment = NULL;
    8298          18 :                     n->indexOid = InvalidOid;
    8299          18 :                     n->oldNumber = InvalidRelFileNumber;
    8300          18 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8301          18 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8302          18 :                     n->primary = false;
    8303          18 :                     n->isconstraint = false;
    8304          18 :                     n->deferrable = false;
    8305          18 :                     n->initdeferred = false;
    8306          18 :                     n->transformed = false;
    8307          18 :                     n->if_not_exists = true;
    8308          18 :                     n->reset_default_tblspc = false;
    8309          18 :                     $$ = (Node *) n;
    8310             :                 }
    8311             :         ;
    8312             : 
    8313             : opt_unique:
    8314        1378 :             UNIQUE                                  { $$ = true; }
    8315        5548 :             | /*EMPTY*/                             { $$ = false; }
    8316             :         ;
    8317             : 
    8318             : access_method_clause:
    8319        3300 :             USING name                              { $$ = $2; }
    8320        3858 :             | /*EMPTY*/                             { $$ = DEFAULT_INDEX_TYPE; }
    8321             :         ;
    8322             : 
    8323        8346 : index_params:   index_elem                          { $$ = list_make1($1); }
    8324        2326 :             | index_params ',' index_elem           { $$ = lappend($1, $3); }
    8325             :         ;
    8326             : 
    8327             : 
    8328             : index_elem_options:
    8329             :     opt_collate opt_qualified_name opt_asc_desc opt_nulls_order
    8330             :         {
    8331       11280 :             $$ = makeNode(IndexElem);
    8332       11280 :             $$->name = NULL;
    8333       11280 :             $$->expr = NULL;
    8334       11280 :             $$->indexcolname = NULL;
    8335       11280 :             $$->collation = $1;
    8336       11280 :             $$->opclass = $2;
    8337       11280 :             $$->opclassopts = NIL;
    8338       11280 :             $$->ordering = $3;
    8339       11280 :             $$->nulls_ordering = $4;
    8340             :         }
    8341             :     | opt_collate any_name reloptions opt_asc_desc opt_nulls_order
    8342             :         {
    8343         142 :             $$ = makeNode(IndexElem);
    8344         142 :             $$->name = NULL;
    8345         142 :             $$->expr = NULL;
    8346         142 :             $$->indexcolname = NULL;
    8347         142 :             $$->collation = $1;
    8348         142 :             $$->opclass = $2;
    8349         142 :             $$->opclassopts = $3;
    8350         142 :             $$->ordering = $4;
    8351         142 :             $$->nulls_ordering = $5;
    8352             :         }
    8353             :     ;
    8354             : 
    8355             : /*
    8356             :  * Index attributes can be either simple column references, or arbitrary
    8357             :  * expressions in parens.  For backwards-compatibility reasons, we allow
    8358             :  * an expression that's just a function call to be written without parens.
    8359             :  */
    8360             : index_elem: ColId index_elem_options
    8361             :                 {
    8362       10268 :                     $$ = $2;
    8363       10268 :                     $$->name = $1;
    8364             :                 }
    8365             :             | func_expr_windowless index_elem_options
    8366             :                 {
    8367         612 :                     $$ = $2;
    8368         612 :                     $$->expr = $1;
    8369             :                 }
    8370             :             | '(' a_expr ')' index_elem_options
    8371             :                 {
    8372         542 :                     $$ = $4;
    8373         542 :                     $$->expr = $2;
    8374             :                 }
    8375             :         ;
    8376             : 
    8377         232 : opt_include:        INCLUDE '(' index_including_params ')'          { $$ = $3; }
    8378        6688 :              |      /* EMPTY */                     { $$ = NIL; }
    8379             :         ;
    8380             : 
    8381         232 : index_including_params: index_elem                      { $$ = list_make1($1); }
    8382         170 :             | index_including_params ',' index_elem     { $$ = lappend($1, $3); }
    8383             :         ;
    8384             : 
    8385         192 : opt_collate: COLLATE any_name                       { $$ = $2; }
    8386       16848 :             | /*EMPTY*/                             { $$ = NIL; }
    8387             :         ;
    8388             : 
    8389             : 
    8390        1822 : opt_asc_desc: ASC                           { $$ = SORTBY_ASC; }
    8391        3556 :             | DESC                          { $$ = SORTBY_DESC; }
    8392      117268 :             | /*EMPTY*/                     { $$ = SORTBY_DEFAULT; }
    8393             :         ;
    8394             : 
    8395         344 : opt_nulls_order: NULLS_LA FIRST_P           { $$ = SORTBY_NULLS_FIRST; }
    8396        1732 :             | NULLS_LA LAST_P               { $$ = SORTBY_NULLS_LAST; }
    8397      120790 :             | /*EMPTY*/                     { $$ = SORTBY_NULLS_DEFAULT; }
    8398             :         ;
    8399             : 
    8400             : 
    8401             : /*****************************************************************************
    8402             :  *
    8403             :  *      QUERY:
    8404             :  *              create [or replace] function <fname>
    8405             :  *                      [(<type-1> { , <type-n>})]
    8406             :  *                      returns <type-r>
    8407             :  *                      as <filename or code in language as appropriate>
    8408             :  *                      language <lang> [with parameters]
    8409             :  *
    8410             :  *****************************************************************************/
    8411             : 
    8412             : CreateFunctionStmt:
    8413             :             CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8414             :             RETURNS func_return opt_createfunc_opt_list opt_routine_body
    8415             :                 {
    8416       23892 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8417             : 
    8418       23892 :                     n->is_procedure = false;
    8419       23892 :                     n->replace = $2;
    8420       23892 :                     n->funcname = $4;
    8421       23892 :                     n->parameters = $5;
    8422       23892 :                     n->returnType = $7;
    8423       23892 :                     n->options = $8;
    8424       23892 :                     n->sql_body = $9;
    8425       23892 :                     $$ = (Node *) n;
    8426             :                 }
    8427             :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8428             :               RETURNS TABLE '(' table_func_column_list ')' opt_createfunc_opt_list opt_routine_body
    8429             :                 {
    8430         202 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8431             : 
    8432         202 :                     n->is_procedure = false;
    8433         202 :                     n->replace = $2;
    8434         202 :                     n->funcname = $4;
    8435         202 :                     n->parameters = mergeTableFuncParameters($5, $9, yyscanner);
    8436         202 :                     n->returnType = TableFuncTypeName($9);
    8437         202 :                     n->returnType->location = @7;
    8438         202 :                     n->options = $11;
    8439         202 :                     n->sql_body = $12;
    8440         202 :                     $$ = (Node *) n;
    8441             :                 }
    8442             :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8443             :               opt_createfunc_opt_list opt_routine_body
    8444             :                 {
    8445         488 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8446             : 
    8447         488 :                     n->is_procedure = false;
    8448         488 :                     n->replace = $2;
    8449         488 :                     n->funcname = $4;
    8450         488 :                     n->parameters = $5;
    8451         488 :                     n->returnType = NULL;
    8452         488 :                     n->options = $6;
    8453         488 :                     n->sql_body = $7;
    8454         488 :                     $$ = (Node *) n;
    8455             :                 }
    8456             :             | CREATE opt_or_replace PROCEDURE func_name func_args_with_defaults
    8457             :               opt_createfunc_opt_list opt_routine_body
    8458             :                 {
    8459         392 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8460             : 
    8461         392 :                     n->is_procedure = true;
    8462         392 :                     n->replace = $2;
    8463         392 :                     n->funcname = $4;
    8464         392 :                     n->parameters = $5;
    8465         392 :                     n->returnType = NULL;
    8466         392 :                     n->options = $6;
    8467         392 :                     n->sql_body = $7;
    8468         392 :                     $$ = (Node *) n;
    8469             :                 }
    8470             :         ;
    8471             : 
    8472             : opt_or_replace:
    8473       10144 :             OR REPLACE                              { $$ = true; }
    8474       20560 :             | /*EMPTY*/                             { $$ = false; }
    8475             :         ;
    8476             : 
    8477       10416 : func_args:  '(' func_args_list ')'                  { $$ = $2; }
    8478        5970 :             | '(' ')'                               { $$ = NIL; }
    8479             :         ;
    8480             : 
    8481             : func_args_list:
    8482       10416 :             func_arg                                { $$ = list_make1($1); }
    8483        8386 :             | func_args_list ',' func_arg           { $$ = lappend($1, $3); }
    8484             :         ;
    8485             : 
    8486             : function_with_argtypes_list:
    8487       12624 :             function_with_argtypes                  { $$ = list_make1($1); }
    8488             :             | function_with_argtypes_list ',' function_with_argtypes
    8489          84 :                                                     { $$ = lappend($1, $3); }
    8490             :         ;
    8491             : 
    8492             : function_with_argtypes:
    8493             :             func_name func_args
    8494             :                 {
    8495       16386 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8496             : 
    8497       16386 :                     n->objname = $1;
    8498       16386 :                     n->objargs = extractArgTypes($2);
    8499       16386 :                     n->objfuncargs = $2;
    8500       16386 :                     $$ = n;
    8501             :                 }
    8502             :             /*
    8503             :              * Because of reduce/reduce conflicts, we can't use func_name
    8504             :              * below, but we can write it out the long way, which actually
    8505             :              * allows more cases.
    8506             :              */
    8507             :             | type_func_name_keyword
    8508             :                 {
    8509           0 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8510             : 
    8511           0 :                     n->objname = list_make1(makeString(pstrdup($1)));
    8512           0 :                     n->args_unspecified = true;
    8513           0 :                     $$ = n;
    8514             :                 }
    8515             :             | ColId
    8516             :                 {
    8517         346 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8518             : 
    8519         346 :                     n->objname = list_make1(makeString($1));
    8520         346 :                     n->args_unspecified = true;
    8521         346 :                     $$ = n;
    8522             :                 }
    8523             :             | ColId indirection
    8524             :                 {
    8525          28 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8526             : 
    8527          28 :                     n->objname = check_func_name(lcons(makeString($1), $2),
    8528             :                                                   yyscanner);
    8529          28 :                     n->args_unspecified = true;
    8530          28 :                     $$ = n;
    8531             :                 }
    8532             :         ;
    8533             : 
    8534             : /*
    8535             :  * func_args_with_defaults is separate because we only want to accept
    8536             :  * defaults in CREATE FUNCTION, not in ALTER etc.
    8537             :  */
    8538             : func_args_with_defaults:
    8539       20274 :         '(' func_args_with_defaults_list ')'        { $$ = $2; }
    8540        4700 :         | '(' ')'                                   { $$ = NIL; }
    8541             :         ;
    8542             : 
    8543             : func_args_with_defaults_list:
    8544       20274 :         func_arg_with_default                       { $$ = list_make1($1); }
    8545             :         | func_args_with_defaults_list ',' func_arg_with_default
    8546       33934 :                                                     { $$ = lappend($1, $3); }
    8547             :         ;
    8548             : 
    8549             : /*
    8550             :  * The style with arg_class first is SQL99 standard, but Oracle puts
    8551             :  * param_name first; accept both since it's likely people will try both
    8552             :  * anyway.  Don't bother trying to save productions by letting arg_class
    8553             :  * have an empty alternative ... you'll get shift/reduce conflicts.
    8554             :  *
    8555             :  * We can catch over-specified arguments here if we want to,
    8556             :  * but for now better to silently swallow typmod, etc.
    8557             :  * - thomas 2000-03-22
    8558             :  */
    8559             : func_arg:
    8560             :             arg_class param_name func_type
    8561             :                 {
    8562       16384 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8563             : 
    8564       16384 :                     n->name = $2;
    8565       16384 :                     n->argType = $3;
    8566       16384 :                     n->mode = $1;
    8567       16384 :                     n->defexpr = NULL;
    8568       16384 :                     n->location = @1;
    8569       16384 :                     $$ = n;
    8570             :                 }
    8571             :             | param_name arg_class func_type
    8572             :                 {
    8573         420 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8574             : 
    8575         420 :                     n->name = $1;
    8576         420 :                     n->argType = $3;
    8577         420 :                     n->mode = $2;
    8578         420 :                     n->defexpr = NULL;
    8579         420 :                     n->location = @1;
    8580         420 :                     $$ = n;
    8581             :                 }
    8582             :             | param_name func_type
    8583             :                 {
    8584       16118 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8585             : 
    8586       16118 :                     n->name = $1;
    8587       16118 :                     n->argType = $2;
    8588       16118 :                     n->mode = FUNC_PARAM_DEFAULT;
    8589       16118 :                     n->defexpr = NULL;
    8590       16118 :                     n->location = @1;
    8591       16118 :                     $$ = n;
    8592             :                 }
    8593             :             | arg_class func_type
    8594             :                 {
    8595         358 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8596             : 
    8597         358 :                     n->name = NULL;
    8598         358 :                     n->argType = $2;
    8599         358 :                     n->mode = $1;
    8600         358 :                     n->defexpr = NULL;
    8601         358 :                     n->location = @1;
    8602         358 :                     $$ = n;
    8603             :                 }
    8604             :             | func_type
    8605             :                 {
    8606       40828 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8607             : 
    8608       40828 :                     n->name = NULL;
    8609       40828 :                     n->argType = $1;
    8610       40828 :                     n->mode = FUNC_PARAM_DEFAULT;
    8611       40828 :                     n->defexpr = NULL;
    8612       40828 :                     n->location = @1;
    8613       40828 :                     $$ = n;
    8614             :                 }
    8615             :         ;
    8616             : 
    8617             : /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
    8618        4088 : arg_class:  IN_P                                { $$ = FUNC_PARAM_IN; }
    8619       12250 :             | OUT_P                             { $$ = FUNC_PARAM_OUT; }
    8620         218 :             | INOUT                             { $$ = FUNC_PARAM_INOUT; }
    8621           0 :             | IN_P OUT_P                        { $$ = FUNC_PARAM_INOUT; }
    8622         606 :             | VARIADIC                          { $$ = FUNC_PARAM_VARIADIC; }
    8623             :         ;
    8624             : 
    8625             : /*
    8626             :  * Ideally param_name should be ColId, but that causes too many conflicts.
    8627             :  */
    8628             : param_name: type_function_name
    8629             :         ;
    8630             : 
    8631             : func_return:
    8632             :             func_type
    8633             :                 {
    8634             :                     /* We can catch over-specified results here if we want to,
    8635             :                      * but for now better to silently swallow typmod, etc.
    8636             :                      * - thomas 2000-03-22
    8637             :                      */
    8638       23892 :                     $$ = $1;
    8639             :                 }
    8640             :         ;
    8641             : 
    8642             : /*
    8643             :  * We would like to make the %TYPE productions here be ColId attrs etc,
    8644             :  * but that causes reduce/reduce conflicts.  type_function_name
    8645             :  * is next best choice.
    8646             :  */
    8647      119600 : func_type:  Typename                                { $$ = $1; }
    8648             :             | type_function_name attrs '%' TYPE_P
    8649             :                 {
    8650          18 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
    8651          18 :                     $$->pct_type = true;
    8652          18 :                     $$->location = @1;
    8653             :                 }
    8654             :             | SETOF type_function_name attrs '%' TYPE_P
    8655             :                 {
    8656           6 :                     $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
    8657           6 :                     $$->pct_type = true;
    8658           6 :                     $$->setof = true;
    8659           6 :                     $$->location = @2;
    8660             :                 }
    8661             :         ;
    8662             : 
    8663             : func_arg_with_default:
    8664             :         func_arg
    8665             :                 {
    8666       47658 :                     $$ = $1;
    8667             :                 }
    8668             :         | func_arg DEFAULT a_expr
    8669             :                 {
    8670        6354 :                     $$ = $1;
    8671        6354 :                     $$->defexpr = $3;
    8672             :                 }
    8673             :         | func_arg '=' a_expr
    8674             :                 {
    8675         196 :                     $$ = $1;
    8676         196 :                     $$->defexpr = $3;
    8677             :                 }
    8678             :         ;
    8679             : 
    8680             : /* Aggregate args can be most things that function args can be */
    8681             : aggr_arg:   func_arg
    8682             :                 {
    8683        1098 :                     if (!($1->mode == FUNC_PARAM_DEFAULT ||
    8684          76 :                           $1->mode == FUNC_PARAM_IN ||
    8685          76 :                           $1->mode == FUNC_PARAM_VARIADIC))
    8686           0 :                         ereport(ERROR,
    8687             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    8688             :                                  errmsg("aggregates cannot have output arguments"),
    8689             :                                  parser_errposition(@1)));
    8690        1098 :                     $$ = $1;
    8691             :                 }
    8692             :         ;
    8693             : 
    8694             : /*
    8695             :  * The SQL standard offers no guidance on how to declare aggregate argument
    8696             :  * lists, since it doesn't have CREATE AGGREGATE etc.  We accept these cases:
    8697             :  *
    8698             :  * (*)                                  - normal agg with no args
    8699             :  * (aggr_arg,...)                       - normal agg with args
    8700             :  * (ORDER BY aggr_arg,...)              - ordered-set agg with no direct args
    8701             :  * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
    8702             :  *
    8703             :  * The zero-argument case is spelled with '*' for consistency with COUNT(*).
    8704             :  *
    8705             :  * An additional restriction is that if the direct-args list ends in a
    8706             :  * VARIADIC item, the ordered-args list must contain exactly one item that
    8707             :  * is also VARIADIC with the same type.  This allows us to collapse the two
    8708             :  * VARIADIC items into one, which is necessary to represent the aggregate in
    8709             :  * pg_proc.  We check this at the grammar stage so that we can return a list
    8710             :  * in which the second VARIADIC item is already discarded, avoiding extra work
    8711             :  * in cases such as DROP AGGREGATE.
    8712             :  *
    8713             :  * The return value of this production is a two-element list, in which the
    8714             :  * first item is a sublist of FunctionParameter nodes (with any duplicate
    8715             :  * VARIADIC item already dropped, as per above) and the second is an Integer
    8716             :  * node, containing -1 if there was no ORDER BY and otherwise the number
    8717             :  * of argument declarations before the ORDER BY.  (If this number is equal
    8718             :  * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
    8719             :  * This representation is passed as-is to CREATE AGGREGATE; for operations
    8720             :  * on existing aggregates, we can just apply extractArgTypes to the first
    8721             :  * sublist.
    8722             :  */
    8723             : aggr_args:  '(' '*' ')'
    8724             :                 {
    8725         170 :                     $$ = list_make2(NIL, makeInteger(-1));
    8726             :                 }
    8727             :             | '(' aggr_args_list ')'
    8728             :                 {
    8729         882 :                     $$ = list_make2($2, makeInteger(-1));
    8730             :                 }
    8731             :             | '(' ORDER BY aggr_args_list ')'
    8732             :                 {
    8733           6 :                     $$ = list_make2($4, makeInteger(0));
    8734             :                 }
    8735             :             | '(' aggr_args_list ORDER BY aggr_args_list ')'
    8736             :                 {
    8737             :                     /* this is the only case requiring consistency checking */
    8738          40 :                     $$ = makeOrderedSetArgs($2, $5, yyscanner);
    8739             :                 }
    8740             :         ;
    8741             : 
    8742             : aggr_args_list:
    8743         968 :             aggr_arg                                { $$ = list_make1($1); }
    8744         130 :             | aggr_args_list ',' aggr_arg           { $$ = lappend($1, $3); }
    8745             :         ;
    8746             : 
    8747             : aggregate_with_argtypes:
    8748             :             func_name aggr_args
    8749             :                 {
    8750         460 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8751             : 
    8752         460 :                     n->objname = $1;
    8753         460 :                     n->objargs = extractAggrArgTypes($2);
    8754         460 :                     n->objfuncargs = (List *) linitial($2);
    8755         460 :                     $$ = n;
    8756             :                 }
    8757             :         ;
    8758             : 
    8759             : aggregate_with_argtypes_list:
    8760         104 :             aggregate_with_argtypes                 { $$ = list_make1($1); }
    8761             :             | aggregate_with_argtypes_list ',' aggregate_with_argtypes
    8762           0 :                                                     { $$ = lappend($1, $3); }
    8763             :         ;
    8764             : 
    8765             : opt_createfunc_opt_list:
    8766             :             createfunc_opt_list
    8767          54 :             | /*EMPTY*/ { $$ = NIL; }
    8768             :     ;
    8769             : 
    8770             : createfunc_opt_list:
    8771             :             /* Must be at least one to prevent conflict */
    8772       24920 :             createfunc_opt_item                     { $$ = list_make1($1); }
    8773       65330 :             | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
    8774             :     ;
    8775             : 
    8776             : /*
    8777             :  * Options common to both CREATE FUNCTION and ALTER FUNCTION
    8778             :  */
    8779             : common_func_opt_item:
    8780             :             CALLED ON NULL_P INPUT_P
    8781             :                 {
    8782         384 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(false), @1);
    8783             :                 }
    8784             :             | RETURNS NULL_P ON NULL_P INPUT_P
    8785             :                 {
    8786         900 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8787             :                 }
    8788             :             | STRICT_P
    8789             :                 {
    8790       12888 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8791             :                 }
    8792             :             | IMMUTABLE
    8793             :                 {
    8794        9374 :                     $$ = makeDefElem("volatility", (Node *) makeString("immutable"), @1);
    8795             :                 }
    8796             :             | STABLE
    8797             :                 {
    8798        2578 :                     $$ = makeDefElem("volatility", (Node *) makeString("stable"), @1);
    8799             :                 }
    8800             :             | VOLATILE
    8801             :                 {
    8802        1704 :                     $$ = makeDefElem("volatility", (Node *) makeString("volatile"), @1);
    8803             :                 }
    8804             :             | EXTERNAL SECURITY DEFINER
    8805             :                 {
    8806           0 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8807             :                 }
    8808             :             | EXTERNAL SECURITY INVOKER
    8809             :                 {
    8810           0 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8811             :                 }
    8812             :             | SECURITY DEFINER
    8813             :                 {
    8814          58 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8815             :                 }
    8816             :             | SECURITY INVOKER
    8817             :                 {
    8818          18 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8819             :                 }
    8820             :             | LEAKPROOF
    8821             :                 {
    8822          50 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(true), @1);
    8823             :                 }
    8824             :             | NOT LEAKPROOF
    8825             :                 {
    8826          12 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(false), @1);
    8827             :                 }
    8828             :             | COST NumericOnly
    8829             :                 {
    8830        4450 :                     $$ = makeDefElem("cost", (Node *) $2, @1);
    8831             :                 }
    8832             :             | ROWS NumericOnly
    8833             :                 {
    8834         612 :                     $$ = makeDefElem("rows", (Node *) $2, @1);
    8835             :                 }
    8836             :             | SUPPORT any_name
    8837             :                 {
    8838         120 :                     $$ = makeDefElem("support", (Node *) $2, @1);
    8839             :                 }
    8840             :             | FunctionSetResetClause
    8841             :                 {
    8842             :                     /* we abuse the normal content of a DefElem here */
    8843         160 :                     $$ = makeDefElem("set", (Node *) $1, @1);
    8844             :                 }
    8845             :             | PARALLEL ColId
    8846             :                 {
    8847       13396 :                     $$ = makeDefElem("parallel", (Node *) makeString($2), @1);
    8848             :                 }
    8849             :         ;
    8850             : 
    8851             : createfunc_opt_item:
    8852             :             AS func_as
    8853             :                 {
    8854       19182 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    8855             :                 }
    8856             :             | LANGUAGE NonReservedWord_or_Sconst
    8857             :                 {
    8858       24900 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    8859             :                 }
    8860             :             | TRANSFORM transform_type_list
    8861             :                 {
    8862         118 :                     $$ = makeDefElem("transform", (Node *) $2, @1);
    8863             :                 }
    8864             :             | WINDOW
    8865             :                 {
    8866          22 :                     $$ = makeDefElem("window", (Node *) makeBoolean(true), @1);
    8867             :                 }
    8868             :             | common_func_opt_item
    8869             :                 {
    8870       46028 :                     $$ = $1;
    8871             :                 }
    8872             :         ;
    8873             : 
    8874       15990 : func_as:    Sconst                      { $$ = list_make1(makeString($1)); }
    8875             :             | Sconst ',' Sconst
    8876             :                 {
    8877        3192 :                     $$ = list_make2(makeString($1), makeString($3));
    8878             :                 }
    8879             :         ;
    8880             : 
    8881             : ReturnStmt: RETURN a_expr
    8882             :                 {
    8883        4980 :                     ReturnStmt *r = makeNode(ReturnStmt);
    8884             : 
    8885        4980 :                     r->returnval = (Node *) $2;
    8886        4980 :                     $$ = (Node *) r;
    8887             :                 }
    8888             :         ;
    8889             : 
    8890             : opt_routine_body:
    8891             :             ReturnStmt
    8892             :                 {
    8893        4974 :                     $$ = $1;
    8894             :                 }
    8895             :             | BEGIN_P ATOMIC routine_body_stmt_list END_P
    8896             :                 {
    8897             :                     /*
    8898             :                      * A compound statement is stored as a single-item list
    8899             :                      * containing the list of statements as its member.  That
    8900             :                      * way, the parse analysis code can tell apart an empty
    8901             :                      * body from no body at all.
    8902             :                      */
    8903         824 :                     $$ = (Node *) list_make1($3);
    8904             :                 }
    8905             :             | /*EMPTY*/
    8906             :                 {
    8907       19176 :                     $$ = NULL;
    8908             :                 }
    8909             :         ;
    8910             : 
    8911             : routine_body_stmt_list:
    8912             :             routine_body_stmt_list routine_body_stmt ';'
    8913             :                 {
    8914             :                     /* As in stmtmulti, discard empty statements */
    8915         838 :                     if ($2 != NULL)
    8916         820 :                         $$ = lappend($1, $2);
    8917             :                     else
    8918          18 :                         $$ = $1;
    8919             :                 }
    8920             :             | /*EMPTY*/
    8921             :                 {
    8922         824 :                     $$ = NIL;
    8923             :                 }
    8924             :         ;
    8925             : 
    8926             : routine_body_stmt:
    8927             :             stmt
    8928             :             | ReturnStmt
    8929             :         ;
    8930             : 
    8931             : transform_type_list:
    8932         118 :             FOR TYPE_P Typename { $$ = list_make1($3); }
    8933           4 :             | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
    8934             :         ;
    8935             : 
    8936             : opt_definition:
    8937         606 :             WITH definition                         { $$ = $2; }
    8938       10298 :             | /*EMPTY*/                             { $$ = NIL; }
    8939             :         ;
    8940             : 
    8941             : table_func_column:  param_name func_type
    8942             :                 {
    8943         462 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8944             : 
    8945         462 :                     n->name = $1;
    8946         462 :                     n->argType = $2;
    8947         462 :                     n->mode = FUNC_PARAM_TABLE;
    8948         462 :                     n->defexpr = NULL;
    8949         462 :                     n->location = @1;
    8950         462 :                     $$ = n;
    8951             :                 }
    8952             :         ;
    8953             : 
    8954             : table_func_column_list:
    8955             :             table_func_column
    8956             :                 {
    8957         202 :                     $$ = list_make1($1);
    8958             :                 }
    8959             :             | table_func_column_list ',' table_func_column
    8960             :                 {
    8961         260 :                     $$ = lappend($1, $3);
    8962             :                 }
    8963             :         ;
    8964             : 
    8965             : /*****************************************************************************
    8966             :  * ALTER FUNCTION / ALTER PROCEDURE / ALTER ROUTINE
    8967             :  *
    8968             :  * RENAME and OWNER subcommands are already provided by the generic
    8969             :  * ALTER infrastructure, here we just specify alterations that can
    8970             :  * only be applied to functions.
    8971             :  *
    8972             :  *****************************************************************************/
    8973             : AlterFunctionStmt:
    8974             :             ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
    8975             :                 {
    8976         654 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8977             : 
    8978         654 :                     n->objtype = OBJECT_FUNCTION;
    8979         654 :                     n->func = $3;
    8980         654 :                     n->actions = $4;
    8981         654 :                     $$ = (Node *) n;
    8982             :                 }
    8983             :             | ALTER PROCEDURE function_with_argtypes alterfunc_opt_list opt_restrict
    8984             :                 {
    8985          18 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8986             : 
    8987          18 :                     n->objtype = OBJECT_PROCEDURE;
    8988          18 :                     n->func = $3;
    8989          18 :                     n->actions = $4;
    8990          18 :                     $$ = (Node *) n;
    8991             :                 }
    8992             :             | ALTER ROUTINE function_with_argtypes alterfunc_opt_list opt_restrict
    8993             :                 {
    8994           0 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8995             : 
    8996           0 :                     n->objtype = OBJECT_ROUTINE;
    8997           0 :                     n->func = $3;
    8998           0 :                     n->actions = $4;
    8999           0 :                     $$ = (Node *) n;
    9000             :                 }
    9001             :         ;
    9002             : 
    9003             : alterfunc_opt_list:
    9004             :             /* At least one option must be specified */
    9005         672 :             common_func_opt_item                    { $$ = list_make1($1); }
    9006           4 :             | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
    9007             :         ;
    9008             : 
    9009             : /* Ignored, merely for SQL compliance */
    9010             : opt_restrict:
    9011             :             RESTRICT
    9012             :             | /* EMPTY */
    9013             :         ;
    9014             : 
    9015             : 
    9016             : /*****************************************************************************
    9017             :  *
    9018             :  *      QUERY:
    9019             :  *
    9020             :  *      DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    9021             :  *      DROP PROCEDURE procname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    9022             :  *      DROP ROUTINE routname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    9023             :  *      DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
    9024             :  *      DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
    9025             :  *
    9026             :  *****************************************************************************/
    9027             : 
    9028             : RemoveFuncStmt:
    9029             :             DROP FUNCTION function_with_argtypes_list opt_drop_behavior
    9030             :                 {
    9031        3256 :                     DropStmt *n = makeNode(DropStmt);
    9032             : 
    9033        3256 :                     n->removeType = OBJECT_FUNCTION;
    9034        3256 :                     n->objects = $3;
    9035        3256 :                     n->behavior = $4;
    9036        3256 :                     n->missing_ok = false;
    9037        3256 :                     n->concurrent = false;
    9038        3256 :                     $$ = (Node *) n;
    9039             :                 }
    9040             :             | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9041             :                 {
    9042         260 :                     DropStmt *n = makeNode(DropStmt);
    9043             : 
    9044         260 :                     n->removeType = OBJECT_FUNCTION;
    9045         260 :                     n->objects = $5;
    9046         260 :                     n->behavior = $6;
    9047         260 :                     n->missing_ok = true;
    9048         260 :                     n->concurrent = false;
    9049         260 :                     $$ = (Node *) n;
    9050             :                 }
    9051             :             | DROP PROCEDURE function_with_argtypes_list opt_drop_behavior
    9052             :                 {
    9053         138 :                     DropStmt *n = makeNode(DropStmt);
    9054             : 
    9055         138 :                     n->removeType = OBJECT_PROCEDURE;
    9056         138 :                     n->objects = $3;
    9057         138 :                     n->behavior = $4;
    9058         138 :                     n->missing_ok = false;
    9059         138 :                     n->concurrent = false;
    9060         138 :                     $$ = (Node *) n;
    9061             :                 }
    9062             :             | DROP PROCEDURE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9063             :                 {
    9064           6 :                     DropStmt *n = makeNode(DropStmt);
    9065             : 
    9066           6 :                     n->removeType = OBJECT_PROCEDURE;
    9067           6 :                     n->objects = $5;
    9068           6 :                     n->behavior = $6;
    9069           6 :                     n->missing_ok = true;
    9070           6 :                     n->concurrent = false;
    9071           6 :                     $$ = (Node *) n;
    9072             :                 }
    9073             :             | DROP ROUTINE function_with_argtypes_list opt_drop_behavior
    9074             :                 {
    9075          12 :                     DropStmt *n = makeNode(DropStmt);
    9076             : 
    9077          12 :                     n->removeType = OBJECT_ROUTINE;
    9078          12 :                     n->objects = $3;
    9079          12 :                     n->behavior = $4;
    9080          12 :                     n->missing_ok = false;
    9081          12 :                     n->concurrent = false;
    9082          12 :                     $$ = (Node *) n;
    9083             :                 }
    9084             :             | DROP ROUTINE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9085             :                 {
    9086           6 :                     DropStmt *n = makeNode(DropStmt);
    9087             : 
    9088           6 :                     n->removeType = OBJECT_ROUTINE;
    9089           6 :                     n->objects = $5;
    9090           6 :                     n->behavior = $6;
    9091           6 :                     n->missing_ok = true;
    9092           6 :                     n->concurrent = false;
    9093           6 :                     $$ = (Node *) n;
    9094             :                 }
    9095             :         ;
    9096             : 
    9097             : RemoveAggrStmt:
    9098             :             DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
    9099             :                 {
    9100          74 :                     DropStmt *n = makeNode(DropStmt);
    9101             : 
    9102          74 :                     n->removeType = OBJECT_AGGREGATE;
    9103          74 :                     n->objects = $3;
    9104          74 :                     n->behavior = $4;
    9105          74 :                     n->missing_ok = false;
    9106          74 :                     n->concurrent = false;
    9107          74 :                     $$ = (Node *) n;
    9108             :                 }
    9109             :             | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
    9110             :                 {
    9111          30 :                     DropStmt *n = makeNode(DropStmt);
    9112             : 
    9113          30 :                     n->removeType = OBJECT_AGGREGATE;
    9114          30 :                     n->objects = $5;
    9115          30 :                     n->behavior = $6;
    9116          30 :                     n->missing_ok = true;
    9117          30 :                     n->concurrent = false;
    9118          30 :                     $$ = (Node *) n;
    9119             :                 }
    9120             :         ;
    9121             : 
    9122             : RemoveOperStmt:
    9123             :             DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
    9124             :                 {
    9125         194 :                     DropStmt *n = makeNode(DropStmt);
    9126             : 
    9127         194 :                     n->removeType = OBJECT_OPERATOR;
    9128         194 :                     n->objects = $3;
    9129         194 :                     n->behavior = $4;
    9130         194 :                     n->missing_ok = false;
    9131         194 :                     n->concurrent = false;
    9132         194 :                     $$ = (Node *) n;
    9133             :                 }
    9134             :             | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
    9135             :                 {
    9136          30 :                     DropStmt *n = makeNode(DropStmt);
    9137             : 
    9138          30 :                     n->removeType = OBJECT_OPERATOR;
    9139          30 :                     n->objects = $5;
    9140          30 :                     n->behavior = $6;
    9141          30 :                     n->missing_ok = true;
    9142          30 :                     n->concurrent = false;
    9143          30 :                     $$ = (Node *) n;
    9144             :                 }
    9145             :         ;
    9146             : 
    9147             : oper_argtypes:
    9148             :             '(' Typename ')'
    9149             :                 {
    9150          12 :                    ereport(ERROR,
    9151             :                            (errcode(ERRCODE_SYNTAX_ERROR),
    9152             :                             errmsg("missing argument"),
    9153             :                             errhint("Use NONE to denote the missing argument of a unary operator."),
    9154             :                             parser_errposition(@3)));
    9155             :                 }
    9156             :             | '(' Typename ',' Typename ')'
    9157        2128 :                     { $$ = list_make2($2, $4); }
    9158             :             | '(' NONE ',' Typename ')'                 /* left unary */
    9159          40 :                     { $$ = list_make2(NULL, $4); }
    9160             :             | '(' Typename ',' NONE ')'                 /* right unary */
    9161          12 :                     { $$ = list_make2($2, NULL); }
    9162             :         ;
    9163             : 
    9164             : any_operator:
    9165             :             all_Op
    9166       20986 :                     { $$ = list_make1(makeString($1)); }
    9167             :             | ColId '.' any_operator
    9168       15906 :                     { $$ = lcons(makeString($1), $3); }
    9169             :         ;
    9170             : 
    9171             : operator_with_argtypes_list:
    9172         224 :             operator_with_argtypes                  { $$ = list_make1($1); }
    9173             :             | operator_with_argtypes_list ',' operator_with_argtypes
    9174           0 :                                                     { $$ = lappend($1, $3); }
    9175             :         ;
    9176             : 
    9177             : operator_with_argtypes:
    9178             :             any_operator oper_argtypes
    9179             :                 {
    9180        2180 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    9181             : 
    9182        2180 :                     n->objname = $1;
    9183        2180 :                     n->objargs = $2;
    9184        2180 :                     $$ = n;
    9185             :                 }
    9186             :         ;
    9187             : 
    9188             : /*****************************************************************************
    9189             :  *
    9190             :  *      DO <anonymous code block> [ LANGUAGE language ]
    9191             :  *
    9192             :  * We use a DefElem list for future extensibility, and to allow flexibility
    9193             :  * in the clause order.
    9194             :  *
    9195             :  *****************************************************************************/
    9196             : 
    9197             : DoStmt: DO dostmt_opt_list
    9198             :                 {
    9199        1142 :                     DoStmt *n = makeNode(DoStmt);
    9200             : 
    9201        1142 :                     n->args = $2;
    9202        1142 :                     $$ = (Node *) n;
    9203             :                 }
    9204             :         ;
    9205             : 
    9206             : dostmt_opt_list:
    9207        1142 :             dostmt_opt_item                     { $$ = list_make1($1); }
    9208         198 :             | dostmt_opt_list dostmt_opt_item   { $$ = lappend($1, $2); }
    9209             :         ;
    9210             : 
    9211             : dostmt_opt_item:
    9212             :             Sconst
    9213             :                 {
    9214        1142 :                     $$ = makeDefElem("as", (Node *) makeString($1), @1);
    9215             :                 }
    9216             :             | LANGUAGE NonReservedWord_or_Sconst
    9217             :                 {
    9218         198 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    9219             :                 }
    9220             :         ;
    9221             : 
    9222             : /*****************************************************************************
    9223             :  *
    9224             :  *      CREATE CAST / DROP CAST
    9225             :  *
    9226             :  *****************************************************************************/
    9227             : 
    9228             : CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
    9229             :                     WITH FUNCTION function_with_argtypes cast_context
    9230             :                 {
    9231         110 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9232             : 
    9233         110 :                     n->sourcetype = $4;
    9234         110 :                     n->targettype = $6;
    9235         110 :                     n->func = $10;
    9236         110 :                     n->context = (CoercionContext) $11;
    9237         110 :                     n->inout = false;
    9238         110 :                     $$ = (Node *) n;
    9239             :                 }
    9240             :             | CREATE CAST '(' Typename AS Typename ')'
    9241             :                     WITHOUT FUNCTION cast_context
    9242             :                 {
    9243         172 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9244             : 
    9245         172 :                     n->sourcetype = $4;
    9246         172 :                     n->targettype = $6;
    9247         172 :                     n->func = NULL;
    9248         172 :                     n->context = (CoercionContext) $10;
    9249         172 :                     n->inout = false;
    9250         172 :                     $$ = (Node *) n;
    9251             :                 }
    9252             :             | CREATE CAST '(' Typename AS Typename ')'
    9253             :                     WITH INOUT cast_context
    9254             :                 {
    9255           8 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9256             : 
    9257           8 :                     n->sourcetype = $4;
    9258           8 :                     n->targettype = $6;
    9259           8 :                     n->func = NULL;
    9260           8 :                     n->context = (CoercionContext) $10;
    9261           8 :                     n->inout = true;
    9262           8 :                     $$ = (Node *) n;
    9263             :                 }
    9264             :         ;
    9265             : 
    9266          40 : cast_context:  AS IMPLICIT_P                    { $$ = COERCION_IMPLICIT; }
    9267          58 :         | AS ASSIGNMENT                         { $$ = COERCION_ASSIGNMENT; }
    9268         192 :         | /*EMPTY*/                             { $$ = COERCION_EXPLICIT; }
    9269             :         ;
    9270             : 
    9271             : 
    9272             : DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
    9273             :                 {
    9274          60 :                     DropStmt *n = makeNode(DropStmt);
    9275             : 
    9276          60 :                     n->removeType = OBJECT_CAST;
    9277          60 :                     n->objects = list_make1(list_make2($5, $7));
    9278          60 :                     n->behavior = $9;
    9279          60 :                     n->missing_ok = $3;
    9280          60 :                     n->concurrent = false;
    9281          60 :                     $$ = (Node *) n;
    9282             :                 }
    9283             :         ;
    9284             : 
    9285          36 : opt_if_exists: IF_P EXISTS                      { $$ = true; }
    9286          38 :         | /*EMPTY*/                             { $$ = false; }
    9287             :         ;
    9288             : 
    9289             : 
    9290             : /*****************************************************************************
    9291             :  *
    9292             :  *      CREATE TRANSFORM / DROP TRANSFORM
    9293             :  *
    9294             :  *****************************************************************************/
    9295             : 
    9296             : CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name '(' transform_element_list ')'
    9297             :                 {
    9298          52 :                     CreateTransformStmt *n = makeNode(CreateTransformStmt);
    9299             : 
    9300          52 :                     n->replace = $2;
    9301          52 :                     n->type_name = $5;
    9302          52 :                     n->lang = $7;
    9303          52 :                     n->fromsql = linitial($9);
    9304          52 :                     n->tosql = lsecond($9);
    9305          52 :                     $$ = (Node *) n;
    9306             :                 }
    9307             :         ;
    9308             : 
    9309             : transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes ',' TO SQL_P WITH FUNCTION function_with_argtypes
    9310             :                 {
    9311          46 :                     $$ = list_make2($5, $11);
    9312             :                 }
    9313             :                 | TO SQL_P WITH FUNCTION function_with_argtypes ',' FROM SQL_P WITH FUNCTION function_with_argtypes
    9314             :                 {
    9315           0 :                     $$ = list_make2($11, $5);
    9316             :                 }
    9317             :                 | FROM SQL_P WITH FUNCTION function_with_argtypes
    9318             :                 {
    9319           4 :                     $$ = list_make2($5, NULL);
    9320             :                 }
    9321             :                 | TO SQL_P WITH FUNCTION function_with_argtypes
    9322             :                 {
    9323           2 :                     $$ = list_make2(NULL, $5);
    9324             :                 }
    9325             :         ;
    9326             : 
    9327             : 
    9328             : DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
    9329             :                 {
    9330          14 :                     DropStmt *n = makeNode(DropStmt);
    9331             : 
    9332          14 :                     n->removeType = OBJECT_TRANSFORM;
    9333          14 :                     n->objects = list_make1(list_make2($5, makeString($7)));
    9334          14 :                     n->behavior = $8;
    9335          14 :                     n->missing_ok = $3;
    9336          14 :                     $$ = (Node *) n;
    9337             :                 }
    9338             :         ;
    9339             : 
    9340             : 
    9341             : /*****************************************************************************
    9342             :  *
    9343             :  *      QUERY:
    9344             :  *
    9345             :  *      REINDEX [ (options) ] {INDEX | TABLE | SCHEMA} [CONCURRENTLY] <name>
    9346             :  *      REINDEX [ (options) ] {DATABASE | SYSTEM} [CONCURRENTLY] [<name>]
    9347             :  *****************************************************************************/
    9348             : 
    9349             : ReindexStmt:
    9350             :             REINDEX opt_reindex_option_list reindex_target_relation opt_concurrently qualified_name
    9351             :                 {
    9352         926 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9353             : 
    9354         926 :                     n->kind = $3;
    9355         926 :                     n->relation = $5;
    9356         926 :                     n->name = NULL;
    9357         926 :                     n->params = $2;
    9358         926 :                     if ($4)
    9359         522 :                         n->params = lappend(n->params,
    9360         522 :                                             makeDefElem("concurrently", NULL, @4));
    9361         926 :                     $$ = (Node *) n;
    9362             :                 }
    9363             :             | REINDEX opt_reindex_option_list SCHEMA opt_concurrently name
    9364             :                 {
    9365         114 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9366             : 
    9367         114 :                     n->kind = REINDEX_OBJECT_SCHEMA;
    9368         114 :                     n->relation = NULL;
    9369         114 :                     n->name = $5;
    9370         114 :                     n->params = $2;
    9371         114 :                     if ($4)
    9372          40 :                         n->params = lappend(n->params,
    9373          40 :                                             makeDefElem("concurrently", NULL, @4));
    9374         114 :                     $$ = (Node *) n;
    9375             :                 }
    9376             :             | REINDEX opt_reindex_option_list reindex_target_all opt_concurrently opt_single_name
    9377             :                 {
    9378          64 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9379             : 
    9380          64 :                     n->kind = $3;
    9381          64 :                     n->relation = NULL;
    9382          64 :                     n->name = $5;
    9383          64 :                     n->params = $2;
    9384          64 :                     if ($4)
    9385          10 :                         n->params = lappend(n->params,
    9386          10 :                                             makeDefElem("concurrently", NULL, @4));
    9387          64 :                     $$ = (Node *) n;
    9388             :                 }
    9389             :         ;
    9390             : reindex_target_relation:
    9391         398 :             INDEX                   { $$ = REINDEX_OBJECT_INDEX; }
    9392         528 :             | TABLE                 { $$ = REINDEX_OBJECT_TABLE; }
    9393             :         ;
    9394             : reindex_target_all:
    9395          34 :             SYSTEM_P                { $$ = REINDEX_OBJECT_SYSTEM; }
    9396          30 :             | DATABASE              { $$ = REINDEX_OBJECT_DATABASE; }
    9397             :         ;
    9398             : opt_reindex_option_list:
    9399         156 :             '(' utility_option_list ')'             { $$ = $2; }
    9400         948 :             | /* EMPTY */                           { $$ = NULL; }
    9401             :         ;
    9402             : 
    9403             : /*****************************************************************************
    9404             :  *
    9405             :  * ALTER TABLESPACE
    9406             :  *
    9407             :  *****************************************************************************/
    9408             : 
    9409             : AlterTblSpcStmt:
    9410             :             ALTER TABLESPACE name SET reloptions
    9411             :                 {
    9412             :                     AlterTableSpaceOptionsStmt *n =
    9413          12 :                         makeNode(AlterTableSpaceOptionsStmt);
    9414             : 
    9415          12 :                     n->tablespacename = $3;
    9416          12 :                     n->options = $5;
    9417          12 :                     n->isReset = false;
    9418          12 :                     $$ = (Node *) n;
    9419             :                 }
    9420             :             | ALTER TABLESPACE name RESET reloptions
    9421             :                 {
    9422             :                     AlterTableSpaceOptionsStmt *n =
    9423          12 :                         makeNode(AlterTableSpaceOptionsStmt);
    9424             : 
    9425          12 :                     n->tablespacename = $3;
    9426          12 :                     n->options = $5;
    9427          12 :                     n->isReset = true;
    9428          12 :                     $$ = (Node *) n;
    9429             :                 }
    9430             :         ;
    9431             : 
    9432             : /*****************************************************************************
    9433             :  *
    9434             :  * ALTER THING name RENAME TO newname
    9435             :  *
    9436             :  *****************************************************************************/
    9437             : 
    9438             : RenameStmt: ALTER AGGREGATE aggregate_with_argtypes RENAME TO name
    9439             :                 {
    9440          42 :                     RenameStmt *n = makeNode(RenameStmt);
    9441             : 
    9442          42 :                     n->renameType = OBJECT_AGGREGATE;
    9443          42 :                     n->object = (Node *) $3;
    9444          42 :                     n->newname = $6;
    9445          42 :                     n->missing_ok = false;
    9446          42 :                     $$ = (Node *) n;
    9447             :                 }
    9448             :             | ALTER COLLATION any_name RENAME TO name
    9449             :                 {
    9450          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9451             : 
    9452          18 :                     n->renameType = OBJECT_COLLATION;
    9453          18 :                     n->object = (Node *) $3;
    9454          18 :                     n->newname = $6;
    9455          18 :                     n->missing_ok = false;
    9456          18 :                     $$ = (Node *) n;
    9457             :                 }
    9458             :             | ALTER CONVERSION_P any_name RENAME TO name
    9459             :                 {
    9460          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9461             : 
    9462          24 :                     n->renameType = OBJECT_CONVERSION;
    9463          24 :                     n->object = (Node *) $3;
    9464          24 :                     n->newname = $6;
    9465          24 :                     n->missing_ok = false;
    9466          24 :                     $$ = (Node *) n;
    9467             :                 }
    9468             :             | ALTER DATABASE name RENAME TO name
    9469             :                 {
    9470           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9471             : 
    9472           6 :                     n->renameType = OBJECT_DATABASE;
    9473           6 :                     n->subname = $3;
    9474           6 :                     n->newname = $6;
    9475           6 :                     n->missing_ok = false;
    9476           6 :                     $$ = (Node *) n;
    9477             :                 }
    9478             :             | ALTER DOMAIN_P any_name RENAME TO name
    9479             :                 {
    9480           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9481             : 
    9482           6 :                     n->renameType = OBJECT_DOMAIN;
    9483           6 :                     n->object = (Node *) $3;
    9484           6 :                     n->newname = $6;
    9485           6 :                     n->missing_ok = false;
    9486           6 :                     $$ = (Node *) n;
    9487             :                 }
    9488             :             | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
    9489             :                 {
    9490           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9491             : 
    9492           6 :                     n->renameType = OBJECT_DOMCONSTRAINT;
    9493           6 :                     n->object = (Node *) $3;
    9494           6 :                     n->subname = $6;
    9495           6 :                     n->newname = $8;
    9496           6 :                     $$ = (Node *) n;
    9497             :                 }
    9498             :             | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
    9499             :                 {
    9500          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9501             : 
    9502          24 :                     n->renameType = OBJECT_FDW;
    9503          24 :                     n->object = (Node *) makeString($5);
    9504          24 :                     n->newname = $8;
    9505          24 :                     n->missing_ok = false;
    9506          24 :                     $$ = (Node *) n;
    9507             :                 }
    9508             :             | ALTER FUNCTION function_with_argtypes RENAME TO name
    9509             :                 {
    9510          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9511             : 
    9512          24 :                     n->renameType = OBJECT_FUNCTION;
    9513          24 :                     n->object = (Node *) $3;
    9514          24 :                     n->newname = $6;
    9515          24 :                     n->missing_ok = false;
    9516          24 :                     $$ = (Node *) n;
    9517             :                 }
    9518             :             | ALTER GROUP_P RoleId RENAME TO RoleId
    9519             :                 {
    9520           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9521             : 
    9522           0 :                     n->renameType = OBJECT_ROLE;
    9523           0 :                     n->subname = $3;
    9524           0 :                     n->newname = $6;
    9525           0 :                     n->missing_ok = false;
    9526           0 :                     $$ = (Node *) n;
    9527             :                 }
    9528             :             | ALTER opt_procedural LANGUAGE name RENAME TO name
    9529             :                 {
    9530          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9531             : 
    9532          18 :                     n->renameType = OBJECT_LANGUAGE;
    9533          18 :                     n->object = (Node *) makeString($4);
    9534          18 :                     n->newname = $7;
    9535          18 :                     n->missing_ok = false;
    9536          18 :                     $$ = (Node *) n;
    9537             :                 }
    9538             :             | ALTER OPERATOR CLASS any_name USING name RENAME TO name
    9539             :                 {
    9540          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9541             : 
    9542          24 :                     n->renameType = OBJECT_OPCLASS;
    9543          24 :                     n->object = (Node *) lcons(makeString($6), $4);
    9544          24 :                     n->newname = $9;
    9545          24 :                     n->missing_ok = false;
    9546          24 :                     $$ = (Node *) n;
    9547             :                 }
    9548             :             | ALTER OPERATOR FAMILY any_name USING name RENAME TO name
    9549             :                 {
    9550          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9551             : 
    9552          24 :                     n->renameType = OBJECT_OPFAMILY;
    9553          24 :                     n->object = (Node *) lcons(makeString($6), $4);
    9554          24 :                     n->newname = $9;
    9555          24 :                     n->missing_ok = false;
    9556          24 :                     $$ = (Node *) n;
    9557             :                 }
    9558             :             | ALTER POLICY name ON qualified_name RENAME TO name
    9559             :                 {
    9560          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9561             : 
    9562          18 :                     n->renameType = OBJECT_POLICY;
    9563          18 :                     n->relation = $5;
    9564          18 :                     n->subname = $3;
    9565          18 :                     n->newname = $8;
    9566          18 :                     n->missing_ok = false;
    9567          18 :                     $$ = (Node *) n;
    9568             :                 }
    9569             :             | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
    9570             :                 {
    9571           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9572             : 
    9573           0 :                     n->renameType = OBJECT_POLICY;
    9574           0 :                     n->relation = $7;
    9575           0 :                     n->subname = $5;
    9576           0 :                     n->newname = $10;
    9577           0 :                     n->missing_ok = true;
    9578           0 :                     $$ = (Node *) n;
    9579             :                 }
    9580             :             | ALTER PROCEDURE function_with_argtypes RENAME TO name
    9581             :                 {
    9582           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9583             : 
    9584           0 :                     n->renameType = OBJECT_PROCEDURE;
    9585           0 :                     n->object = (Node *) $3;
    9586           0 :                     n->newname = $6;
    9587           0 :                     n->missing_ok = false;
    9588           0 :                     $$ = (Node *) n;
    9589             :                 }
    9590             :             | ALTER PUBLICATION name RENAME TO name
    9591             :                 {
    9592          42 :                     RenameStmt *n = makeNode(RenameStmt);
    9593             : 
    9594          42 :                     n->renameType = OBJECT_PUBLICATION;
    9595          42 :                     n->object = (Node *) makeString($3);
    9596          42 :                     n->newname = $6;
    9597          42 :                     n->missing_ok = false;
    9598          42 :                     $$ = (Node *) n;
    9599             :                 }
    9600             :             | ALTER ROUTINE function_with_argtypes RENAME TO name
    9601             :                 {
    9602          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9603             : 
    9604          24 :                     n->renameType = OBJECT_ROUTINE;
    9605          24 :                     n->object = (Node *) $3;
    9606          24 :                     n->newname = $6;
    9607          24 :                     n->missing_ok = false;
    9608          24 :                     $$ = (Node *) n;
    9609             :                 }
    9610             :             | ALTER SCHEMA name RENAME TO name
    9611             :                 {
    9612          20 :                     RenameStmt *n = makeNode(RenameStmt);
    9613             : 
    9614          20 :                     n->renameType = OBJECT_SCHEMA;
    9615          20 :                     n->subname = $3;
    9616          20 :                     n->newname = $6;
    9617          20 :                     n->missing_ok = false;
    9618          20 :                     $$ = (Node *) n;
    9619             :                 }
    9620             :             | ALTER SERVER name RENAME TO name
    9621             :                 {
    9622          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9623             : 
    9624          24 :                     n->renameType = OBJECT_FOREIGN_SERVER;
    9625          24 :                     n->object = (Node *) makeString($3);
    9626          24 :                     n->newname = $6;
    9627          24 :                     n->missing_ok = false;
    9628          24 :                     $$ = (Node *) n;
    9629             :                 }
    9630             :             | ALTER SUBSCRIPTION name RENAME TO name
    9631             :                 {
    9632          38 :                     RenameStmt *n = makeNode(RenameStmt);
    9633             : 
    9634          38 :                     n->renameType = OBJECT_SUBSCRIPTION;
    9635          38 :                     n->object = (Node *) makeString($3);
    9636          38 :                     n->newname = $6;
    9637          38 :                     n->missing_ok = false;
    9638          38 :                     $$ = (Node *) n;
    9639             :                 }
    9640             :             | ALTER TABLE relation_expr RENAME TO name
    9641             :                 {
    9642         286 :                     RenameStmt *n = makeNode(RenameStmt);
    9643             : 
    9644         286 :                     n->renameType = OBJECT_TABLE;
    9645         286 :                     n->relation = $3;
    9646         286 :                     n->subname = NULL;
    9647         286 :                     n->newname = $6;
    9648         286 :                     n->missing_ok = false;
    9649         286 :                     $$ = (Node *) n;
    9650             :                 }
    9651             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
    9652             :                 {
    9653           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9654             : 
    9655           0 :                     n->renameType = OBJECT_TABLE;
    9656           0 :                     n->relation = $5;
    9657           0 :                     n->subname = NULL;
    9658           0 :                     n->newname = $8;
    9659           0 :                     n->missing_ok = true;
    9660           0 :                     $$ = (Node *) n;
    9661             :                 }
    9662             :             | ALTER SEQUENCE qualified_name RENAME TO name
    9663             :                 {
    9664           2 :                     RenameStmt *n = makeNode(RenameStmt);
    9665             : 
    9666           2 :                     n->renameType = OBJECT_SEQUENCE;
    9667           2 :                     n->relation = $3;
    9668           2 :                     n->subname = NULL;
    9669           2 :                     n->newname = $6;
    9670           2 :                     n->missing_ok = false;
    9671           2 :                     $$ = (Node *) n;
    9672             :                 }
    9673             :             | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
    9674             :                 {
    9675           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9676             : 
    9677           0 :                     n->renameType = OBJECT_SEQUENCE;
    9678           0 :                     n->relation = $5;
    9679           0 :                     n->subname = NULL;
    9680           0 :                     n->newname = $8;
    9681           0 :                     n->missing_ok = true;
    9682           0 :                     $$ = (Node *) n;
    9683             :                 }
    9684             :             | ALTER VIEW qualified_name RENAME TO name
    9685             :                 {
    9686           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9687             : 
    9688           6 :                     n->renameType = OBJECT_VIEW;
    9689           6 :                     n->relation = $3;
    9690           6 :                     n->subname = NULL;
    9691           6 :                     n->newname = $6;
    9692           6 :                     n->missing_ok = false;
    9693           6 :                     $$ = (Node *) n;
    9694             :                 }
    9695             :             | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
    9696             :                 {
    9697           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9698             : 
    9699           0 :                     n->renameType = OBJECT_VIEW;
    9700           0 :                     n->relation = $5;
    9701           0 :                     n->subname = NULL;
    9702           0 :                     n->newname = $8;
    9703           0 :                     n->missing_ok = true;
    9704           0 :                     $$ = (Node *) n;
    9705             :                 }
    9706             :             | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
    9707             :                 {
    9708           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9709             : 
    9710           0 :                     n->renameType = OBJECT_MATVIEW;
    9711           0 :                     n->relation = $4;
    9712           0 :                     n->subname = NULL;
    9713           0 :                     n->newname = $7;
    9714           0 :                     n->missing_ok = false;
    9715           0 :                     $$ = (Node *) n;
    9716             :                 }
    9717             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
    9718             :                 {
    9719           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9720             : 
    9721           0 :                     n->renameType = OBJECT_MATVIEW;
    9722           0 :                     n->relation = $6;
    9723           0 :                     n->subname = NULL;
    9724           0 :                     n->newname = $9;
    9725           0 :                     n->missing_ok = true;
    9726           0 :                     $$ = (Node *) n;
    9727             :                 }
    9728             :             | ALTER INDEX qualified_name RENAME TO name
    9729             :                 {
    9730         192 :                     RenameStmt *n = makeNode(RenameStmt);
    9731             : 
    9732         192 :                     n->renameType = OBJECT_INDEX;
    9733         192 :                     n->relation = $3;
    9734         192 :                     n->subname = NULL;
    9735         192 :                     n->newname = $6;
    9736         192 :                     n->missing_ok = false;
    9737         192 :                     $$ = (Node *) n;
    9738             :                 }
    9739             :             | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
    9740             :                 {
    9741          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9742             : 
    9743          12 :                     n->renameType = OBJECT_INDEX;
    9744          12 :                     n->relation = $5;
    9745          12 :                     n->subname = NULL;
    9746          12 :                     n->newname = $8;
    9747          12 :                     n->missing_ok = true;
    9748          12 :                     $$ = (Node *) n;
    9749             :                 }
    9750             :             | ALTER FOREIGN TABLE relation_expr RENAME TO name
    9751             :                 {
    9752           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9753             : 
    9754           6 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9755           6 :                     n->relation = $4;
    9756           6 :                     n->subname = NULL;
    9757           6 :                     n->newname = $7;
    9758           6 :                     n->missing_ok = false;
    9759           6 :                     $$ = (Node *) n;
    9760             :                 }
    9761             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
    9762             :                 {
    9763           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9764             : 
    9765           6 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9766           6 :                     n->relation = $6;
    9767           6 :                     n->subname = NULL;
    9768           6 :                     n->newname = $9;
    9769           6 :                     n->missing_ok = true;
    9770           6 :                     $$ = (Node *) n;
    9771             :                 }
    9772             :             | ALTER TABLE relation_expr RENAME opt_column name TO name
    9773             :                 {
    9774         238 :                     RenameStmt *n = makeNode(RenameStmt);
    9775             : 
    9776         238 :                     n->renameType = OBJECT_COLUMN;
    9777         238 :                     n->relationType = OBJECT_TABLE;
    9778         238 :                     n->relation = $3;
    9779         238 :                     n->subname = $6;
    9780         238 :                     n->newname = $8;
    9781         238 :                     n->missing_ok = false;
    9782         238 :                     $$ = (Node *) n;
    9783             :                 }
    9784             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9785             :                 {
    9786          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9787             : 
    9788          24 :                     n->renameType = OBJECT_COLUMN;
    9789          24 :                     n->relationType = OBJECT_TABLE;
    9790          24 :                     n->relation = $5;
    9791          24 :                     n->subname = $8;
    9792          24 :                     n->newname = $10;
    9793          24 :                     n->missing_ok = true;
    9794          24 :                     $$ = (Node *) n;
    9795             :                 }
    9796             :             | ALTER VIEW qualified_name RENAME opt_column name TO name
    9797             :                 {
    9798          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9799             : 
    9800          18 :                     n->renameType = OBJECT_COLUMN;
    9801          18 :                     n->relationType = OBJECT_VIEW;
    9802          18 :                     n->relation = $3;
    9803          18 :                     n->subname = $6;
    9804          18 :                     n->newname = $8;
    9805          18 :                     n->missing_ok = false;
    9806          18 :                     $$ = (Node *) n;
    9807             :                 }
    9808             :             | ALTER VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    9809             :                 {
    9810           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9811             : 
    9812           0 :                     n->renameType = OBJECT_COLUMN;
    9813           0 :                     n->relationType = OBJECT_VIEW;
    9814           0 :                     n->relation = $5;
    9815           0 :                     n->subname = $8;
    9816           0 :                     n->newname = $10;
    9817           0 :                     n->missing_ok = true;
    9818           0 :                     $$ = (Node *) n;
    9819             :                 }
    9820             :             | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
    9821             :                 {
    9822           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9823             : 
    9824           0 :                     n->renameType = OBJECT_COLUMN;
    9825           0 :                     n->relationType = OBJECT_MATVIEW;
    9826           0 :                     n->relation = $4;
    9827           0 :                     n->subname = $7;
    9828           0 :                     n->newname = $9;
    9829           0 :                     n->missing_ok = false;
    9830           0 :                     $$ = (Node *) n;
    9831             :                 }
    9832             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    9833             :                 {
    9834           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9835             : 
    9836           0 :                     n->renameType = OBJECT_COLUMN;
    9837           0 :                     n->relationType = OBJECT_MATVIEW;
    9838           0 :                     n->relation = $6;
    9839           0 :                     n->subname = $9;
    9840           0 :                     n->newname = $11;
    9841           0 :                     n->missing_ok = true;
    9842           0 :                     $$ = (Node *) n;
    9843             :                 }
    9844             :             | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
    9845             :                 {
    9846          72 :                     RenameStmt *n = makeNode(RenameStmt);
    9847             : 
    9848          72 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9849          72 :                     n->relation = $3;
    9850          72 :                     n->subname = $6;
    9851          72 :                     n->newname = $8;
    9852          72 :                     n->missing_ok = false;
    9853          72 :                     $$ = (Node *) n;
    9854             :                 }
    9855             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
    9856             :                 {
    9857           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9858             : 
    9859           6 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9860           6 :                     n->relation = $5;
    9861           6 :                     n->subname = $8;
    9862           6 :                     n->newname = $10;
    9863           6 :                     n->missing_ok = true;
    9864           6 :                     $$ = (Node *) n;
    9865             :                 }
    9866             :             | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
    9867             :                 {
    9868           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9869             : 
    9870           6 :                     n->renameType = OBJECT_COLUMN;
    9871           6 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    9872           6 :                     n->relation = $4;
    9873           6 :                     n->subname = $7;
    9874           6 :                     n->newname = $9;
    9875           6 :                     n->missing_ok = false;
    9876           6 :                     $$ = (Node *) n;
    9877             :                 }
    9878             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9879             :                 {
    9880           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9881             : 
    9882           6 :                     n->renameType = OBJECT_COLUMN;
    9883           6 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    9884           6 :                     n->relation = $6;
    9885           6 :                     n->subname = $9;
    9886           6 :                     n->newname = $11;
    9887           6 :                     n->missing_ok = true;
    9888           6 :                     $$ = (Node *) n;
    9889             :                 }
    9890             :             | ALTER RULE name ON qualified_name RENAME TO name
    9891             :                 {
    9892          34 :                     RenameStmt *n = makeNode(RenameStmt);
    9893             : 
    9894          34 :                     n->renameType = OBJECT_RULE;
    9895          34 :                     n->relation = $5;
    9896          34 :                     n->subname = $3;
    9897          34 :                     n->newname = $8;
    9898          34 :                     n->missing_ok = false;
    9899          34 :                     $$ = (Node *) n;
    9900             :                 }
    9901             :             | ALTER TRIGGER name ON qualified_name RENAME TO name
    9902             :                 {
    9903          40 :                     RenameStmt *n = makeNode(RenameStmt);
    9904             : 
    9905          40 :                     n->renameType = OBJECT_TRIGGER;
    9906          40 :                     n->relation = $5;
    9907          40 :                     n->subname = $3;
    9908          40 :                     n->newname = $8;
    9909          40 :                     n->missing_ok = false;
    9910          40 :                     $$ = (Node *) n;
    9911             :                 }
    9912             :             | ALTER EVENT TRIGGER name RENAME TO name
    9913             :                 {
    9914          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9915             : 
    9916          12 :                     n->renameType = OBJECT_EVENT_TRIGGER;
    9917          12 :                     n->object = (Node *) makeString($4);
    9918          12 :                     n->newname = $7;
    9919          12 :                     $$ = (Node *) n;
    9920             :                 }
    9921             :             | ALTER ROLE RoleId RENAME TO RoleId
    9922             :                 {
    9923          30 :                     RenameStmt *n = makeNode(RenameStmt);
    9924             : 
    9925          30 :                     n->renameType = OBJECT_ROLE;
    9926          30 :                     n->subname = $3;
    9927          30 :                     n->newname = $6;
    9928          30 :                     n->missing_ok = false;
    9929          30 :                     $$ = (Node *) n;
    9930             :                 }
    9931             :             | ALTER USER RoleId RENAME TO RoleId
    9932             :                 {
    9933           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9934             : 
    9935           0 :                     n->renameType = OBJECT_ROLE;
    9936           0 :                     n->subname = $3;
    9937           0 :                     n->newname = $6;
    9938           0 :                     n->missing_ok = false;
    9939           0 :                     $$ = (Node *) n;
    9940             :                 }
    9941             :             | ALTER TABLESPACE name RENAME TO name
    9942             :                 {
    9943           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9944             : 
    9945           6 :                     n->renameType = OBJECT_TABLESPACE;
    9946           6 :                     n->subname = $3;
    9947           6 :                     n->newname = $6;
    9948           6 :                     n->missing_ok = false;
    9949           6 :                     $$ = (Node *) n;
    9950             :                 }
    9951             :             | ALTER STATISTICS any_name RENAME TO name
    9952             :                 {
    9953          30 :                     RenameStmt *n = makeNode(RenameStmt);
    9954             : 
    9955          30 :                     n->renameType = OBJECT_STATISTIC_EXT;
    9956          30 :                     n->object = (Node *) $3;
    9957          30 :                     n->newname = $6;
    9958          30 :                     n->missing_ok = false;
    9959          30 :                     $$ = (Node *) n;
    9960             :                 }
    9961             :             | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
    9962             :                 {
    9963          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9964             : 
    9965          12 :                     n->renameType = OBJECT_TSPARSER;
    9966          12 :                     n->object = (Node *) $5;
    9967          12 :                     n->newname = $8;
    9968          12 :                     n->missing_ok = false;
    9969          12 :                     $$ = (Node *) n;
    9970             :                 }
    9971             :             | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
    9972             :                 {
    9973          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9974             : 
    9975          24 :                     n->renameType = OBJECT_TSDICTIONARY;
    9976          24 :                     n->object = (Node *) $5;
    9977          24 :                     n->newname = $8;
    9978          24 :                     n->missing_ok = false;
    9979          24 :                     $$ = (Node *) n;
    9980             :                 }
    9981             :             | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
    9982             :                 {
    9983          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9984             : 
    9985          12 :                     n->renameType = OBJECT_TSTEMPLATE;
    9986          12 :                     n->object = (Node *) $5;
    9987          12 :                     n->newname = $8;
    9988          12 :                     n->missing_ok = false;
    9989          12 :                     $$ = (Node *) n;
    9990             :                 }
    9991             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
    9992             :                 {
    9993          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9994             : 
    9995          24 :                     n->renameType = OBJECT_TSCONFIGURATION;
    9996          24 :                     n->object = (Node *) $5;
    9997          24 :                     n->newname = $8;
    9998          24 :                     n->missing_ok = false;
    9999          24 :                     $$ = (Node *) n;
   10000             :                 }
   10001             :             | ALTER TYPE_P any_name RENAME TO name
   10002             :                 {
   10003          26 :                     RenameStmt *n = makeNode(RenameStmt);
   10004             : 
   10005          26 :                     n->renameType = OBJECT_TYPE;
   10006          26 :                     n->object = (Node *) $3;
   10007          26 :                     n->newname = $6;
   10008          26 :                     n->missing_ok = false;
   10009          26 :                     $$ = (Node *) n;
   10010             :                 }
   10011             :             | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
   10012             :                 {
   10013          24 :                     RenameStmt *n = makeNode(RenameStmt);
   10014             : 
   10015          24 :                     n->renameType = OBJECT_ATTRIBUTE;
   10016          24 :                     n->relationType = OBJECT_TYPE;
   10017          24 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
   10018          24 :                     n->subname = $6;
   10019          24 :                     n->newname = $8;
   10020          24 :                     n->behavior = $9;
   10021          24 :                     n->missing_ok = false;
   10022          24 :                     $$ = (Node *) n;
   10023             :                 }
   10024             :         ;
   10025             : 
   10026             : opt_column: COLUMN
   10027             :             | /*EMPTY*/
   10028             :         ;
   10029             : 
   10030         184 : opt_set_data: SET DATA_P                            { $$ = 1; }
   10031         914 :             | /*EMPTY*/                             { $$ = 0; }
   10032             :         ;
   10033             : 
   10034             : /*****************************************************************************
   10035             :  *
   10036             :  * ALTER THING name DEPENDS ON EXTENSION name
   10037             :  *
   10038             :  *****************************************************************************/
   10039             : 
   10040             : AlterObjectDependsStmt:
   10041             :             ALTER FUNCTION function_with_argtypes opt_no DEPENDS ON EXTENSION name
   10042             :                 {
   10043          12 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10044             : 
   10045          12 :                     n->objectType = OBJECT_FUNCTION;
   10046          12 :                     n->object = (Node *) $3;
   10047          12 :                     n->extname = makeString($8);
   10048          12 :                     n->remove = $4;
   10049          12 :                     $$ = (Node *) n;
   10050             :                 }
   10051             :             | ALTER PROCEDURE function_with_argtypes opt_no DEPENDS ON EXTENSION name
   10052             :                 {
   10053           0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10054             : 
   10055           0 :                     n->objectType = OBJECT_PROCEDURE;
   10056           0 :                     n->object = (Node *) $3;
   10057           0 :                     n->extname = makeString($8);
   10058           0 :                     n->remove = $4;
   10059           0 :                     $$ = (Node *) n;
   10060             :                 }
   10061             :             | ALTER ROUTINE function_with_argtypes opt_no DEPENDS ON EXTENSION name
   10062             :                 {
   10063           0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10064             : 
   10065           0 :                     n->objectType = OBJECT_ROUTINE;
   10066           0 :                     n->object = (Node *) $3;
   10067           0 :                     n->extname = makeString($8);
   10068           0 :                     n->remove = $4;
   10069           0 :                     $$ = (Node *) n;
   10070             :                 }
   10071             :             | ALTER TRIGGER name ON qualified_name opt_no DEPENDS ON EXTENSION name
   10072             :                 {
   10073          10 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10074             : 
   10075          10 :                     n->objectType = OBJECT_TRIGGER;
   10076          10 :                     n->relation = $5;
   10077          10 :                     n->object = (Node *) list_make1(makeString($3));
   10078          10 :                     n->extname = makeString($10);
   10079          10 :                     n->remove = $6;
   10080          10 :                     $$ = (Node *) n;
   10081             :                 }
   10082             :             | ALTER MATERIALIZED VIEW qualified_name opt_no DEPENDS ON EXTENSION name
   10083             :                 {
   10084          10 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10085             : 
   10086          10 :                     n->objectType = OBJECT_MATVIEW;
   10087          10 :                     n->relation = $4;
   10088          10 :                     n->extname = makeString($9);
   10089          10 :                     n->remove = $5;
   10090          10 :                     $$ = (Node *) n;
   10091             :                 }
   10092             :             | ALTER INDEX qualified_name opt_no DEPENDS ON EXTENSION name
   10093             :                 {
   10094          14 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10095             : 
   10096          14 :                     n->objectType = OBJECT_INDEX;
   10097          14 :                     n->relation = $3;
   10098          14 :                     n->extname = makeString($8);
   10099          14 :                     n->remove = $4;
   10100          14 :                     $$ = (Node *) n;
   10101             :                 }
   10102             :         ;
   10103             : 
   10104           8 : opt_no:     NO              { $$ = true; }
   10105          38 :             | /* EMPTY */   { $$ = false;   }
   10106             :         ;
   10107             : 
   10108             : /*****************************************************************************
   10109             :  *
   10110             :  * ALTER THING name SET SCHEMA name
   10111             :  *
   10112             :  *****************************************************************************/
   10113             : 
   10114             : AlterObjectSchemaStmt:
   10115             :             ALTER AGGREGATE aggregate_with_argtypes SET SCHEMA name
   10116             :                 {
   10117          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10118             : 
   10119          24 :                     n->objectType = OBJECT_AGGREGATE;
   10120          24 :                     n->object = (Node *) $3;
   10121          24 :                     n->newschema = $6;
   10122          24 :                     n->missing_ok = false;
   10123          24 :                     $$ = (Node *) n;
   10124             :                 }
   10125             :             | ALTER COLLATION any_name SET SCHEMA name
   10126             :                 {
   10127           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10128             : 
   10129           6 :                     n->objectType = OBJECT_COLLATION;
   10130           6 :                     n->object = (Node *) $3;
   10131           6 :                     n->newschema = $6;
   10132           6 :                     n->missing_ok = false;
   10133           6 :                     $$ = (Node *) n;
   10134             :                 }
   10135             :             | ALTER CONVERSION_P any_name SET SCHEMA name
   10136             :                 {
   10137          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10138             : 
   10139          24 :                     n->objectType = OBJECT_CONVERSION;
   10140          24 :                     n->object = (Node *) $3;
   10141          24 :                     n->newschema = $6;
   10142          24 :                     n->missing_ok = false;
   10143          24 :                     $$ = (Node *) n;
   10144             :                 }
   10145             :             | ALTER DOMAIN_P any_name SET SCHEMA name
   10146             :                 {
   10147           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10148             : 
   10149           6 :                     n->objectType = OBJECT_DOMAIN;
   10150           6 :                     n->object = (Node *) $3;
   10151           6 :                     n->newschema = $6;
   10152           6 :                     n->missing_ok = false;
   10153           6 :                     $$ = (Node *) n;
   10154             :                 }
   10155             :             | ALTER EXTENSION name SET SCHEMA name
   10156             :                 {
   10157          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10158             : 
   10159          12 :                     n->objectType = OBJECT_EXTENSION;
   10160          12 :                     n->object = (Node *) makeString($3);
   10161          12 :                     n->newschema = $6;
   10162          12 :                     n->missing_ok = false;
   10163          12 :                     $$ = (Node *) n;
   10164             :                 }
   10165             :             | ALTER FUNCTION function_with_argtypes SET SCHEMA name
   10166             :                 {
   10167          42 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10168             : 
   10169          42 :                     n->objectType = OBJECT_FUNCTION;
   10170          42 :                     n->object = (Node *) $3;
   10171          42 :                     n->newschema = $6;
   10172          42 :                     n->missing_ok = false;
   10173          42 :                     $$ = (Node *) n;
   10174             :                 }
   10175             :             | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
   10176             :                 {
   10177          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10178             : 
   10179          18 :                     n->objectType = OBJECT_OPERATOR;
   10180          18 :                     n->object = (Node *) $3;
   10181          18 :                     n->newschema = $6;
   10182          18 :                     n->missing_ok = false;
   10183          18 :                     $$ = (Node *) n;
   10184             :                 }
   10185             :             | ALTER OPERATOR CLASS any_name USING name SET SCHEMA name
   10186             :                 {
   10187          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10188             : 
   10189          24 :                     n->objectType = OBJECT_OPCLASS;
   10190          24 :                     n->object = (Node *) lcons(makeString($6), $4);
   10191          24 :                     n->newschema = $9;
   10192          24 :                     n->missing_ok = false;
   10193          24 :                     $$ = (Node *) n;
   10194             :                 }
   10195             :             | ALTER OPERATOR FAMILY any_name USING name SET SCHEMA name
   10196             :                 {
   10197          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10198             : 
   10199          24 :                     n->objectType = OBJECT_OPFAMILY;
   10200          24 :                     n->object = (Node *) lcons(makeString($6), $4);
   10201          24 :                     n->newschema = $9;
   10202          24 :                     n->missing_ok = false;
   10203          24 :                     $$ = (Node *) n;
   10204             :                 }
   10205             :             | ALTER PROCEDURE function_with_argtypes SET SCHEMA name
   10206             :                 {
   10207           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10208             : 
   10209           0 :                     n->objectType = OBJECT_PROCEDURE;
   10210           0 :                     n->object = (Node *) $3;
   10211           0 :                     n->newschema = $6;
   10212           0 :                     n->missing_ok = false;
   10213           0 :                     $$ = (Node *) n;
   10214             :                 }
   10215             :             | ALTER ROUTINE function_with_argtypes SET SCHEMA name
   10216             :                 {
   10217           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10218             : 
   10219           0 :                     n->objectType = OBJECT_ROUTINE;
   10220           0 :                     n->object = (Node *) $3;
   10221           0 :                     n->newschema = $6;
   10222           0 :                     n->missing_ok = false;
   10223           0 :                     $$ = (Node *) n;
   10224             :                 }
   10225             :             | ALTER TABLE relation_expr SET SCHEMA name
   10226             :                 {
   10227          66 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10228             : 
   10229          66 :                     n->objectType = OBJECT_TABLE;
   10230          66 :                     n->relation = $3;
   10231          66 :                     n->newschema = $6;
   10232          66 :                     n->missing_ok = false;
   10233          66 :                     $$ = (Node *) n;
   10234             :                 }
   10235             :             | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10236             :                 {
   10237          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10238             : 
   10239          12 :                     n->objectType = OBJECT_TABLE;
   10240          12 :                     n->relation = $5;
   10241          12 :                     n->newschema = $8;
   10242          12 :                     n->missing_ok = true;
   10243          12 :                     $$ = (Node *) n;
   10244             :                 }
   10245             :             | ALTER STATISTICS any_name SET SCHEMA name
   10246             :                 {
   10247          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10248             : 
   10249          18 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10250          18 :                     n->object = (Node *) $3;
   10251          18 :                     n->newschema = $6;
   10252          18 :                     n->missing_ok = false;
   10253          18 :                     $$ = (Node *) n;
   10254             :                 }
   10255             :             | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
   10256             :                 {
   10257          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10258             : 
   10259          18 :                     n->objectType = OBJECT_TSPARSER;
   10260          18 :                     n->object = (Node *) $5;
   10261          18 :                     n->newschema = $8;
   10262          18 :                     n->missing_ok = false;
   10263          18 :                     $$ = (Node *) n;
   10264             :                 }
   10265             :             | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
   10266             :                 {
   10267          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10268             : 
   10269          24 :                     n->objectType = OBJECT_TSDICTIONARY;
   10270          24 :                     n->object = (Node *) $5;
   10271          24 :                     n->newschema = $8;
   10272          24 :                     n->missing_ok = false;
   10273          24 :                     $$ = (Node *) n;
   10274             :                 }
   10275             :             | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
   10276             :                 {
   10277          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10278             : 
   10279          18 :                     n->objectType = OBJECT_TSTEMPLATE;
   10280          18 :                     n->object = (Node *) $5;
   10281          18 :                     n->newschema = $8;
   10282          18 :                     n->missing_ok = false;
   10283          18 :                     $$ = (Node *) n;
   10284             :                 }
   10285             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
   10286             :                 {
   10287          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10288             : 
   10289          24 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10290          24 :                     n->object = (Node *) $5;
   10291          24 :                     n->newschema = $8;
   10292          24 :                     n->missing_ok = false;
   10293          24 :                     $$ = (Node *) n;
   10294             :                 }
   10295             :             | ALTER SEQUENCE qualified_name SET SCHEMA name
   10296             :                 {
   10297           8 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10298             : 
   10299           8 :                     n->objectType = OBJECT_SEQUENCE;
   10300           8 :                     n->relation = $3;
   10301           8 :                     n->newschema = $6;
   10302           8 :                     n->missing_ok = false;
   10303           8 :                     $$ = (Node *) n;
   10304             :                 }
   10305             :             | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
   10306             :                 {
   10307           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10308             : 
   10309           0 :                     n->objectType = OBJECT_SEQUENCE;
   10310           0 :                     n->relation = $5;
   10311           0 :                     n->newschema = $8;
   10312           0 :                     n->missing_ok = true;
   10313           0 :                     $$ = (Node *) n;
   10314             :                 }
   10315             :             | ALTER VIEW qualified_name SET SCHEMA name
   10316             :                 {
   10317           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10318             : 
   10319           0 :                     n->objectType = OBJECT_VIEW;
   10320           0 :                     n->relation = $3;
   10321           0 :                     n->newschema = $6;
   10322           0 :                     n->missing_ok = false;
   10323           0 :                     $$ = (Node *) n;
   10324             :                 }
   10325             :             | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
   10326             :                 {
   10327           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10328             : 
   10329           0 :                     n->objectType = OBJECT_VIEW;
   10330           0 :                     n->relation = $5;
   10331           0 :                     n->newschema = $8;
   10332           0 :                     n->missing_ok = true;
   10333           0 :                     $$ = (Node *) n;
   10334             :                 }
   10335             :             | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
   10336             :                 {
   10337           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10338             : 
   10339           6 :                     n->objectType = OBJECT_MATVIEW;
   10340           6 :                     n->relation = $4;
   10341           6 :                     n->newschema = $7;
   10342           6 :                     n->missing_ok = false;
   10343           6 :                     $$ = (Node *) n;
   10344             :                 }
   10345             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
   10346             :                 {
   10347           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10348             : 
   10349           0 :                     n->objectType = OBJECT_MATVIEW;
   10350           0 :                     n->relation = $6;
   10351           0 :                     n->newschema = $9;
   10352           0 :                     n->missing_ok = true;
   10353           0 :                     $$ = (Node *) n;
   10354             :                 }
   10355             :             | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
   10356             :                 {
   10357           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10358             : 
   10359           6 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10360           6 :                     n->relation = $4;
   10361           6 :                     n->newschema = $7;
   10362           6 :                     n->missing_ok = false;
   10363           6 :                     $$ = (Node *) n;
   10364             :                 }
   10365             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10366             :                 {
   10367           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10368             : 
   10369           6 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10370           6 :                     n->relation = $6;
   10371           6 :                     n->newschema = $9;
   10372           6 :                     n->missing_ok = true;
   10373           6 :                     $$ = (Node *) n;
   10374             :                 }
   10375             :             | ALTER TYPE_P any_name SET SCHEMA name
   10376             :                 {
   10377          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10378             : 
   10379          12 :                     n->objectType = OBJECT_TYPE;
   10380          12 :                     n->object = (Node *) $3;
   10381          12 :                     n->newschema = $6;
   10382          12 :                     n->missing_ok = false;
   10383          12 :                     $$ = (Node *) n;
   10384             :                 }
   10385             :         ;
   10386             : 
   10387             : /*****************************************************************************
   10388             :  *
   10389             :  * ALTER OPERATOR name SET define
   10390             :  *
   10391             :  *****************************************************************************/
   10392             : 
   10393             : AlterOperatorStmt:
   10394             :             ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
   10395             :                 {
   10396         608 :                     AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
   10397             : 
   10398         608 :                     n->opername = $3;
   10399         608 :                     n->options = $6;
   10400         608 :                     $$ = (Node *) n;
   10401             :                 }
   10402             :         ;
   10403             : 
   10404         668 : operator_def_list:  operator_def_elem                               { $$ = list_make1($1); }
   10405         506 :             | operator_def_list ',' operator_def_elem               { $$ = lappend($1, $3); }
   10406             :         ;
   10407             : 
   10408             : operator_def_elem: ColLabel '=' NONE
   10409          30 :                         { $$ = makeDefElem($1, NULL, @1); }
   10410             :                    | ColLabel '=' operator_def_arg
   10411        1110 :                         { $$ = makeDefElem($1, (Node *) $3, @1); }
   10412             :                    | ColLabel
   10413          34 :                         { $$ = makeDefElem($1, NULL, @1); }
   10414             :         ;
   10415             : 
   10416             : /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
   10417             : operator_def_arg:
   10418        1032 :             func_type                       { $$ = (Node *) $1; }
   10419          24 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
   10420          54 :             | qual_all_Op                   { $$ = (Node *) $1; }
   10421           0 :             | NumericOnly                   { $$ = (Node *) $1; }
   10422           0 :             | Sconst                        { $$ = (Node *) makeString($1); }
   10423             :         ;
   10424             : 
   10425             : /*****************************************************************************
   10426             :  *
   10427             :  * ALTER TYPE name SET define
   10428             :  *
   10429             :  * We repurpose ALTER OPERATOR's version of "definition" here
   10430             :  *
   10431             :  *****************************************************************************/
   10432             : 
   10433             : AlterTypeStmt:
   10434             :             ALTER TYPE_P any_name SET '(' operator_def_list ')'
   10435             :                 {
   10436          60 :                     AlterTypeStmt *n = makeNode(AlterTypeStmt);
   10437             : 
   10438          60 :                     n->typeName = $3;
   10439          60 :                     n->options = $6;
   10440          60 :                     $$ = (Node *) n;
   10441             :                 }
   10442             :         ;
   10443             : 
   10444             : /*****************************************************************************
   10445             :  *
   10446             :  * ALTER THING name OWNER TO newname
   10447             :  *
   10448             :  *****************************************************************************/
   10449             : 
   10450             : AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec
   10451             :                 {
   10452         236 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10453             : 
   10454         236 :                     n->objectType = OBJECT_AGGREGATE;
   10455         236 :                     n->object = (Node *) $3;
   10456         236 :                     n->newowner = $6;
   10457         236 :                     $$ = (Node *) n;
   10458             :                 }
   10459             :             | ALTER COLLATION any_name OWNER TO RoleSpec
   10460             :                 {
   10461          24 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10462             : 
   10463          24 :                     n->objectType = OBJECT_COLLATION;
   10464          24 :                     n->object = (Node *) $3;
   10465          24 :                     n->newowner = $6;
   10466          24 :                     $$ = (Node *) n;
   10467             :                 }
   10468             :             | ALTER CONVERSION_P any_name OWNER TO RoleSpec
   10469             :                 {
   10470          24 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10471             : 
   10472          24 :                     n->objectType = OBJECT_CONVERSION;
   10473          24 :                     n->object = (Node *) $3;
   10474          24 :                     n->newowner = $6;
   10475          24 :                     $$ = (Node *) n;
   10476             :                 }
   10477             :             | ALTER DATABASE name OWNER TO RoleSpec
   10478             :                 {
   10479          80 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10480             : 
   10481          80 :                     n->objectType = OBJECT_DATABASE;
   10482          80 :                     n->object = (Node *) makeString($3);
   10483          80 :                     n->newowner = $6;
   10484          80 :                     $$ = (Node *) n;
   10485             :                 }
   10486             :             | ALTER DOMAIN_P any_name OWNER TO RoleSpec
   10487             :                 {
   10488          92 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10489             : 
   10490          92 :                     n->objectType = OBJECT_DOMAIN;
   10491          92 :                     n->object = (Node *) $3;
   10492          92 :                     n->newowner = $6;
   10493          92 :                     $$ = (Node *) n;
   10494             :                 }
   10495             :             | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
   10496             :                 {
   10497        1114 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10498             : 
   10499        1114 :                     n->objectType = OBJECT_FUNCTION;
   10500        1114 :                     n->object = (Node *) $3;
   10501        1114 :                     n->newowner = $6;
   10502        1114 :                     $$ = (Node *) n;
   10503             :                 }
   10504             :             | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
   10505             :                 {
   10506         144 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10507             : 
   10508         144 :                     n->objectType = OBJECT_LANGUAGE;
   10509         144 :                     n->object = (Node *) makeString($4);
   10510         144 :                     n->newowner = $7;
   10511         144 :                     $$ = (Node *) n;
   10512             :                 }
   10513             :             | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
   10514             :                 {
   10515          18 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10516             : 
   10517          18 :                     n->objectType = OBJECT_LARGEOBJECT;
   10518          18 :                     n->object = (Node *) $4;
   10519          18 :                     n->newowner = $7;
   10520          18 :                     $$ = (Node *) n;
   10521             :                 }
   10522             :             | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
   10523             :                 {
   10524          68 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10525             : 
   10526          68 :                     n->objectType = OBJECT_OPERATOR;
   10527          68 :                     n->object = (Node *) $3;
   10528          68 :                     n->newowner = $6;
   10529          68 :                     $$ = (Node *) n;
   10530             :                 }
   10531             :             | ALTER OPERATOR CLASS any_name USING name OWNER TO RoleSpec
   10532             :                 {
   10533          60 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10534             : 
   10535          60 :                     n->objectType = OBJECT_OPCLASS;
   10536          60 :                     n->object = (Node *) lcons(makeString($6), $4);
   10537          60 :                     n->newowner = $9;
   10538          60 :                     $$ = (Node *) n;
   10539             :                 }
   10540             :             | ALTER OPERATOR FAMILY any_name USING name OWNER TO RoleSpec
   10541             :                 {
   10542          76 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10543             : 
   10544          76 :                     n->objectType = OBJECT_OPFAMILY;
   10545          76 :                     n->object = (Node *) lcons(makeString($6), $4);
   10546          76 :                     n->newowner = $9;
   10547          76 :                     $$ = (Node *) n;
   10548             :                 }
   10549             :             | ALTER PROCEDURE function_with_argtypes OWNER TO RoleSpec
   10550             :                 {
   10551          48 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10552             : 
   10553          48 :                     n->objectType = OBJECT_PROCEDURE;
   10554          48 :                     n->object = (Node *) $3;
   10555          48 :                     n->newowner = $6;
   10556          48 :                     $$ = (Node *) n;
   10557             :                 }
   10558             :             | ALTER ROUTINE function_with_argtypes OWNER TO RoleSpec
   10559             :                 {
   10560           0 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10561             : 
   10562           0 :                     n->objectType = OBJECT_ROUTINE;
   10563           0 :                     n->object = (Node *) $3;
   10564           0 :                     n->newowner = $6;
   10565           0 :                     $$ = (Node *) n;
   10566             :                 }
   10567             :             | ALTER SCHEMA name OWNER TO RoleSpec
   10568             :                 {
   10569          78 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10570             : 
   10571          78 :                     n->objectType = OBJECT_SCHEMA;
   10572          78 :                     n->object = (Node *) makeString($3);
   10573          78 :                     n->newowner = $6;
   10574          78 :                     $$ = (Node *) n;
   10575             :                 }
   10576             :             | ALTER TYPE_P any_name OWNER TO RoleSpec
   10577             :                 {
   10578         152 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10579             : 
   10580         152 :                     n->objectType = OBJECT_TYPE;
   10581         152 :                     n->object = (Node *) $3;
   10582         152 :                     n->newowner = $6;
   10583         152 :                     $$ = (Node *) n;
   10584             :                 }
   10585             :             | ALTER TABLESPACE name OWNER TO RoleSpec
   10586             :                 {
   10587           6 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10588             : 
   10589           6 :                     n->objectType = OBJECT_TABLESPACE;
   10590           6 :                     n->object = (Node *) makeString($3);
   10591           6 :                     n->newowner = $6;
   10592           6 :                     $$ = (Node *) n;
   10593             :                 }
   10594             :             | ALTER STATISTICS any_name OWNER TO RoleSpec
   10595             :                 {
   10596          40 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10597             : 
   10598          40 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10599          40 :                     n->object = (Node *) $3;
   10600          40 :                     n->newowner = $6;
   10601          40 :                     $$ = (Node *) n;
   10602             :                 }
   10603             :             | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
   10604             :                 {
   10605          60 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10606             : 
   10607          60 :                     n->objectType = OBJECT_TSDICTIONARY;
   10608          60 :                     n->object = (Node *) $5;
   10609          60 :                     n->newowner = $8;
   10610          60 :                     $$ = (Node *) n;
   10611             :                 }
   10612             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
   10613             :                 {
   10614          40 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10615             : 
   10616          40 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10617          40 :                     n->object = (Node *) $5;
   10618          40 :                     n->newowner = $8;
   10619          40 :                     $$ = (Node *) n;
   10620             :                 }
   10621             :             | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
   10622             :                 {
   10623          22 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10624             : 
   10625          22 :                     n->objectType = OBJECT_FDW;
   10626          22 :                     n->object = (Node *) makeString($5);
   10627          22 :                     n->newowner = $8;
   10628          22 :                     $$ = (Node *) n;
   10629             :                 }
   10630             :             | ALTER SERVER name OWNER TO RoleSpec
   10631             :                 {
   10632          70 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10633             : 
   10634          70 :                     n->objectType = OBJECT_FOREIGN_SERVER;
   10635          70 :                     n->object = (Node *) makeString($3);
   10636          70 :                     n->newowner = $6;
   10637          70 :                     $$ = (Node *) n;
   10638             :                 }
   10639             :             | ALTER EVENT TRIGGER name OWNER TO RoleSpec
   10640             :                 {
   10641          16 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10642             : 
   10643          16 :                     n->objectType = OBJECT_EVENT_TRIGGER;
   10644          16 :                     n->object = (Node *) makeString($4);
   10645          16 :                     n->newowner = $7;
   10646          16 :                     $$ = (Node *) n;
   10647             :                 }
   10648             :             | ALTER PUBLICATION name OWNER TO RoleSpec
   10649             :                 {
   10650          26 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10651             : 
   10652          26 :                     n->objectType = OBJECT_PUBLICATION;
   10653          26 :                     n->object = (Node *) makeString($3);
   10654          26 :                     n->newowner = $6;
   10655          26 :                     $$ = (Node *) n;
   10656             :                 }
   10657             :             | ALTER SUBSCRIPTION name OWNER TO RoleSpec
   10658             :                 {
   10659          18 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10660             : 
   10661          18 :                     n->objectType = OBJECT_SUBSCRIPTION;
   10662          18 :                     n->object = (Node *) makeString($3);
   10663          18 :                     n->newowner = $6;
   10664          18 :                     $$ = (Node *) n;
   10665             :                 }
   10666             :         ;
   10667             : 
   10668             : 
   10669             : /*****************************************************************************
   10670             :  *
   10671             :  * CREATE PUBLICATION name [WITH options]
   10672             :  *
   10673             :  * CREATE PUBLICATION FOR ALL TABLES [WITH options]
   10674             :  *
   10675             :  * CREATE PUBLICATION FOR pub_obj [, ...] [WITH options]
   10676             :  *
   10677             :  * pub_obj is one of:
   10678             :  *
   10679             :  *      TABLE table [, ...]
   10680             :  *      TABLES IN SCHEMA schema [, ...]
   10681             :  *
   10682             :  *****************************************************************************/
   10683             : 
   10684             : CreatePublicationStmt:
   10685             :             CREATE PUBLICATION name opt_definition
   10686             :                 {
   10687         128 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10688             : 
   10689         128 :                     n->pubname = $3;
   10690         128 :                     n->options = $4;
   10691         128 :                     $$ = (Node *) n;
   10692             :                 }
   10693             :             | CREATE PUBLICATION name FOR ALL TABLES opt_definition
   10694             :                 {
   10695          94 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10696             : 
   10697          94 :                     n->pubname = $3;
   10698          94 :                     n->options = $7;
   10699          94 :                     n->for_all_tables = true;
   10700          94 :                     $$ = (Node *) n;
   10701             :                 }
   10702             :             | CREATE PUBLICATION name FOR pub_obj_list opt_definition
   10703             :                 {
   10704         624 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10705             : 
   10706         624 :                     n->pubname = $3;
   10707         624 :                     n->options = $6;
   10708         624 :                     n->pubobjects = (List *) $5;
   10709         624 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10710         594 :                     $$ = (Node *) n;
   10711             :                 }
   10712             :         ;
   10713             : 
   10714             : /*
   10715             :  * FOR TABLE and FOR TABLES IN SCHEMA specifications
   10716             :  *
   10717             :  * This rule parses publication objects with and without keyword prefixes.
   10718             :  *
   10719             :  * The actual type of the object without keyword prefix depends on the previous
   10720             :  * one with keyword prefix. It will be preprocessed in preprocess_pubobj_list().
   10721             :  *
   10722             :  * For the object without keyword prefix, we cannot just use relation_expr here,
   10723             :  * because some extended expressions in relation_expr cannot be used as a
   10724             :  * schemaname and we cannot differentiate it. So, we extract the rules from
   10725             :  * relation_expr here.
   10726             :  */
   10727             : PublicationObjSpec:
   10728             :             TABLE relation_expr opt_column_list OptWhereClause
   10729             :                 {
   10730        1278 :                     $$ = makeNode(PublicationObjSpec);
   10731        1278 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLE;
   10732        1278 :                     $$->pubtable = makeNode(PublicationTable);
   10733        1278 :                     $$->pubtable->relation = $2;
   10734        1278 :                     $$->pubtable->columns = $3;
   10735        1278 :                     $$->pubtable->whereClause = $4;
   10736             :                 }
   10737             :             | TABLES IN_P SCHEMA ColId
   10738             :                 {
   10739         332 :                     $$ = makeNode(PublicationObjSpec);
   10740         332 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   10741         332 :                     $$->name = $4;
   10742         332 :                     $$->location = @4;
   10743             :                 }
   10744             :             | TABLES IN_P SCHEMA CURRENT_SCHEMA
   10745             :                 {
   10746          18 :                     $$ = makeNode(PublicationObjSpec);
   10747          18 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   10748          18 :                     $$->location = @4;
   10749             :                 }
   10750             :             | ColId opt_column_list OptWhereClause
   10751             :                 {
   10752         130 :                     $$ = makeNode(PublicationObjSpec);
   10753         130 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10754             :                     /*
   10755             :                      * If either a row filter or column list is specified, create
   10756             :                      * a PublicationTable object.
   10757             :                      */
   10758         130 :                     if ($2 || $3)
   10759             :                     {
   10760             :                         /*
   10761             :                          * The OptWhereClause must be stored here but it is
   10762             :                          * valid only for tables. For non-table objects, an
   10763             :                          * error will be thrown later via
   10764             :                          * preprocess_pubobj_list().
   10765             :                          */
   10766          42 :                         $$->pubtable = makeNode(PublicationTable);
   10767          42 :                         $$->pubtable->relation = makeRangeVar(NULL, $1, @1);
   10768          42 :                         $$->pubtable->columns = $2;
   10769          42 :                         $$->pubtable->whereClause = $3;
   10770             :                     }
   10771             :                     else
   10772             :                     {
   10773          88 :                         $$->name = $1;
   10774             :                     }
   10775         130 :                     $$->location = @1;
   10776             :                 }
   10777             :             | ColId indirection opt_column_list OptWhereClause
   10778             :                 {
   10779          32 :                     $$ = makeNode(PublicationObjSpec);
   10780          32 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10781          32 :                     $$->pubtable = makeNode(PublicationTable);
   10782          32 :                     $$->pubtable->relation = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   10783          32 :                     $$->pubtable->columns = $3;
   10784          32 :                     $$->pubtable->whereClause = $4;
   10785          32 :                     $$->location = @1;
   10786             :                 }
   10787             :             /* grammar like tablename * , ONLY tablename, ONLY ( tablename ) */
   10788             :             | extended_relation_expr opt_column_list OptWhereClause
   10789             :                 {
   10790           6 :                     $$ = makeNode(PublicationObjSpec);
   10791           6 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10792           6 :                     $$->pubtable = makeNode(PublicationTable);
   10793           6 :                     $$->pubtable->relation = $1;
   10794           6 :                     $$->pubtable->columns = $2;
   10795           6 :                     $$->pubtable->whereClause = $3;
   10796             :                 }
   10797             :             | CURRENT_SCHEMA
   10798             :                 {
   10799          18 :                     $$ = makeNode(PublicationObjSpec);
   10800          18 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10801          18 :                     $$->location = @1;
   10802             :                 }
   10803             :                 ;
   10804             : 
   10805             : pub_obj_list:   PublicationObjSpec
   10806        1590 :                     { $$ = list_make1($1); }
   10807             :             | pub_obj_list ',' PublicationObjSpec
   10808         224 :                     { $$ = lappend($1, $3); }
   10809             :     ;
   10810             : 
   10811             : /*****************************************************************************
   10812             :  *
   10813             :  * ALTER PUBLICATION name SET ( options )
   10814             :  *
   10815             :  * ALTER PUBLICATION name ADD pub_obj [, ...]
   10816             :  *
   10817             :  * ALTER PUBLICATION name DROP pub_obj [, ...]
   10818             :  *
   10819             :  * ALTER PUBLICATION name SET pub_obj [, ...]
   10820             :  *
   10821             :  * pub_obj is one of:
   10822             :  *
   10823             :  *      TABLE table_name [, ...]
   10824             :  *      TABLES IN SCHEMA schema_name [, ...]
   10825             :  *
   10826             :  *****************************************************************************/
   10827             : 
   10828             : AlterPublicationStmt:
   10829             :             ALTER PUBLICATION name SET definition
   10830             :                 {
   10831         116 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10832             : 
   10833         116 :                     n->pubname = $3;
   10834         116 :                     n->options = $5;
   10835         116 :                     $$ = (Node *) n;
   10836             :                 }
   10837             :             | ALTER PUBLICATION name ADD_P pub_obj_list
   10838             :                 {
   10839         348 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10840             : 
   10841         348 :                     n->pubname = $3;
   10842         348 :                     n->pubobjects = $5;
   10843         348 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10844         342 :                     n->action = AP_AddObjects;
   10845         342 :                     $$ = (Node *) n;
   10846             :                 }
   10847             :             | ALTER PUBLICATION name SET pub_obj_list
   10848             :                 {
   10849         464 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10850             : 
   10851         464 :                     n->pubname = $3;
   10852         464 :                     n->pubobjects = $5;
   10853         464 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10854         464 :                     n->action = AP_SetObjects;
   10855         464 :                     $$ = (Node *) n;
   10856             :                 }
   10857             :             | ALTER PUBLICATION name DROP pub_obj_list
   10858             :                 {
   10859         154 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10860             : 
   10861         154 :                     n->pubname = $3;
   10862         154 :                     n->pubobjects = $5;
   10863         154 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10864         154 :                     n->action = AP_DropObjects;
   10865         154 :                     $$ = (Node *) n;
   10866             :                 }
   10867             :         ;
   10868             : 
   10869             : /*****************************************************************************
   10870             :  *
   10871             :  * CREATE SUBSCRIPTION name ...
   10872             :  *
   10873             :  *****************************************************************************/
   10874             : 
   10875             : CreateSubscriptionStmt:
   10876             :             CREATE SUBSCRIPTION name CONNECTION Sconst PUBLICATION name_list opt_definition
   10877             :                 {
   10878             :                     CreateSubscriptionStmt *n =
   10879         448 :                         makeNode(CreateSubscriptionStmt);
   10880         448 :                     n->subname = $3;
   10881         448 :                     n->conninfo = $5;
   10882         448 :                     n->publication = $7;
   10883         448 :                     n->options = $8;
   10884         448 :                     $$ = (Node *) n;
   10885             :                 }
   10886             :         ;
   10887             : 
   10888             : /*****************************************************************************
   10889             :  *
   10890             :  * ALTER SUBSCRIPTION name ...
   10891             :  *
   10892             :  *****************************************************************************/
   10893             : 
   10894             : AlterSubscriptionStmt:
   10895             :             ALTER SUBSCRIPTION name SET definition
   10896             :                 {
   10897             :                     AlterSubscriptionStmt *n =
   10898         186 :                         makeNode(AlterSubscriptionStmt);
   10899             : 
   10900         186 :                     n->kind = ALTER_SUBSCRIPTION_OPTIONS;
   10901         186 :                     n->subname = $3;
   10902         186 :                     n->options = $5;
   10903         186 :                     $$ = (Node *) n;
   10904             :                 }
   10905             :             | ALTER SUBSCRIPTION name CONNECTION Sconst
   10906             :                 {
   10907             :                     AlterSubscriptionStmt *n =
   10908          26 :                         makeNode(AlterSubscriptionStmt);
   10909             : 
   10910          26 :                     n->kind = ALTER_SUBSCRIPTION_CONNECTION;
   10911          26 :                     n->subname = $3;
   10912          26 :                     n->conninfo = $5;
   10913          26 :                     $$ = (Node *) n;
   10914             :                 }
   10915             :             | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
   10916             :                 {
   10917             :                     AlterSubscriptionStmt *n =
   10918          58 :                         makeNode(AlterSubscriptionStmt);
   10919             : 
   10920          58 :                     n->kind = ALTER_SUBSCRIPTION_REFRESH;
   10921          58 :                     n->subname = $3;
   10922          58 :                     n->options = $6;
   10923          58 :                     $$ = (Node *) n;
   10924             :                 }
   10925             :             | ALTER SUBSCRIPTION name ADD_P PUBLICATION name_list opt_definition
   10926             :                 {
   10927             :                     AlterSubscriptionStmt *n =
   10928          28 :                         makeNode(AlterSubscriptionStmt);
   10929             : 
   10930          28 :                     n->kind = ALTER_SUBSCRIPTION_ADD_PUBLICATION;
   10931          28 :                     n->subname = $3;
   10932          28 :                     n->publication = $6;
   10933          28 :                     n->options = $7;
   10934          28 :                     $$ = (Node *) n;
   10935             :                 }
   10936             :             | ALTER SUBSCRIPTION name DROP PUBLICATION name_list opt_definition
   10937             :                 {
   10938             :                     AlterSubscriptionStmt *n =
   10939          26 :                         makeNode(AlterSubscriptionStmt);
   10940             : 
   10941          26 :                     n->kind = ALTER_SUBSCRIPTION_DROP_PUBLICATION;
   10942          26 :                     n->subname = $3;
   10943          26 :                     n->publication = $6;
   10944          26 :                     n->options = $7;
   10945          26 :                     $$ = (Node *) n;
   10946             :                 }
   10947             :             | ALTER SUBSCRIPTION name SET PUBLICATION name_list opt_definition
   10948             :                 {
   10949             :                     AlterSubscriptionStmt *n =
   10950          44 :                         makeNode(AlterSubscriptionStmt);
   10951             : 
   10952          44 :                     n->kind = ALTER_SUBSCRIPTION_SET_PUBLICATION;
   10953          44 :                     n->subname = $3;
   10954          44 :                     n->publication = $6;
   10955          44 :                     n->options = $7;
   10956          44 :                     $$ = (Node *) n;
   10957             :                 }
   10958             :             | ALTER SUBSCRIPTION name ENABLE_P
   10959             :                 {
   10960             :                     AlterSubscriptionStmt *n =
   10961          50 :                         makeNode(AlterSubscriptionStmt);
   10962             : 
   10963          50 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   10964          50 :                     n->subname = $3;
   10965          50 :                     n->options = list_make1(makeDefElem("enabled",
   10966             :                                             (Node *) makeBoolean(true), @1));
   10967          50 :                     $$ = (Node *) n;
   10968             :                 }
   10969             :             | ALTER SUBSCRIPTION name DISABLE_P
   10970             :                 {
   10971             :                     AlterSubscriptionStmt *n =
   10972          34 :                         makeNode(AlterSubscriptionStmt);
   10973             : 
   10974          34 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   10975          34 :                     n->subname = $3;
   10976          34 :                     n->options = list_make1(makeDefElem("enabled",
   10977             :                                             (Node *) makeBoolean(false), @1));
   10978          34 :                     $$ = (Node *) n;
   10979             :                 }
   10980             :             | ALTER SUBSCRIPTION name SKIP definition
   10981             :                 {
   10982             :                     AlterSubscriptionStmt *n =
   10983          24 :                         makeNode(AlterSubscriptionStmt);
   10984             : 
   10985          24 :                     n->kind = ALTER_SUBSCRIPTION_SKIP;
   10986          24 :                     n->subname = $3;
   10987          24 :                     n->options = $5;
   10988          24 :                     $$ = (Node *) n;
   10989             :                 }
   10990             :         ;
   10991             : 
   10992             : /*****************************************************************************
   10993             :  *
   10994             :  * DROP SUBSCRIPTION [ IF EXISTS ] name
   10995             :  *
   10996             :  *****************************************************************************/
   10997             : 
   10998             : DropSubscriptionStmt: DROP SUBSCRIPTION name opt_drop_behavior
   10999             :                 {
   11000         222 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   11001             : 
   11002         222 :                     n->subname = $3;
   11003         222 :                     n->missing_ok = false;
   11004         222 :                     n->behavior = $4;
   11005         222 :                     $$ = (Node *) n;
   11006             :                 }
   11007             :                 |  DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
   11008             :                 {
   11009           6 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   11010             : 
   11011           6 :                     n->subname = $5;
   11012           6 :                     n->missing_ok = true;
   11013           6 :                     n->behavior = $6;
   11014           6 :                     $$ = (Node *) n;
   11015             :                 }
   11016             :         ;
   11017             : 
   11018             : /*****************************************************************************
   11019             :  *
   11020             :  *      QUERY:  Define Rewrite Rule
   11021             :  *
   11022             :  *****************************************************************************/
   11023             : 
   11024             : RuleStmt:   CREATE opt_or_replace RULE name AS
   11025             :             ON event TO qualified_name where_clause
   11026             :             DO opt_instead RuleActionList
   11027             :                 {
   11028        1174 :                     RuleStmt   *n = makeNode(RuleStmt);
   11029             : 
   11030        1174 :                     n->replace = $2;
   11031        1174 :                     n->relation = $9;
   11032        1174 :                     n->rulename = $4;
   11033        1174 :                     n->whereClause = $10;
   11034        1174 :                     n->event = $7;
   11035        1174 :                     n->instead = $12;
   11036        1174 :                     n->actions = $13;
   11037        1174 :                     $$ = (Node *) n;
   11038             :                 }
   11039             :         ;
   11040             : 
   11041             : RuleActionList:
   11042         170 :             NOTHING                                 { $$ = NIL; }
   11043         954 :             | RuleActionStmt                        { $$ = list_make1($1); }
   11044          50 :             | '(' RuleActionMulti ')'               { $$ = $2; }
   11045             :         ;
   11046             : 
   11047             : /* the thrashing around here is to discard "empty" statements... */
   11048             : RuleActionMulti:
   11049             :             RuleActionMulti ';' RuleActionStmtOrEmpty
   11050          70 :                 { if ($3 != NULL)
   11051          50 :                     $$ = lappend($1, $3);
   11052             :                   else
   11053          20 :                     $$ = $1;
   11054             :                 }
   11055             :             | RuleActionStmtOrEmpty
   11056          50 :                 { if ($1 != NULL)
   11057          50 :                     $$ = list_make1($1);
   11058             :                   else
   11059           0 :                     $$ = NIL;
   11060             :                 }
   11061             :         ;
   11062             : 
   11063             : RuleActionStmt:
   11064             :             SelectStmt
   11065             :             | InsertStmt
   11066             :             | UpdateStmt
   11067             :             | DeleteStmt
   11068             :             | NotifyStmt
   11069             :         ;
   11070             : 
   11071             : RuleActionStmtOrEmpty:
   11072         100 :             RuleActionStmt                          { $$ = $1; }
   11073          20 :             |   /*EMPTY*/                           { $$ = NULL; }
   11074             :         ;
   11075             : 
   11076          18 : event:      SELECT                                  { $$ = CMD_SELECT; }
   11077         456 :             | UPDATE                                { $$ = CMD_UPDATE; }
   11078         180 :             | DELETE_P                              { $$ = CMD_DELETE; }
   11079         520 :             | INSERT                                { $$ = CMD_INSERT; }
   11080             :          ;
   11081             : 
   11082             : opt_instead:
   11083         802 :             INSTEAD                                 { $$ = true; }
   11084         156 :             | ALSO                                  { $$ = false; }
   11085         216 :             | /*EMPTY*/                             { $$ = false; }
   11086             :         ;
   11087             : 
   11088             : 
   11089             : /*****************************************************************************
   11090             :  *
   11091             :  *      QUERY:
   11092             :  *              NOTIFY <identifier> can appear both in rule bodies and
   11093             :  *              as a query-level command
   11094             :  *
   11095             :  *****************************************************************************/
   11096             : 
   11097             : NotifyStmt: NOTIFY ColId notify_payload
   11098             :                 {
   11099         130 :                     NotifyStmt *n = makeNode(NotifyStmt);
   11100             : 
   11101         130 :                     n->conditionname = $2;
   11102         130 :                     n->payload = $3;
   11103         130 :                     $$ = (Node *) n;
   11104             :                 }
   11105             :         ;
   11106             : 
   11107             : notify_payload:
   11108          62 :             ',' Sconst                          { $$ = $2; }
   11109          68 :             | /*EMPTY*/                         { $$ = NULL; }
   11110             :         ;
   11111             : 
   11112             : ListenStmt: LISTEN ColId
   11113             :                 {
   11114          74 :                     ListenStmt *n = makeNode(ListenStmt);
   11115             : 
   11116          74 :                     n->conditionname = $2;
   11117          74 :                     $$ = (Node *) n;
   11118             :                 }
   11119             :         ;
   11120             : 
   11121             : UnlistenStmt:
   11122             :             UNLISTEN ColId
   11123             :                 {
   11124           6 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   11125             : 
   11126           6 :                     n->conditionname = $2;
   11127           6 :                     $$ = (Node *) n;
   11128             :                 }
   11129             :             | UNLISTEN '*'
   11130             :                 {
   11131          32 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   11132             : 
   11133          32 :                     n->conditionname = NULL;
   11134          32 :                     $$ = (Node *) n;
   11135             :                 }
   11136             :         ;
   11137             : 
   11138             : 
   11139             : /*****************************************************************************
   11140             :  *
   11141             :  *      Transactions:
   11142             :  *
   11143             :  *      BEGIN / COMMIT / ROLLBACK
   11144             :  *      (also older versions END / ABORT)
   11145             :  *
   11146             :  *****************************************************************************/
   11147             : 
   11148             : TransactionStmt:
   11149             :             ABORT_P opt_transaction opt_transaction_chain
   11150             :                 {
   11151         216 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11152             : 
   11153         216 :                     n->kind = TRANS_STMT_ROLLBACK;
   11154         216 :                     n->options = NIL;
   11155         216 :                     n->chain = $3;
   11156         216 :                     n->location = -1;
   11157         216 :                     $$ = (Node *) n;
   11158             :                 }
   11159             :             | START TRANSACTION transaction_mode_list_or_empty
   11160             :                 {
   11161        1606 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11162             : 
   11163        1606 :                     n->kind = TRANS_STMT_START;
   11164        1606 :                     n->options = $3;
   11165        1606 :                     n->location = -1;
   11166        1606 :                     $$ = (Node *) n;
   11167             :                 }
   11168             :             | COMMIT opt_transaction opt_transaction_chain
   11169             :                 {
   11170       13012 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11171             : 
   11172       13012 :                     n->kind = TRANS_STMT_COMMIT;
   11173       13012 :                     n->options = NIL;
   11174       13012 :                     n->chain = $3;
   11175       13012 :                     n->location = -1;
   11176       13012 :                     $$ = (Node *) n;
   11177             :                 }
   11178             :             | ROLLBACK opt_transaction opt_transaction_chain
   11179             :                 {
   11180        2648 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11181             : 
   11182        2648 :                     n->kind = TRANS_STMT_ROLLBACK;
   11183        2648 :                     n->options = NIL;
   11184        2648 :                     n->chain = $3;
   11185        2648 :                     n->location = -1;
   11186        2648 :                     $$ = (Node *) n;
   11187             :                 }
   11188             :             | SAVEPOINT ColId
   11189             :                 {
   11190        1920 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11191             : 
   11192        1920 :                     n->kind = TRANS_STMT_SAVEPOINT;
   11193        1920 :                     n->savepoint_name = $2;
   11194        1920 :                     n->location = @2;
   11195        1920 :                     $$ = (Node *) n;
   11196             :                 }
   11197             :             | RELEASE SAVEPOINT ColId
   11198             :                 {
   11199         208 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11200             : 
   11201         208 :                     n->kind = TRANS_STMT_RELEASE;
   11202         208 :                     n->savepoint_name = $3;
   11203         208 :                     n->location = @3;
   11204         208 :                     $$ = (Node *) n;
   11205             :                 }
   11206             :             | RELEASE ColId
   11207             :                 {
   11208          86 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11209             : 
   11210          86 :                     n->kind = TRANS_STMT_RELEASE;
   11211          86 :                     n->savepoint_name = $2;
   11212          86 :                     n->location = @2;
   11213          86 :                     $$ = (Node *) n;
   11214             :                 }
   11215             :             | ROLLBACK opt_transaction TO SAVEPOINT ColId
   11216             :                 {
   11217         228 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11218             : 
   11219         228 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   11220         228 :                     n->savepoint_name = $5;
   11221         228 :                     n->location = @5;
   11222         228 :                     $$ = (Node *) n;
   11223             :                 }
   11224             :             | ROLLBACK opt_transaction TO ColId
   11225             :                 {
   11226         496 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11227             : 
   11228         496 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   11229         496 :                     n->savepoint_name = $4;
   11230         496 :                     n->location = @4;
   11231         496 :                     $$ = (Node *) n;
   11232             :                 }
   11233             :             | PREPARE TRANSACTION Sconst
   11234             :                 {
   11235         622 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11236             : 
   11237         622 :                     n->kind = TRANS_STMT_PREPARE;
   11238         622 :                     n->gid = $3;
   11239         622 :                     n->location = @3;
   11240         622 :                     $$ = (Node *) n;
   11241             :                 }
   11242             :             | COMMIT PREPARED Sconst
   11243             :                 {
   11244         472 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11245             : 
   11246         472 :                     n->kind = TRANS_STMT_COMMIT_PREPARED;
   11247         472 :                     n->gid = $3;
   11248         472 :                     n->location = @3;
   11249         472 :                     $$ = (Node *) n;
   11250             :                 }
   11251             :             | ROLLBACK PREPARED Sconst
   11252             :                 {
   11253          72 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11254             : 
   11255          72 :                     n->kind = TRANS_STMT_ROLLBACK_PREPARED;
   11256          72 :                     n->gid = $3;
   11257          72 :                     n->location = @3;
   11258          72 :                     $$ = (Node *) n;
   11259             :                 }
   11260             :         ;
   11261             : 
   11262             : TransactionStmtLegacy:
   11263             :             BEGIN_P opt_transaction transaction_mode_list_or_empty
   11264             :                 {
   11265       15710 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11266             : 
   11267       15710 :                     n->kind = TRANS_STMT_BEGIN;
   11268       15710 :                     n->options = $3;
   11269       15710 :                     n->location = -1;
   11270       15710 :                     $$ = (Node *) n;
   11271             :                 }
   11272             :             | END_P opt_transaction opt_transaction_chain
   11273             :                 {
   11274         360 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11275             : 
   11276         360 :                     n->kind = TRANS_STMT_COMMIT;
   11277         360 :                     n->options = NIL;
   11278         360 :                     n->chain = $3;
   11279         360 :                     n->location = -1;
   11280         360 :                     $$ = (Node *) n;
   11281             :                 }
   11282             :         ;
   11283             : 
   11284             : opt_transaction:    WORK
   11285             :             | TRANSACTION
   11286             :             | /*EMPTY*/
   11287             :         ;
   11288             : 
   11289             : transaction_mode_item:
   11290             :             ISOLATION LEVEL iso_level
   11291        6780 :                     { $$ = makeDefElem("transaction_isolation",
   11292        6780 :                                        makeStringConst($3, @3), @1); }
   11293             :             | READ ONLY
   11294        1510 :                     { $$ = makeDefElem("transaction_read_only",
   11295        1510 :                                        makeIntConst(true, @1), @1); }
   11296             :             | READ WRITE
   11297          90 :                     { $$ = makeDefElem("transaction_read_only",
   11298          90 :                                        makeIntConst(false, @1), @1); }
   11299             :             | DEFERRABLE
   11300          44 :                     { $$ = makeDefElem("transaction_deferrable",
   11301             :                                        makeIntConst(true, @1), @1); }
   11302             :             | NOT DEFERRABLE
   11303          10 :                     { $$ = makeDefElem("transaction_deferrable",
   11304          10 :                                        makeIntConst(false, @1), @1); }
   11305             :         ;
   11306             : 
   11307             : /* Syntax with commas is SQL-spec, without commas is Postgres historical */
   11308             : transaction_mode_list:
   11309             :             transaction_mode_item
   11310        6996 :                     { $$ = list_make1($1); }
   11311             :             | transaction_mode_list ',' transaction_mode_item
   11312        1040 :                     { $$ = lappend($1, $3); }
   11313             :             | transaction_mode_list transaction_mode_item
   11314         398 :                     { $$ = lappend($1, $2); }
   11315             :         ;
   11316             : 
   11317             : transaction_mode_list_or_empty:
   11318             :             transaction_mode_list
   11319             :             | /* EMPTY */
   11320       11020 :                     { $$ = NIL; }
   11321             :         ;
   11322             : 
   11323             : opt_transaction_chain:
   11324         120 :             AND CHAIN       { $$ = true; }
   11325           2 :             | AND NO CHAIN  { $$ = false; }
   11326       16114 :             | /* EMPTY */   { $$ = false; }
   11327             :         ;
   11328             : 
   11329             : 
   11330             : /*****************************************************************************
   11331             :  *
   11332             :  *  QUERY:
   11333             :  *      CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
   11334             :  *          AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
   11335             :  *
   11336             :  *****************************************************************************/
   11337             : 
   11338             : ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11339             :                 AS SelectStmt opt_check_option
   11340             :                 {
   11341       16978 :                     ViewStmt   *n = makeNode(ViewStmt);
   11342             : 
   11343       16978 :                     n->view = $4;
   11344       16978 :                     n->view->relpersistence = $2;
   11345       16978 :                     n->aliases = $5;
   11346       16978 :                     n->query = $8;
   11347       16978 :                     n->replace = false;
   11348       16978 :                     n->options = $6;
   11349       16978 :                     n->withCheckOption = $9;
   11350       16978 :                     $$ = (Node *) n;
   11351             :                 }
   11352             :         | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11353             :                 AS SelectStmt opt_check_option
   11354             :                 {
   11355         248 :                     ViewStmt   *n = makeNode(ViewStmt);
   11356             : 
   11357         248 :                     n->view = $6;
   11358         248 :                     n->view->relpersistence = $4;
   11359         248 :                     n->aliases = $7;
   11360         248 :                     n->query = $10;
   11361         248 :                     n->replace = true;
   11362         248 :                     n->options = $8;
   11363         248 :                     n->withCheckOption = $11;
   11364         248 :                     $$ = (Node *) n;
   11365             :                 }
   11366             :         | CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11367             :                 AS SelectStmt opt_check_option
   11368             :                 {
   11369           8 :                     ViewStmt   *n = makeNode(ViewStmt);
   11370             : 
   11371           8 :                     n->view = $5;
   11372           8 :                     n->view->relpersistence = $2;
   11373           8 :                     n->aliases = $7;
   11374           8 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
   11375           8 :                     n->replace = false;
   11376           8 :                     n->options = $9;
   11377           8 :                     n->withCheckOption = $12;
   11378           8 :                     if (n->withCheckOption != NO_CHECK_OPTION)
   11379           0 :                         ereport(ERROR,
   11380             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   11381             :                                  errmsg("WITH CHECK OPTION not supported on recursive views"),
   11382             :                                  parser_errposition(@12)));
   11383           8 :                     $$ = (Node *) n;
   11384             :                 }
   11385             :         | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11386             :                 AS SelectStmt opt_check_option
   11387             :                 {
   11388           6 :                     ViewStmt   *n = makeNode(ViewStmt);
   11389             : 
   11390           6 :                     n->view = $7;
   11391           6 :                     n->view->relpersistence = $4;
   11392           6 :                     n->aliases = $9;
   11393           6 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
   11394           6 :                     n->replace = true;
   11395           6 :                     n->options = $11;
   11396           6 :                     n->withCheckOption = $14;
   11397           6 :                     if (n->withCheckOption != NO_CHECK_OPTION)
   11398           0 :                         ereport(ERROR,
   11399             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   11400             :                                  errmsg("WITH CHECK OPTION not supported on recursive views"),
   11401             :                                  parser_errposition(@14)));
   11402           6 :                     $$ = (Node *) n;
   11403             :                 }
   11404             :         ;
   11405             : 
   11406             : opt_check_option:
   11407          96 :         WITH CHECK OPTION               { $$ = CASCADED_CHECK_OPTION; }
   11408           6 :         | WITH CASCADED CHECK OPTION    { $$ = CASCADED_CHECK_OPTION; }
   11409          24 :         | WITH LOCAL CHECK OPTION       { $$ = LOCAL_CHECK_OPTION; }
   11410       17114 :         | /* EMPTY */                   { $$ = NO_CHECK_OPTION; }
   11411             :         ;
   11412             : 
   11413             : /*****************************************************************************
   11414             :  *
   11415             :  *      QUERY:
   11416             :  *              LOAD "filename"
   11417             :  *
   11418             :  *****************************************************************************/
   11419             : 
   11420             : LoadStmt:   LOAD file_name
   11421             :                 {
   11422          52 :                     LoadStmt   *n = makeNode(LoadStmt);
   11423             : 
   11424          52 :                     n->filename = $2;
   11425          52 :                     $$ = (Node *) n;
   11426             :                 }
   11427             :         ;
   11428             : 
   11429             : 
   11430             : /*****************************************************************************
   11431             :  *
   11432             :  *      CREATE DATABASE
   11433             :  *
   11434             :  *****************************************************************************/
   11435             : 
   11436             : CreatedbStmt:
   11437             :             CREATE DATABASE name opt_with createdb_opt_list
   11438             :                 {
   11439         788 :                     CreatedbStmt *n = makeNode(CreatedbStmt);
   11440             : 
   11441         788 :                     n->dbname = $3;
   11442         788 :                     n->options = $5;
   11443         788 :                     $$ = (Node *) n;
   11444             :                 }
   11445             :         ;
   11446             : 
   11447             : createdb_opt_list:
   11448         632 :             createdb_opt_items                      { $$ = $1; }
   11449         216 :             | /* EMPTY */                           { $$ = NIL; }
   11450             :         ;
   11451             : 
   11452             : createdb_opt_items:
   11453         632 :             createdb_opt_item                       { $$ = list_make1($1); }
   11454         940 :             | createdb_opt_items createdb_opt_item  { $$ = lappend($1, $2); }
   11455             :         ;
   11456             : 
   11457             : createdb_opt_item:
   11458             :             createdb_opt_name opt_equal NumericOnly
   11459             :                 {
   11460         262 :                     $$ = makeDefElem($1, $3, @1);
   11461             :                 }
   11462             :             | createdb_opt_name opt_equal opt_boolean_or_string
   11463             :                 {
   11464        1310 :                     $$ = makeDefElem($1, (Node *) makeString($3), @1);
   11465             :                 }
   11466             :             | createdb_opt_name opt_equal DEFAULT
   11467             :                 {
   11468           0 :                     $$ = makeDefElem($1, NULL, @1);
   11469             :                 }
   11470             :         ;
   11471             : 
   11472             : /*
   11473             :  * Ideally we'd use ColId here, but that causes shift/reduce conflicts against
   11474             :  * the ALTER DATABASE SET/RESET syntaxes.  Instead call out specific keywords
   11475             :  * we need, and allow IDENT so that database option names don't have to be
   11476             :  * parser keywords unless they are already keywords for other reasons.
   11477             :  *
   11478             :  * XXX this coding technique is fragile since if someone makes a formerly
   11479             :  * non-keyword option name into a keyword and forgets to add it here, the
   11480             :  * option will silently break.  Best defense is to provide a regression test
   11481             :  * exercising every such option, at least at the syntax level.
   11482             :  */
   11483             : createdb_opt_name:
   11484        1114 :             IDENT                           { $$ = $1; }
   11485           2 :             | CONNECTION LIMIT              { $$ = pstrdup("connection_limit"); }
   11486          96 :             | ENCODING                      { $$ = pstrdup($1); }
   11487           0 :             | LOCATION                      { $$ = pstrdup($1); }
   11488           2 :             | OWNER                         { $$ = pstrdup($1); }
   11489          16 :             | TABLESPACE                    { $$ = pstrdup($1); }
   11490         342 :             | TEMPLATE                      { $$ = pstrdup($1); }
   11491             :         ;
   11492             : 
   11493             : /*
   11494             :  *  Though the equals sign doesn't match other WITH options, pg_dump uses
   11495             :  *  equals for backward compatibility, and it doesn't seem worth removing it.
   11496             :  */
   11497             : opt_equal:  '='
   11498             :             | /*EMPTY*/
   11499             :         ;
   11500             : 
   11501             : 
   11502             : /*****************************************************************************
   11503             :  *
   11504             :  *      ALTER DATABASE
   11505             :  *
   11506             :  *****************************************************************************/
   11507             : 
   11508             : AlterDatabaseStmt:
   11509             :             ALTER DATABASE name WITH createdb_opt_list
   11510             :                  {
   11511           0 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11512             : 
   11513           0 :                     n->dbname = $3;
   11514           0 :                     n->options = $5;
   11515           0 :                     $$ = (Node *) n;
   11516             :                  }
   11517             :             | ALTER DATABASE name createdb_opt_list
   11518             :                  {
   11519          60 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11520             : 
   11521          60 :                     n->dbname = $3;
   11522          60 :                     n->options = $4;
   11523          60 :                     $$ = (Node *) n;
   11524             :                  }
   11525             :             | ALTER DATABASE name SET TABLESPACE name
   11526             :                  {
   11527          16 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11528             : 
   11529          16 :                     n->dbname = $3;
   11530          16 :                     n->options = list_make1(makeDefElem("tablespace",
   11531             :                                                         (Node *) makeString($6), @6));
   11532          16 :                     $$ = (Node *) n;
   11533             :                  }
   11534             :             | ALTER DATABASE name REFRESH COLLATION VERSION_P
   11535             :                  {
   11536           6 :                     AlterDatabaseRefreshCollStmt *n = makeNode(AlterDatabaseRefreshCollStmt);
   11537             : 
   11538           6 :                     n->dbname = $3;
   11539           6 :                     $$ = (Node *) n;
   11540             :                  }
   11541             :         ;
   11542             : 
   11543             : AlterDatabaseSetStmt:
   11544             :             ALTER DATABASE name SetResetClause
   11545             :                 {
   11546        1198 :                     AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
   11547             : 
   11548        1198 :                     n->dbname = $3;
   11549        1198 :                     n->setstmt = $4;
   11550        1198 :                     $$ = (Node *) n;
   11551             :                 }
   11552             :         ;
   11553             : 
   11554             : 
   11555             : /*****************************************************************************
   11556             :  *
   11557             :  *      DROP DATABASE [ IF EXISTS ] dbname [ [ WITH ] ( options ) ]
   11558             :  *
   11559             :  * This is implicitly CASCADE, no need for drop behavior
   11560             :  *****************************************************************************/
   11561             : 
   11562             : DropdbStmt: DROP DATABASE name
   11563             :                 {
   11564          92 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11565             : 
   11566          92 :                     n->dbname = $3;
   11567          92 :                     n->missing_ok = false;
   11568          92 :                     n->options = NULL;
   11569          92 :                     $$ = (Node *) n;
   11570             :                 }
   11571             :             | DROP DATABASE IF_P EXISTS name
   11572             :                 {
   11573           4 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11574             : 
   11575           4 :                     n->dbname = $5;
   11576           4 :                     n->missing_ok = true;
   11577           4 :                     n->options = NULL;
   11578           4 :                     $$ = (Node *) n;
   11579             :                 }
   11580             :             | DROP DATABASE name opt_with '(' drop_option_list ')'
   11581             :                 {
   11582          14 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11583             : 
   11584          14 :                     n->dbname = $3;
   11585          14 :                     n->missing_ok = false;
   11586          14 :                     n->options = $6;
   11587          14 :                     $$ = (Node *) n;
   11588             :                 }
   11589             :             | DROP DATABASE IF_P EXISTS name opt_with '(' drop_option_list ')'
   11590             :                 {
   11591          12 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11592             : 
   11593          12 :                     n->dbname = $5;
   11594          12 :                     n->missing_ok = true;
   11595          12 :                     n->options = $8;
   11596          12 :                     $$ = (Node *) n;
   11597             :                 }
   11598             :         ;
   11599             : 
   11600             : drop_option_list:
   11601             :             drop_option
   11602             :                 {
   11603          26 :                     $$ = list_make1((Node *) $1);
   11604             :                 }
   11605             :             | drop_option_list ',' drop_option
   11606             :                 {
   11607           0 :                     $$ = lappend($1, (Node *) $3);
   11608             :                 }
   11609             :         ;
   11610             : 
   11611             : /*
   11612             :  * Currently only the FORCE option is supported, but the syntax is designed
   11613             :  * to be extensible so that we can add more options in the future if required.
   11614             :  */
   11615             : drop_option:
   11616             :             FORCE
   11617             :                 {
   11618          26 :                     $$ = makeDefElem("force", NULL, @1);
   11619             :                 }
   11620             :         ;
   11621             : 
   11622             : /*****************************************************************************
   11623             :  *
   11624             :  *      ALTER COLLATION
   11625             :  *
   11626             :  *****************************************************************************/
   11627             : 
   11628             : AlterCollationStmt: ALTER COLLATION any_name REFRESH VERSION_P
   11629             :                 {
   11630           6 :                     AlterCollationStmt *n = makeNode(AlterCollationStmt);
   11631             : 
   11632           6 :                     n->collname = $3;
   11633           6 :                     $$ = (Node *) n;
   11634             :                 }
   11635             :         ;
   11636             : 
   11637             : 
   11638             : /*****************************************************************************
   11639             :  *
   11640             :  *      ALTER SYSTEM
   11641             :  *
   11642             :  * This is used to change configuration parameters persistently.
   11643             :  *****************************************************************************/
   11644             : 
   11645             : AlterSystemStmt:
   11646             :             ALTER SYSTEM_P SET generic_set
   11647             :                 {
   11648         128 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11649             : 
   11650         128 :                     n->setstmt = $4;
   11651         128 :                     $$ = (Node *) n;
   11652             :                 }
   11653             :             | ALTER SYSTEM_P RESET generic_reset
   11654             :                 {
   11655          54 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11656             : 
   11657          54 :                     n->setstmt = $4;
   11658          54 :                     $$ = (Node *) n;
   11659             :                 }
   11660             :         ;
   11661             : 
   11662             : 
   11663             : /*****************************************************************************
   11664             :  *
   11665             :  * Manipulate a domain
   11666             :  *
   11667             :  *****************************************************************************/
   11668             : 
   11669             : CreateDomainStmt:
   11670             :             CREATE DOMAIN_P any_name opt_as Typename ColQualList
   11671             :                 {
   11672        1500 :                     CreateDomainStmt *n = makeNode(CreateDomainStmt);
   11673             : 
   11674        1500 :                     n->domainname = $3;
   11675        1500 :                     n->typeName = $5;
   11676        1500 :                     SplitColQualList($6, &n->constraints, &n->collClause,
   11677             :                                      yyscanner);
   11678        1500 :                     $$ = (Node *) n;
   11679             :                 }
   11680             :         ;
   11681             : 
   11682             : AlterDomainStmt:
   11683             :             /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
   11684             :             ALTER DOMAIN_P any_name alter_column_default
   11685             :                 {
   11686          14 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11687             : 
   11688          14 :                     n->subtype = AD_AlterDefault;
   11689          14 :                     n->typeName = $3;
   11690          14 :                     n->def = $4;
   11691          14 :                     $$ = (Node *) n;
   11692             :                 }
   11693             :             /* ALTER DOMAIN <domain> DROP NOT NULL */
   11694             :             | ALTER DOMAIN_P any_name DROP NOT NULL_P
   11695             :                 {
   11696          12 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11697             : 
   11698          12 :                     n->subtype = AD_DropNotNull;
   11699          12 :                     n->typeName = $3;
   11700          12 :                     $$ = (Node *) n;
   11701             :                 }
   11702             :             /* ALTER DOMAIN <domain> SET NOT NULL */
   11703             :             | ALTER DOMAIN_P any_name SET NOT NULL_P
   11704             :                 {
   11705          24 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11706             : 
   11707          24 :                     n->subtype = AD_SetNotNull;
   11708          24 :                     n->typeName = $3;
   11709          24 :                     $$ = (Node *) n;
   11710             :                 }
   11711             :             /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
   11712             :             | ALTER DOMAIN_P any_name ADD_P DomainConstraint
   11713             :                 {
   11714         174 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11715             : 
   11716         174 :                     n->subtype = AD_AddConstraint;
   11717         174 :                     n->typeName = $3;
   11718         174 :                     n->def = $5;
   11719         174 :                     $$ = (Node *) n;
   11720             :                 }
   11721             :             /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
   11722             :             | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
   11723             :                 {
   11724          54 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11725             : 
   11726          54 :                     n->subtype = AD_DropConstraint;
   11727          54 :                     n->typeName = $3;
   11728          54 :                     n->name = $6;
   11729          54 :                     n->behavior = $7;
   11730          54 :                     n->missing_ok = false;
   11731          54 :                     $$ = (Node *) n;
   11732             :                 }
   11733             :             /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
   11734             :             | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
   11735             :                 {
   11736           6 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11737             : 
   11738           6 :                     n->subtype = AD_DropConstraint;
   11739           6 :                     n->typeName = $3;
   11740           6 :                     n->name = $8;
   11741           6 :                     n->behavior = $9;
   11742           6 :                     n->missing_ok = true;
   11743           6 :                     $$ = (Node *) n;
   11744             :                 }
   11745             :             /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
   11746             :             | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
   11747             :                 {
   11748          12 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11749             : 
   11750          12 :                     n->subtype = AD_ValidateConstraint;
   11751          12 :                     n->typeName = $3;
   11752          12 :                     n->name = $6;
   11753          12 :                     $$ = (Node *) n;
   11754             :                 }
   11755             :             ;
   11756             : 
   11757             : opt_as:     AS
   11758             :             | /* EMPTY */
   11759             :         ;
   11760             : 
   11761             : 
   11762             : /*****************************************************************************
   11763             :  *
   11764             :  * Manipulate a text search dictionary or configuration
   11765             :  *
   11766             :  *****************************************************************************/
   11767             : 
   11768             : AlterTSDictionaryStmt:
   11769             :             ALTER TEXT_P SEARCH DICTIONARY any_name definition
   11770             :                 {
   11771          40 :                     AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
   11772             : 
   11773          40 :                     n->dictname = $5;
   11774          40 :                     n->options = $6;
   11775          40 :                     $$ = (Node *) n;
   11776             :                 }
   11777             :         ;
   11778             : 
   11779             : AlterTSConfigurationStmt:
   11780             :             ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
   11781             :                 {
   11782        8844 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11783             : 
   11784        8844 :                     n->kind = ALTER_TSCONFIG_ADD_MAPPING;
   11785        8844 :                     n->cfgname = $5;
   11786        8844 :                     n->tokentype = $9;
   11787        8844 :                     n->dicts = $11;
   11788        8844 :                     n->override = false;
   11789        8844 :                     n->replace = false;
   11790        8844 :                     $$ = (Node *) n;
   11791             :                 }
   11792             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
   11793             :                 {
   11794          26 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11795             : 
   11796          26 :                     n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
   11797          26 :                     n->cfgname = $5;
   11798          26 :                     n->tokentype = $9;
   11799          26 :                     n->dicts = $11;
   11800          26 :                     n->override = true;
   11801          26 :                     n->replace = false;
   11802          26 :                     $$ = (Node *) n;
   11803             :                 }
   11804             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
   11805             :                 {
   11806          18 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11807             : 
   11808          18 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT;
   11809          18 :                     n->cfgname = $5;
   11810          18 :                     n->tokentype = NIL;
   11811          18 :                     n->dicts = list_make2($9,$11);
   11812          18 :                     n->override = false;
   11813          18 :                     n->replace = true;
   11814          18 :                     $$ = (Node *) n;
   11815             :                 }
   11816             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
   11817             :                 {
   11818           0 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11819             : 
   11820           0 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN;
   11821           0 :                     n->cfgname = $5;
   11822           0 :                     n->tokentype = $9;
   11823           0 :                     n->dicts = list_make2($11,$13);
   11824           0 :                     n->override = false;
   11825           0 :                     n->replace = true;
   11826           0 :                     $$ = (Node *) n;
   11827             :                 }
   11828             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
   11829             :                 {
   11830          18 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11831             : 
   11832          18 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   11833          18 :                     n->cfgname = $5;
   11834          18 :                     n->tokentype = $9;
   11835          18 :                     n->missing_ok = false;
   11836          18 :                     $$ = (Node *) n;
   11837             :                 }
   11838             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
   11839             :                 {
   11840          12 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11841             : 
   11842          12 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   11843          12 :                     n->cfgname = $5;
   11844          12 :                     n->tokentype = $11;
   11845          12 :                     n->missing_ok = true;
   11846          12 :                     $$ = (Node *) n;
   11847             :                 }
   11848             :         ;
   11849             : 
   11850             : /* Use this if TIME or ORDINALITY after WITH should be taken as an identifier */
   11851             : any_with:   WITH
   11852             :             | WITH_LA
   11853             :         ;
   11854             : 
   11855             : 
   11856             : /*****************************************************************************
   11857             :  *
   11858             :  * Manipulate a conversion
   11859             :  *
   11860             :  *      CREATE [DEFAULT] CONVERSION <conversion_name>
   11861             :  *      FOR <encoding_name> TO <encoding_name> FROM <func_name>
   11862             :  *
   11863             :  *****************************************************************************/
   11864             : 
   11865             : CreateConversionStmt:
   11866             :             CREATE opt_default CONVERSION_P any_name FOR Sconst
   11867             :             TO Sconst FROM any_name
   11868             :             {
   11869          64 :                 CreateConversionStmt *n = makeNode(CreateConversionStmt);
   11870             : 
   11871          64 :                 n->conversion_name = $4;
   11872          64 :                 n->for_encoding_name = $6;
   11873          64 :                 n->to_encoding_name = $8;
   11874          64 :                 n->func_name = $10;
   11875          64 :                 n->def = $2;
   11876          64 :                 $$ = (Node *) n;
   11877             :             }
   11878             :         ;
   11879             : 
   11880             : /*****************************************************************************
   11881             :  *
   11882             :  *      QUERY:
   11883             :  *              CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
   11884             :  *              CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
   11885             :  *              CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
   11886             :  *
   11887             :  *****************************************************************************/
   11888             : 
   11889             : ClusterStmt:
   11890             :             CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
   11891             :                 {
   11892           0 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11893             : 
   11894           0 :                     n->relation = $5;
   11895           0 :                     n->indexname = $6;
   11896           0 :                     n->params = $3;
   11897           0 :                     $$ = (Node *) n;
   11898             :                 }
   11899             :             | CLUSTER '(' utility_option_list ')'
   11900             :                 {
   11901           0 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11902             : 
   11903           0 :                     n->relation = NULL;
   11904           0 :                     n->indexname = NULL;
   11905           0 :                     n->params = $3;
   11906           0 :                     $$ = (Node *) n;
   11907             :                 }
   11908             :             /* unparenthesized VERBOSE kept for pre-14 compatibility */
   11909             :             | CLUSTER opt_verbose qualified_name cluster_index_specification
   11910             :                 {
   11911         188 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11912             : 
   11913         188 :                     n->relation = $3;
   11914         188 :                     n->indexname = $4;
   11915         188 :                     n->params = NIL;
   11916         188 :                     if ($2)
   11917           0 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11918         188 :                     $$ = (Node *) n;
   11919             :                 }
   11920             :             /* unparenthesized VERBOSE kept for pre-17 compatibility */
   11921             :             | CLUSTER opt_verbose
   11922             :                 {
   11923          22 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11924             : 
   11925          22 :                     n->relation = NULL;
   11926          22 :                     n->indexname = NULL;
   11927          22 :                     n->params = NIL;
   11928          22 :                     if ($2)
   11929           6 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11930          22 :                     $$ = (Node *) n;
   11931             :                 }
   11932             :             /* kept for pre-8.3 compatibility */
   11933             :             | CLUSTER opt_verbose name ON qualified_name
   11934             :                 {
   11935          18 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11936             : 
   11937          18 :                     n->relation = $5;
   11938          18 :                     n->indexname = $3;
   11939          18 :                     n->params = NIL;
   11940          18 :                     if ($2)
   11941           0 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11942          18 :                     $$ = (Node *) n;
   11943             :                 }
   11944             :         ;
   11945             : 
   11946             : cluster_index_specification:
   11947         156 :             USING name              { $$ = $2; }
   11948          32 :             | /*EMPTY*/             { $$ = NULL; }
   11949             :         ;
   11950             : 
   11951             : 
   11952             : /*****************************************************************************
   11953             :  *
   11954             :  *      QUERY:
   11955             :  *              VACUUM
   11956             :  *              ANALYZE
   11957             :  *
   11958             :  *****************************************************************************/
   11959             : 
   11960             : VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relation_list
   11961             :                 {
   11962        1232 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11963             : 
   11964        1232 :                     n->options = NIL;
   11965        1232 :                     if ($2)
   11966         146 :                         n->options = lappend(n->options,
   11967         146 :                                              makeDefElem("full", NULL, @2));
   11968        1232 :                     if ($3)
   11969         164 :                         n->options = lappend(n->options,
   11970         164 :                                              makeDefElem("freeze", NULL, @3));
   11971        1232 :                     if ($4)
   11972          18 :                         n->options = lappend(n->options,
   11973          18 :                                              makeDefElem("verbose", NULL, @4));
   11974        1232 :                     if ($5)
   11975         292 :                         n->options = lappend(n->options,
   11976         292 :                                              makeDefElem("analyze", NULL, @5));
   11977        1232 :                     n->rels = $6;
   11978        1232 :                     n->is_vacuumcmd = true;
   11979        1232 :                     $$ = (Node *) n;
   11980             :                 }
   11981             :             | VACUUM '(' utility_option_list ')' opt_vacuum_relation_list
   11982             :                 {
   11983        7644 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11984             : 
   11985        7644 :                     n->options = $3;
   11986        7644 :                     n->rels = $5;
   11987        7644 :                     n->is_vacuumcmd = true;
   11988        7644 :                     $$ = (Node *) n;
   11989             :                 }
   11990             :         ;
   11991             : 
   11992             : AnalyzeStmt: analyze_keyword opt_verbose opt_vacuum_relation_list
   11993             :                 {
   11994        4496 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11995             : 
   11996        4496 :                     n->options = NIL;
   11997        4496 :                     if ($2)
   11998           0 :                         n->options = lappend(n->options,
   11999           0 :                                              makeDefElem("verbose", NULL, @2));
   12000        4496 :                     n->rels = $3;
   12001        4496 :                     n->is_vacuumcmd = false;
   12002        4496 :                     $$ = (Node *) n;
   12003             :                 }
   12004             :             | analyze_keyword '(' utility_option_list ')' opt_vacuum_relation_list
   12005             :                 {
   12006         186 :                     VacuumStmt *n = makeNode(VacuumStmt);
   12007             : 
   12008         186 :                     n->options = $3;
   12009         186 :                     n->rels = $5;
   12010         186 :                     n->is_vacuumcmd = false;
   12011         186 :                     $$ = (Node *) n;
   12012             :                 }
   12013             :         ;
   12014             : 
   12015             : utility_option_list:
   12016             :             utility_option_elem
   12017             :                 {
   12018       21872 :                     $$ = list_make1($1);
   12019             :                 }
   12020             :             | utility_option_list ',' utility_option_elem
   12021             :                 {
   12022       12366 :                     $$ = lappend($1, $3);
   12023             :                 }
   12024             :         ;
   12025             : 
   12026             : analyze_keyword:
   12027             :             ANALYZE
   12028             :             | ANALYSE /* British */
   12029             :         ;
   12030             : 
   12031             : utility_option_elem:
   12032             :             utility_option_name utility_option_arg
   12033             :                 {
   12034       34238 :                     $$ = makeDefElem($1, $2, @1);
   12035             :                 }
   12036             :         ;
   12037             : 
   12038             : utility_option_name:
   12039       30488 :             NonReservedWord                         { $$ = $1; }
   12040        3608 :             | analyze_keyword                       { $$ = "analyze"; }
   12041         148 :             | FORMAT_LA                             { $$ = "format"; }
   12042             :         ;
   12043             : 
   12044             : utility_option_arg:
   12045       17374 :             opt_boolean_or_string                   { $$ = (Node *) makeString($1); }
   12046         382 :             | NumericOnly                           { $$ = (Node *) $1; }
   12047       16482 :             | /* EMPTY */                           { $$ = NULL; }
   12048             :         ;
   12049             : 
   12050             : opt_analyze:
   12051         292 :             analyze_keyword                         { $$ = true; }
   12052         940 :             | /*EMPTY*/                             { $$ = false; }
   12053             :         ;
   12054             : 
   12055             : opt_verbose:
   12056          24 :             VERBOSE                                 { $$ = true; }
   12057        8236 :             | /*EMPTY*/                             { $$ = false; }
   12058             :         ;
   12059             : 
   12060         146 : opt_full:   FULL                                    { $$ = true; }
   12061        1086 :             | /*EMPTY*/                             { $$ = false; }
   12062             :         ;
   12063             : 
   12064         164 : opt_freeze: FREEZE                                  { $$ = true; }
   12065        1068 :             | /*EMPTY*/                             { $$ = false; }
   12066             :         ;
   12067             : 
   12068             : opt_name_list:
   12069        2784 :             '(' name_list ')'                       { $$ = $2; }
   12070       15822 :             | /*EMPTY*/                             { $$ = NIL; }
   12071             :         ;
   12072             : 
   12073             : vacuum_relation:
   12074             :             relation_expr opt_name_list
   12075             :                 {
   12076       13328 :                     $$ = (Node *) makeVacuumRelation($1, InvalidOid, $2);
   12077             :                 }
   12078             :         ;
   12079             : 
   12080             : vacuum_relation_list:
   12081             :             vacuum_relation
   12082       13170 :                     { $$ = list_make1($1); }
   12083             :             | vacuum_relation_list ',' vacuum_relation
   12084         158 :                     { $$ = lappend($1, $3); }
   12085             :         ;
   12086             : 
   12087             : opt_vacuum_relation_list:
   12088       13170 :             vacuum_relation_list                    { $$ = $1; }
   12089         388 :             | /*EMPTY*/                             { $$ = NIL; }
   12090             :         ;
   12091             : 
   12092             : 
   12093             : /*****************************************************************************
   12094             :  *
   12095             :  *      QUERY:
   12096             :  *              EXPLAIN [ANALYZE] [VERBOSE] query
   12097             :  *              EXPLAIN ( options ) query
   12098             :  *
   12099             :  *****************************************************************************/
   12100             : 
   12101             : ExplainStmt:
   12102             :         EXPLAIN ExplainableStmt
   12103             :                 {
   12104        7714 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12105             : 
   12106        7714 :                     n->query = $2;
   12107        7714 :                     n->options = NIL;
   12108        7714 :                     $$ = (Node *) n;
   12109             :                 }
   12110             :         | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
   12111             :                 {
   12112        2304 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12113             : 
   12114        2304 :                     n->query = $4;
   12115        2304 :                     n->options = list_make1(makeDefElem("analyze", NULL, @2));
   12116        2304 :                     if ($3)
   12117           0 :                         n->options = lappend(n->options,
   12118           0 :                                              makeDefElem("verbose", NULL, @3));
   12119        2304 :                     $$ = (Node *) n;
   12120             :                 }
   12121             :         | EXPLAIN VERBOSE ExplainableStmt
   12122             :                 {
   12123          12 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12124             : 
   12125          12 :                     n->query = $3;
   12126          12 :                     n->options = list_make1(makeDefElem("verbose", NULL, @2));
   12127          12 :                     $$ = (Node *) n;
   12128             :                 }
   12129             :         | EXPLAIN '(' utility_option_list ')' ExplainableStmt
   12130             :                 {
   12131       13886 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12132             : 
   12133       13886 :                     n->query = $5;
   12134       13886 :                     n->options = $3;
   12135       13886 :                     $$ = (Node *) n;
   12136             :                 }
   12137             :         ;
   12138             : 
   12139             : ExplainableStmt:
   12140             :             SelectStmt
   12141             :             | InsertStmt
   12142             :             | UpdateStmt
   12143             :             | DeleteStmt
   12144             :             | MergeStmt
   12145             :             | DeclareCursorStmt
   12146             :             | CreateAsStmt
   12147             :             | CreateMatViewStmt
   12148             :             | RefreshMatViewStmt
   12149             :             | ExecuteStmt                   /* by default all are $$=$1 */
   12150             :         ;
   12151             : 
   12152             : /*****************************************************************************
   12153             :  *
   12154             :  *      QUERY:
   12155             :  *              PREPARE <plan_name> [(args, ...)] AS <query>
   12156             :  *
   12157             :  *****************************************************************************/
   12158             : 
   12159             : PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
   12160             :                 {
   12161        2140 :                     PrepareStmt *n = makeNode(PrepareStmt);
   12162             : 
   12163        2140 :                     n->name = $2;
   12164        2140 :                     n->argtypes = $3;
   12165        2140 :                     n->query = $5;
   12166        2140 :                     $$ = (Node *) n;
   12167             :                 }
   12168             :         ;
   12169             : 
   12170        1832 : prep_type_clause: '(' type_list ')'         { $$ = $2; }
   12171         326 :                 | /* EMPTY */               { $$ = NIL; }
   12172             :         ;
   12173             : 
   12174             : PreparableStmt:
   12175             :             SelectStmt
   12176             :             | InsertStmt
   12177             :             | UpdateStmt
   12178             :             | DeleteStmt
   12179             :             | MergeStmt                     /* by default all are $$=$1 */
   12180             :         ;
   12181             : 
   12182             : /*****************************************************************************
   12183             :  *
   12184             :  * EXECUTE <plan_name> [(params, ...)]
   12185             :  * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
   12186             :  *
   12187             :  *****************************************************************************/
   12188             : 
   12189             : ExecuteStmt: EXECUTE name execute_param_clause
   12190             :                 {
   12191       19952 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12192             : 
   12193       19952 :                     n->name = $2;
   12194       19952 :                     n->params = $3;
   12195       19952 :                     $$ = (Node *) n;
   12196             :                 }
   12197             :             | CREATE OptTemp TABLE create_as_target AS
   12198             :                 EXECUTE name execute_param_clause opt_with_data
   12199             :                 {
   12200          76 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   12201          76 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12202             : 
   12203          76 :                     n->name = $7;
   12204          76 :                     n->params = $8;
   12205          76 :                     ctas->query = (Node *) n;
   12206          76 :                     ctas->into = $4;
   12207          76 :                     ctas->objtype = OBJECT_TABLE;
   12208          76 :                     ctas->is_select_into = false;
   12209          76 :                     ctas->if_not_exists = false;
   12210             :                     /* cram additional flags into the IntoClause */
   12211          76 :                     $4->rel->relpersistence = $2;
   12212          76 :                     $4->skipData = !($9);
   12213          76 :                     $$ = (Node *) ctas;
   12214             :                 }
   12215             :             | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS
   12216             :                 EXECUTE name execute_param_clause opt_with_data
   12217             :                 {
   12218          12 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   12219          12 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12220             : 
   12221          12 :                     n->name = $10;
   12222          12 :                     n->params = $11;
   12223          12 :                     ctas->query = (Node *) n;
   12224          12 :                     ctas->into = $7;
   12225          12 :                     ctas->objtype = OBJECT_TABLE;
   12226          12 :                     ctas->is_select_into = false;
   12227          12 :                     ctas->if_not_exists = true;
   12228             :                     /* cram additional flags into the IntoClause */
   12229          12 :                     $7->rel->relpersistence = $2;
   12230          12 :                     $7->skipData = !($12);
   12231          12 :                     $$ = (Node *) ctas;
   12232             :                 }
   12233             :         ;
   12234             : 
   12235       18898 : execute_param_clause: '(' expr_list ')'             { $$ = $2; }
   12236        1142 :                     | /* EMPTY */                   { $$ = NIL; }
   12237             :                     ;
   12238             : 
   12239             : /*****************************************************************************
   12240             :  *
   12241             :  *      QUERY:
   12242             :  *              DEALLOCATE [PREPARE] <plan_name>
   12243             :  *
   12244             :  *****************************************************************************/
   12245             : 
   12246             : DeallocateStmt: DEALLOCATE name
   12247             :                     {
   12248        3988 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12249             : 
   12250        3988 :                         n->name = $2;
   12251        3988 :                         n->isall = false;
   12252        3988 :                         n->location = @2;
   12253        3988 :                         $$ = (Node *) n;
   12254             :                     }
   12255             :                 | DEALLOCATE PREPARE name
   12256             :                     {
   12257          20 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12258             : 
   12259          20 :                         n->name = $3;
   12260          20 :                         n->isall = false;
   12261          20 :                         n->location = @3;
   12262          20 :                         $$ = (Node *) n;
   12263             :                     }
   12264             :                 | DEALLOCATE ALL
   12265             :                     {
   12266          54 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12267             : 
   12268          54 :                         n->name = NULL;
   12269          54 :                         n->isall = true;
   12270          54 :                         n->location = -1;
   12271          54 :                         $$ = (Node *) n;
   12272             :                     }
   12273             :                 | DEALLOCATE PREPARE ALL
   12274             :                     {
   12275           2 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12276             : 
   12277           2 :                         n->name = NULL;
   12278           2 :                         n->isall = true;
   12279           2 :                         n->location = -1;
   12280           2 :                         $$ = (Node *) n;
   12281             :                     }
   12282             :         ;
   12283             : 
   12284             : /*****************************************************************************
   12285             :  *
   12286             :  *      QUERY:
   12287             :  *              INSERT STATEMENTS
   12288             :  *
   12289             :  *****************************************************************************/
   12290             : 
   12291             : InsertStmt:
   12292             :             opt_with_clause INSERT INTO insert_target insert_rest
   12293             :             opt_on_conflict returning_clause
   12294             :                 {
   12295       68416 :                     $5->relation = $4;
   12296       68416 :                     $5->onConflictClause = $6;
   12297       68416 :                     $5->returningClause = $7;
   12298       68416 :                     $5->withClause = $1;
   12299       68416 :                     $$ = (Node *) $5;
   12300             :                 }
   12301             :         ;
   12302             : 
   12303             : /*
   12304             :  * Can't easily make AS optional here, because VALUES in insert_rest would
   12305             :  * have a shift/reduce conflict with VALUES as an optional alias.  We could
   12306             :  * easily allow unreserved_keywords as optional aliases, but that'd be an odd
   12307             :  * divergence from other places.  So just require AS for now.
   12308             :  */
   12309             : insert_target:
   12310             :             qualified_name
   12311             :                 {
   12312       68284 :                     $$ = $1;
   12313             :                 }
   12314             :             | qualified_name AS ColId
   12315             :                 {
   12316         138 :                     $1->alias = makeAlias($3, NIL);
   12317         138 :                     $$ = $1;
   12318             :                 }
   12319             :         ;
   12320             : 
   12321             : insert_rest:
   12322             :             SelectStmt
   12323             :                 {
   12324       43196 :                     $$ = makeNode(InsertStmt);
   12325       43196 :                     $$->cols = NIL;
   12326       43196 :                     $$->selectStmt = $1;
   12327             :                 }
   12328             :             | OVERRIDING override_kind VALUE_P SelectStmt
   12329             :                 {
   12330          96 :                     $$ = makeNode(InsertStmt);
   12331          96 :                     $$->cols = NIL;
   12332          96 :                     $$->override = $2;
   12333          96 :                     $$->selectStmt = $4;
   12334             :                 }
   12335             :             | '(' insert_column_list ')' SelectStmt
   12336             :                 {
   12337       14322 :                     $$ = makeNode(InsertStmt);
   12338       14322 :                     $$->cols = $2;
   12339       14322 :                     $$->selectStmt = $4;
   12340             :                 }
   12341             :             | '(' insert_column_list ')' OVERRIDING override_kind VALUE_P SelectStmt
   12342             :                 {
   12343           0 :                     $$ = makeNode(InsertStmt);
   12344           0 :                     $$->cols = $2;
   12345           0 :                     $$->override = $5;
   12346           0 :                     $$->selectStmt = $7;
   12347             :                 }
   12348             :             | DEFAULT VALUES
   12349             :                 {
   12350       10808 :                     $$ = makeNode(InsertStmt);
   12351       10808 :                     $$->cols = NIL;
   12352       10808 :                     $$->selectStmt = NULL;
   12353             :                 }
   12354             :         ;
   12355             : 
   12356             : override_kind:
   12357          66 :             USER        { $$ = OVERRIDING_USER_VALUE; }
   12358          60 :             | SYSTEM_P  { $$ = OVERRIDING_SYSTEM_VALUE; }
   12359             :         ;
   12360             : 
   12361             : insert_column_list:
   12362             :             insert_column_item
   12363       14650 :                     { $$ = list_make1($1); }
   12364             :             | insert_column_list ',' insert_column_item
   12365       16278 :                     { $$ = lappend($1, $3); }
   12366             :         ;
   12367             : 
   12368             : insert_column_item:
   12369             :             ColId opt_indirection
   12370             :                 {
   12371       30928 :                     $$ = makeNode(ResTarget);
   12372       30928 :                     $$->name = $1;
   12373       30928 :                     $$->indirection = check_indirection($2, yyscanner);
   12374       30928 :                     $$->val = NULL;
   12375       30928 :                     $$->location = @1;
   12376             :                 }
   12377             :         ;
   12378             : 
   12379             : opt_on_conflict:
   12380             :             ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
   12381             :                 {
   12382        1302 :                     $$ = makeNode(OnConflictClause);
   12383        1302 :                     $$->action = ONCONFLICT_UPDATE;
   12384        1302 :                     $$->infer = $3;
   12385        1302 :                     $$->targetList = $7;
   12386        1302 :                     $$->whereClause = $8;
   12387        1302 :                     $$->location = @1;
   12388             :                 }
   12389             :             |
   12390             :             ON CONFLICT opt_conf_expr DO NOTHING
   12391             :                 {
   12392         550 :                     $$ = makeNode(OnConflictClause);
   12393         550 :                     $$->action = ONCONFLICT_NOTHING;
   12394         550 :                     $$->infer = $3;
   12395         550 :                     $$->targetList = NIL;
   12396         550 :                     $$->whereClause = NULL;
   12397         550 :                     $$->location = @1;
   12398             :                 }
   12399             :             | /*EMPTY*/
   12400             :                 {
   12401       66570 :                     $$ = NULL;
   12402             :                 }
   12403             :         ;
   12404             : 
   12405             : opt_conf_expr:
   12406             :             '(' index_params ')' where_clause
   12407             :                 {
   12408        1426 :                     $$ = makeNode(InferClause);
   12409        1426 :                     $$->indexElems = $2;
   12410        1426 :                     $$->whereClause = $4;
   12411        1426 :                     $$->conname = NULL;
   12412        1426 :                     $$->location = @1;
   12413             :                 }
   12414             :             |
   12415             :             ON CONSTRAINT name
   12416             :                 {
   12417         192 :                     $$ = makeNode(InferClause);
   12418         192 :                     $$->indexElems = NIL;
   12419         192 :                     $$->whereClause = NULL;
   12420         192 :                     $$->conname = $3;
   12421         192 :                     $$->location = @1;
   12422             :                 }
   12423             :             | /*EMPTY*/
   12424             :                 {
   12425         234 :                     $$ = NULL;
   12426             :                 }
   12427             :         ;
   12428             : 
   12429             : returning_clause:
   12430             :             RETURNING returning_with_clause target_list
   12431             :                 {
   12432        3162 :                     ReturningClause *n = makeNode(ReturningClause);
   12433             : 
   12434        3162 :                     n->options = $2;
   12435        3162 :                     n->exprs = $3;
   12436        3162 :                     $$ = n;
   12437             :                 }
   12438             :             | /* EMPTY */
   12439             :                 {
   12440       85984 :                     $$ = NULL;
   12441             :                 }
   12442             :         ;
   12443             : 
   12444             : returning_with_clause:
   12445          72 :             WITH '(' returning_options ')'      { $$ = $3; }
   12446        3090 :             | /* EMPTY */                       { $$ = NIL; }
   12447             :         ;
   12448             : 
   12449             : returning_options:
   12450          72 :             returning_option                            { $$ = list_make1($1); }
   12451          54 :             | returning_options ',' returning_option    { $$ = lappend($1, $3); }
   12452             :         ;
   12453             : 
   12454             : returning_option:
   12455             :             returning_option_kind AS ColId
   12456             :                 {
   12457         126 :                     ReturningOption *n = makeNode(ReturningOption);
   12458             : 
   12459         126 :                     n->option = $1;
   12460         126 :                     n->value = $3;
   12461         126 :                     n->location = @1;
   12462         126 :                     $$ = (Node *) n;
   12463             :                 }
   12464             :         ;
   12465             : 
   12466             : returning_option_kind:
   12467          54 :             OLD         { $$ = RETURNING_OPTION_OLD; }
   12468          72 :             | NEW       { $$ = RETURNING_OPTION_NEW; }
   12469             :         ;
   12470             : 
   12471             : 
   12472             : /*****************************************************************************
   12473             :  *
   12474             :  *      QUERY:
   12475             :  *              DELETE STATEMENTS
   12476             :  *
   12477             :  *****************************************************************************/
   12478             : 
   12479             : DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
   12480             :             using_clause where_or_current_clause returning_clause
   12481             :                 {
   12482        4622 :                     DeleteStmt *n = makeNode(DeleteStmt);
   12483             : 
   12484        4622 :                     n->relation = $4;
   12485        4622 :                     n->usingClause = $5;
   12486        4622 :                     n->whereClause = $6;
   12487        4622 :                     n->returningClause = $7;
   12488        4622 :                     n->withClause = $1;
   12489        4622 :                     $$ = (Node *) n;
   12490             :                 }
   12491             :         ;
   12492             : 
   12493             : using_clause:
   12494         108 :                 USING from_list                     { $$ = $2; }
   12495        4514 :             | /*EMPTY*/                             { $$ = NIL; }
   12496             :         ;
   12497             : 
   12498             : 
   12499             : /*****************************************************************************
   12500             :  *
   12501             :  *      QUERY:
   12502             :  *              LOCK TABLE
   12503             :  *
   12504             :  *****************************************************************************/
   12505             : 
   12506             : LockStmt:   LOCK_P opt_table relation_expr_list opt_lock opt_nowait
   12507             :                 {
   12508        2516 :                     LockStmt   *n = makeNode(LockStmt);
   12509             : 
   12510        2516 :                     n->relations = $3;
   12511        2516 :                     n->mode = $4;
   12512        2516 :                     n->nowait = $5;
   12513        2516 :                     $$ = (Node *) n;
   12514             :                 }
   12515             :         ;
   12516             : 
   12517        2408 : opt_lock:   IN_P lock_type MODE             { $$ = $2; }
   12518         108 :             | /*EMPTY*/                     { $$ = AccessExclusiveLock; }
   12519             :         ;
   12520             : 
   12521        1918 : lock_type:  ACCESS SHARE                    { $$ = AccessShareLock; }
   12522          14 :             | ROW SHARE                     { $$ = RowShareLock; }
   12523          88 :             | ROW EXCLUSIVE                 { $$ = RowExclusiveLock; }
   12524          66 :             | SHARE UPDATE EXCLUSIVE        { $$ = ShareUpdateExclusiveLock; }
   12525          80 :             | SHARE                         { $$ = ShareLock; }
   12526          14 :             | SHARE ROW EXCLUSIVE           { $$ = ShareRowExclusiveLock; }
   12527         102 :             | EXCLUSIVE                     { $$ = ExclusiveLock; }
   12528         126 :             | ACCESS EXCLUSIVE              { $$ = AccessExclusiveLock; }
   12529             :         ;
   12530             : 
   12531        1586 : opt_nowait: NOWAIT                          { $$ = true; }
   12532         960 :             | /*EMPTY*/                     { $$ = false; }
   12533             :         ;
   12534             : 
   12535             : opt_nowait_or_skip:
   12536          50 :             NOWAIT                          { $$ = LockWaitError; }
   12537         190 :             | SKIP LOCKED                   { $$ = LockWaitSkip; }
   12538        4988 :             | /*EMPTY*/                     { $$ = LockWaitBlock; }
   12539             :         ;
   12540             : 
   12541             : 
   12542             : /*****************************************************************************
   12543             :  *
   12544             :  *      QUERY:
   12545             :  *              UpdateStmt (UPDATE)
   12546             :  *
   12547             :  *****************************************************************************/
   12548             : 
   12549             : UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
   12550             :             SET set_clause_list
   12551             :             from_clause
   12552             :             where_or_current_clause
   12553             :             returning_clause
   12554             :                 {
   12555       14026 :                     UpdateStmt *n = makeNode(UpdateStmt);
   12556             : 
   12557       14026 :                     n->relation = $3;
   12558       14026 :                     n->targetList = $5;
   12559       14026 :                     n->fromClause = $6;
   12560       14026 :                     n->whereClause = $7;
   12561       14026 :                     n->returningClause = $8;
   12562       14026 :                     n->withClause = $1;
   12563       14026 :                     $$ = (Node *) n;
   12564             :                 }
   12565             :         ;
   12566             : 
   12567             : set_clause_list:
   12568       16878 :             set_clause                          { $$ = $1; }
   12569        4102 :             | set_clause_list ',' set_clause    { $$ = list_concat($1,$3); }
   12570             :         ;
   12571             : 
   12572             : set_clause:
   12573             :             set_target '=' a_expr
   12574             :                 {
   12575       20796 :                     $1->val = (Node *) $3;
   12576       20796 :                     $$ = list_make1($1);
   12577             :                 }
   12578             :             | '(' set_target_list ')' '=' a_expr
   12579             :                 {
   12580         184 :                     int         ncolumns = list_length($2);
   12581         184 :                     int         i = 1;
   12582             :                     ListCell   *col_cell;
   12583             : 
   12584             :                     /* Create a MultiAssignRef source for each target */
   12585         568 :                     foreach(col_cell, $2)
   12586             :                     {
   12587         384 :                         ResTarget  *res_col = (ResTarget *) lfirst(col_cell);
   12588         384 :                         MultiAssignRef *r = makeNode(MultiAssignRef);
   12589             : 
   12590         384 :                         r->source = (Node *) $5;
   12591         384 :                         r->colno = i;
   12592         384 :                         r->ncolumns = ncolumns;
   12593         384 :                         res_col->val = (Node *) r;
   12594         384 :                         i++;
   12595             :                     }
   12596             : 
   12597         184 :                     $$ = $2;
   12598             :                 }
   12599             :         ;
   12600             : 
   12601             : set_target:
   12602             :             ColId opt_indirection
   12603             :                 {
   12604       21186 :                     $$ = makeNode(ResTarget);
   12605       21186 :                     $$->name = $1;
   12606       21186 :                     $$->indirection = check_indirection($2, yyscanner);
   12607       21186 :                     $$->val = NULL;  /* upper production sets this */
   12608       21186 :                     $$->location = @1;
   12609             :                 }
   12610             :         ;
   12611             : 
   12612             : set_target_list:
   12613         190 :             set_target                              { $$ = list_make1($1); }
   12614         200 :             | set_target_list ',' set_target        { $$ = lappend($1,$3); }
   12615             :         ;
   12616             : 
   12617             : 
   12618             : /*****************************************************************************
   12619             :  *
   12620             :  *      QUERY:
   12621             :  *              MERGE
   12622             :  *
   12623             :  *****************************************************************************/
   12624             : 
   12625             : MergeStmt:
   12626             :             opt_with_clause MERGE INTO relation_expr_opt_alias
   12627             :             USING table_ref
   12628             :             ON a_expr
   12629             :             merge_when_list
   12630             :             returning_clause
   12631             :                 {
   12632        2082 :                     MergeStmt  *m = makeNode(MergeStmt);
   12633             : 
   12634        2082 :                     m->withClause = $1;
   12635        2082 :                     m->relation = $4;
   12636        2082 :                     m->sourceRelation = $6;
   12637        2082 :                     m->joinCondition = $8;
   12638        2082 :                     m->mergeWhenClauses = $9;
   12639        2082 :                     m->returningClause = $10;
   12640             : 
   12641        2082 :                     $$ = (Node *) m;
   12642             :                 }
   12643             :         ;
   12644             : 
   12645             : merge_when_list:
   12646        2082 :             merge_when_clause                       { $$ = list_make1($1); }
   12647        1164 :             | merge_when_list merge_when_clause     { $$ = lappend($1,$2); }
   12648             :         ;
   12649             : 
   12650             : /*
   12651             :  * A WHEN clause may be WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, or WHEN NOT
   12652             :  * MATCHED [BY TARGET]. The first two cases match target tuples, and support
   12653             :  * UPDATE/DELETE/DO NOTHING actions. The third case does not match target
   12654             :  * tuples, and only supports INSERT/DO NOTHING actions.
   12655             :  */
   12656             : merge_when_clause:
   12657             :             merge_when_tgt_matched opt_merge_when_condition THEN merge_update
   12658             :                 {
   12659        1550 :                     $4->matchKind = $1;
   12660        1550 :                     $4->condition = $2;
   12661             : 
   12662        1550 :                     $$ = (Node *) $4;
   12663             :                 }
   12664             :             | merge_when_tgt_matched opt_merge_when_condition THEN merge_delete
   12665             :                 {
   12666         518 :                     $4->matchKind = $1;
   12667         518 :                     $4->condition = $2;
   12668             : 
   12669         518 :                     $$ = (Node *) $4;
   12670             :                 }
   12671             :             | merge_when_tgt_not_matched opt_merge_when_condition THEN merge_insert
   12672             :                 {
   12673        1094 :                     $4->matchKind = $1;
   12674        1094 :                     $4->condition = $2;
   12675             : 
   12676        1094 :                     $$ = (Node *) $4;
   12677             :                 }
   12678             :             | merge_when_tgt_matched opt_merge_when_condition THEN DO NOTHING
   12679             :                 {
   12680          64 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12681             : 
   12682          64 :                     m->matchKind = $1;
   12683          64 :                     m->commandType = CMD_NOTHING;
   12684          64 :                     m->condition = $2;
   12685             : 
   12686          64 :                     $$ = (Node *) m;
   12687             :                 }
   12688             :             | merge_when_tgt_not_matched opt_merge_when_condition THEN DO NOTHING
   12689             :                 {
   12690          20 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12691             : 
   12692          20 :                     m->matchKind = $1;
   12693          20 :                     m->commandType = CMD_NOTHING;
   12694          20 :                     m->condition = $2;
   12695             : 
   12696          20 :                     $$ = (Node *) m;
   12697             :                 }
   12698             :         ;
   12699             : 
   12700             : merge_when_tgt_matched:
   12701        1970 :             WHEN MATCHED                    { $$ = MERGE_WHEN_MATCHED; }
   12702         180 :             | WHEN NOT MATCHED BY SOURCE    { $$ = MERGE_WHEN_NOT_MATCHED_BY_SOURCE; }
   12703             :         ;
   12704             : 
   12705             : merge_when_tgt_not_matched:
   12706        1120 :             WHEN NOT MATCHED                { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
   12707          18 :             | WHEN NOT MATCHED BY TARGET    { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
   12708             :         ;
   12709             : 
   12710             : opt_merge_when_condition:
   12711         808 :             AND a_expr              { $$ = $2; }
   12712        2480 :             |                       { $$ = NULL; }
   12713             :         ;
   12714             : 
   12715             : merge_update:
   12716             :             UPDATE SET set_clause_list
   12717             :                 {
   12718        1550 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12719        1550 :                     n->commandType = CMD_UPDATE;
   12720        1550 :                     n->override = OVERRIDING_NOT_SET;
   12721        1550 :                     n->targetList = $3;
   12722        1550 :                     n->values = NIL;
   12723             : 
   12724        1550 :                     $$ = n;
   12725             :                 }
   12726             :         ;
   12727             : 
   12728             : merge_delete:
   12729             :             DELETE_P
   12730             :                 {
   12731         518 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12732         518 :                     n->commandType = CMD_DELETE;
   12733         518 :                     n->override = OVERRIDING_NOT_SET;
   12734         518 :                     n->targetList = NIL;
   12735         518 :                     n->values = NIL;
   12736             : 
   12737         518 :                     $$ = n;
   12738             :                 }
   12739             :         ;
   12740             : 
   12741             : merge_insert:
   12742             :             INSERT merge_values_clause
   12743             :                 {
   12744         730 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12745         730 :                     n->commandType = CMD_INSERT;
   12746         730 :                     n->override = OVERRIDING_NOT_SET;
   12747         730 :                     n->targetList = NIL;
   12748         730 :                     n->values = $2;
   12749         730 :                     $$ = n;
   12750             :                 }
   12751             :             | INSERT OVERRIDING override_kind VALUE_P merge_values_clause
   12752             :                 {
   12753           0 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12754           0 :                     n->commandType = CMD_INSERT;
   12755           0 :                     n->override = $3;
   12756           0 :                     n->targetList = NIL;
   12757           0 :                     n->values = $5;
   12758           0 :                     $$ = n;
   12759             :                 }
   12760             :             | INSERT '(' insert_column_list ')' merge_values_clause
   12761             :                 {
   12762         298 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12763         298 :                     n->commandType = CMD_INSERT;
   12764         298 :                     n->override = OVERRIDING_NOT_SET;
   12765         298 :                     n->targetList = $3;
   12766         298 :                     n->values = $5;
   12767         298 :                     $$ = n;
   12768             :                 }
   12769             :             | INSERT '(' insert_column_list ')' OVERRIDING override_kind VALUE_P merge_values_clause
   12770             :                 {
   12771          30 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12772          30 :                     n->commandType = CMD_INSERT;
   12773          30 :                     n->override = $6;
   12774          30 :                     n->targetList = $3;
   12775          30 :                     n->values = $8;
   12776          30 :                     $$ = n;
   12777             :                 }
   12778             :             | INSERT DEFAULT VALUES
   12779             :                 {
   12780          36 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12781          36 :                     n->commandType = CMD_INSERT;
   12782          36 :                     n->override = OVERRIDING_NOT_SET;
   12783          36 :                     n->targetList = NIL;
   12784          36 :                     n->values = NIL;
   12785          36 :                     $$ = n;
   12786             :                 }
   12787             :         ;
   12788             : 
   12789             : merge_values_clause:
   12790             :             VALUES '(' expr_list ')'
   12791             :                 {
   12792        1058 :                     $$ = $3;
   12793             :                 }
   12794             :         ;
   12795             : 
   12796             : /*****************************************************************************
   12797             :  *
   12798             :  *      QUERY:
   12799             :  *              CURSOR STATEMENTS
   12800             :  *
   12801             :  *****************************************************************************/
   12802             : DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
   12803             :                 {
   12804        4580 :                     DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
   12805             : 
   12806        4580 :                     n->portalname = $2;
   12807             :                     /* currently we always set FAST_PLAN option */
   12808        4580 :                     n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
   12809        4580 :                     n->query = $7;
   12810        4580 :                     $$ = (Node *) n;
   12811             :                 }
   12812             :         ;
   12813             : 
   12814       14640 : cursor_name:    name                        { $$ = $1; }
   12815             :         ;
   12816             : 
   12817        4580 : cursor_options: /*EMPTY*/                   { $$ = 0; }
   12818          28 :             | cursor_options NO SCROLL      { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
   12819         240 :             | cursor_options SCROLL         { $$ = $1 | CURSOR_OPT_SCROLL; }
   12820          14 :             | cursor_options BINARY         { $$ = $1 | CURSOR_OPT_BINARY; }
   12821           0 :             | cursor_options ASENSITIVE     { $$ = $1 | CURSOR_OPT_ASENSITIVE; }
   12822           6 :             | cursor_options INSENSITIVE    { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
   12823             :         ;
   12824             : 
   12825        4482 : opt_hold: /* EMPTY */                       { $$ = 0; }
   12826          92 :             | WITH HOLD                     { $$ = CURSOR_OPT_HOLD; }
   12827           6 :             | WITHOUT HOLD                  { $$ = 0; }
   12828             :         ;
   12829             : 
   12830             : /*****************************************************************************
   12831             :  *
   12832             :  *      QUERY:
   12833             :  *              SELECT STATEMENTS
   12834             :  *
   12835             :  *****************************************************************************/
   12836             : 
   12837             : /* A complete SELECT statement looks like this.
   12838             :  *
   12839             :  * The rule returns either a single SelectStmt node or a tree of them,
   12840             :  * representing a set-operation tree.
   12841             :  *
   12842             :  * There is an ambiguity when a sub-SELECT is within an a_expr and there
   12843             :  * are excess parentheses: do the parentheses belong to the sub-SELECT or
   12844             :  * to the surrounding a_expr?  We don't really care, but bison wants to know.
   12845             :  * To resolve the ambiguity, we are careful to define the grammar so that
   12846             :  * the decision is staved off as long as possible: as long as we can keep
   12847             :  * absorbing parentheses into the sub-SELECT, we will do so, and only when
   12848             :  * it's no longer possible to do that will we decide that parens belong to
   12849             :  * the expression.  For example, in "SELECT (((SELECT 2)) + 3)" the extra
   12850             :  * parentheses are treated as part of the sub-select.  The necessity of doing
   12851             :  * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)".    Had we
   12852             :  * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
   12853             :  * SELECT viewpoint when we see the UNION.
   12854             :  *
   12855             :  * This approach is implemented by defining a nonterminal select_with_parens,
   12856             :  * which represents a SELECT with at least one outer layer of parentheses,
   12857             :  * and being careful to use select_with_parens, never '(' SelectStmt ')',
   12858             :  * in the expression grammar.  We will then have shift-reduce conflicts
   12859             :  * which we can resolve in favor of always treating '(' <select> ')' as
   12860             :  * a select_with_parens.  To resolve the conflicts, the productions that
   12861             :  * conflict with the select_with_parens productions are manually given
   12862             :  * precedences lower than the precedence of ')', thereby ensuring that we
   12863             :  * shift ')' (and then reduce to select_with_parens) rather than trying to
   12864             :  * reduce the inner <select> nonterminal to something else.  We use UMINUS
   12865             :  * precedence for this, which is a fairly arbitrary choice.
   12866             :  *
   12867             :  * To be able to define select_with_parens itself without ambiguity, we need
   12868             :  * a nonterminal select_no_parens that represents a SELECT structure with no
   12869             :  * outermost parentheses.  This is a little bit tedious, but it works.
   12870             :  *
   12871             :  * In non-expression contexts, we use SelectStmt which can represent a SELECT
   12872             :  * with or without outer parentheses.
   12873             :  */
   12874             : 
   12875             : SelectStmt: select_no_parens            %prec UMINUS
   12876             :             | select_with_parens        %prec UMINUS
   12877             :         ;
   12878             : 
   12879             : select_with_parens:
   12880       67018 :             '(' select_no_parens ')'                { $$ = $2; }
   12881         156 :             | '(' select_with_parens ')'            { $$ = $2; }
   12882             :         ;
   12883             : 
   12884             : /*
   12885             :  * This rule parses the equivalent of the standard's <query expression>.
   12886             :  * The duplicative productions are annoying, but hard to get rid of without
   12887             :  * creating shift/reduce conflicts.
   12888             :  *
   12889             :  *  The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
   12890             :  *  In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
   12891             :  *  We now support both orderings, but prefer LIMIT/OFFSET before the locking
   12892             :  * clause.
   12893             :  *  2002-08-28 bjm
   12894             :  */
   12895             : select_no_parens:
   12896      395130 :             simple_select                       { $$ = $1; }
   12897             :             | select_clause sort_clause
   12898             :                 {
   12899       72758 :                     insertSelectOptions((SelectStmt *) $1, $2, NIL,
   12900             :                                         NULL, NULL,
   12901             :                                         yyscanner);
   12902       72758 :                     $$ = $1;
   12903             :                 }
   12904             :             | select_clause opt_sort_clause for_locking_clause opt_select_limit
   12905             :                 {
   12906        4780 :                     insertSelectOptions((SelectStmt *) $1, $2, $3,
   12907        4780 :                                         $4,
   12908             :                                         NULL,
   12909             :                                         yyscanner);
   12910        4780 :                     $$ = $1;
   12911             :                 }
   12912             :             | select_clause opt_sort_clause select_limit opt_for_locking_clause
   12913             :                 {
   12914        4914 :                     insertSelectOptions((SelectStmt *) $1, $2, $4,
   12915        4914 :                                         $3,
   12916             :                                         NULL,
   12917             :                                         yyscanner);
   12918        4902 :                     $$ = $1;
   12919             :                 }
   12920             :             | with_clause select_clause
   12921             :                 {
   12922        2240 :                     insertSelectOptions((SelectStmt *) $2, NULL, NIL,
   12923             :                                         NULL,
   12924        2240 :                                         $1,
   12925             :                                         yyscanner);
   12926        2240 :                     $$ = $2;
   12927             :                 }
   12928             :             | with_clause select_clause sort_clause
   12929             :                 {
   12930         578 :                     insertSelectOptions((SelectStmt *) $2, $3, NIL,
   12931             :                                         NULL,
   12932         578 :                                         $1,
   12933             :                                         yyscanner);
   12934         578 :                     $$ = $2;
   12935             :                 }
   12936             :             | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
   12937             :                 {
   12938           6 :                     insertSelectOptions((SelectStmt *) $2, $3, $4,
   12939           6 :                                         $5,
   12940           6 :                                         $1,
   12941             :                                         yyscanner);
   12942           6 :                     $$ = $2;
   12943             :                 }
   12944             :             | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
   12945             :                 {
   12946          64 :                     insertSelectOptions((SelectStmt *) $2, $3, $5,
   12947          64 :                                         $4,
   12948          64 :                                         $1,
   12949             :                                         yyscanner);
   12950          64 :                     $$ = $2;
   12951             :                 }
   12952             :         ;
   12953             : 
   12954             : select_clause:
   12955      123730 :             simple_select                           { $$ = $1; }
   12956         590 :             | select_with_parens                    { $$ = $1; }
   12957             :         ;
   12958             : 
   12959             : /*
   12960             :  * This rule parses SELECT statements that can appear within set operations,
   12961             :  * including UNION, INTERSECT and EXCEPT.  '(' and ')' can be used to specify
   12962             :  * the ordering of the set operations.  Without '(' and ')' we want the
   12963             :  * operations to be ordered per the precedence specs at the head of this file.
   12964             :  *
   12965             :  * As with select_no_parens, simple_select cannot have outer parentheses,
   12966             :  * but can have parenthesized subclauses.
   12967             :  *
   12968             :  * It might appear that we could fold the first two alternatives into one
   12969             :  * by using opt_distinct_clause.  However, that causes a shift/reduce conflict
   12970             :  * against INSERT ... SELECT ... ON CONFLICT.  We avoid the ambiguity by
   12971             :  * requiring SELECT DISTINCT [ON] to be followed by a non-empty target_list.
   12972             :  *
   12973             :  * Note that sort clauses cannot be included at this level --- SQL requires
   12974             :  *      SELECT foo UNION SELECT bar ORDER BY baz
   12975             :  * to be parsed as
   12976             :  *      (SELECT foo UNION SELECT bar) ORDER BY baz
   12977             :  * not
   12978             :  *      SELECT foo UNION (SELECT bar ORDER BY baz)
   12979             :  * Likewise for WITH, FOR UPDATE and LIMIT.  Therefore, those clauses are
   12980             :  * described as part of the select_no_parens production, not simple_select.
   12981             :  * This does not limit functionality, because you can reintroduce these
   12982             :  * clauses inside parentheses.
   12983             :  *
   12984             :  * NOTE: only the leftmost component SelectStmt should have INTO.
   12985             :  * However, this is not checked by the grammar; parse analysis must check it.
   12986             :  */
   12987             : simple_select:
   12988             :             SELECT opt_all_clause opt_target_list
   12989             :             into_clause from_clause where_clause
   12990             :             group_clause having_clause window_clause
   12991             :                 {
   12992      436434 :                     SelectStmt *n = makeNode(SelectStmt);
   12993             : 
   12994      436434 :                     n->targetList = $3;
   12995      436434 :                     n->intoClause = $4;
   12996      436434 :                     n->fromClause = $5;
   12997      436434 :                     n->whereClause = $6;
   12998      436434 :                     n->groupClause = ($7)->list;
   12999      436434 :                     n->groupDistinct = ($7)->distinct;
   13000      436434 :                     n->havingClause = $8;
   13001      436434 :                     n->windowClause = $9;
   13002      436434 :                     $$ = (Node *) n;
   13003             :                 }
   13004             :             | SELECT distinct_clause target_list
   13005             :             into_clause from_clause where_clause
   13006             :             group_clause having_clause window_clause
   13007             :                 {
   13008        3756 :                     SelectStmt *n = makeNode(SelectStmt);
   13009             : 
   13010        3756 :                     n->distinctClause = $2;
   13011        3756 :                     n->targetList = $3;
   13012        3756 :                     n->intoClause = $4;
   13013        3756 :                     n->fromClause = $5;
   13014        3756 :                     n->whereClause = $6;
   13015        3756 :                     n->groupClause = ($7)->list;
   13016        3756 :                     n->groupDistinct = ($7)->distinct;
   13017        3756 :                     n->havingClause = $8;
   13018        3756 :                     n->windowClause = $9;
   13019        3756 :                     $$ = (Node *) n;
   13020             :                 }
   13021       58878 :             | values_clause                         { $$ = $1; }
   13022             :             | TABLE relation_expr
   13023             :                 {
   13024             :                     /* same as SELECT * FROM relation_expr */
   13025         308 :                     ColumnRef  *cr = makeNode(ColumnRef);
   13026         308 :                     ResTarget  *rt = makeNode(ResTarget);
   13027         308 :                     SelectStmt *n = makeNode(SelectStmt);
   13028             : 
   13029         308 :                     cr->fields = list_make1(makeNode(A_Star));
   13030         308 :                     cr->location = -1;
   13031             : 
   13032         308 :                     rt->name = NULL;
   13033         308 :                     rt->indirection = NIL;
   13034         308 :                     rt->val = (Node *) cr;
   13035         308 :                     rt->location = -1;
   13036             : 
   13037         308 :                     n->targetList = list_make1(rt);
   13038         308 :                     n->fromClause = list_make1($2);
   13039         308 :                     $$ = (Node *) n;
   13040             :                 }
   13041             :             | select_clause UNION set_quantifier select_clause
   13042             :                 {
   13043       18750 :                     $$ = makeSetOp(SETOP_UNION, $3 == SET_QUANTIFIER_ALL, $1, $4);
   13044             :                 }
   13045             :             | select_clause INTERSECT set_quantifier select_clause
   13046             :                 {
   13047         258 :                     $$ = makeSetOp(SETOP_INTERSECT, $3 == SET_QUANTIFIER_ALL, $1, $4);
   13048             :                 }
   13049             :             | select_clause EXCEPT set_quantifier select_clause
   13050             :                 {
   13051         476 :                     $$ = makeSetOp(SETOP_EXCEPT, $3 == SET_QUANTIFIER_ALL, $1, $4);
   13052             :                 }
   13053             :         ;
   13054             : 
   13055             : /*
   13056             :  * SQL standard WITH clause looks like:
   13057             :  *
   13058             :  * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
   13059             :  *      AS (query) [ SEARCH or CYCLE clause ]
   13060             :  *
   13061             :  * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
   13062             :  */
   13063             : with_clause:
   13064             :         WITH cte_list
   13065             :             {
   13066        2010 :                 $$ = makeNode(WithClause);
   13067        2010 :                 $$->ctes = $2;
   13068        2010 :                 $$->recursive = false;
   13069        2010 :                 $$->location = @1;
   13070             :             }
   13071             :         | WITH_LA cte_list
   13072             :             {
   13073           6 :                 $$ = makeNode(WithClause);
   13074           6 :                 $$->ctes = $2;
   13075           6 :                 $$->recursive = false;
   13076           6 :                 $$->location = @1;
   13077             :             }
   13078             :         | WITH RECURSIVE cte_list
   13079             :             {
   13080        1326 :                 $$ = makeNode(WithClause);
   13081        1326 :                 $$->ctes = $3;
   13082        1326 :                 $$->recursive = true;
   13083        1326 :                 $$->location = @1;
   13084             :             }
   13085             :         ;
   13086             : 
   13087             : cte_list:
   13088        3342 :         common_table_expr                       { $$ = list_make1($1); }
   13089        1204 :         | cte_list ',' common_table_expr        { $$ = lappend($1, $3); }
   13090             :         ;
   13091             : 
   13092             : common_table_expr:  name opt_name_list AS opt_materialized '(' PreparableStmt ')' opt_search_clause opt_cycle_clause
   13093             :             {
   13094        4546 :                 CommonTableExpr *n = makeNode(CommonTableExpr);
   13095             : 
   13096        4546 :                 n->ctename = $1;
   13097        4546 :                 n->aliascolnames = $2;
   13098        4546 :                 n->ctematerialized = $4;
   13099        4546 :                 n->ctequery = $6;
   13100        4546 :                 n->search_clause = castNode(CTESearchClause, $8);
   13101        4546 :                 n->cycle_clause = castNode(CTECycleClause, $9);
   13102        4546 :                 n->location = @1;
   13103        4546 :                 $$ = (Node *) n;
   13104             :             }
   13105             :         ;
   13106             : 
   13107             : opt_materialized:
   13108         178 :         MATERIALIZED                            { $$ = CTEMaterializeAlways; }
   13109          48 :         | NOT MATERIALIZED                      { $$ = CTEMaterializeNever; }
   13110        4320 :         | /*EMPTY*/                             { $$ = CTEMaterializeDefault; }
   13111             :         ;
   13112             : 
   13113             : opt_search_clause:
   13114             :         SEARCH DEPTH FIRST_P BY columnList SET ColId
   13115             :             {
   13116          90 :                 CTESearchClause *n = makeNode(CTESearchClause);
   13117             : 
   13118          90 :                 n->search_col_list = $5;
   13119          90 :                 n->search_breadth_first = false;
   13120          90 :                 n->search_seq_column = $7;
   13121          90 :                 n->location = @1;
   13122          90 :                 $$ = (Node *) n;
   13123             :             }
   13124             :         | SEARCH BREADTH FIRST_P BY columnList SET ColId
   13125             :             {
   13126          36 :                 CTESearchClause *n = makeNode(CTESearchClause);
   13127             : 
   13128          36 :                 n->search_col_list = $5;
   13129          36 :                 n->search_breadth_first = true;
   13130          36 :                 n->search_seq_column = $7;
   13131          36 :                 n->location = @1;
   13132          36 :                 $$ = (Node *) n;
   13133             :             }
   13134             :         | /*EMPTY*/
   13135             :             {
   13136        4420 :                 $$ = NULL;
   13137             :             }
   13138             :         ;
   13139             : 
   13140             : opt_cycle_clause:
   13141             :         CYCLE columnList SET ColId TO AexprConst DEFAULT AexprConst USING ColId
   13142             :             {
   13143          66 :                 CTECycleClause *n = makeNode(CTECycleClause);
   13144             : 
   13145          66 :                 n->cycle_col_list = $2;
   13146          66 :                 n->cycle_mark_column = $4;
   13147          66 :                 n->cycle_mark_value = $6;
   13148          66 :                 n->cycle_mark_default = $8;
   13149          66 :                 n->cycle_path_column = $10;
   13150          66 :                 n->location = @1;
   13151          66 :                 $$ = (Node *) n;
   13152             :             }
   13153             :         | CYCLE columnList SET ColId USING ColId
   13154             :             {
   13155          60 :                 CTECycleClause *n = makeNode(CTECycleClause);
   13156             : 
   13157          60 :                 n->cycle_col_list = $2;
   13158          60 :                 n->cycle_mark_column = $4;
   13159          60 :                 n->cycle_mark_value = makeBoolAConst(true, -1);
   13160          60 :                 n->cycle_mark_default = makeBoolAConst(false, -1);
   13161          60 :                 n->cycle_path_column = $6;
   13162          60 :                 n->location = @1;
   13163          60 :                 $$ = (Node *) n;
   13164             :             }
   13165             :         | /*EMPTY*/
   13166             :             {
   13167        4420 :                 $$ = NULL;
   13168             :             }
   13169             :         ;
   13170             : 
   13171             : opt_with_clause:
   13172         454 :         with_clause                             { $$ = $1; }
   13173       88808 :         | /*EMPTY*/                             { $$ = NULL; }
   13174             :         ;
   13175             : 
   13176             : into_clause:
   13177             :             INTO OptTempTableName
   13178             :                 {
   13179         132 :                     $$ = makeNode(IntoClause);
   13180         132 :                     $$->rel = $2;
   13181         132 :                     $$->colNames = NIL;
   13182         132 :                     $$->options = NIL;
   13183         132 :                     $$->onCommit = ONCOMMIT_NOOP;
   13184         132 :                     $$->tableSpaceName = NULL;
   13185         132 :                     $$->viewQuery = NULL;
   13186         132 :                     $$->skipData = false;
   13187             :                 }
   13188             :             | /*EMPTY*/
   13189      440088 :                 { $$ = NULL; }
   13190             :         ;
   13191             : 
   13192             : /*
   13193             :  * Redundancy here is needed to avoid shift/reduce conflicts,
   13194             :  * since TEMP is not a reserved word.  See also OptTemp.
   13195             :  */
   13196             : OptTempTableName:
   13197             :             TEMPORARY opt_table qualified_name
   13198             :                 {
   13199           0 :                     $$ = $3;
   13200           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13201             :                 }
   13202             :             | TEMP opt_table qualified_name
   13203             :                 {
   13204           6 :                     $$ = $3;
   13205           6 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13206             :                 }
   13207             :             | LOCAL TEMPORARY opt_table qualified_name
   13208             :                 {
   13209           0 :                     $$ = $4;
   13210           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13211             :                 }
   13212             :             | LOCAL TEMP opt_table qualified_name
   13213             :                 {
   13214           0 :                     $$ = $4;
   13215           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13216             :                 }
   13217             :             | GLOBAL TEMPORARY opt_table qualified_name
   13218             :                 {
   13219           0 :                     ereport(WARNING,
   13220             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   13221             :                              parser_errposition(@1)));
   13222           0 :                     $$ = $4;
   13223           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13224             :                 }
   13225             :             | GLOBAL TEMP opt_table qualified_name
   13226             :                 {
   13227           0 :                     ereport(WARNING,
   13228             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   13229             :                              parser_errposition(@1)));
   13230           0 :                     $$ = $4;
   13231           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13232             :                 }
   13233             :             | UNLOGGED opt_table qualified_name
   13234             :                 {
   13235           0 :                     $$ = $3;
   13236           0 :                     $$->relpersistence = RELPERSISTENCE_UNLOGGED;
   13237             :                 }
   13238             :             | TABLE qualified_name
   13239             :                 {
   13240          30 :                     $$ = $2;
   13241          30 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   13242             :                 }
   13243             :             | qualified_name
   13244             :                 {
   13245          96 :                     $$ = $1;
   13246          96 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   13247             :                 }
   13248             :         ;
   13249             : 
   13250             : opt_table:  TABLE
   13251             :             | /*EMPTY*/
   13252             :         ;
   13253             : 
   13254             : set_quantifier:
   13255       10822 :             ALL                                     { $$ = SET_QUANTIFIER_ALL; }
   13256          32 :             | DISTINCT                              { $$ = SET_QUANTIFIER_DISTINCT; }
   13257       13280 :             | /*EMPTY*/                             { $$ = SET_QUANTIFIER_DEFAULT; }
   13258             :         ;
   13259             : 
   13260             : /* We use (NIL) as a placeholder to indicate that all target expressions
   13261             :  * should be placed in the DISTINCT list during parsetree analysis.
   13262             :  */
   13263             : distinct_clause:
   13264        3502 :             DISTINCT                                { $$ = list_make1(NIL); }
   13265         260 :             | DISTINCT ON '(' expr_list ')'         { $$ = $4; }
   13266             :         ;
   13267             : 
   13268             : opt_all_clause:
   13269             :             ALL
   13270             :             | /*EMPTY*/
   13271             :         ;
   13272             : 
   13273             : opt_distinct_clause:
   13274           0 :             distinct_clause                         { $$ = $1; }
   13275       40300 :             | opt_all_clause                        { $$ = NIL; }
   13276             :         ;
   13277             : 
   13278             : opt_sort_clause:
   13279        7706 :             sort_clause                             { $$ = $1; }
   13280      369806 :             | /*EMPTY*/                             { $$ = NIL; }
   13281             :         ;
   13282             : 
   13283             : sort_clause:
   13284       81390 :             ORDER BY sortby_list                    { $$ = $3; }
   13285             :         ;
   13286             : 
   13287             : sortby_list:
   13288       81408 :             sortby                                  { $$ = list_make1($1); }
   13289       30036 :             | sortby_list ',' sortby                { $$ = lappend($1, $3); }
   13290             :         ;
   13291             : 
   13292             : sortby:     a_expr USING qual_all_Op opt_nulls_order
   13293             :                 {
   13294         220 :                     $$ = makeNode(SortBy);
   13295         220 :                     $$->node = $1;
   13296         220 :                     $$->sortby_dir = SORTBY_USING;
   13297         220 :                     $$->sortby_nulls = $4;
   13298         220 :                     $$->useOp = $3;
   13299         220 :                     $$->location = @3;
   13300             :                 }
   13301             :             | a_expr opt_asc_desc opt_nulls_order
   13302             :                 {
   13303      111224 :                     $$ = makeNode(SortBy);
   13304      111224 :                     $$->node = $1;
   13305      111224 :                     $$->sortby_dir = $2;
   13306      111224 :                     $$->sortby_nulls = $3;
   13307      111224 :                     $$->useOp = NIL;
   13308      111224 :                     $$->location = -1;       /* no operator */
   13309             :                 }
   13310             :         ;
   13311             : 
   13312             : 
   13313             : select_limit:
   13314             :             limit_clause offset_clause
   13315             :                 {
   13316         172 :                     $$ = $1;
   13317         172 :                     ($$)->limitOffset = $2;
   13318         172 :                     ($$)->offsetLoc = @2;
   13319             :                 }
   13320             :             | offset_clause limit_clause
   13321             :                 {
   13322         226 :                     $$ = $2;
   13323         226 :                     ($$)->limitOffset = $1;
   13324         226 :                     ($$)->offsetLoc = @1;
   13325             :                 }
   13326             :             | limit_clause
   13327             :                 {
   13328        4320 :                     $$ = $1;
   13329             :                 }
   13330             :             | offset_clause
   13331             :                 {
   13332         450 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13333             : 
   13334         450 :                     n->limitOffset = $1;
   13335         450 :                     n->limitCount = NULL;
   13336         450 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13337         450 :                     n->offsetLoc = @1;
   13338         450 :                     n->countLoc = -1;
   13339         450 :                     n->optionLoc = -1;
   13340         450 :                     $$ = n;
   13341             :                 }
   13342             :         ;
   13343             : 
   13344             : opt_select_limit:
   13345         190 :             select_limit                        { $$ = $1; }
   13346       44896 :             | /* EMPTY */                       { $$ = NULL; }
   13347             :         ;
   13348             : 
   13349             : limit_clause:
   13350             :             LIMIT select_limit_value
   13351             :                 {
   13352        4616 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13353             : 
   13354        4616 :                     n->limitOffset = NULL;
   13355        4616 :                     n->limitCount = $2;
   13356        4616 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13357        4616 :                     n->offsetLoc = -1;
   13358        4616 :                     n->countLoc = @1;
   13359        4616 :                     n->optionLoc = -1;
   13360        4616 :                     $$ = n;
   13361             :                 }
   13362             :             | LIMIT select_limit_value ',' select_offset_value
   13363             :                 {
   13364             :                     /* Disabled because it was too confusing, bjm 2002-02-18 */
   13365           0 :                     ereport(ERROR,
   13366             :                             (errcode(ERRCODE_SYNTAX_ERROR),
   13367             :                              errmsg("LIMIT #,# syntax is not supported"),
   13368             :                              errhint("Use separate LIMIT and OFFSET clauses."),
   13369             :                              parser_errposition(@1)));
   13370             :                 }
   13371             :             /* SQL:2008 syntax */
   13372             :             /* to avoid shift/reduce conflicts, handle the optional value with
   13373             :              * a separate production rather than an opt_ expression.  The fact
   13374             :              * that ONLY is fully reserved means that this way, we defer any
   13375             :              * decision about what rule reduces ROW or ROWS to the point where
   13376             :              * we can see the ONLY token in the lookahead slot.
   13377             :              */
   13378             :             | FETCH first_or_next select_fetch_first_value row_or_rows ONLY
   13379             :                 {
   13380          24 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13381             : 
   13382          24 :                     n->limitOffset = NULL;
   13383          24 :                     n->limitCount = $3;
   13384          24 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13385          24 :                     n->offsetLoc = -1;
   13386          24 :                     n->countLoc = @1;
   13387          24 :                     n->optionLoc = -1;
   13388          24 :                     $$ = n;
   13389             :                 }
   13390             :             | FETCH first_or_next select_fetch_first_value row_or_rows WITH TIES
   13391             :                 {
   13392          72 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13393             : 
   13394          72 :                     n->limitOffset = NULL;
   13395          72 :                     n->limitCount = $3;
   13396          72 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13397          72 :                     n->offsetLoc = -1;
   13398          72 :                     n->countLoc = @1;
   13399          72 :                     n->optionLoc = @5;
   13400          72 :                     $$ = n;
   13401             :                 }
   13402             :             | FETCH first_or_next row_or_rows ONLY
   13403             :                 {
   13404           0 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13405             : 
   13406           0 :                     n->limitOffset = NULL;
   13407           0 :                     n->limitCount = makeIntConst(1, -1);
   13408           0 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13409           0 :                     n->offsetLoc = -1;
   13410           0 :                     n->countLoc = @1;
   13411           0 :                     n->optionLoc = -1;
   13412           0 :                     $$ = n;
   13413             :                 }
   13414             :             | FETCH first_or_next row_or_rows WITH TIES
   13415             :                 {
   13416           6 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13417             : 
   13418           6 :                     n->limitOffset = NULL;
   13419           6 :                     n->limitCount = makeIntConst(1, -1);
   13420           6 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13421           6 :                     n->offsetLoc = -1;
   13422           6 :                     n->countLoc = @1;
   13423           6 :                     n->optionLoc = @4;
   13424           6 :                     $$ = n;
   13425             :                 }
   13426             :         ;
   13427             : 
   13428             : offset_clause:
   13429             :             OFFSET select_offset_value
   13430         848 :                 { $$ = $2; }
   13431             :             /* SQL:2008 syntax */
   13432             :             | OFFSET select_fetch_first_value row_or_rows
   13433           0 :                 { $$ = $2; }
   13434             :         ;
   13435             : 
   13436             : select_limit_value:
   13437        4612 :             a_expr                                  { $$ = $1; }
   13438             :             | ALL
   13439             :                 {
   13440             :                     /* LIMIT ALL is represented as a NULL constant */
   13441           4 :                     $$ = makeNullAConst(@1);
   13442             :                 }
   13443             :         ;
   13444             : 
   13445             : select_offset_value:
   13446         848 :             a_expr                                  { $$ = $1; }
   13447             :         ;
   13448             : 
   13449             : /*
   13450             :  * Allowing full expressions without parentheses causes various parsing
   13451             :  * problems with the trailing ROW/ROWS key words.  SQL spec only calls for
   13452             :  * <simple value specification>, which is either a literal or a parameter (but
   13453             :  * an <SQL parameter reference> could be an identifier, bringing up conflicts
   13454             :  * with ROW/ROWS). We solve this by leveraging the presence of ONLY (see above)
   13455             :  * to determine whether the expression is missing rather than trying to make it
   13456             :  * optional in this rule.
   13457             :  *
   13458             :  * c_expr covers almost all the spec-required cases (and more), but it doesn't
   13459             :  * cover signed numeric literals, which are allowed by the spec. So we include
   13460             :  * those here explicitly. We need FCONST as well as ICONST because values that
   13461             :  * don't fit in the platform's "long", but do fit in bigint, should still be
   13462             :  * accepted here. (This is possible in 64-bit Windows as well as all 32-bit
   13463             :  * builds.)
   13464             :  */
   13465             : select_fetch_first_value:
   13466          96 :             c_expr                                  { $$ = $1; }
   13467             :             | '+' I_or_F_const
   13468           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   13469             :             | '-' I_or_F_const
   13470           0 :                 { $$ = doNegate($2, @1); }
   13471             :         ;
   13472             : 
   13473             : I_or_F_const:
   13474           0 :             Iconst                                  { $$ = makeIntConst($1,@1); }
   13475           0 :             | FCONST                                { $$ = makeFloatConst($1,@1); }
   13476             :         ;
   13477             : 
   13478             : /* noise words */
   13479          36 : row_or_rows: ROW                                    { $$ = 0; }
   13480          66 :             | ROWS                                  { $$ = 0; }
   13481             :         ;
   13482             : 
   13483         102 : first_or_next: FIRST_P                              { $$ = 0; }
   13484           0 :             | NEXT                                  { $$ = 0; }
   13485             :         ;
   13486             : 
   13487             : 
   13488             : /*
   13489             :  * This syntax for group_clause tries to follow the spec quite closely.
   13490             :  * However, the spec allows only column references, not expressions,
   13491             :  * which introduces an ambiguity between implicit row constructors
   13492             :  * (a,b) and lists of column references.
   13493             :  *
   13494             :  * We handle this by using the a_expr production for what the spec calls
   13495             :  * <ordinary grouping set>, which in the spec represents either one column
   13496             :  * reference or a parenthesized list of column references. Then, we check the
   13497             :  * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
   13498             :  * grab and use the list, discarding the node. (this is done in parse analysis,
   13499             :  * not here)
   13500             :  *
   13501             :  * (we abuse the row_format field of RowExpr to distinguish implicit and
   13502             :  * explicit row constructors; it's debatable if anyone sanely wants to use them
   13503             :  * in a group clause, but if they have a reason to, we make it possible.)
   13504             :  *
   13505             :  * Each item in the group_clause list is either an expression tree or a
   13506             :  * GroupingSet node of some type.
   13507             :  */
   13508             : group_clause:
   13509             :             GROUP_P BY set_quantifier group_by_list
   13510             :                 {
   13511        4638 :                     GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
   13512             : 
   13513        4638 :                     n->distinct = $3 == SET_QUANTIFIER_DISTINCT;
   13514        4638 :                     n->list = $4;
   13515        4638 :                     $$ = n;
   13516             :                 }
   13517             :             | /*EMPTY*/
   13518             :                 {
   13519      475852 :                     GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
   13520             : 
   13521      475852 :                     n->distinct = false;
   13522      475852 :                     n->list = NIL;
   13523      475852 :                     $$ = n;
   13524             :                 }
   13525             :         ;
   13526             : 
   13527             : group_by_list:
   13528        5236 :             group_by_item                           { $$ = list_make1($1); }
   13529        3036 :             | group_by_list ',' group_by_item       { $$ = lappend($1,$3); }
   13530             :         ;
   13531             : 
   13532             : group_by_item:
   13533        6982 :             a_expr                                  { $$ = $1; }
   13534         222 :             | empty_grouping_set                    { $$ = $1; }
   13535         184 :             | cube_clause                           { $$ = $1; }
   13536         286 :             | rollup_clause                         { $$ = $1; }
   13537         598 :             | grouping_sets_clause                  { $$ = $1; }
   13538             :         ;
   13539             : 
   13540             : empty_grouping_set:
   13541             :             '(' ')'
   13542             :                 {
   13543         222 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, @1);
   13544             :                 }
   13545             :         ;
   13546             : 
   13547             : /*
   13548             :  * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
   13549             :  * so that they shift in these rules rather than reducing the conflicting
   13550             :  * unreserved_keyword rule.
   13551             :  */
   13552             : 
   13553             : rollup_clause:
   13554             :             ROLLUP '(' expr_list ')'
   13555             :                 {
   13556         286 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_ROLLUP, $3, @1);
   13557             :                 }
   13558             :         ;
   13559             : 
   13560             : cube_clause:
   13561             :             CUBE '(' expr_list ')'
   13562             :                 {
   13563         184 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_CUBE, $3, @1);
   13564             :                 }
   13565             :         ;
   13566             : 
   13567             : grouping_sets_clause:
   13568             :             GROUPING SETS '(' group_by_list ')'
   13569             :                 {
   13570         598 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_SETS, $4, @1);
   13571             :                 }
   13572             :         ;
   13573             : 
   13574             : having_clause:
   13575         684 :             HAVING a_expr                           { $$ = $2; }
   13576      479806 :             | /*EMPTY*/                             { $$ = NULL; }
   13577             :         ;
   13578             : 
   13579             : for_locking_clause:
   13580        5126 :             for_locking_items                       { $$ = $1; }
   13581           0 :             | FOR READ ONLY                         { $$ = NIL; }
   13582             :         ;
   13583             : 
   13584             : opt_for_locking_clause:
   13585         340 :             for_locking_clause                      { $$ = $1; }
   13586       44938 :             | /* EMPTY */                           { $$ = NIL; }
   13587             :         ;
   13588             : 
   13589             : for_locking_items:
   13590        5126 :             for_locking_item                        { $$ = list_make1($1); }
   13591         102 :             | for_locking_items for_locking_item    { $$ = lappend($1, $2); }
   13592             :         ;
   13593             : 
   13594             : for_locking_item:
   13595             :             for_locking_strength locked_rels_list opt_nowait_or_skip
   13596             :                 {
   13597        5228 :                     LockingClause *n = makeNode(LockingClause);
   13598             : 
   13599        5228 :                     n->lockedRels = $2;
   13600        5228 :                     n->strength = $1;
   13601        5228 :                     n->waitPolicy = $3;
   13602        5228 :                     $$ = (Node *) n;
   13603             :                 }
   13604             :         ;
   13605             : 
   13606             : for_locking_strength:
   13607        1526 :             FOR UPDATE                          { $$ = LCS_FORUPDATE; }
   13608          76 :             | FOR NO KEY UPDATE                 { $$ = LCS_FORNOKEYUPDATE; }
   13609         214 :             | FOR SHARE                         { $$ = LCS_FORSHARE; }
   13610        3412 :             | FOR KEY SHARE                     { $$ = LCS_FORKEYSHARE; }
   13611             :         ;
   13612             : 
   13613             : locked_rels_list:
   13614        3438 :             OF qualified_name_list                  { $$ = $2; }
   13615        1790 :             | /* EMPTY */                           { $$ = NIL; }
   13616             :         ;
   13617             : 
   13618             : 
   13619             : /*
   13620             :  * We should allow ROW '(' expr_list ')' too, but that seems to require
   13621             :  * making VALUES a fully reserved word, which will probably break more apps
   13622             :  * than allowing the noise-word is worth.
   13623             :  */
   13624             : values_clause:
   13625             :             VALUES '(' expr_list ')'
   13626             :                 {
   13627       58878 :                     SelectStmt *n = makeNode(SelectStmt);
   13628             : 
   13629       58878 :                     n->valuesLists = list_make1($3);
   13630       58878 :                     $$ = (Node *) n;
   13631             :                 }
   13632             :             | values_clause ',' '(' expr_list ')'
   13633             :                 {
   13634       25198 :                     SelectStmt *n = (SelectStmt *) $1;
   13635             : 
   13636       25198 :                     n->valuesLists = lappend(n->valuesLists, $4);
   13637       25198 :                     $$ = (Node *) n;
   13638             :                 }
   13639             :         ;
   13640             : 
   13641             : 
   13642             : /*****************************************************************************
   13643             :  *
   13644             :  *  clauses common to all Optimizable Stmts:
   13645             :  *      from_clause     - allow list of both JOIN expressions and table names
   13646             :  *      where_clause    - qualifications for joins or restrictions
   13647             :  *
   13648             :  *****************************************************************************/
   13649             : 
   13650             : from_clause:
   13651      321074 :             FROM from_list                          { $$ = $2; }
   13652      173442 :             | /*EMPTY*/                             { $$ = NIL; }
   13653             :         ;
   13654             : 
   13655             : from_list:
   13656      321884 :             table_ref                               { $$ = list_make1($1); }
   13657       61828 :             | from_list ',' table_ref               { $$ = lappend($1, $3); }
   13658             :         ;
   13659             : 
   13660             : /*
   13661             :  * table_ref is where an alias clause can be attached.
   13662             :  */
   13663             : table_ref:  relation_expr opt_alias_clause
   13664             :                 {
   13665      406992 :                     $1->alias = $2;
   13666      406992 :                     $$ = (Node *) $1;
   13667             :                 }
   13668             :             | relation_expr opt_alias_clause tablesample_clause
   13669             :                 {
   13670         264 :                     RangeTableSample *n = (RangeTableSample *) $3;
   13671             : 
   13672         264 :                     $1->alias = $2;
   13673             :                     /* relation_expr goes inside the RangeTableSample node */
   13674         264 :                     n->relation = (Node *) $1;
   13675         264 :                     $$ = (Node *) n;
   13676             :                 }
   13677             :             | func_table func_alias_clause
   13678             :                 {
   13679       47354 :                     RangeFunction *n = (RangeFunction *) $1;
   13680             : 
   13681       47354 :                     n->alias = linitial($2);
   13682       47354 :                     n->coldeflist = lsecond($2);
   13683       47354 :                     $$ = (Node *) n;
   13684             :                 }
   13685             :             | LATERAL_P func_table func_alias_clause
   13686             :                 {
   13687        1158 :                     RangeFunction *n = (RangeFunction *) $2;
   13688             : 
   13689        1158 :                     n->lateral = true;
   13690        1158 :                     n->alias = linitial($3);
   13691        1158 :                     n->coldeflist = lsecond($3);
   13692        1158 :                     $$ = (Node *) n;
   13693             :                 }
   13694             :             | xmltable opt_alias_clause
   13695             :                 {
   13696          82 :                     RangeTableFunc *n = (RangeTableFunc *) $1;
   13697             : 
   13698          82 :                     n->alias = $2;
   13699          82 :                     $$ = (Node *) n;
   13700             :                 }
   13701             :             | LATERAL_P xmltable opt_alias_clause
   13702             :                 {
   13703         142 :                     RangeTableFunc *n = (RangeTableFunc *) $2;
   13704             : 
   13705         142 :                     n->lateral = true;
   13706         142 :                     n->alias = $3;
   13707         142 :                     $$ = (Node *) n;
   13708             :                 }
   13709             :             | select_with_parens opt_alias_clause
   13710             :                 {
   13711       14042 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13712             : 
   13713       14042 :                     n->lateral = false;
   13714       14042 :                     n->subquery = $1;
   13715       14042 :                     n->alias = $2;
   13716       14042 :                     $$ = (Node *) n;
   13717             :                 }
   13718             :             | LATERAL_P select_with_parens opt_alias_clause
   13719             :                 {
   13720        1902 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13721             : 
   13722        1902 :                     n->lateral = true;
   13723        1902 :                     n->subquery = $2;
   13724        1902 :                     n->alias = $3;
   13725        1902 :                     $$ = (Node *) n;
   13726             :                 }
   13727             :             | joined_table
   13728             :                 {
   13729       86450 :                     $$ = (Node *) $1;
   13730             :                 }
   13731             :             | '(' joined_table ')' alias_clause
   13732             :                 {
   13733         174 :                     $2->alias = $4;
   13734         174 :                     $$ = (Node *) $2;
   13735             :                 }
   13736             :             | json_table opt_alias_clause
   13737             :                 {
   13738         524 :                     JsonTable  *jt = castNode(JsonTable, $1);
   13739             : 
   13740         524 :                     jt->alias = $2;
   13741         524 :                     $$ = (Node *) jt;
   13742             :                 }
   13743             :             | LATERAL_P json_table opt_alias_clause
   13744             :                 {
   13745           0 :                     JsonTable  *jt = castNode(JsonTable, $2);
   13746             : 
   13747           0 :                     jt->alias = $3;
   13748           0 :                     jt->lateral = true;
   13749           0 :                     $$ = (Node *) jt;
   13750             :                 }
   13751             :         ;
   13752             : 
   13753             : 
   13754             : /*
   13755             :  * It may seem silly to separate joined_table from table_ref, but there is
   13756             :  * method in SQL's madness: if you don't do it this way you get reduce-
   13757             :  * reduce conflicts, because it's not clear to the parser generator whether
   13758             :  * to expect alias_clause after ')' or not.  For the same reason we must
   13759             :  * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
   13760             :  * join_type to expand to empty; if we try it, the parser generator can't
   13761             :  * figure out when to reduce an empty join_type right after table_ref.
   13762             :  *
   13763             :  * Note that a CROSS JOIN is the same as an unqualified
   13764             :  * INNER JOIN, and an INNER JOIN/ON has the same shape
   13765             :  * but a qualification expression to limit membership.
   13766             :  * A NATURAL JOIN implicitly matches column names between
   13767             :  * tables and the shape is determined by which columns are
   13768             :  * in common. We'll collect columns during the later transformations.
   13769             :  */
   13770             : 
   13771             : joined_table:
   13772             :             '(' joined_table ')'
   13773             :                 {
   13774        4014 :                     $$ = $2;
   13775             :                 }
   13776             :             | table_ref CROSS JOIN table_ref
   13777             :                 {
   13778             :                     /* CROSS JOIN is same as unqualified inner join */
   13779         502 :                     JoinExpr   *n = makeNode(JoinExpr);
   13780             : 
   13781         502 :                     n->jointype = JOIN_INNER;
   13782         502 :                     n->isNatural = false;
   13783         502 :                     n->larg = $1;
   13784         502 :                     n->rarg = $4;
   13785         502 :                     n->usingClause = NIL;
   13786         502 :                     n->join_using_alias = NULL;
   13787         502 :                     n->quals = NULL;
   13788         502 :                     $$ = n;
   13789             :                 }
   13790             :             | table_ref join_type JOIN table_ref join_qual
   13791             :                 {
   13792       48690 :                     JoinExpr   *n = makeNode(JoinExpr);
   13793             : 
   13794       48690 :                     n->jointype = $2;
   13795       48690 :                     n->isNatural = false;
   13796       48690 :                     n->larg = $1;
   13797       48690 :                     n->rarg = $4;
   13798       48690 :                     if ($5 != NULL && IsA($5, List))
   13799             :                     {
   13800             :                          /* USING clause */
   13801         498 :                         n->usingClause = linitial_node(List, castNode(List, $5));
   13802         498 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $5));
   13803             :                     }
   13804             :                     else
   13805             :                     {
   13806             :                         /* ON clause */
   13807       48192 :                         n->quals = $5;
   13808             :                     }
   13809       48690 :                     $$ = n;
   13810             :                 }
   13811             :             | table_ref JOIN table_ref join_qual
   13812             :                 {
   13813             :                     /* letting join_type reduce to empty doesn't work */
   13814       37174 :                     JoinExpr   *n = makeNode(JoinExpr);
   13815             : 
   13816       37174 :                     n->jointype = JOIN_INNER;
   13817       37174 :                     n->isNatural = false;
   13818       37174 :                     n->larg = $1;
   13819       37174 :                     n->rarg = $3;
   13820       37174 :                     if ($4 != NULL && IsA($4, List))
   13821             :                     {
   13822             :                         /* USING clause */
   13823         752 :                         n->usingClause = linitial_node(List, castNode(List, $4));
   13824         752 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $4));
   13825             :                     }
   13826             :                     else
   13827             :                     {
   13828             :                         /* ON clause */
   13829       36422 :                         n->quals = $4;
   13830             :                     }
   13831       37174 :                     $$ = n;
   13832             :                 }
   13833             :             | table_ref NATURAL join_type JOIN table_ref
   13834             :                 {
   13835          78 :                     JoinExpr   *n = makeNode(JoinExpr);
   13836             : 
   13837          78 :                     n->jointype = $3;
   13838          78 :                     n->isNatural = true;
   13839          78 :                     n->larg = $1;
   13840          78 :                     n->rarg = $5;
   13841          78 :                     n->usingClause = NIL; /* figure out which columns later... */
   13842          78 :                     n->join_using_alias = NULL;
   13843          78 :                     n->quals = NULL; /* fill later */
   13844          78 :                     $$ = n;
   13845             :                 }
   13846             :             | table_ref NATURAL JOIN table_ref
   13847             :                 {
   13848             :                     /* letting join_type reduce to empty doesn't work */
   13849         180 :                     JoinExpr   *n = makeNode(JoinExpr);
   13850             : 
   13851         180 :                     n->jointype = JOIN_INNER;
   13852         180 :                     n->isNatural = true;
   13853         180 :                     n->larg = $1;
   13854         180 :                     n->rarg = $4;
   13855         180 :                     n->usingClause = NIL; /* figure out which columns later... */
   13856         180 :                     n->join_using_alias = NULL;
   13857         180 :                     n->quals = NULL; /* fill later */
   13858         180 :                     $$ = n;
   13859             :                 }
   13860             :         ;
   13861             : 
   13862             : alias_clause:
   13863             :             AS ColId '(' name_list ')'
   13864             :                 {
   13865        7290 :                     $$ = makeNode(Alias);
   13866        7290 :                     $$->aliasname = $2;
   13867        7290 :                     $$->colnames = $4;
   13868             :                 }
   13869             :             | AS ColId
   13870             :                 {
   13871       11004 :                     $$ = makeNode(Alias);
   13872       11004 :                     $$->aliasname = $2;
   13873             :                 }
   13874             :             | ColId '(' name_list ')'
   13875             :                 {
   13876        5820 :                     $$ = makeNode(Alias);
   13877        5820 :                     $$->aliasname = $1;
   13878        5820 :                     $$->colnames = $3;
   13879             :                 }
   13880             :             | ColId
   13881             :                 {
   13882      268202 :                     $$ = makeNode(Alias);
   13883      268202 :                     $$->aliasname = $1;
   13884             :                 }
   13885             :         ;
   13886             : 
   13887      262792 : opt_alias_clause: alias_clause                      { $$ = $1; }
   13888      161156 :             | /*EMPTY*/                             { $$ = NULL; }
   13889             :         ;
   13890             : 
   13891             : /*
   13892             :  * The alias clause after JOIN ... USING only accepts the AS ColId spelling,
   13893             :  * per SQL standard.  (The grammar could parse the other variants, but they
   13894             :  * don't seem to be useful, and it might lead to parser problems in the
   13895             :  * future.)
   13896             :  */
   13897             : opt_alias_clause_for_join_using:
   13898             :             AS ColId
   13899             :                 {
   13900          84 :                     $$ = makeNode(Alias);
   13901          84 :                     $$->aliasname = $2;
   13902             :                     /* the column name list will be inserted later */
   13903             :                 }
   13904        1166 :             | /*EMPTY*/                             { $$ = NULL; }
   13905             :         ;
   13906             : 
   13907             : /*
   13908             :  * func_alias_clause can include both an Alias and a coldeflist, so we make it
   13909             :  * return a 2-element list that gets disassembled by calling production.
   13910             :  */
   13911             : func_alias_clause:
   13912             :             alias_clause
   13913             :                 {
   13914       29350 :                     $$ = list_make2($1, NIL);
   13915             :                 }
   13916             :             | AS '(' TableFuncElementList ')'
   13917             :                 {
   13918         114 :                     $$ = list_make2(NULL, $3);
   13919             :                 }
   13920             :             | AS ColId '(' TableFuncElementList ')'
   13921             :                 {
   13922         596 :                     Alias      *a = makeNode(Alias);
   13923             : 
   13924         596 :                     a->aliasname = $2;
   13925         596 :                     $$ = list_make2(a, $4);
   13926             :                 }
   13927             :             | ColId '(' TableFuncElementList ')'
   13928             :                 {
   13929          50 :                     Alias      *a = makeNode(Alias);
   13930             : 
   13931          50 :                     a->aliasname = $1;
   13932          50 :                     $$ = list_make2(a, $3);
   13933             :                 }
   13934             :             | /*EMPTY*/
   13935             :                 {
   13936       18402 :                     $$ = list_make2(NULL, NIL);
   13937             :                 }
   13938             :         ;
   13939             : 
   13940        1042 : join_type:  FULL opt_outer                          { $$ = JOIN_FULL; }
   13941       43384 :             | LEFT opt_outer                        { $$ = JOIN_LEFT; }
   13942         378 :             | RIGHT opt_outer                       { $$ = JOIN_RIGHT; }
   13943        3964 :             | INNER_P                               { $$ = JOIN_INNER; }
   13944             :         ;
   13945             : 
   13946             : /* OUTER is just noise... */
   13947             : opt_outer: OUTER_P
   13948             :             | /*EMPTY*/
   13949             :         ;
   13950             : 
   13951             : /* JOIN qualification clauses
   13952             :  * Possibilities are:
   13953             :  *  USING ( column list ) [ AS alias ]
   13954             :  *                        allows only unqualified column names,
   13955             :  *                        which must match between tables.
   13956             :  *  ON expr allows more general qualifications.
   13957             :  *
   13958             :  * We return USING as a two-element List (the first item being a sub-List
   13959             :  * of the common column names, and the second either an Alias item or NULL).
   13960             :  * An ON-expr will not be a List, so it can be told apart that way.
   13961             :  */
   13962             : 
   13963             : join_qual: USING '(' name_list ')' opt_alias_clause_for_join_using
   13964             :                 {
   13965        1250 :                     $$ = (Node *) list_make2($3, $5);
   13966             :                 }
   13967             :             | ON a_expr
   13968             :                 {
   13969       84614 :                     $$ = $2;
   13970             :                 }
   13971             :         ;
   13972             : 
   13973             : 
   13974             : relation_expr:
   13975             :             qualified_name
   13976             :                 {
   13977             :                     /* inheritance query, implicitly */
   13978      494958 :                     $$ = $1;
   13979      494958 :                     $$->inh = true;
   13980      494958 :                     $$->alias = NULL;
   13981             :                 }
   13982             :             | extended_relation_expr
   13983             :                 {
   13984        9244 :                     $$ = $1;
   13985             :                 }
   13986             :         ;
   13987             : 
   13988             : extended_relation_expr:
   13989             :             qualified_name '*'
   13990             :                 {
   13991             :                     /* inheritance query, explicitly */
   13992         204 :                     $$ = $1;
   13993         204 :                     $$->inh = true;
   13994         204 :                     $$->alias = NULL;
   13995             :                 }
   13996             :             | ONLY qualified_name
   13997             :                 {
   13998             :                     /* no inheritance */
   13999        9046 :                     $$ = $2;
   14000        9046 :                     $$->inh = false;
   14001        9046 :                     $$->alias = NULL;
   14002             :                 }
   14003             :             | ONLY '(' qualified_name ')'
   14004             :                 {
   14005             :                     /* no inheritance, SQL99-style syntax */
   14006           0 :                     $$ = $3;
   14007           0 :                     $$->inh = false;
   14008           0 :                     $$->alias = NULL;
   14009             :                 }
   14010             :         ;
   14011             : 
   14012             : 
   14013             : relation_expr_list:
   14014        5492 :             relation_expr                           { $$ = list_make1($1); }
   14015       15756 :             | relation_expr_list ',' relation_expr  { $$ = lappend($1, $3); }
   14016             :         ;
   14017             : 
   14018             : 
   14019             : /*
   14020             :  * Given "UPDATE foo set set ...", we have to decide without looking any
   14021             :  * further ahead whether the first "set" is an alias or the UPDATE's SET
   14022             :  * keyword.  Since "set" is allowed as a column name both interpretations
   14023             :  * are feasible.  We resolve the shift/reduce conflict by giving the first
   14024             :  * relation_expr_opt_alias production a higher precedence than the SET token
   14025             :  * has, causing the parser to prefer to reduce, in effect assuming that the
   14026             :  * SET is not an alias.
   14027             :  */
   14028             : relation_expr_opt_alias: relation_expr                  %prec UMINUS
   14029             :                 {
   14030       18472 :                     $$ = $1;
   14031             :                 }
   14032             :             | relation_expr ColId
   14033             :                 {
   14034        2222 :                     Alias      *alias = makeNode(Alias);
   14035             : 
   14036        2222 :                     alias->aliasname = $2;
   14037        2222 :                     $1->alias = alias;
   14038        2222 :                     $$ = $1;
   14039             :                 }
   14040             :             | relation_expr AS ColId
   14041             :                 {
   14042          90 :                     Alias      *alias = makeNode(Alias);
   14043             : 
   14044          90 :                     alias->aliasname = $3;
   14045          90 :                     $1->alias = alias;
   14046          90 :                     $$ = $1;
   14047             :                 }
   14048             :         ;
   14049             : 
   14050             : /*
   14051             :  * TABLESAMPLE decoration in a FROM item
   14052             :  */
   14053             : tablesample_clause:
   14054             :             TABLESAMPLE func_name '(' expr_list ')' opt_repeatable_clause
   14055             :                 {
   14056         264 :                     RangeTableSample *n = makeNode(RangeTableSample);
   14057             : 
   14058             :                     /* n->relation will be filled in later */
   14059         264 :                     n->method = $2;
   14060         264 :                     n->args = $4;
   14061         264 :                     n->repeatable = $6;
   14062         264 :                     n->location = @2;
   14063         264 :                     $$ = (Node *) n;
   14064             :                 }
   14065             :         ;
   14066             : 
   14067             : opt_repeatable_clause:
   14068         110 :             REPEATABLE '(' a_expr ')'   { $$ = (Node *) $3; }
   14069         154 :             | /*EMPTY*/                 { $$ = NULL; }
   14070             :         ;
   14071             : 
   14072             : /*
   14073             :  * func_table represents a function invocation in a FROM list. It can be
   14074             :  * a plain function call, like "foo(...)", or a ROWS FROM expression with
   14075             :  * one or more function calls, "ROWS FROM (foo(...), bar(...))",
   14076             :  * optionally with WITH ORDINALITY attached.
   14077             :  * In the ROWS FROM syntax, a column definition list can be given for each
   14078             :  * function, for example:
   14079             :  *     ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
   14080             :  *                bar() AS (bar_res_a text, bar_res_b text))
   14081             :  * It's also possible to attach a column definition list to the RangeFunction
   14082             :  * as a whole, but that's handled by the table_ref production.
   14083             :  */
   14084             : func_table: func_expr_windowless opt_ordinality
   14085             :                 {
   14086       48386 :                     RangeFunction *n = makeNode(RangeFunction);
   14087             : 
   14088       48386 :                     n->lateral = false;
   14089       48386 :                     n->ordinality = $2;
   14090       48386 :                     n->is_rowsfrom = false;
   14091       48386 :                     n->functions = list_make1(list_make2($1, NIL));
   14092             :                     /* alias and coldeflist are set by table_ref production */
   14093       48386 :                     $$ = (Node *) n;
   14094             :                 }
   14095             :             | ROWS FROM '(' rowsfrom_list ')' opt_ordinality
   14096             :                 {
   14097         132 :                     RangeFunction *n = makeNode(RangeFunction);
   14098             : 
   14099         132 :                     n->lateral = false;
   14100         132 :                     n->ordinality = $6;
   14101         132 :                     n->is_rowsfrom = true;
   14102         132 :                     n->functions = $4;
   14103             :                     /* alias and coldeflist are set by table_ref production */
   14104         132 :                     $$ = (Node *) n;
   14105             :                 }
   14106             :         ;
   14107             : 
   14108             : rowsfrom_item: func_expr_windowless opt_col_def_list
   14109         318 :                 { $$ = list_make2($1, $2); }
   14110             :         ;
   14111             : 
   14112             : rowsfrom_list:
   14113         132 :             rowsfrom_item                       { $$ = list_make1($1); }
   14114         186 :             | rowsfrom_list ',' rowsfrom_item   { $$ = lappend($1, $3); }
   14115             :         ;
   14116             : 
   14117          54 : opt_col_def_list: AS '(' TableFuncElementList ')'   { $$ = $3; }
   14118         264 :             | /*EMPTY*/                             { $$ = NIL; }
   14119             :         ;
   14120             : 
   14121         908 : opt_ordinality: WITH_LA ORDINALITY                  { $$ = true; }
   14122       47610 :             | /*EMPTY*/                             { $$ = false; }
   14123             :         ;
   14124             : 
   14125             : 
   14126             : where_clause:
   14127      215858 :             WHERE a_expr                            { $$ = $2; }
   14128      291388 :             | /*EMPTY*/                             { $$ = NULL; }
   14129             :         ;
   14130             : 
   14131             : /* variant for UPDATE and DELETE */
   14132             : where_or_current_clause:
   14133       13368 :             WHERE a_expr                            { $$ = $2; }
   14134             :             | WHERE CURRENT_P OF cursor_name
   14135             :                 {
   14136         266 :                     CurrentOfExpr *n = makeNode(CurrentOfExpr);
   14137             : 
   14138             :                     /* cvarno is filled in by parse analysis */
   14139         266 :                     n->cursor_name = $4;
   14140         266 :                     n->cursor_param = 0;
   14141         266 :                     $$ = (Node *) n;
   14142             :                 }
   14143        5014 :             | /*EMPTY*/                             { $$ = NULL; }
   14144             :         ;
   14145             : 
   14146             : 
   14147             : OptTableFuncElementList:
   14148         748 :             TableFuncElementList                { $$ = $1; }
   14149        3786 :             | /*EMPTY*/                         { $$ = NIL; }
   14150             :         ;
   14151             : 
   14152             : TableFuncElementList:
   14153             :             TableFuncElement
   14154             :                 {
   14155        1562 :                     $$ = list_make1($1);
   14156             :                 }
   14157             :             | TableFuncElementList ',' TableFuncElement
   14158             :                 {
   14159        2102 :                     $$ = lappend($1, $3);
   14160             :                 }
   14161             :         ;
   14162             : 
   14163             : TableFuncElement:   ColId Typename opt_collate_clause
   14164             :                 {
   14165        3728 :                     ColumnDef *n = makeNode(ColumnDef);
   14166             : 
   14167        3728 :                     n->colname = $1;
   14168        3728 :                     n->typeName = $2;
   14169        3728 :                     n->inhcount = 0;
   14170        3728 :                     n->is_local = true;
   14171        3728 :                     n->is_not_null = false;
   14172        3728 :                     n->is_from_type = false;
   14173        3728 :                     n->storage = 0;
   14174        3728 :                     n->raw_default = NULL;
   14175        3728 :                     n->cooked_default = NULL;
   14176        3728 :                     n->collClause = (CollateClause *) $3;
   14177        3728 :                     n->collOid = InvalidOid;
   14178        3728 :                     n->constraints = NIL;
   14179        3728 :                     n->location = @1;
   14180        3728 :                     $$ = (Node *) n;
   14181             :                 }
   14182             :         ;
   14183             : 
   14184             : /*
   14185             :  * XMLTABLE
   14186             :  */
   14187             : xmltable:
   14188             :             XMLTABLE '(' c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   14189             :                 {
   14190         202 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   14191             : 
   14192         202 :                     n->rowexpr = $3;
   14193         202 :                     n->docexpr = $4;
   14194         202 :                     n->columns = $6;
   14195         202 :                     n->namespaces = NIL;
   14196         202 :                     n->location = @1;
   14197         202 :                     $$ = (Node *) n;
   14198             :                 }
   14199             :             | XMLTABLE '(' XMLNAMESPACES '(' xml_namespace_list ')' ','
   14200             :                 c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   14201             :                 {
   14202          22 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   14203             : 
   14204          22 :                     n->rowexpr = $8;
   14205          22 :                     n->docexpr = $9;
   14206          22 :                     n->columns = $11;
   14207          22 :                     n->namespaces = $5;
   14208          22 :                     n->location = @1;
   14209          22 :                     $$ = (Node *) n;
   14210             :                 }
   14211             :         ;
   14212             : 
   14213         224 : xmltable_column_list: xmltable_column_el                    { $$ = list_make1($1); }
   14214         544 :             | xmltable_column_list ',' xmltable_column_el   { $$ = lappend($1, $3); }
   14215             :         ;
   14216             : 
   14217             : xmltable_column_el:
   14218             :             ColId Typename
   14219             :                 {
   14220         198 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14221             : 
   14222         198 :                     fc->colname = $1;
   14223         198 :                     fc->for_ordinality = false;
   14224         198 :                     fc->typeName = $2;
   14225         198 :                     fc->is_not_null = false;
   14226         198 :                     fc->colexpr = NULL;
   14227         198 :                     fc->coldefexpr = NULL;
   14228         198 :                     fc->location = @1;
   14229             : 
   14230         198 :                     $$ = (Node *) fc;
   14231             :                 }
   14232             :             | ColId Typename xmltable_column_option_list
   14233             :                 {
   14234         506 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14235             :                     ListCell   *option;
   14236         506 :                     bool        nullability_seen = false;
   14237             : 
   14238         506 :                     fc->colname = $1;
   14239         506 :                     fc->typeName = $2;
   14240         506 :                     fc->for_ordinality = false;
   14241         506 :                     fc->is_not_null = false;
   14242         506 :                     fc->colexpr = NULL;
   14243         506 :                     fc->coldefexpr = NULL;
   14244         506 :                     fc->location = @1;
   14245             : 
   14246        1128 :                     foreach(option, $3)
   14247             :                     {
   14248         622 :                         DefElem   *defel = (DefElem *) lfirst(option);
   14249             : 
   14250         622 :                         if (strcmp(defel->defname, "default") == 0)
   14251             :                         {
   14252          58 :                             if (fc->coldefexpr != NULL)
   14253           0 :                                 ereport(ERROR,
   14254             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14255             :                                          errmsg("only one DEFAULT value is allowed"),
   14256             :                                          parser_errposition(defel->location)));
   14257          58 :                             fc->coldefexpr = defel->arg;
   14258             :                         }
   14259         564 :                         else if (strcmp(defel->defname, "path") == 0)
   14260             :                         {
   14261         506 :                             if (fc->colexpr != NULL)
   14262           0 :                                 ereport(ERROR,
   14263             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14264             :                                          errmsg("only one PATH value per column is allowed"),
   14265             :                                          parser_errposition(defel->location)));
   14266         506 :                             fc->colexpr = defel->arg;
   14267             :                         }
   14268          58 :                         else if (strcmp(defel->defname, "__pg__is_not_null") == 0)
   14269             :                         {
   14270          58 :                             if (nullability_seen)
   14271           0 :                                 ereport(ERROR,
   14272             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14273             :                                          errmsg("conflicting or redundant NULL / NOT NULL declarations for column \"%s\"", fc->colname),
   14274             :                                          parser_errposition(defel->location)));
   14275          58 :                             fc->is_not_null = boolVal(defel->arg);
   14276          58 :                             nullability_seen = true;
   14277             :                         }
   14278             :                         else
   14279             :                         {
   14280           0 :                             ereport(ERROR,
   14281             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   14282             :                                      errmsg("unrecognized column option \"%s\"",
   14283             :                                             defel->defname),
   14284             :                                      parser_errposition(defel->location)));
   14285             :                         }
   14286             :                     }
   14287         506 :                     $$ = (Node *) fc;
   14288             :                 }
   14289             :             | ColId FOR ORDINALITY
   14290             :                 {
   14291          64 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14292             : 
   14293          64 :                     fc->colname = $1;
   14294          64 :                     fc->for_ordinality = true;
   14295             :                     /* other fields are ignored, initialized by makeNode */
   14296          64 :                     fc->location = @1;
   14297             : 
   14298          64 :                     $$ = (Node *) fc;
   14299             :                 }
   14300             :         ;
   14301             : 
   14302             : xmltable_column_option_list:
   14303             :             xmltable_column_option_el
   14304         506 :                 { $$ = list_make1($1); }
   14305             :             | xmltable_column_option_list xmltable_column_option_el
   14306         116 :                 { $$ = lappend($1, $2); }
   14307             :         ;
   14308             : 
   14309             : xmltable_column_option_el:
   14310             :             IDENT b_expr
   14311             :                 {
   14312           6 :                     if (strcmp($1, "__pg__is_not_null") == 0)
   14313           6 :                         ereport(ERROR,
   14314             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   14315             :                                  errmsg("option name \"%s\" cannot be used in XMLTABLE", $1),
   14316             :                                  parser_errposition(@1)));
   14317           0 :                     $$ = makeDefElem($1, $2, @1);
   14318             :                 }
   14319             :             | DEFAULT b_expr
   14320          58 :                 { $$ = makeDefElem("default", $2, @1); }
   14321             :             | NOT NULL_P
   14322          58 :                 { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(true), @1); }
   14323             :             | NULL_P
   14324           0 :                 { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(false), @1); }
   14325             :             | PATH b_expr
   14326         506 :                 { $$ = makeDefElem("path", $2, @1); }
   14327             :         ;
   14328             : 
   14329             : xml_namespace_list:
   14330             :             xml_namespace_el
   14331          22 :                 { $$ = list_make1($1); }
   14332             :             | xml_namespace_list ',' xml_namespace_el
   14333           0 :                 { $$ = lappend($1, $3); }
   14334             :         ;
   14335             : 
   14336             : xml_namespace_el:
   14337             :             b_expr AS ColLabel
   14338             :                 {
   14339          16 :                     $$ = makeNode(ResTarget);
   14340          16 :                     $$->name = $3;
   14341          16 :                     $$->indirection = NIL;
   14342          16 :                     $$->val = $1;
   14343          16 :                     $$->location = @1;
   14344             :                 }
   14345             :             | DEFAULT b_expr
   14346             :                 {
   14347           6 :                     $$ = makeNode(ResTarget);
   14348           6 :                     $$->name = NULL;
   14349           6 :                     $$->indirection = NIL;
   14350           6 :                     $$->val = $2;
   14351           6 :                     $$->location = @1;
   14352             :                 }
   14353             :         ;
   14354             : 
   14355             : json_table:
   14356             :             JSON_TABLE '('
   14357             :                 json_value_expr ',' a_expr json_table_path_name_opt
   14358             :                 json_passing_clause_opt
   14359             :                 COLUMNS '(' json_table_column_definition_list ')'
   14360             :                 json_on_error_clause_opt
   14361             :             ')'
   14362             :                 {
   14363         530 :                     JsonTable *n = makeNode(JsonTable);
   14364             :                     char      *pathstring;
   14365             : 
   14366         530 :                     n->context_item = (JsonValueExpr *) $3;
   14367         530 :                     if (!IsA($5, A_Const) ||
   14368         524 :                         castNode(A_Const, $5)->val.node.type != T_String)
   14369           6 :                         ereport(ERROR,
   14370             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   14371             :                                 errmsg("only string constants are supported in JSON_TABLE path specification"),
   14372             :                                 parser_errposition(@5));
   14373         524 :                     pathstring = castNode(A_Const, $5)->val.sval.sval;
   14374         524 :                     n->pathspec = makeJsonTablePathSpec(pathstring, $6, @5, @6);
   14375         524 :                     n->passing = $7;
   14376         524 :                     n->columns = $10;
   14377         524 :                     n->on_error = (JsonBehavior *) $12;
   14378         524 :                     n->location = @1;
   14379         524 :                     $$ = (Node *) n;
   14380             :                 }
   14381             :         ;
   14382             : 
   14383             : json_table_path_name_opt:
   14384          62 :             AS name         { $$ = $2; }
   14385         480 :             | /* empty */   { $$ = NULL; }
   14386             :         ;
   14387             : 
   14388             : json_table_column_definition_list:
   14389             :             json_table_column_definition
   14390         820 :                 { $$ = list_make1($1); }
   14391             :             | json_table_column_definition_list ',' json_table_column_definition
   14392         528 :                 { $$ = lappend($1, $3); }
   14393             :         ;
   14394             : 
   14395             : json_table_column_definition:
   14396             :             ColId FOR ORDINALITY
   14397             :                 {
   14398          84 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14399             : 
   14400          84 :                     n->coltype = JTC_FOR_ORDINALITY;
   14401          84 :                     n->name = $1;
   14402          84 :                     n->location = @1;
   14403          84 :                     $$ = (Node *) n;
   14404             :                 }
   14405             :             | ColId Typename
   14406             :                 json_table_column_path_clause_opt
   14407             :                 json_wrapper_behavior
   14408             :                 json_quotes_clause_opt
   14409             :                 json_behavior_clause_opt
   14410             :                 {
   14411         728 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14412             : 
   14413         728 :                     n->coltype = JTC_REGULAR;
   14414         728 :                     n->name = $1;
   14415         728 :                     n->typeName = $2;
   14416         728 :                     n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   14417         728 :                     n->pathspec = (JsonTablePathSpec *) $3;
   14418         728 :                     n->wrapper = $4;
   14419         728 :                     n->quotes = $5;
   14420         728 :                     n->on_empty = (JsonBehavior *) linitial($6);
   14421         728 :                     n->on_error = (JsonBehavior *) lsecond($6);
   14422         728 :                     n->location = @1;
   14423         728 :                     $$ = (Node *) n;
   14424             :                 }
   14425             :             | ColId Typename json_format_clause
   14426             :                 json_table_column_path_clause_opt
   14427             :                 json_wrapper_behavior
   14428             :                 json_quotes_clause_opt
   14429             :                 json_behavior_clause_opt
   14430             :                 {
   14431         108 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14432             : 
   14433         108 :                     n->coltype = JTC_FORMATTED;
   14434         108 :                     n->name = $1;
   14435         108 :                     n->typeName = $2;
   14436         108 :                     n->format = (JsonFormat *) $3;
   14437         108 :                     n->pathspec = (JsonTablePathSpec *) $4;
   14438         108 :                     n->wrapper = $5;
   14439         108 :                     n->quotes = $6;
   14440         108 :                     n->on_empty = (JsonBehavior *) linitial($7);
   14441         108 :                     n->on_error = (JsonBehavior *) lsecond($7);
   14442         108 :                     n->location = @1;
   14443         108 :                     $$ = (Node *) n;
   14444             :                 }
   14445             :             | ColId Typename
   14446             :                 EXISTS json_table_column_path_clause_opt
   14447             :                 json_on_error_clause_opt
   14448             :                 {
   14449         138 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14450             : 
   14451         138 :                     n->coltype = JTC_EXISTS;
   14452         138 :                     n->name = $1;
   14453         138 :                     n->typeName = $2;
   14454         138 :                     n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   14455         138 :                     n->wrapper = JSW_NONE;
   14456         138 :                     n->quotes = JS_QUOTES_UNSPEC;
   14457         138 :                     n->pathspec = (JsonTablePathSpec *) $4;
   14458         138 :                     n->on_empty = NULL;
   14459         138 :                     n->on_error = (JsonBehavior *) $5;
   14460         138 :                     n->location = @1;
   14461         138 :                     $$ = (Node *) n;
   14462             :                 }
   14463             :             | NESTED path_opt Sconst
   14464             :                 COLUMNS '(' json_table_column_definition_list ')'
   14465             :                 {
   14466         144 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14467             : 
   14468         144 :                     n->coltype = JTC_NESTED;
   14469         288 :                     n->pathspec = (JsonTablePathSpec *)
   14470         144 :                         makeJsonTablePathSpec($3, NULL, @3, -1);
   14471         144 :                     n->columns = $6;
   14472         144 :                     n->location = @1;
   14473         144 :                     $$ = (Node *) n;
   14474             :                 }
   14475             :             | NESTED path_opt Sconst AS name
   14476             :                 COLUMNS '(' json_table_column_definition_list ')'
   14477             :                 {
   14478         146 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14479             : 
   14480         146 :                     n->coltype = JTC_NESTED;
   14481         292 :                     n->pathspec = (JsonTablePathSpec *)
   14482         146 :                         makeJsonTablePathSpec($3, $5, @3, @5);
   14483         146 :                     n->columns = $8;
   14484         146 :                     n->location = @1;
   14485         146 :                     $$ = (Node *) n;
   14486             :                 }
   14487             :         ;
   14488             : 
   14489             : path_opt:
   14490             :             PATH
   14491             :             | /* EMPTY */
   14492             :         ;
   14493             : 
   14494             : json_table_column_path_clause_opt:
   14495             :             PATH Sconst
   14496         828 :                 { $$ = (Node *) makeJsonTablePathSpec($2, NULL, @2, -1); }
   14497             :             | /* EMPTY */
   14498         152 :                 { $$ = NULL; }
   14499             :         ;
   14500             : 
   14501             : /*****************************************************************************
   14502             :  *
   14503             :  *  Type syntax
   14504             :  *      SQL introduces a large amount of type-specific syntax.
   14505             :  *      Define individual clauses to handle these cases, and use
   14506             :  *       the generic case to handle regular type-extensible Postgres syntax.
   14507             :  *      - thomas 1997-10-10
   14508             :  *
   14509             :  *****************************************************************************/
   14510             : 
   14511             : Typename:   SimpleTypename opt_array_bounds
   14512             :                 {
   14513      524382 :                     $$ = $1;
   14514      524382 :                     $$->arrayBounds = $2;
   14515             :                 }
   14516             :             | SETOF SimpleTypename opt_array_bounds
   14517             :                 {
   14518        2350 :                     $$ = $2;
   14519        2350 :                     $$->arrayBounds = $3;
   14520        2350 :                     $$->setof = true;
   14521             :                 }
   14522             :             /* SQL standard syntax, currently only one-dimensional */
   14523             :             | SimpleTypename ARRAY '[' Iconst ']'
   14524             :                 {
   14525           6 :                     $$ = $1;
   14526           6 :                     $$->arrayBounds = list_make1(makeInteger($4));
   14527             :                 }
   14528             :             | SETOF SimpleTypename ARRAY '[' Iconst ']'
   14529             :                 {
   14530           0 :                     $$ = $2;
   14531           0 :                     $$->arrayBounds = list_make1(makeInteger($5));
   14532           0 :                     $$->setof = true;
   14533             :                 }
   14534             :             | SimpleTypename ARRAY
   14535             :                 {
   14536           0 :                     $$ = $1;
   14537           0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   14538             :                 }
   14539             :             | SETOF SimpleTypename ARRAY
   14540             :                 {
   14541           0 :                     $$ = $2;
   14542           0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   14543           0 :                     $$->setof = true;
   14544             :                 }
   14545             :         ;
   14546             : 
   14547             : opt_array_bounds:
   14548             :             opt_array_bounds '[' ']'
   14549       15288 :                     {  $$ = lappend($1, makeInteger(-1)); }
   14550             :             | opt_array_bounds '[' Iconst ']'
   14551          62 :                     {  $$ = lappend($1, makeInteger($3)); }
   14552             :             | /*EMPTY*/
   14553      526732 :                     {  $$ = NIL; }
   14554             :         ;
   14555             : 
   14556             : SimpleTypename:
   14557      409386 :             GenericType                             { $$ = $1; }
   14558      101842 :             | Numeric                               { $$ = $1; }
   14559        1926 :             | Bit                                   { $$ = $1; }
   14560        3230 :             | Character                             { $$ = $1; }
   14561        5120 :             | ConstDatetime                         { $$ = $1; }
   14562             :             | ConstInterval opt_interval
   14563             :                 {
   14564        3788 :                     $$ = $1;
   14565        3788 :                     $$->typmods = $2;
   14566             :                 }
   14567             :             | ConstInterval '(' Iconst ')'
   14568             :                 {
   14569           0 :                     $$ = $1;
   14570           0 :                     $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   14571             :                                              makeIntConst($3, @3));
   14572             :                 }
   14573        1908 :             | JsonType                              { $$ = $1; }
   14574             :         ;
   14575             : 
   14576             : /* We have a separate ConstTypename to allow defaulting fixed-length
   14577             :  * types such as CHAR() and BIT() to an unspecified length.
   14578             :  * SQL9x requires that these default to a length of one, but this
   14579             :  * makes no sense for constructs like CHAR 'hi' and BIT '0101',
   14580             :  * where there is an obvious better choice to make.
   14581             :  * Note that ConstInterval is not included here since it must
   14582             :  * be pushed up higher in the rules to accommodate the postfix
   14583             :  * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
   14584             :  * the generic-type-name case in AexprConst to avoid premature
   14585             :  * reduce/reduce conflicts against function names.
   14586             :  */
   14587             : ConstTypename:
   14588          78 :             Numeric                                 { $$ = $1; }
   14589           0 :             | ConstBit                              { $$ = $1; }
   14590          34 :             | ConstCharacter                        { $$ = $1; }
   14591        2750 :             | ConstDatetime                         { $$ = $1; }
   14592         264 :             | JsonType                              { $$ = $1; }
   14593             :         ;
   14594             : 
   14595             : /*
   14596             :  * GenericType covers all type names that don't have special syntax mandated
   14597             :  * by the standard, including qualified names.  We also allow type modifiers.
   14598             :  * To avoid parsing conflicts against function invocations, the modifiers
   14599             :  * have to be shown as expr_list here, but parse analysis will only accept
   14600             :  * constants for them.
   14601             :  */
   14602             : GenericType:
   14603             :             type_function_name opt_type_modifiers
   14604             :                 {
   14605      289098 :                     $$ = makeTypeName($1);
   14606      289098 :                     $$->typmods = $2;
   14607      289098 :                     $$->location = @1;
   14608             :                 }
   14609             :             | type_function_name attrs opt_type_modifiers
   14610             :                 {
   14611      120288 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
   14612      120288 :                     $$->typmods = $3;
   14613      120288 :                     $$->location = @1;
   14614             :                 }
   14615             :         ;
   14616             : 
   14617        1396 : opt_type_modifiers: '(' expr_list ')'               { $$ = $2; }
   14618      414212 :                     | /* EMPTY */                   { $$ = NIL; }
   14619             :         ;
   14620             : 
   14621             : /*
   14622             :  * SQL numeric data types
   14623             :  */
   14624             : Numeric:    INT_P
   14625             :                 {
   14626       38260 :                     $$ = SystemTypeName("int4");
   14627       38260 :                     $$->location = @1;
   14628             :                 }
   14629             :             | INTEGER
   14630             :                 {
   14631       27372 :                     $$ = SystemTypeName("int4");
   14632       27372 :                     $$->location = @1;
   14633             :                 }
   14634             :             | SMALLINT
   14635             :                 {
   14636        1306 :                     $$ = SystemTypeName("int2");
   14637        1306 :                     $$->location = @1;
   14638             :                 }
   14639             :             | BIGINT
   14640             :                 {
   14641        5360 :                     $$ = SystemTypeName("int8");
   14642        5360 :                     $$->location = @1;
   14643             :                 }
   14644             :             | REAL
   14645             :                 {
   14646        6890 :                     $$ = SystemTypeName("float4");
   14647        6890 :                     $$->location = @1;
   14648             :                 }
   14649             :             | FLOAT_P opt_float
   14650             :                 {
   14651         538 :                     $$ = $2;
   14652         538 :                     $$->location = @1;
   14653             :                 }
   14654             :             | DOUBLE_P PRECISION
   14655             :                 {
   14656         930 :                     $$ = SystemTypeName("float8");
   14657         930 :                     $$->location = @1;
   14658             :                 }
   14659             :             | DECIMAL_P opt_type_modifiers
   14660             :                 {
   14661          36 :                     $$ = SystemTypeName("numeric");
   14662          36 :                     $$->typmods = $2;
   14663          36 :                     $$->location = @1;
   14664             :                 }
   14665             :             | DEC opt_type_modifiers
   14666             :                 {
   14667           0 :                     $$ = SystemTypeName("numeric");
   14668           0 :                     $$->typmods = $2;
   14669           0 :                     $$->location = @1;
   14670             :                 }
   14671             :             | NUMERIC opt_type_modifiers
   14672             :                 {
   14673        6186 :                     $$ = SystemTypeName("numeric");
   14674        6186 :                     $$->typmods = $2;
   14675        6186 :                     $$->location = @1;
   14676             :                 }
   14677             :             | BOOLEAN_P
   14678             :                 {
   14679       15042 :                     $$ = SystemTypeName("bool");
   14680       15042 :                     $$->location = @1;
   14681             :                 }
   14682             :         ;
   14683             : 
   14684             : opt_float:  '(' Iconst ')'
   14685             :                 {
   14686             :                     /*
   14687             :                      * Check FLOAT() precision limits assuming IEEE floating
   14688             :                      * types - thomas 1997-09-18
   14689             :                      */
   14690           2 :                     if ($2 < 1)
   14691           0 :                         ereport(ERROR,
   14692             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   14693             :                                  errmsg("precision for type float must be at least 1 bit"),
   14694             :                                  parser_errposition(@2)));
   14695           2 :                     else if ($2 <= 24)
   14696           2 :                         $$ = SystemTypeName("float4");
   14697           0 :                     else if ($2 <= 53)
   14698           0 :                         $$ = SystemTypeName("float8");
   14699             :                     else
   14700           0 :                         ereport(ERROR,
   14701             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   14702             :                                  errmsg("precision for type float must be less than 54 bits"),
   14703             :                                  parser_errposition(@2)));
   14704             :                 }
   14705             :             | /*EMPTY*/
   14706             :                 {
   14707         536 :                     $$ = SystemTypeName("float8");
   14708             :                 }
   14709             :         ;
   14710             : 
   14711             : /*
   14712             :  * SQL bit-field data types
   14713             :  * The following implements BIT() and BIT VARYING().
   14714             :  */
   14715             : Bit:        BitWithLength
   14716             :                 {
   14717        1710 :                     $$ = $1;
   14718             :                 }
   14719             :             | BitWithoutLength
   14720             :                 {
   14721         216 :                     $$ = $1;
   14722             :                 }
   14723             :         ;
   14724             : 
   14725             : /* ConstBit is like Bit except "BIT" defaults to unspecified length */
   14726             : /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
   14727             : ConstBit:   BitWithLength
   14728             :                 {
   14729           0 :                     $$ = $1;
   14730             :                 }
   14731             :             | BitWithoutLength
   14732             :                 {
   14733           0 :                     $$ = $1;
   14734           0 :                     $$->typmods = NIL;
   14735             :                 }
   14736             :         ;
   14737             : 
   14738             : BitWithLength:
   14739             :             BIT opt_varying '(' expr_list ')'
   14740             :                 {
   14741             :                     char *typname;
   14742             : 
   14743        1710 :                     typname = $2 ? "varbit" : "bit";
   14744        1710 :                     $$ = SystemTypeName(typname);
   14745        1710 :                     $$->typmods = $4;
   14746        1710 :                     $$->location = @1;
   14747             :                 }
   14748             :         ;
   14749             : 
   14750             : BitWithoutLength:
   14751             :             BIT opt_varying
   14752             :                 {
   14753             :                     /* bit defaults to bit(1), varbit to no limit */
   14754         216 :                     if ($2)
   14755             :                     {
   14756          26 :                         $$ = SystemTypeName("varbit");
   14757             :                     }
   14758             :                     else
   14759             :                     {
   14760         190 :                         $$ = SystemTypeName("bit");
   14761         190 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   14762             :                     }
   14763         216 :                     $$->location = @1;
   14764             :                 }
   14765             :         ;
   14766             : 
   14767             : 
   14768             : /*
   14769             :  * SQL character data types
   14770             :  * The following implements CHAR() and VARCHAR().
   14771             :  */
   14772             : Character:  CharacterWithLength
   14773             :                 {
   14774        1838 :                     $$ = $1;
   14775             :                 }
   14776             :             | CharacterWithoutLength
   14777             :                 {
   14778        1392 :                     $$ = $1;
   14779             :                 }
   14780             :         ;
   14781             : 
   14782             : ConstCharacter:  CharacterWithLength
   14783             :                 {
   14784          12 :                     $$ = $1;
   14785             :                 }
   14786             :             | CharacterWithoutLength
   14787             :                 {
   14788             :                     /* Length was not specified so allow to be unrestricted.
   14789             :                      * This handles problems with fixed-length (bpchar) strings
   14790             :                      * which in column definitions must default to a length
   14791             :                      * of one, but should not be constrained if the length
   14792             :                      * was not specified.
   14793             :                      */
   14794          22 :                     $$ = $1;
   14795          22 :                     $$->typmods = NIL;
   14796             :                 }
   14797             :         ;
   14798             : 
   14799             : CharacterWithLength:  character '(' Iconst ')'
   14800             :                 {
   14801        1850 :                     $$ = SystemTypeName($1);
   14802        1850 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14803        1850 :                     $$->location = @1;
   14804             :                 }
   14805             :         ;
   14806             : 
   14807             : CharacterWithoutLength:  character
   14808             :                 {
   14809        1414 :                     $$ = SystemTypeName($1);
   14810             :                     /* char defaults to char(1), varchar to no limit */
   14811        1414 :                     if (strcmp($1, "bpchar") == 0)
   14812         300 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   14813        1414 :                     $$->location = @1;
   14814             :                 }
   14815             :         ;
   14816             : 
   14817             : character:  CHARACTER opt_varying
   14818         788 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14819             :             | CHAR_P opt_varying
   14820        1172 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14821             :             | VARCHAR
   14822        1300 :                                         { $$ = "varchar"; }
   14823             :             | NATIONAL CHARACTER opt_varying
   14824           0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   14825             :             | NATIONAL CHAR_P opt_varying
   14826           0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   14827             :             | NCHAR opt_varying
   14828           4 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14829             :         ;
   14830             : 
   14831             : opt_varying:
   14832         554 :             VARYING                                 { $$ = true; }
   14833        3336 :             | /*EMPTY*/                             { $$ = false; }
   14834             :         ;
   14835             : 
   14836             : /*
   14837             :  * SQL date/time types
   14838             :  */
   14839             : ConstDatetime:
   14840             :             TIMESTAMP '(' Iconst ')' opt_timezone
   14841             :                 {
   14842         140 :                     if ($5)
   14843         114 :                         $$ = SystemTypeName("timestamptz");
   14844             :                     else
   14845          26 :                         $$ = SystemTypeName("timestamp");
   14846         140 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14847         140 :                     $$->location = @1;
   14848             :                 }
   14849             :             | TIMESTAMP opt_timezone
   14850             :                 {
   14851        5188 :                     if ($2)
   14852        1398 :                         $$ = SystemTypeName("timestamptz");
   14853             :                     else
   14854        3790 :                         $$ = SystemTypeName("timestamp");
   14855        5188 :                     $$->location = @1;
   14856             :                 }
   14857             :             | TIME '(' Iconst ')' opt_timezone
   14858             :                 {
   14859          26 :                     if ($5)
   14860          10 :                         $$ = SystemTypeName("timetz");
   14861             :                     else
   14862          16 :                         $$ = SystemTypeName("time");
   14863          26 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14864          26 :                     $$->location = @1;
   14865             :                 }
   14866             :             | TIME opt_timezone
   14867             :                 {
   14868        2516 :                     if ($2)
   14869         354 :                         $$ = SystemTypeName("timetz");
   14870             :                     else
   14871        2162 :                         $$ = SystemTypeName("time");
   14872        2516 :                     $$->location = @1;
   14873             :                 }
   14874             :         ;
   14875             : 
   14876             : ConstInterval:
   14877             :             INTERVAL
   14878             :                 {
   14879        7098 :                     $$ = SystemTypeName("interval");
   14880        7098 :                     $$->location = @1;
   14881             :                 }
   14882             :         ;
   14883             : 
   14884             : opt_timezone:
   14885        1876 :             WITH_LA TIME ZONE                       { $$ = true; }
   14886         628 :             | WITHOUT_LA TIME ZONE                  { $$ = false; }
   14887        5366 :             | /*EMPTY*/                             { $$ = false; }
   14888             :         ;
   14889             : 
   14890             : opt_interval:
   14891             :             YEAR_P
   14892          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
   14893             :             | MONTH_P
   14894          18 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
   14895             :             | DAY_P
   14896          18 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
   14897             :             | HOUR_P
   14898          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
   14899             :             | MINUTE_P
   14900          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
   14901             :             | interval_second
   14902          36 :                 { $$ = $1; }
   14903             :             | YEAR_P TO MONTH_P
   14904             :                 {
   14905          18 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
   14906             :                                                  INTERVAL_MASK(MONTH), @1));
   14907             :                 }
   14908             :             | DAY_P TO HOUR_P
   14909             :                 {
   14910          24 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   14911             :                                                  INTERVAL_MASK(HOUR), @1));
   14912             :                 }
   14913             :             | DAY_P TO MINUTE_P
   14914             :                 {
   14915          24 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   14916             :                                                  INTERVAL_MASK(HOUR) |
   14917             :                                                  INTERVAL_MASK(MINUTE), @1));
   14918             :                 }
   14919             :             | DAY_P TO interval_second
   14920             :                 {
   14921          48 :                     $$ = $3;
   14922          48 :                     linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
   14923             :                                                 INTERVAL_MASK(HOUR) |
   14924             :                                                 INTERVAL_MASK(MINUTE) |
   14925          48 :                                                 INTERVAL_MASK(SECOND), @1);
   14926             :                 }
   14927             :             | HOUR_P TO MINUTE_P
   14928             :                 {
   14929          18 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
   14930             :                                                  INTERVAL_MASK(MINUTE), @1));
   14931             :                 }
   14932             :             | HOUR_P TO interval_second
   14933             :                 {
   14934          36 :                     $$ = $3;
   14935          36 :                     linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
   14936             :                                                 INTERVAL_MASK(MINUTE) |
   14937          36 :                                                 INTERVAL_MASK(SECOND), @1);
   14938             :                 }
   14939             :             | MINUTE_P TO interval_second
   14940             :                 {
   14941          66 :                     $$ = $3;
   14942          66 :                     linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
   14943          66 :                                                 INTERVAL_MASK(SECOND), @1);
   14944             :                 }
   14945             :             | /*EMPTY*/
   14946        6744 :                 { $$ = NIL; }
   14947             :         ;
   14948             : 
   14949             : interval_second:
   14950             :             SECOND_P
   14951             :                 {
   14952         102 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
   14953             :                 }
   14954             :             | SECOND_P '(' Iconst ')'
   14955             :                 {
   14956          84 :                     $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
   14957             :                                     makeIntConst($3, @3));
   14958             :                 }
   14959             :         ;
   14960             : 
   14961             : JsonType:
   14962             :             JSON
   14963             :                 {
   14964        2172 :                     $$ = SystemTypeName("json");
   14965        2172 :                     $$->location = @1;
   14966             :                 }
   14967             :         ;
   14968             : 
   14969             : /*****************************************************************************
   14970             :  *
   14971             :  *  expression grammar
   14972             :  *
   14973             :  *****************************************************************************/
   14974             : 
   14975             : /*
   14976             :  * General expressions
   14977             :  * This is the heart of the expression syntax.
   14978             :  *
   14979             :  * We have two expression types: a_expr is the unrestricted kind, and
   14980             :  * b_expr is a subset that must be used in some places to avoid shift/reduce
   14981             :  * conflicts.  For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
   14982             :  * because that use of AND conflicts with AND as a boolean operator.  So,
   14983             :  * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
   14984             :  *
   14985             :  * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
   14986             :  * always be used by surrounding it with parens.
   14987             :  *
   14988             :  * c_expr is all the productions that are common to a_expr and b_expr;
   14989             :  * it's factored out just to eliminate redundant coding.
   14990             :  *
   14991             :  * Be careful of productions involving more than one terminal token.
   14992             :  * By default, bison will assign such productions the precedence of their
   14993             :  * last terminal, but in nearly all cases you want it to be the precedence
   14994             :  * of the first terminal instead; otherwise you will not get the behavior
   14995             :  * you expect!  So we use %prec annotations freely to set precedences.
   14996             :  */
   14997     3761488 : a_expr:     c_expr                                  { $$ = $1; }
   14998             :             | a_expr TYPECAST Typename
   14999      241372 :                     { $$ = makeTypeCast($1, $3, @2); }
   15000             :             | a_expr COLLATE any_name
   15001             :                 {
   15002        9006 :                     CollateClause *n = makeNode(CollateClause);
   15003             : 
   15004        9006 :                     n->arg = $1;
   15005        9006 :                     n->collname = $3;
   15006        9006 :                     n->location = @2;
   15007        9006 :                     $$ = (Node *) n;
   15008             :                 }
   15009             :             | a_expr AT TIME ZONE a_expr            %prec AT
   15010             :                 {
   15011         408 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   15012         408 :                                                list_make2($5, $1),
   15013             :                                                COERCE_SQL_SYNTAX,
   15014         408 :                                                @2);
   15015             :                 }
   15016             :             | a_expr AT LOCAL                       %prec AT
   15017             :                 {
   15018          42 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   15019          42 :                                                list_make1($1),
   15020             :                                                COERCE_SQL_SYNTAX,
   15021             :                                                -1);
   15022             :                 }
   15023             :         /*
   15024             :          * These operators must be called out explicitly in order to make use
   15025             :          * of bison's automatic operator-precedence handling.  All other
   15026             :          * operator names are handled by the generic productions using "Op",
   15027             :          * below; and all those operators will have the same precedence.
   15028             :          *
   15029             :          * If you add more explicitly-known operators, be sure to add them
   15030             :          * also to b_expr and to the MathOp list below.
   15031             :          */
   15032             :             | '+' a_expr                    %prec UMINUS
   15033          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   15034             :             | '-' a_expr                    %prec UMINUS
   15035        9216 :                 { $$ = doNegate($2, @1); }
   15036             :             | a_expr '+' a_expr
   15037       14172 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   15038             :             | a_expr '-' a_expr
   15039        4500 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   15040             :             | a_expr '*' a_expr
   15041        6386 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   15042             :             | a_expr '/' a_expr
   15043        3432 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   15044             :             | a_expr '%' a_expr
   15045        2838 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   15046             :             | a_expr '^' a_expr
   15047         478 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   15048             :             | a_expr '<' a_expr
   15049       10590 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   15050             :             | a_expr '>' a_expr
   15051       16870 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   15052             :             | a_expr '=' a_expr
   15053      402036 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   15054             :             | a_expr LESS_EQUALS a_expr
   15055        5314 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   15056             :             | a_expr GREATER_EQUALS a_expr
   15057        7342 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   15058             :             | a_expr NOT_EQUALS a_expr
   15059       41016 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   15060             : 
   15061             :             | a_expr qual_Op a_expr             %prec Op
   15062       59124 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   15063             :             | qual_Op a_expr                    %prec Op
   15064         228 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   15065             : 
   15066             :             | a_expr AND a_expr
   15067      239094 :                 { $$ = makeAndExpr($1, $3, @2); }
   15068             :             | a_expr OR a_expr
   15069       16834 :                 { $$ = makeOrExpr($1, $3, @2); }
   15070             :             | NOT a_expr
   15071       16866 :                 { $$ = makeNotExpr($2, @1); }
   15072             :             | NOT_LA a_expr                     %prec NOT
   15073           0 :                 { $$ = makeNotExpr($2, @1); }
   15074             : 
   15075             :             | a_expr LIKE a_expr
   15076             :                 {
   15077        1964 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   15078        1964 :                                                    $1, $3, @2);
   15079             :                 }
   15080             :             | a_expr LIKE a_expr ESCAPE a_expr                  %prec LIKE
   15081             :                 {
   15082          96 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15083          96 :                                                  list_make2($3, $5),
   15084             :                                                  COERCE_EXPLICIT_CALL,
   15085          96 :                                                  @2);
   15086          96 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   15087          96 :                                                    $1, (Node *) n, @2);
   15088             :                 }
   15089             :             | a_expr NOT_LA LIKE a_expr                         %prec NOT_LA
   15090             :                 {
   15091         198 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   15092         198 :                                                    $1, $4, @2);
   15093             :                 }
   15094             :             | a_expr NOT_LA LIKE a_expr ESCAPE a_expr           %prec NOT_LA
   15095             :                 {
   15096          96 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15097          96 :                                                  list_make2($4, $6),
   15098             :                                                  COERCE_EXPLICIT_CALL,
   15099          96 :                                                  @2);
   15100          96 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   15101          96 :                                                    $1, (Node *) n, @2);
   15102             :                 }
   15103             :             | a_expr ILIKE a_expr
   15104             :                 {
   15105         172 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   15106         172 :                                                    $1, $3, @2);
   15107             :                 }
   15108             :             | a_expr ILIKE a_expr ESCAPE a_expr                 %prec ILIKE
   15109             :                 {
   15110           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15111           0 :                                                  list_make2($3, $5),
   15112             :                                                  COERCE_EXPLICIT_CALL,
   15113           0 :                                                  @2);
   15114           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   15115           0 :                                                    $1, (Node *) n, @2);
   15116             :                 }
   15117             :             | a_expr NOT_LA ILIKE a_expr                        %prec NOT_LA
   15118             :                 {
   15119          30 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   15120          30 :                                                    $1, $4, @2);
   15121             :                 }
   15122             :             | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr          %prec NOT_LA
   15123             :                 {
   15124           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15125           0 :                                                  list_make2($4, $6),
   15126             :                                                  COERCE_EXPLICIT_CALL,
   15127           0 :                                                  @2);
   15128           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   15129           0 :                                                    $1, (Node *) n, @2);
   15130             :                 }
   15131             : 
   15132             :             | a_expr SIMILAR TO a_expr                          %prec SIMILAR
   15133             :                 {
   15134          88 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15135          88 :                                                  list_make1($4),
   15136             :                                                  COERCE_EXPLICIT_CALL,
   15137          88 :                                                  @2);
   15138          88 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   15139          88 :                                                    $1, (Node *) n, @2);
   15140             :                 }
   15141             :             | a_expr SIMILAR TO a_expr ESCAPE a_expr            %prec SIMILAR
   15142             :                 {
   15143          30 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15144          30 :                                                  list_make2($4, $6),
   15145             :                                                  COERCE_EXPLICIT_CALL,
   15146          30 :                                                  @2);
   15147          30 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   15148          30 :                                                    $1, (Node *) n, @2);
   15149             :                 }
   15150             :             | a_expr NOT_LA SIMILAR TO a_expr                   %prec NOT_LA
   15151             :                 {
   15152           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15153           0 :                                                  list_make1($5),
   15154             :                                                  COERCE_EXPLICIT_CALL,
   15155           0 :                                                  @2);
   15156           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   15157           0 :                                                    $1, (Node *) n, @2);
   15158             :                 }
   15159             :             | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr     %prec NOT_LA
   15160             :                 {
   15161           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15162           0 :                                                  list_make2($5, $7),
   15163             :                                                  COERCE_EXPLICIT_CALL,
   15164           0 :                                                  @2);
   15165           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   15166           0 :                                                    $1, (Node *) n, @2);
   15167             :                 }
   15168             : 
   15169             :             /* NullTest clause
   15170             :              * Define SQL-style Null test clause.
   15171             :              * Allow two forms described in the standard:
   15172             :              *  a IS NULL
   15173             :              *  a IS NOT NULL
   15174             :              * Allow two SQL extensions
   15175             :              *  a ISNULL
   15176             :              *  a NOTNULL
   15177             :              */
   15178             :             | a_expr IS NULL_P                          %prec IS
   15179             :                 {
   15180        5290 :                     NullTest   *n = makeNode(NullTest);
   15181             : 
   15182        5290 :                     n->arg = (Expr *) $1;
   15183        5290 :                     n->nulltesttype = IS_NULL;
   15184        5290 :                     n->location = @2;
   15185        5290 :                     $$ = (Node *) n;
   15186             :                 }
   15187             :             | a_expr ISNULL
   15188             :                 {
   15189          96 :                     NullTest   *n = makeNode(NullTest);
   15190             : 
   15191          96 :                     n->arg = (Expr *) $1;
   15192          96 :                     n->nulltesttype = IS_NULL;
   15193          96 :                     n->location = @2;
   15194          96 :                     $$ = (Node *) n;
   15195             :                 }
   15196             :             | a_expr IS NOT NULL_P                      %prec IS
   15197             :                 {
   15198       13454 :                     NullTest   *n = makeNode(NullTest);
   15199             : 
   15200       13454 :                     n->arg = (Expr *) $1;
   15201       13454 :                     n->nulltesttype = IS_NOT_NULL;
   15202       13454 :                     n->location = @2;
   15203       13454 :                     $$ = (Node *) n;
   15204             :                 }
   15205             :             | a_expr NOTNULL
   15206             :                 {
   15207           6 :                     NullTest   *n = makeNode(NullTest);
   15208             : 
   15209           6 :                     n->arg = (Expr *) $1;
   15210           6 :                     n->nulltesttype = IS_NOT_NULL;
   15211           6 :                     n->location = @2;
   15212           6 :                     $$ = (Node *) n;
   15213             :                 }
   15214             :             | row OVERLAPS row
   15215             :                 {
   15216         984 :                     if (list_length($1) != 2)
   15217           0 :                         ereport(ERROR,
   15218             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   15219             :                                  errmsg("wrong number of parameters on left side of OVERLAPS expression"),
   15220             :                                  parser_errposition(@1)));
   15221         984 :                     if (list_length($3) != 2)
   15222           0 :                         ereport(ERROR,
   15223             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   15224             :                                  errmsg("wrong number of parameters on right side of OVERLAPS expression"),
   15225             :                                  parser_errposition(@3)));
   15226         984 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
   15227         984 :                                                list_concat($1, $3),
   15228             :                                                COERCE_SQL_SYNTAX,
   15229         984 :                                                @2);
   15230             :                 }
   15231             :             | a_expr IS TRUE_P                          %prec IS
   15232             :                 {
   15233         530 :                     BooleanTest *b = makeNode(BooleanTest);
   15234             : 
   15235         530 :                     b->arg = (Expr *) $1;
   15236         530 :                     b->booltesttype = IS_TRUE;
   15237         530 :                     b->location = @2;
   15238         530 :                     $$ = (Node *) b;
   15239             :                 }
   15240             :             | a_expr IS NOT TRUE_P                      %prec IS
   15241             :                 {
   15242         140 :                     BooleanTest *b = makeNode(BooleanTest);
   15243             : 
   15244         140 :                     b->arg = (Expr *) $1;
   15245         140 :                     b->booltesttype = IS_NOT_TRUE;
   15246         140 :                     b->location = @2;
   15247         140 :                     $$ = (Node *) b;
   15248             :                 }
   15249             :             | a_expr IS FALSE_P                         %prec IS
   15250             :                 {
   15251         140 :                     BooleanTest *b = makeNode(BooleanTest);
   15252             : 
   15253         140 :                     b->arg = (Expr *) $1;
   15254         140 :                     b->booltesttype = IS_FALSE;
   15255         140 :                     b->location = @2;
   15256         140 :                     $$ = (Node *) b;
   15257             :                 }
   15258             :             | a_expr IS NOT FALSE_P                     %prec IS
   15259             :                 {
   15260          92 :                     BooleanTest *b = makeNode(BooleanTest);
   15261             : 
   15262          92 :                     b->arg = (Expr *) $1;
   15263          92 :                     b->booltesttype = IS_NOT_FALSE;
   15264          92 :                     b->location = @2;
   15265          92 :                     $$ = (Node *) b;
   15266             :                 }
   15267             :             | a_expr IS UNKNOWN                         %prec IS
   15268             :                 {
   15269          52 :                     BooleanTest *b = makeNode(BooleanTest);
   15270             : 
   15271          52 :                     b->arg = (Expr *) $1;
   15272          52 :                     b->booltesttype = IS_UNKNOWN;
   15273          52 :                     b->location = @2;
   15274          52 :                     $$ = (Node *) b;
   15275             :                 }
   15276             :             | a_expr IS NOT UNKNOWN                     %prec IS
   15277             :                 {
   15278          48 :                     BooleanTest *b = makeNode(BooleanTest);
   15279             : 
   15280          48 :                     b->arg = (Expr *) $1;
   15281          48 :                     b->booltesttype = IS_NOT_UNKNOWN;
   15282          48 :                     b->location = @2;
   15283          48 :                     $$ = (Node *) b;
   15284             :                 }
   15285             :             | a_expr IS DISTINCT FROM a_expr            %prec IS
   15286             :                 {
   15287        1248 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   15288             :                 }
   15289             :             | a_expr IS NOT DISTINCT FROM a_expr        %prec IS
   15290             :                 {
   15291          68 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   15292             :                 }
   15293             :             | a_expr BETWEEN opt_asymmetric b_expr AND a_expr       %prec BETWEEN
   15294             :                 {
   15295         466 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN,
   15296             :                                                    "BETWEEN",
   15297         466 :                                                    $1,
   15298         466 :                                                    (Node *) list_make2($4, $6),
   15299         466 :                                                    @2);
   15300             :                 }
   15301             :             | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
   15302             :                 {
   15303          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN,
   15304             :                                                    "NOT BETWEEN",
   15305          12 :                                                    $1,
   15306          12 :                                                    (Node *) list_make2($5, $7),
   15307          12 :                                                    @2);
   15308             :                 }
   15309             :             | a_expr BETWEEN SYMMETRIC b_expr AND a_expr            %prec BETWEEN
   15310             :                 {
   15311          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN_SYM,
   15312             :                                                    "BETWEEN SYMMETRIC",
   15313          12 :                                                    $1,
   15314          12 :                                                    (Node *) list_make2($4, $6),
   15315          12 :                                                    @2);
   15316             :                 }
   15317             :             | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr     %prec NOT_LA
   15318             :                 {
   15319          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN_SYM,
   15320             :                                                    "NOT BETWEEN SYMMETRIC",
   15321          12 :                                                    $1,
   15322          12 :                                                    (Node *) list_make2($5, $7),
   15323          12 :                                                    @2);
   15324             :                 }
   15325             :             | a_expr IN_P select_with_parens
   15326             :                 {
   15327             :                     /* generate foo = ANY (subquery) */
   15328        5450 :                     SubLink    *n = makeNode(SubLink);
   15329             : 
   15330        5450 :                     n->subselect = $3;
   15331        5450 :                     n->subLinkType = ANY_SUBLINK;
   15332        5450 :                     n->subLinkId = 0;
   15333        5450 :                     n->testexpr = $1;
   15334        5450 :                     n->operName = NIL;       /* show it's IN not = ANY */
   15335        5450 :                     n->location = @2;
   15336        5450 :                     $$ = (Node *) n;
   15337             :                 }
   15338             :             | a_expr IN_P '(' expr_list ')'
   15339             :                 {
   15340             :                     /* generate scalar IN expression */
   15341       19068 :                     A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "=", $1, (Node *) $4, @2);
   15342             : 
   15343       19068 :                     n->rexpr_list_start = @3;
   15344       19068 :                     n->rexpr_list_end = @5;
   15345       19068 :                     $$ = (Node *) n;
   15346             :                 }
   15347             :             | a_expr NOT_LA IN_P select_with_parens         %prec NOT_LA
   15348             :                 {
   15349             :                     /* generate NOT (foo = ANY (subquery)) */
   15350         120 :                     SubLink    *n = makeNode(SubLink);
   15351             : 
   15352         120 :                     n->subselect = $4;
   15353         120 :                     n->subLinkType = ANY_SUBLINK;
   15354         120 :                     n->subLinkId = 0;
   15355         120 :                     n->testexpr = $1;
   15356         120 :                     n->operName = NIL;       /* show it's IN not = ANY */
   15357         120 :                     n->location = @2;
   15358             :                     /* Stick a NOT on top; must have same parse location */
   15359         120 :                     $$ = makeNotExpr((Node *) n, @2);
   15360             :                 }
   15361             :             | a_expr NOT_LA IN_P '(' expr_list ')'
   15362             :                 {
   15363             :                     /* generate scalar NOT IN expression */
   15364        2850 :                     A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "<>", $1, (Node *) $5, @2);
   15365             : 
   15366        2850 :                     n->rexpr_list_start = @4;
   15367        2850 :                     n->rexpr_list_end = @6;
   15368        2850 :                     $$ = (Node *) n;
   15369             :                 }
   15370             :             | a_expr subquery_Op sub_type select_with_parens    %prec Op
   15371             :                 {
   15372         168 :                     SubLink    *n = makeNode(SubLink);
   15373             : 
   15374         168 :                     n->subLinkType = $3;
   15375         168 :                     n->subLinkId = 0;
   15376         168 :                     n->testexpr = $1;
   15377         168 :                     n->operName = $2;
   15378         168 :                     n->subselect = $4;
   15379         168 :                     n->location = @2;
   15380         168 :                     $$ = (Node *) n;
   15381             :                 }
   15382             :             | a_expr subquery_Op sub_type '(' a_expr ')'        %prec Op
   15383             :                 {
   15384       17266 :                     if ($3 == ANY_SUBLINK)
   15385       16966 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
   15386             :                     else
   15387         300 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
   15388             :                 }
   15389             :             | UNIQUE opt_unique_null_treatment select_with_parens
   15390             :                 {
   15391             :                     /* Not sure how to get rid of the parentheses
   15392             :                      * but there are lots of shift/reduce errors without them.
   15393             :                      *
   15394             :                      * Should be able to implement this by plopping the entire
   15395             :                      * select into a node, then transforming the target expressions
   15396             :                      * from whatever they are into count(*), and testing the
   15397             :                      * entire result equal to one.
   15398             :                      * But, will probably implement a separate node in the executor.
   15399             :                      */
   15400           0 :                     ereport(ERROR,
   15401             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   15402             :                              errmsg("UNIQUE predicate is not yet implemented"),
   15403             :                              parser_errposition(@1)));
   15404             :                 }
   15405             :             | a_expr IS DOCUMENT_P                  %prec IS
   15406             :                 {
   15407          18 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15408          18 :                                      list_make1($1), @2);
   15409             :                 }
   15410             :             | a_expr IS NOT DOCUMENT_P              %prec IS
   15411             :                 {
   15412          18 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15413          18 :                                                  list_make1($1), @2),
   15414          18 :                                      @2);
   15415             :                 }
   15416             :             | a_expr IS NORMALIZED                              %prec IS
   15417             :                 {
   15418          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15419          12 :                                                list_make1($1),
   15420             :                                                COERCE_SQL_SYNTAX,
   15421          12 :                                                @2);
   15422             :                 }
   15423             :             | a_expr IS unicode_normal_form NORMALIZED          %prec IS
   15424             :                 {
   15425          36 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15426          36 :                                                list_make2($1, makeStringConst($3, @3)),
   15427             :                                                COERCE_SQL_SYNTAX,
   15428          36 :                                                @2);
   15429             :                 }
   15430             :             | a_expr IS NOT NORMALIZED                          %prec IS
   15431             :                 {
   15432           0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15433           0 :                                                            list_make1($1),
   15434             :                                                            COERCE_SQL_SYNTAX,
   15435           0 :                                                            @2),
   15436           0 :                                      @2);
   15437             :                 }
   15438             :             | a_expr IS NOT unicode_normal_form NORMALIZED      %prec IS
   15439             :                 {
   15440           0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15441           0 :                                                            list_make2($1, makeStringConst($4, @4)),
   15442             :                                                            COERCE_SQL_SYNTAX,
   15443           0 :                                                            @2),
   15444           0 :                                      @2);
   15445             :                 }
   15446             :             | a_expr IS json_predicate_type_constraint
   15447             :                     json_key_uniqueness_constraint_opt      %prec IS
   15448             :                 {
   15449         304 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   15450             : 
   15451         304 :                     $$ = makeJsonIsPredicate($1, format, $3, $4, @1);
   15452             :                 }
   15453             :             /*
   15454             :              * Required by SQL/JSON, but there are conflicts
   15455             :             | a_expr
   15456             :                 json_format_clause
   15457             :                 IS  json_predicate_type_constraint
   15458             :                     json_key_uniqueness_constraint_opt      %prec IS
   15459             :                 {
   15460             :                     $$ = makeJsonIsPredicate($1, $2, $4, $5, @1);
   15461             :                 }
   15462             :             */
   15463             :             | a_expr IS NOT
   15464             :                     json_predicate_type_constraint
   15465             :                     json_key_uniqueness_constraint_opt      %prec IS
   15466             :                 {
   15467          46 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   15468             : 
   15469          46 :                     $$ = makeNotExpr(makeJsonIsPredicate($1, format, $4, $5, @1), @1);
   15470             :                 }
   15471             :             /*
   15472             :              * Required by SQL/JSON, but there are conflicts
   15473             :             | a_expr
   15474             :                 json_format_clause
   15475             :                 IS NOT
   15476             :                     json_predicate_type_constraint
   15477             :                     json_key_uniqueness_constraint_opt      %prec IS
   15478             :                 {
   15479             :                     $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, @1), @1);
   15480             :                 }
   15481             :             */
   15482             :             | DEFAULT
   15483             :                 {
   15484             :                     /*
   15485             :                      * The SQL spec only allows DEFAULT in "contextually typed
   15486             :                      * expressions", but for us, it's easier to allow it in
   15487             :                      * any a_expr and then throw error during parse analysis
   15488             :                      * if it's in an inappropriate context.  This way also
   15489             :                      * lets us say something smarter than "syntax error".
   15490             :                      */
   15491        1532 :                     SetToDefault *n = makeNode(SetToDefault);
   15492             : 
   15493             :                     /* parse analysis will fill in the rest */
   15494        1532 :                     n->location = @1;
   15495        1532 :                     $$ = (Node *) n;
   15496             :                 }
   15497             :         ;
   15498             : 
   15499             : /*
   15500             :  * Restricted expressions
   15501             :  *
   15502             :  * b_expr is a subset of the complete expression syntax defined by a_expr.
   15503             :  *
   15504             :  * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
   15505             :  * cause trouble in the places where b_expr is used.  For simplicity, we
   15506             :  * just eliminate all the boolean-keyword-operator productions from b_expr.
   15507             :  */
   15508             : b_expr:     c_expr
   15509        3874 :                 { $$ = $1; }
   15510             :             | b_expr TYPECAST Typename
   15511         240 :                 { $$ = makeTypeCast($1, $3, @2); }
   15512             :             | '+' b_expr                    %prec UMINUS
   15513           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   15514             :             | '-' b_expr                    %prec UMINUS
   15515          66 :                 { $$ = doNegate($2, @1); }
   15516             :             | b_expr '+' b_expr
   15517          36 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   15518             :             | b_expr '-' b_expr
   15519          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   15520             :             | b_expr '*' b_expr
   15521          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   15522             :             | b_expr '/' b_expr
   15523           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   15524             :             | b_expr '%' b_expr
   15525           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   15526             :             | b_expr '^' b_expr
   15527           6 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   15528             :             | b_expr '<' b_expr
   15529           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   15530             :             | b_expr '>' b_expr
   15531           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   15532             :             | b_expr '=' b_expr
   15533           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   15534             :             | b_expr LESS_EQUALS b_expr
   15535           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   15536             :             | b_expr GREATER_EQUALS b_expr
   15537           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   15538             :             | b_expr NOT_EQUALS b_expr
   15539           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   15540             :             | b_expr qual_Op b_expr             %prec Op
   15541          12 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   15542             :             | qual_Op b_expr                    %prec Op
   15543           0 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   15544             :             | b_expr IS DISTINCT FROM b_expr        %prec IS
   15545             :                 {
   15546           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   15547             :                 }
   15548             :             | b_expr IS NOT DISTINCT FROM b_expr    %prec IS
   15549             :                 {
   15550           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   15551             :                 }
   15552             :             | b_expr IS DOCUMENT_P                  %prec IS
   15553             :                 {
   15554           0 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15555           0 :                                      list_make1($1), @2);
   15556             :                 }
   15557             :             | b_expr IS NOT DOCUMENT_P              %prec IS
   15558             :                 {
   15559           0 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15560           0 :                                                  list_make1($1), @2),
   15561           0 :                                      @2);
   15562             :                 }
   15563             :         ;
   15564             : 
   15565             : /*
   15566             :  * Productions that can be used in both a_expr and b_expr.
   15567             :  *
   15568             :  * Note: productions that refer recursively to a_expr or b_expr mostly
   15569             :  * cannot appear here.  However, it's OK to refer to a_exprs that occur
   15570             :  * inside parentheses, such as function arguments; that cannot introduce
   15571             :  * ambiguity to the b_expr syntax.
   15572             :  */
   15573     1873034 : c_expr:     columnref                               { $$ = $1; }
   15574     1255210 :             | AexprConst                            { $$ = $1; }
   15575             :             | PARAM opt_indirection
   15576             :                 {
   15577       46344 :                     ParamRef   *p = makeNode(ParamRef);
   15578             : 
   15579       46344 :                     p->number = $1;
   15580       46344 :                     p->location = @1;
   15581       46344 :                     if ($2)
   15582             :                     {
   15583        1098 :                         A_Indirection *n = makeNode(A_Indirection);
   15584             : 
   15585        1098 :                         n->arg = (Node *) p;
   15586        1098 :                         n->indirection = check_indirection($2, yyscanner);
   15587        1098 :                         $$ = (Node *) n;
   15588             :                     }
   15589             :                     else
   15590       45246 :                         $$ = (Node *) p;
   15591             :                 }
   15592             :             | '(' a_expr ')' opt_indirection
   15593             :                 {
   15594       94004 :                     if ($4)
   15595             :                     {
   15596       12566 :                         A_Indirection *n = makeNode(A_Indirection);
   15597             : 
   15598       12566 :                         n->arg = $2;
   15599       12566 :                         n->indirection = check_indirection($4, yyscanner);
   15600       12566 :                         $$ = (Node *) n;
   15601             :                     }
   15602             :                     else
   15603       81438 :                         $$ = $2;
   15604             :                 }
   15605             :             | case_expr
   15606       40550 :                 { $$ = $1; }
   15607             :             | func_expr
   15608      398216 :                 { $$ = $1; }
   15609             :             | select_with_parens            %prec UMINUS
   15610             :                 {
   15611       28950 :                     SubLink    *n = makeNode(SubLink);
   15612             : 
   15613       28950 :                     n->subLinkType = EXPR_SUBLINK;
   15614       28950 :                     n->subLinkId = 0;
   15615       28950 :                     n->testexpr = NULL;
   15616       28950 :                     n->operName = NIL;
   15617       28950 :                     n->subselect = $1;
   15618       28950 :                     n->location = @1;
   15619       28950 :                     $$ = (Node *) n;
   15620             :                 }
   15621             :             | select_with_parens indirection
   15622             :                 {
   15623             :                     /*
   15624             :                      * Because the select_with_parens nonterminal is designed
   15625             :                      * to "eat" as many levels of parens as possible, the
   15626             :                      * '(' a_expr ')' opt_indirection production above will
   15627             :                      * fail to match a sub-SELECT with indirection decoration;
   15628             :                      * the sub-SELECT won't be regarded as an a_expr as long
   15629             :                      * as there are parens around it.  To support applying
   15630             :                      * subscripting or field selection to a sub-SELECT result,
   15631             :                      * we need this redundant-looking production.
   15632             :                      */
   15633          18 :                     SubLink    *n = makeNode(SubLink);
   15634          18 :                     A_Indirection *a = makeNode(A_Indirection);
   15635             : 
   15636          18 :                     n->subLinkType = EXPR_SUBLINK;
   15637          18 :                     n->subLinkId = 0;
   15638          18 :                     n->testexpr = NULL;
   15639          18 :                     n->operName = NIL;
   15640          18 :                     n->subselect = $1;
   15641          18 :                     n->location = @1;
   15642          18 :                     a->arg = (Node *) n;
   15643          18 :                     a->indirection = check_indirection($2, yyscanner);
   15644          18 :                     $$ = (Node *) a;
   15645             :                 }
   15646             :             | EXISTS select_with_parens
   15647             :                 {
   15648        6452 :                     SubLink    *n = makeNode(SubLink);
   15649             : 
   15650        6452 :                     n->subLinkType = EXISTS_SUBLINK;
   15651        6452 :                     n->subLinkId = 0;
   15652        6452 :                     n->testexpr = NULL;
   15653        6452 :                     n->operName = NIL;
   15654        6452 :                     n->subselect = $2;
   15655        6452 :                     n->location = @1;
   15656        6452 :                     $$ = (Node *) n;
   15657             :                 }
   15658             :             | ARRAY select_with_parens
   15659             :                 {
   15660        8944 :                     SubLink    *n = makeNode(SubLink);
   15661             : 
   15662        8944 :                     n->subLinkType = ARRAY_SUBLINK;
   15663        8944 :                     n->subLinkId = 0;
   15664        8944 :                     n->testexpr = NULL;
   15665        8944 :                     n->operName = NIL;
   15666        8944 :                     n->subselect = $2;
   15667        8944 :                     n->location = @1;
   15668        8944 :                     $$ = (Node *) n;
   15669             :                 }
   15670             :             | ARRAY array_expr
   15671             :                 {
   15672        7476 :                     A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
   15673             : 
   15674             :                     /* point outermost A_ArrayExpr to the ARRAY keyword */
   15675        7476 :                     n->location = @1;
   15676        7476 :                     $$ = (Node *) n;
   15677             :                 }
   15678             :             | explicit_row
   15679             :                 {
   15680        3816 :                     RowExpr    *r = makeNode(RowExpr);
   15681             : 
   15682        3816 :                     r->args = $1;
   15683        3816 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15684        3816 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15685        3816 :                     r->row_format = COERCE_EXPLICIT_CALL; /* abuse */
   15686        3816 :                     r->location = @1;
   15687        3816 :                     $$ = (Node *) r;
   15688             :                 }
   15689             :             | implicit_row
   15690             :                 {
   15691        2674 :                     RowExpr    *r = makeNode(RowExpr);
   15692             : 
   15693        2674 :                     r->args = $1;
   15694        2674 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15695        2674 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15696        2674 :                     r->row_format = COERCE_IMPLICIT_CAST; /* abuse */
   15697        2674 :                     r->location = @1;
   15698        2674 :                     $$ = (Node *) r;
   15699             :                 }
   15700             :             | GROUPING '(' expr_list ')'
   15701             :               {
   15702         362 :                   GroupingFunc *g = makeNode(GroupingFunc);
   15703             : 
   15704         362 :                   g->args = $3;
   15705         362 :                   g->location = @1;
   15706         362 :                   $$ = (Node *) g;
   15707             :               }
   15708             :         ;
   15709             : 
   15710             : func_application: func_name '(' ')'
   15711             :                 {
   15712       33008 :                     $$ = (Node *) makeFuncCall($1, NIL,
   15713             :                                                COERCE_EXPLICIT_CALL,
   15714       33008 :                                                @1);
   15715             :                 }
   15716             :             | func_name '(' func_arg_list opt_sort_clause ')'
   15717             :                 {
   15718      322994 :                     FuncCall   *n = makeFuncCall($1, $3,
   15719             :                                                  COERCE_EXPLICIT_CALL,
   15720      322994 :                                                  @1);
   15721             : 
   15722      322994 :                     n->agg_order = $4;
   15723      322994 :                     $$ = (Node *) n;
   15724             :                 }
   15725             :             | func_name '(' VARIADIC func_arg_expr opt_sort_clause ')'
   15726             :                 {
   15727         614 :                     FuncCall   *n = makeFuncCall($1, list_make1($4),
   15728             :                                                  COERCE_EXPLICIT_CALL,
   15729         614 :                                                  @1);
   15730             : 
   15731         614 :                     n->func_variadic = true;
   15732         614 :                     n->agg_order = $5;
   15733         614 :                     $$ = (Node *) n;
   15734             :                 }
   15735             :             | func_name '(' func_arg_list ',' VARIADIC func_arg_expr opt_sort_clause ')'
   15736             :                 {
   15737         120 :                     FuncCall   *n = makeFuncCall($1, lappend($3, $6),
   15738             :                                                  COERCE_EXPLICIT_CALL,
   15739         120 :                                                  @1);
   15740             : 
   15741         120 :                     n->func_variadic = true;
   15742         120 :                     n->agg_order = $7;
   15743         120 :                     $$ = (Node *) n;
   15744             :                 }
   15745             :             | func_name '(' ALL func_arg_list opt_sort_clause ')'
   15746             :                 {
   15747           0 :                     FuncCall   *n = makeFuncCall($1, $4,
   15748             :                                                  COERCE_EXPLICIT_CALL,
   15749           0 :                                                  @1);
   15750             : 
   15751           0 :                     n->agg_order = $5;
   15752             :                     /* Ideally we'd mark the FuncCall node to indicate
   15753             :                      * "must be an aggregate", but there's no provision
   15754             :                      * for that in FuncCall at the moment.
   15755             :                      */
   15756           0 :                     $$ = (Node *) n;
   15757             :                 }
   15758             :             | func_name '(' DISTINCT func_arg_list opt_sort_clause ')'
   15759             :                 {
   15760         550 :                     FuncCall   *n = makeFuncCall($1, $4,
   15761             :                                                  COERCE_EXPLICIT_CALL,
   15762         550 :                                                  @1);
   15763             : 
   15764         550 :                     n->agg_order = $5;
   15765         550 :                     n->agg_distinct = true;
   15766         550 :                     $$ = (Node *) n;
   15767             :                 }
   15768             :             | func_name '(' '*' ')'
   15769             :                 {
   15770             :                     /*
   15771             :                      * We consider AGGREGATE(*) to invoke a parameterless
   15772             :                      * aggregate.  This does the right thing for COUNT(*),
   15773             :                      * and there are no other aggregates in SQL that accept
   15774             :                      * '*' as parameter.
   15775             :                      *
   15776             :                      * The FuncCall node is also marked agg_star = true,
   15777             :                      * so that later processing can detect what the argument
   15778             :                      * really was.
   15779             :                      */
   15780       12576 :                     FuncCall   *n = makeFuncCall($1, NIL,
   15781             :                                                  COERCE_EXPLICIT_CALL,
   15782       12576 :                                                  @1);
   15783             : 
   15784       12576 :                     n->agg_star = true;
   15785       12576 :                     $$ = (Node *) n;
   15786             :                 }
   15787             :         ;
   15788             : 
   15789             : 
   15790             : /*
   15791             :  * func_expr and its cousin func_expr_windowless are split out from c_expr just
   15792             :  * so that we have classifications for "everything that is a function call or
   15793             :  * looks like one".  This isn't very important, but it saves us having to
   15794             :  * document which variants are legal in places like "FROM function()" or the
   15795             :  * backwards-compatible functional-index syntax for CREATE INDEX.
   15796             :  * (Note that many of the special SQL functions wouldn't actually make any
   15797             :  * sense as functional index entries, but we ignore that consideration here.)
   15798             :  */
   15799             : func_expr: func_application within_group_clause filter_clause over_clause
   15800             :                 {
   15801      320154 :                     FuncCall   *n = (FuncCall *) $1;
   15802             : 
   15803             :                     /*
   15804             :                      * The order clause for WITHIN GROUP and the one for
   15805             :                      * plain-aggregate ORDER BY share a field, so we have to
   15806             :                      * check here that at most one is present.  We also check
   15807             :                      * for DISTINCT and VARIADIC here to give a better error
   15808             :                      * location.  Other consistency checks are deferred to
   15809             :                      * parse analysis.
   15810             :                      */
   15811      320154 :                     if ($2 != NIL)
   15812             :                     {
   15813         348 :                         if (n->agg_order != NIL)
   15814           6 :                             ereport(ERROR,
   15815             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15816             :                                      errmsg("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
   15817             :                                      parser_errposition(@2)));
   15818         342 :                         if (n->agg_distinct)
   15819           0 :                             ereport(ERROR,
   15820             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15821             :                                      errmsg("cannot use DISTINCT with WITHIN GROUP"),
   15822             :                                      parser_errposition(@2)));
   15823         342 :                         if (n->func_variadic)
   15824           0 :                             ereport(ERROR,
   15825             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15826             :                                      errmsg("cannot use VARIADIC with WITHIN GROUP"),
   15827             :                                      parser_errposition(@2)));
   15828         342 :                         n->agg_order = $2;
   15829         342 :                         n->agg_within_group = true;
   15830             :                     }
   15831      320148 :                     n->agg_filter = $3;
   15832      320148 :                     n->over = $4;
   15833      320148 :                     $$ = (Node *) n;
   15834             :                 }
   15835             :             | json_aggregate_func filter_clause over_clause
   15836             :                 {
   15837         720 :                     JsonAggConstructor *n = IsA($1, JsonObjectAgg) ?
   15838         360 :                         ((JsonObjectAgg *) $1)->constructor :
   15839         156 :                         ((JsonArrayAgg *) $1)->constructor;
   15840             : 
   15841         360 :                     n->agg_filter = $2;
   15842         360 :                     n->over = $3;
   15843         360 :                     $$ = (Node *) $1;
   15844             :                 }
   15845             :             | func_expr_common_subexpr
   15846       77708 :                 { $$ = $1; }
   15847             :         ;
   15848             : 
   15849             : /*
   15850             :  * Like func_expr but does not accept WINDOW functions directly
   15851             :  * (but they can still be contained in arguments for functions etc).
   15852             :  * Use this when window expressions are not allowed, where needed to
   15853             :  * disambiguate the grammar (e.g. in CREATE INDEX).
   15854             :  */
   15855             : func_expr_windowless:
   15856       49082 :             func_application                        { $$ = $1; }
   15857         402 :             | func_expr_common_subexpr              { $$ = $1; }
   15858           0 :             | json_aggregate_func                   { $$ = $1; }
   15859             :         ;
   15860             : 
   15861             : /*
   15862             :  * Special expressions that are considered to be functions.
   15863             :  */
   15864             : func_expr_common_subexpr:
   15865             :             COLLATION FOR '(' a_expr ')'
   15866             :                 {
   15867          30 :                     $$ = (Node *) makeFuncCall(SystemFuncName("pg_collation_for"),
   15868          30 :                                                list_make1($4),
   15869             :                                                COERCE_SQL_SYNTAX,
   15870          30 :                                                @1);
   15871             :                 }
   15872             :             | CURRENT_DATE
   15873             :                 {
   15874         312 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_DATE, -1, @1);
   15875             :                 }
   15876             :             | CURRENT_TIME
   15877             :                 {
   15878          24 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME, -1, @1);
   15879             :                 }
   15880             :             | CURRENT_TIME '(' Iconst ')'
   15881             :                 {
   15882          24 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME_N, $3, @1);
   15883             :                 }
   15884             :             | CURRENT_TIMESTAMP
   15885             :                 {
   15886         284 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP, -1, @1);
   15887             :                 }
   15888             :             | CURRENT_TIMESTAMP '(' Iconst ')'
   15889             :                 {
   15890         176 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP_N, $3, @1);
   15891             :                 }
   15892             :             | LOCALTIME
   15893             :                 {
   15894          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIME, -1, @1);
   15895             :                 }
   15896             :             | LOCALTIME '(' Iconst ')'
   15897             :                 {
   15898          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIME_N, $3, @1);
   15899             :                 }
   15900             :             | LOCALTIMESTAMP
   15901             :                 {
   15902          36 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP, -1, @1);
   15903             :                 }
   15904             :             | LOCALTIMESTAMP '(' Iconst ')'
   15905             :                 {
   15906          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP_N, $3, @1);
   15907             :                 }
   15908             :             | CURRENT_ROLE
   15909             :                 {
   15910          68 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_ROLE, -1, @1);
   15911             :                 }
   15912             :             | CURRENT_USER
   15913             :                 {
   15914        1092 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_USER, -1, @1);
   15915             :                 }
   15916             :             | SESSION_USER
   15917             :                 {
   15918         586 :                     $$ = makeSQLValueFunction(SVFOP_SESSION_USER, -1, @1);
   15919             :                 }
   15920             :             | SYSTEM_USER
   15921             :                 {
   15922          20 :                     $$ = (Node *) makeFuncCall(SystemFuncName("system_user"),
   15923             :                                                NIL,
   15924             :                                                COERCE_SQL_SYNTAX,
   15925             :                                                @1);
   15926             :                 }
   15927             :             | USER
   15928             :                 {
   15929          24 :                     $$ = makeSQLValueFunction(SVFOP_USER, -1, @1);
   15930             :                 }
   15931             :             | CURRENT_CATALOG
   15932             :                 {
   15933          52 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_CATALOG, -1, @1);
   15934             :                 }
   15935             :             | CURRENT_SCHEMA
   15936             :                 {
   15937          30 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_SCHEMA, -1, @1);
   15938             :                 }
   15939             :             | CAST '(' a_expr AS Typename ')'
   15940       63758 :                 { $$ = makeTypeCast($3, $5, @1); }
   15941             :             | EXTRACT '(' extract_list ')'
   15942             :                 {
   15943        1390 :                     $$ = (Node *) makeFuncCall(SystemFuncName("extract"),
   15944        1390 :                                                $3,
   15945             :                                                COERCE_SQL_SYNTAX,
   15946        1390 :                                                @1);
   15947             :                 }
   15948             :             | NORMALIZE '(' a_expr ')'
   15949             :                 {
   15950          18 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   15951          18 :                                                list_make1($3),
   15952             :                                                COERCE_SQL_SYNTAX,
   15953          18 :                                                @1);
   15954             :                 }
   15955             :             | NORMALIZE '(' a_expr ',' unicode_normal_form ')'
   15956             :                 {
   15957          42 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   15958          42 :                                                list_make2($3, makeStringConst($5, @5)),
   15959             :                                                COERCE_SQL_SYNTAX,
   15960          42 :                                                @1);
   15961             :                 }
   15962             :             | OVERLAY '(' overlay_list ')'
   15963             :                 {
   15964          82 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlay"),
   15965          82 :                                                $3,
   15966             :                                                COERCE_SQL_SYNTAX,
   15967          82 :                                                @1);
   15968             :                 }
   15969             :             | OVERLAY '(' func_arg_list_opt ')'
   15970             :                 {
   15971             :                     /*
   15972             :                      * allow functions named overlay() to be called without
   15973             :                      * special syntax
   15974             :                      */
   15975           0 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("overlay")),
   15976           0 :                                                $3,
   15977             :                                                COERCE_EXPLICIT_CALL,
   15978           0 :                                                @1);
   15979             :                 }
   15980             :             | POSITION '(' position_list ')'
   15981             :                 {
   15982             :                     /*
   15983             :                      * position(A in B) is converted to position(B, A)
   15984             :                      *
   15985             :                      * We deliberately don't offer a "plain syntax" option
   15986             :                      * for position(), because the reversal of the arguments
   15987             :                      * creates too much risk of confusion.
   15988             :                      */
   15989         402 :                     $$ = (Node *) makeFuncCall(SystemFuncName("position"),
   15990         402 :                                                $3,
   15991             :                                                COERCE_SQL_SYNTAX,
   15992         402 :                                                @1);
   15993             :                 }
   15994             :             | SUBSTRING '(' substr_list ')'
   15995             :                 {
   15996             :                     /* substring(A from B for C) is converted to
   15997             :                      * substring(A, B, C) - thomas 2000-11-28
   15998             :                      */
   15999         718 :                     $$ = (Node *) makeFuncCall(SystemFuncName("substring"),
   16000         718 :                                                $3,
   16001             :                                                COERCE_SQL_SYNTAX,
   16002         718 :                                                @1);
   16003             :                 }
   16004             :             | SUBSTRING '(' func_arg_list_opt ')'
   16005             :                 {
   16006             :                     /*
   16007             :                      * allow functions named substring() to be called without
   16008             :                      * special syntax
   16009             :                      */
   16010         254 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("substring")),
   16011         254 :                                                $3,
   16012             :                                                COERCE_EXPLICIT_CALL,
   16013         254 :                                                @1);
   16014             :                 }
   16015             :             | TREAT '(' a_expr AS Typename ')'
   16016             :                 {
   16017             :                     /* TREAT(expr AS target) converts expr of a particular type to target,
   16018             :                      * which is defined to be a subtype of the original expression.
   16019             :                      * In SQL99, this is intended for use with structured UDTs,
   16020             :                      * but let's make this a generally useful form allowing stronger
   16021             :                      * coercions than are handled by implicit casting.
   16022             :                      *
   16023             :                      * Convert SystemTypeName() to SystemFuncName() even though
   16024             :                      * at the moment they result in the same thing.
   16025             :                      */
   16026           0 :                     $$ = (Node *) makeFuncCall(SystemFuncName(strVal(llast($5->names))),
   16027           0 :                                                list_make1($3),
   16028             :                                                COERCE_EXPLICIT_CALL,
   16029           0 :                                                @1);
   16030             :                 }
   16031             :             | TRIM '(' BOTH trim_list ')'
   16032             :                 {
   16033             :                     /* various trim expressions are defined in SQL
   16034             :                      * - thomas 1997-07-19
   16035             :                      */
   16036          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   16037          12 :                                                $4,
   16038             :                                                COERCE_SQL_SYNTAX,
   16039          12 :                                                @1);
   16040             :                 }
   16041             :             | TRIM '(' LEADING trim_list ')'
   16042             :                 {
   16043          24 :                     $$ = (Node *) makeFuncCall(SystemFuncName("ltrim"),
   16044          24 :                                                $4,
   16045             :                                                COERCE_SQL_SYNTAX,
   16046          24 :                                                @1);
   16047             :                 }
   16048             :             | TRIM '(' TRAILING trim_list ')'
   16049             :                 {
   16050         582 :                     $$ = (Node *) makeFuncCall(SystemFuncName("rtrim"),
   16051         582 :                                                $4,
   16052             :                                                COERCE_SQL_SYNTAX,
   16053         582 :                                                @1);
   16054             :                 }
   16055             :             | TRIM '(' trim_list ')'
   16056             :                 {
   16057          98 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   16058          98 :                                                $3,
   16059             :                                                COERCE_SQL_SYNTAX,
   16060          98 :                                                @1);
   16061             :                 }
   16062             :             | NULLIF '(' a_expr ',' a_expr ')'
   16063             :                 {
   16064         420 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
   16065             :                 }
   16066             :             | COALESCE '(' expr_list ')'
   16067             :                 {
   16068        3250 :                     CoalesceExpr *c = makeNode(CoalesceExpr);
   16069             : 
   16070        3250 :                     c->args = $3;
   16071        3250 :                     c->location = @1;
   16072        3250 :                     $$ = (Node *) c;
   16073             :                 }
   16074             :             | GREATEST '(' expr_list ')'
   16075             :                 {
   16076         146 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   16077             : 
   16078         146 :                     v->args = $3;
   16079         146 :                     v->op = IS_GREATEST;
   16080         146 :                     v->location = @1;
   16081         146 :                     $$ = (Node *) v;
   16082             :                 }
   16083             :             | LEAST '(' expr_list ')'
   16084             :                 {
   16085         124 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   16086             : 
   16087         124 :                     v->args = $3;
   16088         124 :                     v->op = IS_LEAST;
   16089         124 :                     v->location = @1;
   16090         124 :                     $$ = (Node *) v;
   16091             :                 }
   16092             :             | XMLCONCAT '(' expr_list ')'
   16093             :                 {
   16094          64 :                     $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
   16095             :                 }
   16096             :             | XMLELEMENT '(' NAME_P ColLabel ')'
   16097             :                 {
   16098           6 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
   16099             :                 }
   16100             :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
   16101             :                 {
   16102          36 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
   16103             :                 }
   16104             :             | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
   16105             :                 {
   16106         118 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
   16107             :                 }
   16108             :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
   16109             :                 {
   16110          22 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
   16111             :                 }
   16112             :             | XMLEXISTS '(' c_expr xmlexists_argument ')'
   16113             :                 {
   16114             :                     /* xmlexists(A PASSING [BY REF] B [BY REF]) is
   16115             :                      * converted to xmlexists(A, B)*/
   16116          54 :                     $$ = (Node *) makeFuncCall(SystemFuncName("xmlexists"),
   16117          54 :                                                list_make2($3, $4),
   16118             :                                                COERCE_SQL_SYNTAX,
   16119          54 :                                                @1);
   16120             :                 }
   16121             :             | XMLFOREST '(' xml_attribute_list ')'
   16122             :                 {
   16123          34 :                     $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
   16124             :                 }
   16125             :             | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
   16126             :                 {
   16127             :                     XmlExpr *x = (XmlExpr *)
   16128         142 :                         makeXmlExpr(IS_XMLPARSE, NULL, NIL,
   16129         142 :                                     list_make2($4, makeBoolAConst($5, -1)),
   16130         142 :                                     @1);
   16131             : 
   16132         142 :                     x->xmloption = $3;
   16133         142 :                     $$ = (Node *) x;
   16134             :                 }
   16135             :             | XMLPI '(' NAME_P ColLabel ')'
   16136             :                 {
   16137          30 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
   16138             :                 }
   16139             :             | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
   16140             :                 {
   16141          52 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
   16142             :                 }
   16143             :             | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
   16144             :                 {
   16145          70 :                     $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
   16146          70 :                                      list_make3($3, $5, $6), @1);
   16147             :                 }
   16148             :             | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename xml_indent_option ')'
   16149             :                 {
   16150         226 :                     XmlSerialize *n = makeNode(XmlSerialize);
   16151             : 
   16152         226 :                     n->xmloption = $3;
   16153         226 :                     n->expr = $4;
   16154         226 :                     n->typeName = $6;
   16155         226 :                     n->indent = $7;
   16156         226 :                     n->location = @1;
   16157         226 :                     $$ = (Node *) n;
   16158             :                 }
   16159             :             | JSON_OBJECT '(' func_arg_list ')'
   16160             :                 {
   16161             :                     /* Support for legacy (non-standard) json_object() */
   16162          90 :                     $$ = (Node *) makeFuncCall(SystemFuncName("json_object"),
   16163          90 :                                                $3, COERCE_EXPLICIT_CALL, @1);
   16164             :                 }
   16165             :             | JSON_OBJECT '(' json_name_and_value_list
   16166             :                 json_object_constructor_null_clause_opt
   16167             :                 json_key_uniqueness_constraint_opt
   16168             :                 json_returning_clause_opt ')'
   16169             :                 {
   16170         348 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   16171             : 
   16172         348 :                     n->exprs = $3;
   16173         348 :                     n->absent_on_null = $4;
   16174         348 :                     n->unique = $5;
   16175         348 :                     n->output = (JsonOutput *) $6;
   16176         348 :                     n->location = @1;
   16177         348 :                     $$ = (Node *) n;
   16178             :                 }
   16179             :             | JSON_OBJECT '(' json_returning_clause_opt ')'
   16180             :                 {
   16181          92 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   16182             : 
   16183          92 :                     n->exprs = NULL;
   16184          92 :                     n->absent_on_null = false;
   16185          92 :                     n->unique = false;
   16186          92 :                     n->output = (JsonOutput *) $3;
   16187          92 :                     n->location = @1;
   16188          92 :                     $$ = (Node *) n;
   16189             :                 }
   16190             :             | JSON_ARRAY '('
   16191             :                 json_value_expr_list
   16192             :                 json_array_constructor_null_clause_opt
   16193             :                 json_returning_clause_opt
   16194             :             ')'
   16195             :                 {
   16196         108 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   16197             : 
   16198         108 :                     n->exprs = $3;
   16199         108 :                     n->absent_on_null = $4;
   16200         108 :                     n->output = (JsonOutput *) $5;
   16201         108 :                     n->location = @1;
   16202         108 :                     $$ = (Node *) n;
   16203             :                 }
   16204             :             | JSON_ARRAY '('
   16205             :                 select_no_parens
   16206             :                 json_format_clause_opt
   16207             :                 /* json_array_constructor_null_clause_opt */
   16208             :                 json_returning_clause_opt
   16209             :             ')'
   16210             :                 {
   16211          60 :                     JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
   16212             : 
   16213          60 :                     n->query = $3;
   16214          60 :                     n->format = (JsonFormat *) $4;
   16215          60 :                     n->absent_on_null = true;    /* XXX */
   16216          60 :                     n->output = (JsonOutput *) $5;
   16217          60 :                     n->location = @1;
   16218          60 :                     $$ = (Node *) n;
   16219             :                 }
   16220             :             | JSON_ARRAY '('
   16221             :                 json_returning_clause_opt
   16222             :             ')'
   16223             :                 {
   16224          86 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   16225             : 
   16226          86 :                     n->exprs = NIL;
   16227          86 :                     n->absent_on_null = true;
   16228          86 :                     n->output = (JsonOutput *) $3;
   16229          86 :                     n->location = @1;
   16230          86 :                     $$ = (Node *) n;
   16231             :                 }
   16232             :             | JSON '(' json_value_expr json_key_uniqueness_constraint_opt ')'
   16233             :                 {
   16234         164 :                     JsonParseExpr *n = makeNode(JsonParseExpr);
   16235             : 
   16236         164 :                     n->expr = (JsonValueExpr *) $3;
   16237         164 :                     n->unique_keys = $4;
   16238         164 :                     n->output = NULL;
   16239         164 :                     n->location = @1;
   16240         164 :                     $$ = (Node *) n;
   16241             :                 }
   16242             :             | JSON_SCALAR '(' a_expr ')'
   16243             :                 {
   16244         112 :                     JsonScalarExpr *n = makeNode(JsonScalarExpr);
   16245             : 
   16246         112 :                     n->expr = (Expr *) $3;
   16247         112 :                     n->output = NULL;
   16248         112 :                     n->location = @1;
   16249         112 :                     $$ = (Node *) n;
   16250             :                 }
   16251             :             | JSON_SERIALIZE '(' json_value_expr json_returning_clause_opt ')'
   16252             :                 {
   16253         108 :                     JsonSerializeExpr *n = makeNode(JsonSerializeExpr);
   16254             : 
   16255         108 :                     n->expr = (JsonValueExpr *) $3;
   16256         108 :                     n->output = (JsonOutput *) $4;
   16257         108 :                     n->location = @1;
   16258         108 :                     $$ = (Node *) n;
   16259             :                 }
   16260             :             | MERGE_ACTION '(' ')'
   16261             :                 {
   16262         210 :                     MergeSupportFunc *m = makeNode(MergeSupportFunc);
   16263             : 
   16264         210 :                     m->msftype = TEXTOID;
   16265         210 :                     m->location = @1;
   16266         210 :                     $$ = (Node *) m;
   16267             :                 }
   16268             :             | JSON_QUERY '('
   16269             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16270             :                 json_returning_clause_opt
   16271             :                 json_wrapper_behavior
   16272             :                 json_quotes_clause_opt
   16273             :                 json_behavior_clause_opt
   16274             :             ')'
   16275             :                 {
   16276         984 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16277             : 
   16278         984 :                     n->op = JSON_QUERY_OP;
   16279         984 :                     n->context_item = (JsonValueExpr *) $3;
   16280         984 :                     n->pathspec = $5;
   16281         984 :                     n->passing = $6;
   16282         984 :                     n->output = (JsonOutput *) $7;
   16283         984 :                     n->wrapper = $8;
   16284         984 :                     n->quotes = $9;
   16285         984 :                     n->on_empty = (JsonBehavior *) linitial($10);
   16286         984 :                     n->on_error = (JsonBehavior *) lsecond($10);
   16287         984 :                     n->location = @1;
   16288         984 :                     $$ = (Node *) n;
   16289             :                 }
   16290             :             | JSON_EXISTS '('
   16291             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16292             :                 json_on_error_clause_opt
   16293             :             ')'
   16294             :                 {
   16295         168 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16296             : 
   16297         168 :                     n->op = JSON_EXISTS_OP;
   16298         168 :                     n->context_item = (JsonValueExpr *) $3;
   16299         168 :                     n->pathspec = $5;
   16300         168 :                     n->passing = $6;
   16301         168 :                     n->output = NULL;
   16302         168 :                     n->on_error = (JsonBehavior *) $7;
   16303         168 :                     n->location = @1;
   16304         168 :                     $$ = (Node *) n;
   16305             :                 }
   16306             :             | JSON_VALUE '('
   16307             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16308             :                 json_returning_clause_opt
   16309             :                 json_behavior_clause_opt
   16310             :             ')'
   16311             :                 {
   16312         576 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16313             : 
   16314         576 :                     n->op = JSON_VALUE_OP;
   16315         576 :                     n->context_item = (JsonValueExpr *) $3;
   16316         576 :                     n->pathspec = $5;
   16317         576 :                     n->passing = $6;
   16318         576 :                     n->output = (JsonOutput *) $7;
   16319         576 :                     n->on_empty = (JsonBehavior *) linitial($8);
   16320         576 :                     n->on_error = (JsonBehavior *) lsecond($8);
   16321         576 :                     n->location = @1;
   16322         576 :                     $$ = (Node *) n;
   16323             :                 }
   16324             :             ;
   16325             : 
   16326             : 
   16327             : /*
   16328             :  * SQL/XML support
   16329             :  */
   16330             : xml_root_version: VERSION_P a_expr
   16331          24 :                 { $$ = $2; }
   16332             :             | VERSION_P NO VALUE_P
   16333          46 :                 { $$ = makeNullAConst(-1); }
   16334             :         ;
   16335             : 
   16336             : opt_xml_root_standalone: ',' STANDALONE_P YES_P
   16337          28 :                 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
   16338             :             | ',' STANDALONE_P NO
   16339          12 :                 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
   16340             :             | ',' STANDALONE_P NO VALUE_P
   16341          12 :                 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
   16342             :             | /*EMPTY*/
   16343          18 :                 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
   16344             :         ;
   16345             : 
   16346          58 : xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')'    { $$ = $3; }
   16347             :         ;
   16348             : 
   16349          92 : xml_attribute_list: xml_attribute_el                    { $$ = list_make1($1); }
   16350         150 :             | xml_attribute_list ',' xml_attribute_el   { $$ = lappend($1, $3); }
   16351             :         ;
   16352             : 
   16353             : xml_attribute_el: a_expr AS ColLabel
   16354             :                 {
   16355         116 :                     $$ = makeNode(ResTarget);
   16356         116 :                     $$->name = $3;
   16357         116 :                     $$->indirection = NIL;
   16358         116 :                     $$->val = (Node *) $1;
   16359         116 :                     $$->location = @1;
   16360             :                 }
   16361             :             | a_expr
   16362             :                 {
   16363         126 :                     $$ = makeNode(ResTarget);
   16364         126 :                     $$->name = NULL;
   16365         126 :                     $$->indirection = NIL;
   16366         126 :                     $$->val = (Node *) $1;
   16367         126 :                     $$->location = @1;
   16368             :                 }
   16369             :         ;
   16370             : 
   16371         190 : document_or_content: DOCUMENT_P                     { $$ = XMLOPTION_DOCUMENT; }
   16372         194 :             | CONTENT_P                             { $$ = XMLOPTION_CONTENT; }
   16373             :         ;
   16374             : 
   16375         142 : xml_indent_option: INDENT                           { $$ = true; }
   16376          42 :             | NO INDENT                             { $$ = false; }
   16377          42 :             | /*EMPTY*/                             { $$ = false; }
   16378             :         ;
   16379             : 
   16380           0 : xml_whitespace_option: PRESERVE WHITESPACE_P        { $$ = true; }
   16381           4 :             | STRIP_P WHITESPACE_P                  { $$ = false; }
   16382         138 :             | /*EMPTY*/                             { $$ = false; }
   16383             :         ;
   16384             : 
   16385             : /* We allow several variants for SQL and other compatibility. */
   16386             : xmlexists_argument:
   16387             :             PASSING c_expr
   16388             :                 {
   16389         236 :                     $$ = $2;
   16390             :                 }
   16391             :             | PASSING c_expr xml_passing_mech
   16392             :                 {
   16393           0 :                     $$ = $2;
   16394             :                 }
   16395             :             | PASSING xml_passing_mech c_expr
   16396             :                 {
   16397          42 :                     $$ = $3;
   16398             :                 }
   16399             :             | PASSING xml_passing_mech c_expr xml_passing_mech
   16400             :                 {
   16401           6 :                     $$ = $3;
   16402             :                 }
   16403             :         ;
   16404             : 
   16405             : xml_passing_mech:
   16406             :             BY REF_P
   16407             :             | BY VALUE_P
   16408             :         ;
   16409             : 
   16410             : 
   16411             : /*
   16412             :  * Aggregate decoration clauses
   16413             :  */
   16414             : within_group_clause:
   16415         348 :             WITHIN GROUP_P '(' sort_clause ')'      { $$ = $4; }
   16416      319812 :             | /*EMPTY*/                             { $$ = NIL; }
   16417             :         ;
   16418             : 
   16419             : filter_clause:
   16420         854 :             FILTER '(' WHERE a_expr ')'             { $$ = $4; }
   16421      319666 :             | /*EMPTY*/                             { $$ = NULL; }
   16422             :         ;
   16423             : 
   16424             : 
   16425             : /*
   16426             :  * Window Definitions
   16427             :  */
   16428             : window_clause:
   16429         540 :             WINDOW window_definition_list           { $$ = $2; }
   16430      479950 :             | /*EMPTY*/                             { $$ = NIL; }
   16431             :         ;
   16432             : 
   16433             : window_definition_list:
   16434         540 :             window_definition                       { $$ = list_make1($1); }
   16435             :             | window_definition_list ',' window_definition
   16436          12 :                                                     { $$ = lappend($1, $3); }
   16437             :         ;
   16438             : 
   16439             : window_definition:
   16440             :             ColId AS window_specification
   16441             :                 {
   16442         552 :                     WindowDef  *n = $3;
   16443             : 
   16444         552 :                     n->name = $1;
   16445         552 :                     $$ = n;
   16446             :                 }
   16447             :         ;
   16448             : 
   16449             : over_clause: OVER window_specification
   16450        2618 :                 { $$ = $2; }
   16451             :             | OVER ColId
   16452             :                 {
   16453         954 :                     WindowDef  *n = makeNode(WindowDef);
   16454             : 
   16455         954 :                     n->name = $2;
   16456         954 :                     n->refname = NULL;
   16457         954 :                     n->partitionClause = NIL;
   16458         954 :                     n->orderClause = NIL;
   16459         954 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   16460         954 :                     n->startOffset = NULL;
   16461         954 :                     n->endOffset = NULL;
   16462         954 :                     n->location = @2;
   16463         954 :                     $$ = n;
   16464             :                 }
   16465             :             | /*EMPTY*/
   16466      316942 :                 { $$ = NULL; }
   16467             :         ;
   16468             : 
   16469             : window_specification: '(' opt_existing_window_name opt_partition_clause
   16470             :                         opt_sort_clause opt_frame_clause ')'
   16471             :                 {
   16472        3170 :                     WindowDef  *n = makeNode(WindowDef);
   16473             : 
   16474        3170 :                     n->name = NULL;
   16475        3170 :                     n->refname = $2;
   16476        3170 :                     n->partitionClause = $3;
   16477        3170 :                     n->orderClause = $4;
   16478             :                     /* copy relevant fields of opt_frame_clause */
   16479        3170 :                     n->frameOptions = $5->frameOptions;
   16480        3170 :                     n->startOffset = $5->startOffset;
   16481        3170 :                     n->endOffset = $5->endOffset;
   16482        3170 :                     n->location = @1;
   16483        3170 :                     $$ = n;
   16484             :                 }
   16485             :         ;
   16486             : 
   16487             : /*
   16488             :  * If we see PARTITION, RANGE, ROWS or GROUPS as the first token after the '('
   16489             :  * of a window_specification, we want the assumption to be that there is
   16490             :  * no existing_window_name; but those keywords are unreserved and so could
   16491             :  * be ColIds.  We fix this by making them have the same precedence as IDENT
   16492             :  * and giving the empty production here a slightly higher precedence, so
   16493             :  * that the shift/reduce conflict is resolved in favor of reducing the rule.
   16494             :  * These keywords are thus precluded from being an existing_window_name but
   16495             :  * are not reserved for any other purpose.
   16496             :  */
   16497          54 : opt_existing_window_name: ColId                     { $$ = $1; }
   16498        3122 :             | /*EMPTY*/             %prec Op        { $$ = NULL; }
   16499             :         ;
   16500             : 
   16501         922 : opt_partition_clause: PARTITION BY expr_list        { $$ = $3; }
   16502        2248 :             | /*EMPTY*/                             { $$ = NIL; }
   16503             :         ;
   16504             : 
   16505             : /*
   16506             :  * For frame clauses, we return a WindowDef, but only some fields are used:
   16507             :  * frameOptions, startOffset, and endOffset.
   16508             :  */
   16509             : opt_frame_clause:
   16510             :             RANGE frame_extent opt_window_exclusion_clause
   16511             :                 {
   16512         796 :                     WindowDef  *n = $2;
   16513             : 
   16514         796 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
   16515         796 :                     n->frameOptions |= $3;
   16516         796 :                     $$ = n;
   16517             :                 }
   16518             :             | ROWS frame_extent opt_window_exclusion_clause
   16519             :                 {
   16520         624 :                     WindowDef  *n = $2;
   16521             : 
   16522         624 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
   16523         624 :                     n->frameOptions |= $3;
   16524         624 :                     $$ = n;
   16525             :                 }
   16526             :             | GROUPS frame_extent opt_window_exclusion_clause
   16527             :                 {
   16528         204 :                     WindowDef  *n = $2;
   16529             : 
   16530         204 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_GROUPS;
   16531         204 :                     n->frameOptions |= $3;
   16532         204 :                     $$ = n;
   16533             :                 }
   16534             :             | /*EMPTY*/
   16535             :                 {
   16536        1546 :                     WindowDef  *n = makeNode(WindowDef);
   16537             : 
   16538        1546 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   16539        1546 :                     n->startOffset = NULL;
   16540        1546 :                     n->endOffset = NULL;
   16541        1546 :                     $$ = n;
   16542             :                 }
   16543             :         ;
   16544             : 
   16545             : frame_extent: frame_bound
   16546             :                 {
   16547          12 :                     WindowDef  *n = $1;
   16548             : 
   16549             :                     /* reject invalid cases */
   16550          12 :                     if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   16551           0 :                         ereport(ERROR,
   16552             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16553             :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   16554             :                                  parser_errposition(@1)));
   16555          12 :                     if (n->frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING)
   16556           0 :                         ereport(ERROR,
   16557             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16558             :                                  errmsg("frame starting from following row cannot end with current row"),
   16559             :                                  parser_errposition(@1)));
   16560          12 :                     n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
   16561          12 :                     $$ = n;
   16562             :                 }
   16563             :             | BETWEEN frame_bound AND frame_bound
   16564             :                 {
   16565        1612 :                     WindowDef  *n1 = $2;
   16566        1612 :                     WindowDef  *n2 = $4;
   16567             : 
   16568             :                     /* form merged options */
   16569        1612 :                     int     frameOptions = n1->frameOptions;
   16570             :                     /* shift converts START_ options to END_ options */
   16571        1612 :                     frameOptions |= n2->frameOptions << 1;
   16572        1612 :                     frameOptions |= FRAMEOPTION_BETWEEN;
   16573             :                     /* reject invalid cases */
   16574        1612 :                     if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   16575           0 :                         ereport(ERROR,
   16576             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16577             :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   16578             :                                  parser_errposition(@2)));
   16579        1612 :                     if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
   16580           0 :                         ereport(ERROR,
   16581             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16582             :                                  errmsg("frame end cannot be UNBOUNDED PRECEDING"),
   16583             :                                  parser_errposition(@4)));
   16584        1612 :                     if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
   16585         460 :                         (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING))
   16586           0 :                         ereport(ERROR,
   16587             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16588             :                                  errmsg("frame starting from current row cannot have preceding rows"),
   16589             :                                  parser_errposition(@4)));
   16590        1612 :                     if ((frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING) &&
   16591         168 :                         (frameOptions & (FRAMEOPTION_END_OFFSET_PRECEDING |
   16592             :                                          FRAMEOPTION_END_CURRENT_ROW)))
   16593           0 :                         ereport(ERROR,
   16594             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16595             :                                  errmsg("frame starting from following row cannot have preceding rows"),
   16596             :                                  parser_errposition(@4)));
   16597        1612 :                     n1->frameOptions = frameOptions;
   16598        1612 :                     n1->endOffset = n2->startOffset;
   16599        1612 :                     $$ = n1;
   16600             :                 }
   16601             :         ;
   16602             : 
   16603             : /*
   16604             :  * This is used for both frame start and frame end, with output set up on
   16605             :  * the assumption it's frame start; the frame_extent productions must reject
   16606             :  * invalid cases.
   16607             :  */
   16608             : frame_bound:
   16609             :             UNBOUNDED PRECEDING
   16610             :                 {
   16611         198 :                     WindowDef  *n = makeNode(WindowDef);
   16612             : 
   16613         198 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
   16614         198 :                     n->startOffset = NULL;
   16615         198 :                     n->endOffset = NULL;
   16616         198 :                     $$ = n;
   16617             :                 }
   16618             :             | UNBOUNDED FOLLOWING
   16619             :                 {
   16620         376 :                     WindowDef  *n = makeNode(WindowDef);
   16621             : 
   16622         376 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
   16623         376 :                     n->startOffset = NULL;
   16624         376 :                     n->endOffset = NULL;
   16625         376 :                     $$ = n;
   16626             :                 }
   16627             :             | CURRENT_P ROW
   16628             :                 {
   16629         604 :                     WindowDef  *n = makeNode(WindowDef);
   16630             : 
   16631         604 :                     n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
   16632         604 :                     n->startOffset = NULL;
   16633         604 :                     n->endOffset = NULL;
   16634         604 :                     $$ = n;
   16635             :                 }
   16636             :             | a_expr PRECEDING
   16637             :                 {
   16638         906 :                     WindowDef  *n = makeNode(WindowDef);
   16639             : 
   16640         906 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_PRECEDING;
   16641         906 :                     n->startOffset = $1;
   16642         906 :                     n->endOffset = NULL;
   16643         906 :                     $$ = n;
   16644             :                 }
   16645             :             | a_expr FOLLOWING
   16646             :                 {
   16647        1152 :                     WindowDef  *n = makeNode(WindowDef);
   16648             : 
   16649        1152 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_FOLLOWING;
   16650        1152 :                     n->startOffset = $1;
   16651        1152 :                     n->endOffset = NULL;
   16652        1152 :                     $$ = n;
   16653             :                 }
   16654             :         ;
   16655             : 
   16656             : opt_window_exclusion_clause:
   16657          84 :             EXCLUDE CURRENT_P ROW   { $$ = FRAMEOPTION_EXCLUDE_CURRENT_ROW; }
   16658          96 :             | EXCLUDE GROUP_P       { $$ = FRAMEOPTION_EXCLUDE_GROUP; }
   16659         150 :             | EXCLUDE TIES          { $$ = FRAMEOPTION_EXCLUDE_TIES; }
   16660          18 :             | EXCLUDE NO OTHERS     { $$ = 0; }
   16661        1276 :             | /*EMPTY*/             { $$ = 0; }
   16662             :         ;
   16663             : 
   16664             : 
   16665             : /*
   16666             :  * Supporting nonterminals for expressions.
   16667             :  */
   16668             : 
   16669             : /* Explicit row production.
   16670             :  *
   16671             :  * SQL99 allows an optional ROW keyword, so we can now do single-element rows
   16672             :  * without conflicting with the parenthesized a_expr production.  Without the
   16673             :  * ROW keyword, there must be more than one a_expr inside the parens.
   16674             :  */
   16675           0 : row:        ROW '(' expr_list ')'                   { $$ = $3; }
   16676           0 :             | ROW '(' ')'                           { $$ = NIL; }
   16677        1968 :             | '(' expr_list ',' a_expr ')'          { $$ = lappend($2, $4); }
   16678             :         ;
   16679             : 
   16680        3780 : explicit_row:   ROW '(' expr_list ')'               { $$ = $3; }
   16681          36 :             | ROW '(' ')'                           { $$ = NIL; }
   16682             :         ;
   16683             : 
   16684        2674 : implicit_row:   '(' expr_list ',' a_expr ')'        { $$ = lappend($2, $4); }
   16685             :         ;
   16686             : 
   16687       17110 : sub_type:   ANY                                     { $$ = ANY_SUBLINK; }
   16688           0 :             | SOME                                  { $$ = ANY_SUBLINK; }
   16689         324 :             | ALL                                   { $$ = ALL_SUBLINK; }
   16690             :         ;
   16691             : 
   16692       11144 : all_Op:     Op                                      { $$ = $1; }
   16693       28390 :             | MathOp                                { $$ = $1; }
   16694             :         ;
   16695             : 
   16696          40 : MathOp:      '+'                                    { $$ = "+"; }
   16697          62 :             | '-'                                   { $$ = "-"; }
   16698         116 :             | '*'                                   { $$ = "*"; }
   16699           0 :             | '/'                                   { $$ = "/"; }
   16700           8 :             | '%'                                   { $$ = "%"; }
   16701           0 :             | '^'                                   { $$ = "^"; }
   16702         790 :             | '<'                                    { $$ = "<"; }
   16703         674 :             | '>'                                    { $$ = ">"; }
   16704       24774 :             | '='                                   { $$ = "="; }
   16705         650 :             | LESS_EQUALS                           { $$ = "<="; }
   16706         642 :             | GREATER_EQUALS                        { $$ = ">="; }
   16707         634 :             | NOT_EQUALS                            { $$ = "<>"; }
   16708             :         ;
   16709             : 
   16710             : qual_Op:    Op
   16711       43964 :                     { $$ = list_make1(makeString($1)); }
   16712             :             | OPERATOR '(' any_operator ')'
   16713       15406 :                     { $$ = $3; }
   16714             :         ;
   16715             : 
   16716             : qual_all_Op:
   16717             :             all_Op
   16718        1416 :                     { $$ = list_make1(makeString($1)); }
   16719             :             | OPERATOR '(' any_operator ')'
   16720          44 :                     { $$ = $3; }
   16721             :         ;
   16722             : 
   16723             : subquery_Op:
   16724             :             all_Op
   16725       17132 :                     { $$ = list_make1(makeString($1)); }
   16726             :             | OPERATOR '(' any_operator ')'
   16727         270 :                     { $$ = $3; }
   16728             :             | LIKE
   16729          24 :                     { $$ = list_make1(makeString("~~")); }
   16730             :             | NOT_LA LIKE
   16731          12 :                     { $$ = list_make1(makeString("!~~")); }
   16732             :             | ILIKE
   16733          12 :                     { $$ = list_make1(makeString("~~*")); }
   16734             :             | NOT_LA ILIKE
   16735           0 :                     { $$ = list_make1(makeString("!~~*")); }
   16736             : /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
   16737             :  * the regular expression is preprocessed by a function (similar_to_escape),
   16738             :  * and the ~ operator for posix regular expressions is used.
   16739             :  *        x SIMILAR TO y     ->    x ~ similar_to_escape(y)
   16740             :  * this transformation is made on the fly by the parser upwards.
   16741             :  * however the SubLink structure which handles any/some/all stuff
   16742             :  * is not ready for such a thing.
   16743             :  */
   16744             :             ;
   16745             : 
   16746             : expr_list:  a_expr
   16747             :                 {
   16748      165766 :                     $$ = list_make1($1);
   16749             :                 }
   16750             :             | expr_list ',' a_expr
   16751             :                 {
   16752      147176 :                     $$ = lappend($1, $3);
   16753             :                 }
   16754             :         ;
   16755             : 
   16756             : /* function arguments can have names */
   16757             : func_arg_list:  func_arg_expr
   16758             :                 {
   16759      324008 :                     $$ = list_make1($1);
   16760             :                 }
   16761             :             | func_arg_list ',' func_arg_expr
   16762             :                 {
   16763      283122 :                     $$ = lappend($1, $3);
   16764             :                 }
   16765             :         ;
   16766             : 
   16767             : func_arg_expr:  a_expr
   16768             :                 {
   16769      560738 :                     $$ = $1;
   16770             :                 }
   16771             :             | param_name COLON_EQUALS a_expr
   16772             :                 {
   16773       45514 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   16774             : 
   16775       45514 :                     na->name = $1;
   16776       45514 :                     na->arg = (Expr *) $3;
   16777       45514 :                     na->argnumber = -1;      /* until determined */
   16778       45514 :                     na->location = @1;
   16779       45514 :                     $$ = (Node *) na;
   16780             :                 }
   16781             :             | param_name EQUALS_GREATER a_expr
   16782             :                 {
   16783        1612 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   16784             : 
   16785        1612 :                     na->name = $1;
   16786        1612 :                     na->arg = (Expr *) $3;
   16787        1612 :                     na->argnumber = -1;      /* until determined */
   16788        1612 :                     na->location = @1;
   16789        1612 :                     $$ = (Node *) na;
   16790             :                 }
   16791             :         ;
   16792             : 
   16793         254 : func_arg_list_opt:  func_arg_list                   { $$ = $1; }
   16794           0 :             | /*EMPTY*/                             { $$ = NIL; }
   16795             :         ;
   16796             : 
   16797        2178 : type_list:  Typename                                { $$ = list_make1($1); }
   16798         590 :             | type_list ',' Typename                { $$ = lappend($1, $3); }
   16799             :         ;
   16800             : 
   16801             : array_expr: '[' expr_list ']'
   16802             :                 {
   16803        7730 :                     $$ = makeAArrayExpr($2, @1, @3);
   16804             :                 }
   16805             :             | '[' array_expr_list ']'
   16806             :                 {
   16807         412 :                     $$ = makeAArrayExpr($2, @1, @3);
   16808             :                 }
   16809             :             | '[' ']'
   16810             :                 {
   16811          88 :                     $$ = makeAArrayExpr(NIL, @1, @2);
   16812             :                 }
   16813             :         ;
   16814             : 
   16815         412 : array_expr_list: array_expr                         { $$ = list_make1($1); }
   16816         342 :             | array_expr_list ',' array_expr        { $$ = lappend($1, $3); }
   16817             :         ;
   16818             : 
   16819             : 
   16820             : extract_list:
   16821             :             extract_arg FROM a_expr
   16822             :                 {
   16823        1390 :                     $$ = list_make2(makeStringConst($1, @1), $3);
   16824             :                 }
   16825             :         ;
   16826             : 
   16827             : /* Allow delimited string Sconst in extract_arg as an SQL extension.
   16828             :  * - thomas 2001-04-12
   16829             :  */
   16830             : extract_arg:
   16831        1132 :             IDENT                                   { $$ = $1; }
   16832          72 :             | YEAR_P                                { $$ = "year"; }
   16833          42 :             | MONTH_P                               { $$ = "month"; }
   16834          54 :             | DAY_P                                 { $$ = "day"; }
   16835          30 :             | HOUR_P                                { $$ = "hour"; }
   16836          30 :             | MINUTE_P                              { $$ = "minute"; }
   16837          30 :             | SECOND_P                              { $$ = "second"; }
   16838           0 :             | Sconst                                { $$ = $1; }
   16839             :         ;
   16840             : 
   16841             : unicode_normal_form:
   16842          24 :             NFC                                     { $$ = "NFC"; }
   16843          18 :             | NFD                                   { $$ = "NFD"; }
   16844          18 :             | NFKC                                  { $$ = "NFKC"; }
   16845          18 :             | NFKD                                  { $$ = "NFKD"; }
   16846             :         ;
   16847             : 
   16848             : /* OVERLAY() arguments */
   16849             : overlay_list:
   16850             :             a_expr PLACING a_expr FROM a_expr FOR a_expr
   16851             :                 {
   16852             :                     /* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D) */
   16853          34 :                     $$ = list_make4($1, $3, $5, $7);
   16854             :                 }
   16855             :             | a_expr PLACING a_expr FROM a_expr
   16856             :                 {
   16857             :                     /* overlay(A PLACING B FROM C) is converted to overlay(A, B, C) */
   16858          48 :                     $$ = list_make3($1, $3, $5);
   16859             :                 }
   16860             :         ;
   16861             : 
   16862             : /* position_list uses b_expr not a_expr to avoid conflict with general IN */
   16863             : position_list:
   16864         402 :             b_expr IN_P b_expr                      { $$ = list_make2($3, $1); }
   16865             :         ;
   16866             : 
   16867             : /*
   16868             :  * SUBSTRING() arguments
   16869             :  *
   16870             :  * Note that SQL:1999 has both
   16871             :  *     text FROM int FOR int
   16872             :  * and
   16873             :  *     text FROM pattern FOR escape
   16874             :  *
   16875             :  * In the parser we map them both to a call to the substring() function and
   16876             :  * rely on type resolution to pick the right one.
   16877             :  *
   16878             :  * In SQL:2003, the second variant was changed to
   16879             :  *     text SIMILAR pattern ESCAPE escape
   16880             :  * We could in theory map that to a different function internally, but
   16881             :  * since we still support the SQL:1999 version, we don't.  However,
   16882             :  * ruleutils.c will reverse-list the call in the newer style.
   16883             :  */
   16884             : substr_list:
   16885             :             a_expr FROM a_expr FOR a_expr
   16886             :                 {
   16887         122 :                     $$ = list_make3($1, $3, $5);
   16888             :                 }
   16889             :             | a_expr FOR a_expr FROM a_expr
   16890             :                 {
   16891             :                     /* not legal per SQL, but might as well allow it */
   16892           0 :                     $$ = list_make3($1, $5, $3);
   16893             :                 }
   16894             :             | a_expr FROM a_expr
   16895             :                 {
   16896             :                     /*
   16897             :                      * Because we aren't restricting data types here, this
   16898             :                      * syntax can end up resolving to textregexsubstr().
   16899             :                      * We've historically allowed that to happen, so continue
   16900             :                      * to accept it.  However, ruleutils.c will reverse-list
   16901             :                      * such a call in regular function call syntax.
   16902             :                      */
   16903         376 :                     $$ = list_make2($1, $3);
   16904             :                 }
   16905             :             | a_expr FOR a_expr
   16906             :                 {
   16907             :                     /* not legal per SQL */
   16908             : 
   16909             :                     /*
   16910             :                      * Since there are no cases where this syntax allows
   16911             :                      * a textual FOR value, we forcibly cast the argument
   16912             :                      * to int4.  The possible matches in pg_proc are
   16913             :                      * substring(text,int4) and substring(text,text),
   16914             :                      * and we don't want the parser to choose the latter,
   16915             :                      * which it is likely to do if the second argument
   16916             :                      * is unknown or doesn't have an implicit cast to int4.
   16917             :                      */
   16918          36 :                     $$ = list_make3($1, makeIntConst(1, -1),
   16919             :                                     makeTypeCast($3,
   16920             :                                                  SystemTypeName("int4"), -1));
   16921             :                 }
   16922             :             | a_expr SIMILAR a_expr ESCAPE a_expr
   16923             :                 {
   16924         184 :                     $$ = list_make3($1, $3, $5);
   16925             :                 }
   16926             :         ;
   16927             : 
   16928         606 : trim_list:  a_expr FROM expr_list                   { $$ = lappend($3, $1); }
   16929          24 :             | FROM expr_list                        { $$ = $2; }
   16930          86 :             | expr_list                             { $$ = $1; }
   16931             :         ;
   16932             : 
   16933             : /*
   16934             :  * Define SQL-style CASE clause.
   16935             :  * - Full specification
   16936             :  *  CASE WHEN a = b THEN c ... ELSE d END
   16937             :  * - Implicit argument
   16938             :  *  CASE a WHEN b THEN c ... ELSE d END
   16939             :  */
   16940             : case_expr:  CASE case_arg when_clause_list case_default END_P
   16941             :                 {
   16942       40550 :                     CaseExpr   *c = makeNode(CaseExpr);
   16943             : 
   16944       40550 :                     c->casetype = InvalidOid; /* not analyzed yet */
   16945       40550 :                     c->arg = (Expr *) $2;
   16946       40550 :                     c->args = $3;
   16947       40550 :                     c->defresult = (Expr *) $4;
   16948       40550 :                     c->location = @1;
   16949       40550 :                     $$ = (Node *) c;
   16950             :                 }
   16951             :         ;
   16952             : 
   16953             : when_clause_list:
   16954             :             /* There must be at least one */
   16955       40550 :             when_clause                             { $$ = list_make1($1); }
   16956       29372 :             | when_clause_list when_clause          { $$ = lappend($1, $2); }
   16957             :         ;
   16958             : 
   16959             : when_clause:
   16960             :             WHEN a_expr THEN a_expr
   16961             :                 {
   16962       69922 :                     CaseWhen   *w = makeNode(CaseWhen);
   16963             : 
   16964       69922 :                     w->expr = (Expr *) $2;
   16965       69922 :                     w->result = (Expr *) $4;
   16966       69922 :                     w->location = @1;
   16967       69922 :                     $$ = (Node *) w;
   16968             :                 }
   16969             :         ;
   16970             : 
   16971             : case_default:
   16972       30860 :             ELSE a_expr                             { $$ = $2; }
   16973        9690 :             | /*EMPTY*/                             { $$ = NULL; }
   16974             :         ;
   16975             : 
   16976        6702 : case_arg:   a_expr                                  { $$ = $1; }
   16977       33848 :             | /*EMPTY*/                             { $$ = NULL; }
   16978             :         ;
   16979             : 
   16980             : columnref:  ColId
   16981             :                 {
   16982      780562 :                     $$ = makeColumnRef($1, NIL, @1, yyscanner);
   16983             :                 }
   16984             :             | ColId indirection
   16985             :                 {
   16986     1092472 :                     $$ = makeColumnRef($1, $2, @1, yyscanner);
   16987             :                 }
   16988             :         ;
   16989             : 
   16990             : indirection_el:
   16991             :             '.' attr_name
   16992             :                 {
   16993     1487552 :                     $$ = (Node *) makeString($2);
   16994             :                 }
   16995             :             | '.' '*'
   16996             :                 {
   16997        6930 :                     $$ = (Node *) makeNode(A_Star);
   16998             :                 }
   16999             :             | '[' a_expr ']'
   17000             :                 {
   17001       13144 :                     A_Indices *ai = makeNode(A_Indices);
   17002             : 
   17003       13144 :                     ai->is_slice = false;
   17004       13144 :                     ai->lidx = NULL;
   17005       13144 :                     ai->uidx = $2;
   17006       13144 :                     $$ = (Node *) ai;
   17007             :                 }
   17008             :             | '[' opt_slice_bound ':' opt_slice_bound ']'
   17009             :                 {
   17010         588 :                     A_Indices *ai = makeNode(A_Indices);
   17011             : 
   17012         588 :                     ai->is_slice = true;
   17013         588 :                     ai->lidx = $2;
   17014         588 :                     ai->uidx = $4;
   17015         588 :                     $$ = (Node *) ai;
   17016             :                 }
   17017             :         ;
   17018             : 
   17019             : opt_slice_bound:
   17020         996 :             a_expr                                  { $$ = $1; }
   17021         180 :             | /*EMPTY*/                             { $$ = NULL; }
   17022             :         ;
   17023             : 
   17024             : indirection:
   17025     1487476 :             indirection_el                          { $$ = list_make1($1); }
   17026        3092 :             | indirection indirection_el            { $$ = lappend($1, $2); }
   17027             :         ;
   17028             : 
   17029             : opt_indirection:
   17030      199506 :             /*EMPTY*/                               { $$ = NIL; }
   17031       17646 :             | opt_indirection indirection_el        { $$ = lappend($1, $2); }
   17032             :         ;
   17033             : 
   17034             : opt_asymmetric: ASYMMETRIC
   17035             :             | /*EMPTY*/
   17036             :         ;
   17037             : 
   17038             : /* SQL/JSON support */
   17039             : json_passing_clause_opt:
   17040         336 :             PASSING json_arguments                  { $$ = $2; }
   17041        1934 :             | /*EMPTY*/                             { $$ = NIL; }
   17042             :         ;
   17043             : 
   17044             : json_arguments:
   17045         336 :             json_argument                           { $$ = list_make1($1); }
   17046         126 :             | json_arguments ',' json_argument      { $$ = lappend($1, $3); }
   17047             :         ;
   17048             : 
   17049             : json_argument:
   17050             :             json_value_expr AS ColLabel
   17051             :             {
   17052         462 :                 JsonArgument *n = makeNode(JsonArgument);
   17053             : 
   17054         462 :                 n->val = (JsonValueExpr *) $1;
   17055         462 :                 n->name = $3;
   17056         462 :                 $$ = (Node *) n;
   17057             :             }
   17058             :         ;
   17059             : 
   17060             : /* ARRAY is a noise word */
   17061             : json_wrapper_behavior:
   17062          42 :               WITHOUT WRAPPER                   { $$ = JSW_NONE; }
   17063           0 :             | WITHOUT ARRAY WRAPPER             { $$ = JSW_NONE; }
   17064          78 :             | WITH WRAPPER                      { $$ = JSW_UNCONDITIONAL; }
   17065          12 :             | WITH ARRAY WRAPPER                { $$ = JSW_UNCONDITIONAL; }
   17066           0 :             | WITH CONDITIONAL ARRAY WRAPPER    { $$ = JSW_CONDITIONAL; }
   17067          12 :             | WITH UNCONDITIONAL ARRAY WRAPPER  { $$ = JSW_UNCONDITIONAL; }
   17068          36 :             | WITH CONDITIONAL WRAPPER          { $$ = JSW_CONDITIONAL; }
   17069           6 :             | WITH UNCONDITIONAL WRAPPER        { $$ = JSW_UNCONDITIONAL; }
   17070        1634 :             | /* empty */                       { $$ = JSW_UNSPEC; }
   17071             :         ;
   17072             : 
   17073             : json_behavior:
   17074             :             DEFAULT a_expr
   17075         384 :                 { $$ = (Node *) makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); }
   17076             :             | json_behavior_type
   17077         702 :                 { $$ = (Node *) makeJsonBehavior($1, NULL, @1); }
   17078             :         ;
   17079             : 
   17080             : json_behavior_type:
   17081         492 :             ERROR_P     { $$ = JSON_BEHAVIOR_ERROR; }
   17082          30 :             | NULL_P    { $$ = JSON_BEHAVIOR_NULL; }
   17083          30 :             | TRUE_P    { $$ = JSON_BEHAVIOR_TRUE; }
   17084          12 :             | FALSE_P   { $$ = JSON_BEHAVIOR_FALSE; }
   17085          12 :             | UNKNOWN   { $$ = JSON_BEHAVIOR_UNKNOWN; }
   17086          30 :             | EMPTY_P ARRAY { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
   17087          72 :             | EMPTY_P OBJECT_P  { $$ = JSON_BEHAVIOR_EMPTY_OBJECT; }
   17088             :             /* non-standard, for Oracle compatibility only */
   17089          24 :             | EMPTY_P   { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
   17090             :         ;
   17091             : 
   17092             : json_behavior_clause_opt:
   17093             :             json_behavior ON EMPTY_P
   17094         174 :                 { $$ = list_make2($1, NULL); }
   17095             :             | json_behavior ON ERROR_P
   17096         552 :                 { $$ = list_make2(NULL, $1); }
   17097             :             | json_behavior ON EMPTY_P json_behavior ON ERROR_P
   17098         102 :                 { $$ = list_make2($1, $4); }
   17099             :             | /* EMPTY */
   17100        1568 :                 { $$ = list_make2(NULL, NULL); }
   17101             :         ;
   17102             : 
   17103             : json_on_error_clause_opt:
   17104             :             json_behavior ON ERROR_P
   17105         150 :                 { $$ = $1; }
   17106             :             | /* EMPTY */
   17107         686 :                 { $$ = NULL; }
   17108             :         ;
   17109             : 
   17110             : json_value_expr:
   17111             :             a_expr json_format_clause_opt
   17112             :             {
   17113             :                 /* formatted_expr will be set during parse-analysis. */
   17114        4202 :                 $$ = (Node *) makeJsonValueExpr((Expr *) $1, NULL,
   17115        4202 :                                                 castNode(JsonFormat, $2));
   17116             :             }
   17117             :         ;
   17118             : 
   17119             : json_format_clause:
   17120             :             FORMAT_LA JSON ENCODING name
   17121             :                 {
   17122             :                     int     encoding;
   17123             : 
   17124         100 :                     if (!pg_strcasecmp($4, "utf8"))
   17125          64 :                         encoding = JS_ENC_UTF8;
   17126          36 :                     else if (!pg_strcasecmp($4, "utf16"))
   17127          12 :                         encoding = JS_ENC_UTF16;
   17128          24 :                     else if (!pg_strcasecmp($4, "utf32"))
   17129          12 :                         encoding = JS_ENC_UTF32;
   17130             :                     else
   17131          12 :                         ereport(ERROR,
   17132             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   17133             :                                  errmsg("unrecognized JSON encoding: %s", $4),
   17134             :                                  parser_errposition(@4)));
   17135             : 
   17136          88 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
   17137             :                 }
   17138             :             | FORMAT_LA JSON
   17139             :                 {
   17140         412 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
   17141             :                 }
   17142             :         ;
   17143             : 
   17144             : json_format_clause_opt:
   17145             :             json_format_clause
   17146             :                 {
   17147         392 :                     $$ = $1;
   17148             :                 }
   17149             :             | /* EMPTY */
   17150             :                 {
   17151        5314 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   17152             :                 }
   17153             :         ;
   17154             : 
   17155             : json_quotes_clause_opt:
   17156          12 :             KEEP QUOTES ON SCALAR STRING_P      { $$ = JS_QUOTES_KEEP; }
   17157          90 :             | KEEP QUOTES                       { $$ = JS_QUOTES_KEEP; }
   17158          12 :             | OMIT QUOTES ON SCALAR STRING_P    { $$ = JS_QUOTES_OMIT; }
   17159         168 :             | OMIT QUOTES                       { $$ = JS_QUOTES_OMIT; }
   17160        1538 :             | /* EMPTY */                       { $$ = JS_QUOTES_UNSPEC; }
   17161             :         ;
   17162             : 
   17163             : json_returning_clause_opt:
   17164             :             RETURNING Typename json_format_clause_opt
   17165             :                 {
   17166        1444 :                     JsonOutput *n = makeNode(JsonOutput);
   17167             : 
   17168        1444 :                     n->typeName = $2;
   17169        1444 :                     n->returning = makeNode(JsonReturning);
   17170        1444 :                     n->returning->format = (JsonFormat *) $3;
   17171        1444 :                     $$ = (Node *) n;
   17172             :                 }
   17173        1278 :             | /* EMPTY */                           { $$ = NULL; }
   17174             :         ;
   17175             : 
   17176             : /*
   17177             :  * We must assign the only-JSON production a precedence less than IDENT in
   17178             :  * order to favor shifting over reduction when JSON is followed by VALUE_P,
   17179             :  * OBJECT_P, or SCALAR.  (ARRAY doesn't need that treatment, because it's a
   17180             :  * fully reserved word.)  Because json_predicate_type_constraint is always
   17181             :  * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
   17182             :  * production to have precedence less than WITH and WITHOUT.  UNBOUNDED isn't
   17183             :  * really related to this syntax, but it's a convenient choice because it
   17184             :  * already has a precedence less than IDENT for other reasons.
   17185             :  */
   17186             : json_predicate_type_constraint:
   17187         202 :             JSON                    %prec UNBOUNDED { $$ = JS_TYPE_ANY; }
   17188          28 :             | JSON VALUE_P                          { $$ = JS_TYPE_ANY; }
   17189          40 :             | JSON ARRAY                            { $$ = JS_TYPE_ARRAY; }
   17190          40 :             | JSON OBJECT_P                         { $$ = JS_TYPE_OBJECT; }
   17191          40 :             | JSON SCALAR                           { $$ = JS_TYPE_SCALAR; }
   17192             :         ;
   17193             : 
   17194             : /*
   17195             :  * KEYS is a noise word here.  To avoid shift/reduce conflicts, assign the
   17196             :  * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
   17197             :  * This prevents reducing them when the next token is KEYS.
   17198             :  */
   17199             : json_key_uniqueness_constraint_opt:
   17200         108 :             WITH UNIQUE KEYS                            { $$ = true; }
   17201         100 :             | WITH UNIQUE               %prec UNBOUNDED { $$ = true; }
   17202          44 :             | WITHOUT UNIQUE KEYS                       { $$ = false; }
   17203          16 :             | WITHOUT UNIQUE            %prec UNBOUNDED { $$ = false; }
   17204         798 :             | /* EMPTY */               %prec UNBOUNDED { $$ = false; }
   17205             :         ;
   17206             : 
   17207             : json_name_and_value_list:
   17208             :             json_name_and_value
   17209         348 :                 { $$ = list_make1($1); }
   17210             :             | json_name_and_value_list ',' json_name_and_value
   17211         256 :                 { $$ = lappend($1, $3); }
   17212             :         ;
   17213             : 
   17214             : json_name_and_value:
   17215             : /* Supporting this syntax seems to require major surgery
   17216             :             KEY c_expr VALUE_P json_value_expr
   17217             :                 { $$ = makeJsonKeyValue($2, $4); }
   17218             :             |
   17219             : */
   17220             :             c_expr VALUE_P json_value_expr
   17221          24 :                 { $$ = makeJsonKeyValue($1, $3); }
   17222             :             |
   17223             :             a_expr ':' json_value_expr
   17224         784 :                 { $$ = makeJsonKeyValue($1, $3); }
   17225             :         ;
   17226             : 
   17227             : /* empty means false for objects, true for arrays */
   17228             : json_object_constructor_null_clause_opt:
   17229          30 :             NULL_P ON NULL_P                    { $$ = false; }
   17230         110 :             | ABSENT ON NULL_P                  { $$ = true; }
   17231         412 :             | /* EMPTY */                       { $$ = false; }
   17232             :         ;
   17233             : 
   17234             : json_array_constructor_null_clause_opt:
   17235          60 :             NULL_P ON NULL_P                        { $$ = false; }
   17236          36 :             | ABSENT ON NULL_P                      { $$ = true; }
   17237         168 :             | /* EMPTY */                           { $$ = true; }
   17238             :         ;
   17239             : 
   17240             : json_value_expr_list:
   17241         108 :             json_value_expr                             { $$ = list_make1($1); }
   17242         126 :             | json_value_expr_list ',' json_value_expr  { $$ = lappend($1, $3);}
   17243             :         ;
   17244             : 
   17245             : json_aggregate_func:
   17246             :             JSON_OBJECTAGG '('
   17247             :                 json_name_and_value
   17248             :                 json_object_constructor_null_clause_opt
   17249             :                 json_key_uniqueness_constraint_opt
   17250             :                 json_returning_clause_opt
   17251             :             ')'
   17252             :                 {
   17253         204 :                     JsonObjectAgg *n = makeNode(JsonObjectAgg);
   17254             : 
   17255         204 :                     n->arg = (JsonKeyValue *) $3;
   17256         204 :                     n->absent_on_null = $4;
   17257         204 :                     n->unique = $5;
   17258         204 :                     n->constructor = makeNode(JsonAggConstructor);
   17259         204 :                     n->constructor->output = (JsonOutput *) $6;
   17260         204 :                     n->constructor->agg_order = NULL;
   17261         204 :                     n->constructor->location = @1;
   17262         204 :                     $$ = (Node *) n;
   17263             :                 }
   17264             :             | JSON_ARRAYAGG '('
   17265             :                 json_value_expr
   17266             :                 json_array_aggregate_order_by_clause_opt
   17267             :                 json_array_constructor_null_clause_opt
   17268             :                 json_returning_clause_opt
   17269             :             ')'
   17270             :                 {
   17271         156 :                     JsonArrayAgg *n = makeNode(JsonArrayAgg);
   17272             : 
   17273         156 :                     n->arg = (JsonValueExpr *) $3;
   17274         156 :                     n->absent_on_null = $5;
   17275         156 :                     n->constructor = makeNode(JsonAggConstructor);
   17276         156 :                     n->constructor->agg_order = $4;
   17277         156 :                     n->constructor->output = (JsonOutput *) $6;
   17278         156 :                     n->constructor->location = @1;
   17279         156 :                     $$ = (Node *) n;
   17280             :                 }
   17281             :         ;
   17282             : 
   17283             : json_array_aggregate_order_by_clause_opt:
   17284          18 :             ORDER BY sortby_list                    { $$ = $3; }
   17285         138 :             | /* EMPTY */                           { $$ = NIL; }
   17286             :         ;
   17287             : 
   17288             : /*****************************************************************************
   17289             :  *
   17290             :  *  target list for SELECT
   17291             :  *
   17292             :  *****************************************************************************/
   17293             : 
   17294      476270 : opt_target_list: target_list                        { $$ = $1; }
   17295         494 :             | /* EMPTY */                           { $$ = NIL; }
   17296             :         ;
   17297             : 
   17298             : target_list:
   17299      483194 :             target_el                               { $$ = list_make1($1); }
   17300      711132 :             | target_list ',' target_el             { $$ = lappend($1, $3); }
   17301             :         ;
   17302             : 
   17303             : target_el:  a_expr AS ColLabel
   17304             :                 {
   17305      245266 :                     $$ = makeNode(ResTarget);
   17306      245266 :                     $$->name = $3;
   17307      245266 :                     $$->indirection = NIL;
   17308      245266 :                     $$->val = (Node *) $1;
   17309      245266 :                     $$->location = @1;
   17310             :                 }
   17311             :             | a_expr BareColLabel
   17312             :                 {
   17313        3626 :                     $$ = makeNode(ResTarget);
   17314        3626 :                     $$->name = $2;
   17315        3626 :                     $$->indirection = NIL;
   17316        3626 :                     $$->val = (Node *) $1;
   17317        3626 :                     $$->location = @1;
   17318             :                 }
   17319             :             | a_expr
   17320             :                 {
   17321      889644 :                     $$ = makeNode(ResTarget);
   17322      889644 :                     $$->name = NULL;
   17323      889644 :                     $$->indirection = NIL;
   17324      889644 :                     $$->val = (Node *) $1;
   17325      889644 :                     $$->location = @1;
   17326             :                 }
   17327             :             | '*'
   17328             :                 {
   17329       55790 :                     ColumnRef  *n = makeNode(ColumnRef);
   17330             : 
   17331       55790 :                     n->fields = list_make1(makeNode(A_Star));
   17332       55790 :                     n->location = @1;
   17333             : 
   17334       55790 :                     $$ = makeNode(ResTarget);
   17335       55790 :                     $$->name = NULL;
   17336       55790 :                     $$->indirection = NIL;
   17337       55790 :                     $$->val = (Node *) n;
   17338       55790 :                     $$->location = @1;
   17339             :                 }
   17340             :         ;
   17341             : 
   17342             : 
   17343             : /*****************************************************************************
   17344             :  *
   17345             :  *  Names and constants
   17346             :  *
   17347             :  *****************************************************************************/
   17348             : 
   17349             : qualified_name_list:
   17350       17606 :             qualified_name                          { $$ = list_make1($1); }
   17351         466 :             | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
   17352             :         ;
   17353             : 
   17354             : /*
   17355             :  * The production for a qualified relation name has to exactly match the
   17356             :  * production for a qualified func_name, because in a FROM clause we cannot
   17357             :  * tell which we are parsing until we see what comes after it ('(' for a
   17358             :  * func_name, something else for a relation). Therefore we allow 'indirection'
   17359             :  * which may contain subscripts, and reject that case in the C code.
   17360             :  */
   17361             : qualified_name:
   17362             :             ColId
   17363             :                 {
   17364      426632 :                     $$ = makeRangeVar(NULL, $1, @1);
   17365             :                 }
   17366             :             | ColId indirection
   17367             :                 {
   17368      264046 :                     $$ = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   17369             :                 }
   17370             :         ;
   17371             : 
   17372             : name_list:  name
   17373       29126 :                     { $$ = list_make1(makeString($1)); }
   17374             :             | name_list ',' name
   17375       62462 :                     { $$ = lappend($1, makeString($3)); }
   17376             :         ;
   17377             : 
   17378             : 
   17379      182294 : name:       ColId                                   { $$ = $1; };
   17380             : 
   17381     1617546 : attr_name:  ColLabel                                { $$ = $1; };
   17382             : 
   17383          52 : file_name:  Sconst                                  { $$ = $1; };
   17384             : 
   17385             : /*
   17386             :  * The production for a qualified func_name has to exactly match the
   17387             :  * production for a qualified columnref, because we cannot tell which we
   17388             :  * are parsing until we see what comes after it ('(' or Sconst for a func_name,
   17389             :  * anything else for a columnref).  Therefore we allow 'indirection' which
   17390             :  * may contain subscripts, and reject that case in the C code.  (If we
   17391             :  * ever implement SQL99-like methods, such syntax may actually become legal!)
   17392             :  */
   17393             : func_name:  type_function_name
   17394      295446 :                     { $$ = list_make1(makeString($1)); }
   17395             :             | ColId indirection
   17396             :                     {
   17397      130880 :                         $$ = check_func_name(lcons(makeString($1), $2),
   17398             :                                              yyscanner);
   17399             :                     }
   17400             :         ;
   17401             : 
   17402             : 
   17403             : /*
   17404             :  * Constants
   17405             :  */
   17406             : AexprConst: Iconst
   17407             :                 {
   17408      379280 :                     $$ = makeIntConst($1, @1);
   17409             :                 }
   17410             :             | FCONST
   17411             :                 {
   17412       11410 :                     $$ = makeFloatConst($1, @1);
   17413             :                 }
   17414             :             | Sconst
   17415             :                 {
   17416      707984 :                     $$ = makeStringConst($1, @1);
   17417             :                 }
   17418             :             | BCONST
   17419             :                 {
   17420         754 :                     $$ = makeBitStringConst($1, @1);
   17421             :                 }
   17422             :             | XCONST
   17423             :                 {
   17424             :                     /* This is a bit constant per SQL99:
   17425             :                      * Without Feature F511, "BIT data type",
   17426             :                      * a <general literal> shall not be a
   17427             :                      * <bit string literal> or a <hex string literal>.
   17428             :                      */
   17429        3302 :                     $$ = makeBitStringConst($1, @1);
   17430             :                 }
   17431             :             | func_name Sconst
   17432             :                 {
   17433             :                     /* generic type 'literal' syntax */
   17434        9836 :                     TypeName   *t = makeTypeNameFromNameList($1);
   17435             : 
   17436        9836 :                     t->location = @1;
   17437        9836 :                     $$ = makeStringConstCast($2, @2, t);
   17438             :                 }
   17439             :             | func_name '(' func_arg_list opt_sort_clause ')' Sconst
   17440             :                 {
   17441             :                     /* generic syntax with a type modifier */
   17442           0 :                     TypeName   *t = makeTypeNameFromNameList($1);
   17443             :                     ListCell   *lc;
   17444             : 
   17445             :                     /*
   17446             :                      * We must use func_arg_list and opt_sort_clause in the
   17447             :                      * production to avoid reduce/reduce conflicts, but we
   17448             :                      * don't actually wish to allow NamedArgExpr in this
   17449             :                      * context, nor ORDER BY.
   17450             :                      */
   17451           0 :                     foreach(lc, $3)
   17452             :                     {
   17453           0 :                         NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
   17454             : 
   17455           0 :                         if (IsA(arg, NamedArgExpr))
   17456           0 :                             ereport(ERROR,
   17457             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17458             :                                      errmsg("type modifier cannot have parameter name"),
   17459             :                                      parser_errposition(arg->location)));
   17460             :                     }
   17461           0 :                     if ($4 != NIL)
   17462           0 :                             ereport(ERROR,
   17463             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17464             :                                      errmsg("type modifier cannot have ORDER BY"),
   17465             :                                      parser_errposition(@4)));
   17466             : 
   17467           0 :                     t->typmods = $3;
   17468           0 :                     t->location = @1;
   17469           0 :                     $$ = makeStringConstCast($6, @6, t);
   17470             :                 }
   17471             :             | ConstTypename Sconst
   17472             :                 {
   17473        3126 :                     $$ = makeStringConstCast($2, @2, $1);
   17474             :                 }
   17475             :             | ConstInterval Sconst opt_interval
   17476             :                 {
   17477        3298 :                     TypeName   *t = $1;
   17478             : 
   17479        3298 :                     t->typmods = $3;
   17480        3298 :                     $$ = makeStringConstCast($2, @2, t);
   17481             :                 }
   17482             :             | ConstInterval '(' Iconst ')' Sconst
   17483             :                 {
   17484          12 :                     TypeName   *t = $1;
   17485             : 
   17486          12 :                     t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   17487             :                                             makeIntConst($3, @3));
   17488          12 :                     $$ = makeStringConstCast($5, @5, t);
   17489             :                 }
   17490             :             | TRUE_P
   17491             :                 {
   17492       31200 :                     $$ = makeBoolAConst(true, @1);
   17493             :                 }
   17494             :             | FALSE_P
   17495             :                 {
   17496       36466 :                     $$ = makeBoolAConst(false, @1);
   17497             :                 }
   17498             :             | NULL_P
   17499             :                 {
   17500       68674 :                     $$ = makeNullAConst(@1);
   17501             :                 }
   17502             :         ;
   17503             : 
   17504      405798 : Iconst:     ICONST                                  { $$ = $1; };
   17505      780496 : Sconst:     SCONST                                  { $$ = $1; };
   17506             : 
   17507       18086 : SignedIconst: Iconst                                { $$ = $1; }
   17508           0 :             | '+' Iconst                            { $$ = + $2; }
   17509         306 :             | '-' Iconst                            { $$ = - $2; }
   17510             :         ;
   17511             : 
   17512             : /* Role specifications */
   17513             : RoleId:     RoleSpec
   17514             :                 {
   17515        1914 :                     RoleSpec   *spc = (RoleSpec *) $1;
   17516             : 
   17517        1914 :                     switch (spc->roletype)
   17518             :                     {
   17519        1904 :                         case ROLESPEC_CSTRING:
   17520        1904 :                             $$ = spc->rolename;
   17521        1904 :                             break;
   17522           4 :                         case ROLESPEC_PUBLIC:
   17523           4 :                             ereport(ERROR,
   17524             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17525             :                                      errmsg("role name \"%s\" is reserved",
   17526             :                                             "public"),
   17527             :                                      parser_errposition(@1)));
   17528             :                             break;
   17529           2 :                         case ROLESPEC_SESSION_USER:
   17530           2 :                             ereport(ERROR,
   17531             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17532             :                                      errmsg("%s cannot be used as a role name here",
   17533             :                                             "SESSION_USER"),
   17534             :                                      parser_errposition(@1)));
   17535             :                             break;
   17536           2 :                         case ROLESPEC_CURRENT_USER:
   17537           2 :                             ereport(ERROR,
   17538             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17539             :                                      errmsg("%s cannot be used as a role name here",
   17540             :                                             "CURRENT_USER"),
   17541             :                                      parser_errposition(@1)));
   17542             :                             break;
   17543           2 :                         case ROLESPEC_CURRENT_ROLE:
   17544           2 :                             ereport(ERROR,
   17545             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17546             :                                      errmsg("%s cannot be used as a role name here",
   17547             :                                             "CURRENT_ROLE"),
   17548             :                                      parser_errposition(@1)));
   17549             :                             break;
   17550             :                     }
   17551             :                 }
   17552             :             ;
   17553             : 
   17554             : RoleSpec:   NonReservedWord
   17555             :                 {
   17556             :                     /*
   17557             :                      * "public" and "none" are not keywords, but they must
   17558             :                      * be treated specially here.
   17559             :                      */
   17560             :                     RoleSpec   *n;
   17561             : 
   17562       34984 :                     if (strcmp($1, "public") == 0)
   17563             :                     {
   17564       17910 :                         n = (RoleSpec *) makeRoleSpec(ROLESPEC_PUBLIC, @1);
   17565       17910 :                         n->roletype = ROLESPEC_PUBLIC;
   17566             :                     }
   17567       17074 :                     else if (strcmp($1, "none") == 0)
   17568             :                     {
   17569          26 :                         ereport(ERROR,
   17570             :                                 (errcode(ERRCODE_RESERVED_NAME),
   17571             :                                  errmsg("role name \"%s\" is reserved",
   17572             :                                         "none"),
   17573             :                                  parser_errposition(@1)));
   17574             :                     }
   17575             :                     else
   17576             :                     {
   17577       17048 :                         n = makeRoleSpec(ROLESPEC_CSTRING, @1);
   17578       17048 :                         n->rolename = pstrdup($1);
   17579             :                     }
   17580       34958 :                     $$ = n;
   17581             :                 }
   17582             :             | CURRENT_ROLE
   17583             :                 {
   17584         130 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_ROLE, @1);
   17585             :                 }
   17586             :             | CURRENT_USER
   17587             :                 {
   17588         228 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
   17589             :                 }
   17590             :             | SESSION_USER
   17591             :                 {
   17592          36 :                     $$ = makeRoleSpec(ROLESPEC_SESSION_USER, @1);
   17593             :                 }
   17594             :         ;
   17595             : 
   17596             : role_list:  RoleSpec
   17597        3250 :                 { $$ = list_make1($1); }
   17598             :             | role_list ',' RoleSpec
   17599         270 :                 { $$ = lappend($1, $3); }
   17600             :         ;
   17601             : 
   17602             : 
   17603             : /*****************************************************************************
   17604             :  *
   17605             :  * PL/pgSQL extensions
   17606             :  *
   17607             :  * You'd think a PL/pgSQL "expression" should be just an a_expr, but
   17608             :  * historically it can include just about anything that can follow SELECT.
   17609             :  * Therefore the returned struct is a SelectStmt.
   17610             :  *****************************************************************************/
   17611             : 
   17612             : PLpgSQL_Expr: opt_distinct_clause opt_target_list
   17613             :             from_clause where_clause
   17614             :             group_clause having_clause window_clause
   17615             :             opt_sort_clause opt_select_limit opt_for_locking_clause
   17616             :                 {
   17617       40300 :                     SelectStmt *n = makeNode(SelectStmt);
   17618             : 
   17619       40300 :                     n->distinctClause = $1;
   17620       40300 :                     n->targetList = $2;
   17621       40300 :                     n->fromClause = $3;
   17622       40300 :                     n->whereClause = $4;
   17623       40300 :                     n->groupClause = ($5)->list;
   17624       40300 :                     n->groupDistinct = ($5)->distinct;
   17625       40300 :                     n->havingClause = $6;
   17626       40300 :                     n->windowClause = $7;
   17627       40300 :                     n->sortClause = $8;
   17628       40300 :                     if ($9)
   17629             :                     {
   17630           4 :                         n->limitOffset = $9->limitOffset;
   17631           4 :                         n->limitCount = $9->limitCount;
   17632           4 :                         if (!n->sortClause &&
   17633           4 :                             $9->limitOption == LIMIT_OPTION_WITH_TIES)
   17634           0 :                             ereport(ERROR,
   17635             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17636             :                                      errmsg("WITH TIES cannot be specified without ORDER BY clause"),
   17637             :                                      parser_errposition($9->optionLoc)));
   17638           4 :                         n->limitOption = $9->limitOption;
   17639             :                     }
   17640       40300 :                     n->lockingClause = $10;
   17641       40300 :                     $$ = (Node *) n;
   17642             :                 }
   17643             :         ;
   17644             : 
   17645             : /*
   17646             :  * PL/pgSQL Assignment statement: name opt_indirection := PLpgSQL_Expr
   17647             :  */
   17648             : 
   17649             : PLAssignStmt: plassign_target opt_indirection plassign_equals PLpgSQL_Expr
   17650             :                 {
   17651        7044 :                     PLAssignStmt *n = makeNode(PLAssignStmt);
   17652             : 
   17653        7044 :                     n->name = $1;
   17654        7044 :                     n->indirection = check_indirection($2, yyscanner);
   17655             :                     /* nnames will be filled by calling production */
   17656        7044 :                     n->val = (SelectStmt *) $4;
   17657        7044 :                     n->location = @1;
   17658        7044 :                     $$ = (Node *) n;
   17659             :                 }
   17660             :         ;
   17661             : 
   17662        7020 : plassign_target: ColId                          { $$ = $1; }
   17663          24 :             | PARAM                             { $$ = psprintf("$%d", $1); }
   17664             :         ;
   17665             : 
   17666             : plassign_equals: COLON_EQUALS
   17667             :             | '='
   17668             :         ;
   17669             : 
   17670             : 
   17671             : /*
   17672             :  * Name classification hierarchy.
   17673             :  *
   17674             :  * IDENT is the lexeme returned by the lexer for identifiers that match
   17675             :  * no known keyword.  In most cases, we can accept certain keywords as
   17676             :  * names, not only IDENTs.  We prefer to accept as many such keywords
   17677             :  * as possible to minimize the impact of "reserved words" on programmers.
   17678             :  * So, we divide names into several possible classes.  The classification
   17679             :  * is chosen in part to make keywords acceptable as names wherever possible.
   17680             :  */
   17681             : 
   17682             : /* Column identifier --- names that can be column, table, etc names.
   17683             :  */
   17684     3495538 : ColId:      IDENT                                   { $$ = $1; }
   17685       60132 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17686        6290 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17687             :         ;
   17688             : 
   17689             : /* Type/function identifier --- names that can be type or function names.
   17690             :  */
   17691      709870 : type_function_name: IDENT                           { $$ = $1; }
   17692       75430 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17693          66 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17694             :         ;
   17695             : 
   17696             : /* Any not-fully-reserved word --- these names can be, eg, role names.
   17697             :  */
   17698       84704 : NonReservedWord:    IDENT                           { $$ = $1; }
   17699       30376 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17700         178 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17701        5222 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17702             :         ;
   17703             : 
   17704             : /* Column label --- allowed labels in "AS" clauses.
   17705             :  * This presently includes *all* Postgres keywords.
   17706             :  */
   17707     1846718 : ColLabel:   IDENT                                   { $$ = $1; }
   17708       40454 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17709         284 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17710        1796 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17711        7514 :             | reserved_keyword                      { $$ = pstrdup($1); }
   17712             :         ;
   17713             : 
   17714             : /* Bare column label --- names that can be column labels without writing "AS".
   17715             :  * This classification is orthogonal to the other keyword categories.
   17716             :  */
   17717        3612 : BareColLabel:   IDENT                               { $$ = $1; }
   17718          14 :             | bare_label_keyword                    { $$ = pstrdup($1); }
   17719             :         ;
   17720             : 
   17721             : 
   17722             : /*
   17723             :  * Keyword category lists.  Generally, every keyword present in
   17724             :  * the Postgres grammar should appear in exactly one of these lists.
   17725             :  *
   17726             :  * Put a new keyword into the first list that it can go into without causing
   17727             :  * shift or reduce conflicts.  The earlier lists define "less reserved"
   17728             :  * categories of keywords.
   17729             :  *
   17730             :  * Make sure that each keyword's category in kwlist.h matches where
   17731             :  * it is listed here.  (Someday we may be able to generate these lists and
   17732             :  * kwlist.h's table from one source of truth.)
   17733             :  */
   17734             : 
   17735             : /* "Unreserved" keywords --- available for use as any kind of name.
   17736             :  */
   17737             : unreserved_keyword:
   17738             :               ABORT_P
   17739             :             | ABSENT
   17740             :             | ABSOLUTE_P
   17741             :             | ACCESS
   17742             :             | ACTION
   17743             :             | ADD_P
   17744             :             | ADMIN
   17745             :             | AFTER
   17746             :             | AGGREGATE
   17747             :             | ALSO
   17748             :             | ALTER
   17749             :             | ALWAYS
   17750             :             | ASENSITIVE
   17751             :             | ASSERTION
   17752             :             | ASSIGNMENT
   17753             :             | AT
   17754             :             | ATOMIC
   17755             :             | ATTACH
   17756             :             | ATTRIBUTE
   17757             :             | BACKWARD
   17758             :             | BEFORE
   17759             :             | BEGIN_P
   17760             :             | BREADTH
   17761             :             | BY
   17762             :             | CACHE
   17763             :             | CALL
   17764             :             | CALLED
   17765             :             | CASCADE
   17766             :             | CASCADED
   17767             :             | CATALOG_P
   17768             :             | CHAIN
   17769             :             | CHARACTERISTICS
   17770             :             | CHECKPOINT
   17771             :             | CLASS
   17772             :             | CLOSE
   17773             :             | CLUSTER
   17774             :             | COLUMNS
   17775             :             | COMMENT
   17776             :             | COMMENTS
   17777             :             | COMMIT
   17778             :             | COMMITTED
   17779             :             | COMPRESSION
   17780             :             | CONDITIONAL
   17781             :             | CONFIGURATION
   17782             :             | CONFLICT
   17783             :             | CONNECTION
   17784             :             | CONSTRAINTS
   17785             :             | CONTENT_P
   17786             :             | CONTINUE_P
   17787             :             | CONVERSION_P
   17788             :             | COPY
   17789             :             | COST
   17790             :             | CSV
   17791             :             | CUBE
   17792             :             | CURRENT_P
   17793             :             | CURSOR
   17794             :             | CYCLE
   17795             :             | DATA_P
   17796             :             | DATABASE
   17797             :             | DAY_P
   17798             :             | DEALLOCATE
   17799             :             | DECLARE
   17800             :             | DEFAULTS
   17801             :             | DEFERRED
   17802             :             | DEFINER
   17803             :             | DELETE_P
   17804             :             | DELIMITER
   17805             :             | DELIMITERS
   17806             :             | DEPENDS
   17807             :             | DEPTH
   17808             :             | DETACH
   17809             :             | DICTIONARY
   17810             :             | DISABLE_P
   17811             :             | DISCARD
   17812             :             | DOCUMENT_P
   17813             :             | DOMAIN_P
   17814             :             | DOUBLE_P
   17815             :             | DROP
   17816             :             | EACH
   17817             :             | EMPTY_P
   17818             :             | ENABLE_P
   17819             :             | ENCODING
   17820             :             | ENCRYPTED
   17821             :             | ENFORCED
   17822             :             | ENUM_P
   17823             :             | ERROR_P
   17824             :             | ESCAPE
   17825             :             | EVENT
   17826             :             | EXCLUDE
   17827             :             | EXCLUDING
   17828             :             | EXCLUSIVE
   17829             :             | EXECUTE
   17830             :             | EXPLAIN
   17831             :             | EXPRESSION
   17832             :             | EXTENSION
   17833             :             | EXTERNAL
   17834             :             | FAMILY
   17835             :             | FILTER
   17836             :             | FINALIZE
   17837             :             | FIRST_P
   17838             :             | FOLLOWING
   17839             :             | FORCE
   17840             :             | FORMAT
   17841             :             | FORWARD
   17842             :             | FUNCTION
   17843             :             | FUNCTIONS
   17844             :             | GENERATED
   17845             :             | GLOBAL
   17846             :             | GRANTED
   17847             :             | GROUPS
   17848             :             | HANDLER
   17849             :             | HEADER_P
   17850             :             | HOLD
   17851             :             | HOUR_P
   17852             :             | IDENTITY_P
   17853             :             | IF_P
   17854             :             | IMMEDIATE
   17855             :             | IMMUTABLE
   17856             :             | IMPLICIT_P
   17857             :             | IMPORT_P
   17858             :             | INCLUDE
   17859             :             | INCLUDING
   17860             :             | INCREMENT
   17861             :             | INDENT
   17862             :             | INDEX
   17863             :             | INDEXES
   17864             :             | INHERIT
   17865             :             | INHERITS
   17866             :             | INLINE_P
   17867             :             | INPUT_P
   17868             :             | INSENSITIVE
   17869             :             | INSERT
   17870             :             | INSTEAD
   17871             :             | INVOKER
   17872             :             | ISOLATION
   17873             :             | KEEP
   17874             :             | KEY
   17875             :             | KEYS
   17876             :             | LABEL
   17877             :             | LANGUAGE
   17878             :             | LARGE_P
   17879             :             | LAST_P
   17880             :             | LEAKPROOF
   17881             :             | LEVEL
   17882             :             | LISTEN
   17883             :             | LOAD
   17884             :             | LOCAL
   17885             :             | LOCATION
   17886             :             | LOCK_P
   17887             :             | LOCKED
   17888             :             | LOGGED
   17889             :             | MAPPING
   17890             :             | MATCH
   17891             :             | MATCHED
   17892             :             | MATERIALIZED
   17893             :             | MAXVALUE
   17894             :             | MERGE
   17895             :             | METHOD
   17896             :             | MINUTE_P
   17897             :             | MINVALUE
   17898             :             | MODE
   17899             :             | MONTH_P
   17900             :             | MOVE
   17901             :             | NAME_P
   17902             :             | NAMES
   17903             :             | NESTED
   17904             :             | NEW
   17905             :             | NEXT
   17906             :             | NFC
   17907             :             | NFD
   17908             :             | NFKC
   17909             :             | NFKD
   17910             :             | NO
   17911             :             | NORMALIZED
   17912             :             | NOTHING
   17913             :             | NOTIFY
   17914             :             | NOWAIT
   17915             :             | NULLS_P
   17916             :             | OBJECT_P
   17917             :             | OBJECTS_P
   17918             :             | OF
   17919             :             | OFF
   17920             :             | OIDS
   17921             :             | OLD
   17922             :             | OMIT
   17923             :             | OPERATOR
   17924             :             | OPTION
   17925             :             | OPTIONS
   17926             :             | ORDINALITY
   17927             :             | OTHERS
   17928             :             | OVER
   17929             :             | OVERRIDING
   17930             :             | OWNED
   17931             :             | OWNER
   17932             :             | PARALLEL
   17933             :             | PARAMETER
   17934             :             | PARSER
   17935             :             | PARTIAL
   17936             :             | PARTITION
   17937             :             | PASSING
   17938             :             | PASSWORD
   17939             :             | PATH
   17940             :             | PERIOD
   17941             :             | PLAN
   17942             :             | PLANS
   17943             :             | POLICY
   17944             :             | PRECEDING
   17945             :             | PREPARE
   17946             :             | PREPARED
   17947             :             | PRESERVE
   17948             :             | PRIOR
   17949             :             | PRIVILEGES
   17950             :             | PROCEDURAL
   17951             :             | PROCEDURE
   17952             :             | PROCEDURES
   17953             :             | PROGRAM
   17954             :             | PUBLICATION
   17955             :             | QUOTE
   17956             :             | QUOTES
   17957             :             | RANGE
   17958             :             | READ
   17959             :             | REASSIGN
   17960             :             | RECURSIVE
   17961             :             | REF_P
   17962             :             | REFERENCING
   17963             :             | REFRESH
   17964             :             | REINDEX
   17965             :             | RELATIVE_P
   17966             :             | RELEASE
   17967             :             | RENAME
   17968             :             | REPEATABLE
   17969             :             | REPLACE
   17970             :             | REPLICA
   17971             :             | RESET
   17972             :             | RESTART
   17973             :             | RESTRICT
   17974             :             | RETURN
   17975             :             | RETURNS
   17976             :             | REVOKE
   17977             :             | ROLE
   17978             :             | ROLLBACK
   17979             :             | ROLLUP
   17980             :             | ROUTINE
   17981             :             | ROUTINES
   17982             :             | ROWS
   17983             :             | RULE
   17984             :             | SAVEPOINT
   17985             :             | SCALAR
   17986             :             | SCHEMA
   17987             :             | SCHEMAS
   17988             :             | SCROLL
   17989             :             | SEARCH
   17990             :             | SECOND_P
   17991             :             | SECURITY
   17992             :             | SEQUENCE
   17993             :             | SEQUENCES
   17994             :             | SERIALIZABLE
   17995             :             | SERVER
   17996             :             | SESSION
   17997             :             | SET
   17998             :             | SETS
   17999             :             | SHARE
   18000             :             | SHOW
   18001             :             | SIMPLE
   18002             :             | SKIP
   18003             :             | SNAPSHOT
   18004             :             | SOURCE
   18005             :             | SQL_P
   18006             :             | STABLE
   18007             :             | STANDALONE_P
   18008             :             | START
   18009             :             | STATEMENT
   18010             :             | STATISTICS
   18011             :             | STDIN
   18012             :             | STDOUT
   18013             :             | STORAGE
   18014             :             | STORED
   18015             :             | STRICT_P
   18016             :             | STRING_P
   18017             :             | STRIP_P
   18018             :             | SUBSCRIPTION
   18019             :             | SUPPORT
   18020             :             | SYSID
   18021             :             | SYSTEM_P
   18022             :             | TABLES
   18023             :             | TABLESPACE
   18024             :             | TARGET
   18025             :             | TEMP
   18026             :             | TEMPLATE
   18027             :             | TEMPORARY
   18028             :             | TEXT_P
   18029             :             | TIES
   18030             :             | TRANSACTION
   18031             :             | TRANSFORM
   18032             :             | TRIGGER
   18033             :             | TRUNCATE
   18034             :             | TRUSTED
   18035             :             | TYPE_P
   18036             :             | TYPES_P
   18037             :             | UESCAPE
   18038             :             | UNBOUNDED
   18039             :             | UNCOMMITTED
   18040             :             | UNCONDITIONAL
   18041             :             | UNENCRYPTED
   18042             :             | UNKNOWN
   18043             :             | UNLISTEN
   18044             :             | UNLOGGED
   18045             :             | UNTIL
   18046             :             | UPDATE
   18047             :             | VACUUM
   18048             :             | VALID
   18049             :             | VALIDATE
   18050             :             | VALIDATOR
   18051             :             | VALUE_P
   18052             :             | VARYING
   18053             :             | VERSION_P
   18054             :             | VIEW
   18055             :             | VIEWS
   18056             :             | VIRTUAL
   18057             :             | VOLATILE
   18058             :             | WHITESPACE_P
   18059             :             | WITHIN
   18060             :             | WITHOUT
   18061             :             | WORK
   18062             :             | WRAPPER
   18063             :             | WRITE
   18064             :             | XML_P
   18065             :             | YEAR_P
   18066             :             | YES_P
   18067             :             | ZONE
   18068             :         ;
   18069             : 
   18070             : /* Column identifier --- keywords that can be column, table, etc names.
   18071             :  *
   18072             :  * Many of these keywords will in fact be recognized as type or function
   18073             :  * names too; but they have special productions for the purpose, and so
   18074             :  * can't be treated as "generic" type or function names.
   18075             :  *
   18076             :  * The type names appearing here are not usable as function names
   18077             :  * because they can be followed by '(' in typename productions, which
   18078             :  * looks too much like a function call for an LR(1) parser.
   18079             :  */
   18080             : col_name_keyword:
   18081             :               BETWEEN
   18082             :             | BIGINT
   18083             :             | BIT
   18084             :             | BOOLEAN_P
   18085             :             | CHAR_P
   18086             :             | CHARACTER
   18087             :             | COALESCE
   18088             :             | DEC
   18089             :             | DECIMAL_P
   18090             :             | EXISTS
   18091             :             | EXTRACT
   18092             :             | FLOAT_P
   18093             :             | GREATEST
   18094             :             | GROUPING
   18095             :             | INOUT
   18096             :             | INT_P
   18097             :             | INTEGER
   18098             :             | INTERVAL
   18099             :             | JSON
   18100             :             | JSON_ARRAY
   18101             :             | JSON_ARRAYAGG
   18102             :             | JSON_EXISTS
   18103             :             | JSON_OBJECT
   18104             :             | JSON_OBJECTAGG
   18105             :             | JSON_QUERY
   18106             :             | JSON_SCALAR
   18107             :             | JSON_SERIALIZE
   18108             :             | JSON_TABLE
   18109             :             | JSON_VALUE
   18110             :             | LEAST
   18111             :             | MERGE_ACTION
   18112             :             | NATIONAL
   18113             :             | NCHAR
   18114             :             | NONE
   18115             :             | NORMALIZE
   18116             :             | NULLIF
   18117             :             | NUMERIC
   18118             :             | OUT_P
   18119             :             | OVERLAY
   18120             :             | POSITION
   18121             :             | PRECISION
   18122             :             | REAL
   18123             :             | ROW
   18124             :             | SETOF
   18125             :             | SMALLINT
   18126             :             | SUBSTRING
   18127             :             | TIME
   18128             :             | TIMESTAMP
   18129             :             | TREAT
   18130             :             | TRIM
   18131             :             | VALUES
   18132             :             | VARCHAR
   18133             :             | XMLATTRIBUTES
   18134             :             | XMLCONCAT
   18135             :             | XMLELEMENT
   18136             :             | XMLEXISTS
   18137             :             | XMLFOREST
   18138             :             | XMLNAMESPACES
   18139             :             | XMLPARSE
   18140             :             | XMLPI
   18141             :             | XMLROOT
   18142             :             | XMLSERIALIZE
   18143             :             | XMLTABLE
   18144             :         ;
   18145             : 
   18146             : /* Type/function identifier --- keywords that can be type or function names.
   18147             :  *
   18148             :  * Most of these are keywords that are used as operators in expressions;
   18149             :  * in general such keywords can't be column names because they would be
   18150             :  * ambiguous with variables, but they are unambiguous as function identifiers.
   18151             :  *
   18152             :  * Do not include POSITION, SUBSTRING, etc here since they have explicit
   18153             :  * productions in a_expr to support the goofy SQL9x argument syntax.
   18154             :  * - thomas 2000-11-28
   18155             :  */
   18156             : type_func_name_keyword:
   18157             :               AUTHORIZATION
   18158             :             | BINARY
   18159             :             | COLLATION
   18160             :             | CONCURRENTLY
   18161             :             | CROSS
   18162             :             | CURRENT_SCHEMA
   18163             :             | FREEZE
   18164             :             | FULL
   18165             :             | ILIKE
   18166             :             | INNER_P
   18167             :             | IS
   18168             :             | ISNULL
   18169             :             | JOIN
   18170             :             | LEFT
   18171             :             | LIKE
   18172             :             | NATURAL
   18173             :             | NOTNULL
   18174             :             | OUTER_P
   18175             :             | OVERLAPS
   18176             :             | RIGHT
   18177             :             | SIMILAR
   18178             :             | TABLESAMPLE
   18179             :             | VERBOSE
   18180             :         ;
   18181             : 
   18182             : /* Reserved keyword --- these keywords are usable only as a ColLabel.
   18183             :  *
   18184             :  * Keywords appear here if they could not be distinguished from variable,
   18185             :  * type, or function names in some contexts.  Don't put things here unless
   18186             :  * forced to.
   18187             :  */
   18188             : reserved_keyword:
   18189             :               ALL
   18190             :             | ANALYSE
   18191             :             | ANALYZE
   18192             :             | AND
   18193             :             | ANY
   18194             :             | ARRAY
   18195             :             | AS
   18196             :             | ASC
   18197             :             | ASYMMETRIC
   18198             :             | BOTH
   18199             :             | CASE
   18200             :             | CAST
   18201             :             | CHECK
   18202             :             | COLLATE
   18203             :             | COLUMN
   18204             :             | CONSTRAINT
   18205             :             | CREATE
   18206             :             | CURRENT_CATALOG
   18207             :             | CURRENT_DATE
   18208             :             | CURRENT_ROLE
   18209             :             | CURRENT_TIME
   18210             :             | CURRENT_TIMESTAMP
   18211             :             | CURRENT_USER
   18212             :             | DEFAULT
   18213             :             | DEFERRABLE
   18214             :             | DESC
   18215             :             | DISTINCT
   18216             :             | DO
   18217             :             | ELSE
   18218             :             | END_P
   18219             :             | EXCEPT
   18220             :             | FALSE_P
   18221             :             | FETCH
   18222             :             | FOR
   18223             :             | FOREIGN
   18224             :             | FROM
   18225             :             | GRANT
   18226             :             | GROUP_P
   18227             :             | HAVING
   18228             :             | IN_P
   18229             :             | INITIALLY
   18230             :             | INTERSECT
   18231             :             | INTO
   18232             :             | LATERAL_P
   18233             :             | LEADING
   18234             :             | LIMIT
   18235             :             | LOCALTIME
   18236             :             | LOCALTIMESTAMP
   18237             :             | NOT
   18238             :             | NULL_P
   18239             :             | OFFSET
   18240             :             | ON
   18241             :             | ONLY
   18242             :             | OR
   18243             :             | ORDER
   18244             :             | PLACING
   18245             :             | PRIMARY
   18246             :             | REFERENCES
   18247             :             | RETURNING
   18248             :             | SELECT
   18249             :             | SESSION_USER
   18250             :             | SOME
   18251             :             | SYMMETRIC
   18252             :             | SYSTEM_USER
   18253             :             | TABLE
   18254             :             | THEN
   18255             :             | TO
   18256             :             | TRAILING
   18257             :             | TRUE_P
   18258             :             | UNION
   18259             :             | UNIQUE
   18260             :             | USER
   18261             :             | USING
   18262             :             | VARIADIC
   18263             :             | WHEN
   18264             :             | WHERE
   18265             :             | WINDOW
   18266             :             | WITH
   18267             :         ;
   18268             : 
   18269             : /*
   18270             :  * While all keywords can be used as column labels when preceded by AS,
   18271             :  * not all of them can be used as a "bare" column label without AS.
   18272             :  * Those that can be used as a bare label must be listed here,
   18273             :  * in addition to appearing in one of the category lists above.
   18274             :  *
   18275             :  * Always add a new keyword to this list if possible.  Mark it BARE_LABEL
   18276             :  * in kwlist.h if it is included here, or AS_LABEL if it is not.
   18277             :  */
   18278             : bare_label_keyword:
   18279             :               ABORT_P
   18280             :             | ABSENT
   18281             :             | ABSOLUTE_P
   18282             :             | ACCESS
   18283             :             | ACTION
   18284             :             | ADD_P
   18285             :             | ADMIN
   18286             :             | AFTER
   18287             :             | AGGREGATE
   18288             :             | ALL
   18289             :             | ALSO
   18290             :             | ALTER
   18291             :             | ALWAYS
   18292             :             | ANALYSE
   18293             :             | ANALYZE
   18294             :             | AND
   18295             :             | ANY
   18296             :             | ASC
   18297             :             | ASENSITIVE
   18298             :             | ASSERTION
   18299             :             | ASSIGNMENT
   18300             :             | ASYMMETRIC
   18301             :             | AT
   18302             :             | ATOMIC
   18303             :             | ATTACH
   18304             :             | ATTRIBUTE
   18305             :             | AUTHORIZATION
   18306             :             | BACKWARD
   18307             :             | BEFORE
   18308             :             | BEGIN_P
   18309             :             | BETWEEN
   18310             :             | BIGINT
   18311             :             | BINARY
   18312             :             | BIT
   18313             :             | BOOLEAN_P
   18314             :             | BOTH
   18315             :             | BREADTH
   18316             :             | BY
   18317             :             | CACHE
   18318             :             | CALL
   18319             :             | CALLED
   18320             :             | CASCADE
   18321             :             | CASCADED
   18322             :             | CASE
   18323             :             | CAST
   18324             :             | CATALOG_P
   18325             :             | CHAIN
   18326             :             | CHARACTERISTICS
   18327             :             | CHECK
   18328             :             | CHECKPOINT
   18329             :             | CLASS
   18330             :             | CLOSE
   18331             :             | CLUSTER
   18332             :             | COALESCE
   18333             :             | COLLATE
   18334             :             | COLLATION
   18335             :             | COLUMN
   18336             :             | COLUMNS
   18337             :             | COMMENT
   18338             :             | COMMENTS
   18339             :             | COMMIT
   18340             :             | COMMITTED
   18341             :             | COMPRESSION
   18342             :             | CONCURRENTLY
   18343             :             | CONDITIONAL
   18344             :             | CONFIGURATION
   18345             :             | CONFLICT
   18346             :             | CONNECTION
   18347             :             | CONSTRAINT
   18348             :             | CONSTRAINTS
   18349             :             | CONTENT_P
   18350             :             | CONTINUE_P
   18351             :             | CONVERSION_P
   18352             :             | COPY
   18353             :             | COST
   18354             :             | CROSS
   18355             :             | CSV
   18356             :             | CUBE
   18357             :             | CURRENT_P
   18358             :             | CURRENT_CATALOG
   18359             :             | CURRENT_DATE
   18360             :             | CURRENT_ROLE
   18361             :             | CURRENT_SCHEMA
   18362             :             | CURRENT_TIME
   18363             :             | CURRENT_TIMESTAMP
   18364             :             | CURRENT_USER
   18365             :             | CURSOR
   18366             :             | CYCLE
   18367             :             | DATA_P
   18368             :             | DATABASE
   18369             :             | DEALLOCATE
   18370             :             | DEC
   18371             :             | DECIMAL_P
   18372             :             | DECLARE
   18373             :             | DEFAULT
   18374             :             | DEFAULTS
   18375             :             | DEFERRABLE
   18376             :             | DEFERRED
   18377             :             | DEFINER
   18378             :             | DELETE_P
   18379             :             | DELIMITER
   18380             :             | DELIMITERS
   18381             :             | DEPENDS
   18382             :             | DEPTH
   18383             :             | DESC
   18384             :             | DETACH
   18385             :             | DICTIONARY
   18386             :             | DISABLE_P
   18387             :             | DISCARD
   18388             :             | DISTINCT
   18389             :             | DO
   18390             :             | DOCUMENT_P
   18391             :             | DOMAIN_P
   18392             :             | DOUBLE_P
   18393             :             | DROP
   18394             :             | EACH
   18395             :             | ELSE
   18396             :             | EMPTY_P
   18397             :             | ENABLE_P
   18398             :             | ENCODING
   18399             :             | ENCRYPTED
   18400             :             | END_P
   18401             :             | ENFORCED
   18402             :             | ENUM_P
   18403             :             | ERROR_P
   18404             :             | ESCAPE
   18405             :             | EVENT
   18406             :             | EXCLUDE
   18407             :             | EXCLUDING
   18408             :             | EXCLUSIVE
   18409             :             | EXECUTE
   18410             :             | EXISTS
   18411             :             | EXPLAIN
   18412             :             | EXPRESSION
   18413             :             | EXTENSION
   18414             :             | EXTERNAL
   18415             :             | EXTRACT
   18416             :             | FALSE_P
   18417             :             | FAMILY
   18418             :             | FINALIZE
   18419             :             | FIRST_P
   18420             :             | FLOAT_P
   18421             :             | FOLLOWING
   18422             :             | FORCE
   18423             :             | FOREIGN
   18424             :             | FORMAT
   18425             :             | FORWARD
   18426             :             | FREEZE
   18427             :             | FULL
   18428             :             | FUNCTION
   18429             :             | FUNCTIONS
   18430             :             | GENERATED
   18431             :             | GLOBAL
   18432             :             | GRANTED
   18433             :             | GREATEST
   18434             :             | GROUPING
   18435             :             | GROUPS
   18436             :             | HANDLER
   18437             :             | HEADER_P
   18438             :             | HOLD
   18439             :             | IDENTITY_P
   18440             :             | IF_P
   18441             :             | ILIKE
   18442             :             | IMMEDIATE
   18443             :             | IMMUTABLE
   18444             :             | IMPLICIT_P
   18445             :             | IMPORT_P
   18446             :             | IN_P
   18447             :             | INCLUDE
   18448             :             | INCLUDING
   18449             :             | INCREMENT
   18450             :             | INDENT
   18451             :             | INDEX
   18452             :             | INDEXES
   18453             :             | INHERIT
   18454             :             | INHERITS
   18455             :             | INITIALLY
   18456             :             | INLINE_P
   18457             :             | INNER_P
   18458             :             | INOUT
   18459             :             | INPUT_P
   18460             :             | INSENSITIVE
   18461             :             | INSERT
   18462             :             | INSTEAD
   18463             :             | INT_P
   18464             :             | INTEGER
   18465             :             | INTERVAL
   18466             :             | INVOKER
   18467             :             | IS
   18468             :             | ISOLATION
   18469             :             | JOIN
   18470             :             | JSON
   18471             :             | JSON_ARRAY
   18472             :             | JSON_ARRAYAGG
   18473             :             | JSON_EXISTS
   18474             :             | JSON_OBJECT
   18475             :             | JSON_OBJECTAGG
   18476             :             | JSON_QUERY
   18477             :             | JSON_SCALAR
   18478             :             | JSON_SERIALIZE
   18479             :             | JSON_TABLE
   18480             :             | JSON_VALUE
   18481             :             | KEEP
   18482             :             | KEY
   18483             :             | KEYS
   18484             :             | LABEL
   18485             :             | LANGUAGE
   18486             :             | LARGE_P
   18487             :             | LAST_P
   18488             :             | LATERAL_P
   18489             :             | LEADING
   18490             :             | LEAKPROOF
   18491             :             | LEAST
   18492             :             | LEFT
   18493             :             | LEVEL
   18494             :             | LIKE
   18495             :             | LISTEN
   18496             :             | LOAD
   18497             :             | LOCAL
   18498             :             | LOCALTIME
   18499             :             | LOCALTIMESTAMP
   18500             :             | LOCATION
   18501             :             | LOCK_P
   18502             :             | LOCKED
   18503             :             | LOGGED
   18504             :             | MAPPING
   18505             :             | MATCH
   18506             :             | MATCHED
   18507             :             | MATERIALIZED
   18508             :             | MAXVALUE
   18509             :             | MERGE
   18510             :             | MERGE_ACTION
   18511             :             | METHOD
   18512             :             | MINVALUE
   18513             :             | MODE
   18514             :             | MOVE
   18515             :             | NAME_P
   18516             :             | NAMES
   18517             :             | NATIONAL
   18518             :             | NATURAL
   18519             :             | NCHAR
   18520             :             | NESTED
   18521             :             | NEW
   18522             :             | NEXT
   18523             :             | NFC
   18524             :             | NFD
   18525             :             | NFKC
   18526             :             | NFKD
   18527             :             | NO
   18528             :             | NONE
   18529             :             | NORMALIZE
   18530             :             | NORMALIZED
   18531             :             | NOT
   18532             :             | NOTHING
   18533             :             | NOTIFY
   18534             :             | NOWAIT
   18535             :             | NULL_P
   18536             :             | NULLIF
   18537             :             | NULLS_P
   18538             :             | NUMERIC
   18539             :             | OBJECT_P
   18540             :             | OBJECTS_P
   18541             :             | OF
   18542             :             | OFF
   18543             :             | OIDS
   18544             :             | OLD
   18545             :             | OMIT
   18546             :             | ONLY
   18547             :             | OPERATOR
   18548             :             | OPTION
   18549             :             | OPTIONS
   18550             :             | OR
   18551             :             | ORDINALITY
   18552             :             | OTHERS
   18553             :             | OUT_P
   18554             :             | OUTER_P
   18555             :             | OVERLAY
   18556             :             | OVERRIDING
   18557             :             | OWNED
   18558             :             | OWNER
   18559             :             | PARALLEL
   18560             :             | PARAMETER
   18561             :             | PARSER
   18562             :             | PARTIAL
   18563             :             | PARTITION
   18564             :             | PASSING
   18565             :             | PASSWORD
   18566             :             | PATH
   18567             :             | PERIOD
   18568             :             | PLACING
   18569             :             | PLAN
   18570             :             | PLANS
   18571             :             | POLICY
   18572             :             | POSITION
   18573             :             | PRECEDING
   18574             :             | PREPARE
   18575             :             | PREPARED
   18576             :             | PRESERVE
   18577             :             | PRIMARY
   18578             :             | PRIOR
   18579             :             | PRIVILEGES
   18580             :             | PROCEDURAL
   18581             :             | PROCEDURE
   18582             :             | PROCEDURES
   18583             :             | PROGRAM
   18584             :             | PUBLICATION
   18585             :             | QUOTE
   18586             :             | QUOTES
   18587             :             | RANGE
   18588             :             | READ
   18589             :             | REAL
   18590             :             | REASSIGN
   18591             :             | RECURSIVE
   18592             :             | REF_P
   18593             :             | REFERENCES
   18594             :             | REFERENCING
   18595             :             | REFRESH
   18596             :             | REINDEX
   18597             :             | RELATIVE_P
   18598             :             | RELEASE
   18599             :             | RENAME
   18600             :             | REPEATABLE
   18601             :             | REPLACE
   18602             :             | REPLICA
   18603             :             | RESET
   18604             :             | RESTART
   18605             :             | RESTRICT
   18606             :             | RETURN
   18607             :             | RETURNS
   18608             :             | REVOKE
   18609             :             | RIGHT
   18610             :             | ROLE
   18611             :             | ROLLBACK
   18612             :             | ROLLUP
   18613             :             | ROUTINE
   18614             :             | ROUTINES
   18615             :             | ROW
   18616             :             | ROWS
   18617             :             | RULE
   18618             :             | SAVEPOINT
   18619             :             | SCALAR
   18620             :             | SCHEMA
   18621             :             | SCHEMAS
   18622             :             | SCROLL
   18623             :             | SEARCH
   18624             :             | SECURITY
   18625             :             | SELECT
   18626             :             | SEQUENCE
   18627             :             | SEQUENCES
   18628             :             | SERIALIZABLE
   18629             :             | SERVER
   18630             :             | SESSION
   18631             :             | SESSION_USER
   18632             :             | SET
   18633             :             | SETOF
   18634             :             | SETS
   18635             :             | SHARE
   18636             :             | SHOW
   18637             :             | SIMILAR
   18638             :             | SIMPLE
   18639             :             | SKIP
   18640             :             | SMALLINT
   18641             :             | SNAPSHOT
   18642             :             | SOME
   18643             :             | SOURCE
   18644             :             | SQL_P
   18645             :             | STABLE
   18646             :             | STANDALONE_P
   18647             :             | START
   18648             :             | STATEMENT
   18649             :             | STATISTICS
   18650             :             | STDIN
   18651             :             | STDOUT
   18652             :             | STORAGE
   18653             :             | STORED
   18654             :             | STRICT_P
   18655             :             | STRING_P
   18656             :             | STRIP_P
   18657             :             | SUBSCRIPTION
   18658             :             | SUBSTRING
   18659             :             | SUPPORT
   18660             :             | SYMMETRIC
   18661             :             | SYSID
   18662             :             | SYSTEM_P
   18663             :             | SYSTEM_USER
   18664             :             | TABLE
   18665             :             | TABLES
   18666             :             | TABLESAMPLE
   18667             :             | TABLESPACE
   18668             :             | TARGET
   18669             :             | TEMP
   18670             :             | TEMPLATE
   18671             :             | TEMPORARY
   18672             :             | TEXT_P
   18673             :             | THEN
   18674             :             | TIES
   18675             :             | TIME
   18676             :             | TIMESTAMP
   18677             :             | TRAILING
   18678             :             | TRANSACTION
   18679             :             | TRANSFORM
   18680             :             | TREAT
   18681             :             | TRIGGER
   18682             :             | TRIM
   18683             :             | TRUE_P
   18684             :             | TRUNCATE
   18685             :             | TRUSTED
   18686             :             | TYPE_P
   18687             :             | TYPES_P
   18688             :             | UESCAPE
   18689             :             | UNBOUNDED
   18690             :             | UNCOMMITTED
   18691             :             | UNCONDITIONAL
   18692             :             | UNENCRYPTED
   18693             :             | UNIQUE
   18694             :             | UNKNOWN
   18695             :             | UNLISTEN
   18696             :             | UNLOGGED
   18697             :             | UNTIL
   18698             :             | UPDATE
   18699             :             | USER
   18700             :             | USING
   18701             :             | VACUUM
   18702             :             | VALID
   18703             :             | VALIDATE
   18704             :             | VALIDATOR
   18705             :             | VALUE_P
   18706             :             | VALUES
   18707             :             | VARCHAR
   18708             :             | VARIADIC
   18709             :             | VERBOSE
   18710             :             | VERSION_P
   18711             :             | VIEW
   18712             :             | VIEWS
   18713             :             | VIRTUAL
   18714             :             | VOLATILE
   18715             :             | WHEN
   18716             :             | WHITESPACE_P
   18717             :             | WORK
   18718             :             | WRAPPER
   18719             :             | WRITE
   18720             :             | XML_P
   18721             :             | XMLATTRIBUTES
   18722             :             | XMLCONCAT
   18723             :             | XMLELEMENT
   18724             :             | XMLEXISTS
   18725             :             | XMLFOREST
   18726             :             | XMLNAMESPACES
   18727             :             | XMLPARSE
   18728             :             | XMLPI
   18729             :             | XMLROOT
   18730             :             | XMLSERIALIZE
   18731             :             | XMLTABLE
   18732             :             | YES_P
   18733             :             | ZONE
   18734             :         ;
   18735             : 
   18736             : %%
   18737             : 
   18738             : /*
   18739             :  * The signature of this function is required by bison.  However, we
   18740             :  * ignore the passed yylloc and instead use the last token position
   18741             :  * available from the scanner.
   18742             :  */
   18743             : static void
   18744         696 : base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
   18745             : {
   18746         696 :     parser_yyerror(msg);
   18747             : }
   18748             : 
   18749             : static RawStmt *
   18750      832804 : makeRawStmt(Node *stmt, int stmt_location)
   18751             : {
   18752      832804 :     RawStmt    *rs = makeNode(RawStmt);
   18753             : 
   18754      832804 :     rs->stmt = stmt;
   18755      832804 :     rs->stmt_location = stmt_location;
   18756      832804 :     rs->stmt_len = 0;            /* might get changed later */
   18757      832804 :     return rs;
   18758             : }
   18759             : 
   18760             : /* Adjust a RawStmt to reflect that it doesn't run to the end of the string */
   18761             : static void
   18762      587610 : updateRawStmtEnd(RawStmt *rs, int end_location)
   18763             : {
   18764             :     /*
   18765             :      * If we already set the length, don't change it.  This is for situations
   18766             :      * like "select foo ;; select bar" where the same statement will be last
   18767             :      * in the string for more than one semicolon.
   18768             :      */
   18769      587610 :     if (rs->stmt_len > 0)
   18770         552 :         return;
   18771             : 
   18772             :     /* OK, update length of RawStmt */
   18773      587058 :     rs->stmt_len = end_location - rs->stmt_location;
   18774             : }
   18775             : 
   18776             : static Node *
   18777     1873048 : makeColumnRef(char *colname, List *indirection,
   18778             :               int location, core_yyscan_t yyscanner)
   18779             : {
   18780             :     /*
   18781             :      * Generate a ColumnRef node, with an A_Indirection node added if there is
   18782             :      * any subscripting in the specified indirection list.  However, any field
   18783             :      * selection at the start of the indirection list must be transposed into
   18784             :      * the "fields" part of the ColumnRef node.
   18785             :      */
   18786     1873048 :     ColumnRef  *c = makeNode(ColumnRef);
   18787     1873048 :     int         nfields = 0;
   18788             :     ListCell   *l;
   18789             : 
   18790     1873048 :     c->location = location;
   18791     2958184 :     foreach(l, indirection)
   18792             :     {
   18793     1095284 :         if (IsA(lfirst(l), A_Indices))
   18794             :         {
   18795       10148 :             A_Indirection *i = makeNode(A_Indirection);
   18796             : 
   18797       10148 :             if (nfields == 0)
   18798             :             {
   18799             :                 /* easy case - all indirection goes to A_Indirection */
   18800        7422 :                 c->fields = list_make1(makeString(colname));
   18801        7422 :                 i->indirection = check_indirection(indirection, yyscanner);
   18802             :             }
   18803             :             else
   18804             :             {
   18805             :                 /* got to split the list in two */
   18806        2726 :                 i->indirection = check_indirection(list_copy_tail(indirection,
   18807             :                                                                   nfields),
   18808             :                                                    yyscanner);
   18809        2726 :                 indirection = list_truncate(indirection, nfields);
   18810        2726 :                 c->fields = lcons(makeString(colname), indirection);
   18811             :             }
   18812       10148 :             i->arg = (Node *) c;
   18813       10148 :             return (Node *) i;
   18814             :         }
   18815     1085136 :         else if (IsA(lfirst(l), A_Star))
   18816             :         {
   18817             :             /* We only allow '*' at the end of a ColumnRef */
   18818        5460 :             if (lnext(indirection, l) != NULL)
   18819           0 :                 parser_yyerror("improper use of \"*\"");
   18820             :         }
   18821     1085136 :         nfields++;
   18822             :     }
   18823             :     /* No subscripting, so all indirection gets added to field list */
   18824     1862900 :     c->fields = lcons(makeString(colname), indirection);
   18825     1862900 :     return (Node *) c;
   18826             : }
   18827             : 
   18828             : static Node *
   18829      321678 : makeTypeCast(Node *arg, TypeName *typename, int location)
   18830             : {
   18831      321678 :     TypeCast   *n = makeNode(TypeCast);
   18832             : 
   18833      321678 :     n->arg = arg;
   18834      321678 :     n->typeName = typename;
   18835      321678 :     n->location = location;
   18836      321678 :     return (Node *) n;
   18837             : }
   18838             : 
   18839             : static Node *
   18840       16272 : makeStringConstCast(char *str, int location, TypeName *typename)
   18841             : {
   18842       16272 :     Node       *s = makeStringConst(str, location);
   18843             : 
   18844       16272 :     return makeTypeCast(s, typename, -1);
   18845             : }
   18846             : 
   18847             : static Node *
   18848      389630 : makeIntConst(int val, int location)
   18849             : {
   18850      389630 :     A_Const    *n = makeNode(A_Const);
   18851             : 
   18852      389630 :     n->val.ival.type = T_Integer;
   18853      389630 :     n->val.ival.ival = val;
   18854      389630 :     n->location = location;
   18855             : 
   18856      389630 :     return (Node *) n;
   18857             : }
   18858             : 
   18859             : static Node *
   18860       11628 : makeFloatConst(char *str, int location)
   18861             : {
   18862       11628 :     A_Const    *n = makeNode(A_Const);
   18863             : 
   18864       11628 :     n->val.fval.type = T_Float;
   18865       11628 :     n->val.fval.fval = str;
   18866       11628 :     n->location = location;
   18867             : 
   18868       11628 :     return (Node *) n;
   18869             : }
   18870             : 
   18871             : static Node *
   18872       67928 : makeBoolAConst(bool state, int location)
   18873             : {
   18874       67928 :     A_Const    *n = makeNode(A_Const);
   18875             : 
   18876       67928 :     n->val.boolval.type = T_Boolean;
   18877       67928 :     n->val.boolval.boolval = state;
   18878       67928 :     n->location = location;
   18879             : 
   18880       67928 :     return (Node *) n;
   18881             : }
   18882             : 
   18883             : static Node *
   18884        4056 : makeBitStringConst(char *str, int location)
   18885             : {
   18886        4056 :     A_Const    *n = makeNode(A_Const);
   18887             : 
   18888        4056 :     n->val.bsval.type = T_BitString;
   18889        4056 :     n->val.bsval.bsval = str;
   18890        4056 :     n->location = location;
   18891             : 
   18892        4056 :     return (Node *) n;
   18893             : }
   18894             : 
   18895             : static Node *
   18896       68724 : makeNullAConst(int location)
   18897             : {
   18898       68724 :     A_Const    *n = makeNode(A_Const);
   18899             : 
   18900       68724 :     n->isnull = true;
   18901       68724 :     n->location = location;
   18902             : 
   18903       68724 :     return (Node *) n;
   18904             : }
   18905             : 
   18906             : static Node *
   18907        5696 : makeAConst(Node *v, int location)
   18908             : {
   18909             :     Node       *n;
   18910             : 
   18911        5696 :     switch (v->type)
   18912             :     {
   18913         218 :         case T_Float:
   18914         218 :             n = makeFloatConst(castNode(Float, v)->fval, location);
   18915         218 :             break;
   18916             : 
   18917        5478 :         case T_Integer:
   18918        5478 :             n = makeIntConst(castNode(Integer, v)->ival, location);
   18919        5478 :             break;
   18920             : 
   18921           0 :         default:
   18922             :             /* currently not used */
   18923             :             Assert(false);
   18924           0 :             n = NULL;
   18925             :     }
   18926             : 
   18927        5696 :     return n;
   18928             : }
   18929             : 
   18930             : /* makeRoleSpec
   18931             :  * Create a RoleSpec with the given type
   18932             :  */
   18933             : static RoleSpec *
   18934       35974 : makeRoleSpec(RoleSpecType type, int location)
   18935             : {
   18936       35974 :     RoleSpec   *spec = makeNode(RoleSpec);
   18937             : 
   18938       35974 :     spec->roletype = type;
   18939       35974 :     spec->location = location;
   18940             : 
   18941       35974 :     return spec;
   18942             : }
   18943             : 
   18944             : /* check_qualified_name --- check the result of qualified_name production
   18945             :  *
   18946             :  * It's easiest to let the grammar production for qualified_name allow
   18947             :  * subscripts and '*', which we then must reject here.
   18948             :  */
   18949             : static void
   18950      264078 : check_qualified_name(List *names, core_yyscan_t yyscanner)
   18951             : {
   18952             :     ListCell   *i;
   18953             : 
   18954      528156 :     foreach(i, names)
   18955             :     {
   18956      264078 :         if (!IsA(lfirst(i), String))
   18957           0 :             parser_yyerror("syntax error");
   18958             :     }
   18959      264078 : }
   18960             : 
   18961             : /* check_func_name --- check the result of func_name production
   18962             :  *
   18963             :  * It's easiest to let the grammar production for func_name allow subscripts
   18964             :  * and '*', which we then must reject here.
   18965             :  */
   18966             : static List *
   18967      130908 : check_func_name(List *names, core_yyscan_t yyscanner)
   18968             : {
   18969             :     ListCell   *i;
   18970             : 
   18971      392724 :     foreach(i, names)
   18972             :     {
   18973      261816 :         if (!IsA(lfirst(i), String))
   18974           0 :             parser_yyerror("syntax error");
   18975             :     }
   18976      130908 :     return names;
   18977             : }
   18978             : 
   18979             : /* check_indirection --- check the result of indirection production
   18980             :  *
   18981             :  * We only allow '*' at the end of the list, but it's hard to enforce that
   18982             :  * in the grammar, so do it here.
   18983             :  */
   18984             : static List *
   18985       82988 : check_indirection(List *indirection, core_yyscan_t yyscanner)
   18986             : {
   18987             :     ListCell   *l;
   18988             : 
   18989      111080 :     foreach(l, indirection)
   18990             :     {
   18991       28092 :         if (IsA(lfirst(l), A_Star))
   18992             :         {
   18993        1470 :             if (lnext(indirection, l) != NULL)
   18994           0 :                 parser_yyerror("improper use of \"*\"");
   18995             :         }
   18996             :     }
   18997       82988 :     return indirection;
   18998             : }
   18999             : 
   19000             : /* extractArgTypes()
   19001             :  * Given a list of FunctionParameter nodes, extract a list of just the
   19002             :  * argument types (TypeNames) for input parameters only.  This is what
   19003             :  * is needed to look up an existing function, which is what is wanted by
   19004             :  * the productions that use this call.
   19005             :  */
   19006             : static List *
   19007       16846 : extractArgTypes(List *parameters)
   19008             : {
   19009       16846 :     List       *result = NIL;
   19010             :     ListCell   *i;
   19011             : 
   19012       36090 :     foreach(i, parameters)
   19013             :     {
   19014       19244 :         FunctionParameter *p = (FunctionParameter *) lfirst(i);
   19015             : 
   19016       19244 :         if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
   19017       19022 :             result = lappend(result, p->argType);
   19018             :     }
   19019       16846 :     return result;
   19020             : }
   19021             : 
   19022             : /* extractAggrArgTypes()
   19023             :  * As above, but work from the output of the aggr_args production.
   19024             :  */
   19025             : static List *
   19026         460 : extractAggrArgTypes(List *aggrargs)
   19027             : {
   19028             :     Assert(list_length(aggrargs) == 2);
   19029         460 :     return extractArgTypes((List *) linitial(aggrargs));
   19030             : }
   19031             : 
   19032             : /* makeOrderedSetArgs()
   19033             :  * Build the result of the aggr_args production (which see the comments for).
   19034             :  * This handles only the case where both given lists are nonempty, so that
   19035             :  * we have to deal with multiple VARIADIC arguments.
   19036             :  */
   19037             : static List *
   19038          40 : makeOrderedSetArgs(List *directargs, List *orderedargs,
   19039             :                    core_yyscan_t yyscanner)
   19040             : {
   19041          40 :     FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
   19042             :     Integer    *ndirectargs;
   19043             : 
   19044             :     /* No restriction unless last direct arg is VARIADIC */
   19045          40 :     if (lastd->mode == FUNC_PARAM_VARIADIC)
   19046             :     {
   19047          20 :         FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
   19048             : 
   19049             :         /*
   19050             :          * We ignore the names, though the aggr_arg production allows them; it
   19051             :          * doesn't allow default values, so those need not be checked.
   19052             :          */
   19053          20 :         if (list_length(orderedargs) != 1 ||
   19054          20 :             firsto->mode != FUNC_PARAM_VARIADIC ||
   19055          20 :             !equal(lastd->argType, firsto->argType))
   19056           0 :             ereport(ERROR,
   19057             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19058             :                      errmsg("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
   19059             :                      parser_errposition(firsto->location)));
   19060             : 
   19061             :         /* OK, drop the duplicate VARIADIC argument from the internal form */
   19062          20 :         orderedargs = NIL;
   19063             :     }
   19064             : 
   19065             :     /* don't merge into the next line, as list_concat changes directargs */
   19066          40 :     ndirectargs = makeInteger(list_length(directargs));
   19067             : 
   19068          40 :     return list_make2(list_concat(directargs, orderedargs),
   19069             :                       ndirectargs);
   19070             : }
   19071             : 
   19072             : /* insertSelectOptions()
   19073             :  * Insert ORDER BY, etc into an already-constructed SelectStmt.
   19074             :  *
   19075             :  * This routine is just to avoid duplicating code in SelectStmt productions.
   19076             :  */
   19077             : static void
   19078       85340 : insertSelectOptions(SelectStmt *stmt,
   19079             :                     List *sortClause, List *lockingClause,
   19080             :                     SelectLimit *limitClause,
   19081             :                     WithClause *withClause,
   19082             :                     core_yyscan_t yyscanner)
   19083             : {
   19084             :     Assert(IsA(stmt, SelectStmt));
   19085             : 
   19086             :     /*
   19087             :      * Tests here are to reject constructs like
   19088             :      *  (SELECT foo ORDER BY bar) ORDER BY baz
   19089             :      */
   19090       85340 :     if (sortClause)
   19091             :     {
   19092       75936 :         if (stmt->sortClause)
   19093           0 :             ereport(ERROR,
   19094             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19095             :                      errmsg("multiple ORDER BY clauses not allowed"),
   19096             :                      parser_errposition(exprLocation((Node *) sortClause))));
   19097       75936 :         stmt->sortClause = sortClause;
   19098             :     }
   19099             :     /* We can handle multiple locking clauses, though */
   19100       85340 :     stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
   19101       85340 :     if (limitClause && limitClause->limitOffset)
   19102             :     {
   19103         848 :         if (stmt->limitOffset)
   19104           0 :             ereport(ERROR,
   19105             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19106             :                      errmsg("multiple OFFSET clauses not allowed"),
   19107             :                      parser_errposition(limitClause->offsetLoc)));
   19108         848 :         stmt->limitOffset = limitClause->limitOffset;
   19109             :     }
   19110       85340 :     if (limitClause && limitClause->limitCount)
   19111             :     {
   19112        4714 :         if (stmt->limitCount)
   19113           0 :             ereport(ERROR,
   19114             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19115             :                      errmsg("multiple LIMIT clauses not allowed"),
   19116             :                      parser_errposition(limitClause->countLoc)));
   19117        4714 :         stmt->limitCount = limitClause->limitCount;
   19118             :     }
   19119       85340 :     if (limitClause)
   19120             :     {
   19121             :         /* If there was a conflict, we must have detected it above */
   19122             :         Assert(!stmt->limitOption);
   19123        5164 :         if (!stmt->sortClause && limitClause->limitOption == LIMIT_OPTION_WITH_TIES)
   19124           6 :             ereport(ERROR,
   19125             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19126             :                      errmsg("WITH TIES cannot be specified without ORDER BY clause"),
   19127             :                      parser_errposition(limitClause->optionLoc)));
   19128        5158 :         if (limitClause->limitOption == LIMIT_OPTION_WITH_TIES && stmt->lockingClause)
   19129             :         {
   19130             :             ListCell   *lc;
   19131             : 
   19132           6 :             foreach(lc, stmt->lockingClause)
   19133             :             {
   19134           6 :                 LockingClause *lock = lfirst_node(LockingClause, lc);
   19135             : 
   19136           6 :                 if (lock->waitPolicy == LockWaitSkip)
   19137           6 :                     ereport(ERROR,
   19138             :                             (errcode(ERRCODE_SYNTAX_ERROR),
   19139             :                              errmsg("%s and %s options cannot be used together",
   19140             :                                     "SKIP LOCKED", "WITH TIES"),
   19141             :                              parser_errposition(limitClause->optionLoc)));
   19142             :             }
   19143             :         }
   19144        5152 :         stmt->limitOption = limitClause->limitOption;
   19145             :     }
   19146       85328 :     if (withClause)
   19147             :     {
   19148        2888 :         if (stmt->withClause)
   19149           0 :             ereport(ERROR,
   19150             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19151             :                      errmsg("multiple WITH clauses not allowed"),
   19152             :                      parser_errposition(exprLocation((Node *) withClause))));
   19153        2888 :         stmt->withClause = withClause;
   19154             :     }
   19155       85328 : }
   19156             : 
   19157             : static Node *
   19158       19484 : makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
   19159             : {
   19160       19484 :     SelectStmt *n = makeNode(SelectStmt);
   19161             : 
   19162       19484 :     n->op = op;
   19163       19484 :     n->all = all;
   19164       19484 :     n->larg = (SelectStmt *) larg;
   19165       19484 :     n->rarg = (SelectStmt *) rarg;
   19166       19484 :     return (Node *) n;
   19167             : }
   19168             : 
   19169             : /* SystemFuncName()
   19170             :  * Build a properly-qualified reference to a built-in function.
   19171             :  */
   19172             : List *
   19173       19512 : SystemFuncName(char *name)
   19174             : {
   19175       19512 :     return list_make2(makeString("pg_catalog"), makeString(name));
   19176             : }
   19177             : 
   19178             : /* SystemTypeName()
   19179             :  * Build a properly-qualified reference to a built-in type.
   19180             :  *
   19181             :  * typmod is defaulted, but may be changed afterwards by caller.
   19182             :  * Likewise for the location.
   19183             :  */
   19184             : TypeName *
   19185      125252 : SystemTypeName(char *name)
   19186             : {
   19187      125252 :     return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
   19188             :                                                makeString(name)));
   19189             : }
   19190             : 
   19191             : /* doNegate()
   19192             :  * Handle negation of a numeric constant.
   19193             :  *
   19194             :  * Formerly, we did this here because the optimizer couldn't cope with
   19195             :  * indexquals that looked like "var = -4" --- it wants "var = const"
   19196             :  * and a unary minus operator applied to a constant didn't qualify.
   19197             :  * As of Postgres 7.0, that problem doesn't exist anymore because there
   19198             :  * is a constant-subexpression simplifier in the optimizer.  However,
   19199             :  * there's still a good reason for doing this here, which is that we can
   19200             :  * postpone committing to a particular internal representation for simple
   19201             :  * negative constants.  It's better to leave "-123.456" in string form
   19202             :  * until we know what the desired type is.
   19203             :  */
   19204             : static Node *
   19205        9282 : doNegate(Node *n, int location)
   19206             : {
   19207        9282 :     if (IsA(n, A_Const))
   19208             :     {
   19209        8278 :         A_Const    *con = (A_Const *) n;
   19210             : 
   19211             :         /* report the constant's location as that of the '-' sign */
   19212        8278 :         con->location = location;
   19213             : 
   19214        8278 :         if (IsA(&con->val, Integer))
   19215             :         {
   19216        7320 :             con->val.ival.ival = -con->val.ival.ival;
   19217        7320 :             return n;
   19218             :         }
   19219         958 :         if (IsA(&con->val, Float))
   19220             :         {
   19221         958 :             doNegateFloat(&con->val.fval);
   19222         958 :             return n;
   19223             :         }
   19224             :     }
   19225             : 
   19226        1004 :     return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
   19227             : }
   19228             : 
   19229             : static void
   19230         980 : doNegateFloat(Float *v)
   19231             : {
   19232         980 :     char       *oldval = v->fval;
   19233             : 
   19234         980 :     if (*oldval == '+')
   19235           0 :         oldval++;
   19236         980 :     if (*oldval == '-')
   19237           0 :         v->fval = oldval + 1;    /* just strip the '-' */
   19238             :     else
   19239         980 :         v->fval = psprintf("-%s", oldval);
   19240         980 : }
   19241             : 
   19242             : static Node *
   19243      239094 : makeAndExpr(Node *lexpr, Node *rexpr, int location)
   19244             : {
   19245             :     /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
   19246      239094 :     if (IsA(lexpr, BoolExpr))
   19247             :     {
   19248      113018 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   19249             : 
   19250      113018 :         if (blexpr->boolop == AND_EXPR)
   19251             :         {
   19252      110288 :             blexpr->args = lappend(blexpr->args, rexpr);
   19253      110288 :             return (Node *) blexpr;
   19254             :         }
   19255             :     }
   19256      128806 :     return (Node *) makeBoolExpr(AND_EXPR, list_make2(lexpr, rexpr), location);
   19257             : }
   19258             : 
   19259             : static Node *
   19260       16834 : makeOrExpr(Node *lexpr, Node *rexpr, int location)
   19261             : {
   19262             :     /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
   19263       16834 :     if (IsA(lexpr, BoolExpr))
   19264             :     {
   19265        5924 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   19266             : 
   19267        5924 :         if (blexpr->boolop == OR_EXPR)
   19268             :         {
   19269        4336 :             blexpr->args = lappend(blexpr->args, rexpr);
   19270        4336 :             return (Node *) blexpr;
   19271             :         }
   19272             :     }
   19273       12498 :     return (Node *) makeBoolExpr(OR_EXPR, list_make2(lexpr, rexpr), location);
   19274             : }
   19275             : 
   19276             : static Node *
   19277       17050 : makeNotExpr(Node *expr, int location)
   19278             : {
   19279       17050 :     return (Node *) makeBoolExpr(NOT_EXPR, list_make1(expr), location);
   19280             : }
   19281             : 
   19282             : static Node *
   19283        8230 : makeAArrayExpr(List *elements, int location, int location_end)
   19284             : {
   19285        8230 :     A_ArrayExpr *n = makeNode(A_ArrayExpr);
   19286             : 
   19287        8230 :     n->elements = elements;
   19288        8230 :     n->location = location;
   19289        8230 :     n->list_start = location;
   19290        8230 :     n->list_end = location_end;
   19291        8230 :     return (Node *) n;
   19292             : }
   19293             : 
   19294             : static Node *
   19295        2780 : makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod, int location)
   19296             : {
   19297        2780 :     SQLValueFunction *svf = makeNode(SQLValueFunction);
   19298             : 
   19299        2780 :     svf->op = op;
   19300             :     /* svf->type will be filled during parse analysis */
   19301        2780 :     svf->typmod = typmod;
   19302        2780 :     svf->location = location;
   19303        2780 :     return (Node *) svf;
   19304             : }
   19305             : 
   19306             : static Node *
   19307         610 : makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
   19308             :             int location)
   19309             : {
   19310         610 :     XmlExpr    *x = makeNode(XmlExpr);
   19311             : 
   19312         610 :     x->op = op;
   19313         610 :     x->name = name;
   19314             : 
   19315             :     /*
   19316             :      * named_args is a list of ResTarget; it'll be split apart into separate
   19317             :      * expression and name lists in transformXmlExpr().
   19318             :      */
   19319         610 :     x->named_args = named_args;
   19320         610 :     x->arg_names = NIL;
   19321         610 :     x->args = args;
   19322             :     /* xmloption, if relevant, must be filled in by caller */
   19323             :     /* type and typmod will be filled in during parse analysis */
   19324         610 :     x->type = InvalidOid;        /* marks the node as not analyzed */
   19325         610 :     x->location = location;
   19326         610 :     return (Node *) x;
   19327             : }
   19328             : 
   19329             : /*
   19330             :  * Merge the input and output parameters of a table function.
   19331             :  */
   19332             : static List *
   19333         202 : mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner)
   19334             : {
   19335             :     ListCell   *lc;
   19336             : 
   19337             :     /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
   19338         412 :     foreach(lc, func_args)
   19339             :     {
   19340         210 :         FunctionParameter *p = (FunctionParameter *) lfirst(lc);
   19341             : 
   19342         210 :         if (p->mode != FUNC_PARAM_DEFAULT &&
   19343           0 :             p->mode != FUNC_PARAM_IN &&
   19344           0 :             p->mode != FUNC_PARAM_VARIADIC)
   19345           0 :             ereport(ERROR,
   19346             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19347             :                      errmsg("OUT and INOUT arguments aren't allowed in TABLE functions"),
   19348             :                      parser_errposition(p->location)));
   19349             :     }
   19350             : 
   19351         202 :     return list_concat(func_args, columns);
   19352             : }
   19353             : 
   19354             : /*
   19355             :  * Determine return type of a TABLE function.  A single result column
   19356             :  * returns setof that column's type; otherwise return setof record.
   19357             :  */
   19358             : static TypeName *
   19359         202 : TableFuncTypeName(List *columns)
   19360             : {
   19361             :     TypeName   *result;
   19362             : 
   19363         202 :     if (list_length(columns) == 1)
   19364             :     {
   19365          70 :         FunctionParameter *p = (FunctionParameter *) linitial(columns);
   19366             : 
   19367          70 :         result = copyObject(p->argType);
   19368             :     }
   19369             :     else
   19370         132 :         result = SystemTypeName("record");
   19371             : 
   19372         202 :     result->setof = true;
   19373             : 
   19374         202 :     return result;
   19375             : }
   19376             : 
   19377             : /*
   19378             :  * Convert a list of (dotted) names to a RangeVar (like
   19379             :  * makeRangeVarFromNameList, but with position support).  The
   19380             :  * "AnyName" refers to the any_name production in the grammar.
   19381             :  */
   19382             : static RangeVar *
   19383        4768 : makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
   19384             : {
   19385        4768 :     RangeVar   *r = makeNode(RangeVar);
   19386             : 
   19387        4768 :     switch (list_length(names))
   19388             :     {
   19389        4646 :         case 1:
   19390        4646 :             r->catalogname = NULL;
   19391        4646 :             r->schemaname = NULL;
   19392        4646 :             r->relname = strVal(linitial(names));
   19393        4646 :             break;
   19394         122 :         case 2:
   19395         122 :             r->catalogname = NULL;
   19396         122 :             r->schemaname = strVal(linitial(names));
   19397         122 :             r->relname = strVal(lsecond(names));
   19398         122 :             break;
   19399           0 :         case 3:
   19400           0 :             r->catalogname = strVal(linitial(names));
   19401           0 :             r->schemaname = strVal(lsecond(names));
   19402           0 :             r->relname = strVal(lthird(names));
   19403           0 :             break;
   19404           0 :         default:
   19405           0 :             ereport(ERROR,
   19406             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19407             :                      errmsg("improper qualified name (too many dotted names): %s",
   19408             :                             NameListToString(names)),
   19409             :                      parser_errposition(position)));
   19410             :             break;
   19411             :     }
   19412             : 
   19413        4768 :     r->relpersistence = RELPERSISTENCE_PERMANENT;
   19414        4768 :     r->location = position;
   19415             : 
   19416        4768 :     return r;
   19417             : }
   19418             : 
   19419             : /*
   19420             :  * Convert a relation_name with name and namelist to a RangeVar using
   19421             :  * makeRangeVar.
   19422             :  */
   19423             : static RangeVar *
   19424      264078 : makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
   19425             :                               core_yyscan_t yyscanner)
   19426             : {
   19427             :     RangeVar   *r;
   19428             : 
   19429      264078 :     check_qualified_name(namelist, yyscanner);
   19430      264078 :     r = makeRangeVar(NULL, NULL, location);
   19431             : 
   19432      264078 :     switch (list_length(namelist))
   19433             :     {
   19434      264078 :         case 1:
   19435      264078 :             r->catalogname = NULL;
   19436      264078 :             r->schemaname = name;
   19437      264078 :             r->relname = strVal(linitial(namelist));
   19438      264078 :             break;
   19439           0 :         case 2:
   19440           0 :             r->catalogname = name;
   19441           0 :             r->schemaname = strVal(linitial(namelist));
   19442           0 :             r->relname = strVal(lsecond(namelist));
   19443           0 :             break;
   19444           0 :         default:
   19445           0 :             ereport(ERROR,
   19446             :                     errcode(ERRCODE_SYNTAX_ERROR),
   19447             :                     errmsg("improper qualified name (too many dotted names): %s",
   19448             :                            NameListToString(lcons(makeString(name), namelist))),
   19449             :                     parser_errposition(location));
   19450             :             break;
   19451             :     }
   19452             : 
   19453      264078 :     return r;
   19454             : }
   19455             : 
   19456             : /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
   19457             : static void
   19458       74582 : SplitColQualList(List *qualList,
   19459             :                  List **constraintList, CollateClause **collClause,
   19460             :                  core_yyscan_t yyscanner)
   19461             : {
   19462             :     ListCell   *cell;
   19463             : 
   19464       74582 :     *collClause = NULL;
   19465       95060 :     foreach(cell, qualList)
   19466             :     {
   19467       20478 :         Node       *n = (Node *) lfirst(cell);
   19468             : 
   19469       20478 :         if (IsA(n, Constraint))
   19470             :         {
   19471             :             /* keep it in list */
   19472       19710 :             continue;
   19473             :         }
   19474         768 :         if (IsA(n, CollateClause))
   19475             :         {
   19476         768 :             CollateClause *c = (CollateClause *) n;
   19477             : 
   19478         768 :             if (*collClause)
   19479           0 :                 ereport(ERROR,
   19480             :                         (errcode(ERRCODE_SYNTAX_ERROR),
   19481             :                          errmsg("multiple COLLATE clauses not allowed"),
   19482             :                          parser_errposition(c->location)));
   19483         768 :             *collClause = c;
   19484             :         }
   19485             :         else
   19486           0 :             elog(ERROR, "unexpected node type %d", (int) n->type);
   19487             :         /* remove non-Constraint nodes from qualList */
   19488         768 :         qualList = foreach_delete_current(qualList, cell);
   19489             :     }
   19490       74582 :     *constraintList = qualList;
   19491       74582 : }
   19492             : 
   19493             : /*
   19494             :  * Process result of ConstraintAttributeSpec, and set appropriate bool flags
   19495             :  * in the output command node.  Pass NULL for any flags the particular
   19496             :  * command doesn't support.
   19497             :  */
   19498             : static void
   19499       18410 : processCASbits(int cas_bits, int location, const char *constrType,
   19500             :                bool *deferrable, bool *initdeferred, bool *is_enforced,
   19501             :                bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner)
   19502             : {
   19503             :     /* defaults */
   19504       18410 :     if (deferrable)
   19505       16258 :         *deferrable = false;
   19506       18410 :     if (initdeferred)
   19507       16258 :         *initdeferred = false;
   19508       18410 :     if (not_valid)
   19509        3968 :         *not_valid = false;
   19510       18410 :     if (is_enforced)
   19511        3480 :         *is_enforced = true;
   19512             : 
   19513       18410 :     if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
   19514             :     {
   19515         242 :         if (deferrable)
   19516         242 :             *deferrable = true;
   19517             :         else
   19518           0 :             ereport(ERROR,
   19519             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19520             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19521             :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   19522             :                             constrType),
   19523             :                      parser_errposition(location)));
   19524             :     }
   19525             : 
   19526       18410 :     if (cas_bits & CAS_INITIALLY_DEFERRED)
   19527             :     {
   19528         152 :         if (initdeferred)
   19529         152 :             *initdeferred = true;
   19530             :         else
   19531           0 :             ereport(ERROR,
   19532             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19533             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19534             :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   19535             :                             constrType),
   19536             :                      parser_errposition(location)));
   19537             :     }
   19538             : 
   19539       18410 :     if (cas_bits & CAS_NOT_VALID)
   19540             :     {
   19541         722 :         if (not_valid)
   19542         722 :             *not_valid = true;
   19543             :         else
   19544           0 :             ereport(ERROR,
   19545             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19546             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19547             :                      errmsg("%s constraints cannot be marked NOT VALID",
   19548             :                             constrType),
   19549             :                      parser_errposition(location)));
   19550             :     }
   19551             : 
   19552       18410 :     if (cas_bits & CAS_NO_INHERIT)
   19553             :     {
   19554         248 :         if (no_inherit)
   19555         248 :             *no_inherit = true;
   19556             :         else
   19557           0 :             ereport(ERROR,
   19558             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19559             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19560             :                      errmsg("%s constraints cannot be marked NO INHERIT",
   19561             :                             constrType),
   19562             :                      parser_errposition(location)));
   19563             :     }
   19564             : 
   19565       18410 :     if (cas_bits & CAS_NOT_ENFORCED)
   19566             :     {
   19567         162 :         if (is_enforced)
   19568         156 :             *is_enforced = false;
   19569             :         else
   19570           6 :             ereport(ERROR,
   19571             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19572             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19573             :                      errmsg("%s constraints cannot be marked NOT ENFORCED",
   19574             :                             constrType),
   19575             :                      parser_errposition(location)));
   19576             : 
   19577             :         /*
   19578             :          * NB: The validated status is irrelevant when the constraint is set to
   19579             :          * NOT ENFORCED, but for consistency, it should be set accordingly.
   19580             :          * This ensures that if the constraint is later changed to ENFORCED, it
   19581             :          * will automatically be in the correct NOT VALIDATED state.
   19582             :          */
   19583         156 :         if (not_valid)
   19584         120 :             *not_valid = true;
   19585             :     }
   19586             : 
   19587       18404 :     if (cas_bits & CAS_ENFORCED)
   19588             :     {
   19589         102 :         if (is_enforced)
   19590          96 :             *is_enforced = true;
   19591             :         else
   19592           6 :             ereport(ERROR,
   19593             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19594             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19595             :                      errmsg("%s constraints cannot be marked ENFORCED",
   19596             :                             constrType),
   19597             :                      parser_errposition(location)));
   19598             :     }
   19599       18398 : }
   19600             : 
   19601             : /*
   19602             :  * Parse a user-supplied partition strategy string into parse node
   19603             :  * PartitionStrategy representation, or die trying.
   19604             :  */
   19605             : static PartitionStrategy
   19606        5152 : parsePartitionStrategy(char *strategy, int location, core_yyscan_t yyscanner)
   19607             : {
   19608        5152 :     if (pg_strcasecmp(strategy, "list") == 0)
   19609        2600 :         return PARTITION_STRATEGY_LIST;
   19610        2552 :     else if (pg_strcasecmp(strategy, "range") == 0)
   19611        2286 :         return PARTITION_STRATEGY_RANGE;
   19612         266 :     else if (pg_strcasecmp(strategy, "hash") == 0)
   19613         260 :         return PARTITION_STRATEGY_HASH;
   19614             : 
   19615           6 :     ereport(ERROR,
   19616             :             (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   19617             :              errmsg("unrecognized partitioning strategy \"%s\"", strategy),
   19618             :              parser_errposition(location)));
   19619             :     return PARTITION_STRATEGY_LIST; /* keep compiler quiet */
   19620             : 
   19621             : }
   19622             : 
   19623             : /*
   19624             :  * Process pubobjspec_list to check for errors in any of the objects and
   19625             :  * convert PUBLICATIONOBJ_CONTINUATION into appropriate PublicationObjSpecType.
   19626             :  */
   19627             : static void
   19628        1590 : preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
   19629             : {
   19630             :     ListCell   *cell;
   19631             :     PublicationObjSpec *pubobj;
   19632        1590 :     PublicationObjSpecType prevobjtype = PUBLICATIONOBJ_CONTINUATION;
   19633             : 
   19634        1590 :     if (!pubobjspec_list)
   19635           0 :         return;
   19636             : 
   19637        1590 :     pubobj = (PublicationObjSpec *) linitial(pubobjspec_list);
   19638        1590 :     if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   19639          12 :         ereport(ERROR,
   19640             :                 errcode(ERRCODE_SYNTAX_ERROR),
   19641             :                 errmsg("invalid publication object list"),
   19642             :                 errdetail("One of TABLE or TABLES IN SCHEMA must be specified before a standalone table or schema name."),
   19643             :                 parser_errposition(pubobj->location));
   19644             : 
   19645        3356 :     foreach(cell, pubobjspec_list)
   19646             :     {
   19647        1802 :         pubobj = (PublicationObjSpec *) lfirst(cell);
   19648             : 
   19649        1802 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   19650         174 :             pubobj->pubobjtype = prevobjtype;
   19651             : 
   19652        1802 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE)
   19653             :         {
   19654             :             /* relation name or pubtable must be set for this type of object */
   19655        1398 :             if (!pubobj->name && !pubobj->pubtable)
   19656           6 :                 ereport(ERROR,
   19657             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19658             :                         errmsg("invalid table name"),
   19659             :                         parser_errposition(pubobj->location));
   19660             : 
   19661        1392 :             if (pubobj->name)
   19662             :             {
   19663             :                 /* convert it to PublicationTable */
   19664          58 :                 PublicationTable *pubtable = makeNode(PublicationTable);
   19665             : 
   19666          58 :                 pubtable->relation =
   19667          58 :                     makeRangeVar(NULL, pubobj->name, pubobj->location);
   19668          58 :                 pubobj->pubtable = pubtable;
   19669          58 :                 pubobj->name = NULL;
   19670             :             }
   19671             :         }
   19672         404 :         else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
   19673          24 :                  pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA)
   19674             :         {
   19675             :             /* WHERE clause is not allowed on a schema object */
   19676         404 :             if (pubobj->pubtable && pubobj->pubtable->whereClause)
   19677           6 :                 ereport(ERROR,
   19678             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19679             :                         errmsg("WHERE clause not allowed for schema"),
   19680             :                         parser_errposition(pubobj->location));
   19681             : 
   19682             :             /* Column list is not allowed on a schema object */
   19683         398 :             if (pubobj->pubtable && pubobj->pubtable->columns)
   19684           6 :                 ereport(ERROR,
   19685             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19686             :                         errmsg("column specification not allowed for schema"),
   19687             :                         parser_errposition(pubobj->location));
   19688             : 
   19689             :             /*
   19690             :              * We can distinguish between the different type of schema objects
   19691             :              * based on whether name and pubtable is set.
   19692             :              */
   19693         392 :             if (pubobj->name)
   19694         362 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   19695          30 :             else if (!pubobj->name && !pubobj->pubtable)
   19696          24 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   19697             :             else
   19698           6 :                 ereport(ERROR,
   19699             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19700             :                         errmsg("invalid schema name"),
   19701             :                         parser_errposition(pubobj->location));
   19702             :         }
   19703             : 
   19704        1778 :         prevobjtype = pubobj->pubobjtype;
   19705             :     }
   19706             : }
   19707             : 
   19708             : /*----------
   19709             :  * Recursive view transformation
   19710             :  *
   19711             :  * Convert
   19712             :  *
   19713             :  *     CREATE RECURSIVE VIEW relname (aliases) AS query
   19714             :  *
   19715             :  * to
   19716             :  *
   19717             :  *     CREATE VIEW relname (aliases) AS
   19718             :  *         WITH RECURSIVE relname (aliases) AS (query)
   19719             :  *         SELECT aliases FROM relname
   19720             :  *
   19721             :  * Actually, just the WITH ... part, which is then inserted into the original
   19722             :  * view definition as the query.
   19723             :  * ----------
   19724             :  */
   19725             : static Node *
   19726          14 : makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
   19727             : {
   19728          14 :     SelectStmt *s = makeNode(SelectStmt);
   19729          14 :     WithClause *w = makeNode(WithClause);
   19730          14 :     CommonTableExpr *cte = makeNode(CommonTableExpr);
   19731          14 :     List       *tl = NIL;
   19732             :     ListCell   *lc;
   19733             : 
   19734             :     /* create common table expression */
   19735          14 :     cte->ctename = relname;
   19736          14 :     cte->aliascolnames = aliases;
   19737          14 :     cte->ctematerialized = CTEMaterializeDefault;
   19738          14 :     cte->ctequery = query;
   19739          14 :     cte->location = -1;
   19740             : 
   19741             :     /* create WITH clause and attach CTE */
   19742          14 :     w->recursive = true;
   19743          14 :     w->ctes = list_make1(cte);
   19744          14 :     w->location = -1;
   19745             : 
   19746             :     /*
   19747             :      * create target list for the new SELECT from the alias list of the
   19748             :      * recursive view specification
   19749             :      */
   19750          28 :     foreach(lc, aliases)
   19751             :     {
   19752          14 :         ResTarget  *rt = makeNode(ResTarget);
   19753             : 
   19754          14 :         rt->name = NULL;
   19755          14 :         rt->indirection = NIL;
   19756          14 :         rt->val = makeColumnRef(strVal(lfirst(lc)), NIL, -1, 0);
   19757          14 :         rt->location = -1;
   19758             : 
   19759          14 :         tl = lappend(tl, rt);
   19760             :     }
   19761             : 
   19762             :     /*
   19763             :      * create new SELECT combining WITH clause, target list, and fake FROM
   19764             :      * clause
   19765             :      */
   19766          14 :     s->withClause = w;
   19767          14 :     s->targetList = tl;
   19768          14 :     s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));
   19769             : 
   19770          14 :     return (Node *) s;
   19771             : }
   19772             : 
   19773             : /* parser_init()
   19774             :  * Initialize to parse one query string
   19775             :  */
   19776             : void
   19777      789468 : parser_init(base_yy_extra_type *yyext)
   19778             : {
   19779      789468 :     yyext->parsetree = NIL;      /* in case grammar forgets to set it */
   19780      789468 : }

Generated by: LCOV version 1.16