LCOV - code coverage report
Current view: top level - src/backend/parser - gram.y (source / functions) Hit Total Coverage
Test: PostgreSQL 18devel Lines: 6749 7465 90.4 %
Date: 2025-01-18 04:15:08 Functions: 42 42 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : %{
       2             : 
       3             : /*#define YYDEBUG 1*/
       4             : /*-------------------------------------------------------------------------
       5             :  *
       6             :  * gram.y
       7             :  *    POSTGRESQL BISON rules/actions
       8             :  *
       9             :  * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
      10             :  * Portions Copyright (c) 1994, Regents of the University of California
      11             :  *
      12             :  *
      13             :  * IDENTIFICATION
      14             :  *    src/backend/parser/gram.y
      15             :  *
      16             :  * HISTORY
      17             :  *    AUTHOR            DATE            MAJOR EVENT
      18             :  *    Andrew Yu         Sept, 1994      POSTQUEL to SQL conversion
      19             :  *    Andrew Yu         Oct, 1994       lispy code conversion
      20             :  *
      21             :  * NOTES
      22             :  *    CAPITALS are used to represent terminal symbols.
      23             :  *    non-capitals are used to represent non-terminals.
      24             :  *
      25             :  *    In general, nothing in this file should initiate database accesses
      26             :  *    nor depend on changeable state (such as SET variables).  If you do
      27             :  *    database accesses, your code will fail when we have aborted the
      28             :  *    current transaction and are just parsing commands to find the next
      29             :  *    ROLLBACK or COMMIT.  If you make use of SET variables, then you
      30             :  *    will do the wrong thing in multi-query strings like this:
      31             :  *          SET constraint_exclusion TO off; SELECT * FROM foo;
      32             :  *    because the entire string is parsed by gram.y before the SET gets
      33             :  *    executed.  Anything that depends on the database or changeable state
      34             :  *    should be handled during parse analysis so that it happens at the
      35             :  *    right time not the wrong time.
      36             :  *
      37             :  * WARNINGS
      38             :  *    If you use a list, make sure the datum is a node so that the printing
      39             :  *    routines work.
      40             :  *
      41             :  *    Sometimes we assign constants to makeStrings. Make sure we don't free
      42             :  *    those.
      43             :  *
      44             :  *-------------------------------------------------------------------------
      45             :  */
      46             : #include "postgres.h"
      47             : 
      48             : #include <ctype.h>
      49             : #include <limits.h>
      50             : 
      51             : #include "catalog/index.h"
      52             : #include "catalog/namespace.h"
      53             : #include "catalog/pg_am.h"
      54             : #include "catalog/pg_trigger.h"
      55             : #include "commands/defrem.h"
      56             : #include "commands/trigger.h"
      57             : #include "gramparse.h"
      58             : #include "nodes/makefuncs.h"
      59             : #include "nodes/nodeFuncs.h"
      60             : #include "parser/parser.h"
      61             : #include "utils/datetime.h"
      62             : #include "utils/xml.h"
      63             : 
      64             : 
      65             : /*
      66             :  * Location tracking support.  Unlike bison's default, we only want
      67             :  * to track the start position not the end position of each nonterminal.
      68             :  * Nonterminals that reduce to empty receive position "-1".  Since a
      69             :  * production's leading RHS nonterminal(s) may have reduced to empty,
      70             :  * we have to scan to find the first one that's not -1.
      71             :  */
      72             : #define YYLLOC_DEFAULT(Current, Rhs, N) \
      73             :     do { \
      74             :         (Current) = (-1); \
      75             :         for (int _i = 1; _i <= (N); _i++) \
      76             :         { \
      77             :             if ((Rhs)[_i] >= 0) \
      78             :             { \
      79             :                 (Current) = (Rhs)[_i]; \
      80             :                 break; \
      81             :             } \
      82             :         } \
      83             :     } while (0)
      84             : 
      85             : /*
      86             :  * Bison doesn't allocate anything that needs to live across parser calls,
      87             :  * so we can easily have it use palloc instead of malloc.  This prevents
      88             :  * memory leaks if we error out during parsing.
      89             :  */
      90             : #define YYMALLOC palloc
      91             : #define YYFREE   pfree
      92             : 
      93             : /* Private struct for the result of privilege_target production */
      94             : typedef struct PrivTarget
      95             : {
      96             :     GrantTargetType targtype;
      97             :     ObjectType  objtype;
      98             :     List       *objs;
      99             : } PrivTarget;
     100             : 
     101             : /* Private struct for the result of import_qualification production */
     102             : typedef struct ImportQual
     103             : {
     104             :     ImportForeignSchemaType type;
     105             :     List       *table_names;
     106             : } ImportQual;
     107             : 
     108             : /* Private struct for the result of select_limit & limit_clause productions */
     109             : typedef struct SelectLimit
     110             : {
     111             :     Node       *limitOffset;
     112             :     Node       *limitCount;
     113             :     LimitOption limitOption;    /* indicates presence of WITH TIES */
     114             :     ParseLoc    offsetLoc;      /* location of OFFSET token, if present */
     115             :     ParseLoc    countLoc;       /* location of LIMIT/FETCH token, if present */
     116             :     ParseLoc    optionLoc;      /* location of WITH TIES, if present */
     117             : } SelectLimit;
     118             : 
     119             : /* Private struct for the result of group_clause production */
     120             : typedef struct GroupClause
     121             : {
     122             :     bool        distinct;
     123             :     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 void updatePreparableStmtEnd(Node *n, int end_location);
     158             : static Node *makeColumnRef(char *colname, List *indirection,
     159             :                            int location, core_yyscan_t yyscanner);
     160             : static Node *makeTypeCast(Node *arg, TypeName *typename, int location);
     161             : static Node *makeStringConstCast(char *str, int location, TypeName *typename);
     162             : static Node *makeIntConst(int val, int location);
     163             : static Node *makeFloatConst(char *str, int location);
     164             : static Node *makeBoolAConst(bool state, int location);
     165             : static Node *makeBitStringConst(char *str, int location);
     166             : static Node *makeNullAConst(int location);
     167             : static Node *makeAConst(Node *v, int location);
     168             : static RoleSpec *makeRoleSpec(RoleSpecType type, int location);
     169             : static void check_qualified_name(List *names, core_yyscan_t yyscanner);
     170             : static List *check_func_name(List *names, core_yyscan_t yyscanner);
     171             : static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
     172             : static List *extractArgTypes(List *parameters);
     173             : static List *extractAggrArgTypes(List *aggrargs);
     174             : static List *makeOrderedSetArgs(List *directargs, List *orderedargs,
     175             :                                 core_yyscan_t yyscanner);
     176             : static void insertSelectOptions(SelectStmt *stmt,
     177             :                                 List *sortClause, List *lockingClause,
     178             :                                 SelectLimit *limitClause,
     179             :                                 WithClause *withClause,
     180             :                                 core_yyscan_t yyscanner);
     181             : static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg, int location);
     182             : static Node *doNegate(Node *n, int location);
     183             : static void doNegateFloat(Float *v);
     184             : static Node *makeAndExpr(Node *lexpr, Node *rexpr, int location);
     185             : static Node *makeOrExpr(Node *lexpr, Node *rexpr, int location);
     186             : static Node *makeNotExpr(Node *expr, int location);
     187             : static Node *makeAArrayExpr(List *elements, int location);
     188             : static Node *makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod,
     189             :                                   int location);
     190             : static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
     191             :                          List *args, int location);
     192             : static List *mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner);
     193             : static TypeName *TableFuncTypeName(List *columns);
     194             : static RangeVar *makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner);
     195             : static RangeVar *makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
     196             :                                                core_yyscan_t yyscanner);
     197             : static void SplitColQualList(List *qualList,
     198             :                              List **constraintList, CollateClause **collClause,
     199             :                              core_yyscan_t yyscanner);
     200             : static void processCASbits(int cas_bits, int location, const char *constrType,
     201             :                bool *deferrable, bool *initdeferred, bool *is_enforced,
     202             :                bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner);
     203             : static PartitionStrategy parsePartitionStrategy(char *strategy, int location,
     204             :                                                 core_yyscan_t yyscanner);
     205             : static void preprocess_pubobj_list(List *pubobjspec_list,
     206             :                                    core_yyscan_t yyscanner);
     207             : static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
     208             : 
     209             : %}
     210             : 
     211             : %pure-parser
     212             : %expect 0
     213             : %name-prefix="base_yy"
     214             : %locations
     215             : 
     216             : %parse-param {core_yyscan_t yyscanner}
     217             : %lex-param   {core_yyscan_t yyscanner}
     218             : 
     219             : %union
     220             : {
     221             :     core_YYSTYPE core_yystype;
     222             :     /* these fields must match core_YYSTYPE: */
     223             :     int         ival;
     224             :     char       *str;
     225             :     const char *keyword;
     226             : 
     227             :     char        chr;
     228             :     bool        boolean;
     229             :     JoinType    jtype;
     230             :     DropBehavior dbehavior;
     231             :     OnCommitAction oncommit;
     232             :     List       *list;
     233             :     Node       *node;
     234             :     ObjectType  objtype;
     235             :     TypeName   *typnam;
     236             :     FunctionParameter *fun_param;
     237             :     FunctionParameterMode fun_param_mode;
     238             :     ObjectWithArgs *objwithargs;
     239             :     DefElem    *defelt;
     240             :     SortBy     *sortby;
     241             :     WindowDef  *windef;
     242             :     JoinExpr   *jexpr;
     243             :     IndexElem  *ielem;
     244             :     StatsElem  *selem;
     245             :     Alias      *alias;
     246             :     RangeVar   *range;
     247             :     IntoClause *into;
     248             :     WithClause *with;
     249             :     InferClause *infer;
     250             :     OnConflictClause *onconflict;
     251             :     A_Indices  *aind;
     252             :     ResTarget  *target;
     253             :     struct PrivTarget *privtarget;
     254             :     AccessPriv *accesspriv;
     255             :     struct ImportQual *importqual;
     256             :     InsertStmt *istmt;
     257             :     VariableSetStmt *vsetstmt;
     258             :     PartitionElem *partelem;
     259             :     PartitionSpec *partspec;
     260             :     PartitionBoundSpec *partboundspec;
     261             :     RoleSpec   *rolespec;
     262             :     PublicationObjSpec *publicationobjectspec;
     263             :     struct SelectLimit *selectlimit;
     264             :     SetQuantifier setquantifier;
     265             :     struct GroupClause *groupclause;
     266             :     MergeMatchKind mergematch;
     267             :     MergeWhenClause *mergewhen;
     268             :     struct KeyActions *keyactions;
     269             :     struct KeyAction *keyaction;
     270             :     ReturningClause *retclause;
     271             :     ReturningOptionKind retoptionkind;
     272             : }
     273             : 
     274             : %type <node>  stmt toplevel_stmt schema_stmt routine_body_stmt
     275             :         AlterEventTrigStmt AlterCollationStmt
     276             :         AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt
     277             :         AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
     278             :         AlterObjectDependsStmt AlterObjectSchemaStmt AlterOwnerStmt
     279             :         AlterOperatorStmt AlterTypeStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
     280             :         AlterTblSpcStmt AlterExtensionStmt AlterExtensionContentsStmt
     281             :         AlterCompositeTypeStmt AlterUserMappingStmt
     282             :         AlterRoleStmt AlterRoleSetStmt AlterPolicyStmt AlterStatsStmt
     283             :         AlterDefaultPrivilegesStmt DefACLAction
     284             :         AnalyzeStmt CallStmt ClosePortalStmt ClusterStmt CommentStmt
     285             :         ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
     286             :         CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt
     287             :         CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
     288             :         CreateSchemaStmt CreateSeqStmt CreateStmt CreateStatsStmt CreateTableSpaceStmt
     289             :         CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt
     290             :         CreateAssertionStmt CreateTransformStmt CreateTrigStmt CreateEventTrigStmt
     291             :         CreateUserStmt CreateUserMappingStmt CreateRoleStmt CreatePolicyStmt
     292             :         CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
     293             :         DropOpClassStmt DropOpFamilyStmt DropStmt
     294             :         DropCastStmt DropRoleStmt
     295             :         DropdbStmt DropTableSpaceStmt
     296             :         DropTransformStmt
     297             :         DropUserMappingStmt ExplainStmt FetchStmt
     298             :         GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
     299             :         ListenStmt LoadStmt LockStmt MergeStmt NotifyStmt ExplainableStmt PreparableStmt
     300             :         CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
     301             :         RemoveFuncStmt RemoveOperStmt RenameStmt ReturnStmt RevokeStmt RevokeRoleStmt
     302             :         RuleActionStmt RuleActionStmtOrEmpty RuleStmt
     303             :         SecLabelStmt SelectStmt TransactionStmt TransactionStmtLegacy TruncateStmt
     304             :         UnlistenStmt UpdateStmt VacuumStmt
     305             :         VariableResetStmt VariableSetStmt VariableShowStmt
     306             :         ViewStmt CheckPointStmt CreateConversionStmt
     307             :         DeallocateStmt PrepareStmt ExecuteStmt
     308             :         DropOwnedStmt ReassignOwnedStmt
     309             :         AlterTSConfigurationStmt AlterTSDictionaryStmt
     310             :         CreateMatViewStmt RefreshMatViewStmt CreateAmStmt
     311             :         CreatePublicationStmt AlterPublicationStmt
     312             :         CreateSubscriptionStmt AlterSubscriptionStmt DropSubscriptionStmt
     313             : 
     314             : %type <node>  select_no_parens select_with_parens select_clause
     315             :                 simple_select values_clause
     316             :                 PLpgSQL_Expr PLAssignStmt
     317             : 
     318             : %type <str>           opt_single_name
     319             : %type <list>      opt_qualified_name
     320             : %type <boolean>       opt_concurrently
     321             : %type <dbehavior> opt_drop_behavior
     322             : 
     323             : %type <node>  alter_column_default opclass_item opclass_drop alter_using
     324             : %type <ival>  add_drop opt_asc_desc opt_nulls_order
     325             : 
     326             : %type <node>  alter_table_cmd alter_type_cmd opt_collate_clause
     327             :        replica_identity partition_cmd index_partition_cmd
     328             : %type <list>  alter_table_cmds alter_type_cmds
     329             : %type <list>    alter_identity_column_option_list
     330             : %type <defelt>  alter_identity_column_option
     331             : %type <node>  set_statistics_value
     332             : %type <str>       set_access_method_name
     333             : 
     334             : %type <list>  createdb_opt_list createdb_opt_items copy_opt_list
     335             :                 transaction_mode_list
     336             :                 create_extension_opt_list alter_extension_opt_list
     337             : %type <defelt>    createdb_opt_item copy_opt_item
     338             :                 transaction_mode_item
     339             :                 create_extension_opt_item alter_extension_opt_item
     340             : 
     341             : %type <ival>  opt_lock lock_type cast_context
     342             : %type <str>       utility_option_name
     343             : %type <defelt>    utility_option_elem
     344             : %type <list>  utility_option_list
     345             : %type <node>  utility_option_arg
     346             : %type <defelt>    drop_option
     347             : %type <boolean>   opt_or_replace opt_no
     348             :                 opt_grant_grant_option
     349             :                 opt_nowait opt_if_exists opt_with_data
     350             :                 opt_transaction_chain
     351             : %type <list>  grant_role_opt_list
     352             : %type <defelt>    grant_role_opt
     353             : %type <node>  grant_role_opt_value
     354             : %type <ival>  opt_nowait_or_skip
     355             : 
     356             : %type <list>  OptRoleList AlterOptRoleList
     357             : %type <defelt>    CreateOptRoleElem AlterOptRoleElem
     358             : 
     359             : %type <str>       opt_type
     360             : %type <str>       foreign_server_version opt_foreign_server_version
     361             : %type <str>       opt_in_database
     362             : 
     363             : %type <str>       parameter_name
     364             : %type <list>  OptSchemaEltList parameter_name_list
     365             : 
     366             : %type <chr>       am_type
     367             : 
     368             : %type <boolean> TriggerForSpec TriggerForType
     369             : %type <ival>  TriggerActionTime
     370             : %type <list>  TriggerEvents TriggerOneEvent
     371             : %type <node>  TriggerFuncArg
     372             : %type <node>  TriggerWhen
     373             : %type <str>       TransitionRelName
     374             : %type <boolean>   TransitionRowOrTable TransitionOldOrNew
     375             : %type <node>  TriggerTransition
     376             : 
     377             : %type <list>  event_trigger_when_list event_trigger_value_list
     378             : %type <defelt>    event_trigger_when_item
     379             : %type <chr>       enable_trigger
     380             : 
     381             : %type <str>       copy_file_name
     382             :                 access_method_clause attr_name
     383             :                 table_access_method_clause name cursor_name file_name
     384             :                 cluster_index_specification
     385             : 
     386             : %type <list>  func_name handler_name qual_Op qual_all_Op subquery_Op
     387             :                 opt_inline_handler opt_validator validator_clause
     388             :                 opt_collate
     389             : 
     390             : %type <range> qualified_name insert_target OptConstrFromTable
     391             : 
     392             : %type <str>       all_Op MathOp
     393             : 
     394             : %type <str>       row_security_cmd RowSecurityDefaultForCmd
     395             : %type <boolean> RowSecurityDefaultPermissive
     396             : %type <node>  RowSecurityOptionalWithCheck RowSecurityOptionalExpr
     397             : %type <list>  RowSecurityDefaultToRole RowSecurityOptionalToRole
     398             : 
     399             : %type <str>       iso_level opt_encoding
     400             : %type <rolespec> grantee
     401             : %type <list>  grantee_list
     402             : %type <accesspriv> privilege
     403             : %type <list>  privileges privilege_list
     404             : %type <privtarget> privilege_target
     405             : %type <objwithargs> function_with_argtypes aggregate_with_argtypes operator_with_argtypes
     406             : %type <list>  function_with_argtypes_list aggregate_with_argtypes_list operator_with_argtypes_list
     407             : %type <ival>  defacl_privilege_target
     408             : %type <defelt>    DefACLOption
     409             : %type <list>  DefACLOptionList
     410             : %type <ival>  import_qualification_type
     411             : %type <importqual> import_qualification
     412             : %type <node>  vacuum_relation
     413             : %type <selectlimit> opt_select_limit select_limit limit_clause
     414             : 
     415             : %type <list>  parse_toplevel stmtmulti routine_body_stmt_list
     416             :                 OptTableElementList TableElementList OptInherit definition
     417             :                 OptTypedTableElementList TypedTableElementList
     418             :                 reloptions opt_reloptions
     419             :                 OptWith opt_definition func_args func_args_list
     420             :                 func_args_with_defaults func_args_with_defaults_list
     421             :                 aggr_args aggr_args_list
     422             :                 func_as createfunc_opt_list opt_createfunc_opt_list alterfunc_opt_list
     423             :                 old_aggr_definition old_aggr_list
     424             :                 oper_argtypes RuleActionList RuleActionMulti
     425             :                 opt_column_list columnList opt_name_list
     426             :                 sort_clause opt_sort_clause sortby_list index_params
     427             :                 stats_params
     428             :                 opt_include opt_c_include index_including_params
     429             :                 name_list role_list from_clause from_list opt_array_bounds
     430             :                 qualified_name_list any_name any_name_list type_name_list
     431             :                 any_operator expr_list attrs
     432             :                 distinct_clause opt_distinct_clause
     433             :                 target_list opt_target_list insert_column_list set_target_list
     434             :                 merge_values_clause
     435             :                 set_clause_list set_clause
     436             :                 def_list operator_def_list indirection opt_indirection
     437             :                 reloption_list TriggerFuncArgs opclass_item_list opclass_drop_list
     438             :                 opclass_purpose opt_opfamily transaction_mode_list_or_empty
     439             :                 OptTableFuncElementList TableFuncElementList opt_type_modifiers
     440             :                 prep_type_clause
     441             :                 execute_param_clause using_clause
     442             :                 returning_with_clause returning_options
     443             :                 opt_enum_val_list enum_val_list table_func_column_list
     444             :                 create_generic_options alter_generic_options
     445             :                 relation_expr_list dostmt_opt_list
     446             :                 transform_element_list transform_type_list
     447             :                 TriggerTransitions TriggerReferencing
     448             :                 vacuum_relation_list opt_vacuum_relation_list
     449             :                 drop_option_list pub_obj_list
     450             : 
     451             : %type <retclause> returning_clause
     452             : %type <node>  returning_option
     453             : %type <retoptionkind> returning_option_kind
     454             : %type <node>  opt_routine_body
     455             : %type <groupclause> group_clause
     456             : %type <list>  group_by_list
     457             : %type <node>  group_by_item empty_grouping_set rollup_clause cube_clause
     458             : %type <node>  grouping_sets_clause
     459             : 
     460             : %type <list>  opt_fdw_options fdw_options
     461             : %type <defelt>    fdw_option
     462             : 
     463             : %type <range> OptTempTableName
     464             : %type <into>  into_clause create_as_target create_mv_target
     465             : 
     466             : %type <defelt>    createfunc_opt_item common_func_opt_item dostmt_opt_item
     467             : %type <fun_param> func_arg func_arg_with_default table_func_column aggr_arg
     468             : %type <fun_param_mode> arg_class
     469             : %type <typnam>    func_return func_type
     470             : 
     471             : %type <boolean>  opt_trusted opt_restart_seqs
     472             : %type <ival>   OptTemp
     473             : %type <ival>   OptNoLog
     474             : %type <oncommit> OnCommitOption
     475             : 
     476             : %type <ival>  for_locking_strength
     477             : %type <node>  for_locking_item
     478             : %type <list>  for_locking_clause opt_for_locking_clause for_locking_items
     479             : %type <list>  locked_rels_list
     480             : %type <setquantifier> set_quantifier
     481             : 
     482             : %type <node>  join_qual
     483             : %type <jtype> join_type
     484             : 
     485             : %type <list>  extract_list overlay_list position_list
     486             : %type <list>  substr_list trim_list
     487             : %type <list>  opt_interval interval_second
     488             : %type <str>       unicode_normal_form
     489             : 
     490             : %type <boolean> opt_instead
     491             : %type <boolean> opt_unique opt_verbose opt_full
     492             : %type <boolean> opt_freeze opt_analyze opt_default
     493             : %type <defelt>    opt_binary copy_delimiter
     494             : 
     495             : %type <boolean> copy_from opt_program
     496             : 
     497             : %type <ival>  event cursor_options opt_hold opt_set_data
     498             : %type <objtype>   object_type_any_name object_type_name object_type_name_on_any_name
     499             :                 drop_type_name
     500             : 
     501             : %type <node>  fetch_args select_limit_value
     502             :                 offset_clause select_offset_value
     503             :                 select_fetch_first_value I_or_F_const
     504             : %type <ival>  row_or_rows first_or_next
     505             : 
     506             : %type <list>  OptSeqOptList SeqOptList OptParenthesizedSeqOptList
     507             : %type <defelt>    SeqOptElem
     508             : 
     509             : %type <istmt> insert_rest
     510             : %type <infer> opt_conf_expr
     511             : %type <onconflict> opt_on_conflict
     512             : %type <mergewhen> merge_insert merge_update merge_delete
     513             : 
     514             : %type <mergematch> merge_when_tgt_matched merge_when_tgt_not_matched
     515             : %type <node>  merge_when_clause opt_merge_when_condition
     516             : %type <list>  merge_when_list
     517             : 
     518             : %type <vsetstmt> generic_set set_rest set_rest_more generic_reset reset_rest
     519             :                  SetResetClause FunctionSetResetClause
     520             : 
     521             : %type <node>  TableElement TypedTableElement ConstraintElem DomainConstraintElem TableFuncElement
     522             : %type <node>  columnDef columnOptions optionalPeriodName
     523             : %type <defelt>    def_elem reloption_elem old_aggr_elem operator_def_elem
     524             : %type <node>  def_arg columnElem where_clause where_or_current_clause
     525             :                 a_expr b_expr c_expr AexprConst indirection_el opt_slice_bound
     526             :                 columnref in_expr having_clause func_table xmltable array_expr
     527             :                 OptWhereClause operator_def_arg
     528             : %type <list>  opt_column_and_period_list
     529             : %type <list>  rowsfrom_item rowsfrom_list opt_col_def_list
     530             : %type <boolean> opt_ordinality opt_without_overlaps
     531             : %type <list>  ExclusionConstraintList ExclusionConstraintElem
     532             : %type <list>  func_arg_list func_arg_list_opt
     533             : %type <node>  func_arg_expr
     534             : %type <list>  row explicit_row implicit_row type_list array_expr_list
     535             : %type <node>  case_expr case_arg when_clause case_default
     536             : %type <list>  when_clause_list
     537             : %type <node>  opt_search_clause opt_cycle_clause
     538             : %type <ival>  sub_type opt_materialized
     539             : %type <node>  NumericOnly
     540             : %type <list>  NumericOnly_list
     541             : %type <alias> alias_clause opt_alias_clause opt_alias_clause_for_join_using
     542             : %type <list>  func_alias_clause
     543             : %type <sortby>    sortby
     544             : %type <ielem> index_elem index_elem_options
     545             : %type <selem> stats_param
     546             : %type <node>  table_ref
     547             : %type <jexpr> joined_table
     548             : %type <range> relation_expr
     549             : %type <range> extended_relation_expr
     550             : %type <range> relation_expr_opt_alias
     551             : %type <node>  tablesample_clause opt_repeatable_clause
     552             : %type <target>    target_el set_target insert_column_item
     553             : 
     554             : %type <str>       generic_option_name
     555             : %type <node>  generic_option_arg
     556             : %type <defelt>    generic_option_elem alter_generic_option_elem
     557             : %type <list>  generic_option_list alter_generic_option_list
     558             : 
     559             : %type <ival>  reindex_target_relation reindex_target_all
     560             : %type <list>  opt_reindex_option_list
     561             : 
     562             : %type <node>  copy_generic_opt_arg copy_generic_opt_arg_list_item
     563             : %type <defelt>    copy_generic_opt_elem
     564             : %type <list>  copy_generic_opt_list copy_generic_opt_arg_list
     565             : %type <list>  copy_options
     566             : 
     567             : %type <typnam>    Typename SimpleTypename ConstTypename
     568             :                 GenericType Numeric opt_float JsonType
     569             :                 Character ConstCharacter
     570             :                 CharacterWithLength CharacterWithoutLength
     571             :                 ConstDatetime ConstInterval
     572             :                 Bit ConstBit BitWithLength BitWithoutLength
     573             : %type <str>       character
     574             : %type <str>       extract_arg
     575             : %type <boolean> opt_varying opt_timezone opt_no_inherit
     576             : 
     577             : %type <ival>  Iconst SignedIconst
     578             : %type <str>       Sconst comment_text notify_payload
     579             : %type <str>       RoleId opt_boolean_or_string
     580             : %type <list>  var_list
     581             : %type <str>       ColId ColLabel BareColLabel
     582             : %type <str>       NonReservedWord NonReservedWord_or_Sconst
     583             : %type <str>       var_name type_function_name param_name
     584             : %type <str>       createdb_opt_name plassign_target
     585             : %type <node>  var_value zone_value
     586             : %type <rolespec> auth_ident RoleSpec opt_granted_by
     587             : %type <publicationobjectspec> PublicationObjSpec
     588             : 
     589             : %type <keyword> unreserved_keyword type_func_name_keyword
     590             : %type <keyword> col_name_keyword reserved_keyword
     591             : %type <keyword> bare_label_keyword
     592             : 
     593             : %type <node>  DomainConstraint TableConstraint TableLikeClause
     594             : %type <ival>  TableLikeOptionList TableLikeOption
     595             : %type <str>       column_compression opt_column_compression column_storage opt_column_storage
     596             : %type <list>  ColQualList
     597             : %type <node>  ColConstraint ColConstraintElem ConstraintAttr
     598             : %type <ival>  key_match
     599             : %type <keyaction> key_delete key_update key_action
     600             : %type <keyactions> key_actions
     601             : %type <ival>  ConstraintAttributeSpec ConstraintAttributeElem
     602             : %type <str>       ExistingIndex
     603             : 
     604             : %type <list>  constraints_set_list
     605             : %type <boolean> constraints_set_mode
     606             : %type <str>       OptTableSpace OptConsTableSpace
     607             : %type <rolespec> OptTableSpaceOwner
     608             : %type <ival>  opt_check_option
     609             : 
     610             : %type <str>       opt_provider security_label
     611             : 
     612             : %type <target>    xml_attribute_el
     613             : %type <list>  xml_attribute_list xml_attributes
     614             : %type <node>  xml_root_version opt_xml_root_standalone
     615             : %type <node>  xmlexists_argument
     616             : %type <ival>  document_or_content
     617             : %type <boolean>   xml_indent_option xml_whitespace_option
     618             : %type <list>  xmltable_column_list xmltable_column_option_list
     619             : %type <node>  xmltable_column_el
     620             : %type <defelt>    xmltable_column_option_el
     621             : %type <list>  xml_namespace_list
     622             : %type <target>    xml_namespace_el
     623             : 
     624             : %type <node>  func_application func_expr_common_subexpr
     625             : %type <node>  func_expr func_expr_windowless
     626             : %type <node>  common_table_expr
     627             : %type <with>  with_clause opt_with_clause
     628             : %type <list>  cte_list
     629             : 
     630             : %type <list>  within_group_clause
     631             : %type <node>  filter_clause
     632             : %type <list>  window_clause window_definition_list opt_partition_clause
     633             : %type <windef>    window_definition over_clause window_specification
     634             :                 opt_frame_clause frame_extent frame_bound
     635             : %type <ival>  opt_window_exclusion_clause
     636             : %type <str>       opt_existing_window_name
     637             : %type <boolean> opt_if_not_exists
     638             : %type <boolean> opt_unique_null_treatment
     639             : %type <ival>  generated_when override_kind
     640             : %type <partspec>  PartitionSpec OptPartitionSpec
     641             : %type <partelem>  part_elem
     642             : %type <list>      part_params
     643             : %type <partboundspec> PartitionBoundSpec
     644             : %type <list>      hash_partbound
     645             : %type <defelt>        hash_partbound_elem
     646             : 
     647             : %type <node>  json_format_clause
     648             :                 json_format_clause_opt
     649             :                 json_value_expr
     650             :                 json_returning_clause_opt
     651             :                 json_name_and_value
     652             :                 json_aggregate_func
     653             :                 json_argument
     654             :                 json_behavior
     655             :                 json_on_error_clause_opt
     656             :                 json_table
     657             :                 json_table_column_definition
     658             :                 json_table_column_path_clause_opt
     659             : %type <list>  json_name_and_value_list
     660             :                 json_value_expr_list
     661             :                 json_array_aggregate_order_by_clause_opt
     662             :                 json_arguments
     663             :                 json_behavior_clause_opt
     664             :                 json_passing_clause_opt
     665             :                 json_table_column_definition_list
     666             : %type <str>       json_table_path_name_opt
     667             : %type <ival>  json_behavior_type
     668             :                 json_predicate_type_constraint
     669             :                 json_quotes_clause_opt
     670             :                 json_wrapper_behavior
     671             : %type <boolean>   json_key_uniqueness_constraint_opt
     672             :                 json_object_constructor_null_clause_opt
     673             :                 json_array_constructor_null_clause_opt
     674             : 
     675             : 
     676             : /*
     677             :  * Non-keyword token types.  These are hard-wired into the "flex" lexer.
     678             :  * They must be listed first so that their numeric codes do not depend on
     679             :  * the set of keywords.  PL/pgSQL depends on this so that it can share the
     680             :  * same lexer.  If you add/change tokens here, fix PL/pgSQL to match!
     681             :  *
     682             :  * UIDENT and USCONST are reduced to IDENT and SCONST in parser.c, so that
     683             :  * they need no productions here; but we must assign token codes to them.
     684             :  *
     685             :  * DOT_DOT is unused in the core SQL grammar, and so will always provoke
     686             :  * parse errors.  It is needed by PL/pgSQL.
     687             :  */
     688             : %token <str>  IDENT UIDENT FCONST SCONST USCONST BCONST XCONST Op
     689             : %token <ival> ICONST PARAM
     690             : %token          TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
     691             : %token          LESS_EQUALS GREATER_EQUALS NOT_EQUALS
     692             : 
     693             : /*
     694             :  * If you want to make any keyword changes, update the keyword table in
     695             :  * src/include/parser/kwlist.h and add new keywords to the appropriate one
     696             :  * of the reserved-or-not-so-reserved keyword lists, below; search
     697             :  * this file for "Keyword category lists".
     698             :  */
     699             : 
     700             : /* ordinary key words in alphabetical order */
     701             : %token <keyword> ABORT_P ABSENT ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
     702             :     AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
     703             :     ASENSITIVE ASSERTION ASSIGNMENT ASYMMETRIC ATOMIC AT ATTACH ATTRIBUTE AUTHORIZATION
     704             : 
     705             :     BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
     706             :     BOOLEAN_P BOTH BREADTH BY
     707             : 
     708             :     CACHE CALL CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
     709             :     CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
     710             :     CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
     711             :     COMMITTED COMPRESSION CONCURRENTLY CONDITIONAL CONFIGURATION CONFLICT
     712             :     CONNECTION CONSTRAINT CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY
     713             :     COST CREATE CROSS CSV CUBE CURRENT_P
     714             :     CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
     715             :     CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
     716             : 
     717             :     DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
     718             :     DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DEPENDS DEPTH DESC
     719             :     DETACH DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P
     720             :     DOUBLE_P DROP
     721             : 
     722             :     EACH ELSE EMPTY_P ENABLE_P ENCODING ENCRYPTED END_P ENFORCED ENUM_P ERROR_P
     723             :     ESCAPE EVENT EXCEPT EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN
     724             :     EXPRESSION EXTENSION EXTERNAL EXTRACT
     725             : 
     726             :     FALSE_P FAMILY FETCH FILTER FINALIZE FIRST_P FLOAT_P FOLLOWING FOR
     727             :     FORCE FOREIGN FORMAT FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
     728             : 
     729             :     GENERATED GLOBAL GRANT GRANTED GREATEST GROUP_P GROUPING GROUPS
     730             : 
     731             :     HANDLER HAVING HEADER_P HOLD HOUR_P
     732             : 
     733             :     IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P INCLUDE
     734             :     INCLUDING INCREMENT INDENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
     735             :     INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
     736             :     INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
     737             : 
     738             :     JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_EXISTS JSON_OBJECT JSON_OBJECTAGG
     739             :     JSON_QUERY JSON_SCALAR JSON_SERIALIZE JSON_TABLE JSON_VALUE
     740             : 
     741             :     KEEP KEY KEYS
     742             : 
     743             :     LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
     744             :     LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
     745             :     LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED
     746             : 
     747             :     MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE MERGE_ACTION METHOD
     748             :     MINUTE_P MINVALUE MODE MONTH_P MOVE
     749             : 
     750             :     NAME_P NAMES NATIONAL NATURAL NCHAR NESTED NEW NEXT NFC NFD NFKC NFKD NO
     751             :     NONE NORMALIZE NORMALIZED
     752             :     NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
     753             :     NULLS_P NUMERIC
     754             : 
     755             :     OBJECT_P OF OFF OFFSET OIDS OLD OMIT ON ONLY OPERATOR OPTION OPTIONS OR
     756             :     ORDER ORDINALITY OTHERS OUT_P OUTER_P
     757             :     OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
     758             : 
     759             :     PARALLEL PARAMETER PARSER PARTIAL PARTITION PASSING PASSWORD PATH
     760             :     PERIOD PLACING PLAN PLANS POLICY
     761             :     POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
     762             :     PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PUBLICATION
     763             : 
     764             :     QUOTE QUOTES
     765             : 
     766             :     RANGE READ REAL REASSIGN RECURSIVE REF_P REFERENCES REFERENCING
     767             :     REFRESH REINDEX RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
     768             :     RESET RESTART RESTRICT RETURN RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
     769             :     ROUTINE ROUTINES ROW ROWS RULE
     770             : 
     771             :     SAVEPOINT SCALAR SCHEMA SCHEMAS SCROLL SEARCH SECOND_P SECURITY SELECT
     772             :     SEQUENCE SEQUENCES
     773             :     SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
     774             :     SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SOURCE SQL_P STABLE STANDALONE_P
     775             :     START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRING_P STRIP_P
     776             :     SUBSCRIPTION SUBSTRING SUPPORT SYMMETRIC SYSID SYSTEM_P SYSTEM_USER
     777             : 
     778             :     TABLE TABLES TABLESAMPLE TABLESPACE TARGET TEMP TEMPLATE TEMPORARY TEXT_P THEN
     779             :     TIES TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM
     780             :     TREAT TRIGGER TRIM TRUE_P
     781             :     TRUNCATE TRUSTED TYPE_P TYPES_P
     782             : 
     783             :     UESCAPE UNBOUNDED UNCONDITIONAL UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
     784             :     UNLISTEN UNLOGGED UNTIL UPDATE USER USING
     785             : 
     786             :     VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
     787             :     VERBOSE VERSION_P VIEW VIEWS VOLATILE
     788             : 
     789             :     WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
     790             : 
     791             :     XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLNAMESPACES
     792             :     XMLPARSE XMLPI XMLROOT XMLSERIALIZE XMLTABLE
     793             : 
     794             :     YEAR_P YES_P
     795             : 
     796             :     ZONE
     797             : 
     798             : /*
     799             :  * The grammar thinks these are keywords, but they are not in the kwlist.h
     800             :  * list and so can never be entered directly.  The filter in parser.c
     801             :  * creates these tokens when required (based on looking one token ahead).
     802             :  *
     803             :  * NOT_LA exists so that productions such as NOT LIKE can be given the same
     804             :  * precedence as LIKE; otherwise they'd effectively have the same precedence
     805             :  * as NOT, at least with respect to their left-hand subexpression.
     806             :  * FORMAT_LA, NULLS_LA, WITH_LA, and WITHOUT_LA are needed to make the grammar
     807             :  * LALR(1).
     808             :  */
     809             : %token      FORMAT_LA NOT_LA NULLS_LA WITH_LA WITHOUT_LA
     810             : 
     811             : /*
     812             :  * The grammar likewise thinks these tokens are keywords, but they are never
     813             :  * generated by the scanner.  Rather, they can be injected by parser.c as
     814             :  * the initial token of the string (using the lookahead-token mechanism
     815             :  * implemented there).  This provides a way to tell the grammar to parse
     816             :  * something other than the usual list of SQL commands.
     817             :  */
     818             : %token      MODE_TYPE_NAME
     819             : %token      MODE_PLPGSQL_EXPR
     820             : %token      MODE_PLPGSQL_ASSIGN1
     821             : %token      MODE_PLPGSQL_ASSIGN2
     822             : %token      MODE_PLPGSQL_ASSIGN3
     823             : 
     824             : 
     825             : /* Precedence: lowest to highest */
     826             : %left       UNION EXCEPT
     827             : %left       INTERSECT
     828             : %left       OR
     829             : %left       AND
     830             : %right      NOT
     831             : %nonassoc   IS ISNULL NOTNULL   /* IS sets precedence for IS NULL, etc */
     832             : %nonassoc   '<' '>' '=' LESS_EQUALS GREATER_EQUALS NOT_EQUALS
     833             : %nonassoc   BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
     834             : %nonassoc   ESCAPE          /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
     835             : 
     836             : /*
     837             :  * Sometimes it is necessary to assign precedence to keywords that are not
     838             :  * really part of the operator hierarchy, in order to resolve grammar
     839             :  * ambiguities.  It's best to avoid doing so whenever possible, because such
     840             :  * assignments have global effect and may hide ambiguities besides the one
     841             :  * you intended to solve.  (Attaching a precedence to a single rule with
     842             :  * %prec is far safer and should be preferred.)  If you must give precedence
     843             :  * to a new keyword, try very hard to give it the same precedence as IDENT.
     844             :  * If the keyword has IDENT's precedence then it clearly acts the same as
     845             :  * non-keywords and other similar keywords, thus reducing the risk of
     846             :  * unexpected precedence effects.
     847             :  *
     848             :  * We used to need to assign IDENT an explicit precedence just less than Op,
     849             :  * to support target_el without AS.  While that's not really necessary since
     850             :  * we removed postfix operators, we continue to do so because it provides a
     851             :  * reference point for a precedence level that we can assign to other
     852             :  * keywords that lack a natural precedence level.
     853             :  *
     854             :  * We need to do this for PARTITION, RANGE, ROWS, and GROUPS to support
     855             :  * opt_existing_window_name (see comment there).
     856             :  *
     857             :  * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
     858             :  * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
     859             :  * there is no principled way to distinguish these from the productions
     860             :  * a_expr PRECEDING/FOLLOWING.  We hack this up by giving UNBOUNDED slightly
     861             :  * lower precedence than PRECEDING and FOLLOWING.  At present this doesn't
     862             :  * appear to cause UNBOUNDED to be treated differently from other unreserved
     863             :  * keywords anywhere else in the grammar, but it's definitely risky.  We can
     864             :  * blame any funny behavior of UNBOUNDED on the SQL standard, though.
     865             :  *
     866             :  * To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
     867             :  * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
     868             :  * rather than reducing a conflicting rule that takes CUBE as a function name.
     869             :  * Using the same precedence as IDENT seems right for the reasons given above.
     870             :  *
     871             :  * SET is likewise assigned the same precedence as IDENT, to support the
     872             :  * relation_expr_opt_alias production (see comment there).
     873             :  *
     874             :  * KEYS, OBJECT_P, SCALAR, VALUE_P, WITH, and WITHOUT are similarly assigned
     875             :  * the same precedence as IDENT.  This allows resolving conflicts in the
     876             :  * json_predicate_type_constraint and json_key_uniqueness_constraint_opt
     877             :  * productions (see comments there).
     878             :  *
     879             :  * Like the UNBOUNDED PRECEDING/FOLLOWING case, NESTED is assigned a lower
     880             :  * precedence than PATH to fix ambiguity in the json_table production.
     881             :  */
     882             : %nonassoc   UNBOUNDED NESTED /* ideally would have same precedence as IDENT */
     883             : %nonassoc   IDENT PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
     884             :             SET KEYS OBJECT_P SCALAR VALUE_P WITH WITHOUT PATH
     885             : %left       Op OPERATOR     /* multi-character ops and user-defined operators */
     886             : %left       '+' '-'
     887             : %left       '*' '/' '%'
     888             : %left       '^'
     889             : /* Unary Operators */
     890             : %left       AT              /* sets precedence for AT TIME ZONE, AT LOCAL */
     891             : %left       COLLATE
     892             : %right      UMINUS
     893             : %left       '[' ']'
     894             : %left       '(' ')'
     895             : %left       TYPECAST
     896             : %left       '.'
     897             : /*
     898             :  * These might seem to be low-precedence, but actually they are not part
     899             :  * of the arithmetic hierarchy at all in their use as JOIN operators.
     900             :  * We make them high-precedence to support their use as function names.
     901             :  * They wouldn't be given a precedence at all, were it not that we need
     902             :  * left-associativity among the JOIN rules themselves.
     903             :  */
     904             : %left       JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
     905             : 
     906             : %%
     907             : 
     908             : /*
     909             :  *  The target production for the whole parse.
     910             :  *
     911             :  * Ordinarily we parse a list of statements, but if we see one of the
     912             :  * special MODE_XXX symbols as first token, we parse something else.
     913             :  * The options here correspond to enum RawParseMode, which see for details.
     914             :  */
     915             : parse_toplevel:
     916             :             stmtmulti
     917             :             {
     918      708164 :                 pg_yyget_extra(yyscanner)->parsetree = $1;
     919             :                 (void) yynerrs;     /* suppress compiler warning */
     920             :             }
     921             :             | MODE_TYPE_NAME Typename
     922             :             {
     923        9544 :                 pg_yyget_extra(yyscanner)->parsetree = list_make1($2);
     924             :             }
     925             :             | MODE_PLPGSQL_EXPR PLpgSQL_Expr
     926             :             {
     927       32416 :                 pg_yyget_extra(yyscanner)->parsetree =
     928       32416 :                     list_make1(makeRawStmt($2, @2));
     929             :             }
     930             :             | MODE_PLPGSQL_ASSIGN1 PLAssignStmt
     931             :             {
     932        6202 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     933             : 
     934        6202 :                 n->nnames = 1;
     935        6202 :                 pg_yyget_extra(yyscanner)->parsetree =
     936        6202 :                     list_make1(makeRawStmt((Node *) n, @2));
     937             :             }
     938             :             | MODE_PLPGSQL_ASSIGN2 PLAssignStmt
     939             :             {
     940         650 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     941             : 
     942         650 :                 n->nnames = 2;
     943         650 :                 pg_yyget_extra(yyscanner)->parsetree =
     944         650 :                     list_make1(makeRawStmt((Node *) n, @2));
     945             :             }
     946             :             | MODE_PLPGSQL_ASSIGN3 PLAssignStmt
     947             :             {
     948          28 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     949             : 
     950          28 :                 n->nnames = 3;
     951          28 :                 pg_yyget_extra(yyscanner)->parsetree =
     952          28 :                     list_make1(makeRawStmt((Node *) n, @2));
     953             :             }
     954             :         ;
     955             : 
     956             : /*
     957             :  * At top level, we wrap each stmt with a RawStmt node carrying start location
     958             :  * and length of the stmt's text.
     959             :  * We also take care to discard empty statements entirely (which among other
     960             :  * things dodges the problem of assigning them a location).
     961             :  */
     962             : stmtmulti:  stmtmulti ';' toplevel_stmt
     963             :                 {
     964      564396 :                     if ($1 != NIL)
     965             :                     {
     966             :                         /* update length of previous stmt */
     967      564300 :                         updateRawStmtEnd(llast_node(RawStmt, $1), @2);
     968             :                     }
     969      564396 :                     if ($3 != NULL)
     970       49824 :                         $$ = lappend($1, makeRawStmt($3, @3));
     971             :                     else
     972      514572 :                         $$ = $1;
     973             :                 }
     974             :             | toplevel_stmt
     975             :                 {
     976      708172 :                     if ($1 != NULL)
     977      707694 :                         $$ = list_make1(makeRawStmt($1, @1));
     978             :                     else
     979         478 :                         $$ = NIL;
     980             :                 }
     981             :         ;
     982             : 
     983             : /*
     984             :  * toplevel_stmt includes BEGIN and END.  stmt does not include them, because
     985             :  * those words have different meanings in function bodies.
     986             :  */
     987             : toplevel_stmt:
     988             :             stmt
     989             :             | TransactionStmtLegacy
     990             :         ;
     991             : 
     992             : stmt:
     993             :             AlterEventTrigStmt
     994             :             | AlterCollationStmt
     995             :             | AlterDatabaseStmt
     996             :             | AlterDatabaseSetStmt
     997             :             | AlterDefaultPrivilegesStmt
     998             :             | AlterDomainStmt
     999             :             | AlterEnumStmt
    1000             :             | AlterExtensionStmt
    1001             :             | AlterExtensionContentsStmt
    1002             :             | AlterFdwStmt
    1003             :             | AlterForeignServerStmt
    1004             :             | AlterFunctionStmt
    1005             :             | AlterGroupStmt
    1006             :             | AlterObjectDependsStmt
    1007             :             | AlterObjectSchemaStmt
    1008             :             | AlterOwnerStmt
    1009             :             | AlterOperatorStmt
    1010             :             | AlterTypeStmt
    1011             :             | AlterPolicyStmt
    1012             :             | AlterSeqStmt
    1013             :             | AlterSystemStmt
    1014             :             | AlterTableStmt
    1015             :             | AlterTblSpcStmt
    1016             :             | AlterCompositeTypeStmt
    1017             :             | AlterPublicationStmt
    1018             :             | AlterRoleSetStmt
    1019             :             | AlterRoleStmt
    1020             :             | AlterSubscriptionStmt
    1021             :             | AlterStatsStmt
    1022             :             | AlterTSConfigurationStmt
    1023             :             | AlterTSDictionaryStmt
    1024             :             | AlterUserMappingStmt
    1025             :             | AnalyzeStmt
    1026             :             | CallStmt
    1027             :             | CheckPointStmt
    1028             :             | ClosePortalStmt
    1029             :             | ClusterStmt
    1030             :             | CommentStmt
    1031             :             | ConstraintsSetStmt
    1032             :             | CopyStmt
    1033             :             | CreateAmStmt
    1034             :             | CreateAsStmt
    1035             :             | CreateAssertionStmt
    1036             :             | CreateCastStmt
    1037             :             | CreateConversionStmt
    1038             :             | CreateDomainStmt
    1039             :             | CreateExtensionStmt
    1040             :             | CreateFdwStmt
    1041             :             | CreateForeignServerStmt
    1042             :             | CreateForeignTableStmt
    1043             :             | CreateFunctionStmt
    1044             :             | CreateGroupStmt
    1045             :             | CreateMatViewStmt
    1046             :             | CreateOpClassStmt
    1047             :             | CreateOpFamilyStmt
    1048             :             | CreatePublicationStmt
    1049             :             | AlterOpFamilyStmt
    1050             :             | CreatePolicyStmt
    1051             :             | CreatePLangStmt
    1052             :             | CreateSchemaStmt
    1053             :             | CreateSeqStmt
    1054             :             | CreateStmt
    1055             :             | CreateSubscriptionStmt
    1056             :             | CreateStatsStmt
    1057             :             | CreateTableSpaceStmt
    1058             :             | CreateTransformStmt
    1059             :             | CreateTrigStmt
    1060             :             | CreateEventTrigStmt
    1061             :             | CreateRoleStmt
    1062             :             | CreateUserStmt
    1063             :             | CreateUserMappingStmt
    1064             :             | CreatedbStmt
    1065             :             | DeallocateStmt
    1066             :             | DeclareCursorStmt
    1067             :             | DefineStmt
    1068             :             | DeleteStmt
    1069             :             | DiscardStmt
    1070             :             | DoStmt
    1071             :             | DropCastStmt
    1072             :             | DropOpClassStmt
    1073             :             | DropOpFamilyStmt
    1074             :             | DropOwnedStmt
    1075             :             | DropStmt
    1076             :             | DropSubscriptionStmt
    1077             :             | DropTableSpaceStmt
    1078             :             | DropTransformStmt
    1079             :             | DropRoleStmt
    1080             :             | DropUserMappingStmt
    1081             :             | DropdbStmt
    1082             :             | ExecuteStmt
    1083             :             | ExplainStmt
    1084             :             | FetchStmt
    1085             :             | GrantStmt
    1086             :             | GrantRoleStmt
    1087             :             | ImportForeignSchemaStmt
    1088             :             | IndexStmt
    1089             :             | InsertStmt
    1090             :             | ListenStmt
    1091             :             | RefreshMatViewStmt
    1092             :             | LoadStmt
    1093             :             | LockStmt
    1094             :             | MergeStmt
    1095             :             | NotifyStmt
    1096             :             | PrepareStmt
    1097             :             | ReassignOwnedStmt
    1098             :             | ReindexStmt
    1099             :             | RemoveAggrStmt
    1100             :             | RemoveFuncStmt
    1101             :             | RemoveOperStmt
    1102             :             | RenameStmt
    1103             :             | RevokeStmt
    1104             :             | RevokeRoleStmt
    1105             :             | RuleStmt
    1106             :             | SecLabelStmt
    1107             :             | SelectStmt
    1108             :             | TransactionStmt
    1109             :             | TruncateStmt
    1110             :             | UnlistenStmt
    1111             :             | UpdateStmt
    1112             :             | VacuumStmt
    1113             :             | VariableResetStmt
    1114             :             | VariableSetStmt
    1115             :             | VariableShowStmt
    1116             :             | ViewStmt
    1117             :             | /*EMPTY*/
    1118      515068 :                 { $$ = NULL; }
    1119             :         ;
    1120             : 
    1121             : /*
    1122             :  * Generic supporting productions for DDL
    1123             :  */
    1124             : opt_single_name:
    1125        5222 :             ColId                           { $$ = $1; }
    1126        1460 :             | /* EMPTY */                   { $$ = NULL; }
    1127             :         ;
    1128             : 
    1129             : opt_qualified_name:
    1130        1728 :             any_name                        { $$ = $1; }
    1131       14722 :             | /*EMPTY*/                     { $$ = NIL; }
    1132             :         ;
    1133             : 
    1134             : opt_concurrently:
    1135        1012 :             CONCURRENTLY                    { $$ = true; }
    1136        7364 :             | /*EMPTY*/                     { $$ = false; }
    1137             :         ;
    1138             : 
    1139             : opt_drop_behavior:
    1140        1900 :             CASCADE                         { $$ = DROP_CASCADE; }
    1141         170 :             | RESTRICT                      { $$ = DROP_RESTRICT; }
    1142       36412 :             | /* EMPTY */                   { $$ = DROP_RESTRICT; /* default */ }
    1143             :         ;
    1144             : 
    1145             : /*****************************************************************************
    1146             :  *
    1147             :  * CALL statement
    1148             :  *
    1149             :  *****************************************************************************/
    1150             : 
    1151             : CallStmt:   CALL func_application
    1152             :                 {
    1153         602 :                     CallStmt   *n = makeNode(CallStmt);
    1154             : 
    1155         602 :                     n->funccall = castNode(FuncCall, $2);
    1156         602 :                     $$ = (Node *) n;
    1157             :                 }
    1158             :         ;
    1159             : 
    1160             : /*****************************************************************************
    1161             :  *
    1162             :  * Create a new Postgres DBMS role
    1163             :  *
    1164             :  *****************************************************************************/
    1165             : 
    1166             : CreateRoleStmt:
    1167             :             CREATE ROLE RoleId opt_with OptRoleList
    1168             :                 {
    1169        1302 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1170             : 
    1171        1302 :                     n->stmt_type = ROLESTMT_ROLE;
    1172        1302 :                     n->role = $3;
    1173        1302 :                     n->options = $5;
    1174        1302 :                     $$ = (Node *) n;
    1175             :                 }
    1176             :         ;
    1177             : 
    1178             : 
    1179             : opt_with:   WITH
    1180             :             | WITH_LA
    1181             :             | /*EMPTY*/
    1182             :         ;
    1183             : 
    1184             : /*
    1185             :  * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
    1186             :  * for backwards compatibility).  Note: the only option required by SQL99
    1187             :  * is "WITH ADMIN name".
    1188             :  */
    1189             : OptRoleList:
    1190        1178 :             OptRoleList CreateOptRoleElem           { $$ = lappend($1, $2); }
    1191        1772 :             | /* EMPTY */                           { $$ = NIL; }
    1192             :         ;
    1193             : 
    1194             : AlterOptRoleList:
    1195         586 :             AlterOptRoleList AlterOptRoleElem       { $$ = lappend($1, $2); }
    1196         406 :             | /* EMPTY */                           { $$ = NIL; }
    1197             :         ;
    1198             : 
    1199             : AlterOptRoleElem:
    1200             :             PASSWORD Sconst
    1201             :                 {
    1202         182 :                     $$ = makeDefElem("password",
    1203         182 :                                      (Node *) makeString($2), @1);
    1204             :                 }
    1205             :             | PASSWORD NULL_P
    1206             :                 {
    1207          12 :                     $$ = makeDefElem("password", NULL, @1);
    1208             :                 }
    1209             :             | ENCRYPTED PASSWORD Sconst
    1210             :                 {
    1211             :                     /*
    1212             :                      * These days, passwords are always stored in encrypted
    1213             :                      * form, so there is no difference between PASSWORD and
    1214             :                      * ENCRYPTED PASSWORD.
    1215             :                      */
    1216          16 :                     $$ = makeDefElem("password",
    1217          16 :                                      (Node *) makeString($3), @1);
    1218             :                 }
    1219             :             | UNENCRYPTED PASSWORD Sconst
    1220             :                 {
    1221           0 :                     ereport(ERROR,
    1222             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1223             :                              errmsg("UNENCRYPTED PASSWORD is no longer supported"),
    1224             :                              errhint("Remove UNENCRYPTED to store the password in encrypted form instead."),
    1225             :                              parser_errposition(@1)));
    1226             :                 }
    1227             :             | INHERIT
    1228             :                 {
    1229          86 :                     $$ = makeDefElem("inherit", (Node *) makeBoolean(true), @1);
    1230             :                 }
    1231             :             | CONNECTION LIMIT SignedIconst
    1232             :                 {
    1233          24 :                     $$ = makeDefElem("connectionlimit", (Node *) makeInteger($3), @1);
    1234             :                 }
    1235             :             | VALID UNTIL Sconst
    1236             :                 {
    1237           2 :                     $$ = makeDefElem("validUntil", (Node *) makeString($3), @1);
    1238             :                 }
    1239             :         /*  Supported but not documented for roles, for use by ALTER GROUP. */
    1240             :             | USER role_list
    1241             :                 {
    1242           6 :                     $$ = makeDefElem("rolemembers", (Node *) $2, @1);
    1243             :                 }
    1244             :             | IDENT
    1245             :                 {
    1246             :                     /*
    1247             :                      * We handle identifiers that aren't parser keywords with
    1248             :                      * the following special-case codes, to avoid bloating the
    1249             :                      * size of the main parser.
    1250             :                      */
    1251        1292 :                     if (strcmp($1, "superuser") == 0)
    1252         182 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(true), @1);
    1253        1110 :                     else if (strcmp($1, "nosuperuser") == 0)
    1254         100 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(false), @1);
    1255        1010 :                     else if (strcmp($1, "createrole") == 0)
    1256          92 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(true), @1);
    1257         918 :                     else if (strcmp($1, "nocreaterole") == 0)
    1258          38 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(false), @1);
    1259         880 :                     else if (strcmp($1, "replication") == 0)
    1260         120 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(true), @1);
    1261         760 :                     else if (strcmp($1, "noreplication") == 0)
    1262          96 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(false), @1);
    1263         664 :                     else if (strcmp($1, "createdb") == 0)
    1264          82 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(true), @1);
    1265         582 :                     else if (strcmp($1, "nocreatedb") == 0)
    1266          46 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(false), @1);
    1267         536 :                     else if (strcmp($1, "login") == 0)
    1268         274 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(true), @1);
    1269         262 :                     else if (strcmp($1, "nologin") == 0)
    1270          86 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(false), @1);
    1271         176 :                     else if (strcmp($1, "bypassrls") == 0)
    1272          72 :                         $$ = makeDefElem("bypassrls", (Node *) makeBoolean(true), @1);
    1273         104 :                     else if (strcmp($1, "nobypassrls") == 0)
    1274          68 :                         $$ = makeDefElem("bypassrls", (Node *) makeBoolean(false), @1);
    1275          36 :                     else if (strcmp($1, "noinherit") == 0)
    1276             :                     {
    1277             :                         /*
    1278             :                          * Note that INHERIT is a keyword, so it's handled by main parser, but
    1279             :                          * NOINHERIT is handled here.
    1280             :                          */
    1281          36 :                         $$ = makeDefElem("inherit", (Node *) makeBoolean(false), @1);
    1282             :                     }
    1283             :                     else
    1284           0 :                         ereport(ERROR,
    1285             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    1286             :                                  errmsg("unrecognized role option \"%s\"", $1),
    1287             :                                      parser_errposition(@1)));
    1288             :                 }
    1289             :         ;
    1290             : 
    1291             : CreateOptRoleElem:
    1292        1034 :             AlterOptRoleElem            { $$ = $1; }
    1293             :             /* The following are not supported by ALTER ROLE/USER/GROUP */
    1294             :             | SYSID Iconst
    1295             :                 {
    1296           6 :                     $$ = makeDefElem("sysid", (Node *) makeInteger($2), @1);
    1297             :                 }
    1298             :             | ADMIN role_list
    1299             :                 {
    1300          22 :                     $$ = makeDefElem("adminmembers", (Node *) $2, @1);
    1301             :                 }
    1302             :             | ROLE role_list
    1303             :                 {
    1304          16 :                     $$ = makeDefElem("rolemembers", (Node *) $2, @1);
    1305             :                 }
    1306             :             | IN_P ROLE role_list
    1307             :                 {
    1308         100 :                     $$ = makeDefElem("addroleto", (Node *) $3, @1);
    1309             :                 }
    1310             :             | IN_P GROUP_P role_list
    1311             :                 {
    1312           0 :                     $$ = makeDefElem("addroleto", (Node *) $3, @1);
    1313             :                 }
    1314             :         ;
    1315             : 
    1316             : 
    1317             : /*****************************************************************************
    1318             :  *
    1319             :  * Create a new Postgres DBMS user (role with implied login ability)
    1320             :  *
    1321             :  *****************************************************************************/
    1322             : 
    1323             : CreateUserStmt:
    1324             :             CREATE USER RoleId opt_with OptRoleList
    1325             :                 {
    1326         446 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1327             : 
    1328         446 :                     n->stmt_type = ROLESTMT_USER;
    1329         446 :                     n->role = $3;
    1330         446 :                     n->options = $5;
    1331         446 :                     $$ = (Node *) n;
    1332             :                 }
    1333             :         ;
    1334             : 
    1335             : 
    1336             : /*****************************************************************************
    1337             :  *
    1338             :  * Alter a postgresql DBMS role
    1339             :  *
    1340             :  *****************************************************************************/
    1341             : 
    1342             : AlterRoleStmt:
    1343             :             ALTER ROLE RoleSpec opt_with AlterOptRoleList
    1344             :                  {
    1345         314 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1346             : 
    1347         314 :                     n->role = $3;
    1348         314 :                     n->action = +1;  /* add, if there are members */
    1349         314 :                     n->options = $5;
    1350         314 :                     $$ = (Node *) n;
    1351             :                  }
    1352             :             | ALTER USER RoleSpec opt_with AlterOptRoleList
    1353             :                  {
    1354          92 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1355             : 
    1356          92 :                     n->role = $3;
    1357          92 :                     n->action = +1;  /* add, if there are members */
    1358          92 :                     n->options = $5;
    1359          92 :                     $$ = (Node *) n;
    1360             :                  }
    1361             :         ;
    1362             : 
    1363             : opt_in_database:
    1364          86 :                /* EMPTY */                  { $$ = NULL; }
    1365           0 :             | IN_P DATABASE name    { $$ = $3; }
    1366             :         ;
    1367             : 
    1368             : AlterRoleSetStmt:
    1369             :             ALTER ROLE RoleSpec opt_in_database SetResetClause
    1370             :                 {
    1371          48 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1372             : 
    1373          48 :                     n->role = $3;
    1374          48 :                     n->database = $4;
    1375          48 :                     n->setstmt = $5;
    1376          48 :                     $$ = (Node *) n;
    1377             :                 }
    1378             :             | ALTER ROLE ALL opt_in_database SetResetClause
    1379             :                 {
    1380           4 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1381             : 
    1382           4 :                     n->role = NULL;
    1383           4 :                     n->database = $4;
    1384           4 :                     n->setstmt = $5;
    1385           4 :                     $$ = (Node *) n;
    1386             :                 }
    1387             :             | ALTER USER RoleSpec opt_in_database SetResetClause
    1388             :                 {
    1389          26 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1390             : 
    1391          26 :                     n->role = $3;
    1392          26 :                     n->database = $4;
    1393          26 :                     n->setstmt = $5;
    1394          26 :                     $$ = (Node *) n;
    1395             :                 }
    1396             :             | ALTER USER ALL opt_in_database SetResetClause
    1397             :                 {
    1398           4 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1399             : 
    1400           4 :                     n->role = NULL;
    1401           4 :                     n->database = $4;
    1402           4 :                     n->setstmt = $5;
    1403           4 :                     $$ = (Node *) n;
    1404             :                 }
    1405             :         ;
    1406             : 
    1407             : 
    1408             : /*****************************************************************************
    1409             :  *
    1410             :  * Drop a postgresql DBMS role
    1411             :  *
    1412             :  * XXX Ideally this would have CASCADE/RESTRICT options, but a role
    1413             :  * might own objects in multiple databases, and there is presently no way to
    1414             :  * implement cascading to other databases.  So we always behave as RESTRICT.
    1415             :  *****************************************************************************/
    1416             : 
    1417             : DropRoleStmt:
    1418             :             DROP ROLE role_list
    1419             :                 {
    1420        1072 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1421             : 
    1422        1072 :                     n->missing_ok = false;
    1423        1072 :                     n->roles = $3;
    1424        1072 :                     $$ = (Node *) n;
    1425             :                 }
    1426             :             | DROP ROLE IF_P EXISTS role_list
    1427             :                 {
    1428         134 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1429             : 
    1430         134 :                     n->missing_ok = true;
    1431         134 :                     n->roles = $5;
    1432         134 :                     $$ = (Node *) n;
    1433             :                 }
    1434             :             | DROP USER role_list
    1435             :                 {
    1436         398 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1437             : 
    1438         398 :                     n->missing_ok = false;
    1439         398 :                     n->roles = $3;
    1440         398 :                     $$ = (Node *) n;
    1441             :                 }
    1442             :             | DROP USER IF_P EXISTS role_list
    1443             :                 {
    1444          36 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1445             : 
    1446          36 :                     n->roles = $5;
    1447          36 :                     n->missing_ok = true;
    1448          36 :                     $$ = (Node *) n;
    1449             :                 }
    1450             :             | DROP GROUP_P role_list
    1451             :                 {
    1452          36 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1453             : 
    1454          36 :                     n->missing_ok = false;
    1455          36 :                     n->roles = $3;
    1456          36 :                     $$ = (Node *) n;
    1457             :                 }
    1458             :             | DROP GROUP_P IF_P EXISTS role_list
    1459             :                 {
    1460           6 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1461             : 
    1462           6 :                     n->missing_ok = true;
    1463           6 :                     n->roles = $5;
    1464           6 :                     $$ = (Node *) n;
    1465             :                 }
    1466             :             ;
    1467             : 
    1468             : 
    1469             : /*****************************************************************************
    1470             :  *
    1471             :  * Create a postgresql group (role without login ability)
    1472             :  *
    1473             :  *****************************************************************************/
    1474             : 
    1475             : CreateGroupStmt:
    1476             :             CREATE GROUP_P RoleId opt_with OptRoleList
    1477             :                 {
    1478          24 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1479             : 
    1480          24 :                     n->stmt_type = ROLESTMT_GROUP;
    1481          24 :                     n->role = $3;
    1482          24 :                     n->options = $5;
    1483          24 :                     $$ = (Node *) n;
    1484             :                 }
    1485             :         ;
    1486             : 
    1487             : 
    1488             : /*****************************************************************************
    1489             :  *
    1490             :  * Alter a postgresql group
    1491             :  *
    1492             :  *****************************************************************************/
    1493             : 
    1494             : AlterGroupStmt:
    1495             :             ALTER GROUP_P RoleSpec add_drop USER role_list
    1496             :                 {
    1497          42 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1498             : 
    1499          42 :                     n->role = $3;
    1500          42 :                     n->action = $4;
    1501          42 :                     n->options = list_make1(makeDefElem("rolemembers",
    1502             :                                                         (Node *) $6, @6));
    1503          42 :                     $$ = (Node *) n;
    1504             :                 }
    1505             :         ;
    1506             : 
    1507          86 : add_drop:   ADD_P                                   { $$ = +1; }
    1508         180 :             | DROP                                  { $$ = -1; }
    1509             :         ;
    1510             : 
    1511             : 
    1512             : /*****************************************************************************
    1513             :  *
    1514             :  * Manipulate a schema
    1515             :  *
    1516             :  *****************************************************************************/
    1517             : 
    1518             : CreateSchemaStmt:
    1519             :             CREATE SCHEMA opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
    1520             :                 {
    1521         158 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1522             : 
    1523             :                     /* One can omit the schema name or the authorization id. */
    1524         158 :                     n->schemaname = $3;
    1525         158 :                     n->authrole = $5;
    1526         158 :                     n->schemaElts = $6;
    1527         158 :                     n->if_not_exists = false;
    1528         158 :                     $$ = (Node *) n;
    1529             :                 }
    1530             :             | CREATE SCHEMA ColId OptSchemaEltList
    1531             :                 {
    1532         814 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1533             : 
    1534             :                     /* ...but not both */
    1535         814 :                     n->schemaname = $3;
    1536         814 :                     n->authrole = NULL;
    1537         814 :                     n->schemaElts = $4;
    1538         814 :                     n->if_not_exists = false;
    1539         814 :                     $$ = (Node *) n;
    1540             :                 }
    1541             :             | CREATE SCHEMA IF_P NOT EXISTS opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
    1542             :                 {
    1543          18 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1544             : 
    1545             :                     /* schema name can be omitted here, too */
    1546          18 :                     n->schemaname = $6;
    1547          18 :                     n->authrole = $8;
    1548          18 :                     if ($9 != NIL)
    1549           0 :                         ereport(ERROR,
    1550             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1551             :                                  errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
    1552             :                                  parser_errposition(@9)));
    1553          18 :                     n->schemaElts = $9;
    1554          18 :                     n->if_not_exists = true;
    1555          18 :                     $$ = (Node *) n;
    1556             :                 }
    1557             :             | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
    1558             :                 {
    1559          34 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1560             : 
    1561             :                     /* ...but not here */
    1562          34 :                     n->schemaname = $6;
    1563          34 :                     n->authrole = NULL;
    1564          34 :                     if ($7 != NIL)
    1565           6 :                         ereport(ERROR,
    1566             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1567             :                                  errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
    1568             :                                  parser_errposition(@7)));
    1569          28 :                     n->schemaElts = $7;
    1570          28 :                     n->if_not_exists = true;
    1571          28 :                     $$ = (Node *) n;
    1572             :                 }
    1573             :         ;
    1574             : 
    1575             : OptSchemaEltList:
    1576             :             OptSchemaEltList schema_stmt
    1577             :                 {
    1578         546 :                     $$ = lappend($1, $2);
    1579             :                 }
    1580             :             | /* EMPTY */
    1581        1024 :                 { $$ = NIL; }
    1582             :         ;
    1583             : 
    1584             : /*
    1585             :  *  schema_stmt are the ones that can show up inside a CREATE SCHEMA
    1586             :  *  statement (in addition to by themselves).
    1587             :  */
    1588             : schema_stmt:
    1589             :             CreateStmt
    1590             :             | IndexStmt
    1591             :             | CreateSeqStmt
    1592             :             | CreateTrigStmt
    1593             :             | GrantStmt
    1594             :             | ViewStmt
    1595             :         ;
    1596             : 
    1597             : 
    1598             : /*****************************************************************************
    1599             :  *
    1600             :  * Set PG internal variable
    1601             :  *    SET name TO 'var_value'
    1602             :  * Include SQL syntax (thomas 1997-10-22):
    1603             :  *    SET TIME ZONE 'var_value'
    1604             :  *
    1605             :  *****************************************************************************/
    1606             : 
    1607             : VariableSetStmt:
    1608             :             SET set_rest
    1609             :                 {
    1610       19144 :                     VariableSetStmt *n = $2;
    1611             : 
    1612       19144 :                     n->is_local = false;
    1613       19144 :                     $$ = (Node *) n;
    1614             :                 }
    1615             :             | SET LOCAL set_rest
    1616             :                 {
    1617        1202 :                     VariableSetStmt *n = $3;
    1618             : 
    1619        1202 :                     n->is_local = true;
    1620        1202 :                     $$ = (Node *) n;
    1621             :                 }
    1622             :             | SET SESSION set_rest
    1623             :                 {
    1624          84 :                     VariableSetStmt *n = $3;
    1625             : 
    1626          84 :                     n->is_local = false;
    1627          84 :                     $$ = (Node *) n;
    1628             :                 }
    1629             :         ;
    1630             : 
    1631             : set_rest:
    1632             :             TRANSACTION transaction_mode_list
    1633             :                 {
    1634         520 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1635             : 
    1636         520 :                     n->kind = VAR_SET_MULTI;
    1637         520 :                     n->name = "TRANSACTION";
    1638         520 :                     n->args = $2;
    1639         520 :                     n->jumble_args = true;
    1640         520 :                     n->location = -1;
    1641         520 :                     $$ = n;
    1642             :                 }
    1643             :             | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
    1644             :                 {
    1645          18 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1646             : 
    1647          18 :                     n->kind = VAR_SET_MULTI;
    1648          18 :                     n->name = "SESSION CHARACTERISTICS";
    1649          18 :                     n->args = $5;
    1650          18 :                     n->jumble_args = true;
    1651          18 :                     n->location = -1;
    1652          18 :                     $$ = n;
    1653             :                 }
    1654             :             | set_rest_more
    1655             :             ;
    1656             : 
    1657             : generic_set:
    1658             :             var_name TO var_list
    1659             :                 {
    1660        4594 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1661             : 
    1662        4594 :                     n->kind = VAR_SET_VALUE;
    1663        4594 :                     n->name = $1;
    1664        4594 :                     n->args = $3;
    1665        4594 :                     n->location = @3;
    1666        4594 :                     $$ = n;
    1667             :                 }
    1668             :             | var_name '=' var_list
    1669             :                 {
    1670       12942 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1671             : 
    1672       12942 :                     n->kind = VAR_SET_VALUE;
    1673       12942 :                     n->name = $1;
    1674       12942 :                     n->args = $3;
    1675       12942 :                     n->location = @3;
    1676       12942 :                     $$ = n;
    1677             :                 }
    1678             :             | var_name TO DEFAULT
    1679             :                 {
    1680         136 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1681             : 
    1682         136 :                     n->kind = VAR_SET_DEFAULT;
    1683         136 :                     n->name = $1;
    1684         136 :                     n->location = -1;
    1685         136 :                     $$ = n;
    1686             :                 }
    1687             :             | var_name '=' DEFAULT
    1688             :                 {
    1689          10 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1690             : 
    1691          10 :                     n->kind = VAR_SET_DEFAULT;
    1692          10 :                     n->name = $1;
    1693          10 :                     n->location = -1;
    1694          10 :                     $$ = n;
    1695             :                 }
    1696             :         ;
    1697             : 
    1698             : set_rest_more:  /* Generic SET syntaxes: */
    1699       17570 :             generic_set                         {$$ = $1;}
    1700             :             | var_name FROM CURRENT_P
    1701             :                 {
    1702           4 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1703             : 
    1704           4 :                     n->kind = VAR_SET_CURRENT;
    1705           4 :                     n->name = $1;
    1706           4 :                     n->location = -1;
    1707           4 :                     $$ = n;
    1708             :                 }
    1709             :             /* Special syntaxes mandated by SQL standard: */
    1710             :             | TIME ZONE zone_value
    1711             :                 {
    1712         104 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1713             : 
    1714         104 :                     n->kind = VAR_SET_VALUE;
    1715         104 :                     n->name = "timezone";
    1716         104 :                     n->location = -1;
    1717         104 :                     n->jumble_args = true;
    1718         104 :                     if ($3 != NULL)
    1719          88 :                         n->args = list_make1($3);
    1720             :                     else
    1721          16 :                         n->kind = VAR_SET_DEFAULT;
    1722         104 :                     $$ = n;
    1723             :                 }
    1724             :             | CATALOG_P Sconst
    1725             :                 {
    1726           0 :                     ereport(ERROR,
    1727             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1728             :                              errmsg("current database cannot be changed"),
    1729             :                              parser_errposition(@2)));
    1730             :                     $$ = NULL; /*not reached*/
    1731             :                 }
    1732             :             | SCHEMA Sconst
    1733             :                 {
    1734           4 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1735             : 
    1736           4 :                     n->kind = VAR_SET_VALUE;
    1737           4 :                     n->name = "search_path";
    1738           4 :                     n->args = list_make1(makeStringConst($2, @2));
    1739           4 :                     n->location = @2;
    1740           4 :                     $$ = n;
    1741             :                 }
    1742             :             | NAMES opt_encoding
    1743             :                 {
    1744           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1745             : 
    1746           0 :                     n->kind = VAR_SET_VALUE;
    1747           0 :                     n->name = "client_encoding";
    1748           0 :                     n->location = @2;
    1749           0 :                     if ($2 != NULL)
    1750           0 :                         n->args = list_make1(makeStringConst($2, @2));
    1751             :                     else
    1752           0 :                         n->kind = VAR_SET_DEFAULT;
    1753           0 :                     $$ = n;
    1754             :                 }
    1755             :             | ROLE NonReservedWord_or_Sconst
    1756             :                 {
    1757         906 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1758             : 
    1759         906 :                     n->kind = VAR_SET_VALUE;
    1760         906 :                     n->name = "role";
    1761         906 :                     n->args = list_make1(makeStringConst($2, @2));
    1762         906 :                     n->location = @2;
    1763         906 :                     $$ = n;
    1764             :                 }
    1765             :             | SESSION AUTHORIZATION NonReservedWord_or_Sconst
    1766             :                 {
    1767        2544 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1768             : 
    1769        2544 :                     n->kind = VAR_SET_VALUE;
    1770        2544 :                     n->name = "session_authorization";
    1771        2544 :                     n->args = list_make1(makeStringConst($3, @3));
    1772        2544 :                     n->location = @3;
    1773        2544 :                     $$ = n;
    1774             :                 }
    1775             :             | SESSION AUTHORIZATION DEFAULT
    1776             :                 {
    1777           4 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1778             : 
    1779           4 :                     n->kind = VAR_SET_DEFAULT;
    1780           4 :                     n->name = "session_authorization";
    1781           4 :                     n->location = -1;
    1782           4 :                     $$ = n;
    1783             :                 }
    1784             :             | XML_P OPTION document_or_content
    1785             :                 {
    1786          16 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1787             : 
    1788          16 :                     n->kind = VAR_SET_VALUE;
    1789          16 :                     n->name = "xmloption";
    1790          16 :                     n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
    1791          16 :                     n->jumble_args = true;
    1792          16 :                     n->location = -1;
    1793          16 :                     $$ = n;
    1794             :                 }
    1795             :             /* Special syntaxes invented by PostgreSQL: */
    1796             :             | TRANSACTION SNAPSHOT Sconst
    1797             :                 {
    1798          44 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1799             : 
    1800          44 :                     n->kind = VAR_SET_MULTI;
    1801          44 :                     n->name = "TRANSACTION SNAPSHOT";
    1802          44 :                     n->args = list_make1(makeStringConst($3, @3));
    1803          44 :                     n->location = @3;
    1804          44 :                     $$ = n;
    1805             :                 }
    1806             :         ;
    1807             : 
    1808       22004 : var_name:   ColId                               { $$ = $1; }
    1809             :             | var_name '.' ColId
    1810         458 :                 { $$ = psprintf("%s.%s", $1, $3); }
    1811             :         ;
    1812             : 
    1813       17536 : var_list:   var_value                               { $$ = list_make1($1); }
    1814         166 :             | var_list ',' var_value                { $$ = lappend($1, $3); }
    1815             :         ;
    1816             : 
    1817             : var_value:  opt_boolean_or_string
    1818       13272 :                 { $$ = makeStringConst($1, @1); }
    1819             :             | NumericOnly
    1820        4430 :                 { $$ = makeAConst($1, @1); }
    1821             :         ;
    1822             : 
    1823           0 : iso_level:  READ UNCOMMITTED                        { $$ = "read uncommitted"; }
    1824         908 :             | READ COMMITTED                        { $$ = "read committed"; }
    1825        2486 :             | REPEATABLE READ                       { $$ = "repeatable read"; }
    1826        3196 :             | SERIALIZABLE                          { $$ = "serializable"; }
    1827             :         ;
    1828             : 
    1829             : opt_boolean_or_string:
    1830         580 :             TRUE_P                                  { $$ = "true"; }
    1831        1294 :             | FALSE_P                               { $$ = "false"; }
    1832        2080 :             | ON                                    { $$ = "on"; }
    1833             :             /*
    1834             :              * OFF is also accepted as a boolean value, but is handled by
    1835             :              * the NonReservedWord rule.  The action for booleans and strings
    1836             :              * is the same, so we don't need to distinguish them here.
    1837             :              */
    1838       27656 :             | NonReservedWord_or_Sconst             { $$ = $1; }
    1839             :         ;
    1840             : 
    1841             : /* Timezone values can be:
    1842             :  * - a string such as 'pst8pdt'
    1843             :  * - an identifier such as "pst8pdt"
    1844             :  * - an integer or floating point number
    1845             :  * - a time interval per SQL99
    1846             :  * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
    1847             :  * so use IDENT (meaning we reject anything that is a key word).
    1848             :  */
    1849             : zone_value:
    1850             :             Sconst
    1851             :                 {
    1852          60 :                     $$ = makeStringConst($1, @1);
    1853             :                 }
    1854             :             | IDENT
    1855             :                 {
    1856           4 :                     $$ = makeStringConst($1, @1);
    1857             :                 }
    1858             :             | ConstInterval Sconst opt_interval
    1859             :                 {
    1860           0 :                     TypeName   *t = $1;
    1861             : 
    1862           0 :                     if ($3 != NIL)
    1863             :                     {
    1864           0 :                         A_Const    *n = (A_Const *) linitial($3);
    1865             : 
    1866           0 :                         if ((n->val.ival.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
    1867           0 :                             ereport(ERROR,
    1868             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    1869             :                                      errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
    1870             :                                      parser_errposition(@3)));
    1871             :                     }
    1872           0 :                     t->typmods = $3;
    1873           0 :                     $$ = makeStringConstCast($2, @2, t);
    1874             :                 }
    1875             :             | ConstInterval '(' Iconst ')' Sconst
    1876             :                 {
    1877           0 :                     TypeName   *t = $1;
    1878             : 
    1879           0 :                     t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
    1880             :                                             makeIntConst($3, @3));
    1881           0 :                     $$ = makeStringConstCast($5, @5, t);
    1882             :                 }
    1883          24 :             | NumericOnly                           { $$ = makeAConst($1, @1); }
    1884          14 :             | DEFAULT                               { $$ = NULL; }
    1885           2 :             | LOCAL                                 { $$ = NULL; }
    1886             :         ;
    1887             : 
    1888             : opt_encoding:
    1889           0 :             Sconst                                  { $$ = $1; }
    1890           0 :             | DEFAULT                               { $$ = NULL; }
    1891           0 :             | /*EMPTY*/                             { $$ = NULL; }
    1892             :         ;
    1893             : 
    1894             : NonReservedWord_or_Sconst:
    1895       48710 :             NonReservedWord                         { $$ = $1; }
    1896        5018 :             | Sconst                                { $$ = $1; }
    1897             :         ;
    1898             : 
    1899             : VariableResetStmt:
    1900        4232 :             RESET reset_rest                        { $$ = (Node *) $2; }
    1901             :         ;
    1902             : 
    1903             : reset_rest:
    1904        3452 :             generic_reset                           { $$ = $1; }
    1905             :             | TIME ZONE
    1906             :                 {
    1907          14 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1908             : 
    1909          14 :                     n->kind = VAR_RESET;
    1910          14 :                     n->name = "timezone";
    1911          14 :                     n->location = -1;
    1912          14 :                     $$ = n;
    1913             :                 }
    1914             :             | TRANSACTION ISOLATION LEVEL
    1915             :                 {
    1916           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1917             : 
    1918           0 :                     n->kind = VAR_RESET;
    1919           0 :                     n->name = "transaction_isolation";
    1920           0 :                     n->location = -1;
    1921           0 :                     $$ = n;
    1922             :                 }
    1923             :             | SESSION AUTHORIZATION
    1924             :                 {
    1925         766 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1926             : 
    1927         766 :                     n->kind = VAR_RESET;
    1928         766 :                     n->name = "session_authorization";
    1929         766 :                     n->location = -1;
    1930         766 :                     $$ = n;
    1931             :                 }
    1932             :         ;
    1933             : 
    1934             : generic_reset:
    1935             :             var_name
    1936             :                 {
    1937        3488 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1938             : 
    1939        3488 :                     n->kind = VAR_RESET;
    1940        3488 :                     n->name = $1;
    1941        3488 :                     n->location = -1;
    1942        3488 :                     $$ = n;
    1943             :                 }
    1944             :             | ALL
    1945             :                 {
    1946          18 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1947             : 
    1948          18 :                     n->kind = VAR_RESET_ALL;
    1949          18 :                     n->location = -1;
    1950          18 :                     $$ = n;
    1951             :                 }
    1952             :         ;
    1953             : 
    1954             : /* SetResetClause allows SET or RESET without LOCAL */
    1955             : SetResetClause:
    1956        1176 :             SET set_rest                    { $$ = $2; }
    1957          44 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    1958             :         ;
    1959             : 
    1960             : /* SetResetClause allows SET or RESET without LOCAL */
    1961             : FunctionSetResetClause:
    1962         128 :             SET set_rest_more               { $$ = $2; }
    1963          12 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    1964             :         ;
    1965             : 
    1966             : 
    1967             : VariableShowStmt:
    1968             :             SHOW var_name
    1969             :                 {
    1970         830 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1971             : 
    1972         830 :                     n->name = $2;
    1973         830 :                     $$ = (Node *) n;
    1974             :                 }
    1975             :             | SHOW TIME ZONE
    1976             :                 {
    1977          10 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1978             : 
    1979          10 :                     n->name = "timezone";
    1980          10 :                     $$ = (Node *) n;
    1981             :                 }
    1982             :             | SHOW TRANSACTION ISOLATION LEVEL
    1983             :                 {
    1984           4 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1985             : 
    1986           4 :                     n->name = "transaction_isolation";
    1987           4 :                     $$ = (Node *) n;
    1988             :                 }
    1989             :             | SHOW SESSION AUTHORIZATION
    1990             :                 {
    1991           0 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1992             : 
    1993           0 :                     n->name = "session_authorization";
    1994           0 :                     $$ = (Node *) n;
    1995             :                 }
    1996             :             | SHOW ALL
    1997             :                 {
    1998           0 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1999             : 
    2000           0 :                     n->name = "all";
    2001           0 :                     $$ = (Node *) n;
    2002             :                 }
    2003             :         ;
    2004             : 
    2005             : 
    2006             : ConstraintsSetStmt:
    2007             :             SET CONSTRAINTS constraints_set_list constraints_set_mode
    2008             :                 {
    2009         104 :                     ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
    2010             : 
    2011         104 :                     n->constraints = $3;
    2012         104 :                     n->deferred = $4;
    2013         104 :                     $$ = (Node *) n;
    2014             :                 }
    2015             :         ;
    2016             : 
    2017             : constraints_set_list:
    2018          56 :             ALL                                     { $$ = NIL; }
    2019          48 :             | qualified_name_list                   { $$ = $1; }
    2020             :         ;
    2021             : 
    2022             : constraints_set_mode:
    2023          68 :             DEFERRED                                { $$ = true; }
    2024          36 :             | IMMEDIATE                             { $$ = false; }
    2025             :         ;
    2026             : 
    2027             : 
    2028             : /*
    2029             :  * Checkpoint statement
    2030             :  */
    2031             : CheckPointStmt:
    2032             :             CHECKPOINT
    2033             :                 {
    2034         204 :                     CheckPointStmt *n = makeNode(CheckPointStmt);
    2035             : 
    2036         204 :                     $$ = (Node *) n;
    2037             :                 }
    2038             :         ;
    2039             : 
    2040             : 
    2041             : /*****************************************************************************
    2042             :  *
    2043             :  * DISCARD { ALL | TEMP | PLANS | SEQUENCES }
    2044             :  *
    2045             :  *****************************************************************************/
    2046             : 
    2047             : DiscardStmt:
    2048             :             DISCARD ALL
    2049             :                 {
    2050           6 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2051             : 
    2052           6 :                     n->target = DISCARD_ALL;
    2053           6 :                     $$ = (Node *) n;
    2054             :                 }
    2055             :             | DISCARD TEMP
    2056             :                 {
    2057           8 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2058             : 
    2059           8 :                     n->target = DISCARD_TEMP;
    2060           8 :                     $$ = (Node *) n;
    2061             :                 }
    2062             :             | DISCARD TEMPORARY
    2063             :                 {
    2064           0 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2065             : 
    2066           0 :                     n->target = DISCARD_TEMP;
    2067           0 :                     $$ = (Node *) n;
    2068             :                 }
    2069             :             | DISCARD PLANS
    2070             :                 {
    2071           4 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2072             : 
    2073           4 :                     n->target = DISCARD_PLANS;
    2074           4 :                     $$ = (Node *) n;
    2075             :                 }
    2076             :             | DISCARD SEQUENCES
    2077             :                 {
    2078          12 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2079             : 
    2080          12 :                     n->target = DISCARD_SEQUENCES;
    2081          12 :                     $$ = (Node *) n;
    2082             :                 }
    2083             : 
    2084             :         ;
    2085             : 
    2086             : 
    2087             : /*****************************************************************************
    2088             :  *
    2089             :  *  ALTER [ TABLE | INDEX | SEQUENCE | VIEW | MATERIALIZED VIEW | FOREIGN TABLE ] variations
    2090             :  *
    2091             :  * Note: we accept all subcommands for each of the variants, and sort
    2092             :  * out what's really legal at execution time.
    2093             :  *****************************************************************************/
    2094             : 
    2095             : AlterTableStmt:
    2096             :             ALTER TABLE relation_expr alter_table_cmds
    2097             :                 {
    2098       23724 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2099             : 
    2100       23724 :                     n->relation = $3;
    2101       23724 :                     n->cmds = $4;
    2102       23724 :                     n->objtype = OBJECT_TABLE;
    2103       23724 :                     n->missing_ok = false;
    2104       23724 :                     $$ = (Node *) n;
    2105             :                 }
    2106             :         |   ALTER TABLE IF_P EXISTS relation_expr alter_table_cmds
    2107             :                 {
    2108          54 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2109             : 
    2110          54 :                     n->relation = $5;
    2111          54 :                     n->cmds = $6;
    2112          54 :                     n->objtype = OBJECT_TABLE;
    2113          54 :                     n->missing_ok = true;
    2114          54 :                     $$ = (Node *) n;
    2115             :                 }
    2116             :         |   ALTER TABLE relation_expr partition_cmd
    2117             :                 {
    2118        2830 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2119             : 
    2120        2830 :                     n->relation = $3;
    2121        2830 :                     n->cmds = list_make1($4);
    2122        2830 :                     n->objtype = OBJECT_TABLE;
    2123        2830 :                     n->missing_ok = false;
    2124        2830 :                     $$ = (Node *) n;
    2125             :                 }
    2126             :         |   ALTER TABLE IF_P EXISTS relation_expr partition_cmd
    2127             :                 {
    2128           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2129             : 
    2130           0 :                     n->relation = $5;
    2131           0 :                     n->cmds = list_make1($6);
    2132           0 :                     n->objtype = OBJECT_TABLE;
    2133           0 :                     n->missing_ok = true;
    2134           0 :                     $$ = (Node *) n;
    2135             :                 }
    2136             :         |   ALTER TABLE ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2137             :                 {
    2138             :                     AlterTableMoveAllStmt *n =
    2139          12 :                         makeNode(AlterTableMoveAllStmt);
    2140             : 
    2141          12 :                     n->orig_tablespacename = $6;
    2142          12 :                     n->objtype = OBJECT_TABLE;
    2143          12 :                     n->roles = NIL;
    2144          12 :                     n->new_tablespacename = $9;
    2145          12 :                     n->nowait = $10;
    2146          12 :                     $$ = (Node *) n;
    2147             :                 }
    2148             :         |   ALTER TABLE ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2149             :                 {
    2150             :                     AlterTableMoveAllStmt *n =
    2151           0 :                         makeNode(AlterTableMoveAllStmt);
    2152             : 
    2153           0 :                     n->orig_tablespacename = $6;
    2154           0 :                     n->objtype = OBJECT_TABLE;
    2155           0 :                     n->roles = $9;
    2156           0 :                     n->new_tablespacename = $12;
    2157           0 :                     n->nowait = $13;
    2158           0 :                     $$ = (Node *) n;
    2159             :                 }
    2160             :         |   ALTER INDEX qualified_name alter_table_cmds
    2161             :                 {
    2162         226 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2163             : 
    2164         226 :                     n->relation = $3;
    2165         226 :                     n->cmds = $4;
    2166         226 :                     n->objtype = OBJECT_INDEX;
    2167         226 :                     n->missing_ok = false;
    2168         226 :                     $$ = (Node *) n;
    2169             :                 }
    2170             :         |   ALTER INDEX IF_P EXISTS qualified_name alter_table_cmds
    2171             :                 {
    2172           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2173             : 
    2174           0 :                     n->relation = $5;
    2175           0 :                     n->cmds = $6;
    2176           0 :                     n->objtype = OBJECT_INDEX;
    2177           0 :                     n->missing_ok = true;
    2178           0 :                     $$ = (Node *) n;
    2179             :                 }
    2180             :         |   ALTER INDEX qualified_name index_partition_cmd
    2181             :                 {
    2182         398 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2183             : 
    2184         398 :                     n->relation = $3;
    2185         398 :                     n->cmds = list_make1($4);
    2186         398 :                     n->objtype = OBJECT_INDEX;
    2187         398 :                     n->missing_ok = false;
    2188         398 :                     $$ = (Node *) n;
    2189             :                 }
    2190             :         |   ALTER INDEX ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2191             :                 {
    2192             :                     AlterTableMoveAllStmt *n =
    2193           6 :                         makeNode(AlterTableMoveAllStmt);
    2194             : 
    2195           6 :                     n->orig_tablespacename = $6;
    2196           6 :                     n->objtype = OBJECT_INDEX;
    2197           6 :                     n->roles = NIL;
    2198           6 :                     n->new_tablespacename = $9;
    2199           6 :                     n->nowait = $10;
    2200           6 :                     $$ = (Node *) n;
    2201             :                 }
    2202             :         |   ALTER INDEX ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2203             :                 {
    2204             :                     AlterTableMoveAllStmt *n =
    2205           0 :                         makeNode(AlterTableMoveAllStmt);
    2206             : 
    2207           0 :                     n->orig_tablespacename = $6;
    2208           0 :                     n->objtype = OBJECT_INDEX;
    2209           0 :                     n->roles = $9;
    2210           0 :                     n->new_tablespacename = $12;
    2211           0 :                     n->nowait = $13;
    2212           0 :                     $$ = (Node *) n;
    2213             :                 }
    2214             :         |   ALTER SEQUENCE qualified_name alter_table_cmds
    2215             :                 {
    2216          76 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2217             : 
    2218          76 :                     n->relation = $3;
    2219          76 :                     n->cmds = $4;
    2220          76 :                     n->objtype = OBJECT_SEQUENCE;
    2221          76 :                     n->missing_ok = false;
    2222          76 :                     $$ = (Node *) n;
    2223             :                 }
    2224             :         |   ALTER SEQUENCE IF_P EXISTS qualified_name alter_table_cmds
    2225             :                 {
    2226           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2227             : 
    2228           0 :                     n->relation = $5;
    2229           0 :                     n->cmds = $6;
    2230           0 :                     n->objtype = OBJECT_SEQUENCE;
    2231           0 :                     n->missing_ok = true;
    2232           0 :                     $$ = (Node *) n;
    2233             :                 }
    2234             :         |   ALTER VIEW qualified_name alter_table_cmds
    2235             :                 {
    2236         242 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2237             : 
    2238         242 :                     n->relation = $3;
    2239         242 :                     n->cmds = $4;
    2240         242 :                     n->objtype = OBJECT_VIEW;
    2241         242 :                     n->missing_ok = false;
    2242         242 :                     $$ = (Node *) n;
    2243             :                 }
    2244             :         |   ALTER VIEW IF_P EXISTS qualified_name alter_table_cmds
    2245             :                 {
    2246           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2247             : 
    2248           0 :                     n->relation = $5;
    2249           0 :                     n->cmds = $6;
    2250           0 :                     n->objtype = OBJECT_VIEW;
    2251           0 :                     n->missing_ok = true;
    2252           0 :                     $$ = (Node *) n;
    2253             :                 }
    2254             :         |   ALTER MATERIALIZED VIEW qualified_name alter_table_cmds
    2255             :                 {
    2256          48 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2257             : 
    2258          48 :                     n->relation = $4;
    2259          48 :                     n->cmds = $5;
    2260          48 :                     n->objtype = OBJECT_MATVIEW;
    2261          48 :                     n->missing_ok = false;
    2262          48 :                     $$ = (Node *) n;
    2263             :                 }
    2264             :         |   ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name alter_table_cmds
    2265             :                 {
    2266           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2267             : 
    2268           0 :                     n->relation = $6;
    2269           0 :                     n->cmds = $7;
    2270           0 :                     n->objtype = OBJECT_MATVIEW;
    2271           0 :                     n->missing_ok = true;
    2272           0 :                     $$ = (Node *) n;
    2273             :                 }
    2274             :         |   ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2275             :                 {
    2276             :                     AlterTableMoveAllStmt *n =
    2277          12 :                         makeNode(AlterTableMoveAllStmt);
    2278             : 
    2279          12 :                     n->orig_tablespacename = $7;
    2280          12 :                     n->objtype = OBJECT_MATVIEW;
    2281          12 :                     n->roles = NIL;
    2282          12 :                     n->new_tablespacename = $10;
    2283          12 :                     n->nowait = $11;
    2284          12 :                     $$ = (Node *) n;
    2285             :                 }
    2286             :         |   ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2287             :                 {
    2288             :                     AlterTableMoveAllStmt *n =
    2289           0 :                         makeNode(AlterTableMoveAllStmt);
    2290             : 
    2291           0 :                     n->orig_tablespacename = $7;
    2292           0 :                     n->objtype = OBJECT_MATVIEW;
    2293           0 :                     n->roles = $10;
    2294           0 :                     n->new_tablespacename = $13;
    2295           0 :                     n->nowait = $14;
    2296           0 :                     $$ = (Node *) n;
    2297             :                 }
    2298             :         |   ALTER FOREIGN TABLE relation_expr alter_table_cmds
    2299             :                 {
    2300         374 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2301             : 
    2302         374 :                     n->relation = $4;
    2303         374 :                     n->cmds = $5;
    2304         374 :                     n->objtype = OBJECT_FOREIGN_TABLE;
    2305         374 :                     n->missing_ok = false;
    2306         374 :                     $$ = (Node *) n;
    2307             :                 }
    2308             :         |   ALTER FOREIGN TABLE IF_P EXISTS relation_expr alter_table_cmds
    2309             :                 {
    2310         108 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2311             : 
    2312         108 :                     n->relation = $6;
    2313         108 :                     n->cmds = $7;
    2314         108 :                     n->objtype = OBJECT_FOREIGN_TABLE;
    2315         108 :                     n->missing_ok = true;
    2316         108 :                     $$ = (Node *) n;
    2317             :                 }
    2318             :         ;
    2319             : 
    2320             : alter_table_cmds:
    2321       24852 :             alter_table_cmd                         { $$ = list_make1($1); }
    2322         942 :             | alter_table_cmds ',' alter_table_cmd  { $$ = lappend($1, $3); }
    2323             :         ;
    2324             : 
    2325             : partition_cmd:
    2326             :             /* ALTER TABLE <name> ATTACH PARTITION <table_name> FOR VALUES */
    2327             :             ATTACH PARTITION qualified_name PartitionBoundSpec
    2328             :                 {
    2329        2240 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2330        2240 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2331             : 
    2332        2240 :                     n->subtype = AT_AttachPartition;
    2333        2240 :                     cmd->name = $3;
    2334        2240 :                     cmd->bound = $4;
    2335        2240 :                     cmd->concurrent = false;
    2336        2240 :                     n->def = (Node *) cmd;
    2337             : 
    2338        2240 :                     $$ = (Node *) n;
    2339             :                 }
    2340             :             /* ALTER TABLE <name> DETACH PARTITION <partition_name> [CONCURRENTLY] */
    2341             :             | DETACH PARTITION qualified_name opt_concurrently
    2342             :                 {
    2343         570 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2344         570 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2345             : 
    2346         570 :                     n->subtype = AT_DetachPartition;
    2347         570 :                     cmd->name = $3;
    2348         570 :                     cmd->bound = NULL;
    2349         570 :                     cmd->concurrent = $4;
    2350         570 :                     n->def = (Node *) cmd;
    2351             : 
    2352         570 :                     $$ = (Node *) n;
    2353             :                 }
    2354             :             | DETACH PARTITION qualified_name FINALIZE
    2355             :                 {
    2356          20 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2357          20 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2358             : 
    2359          20 :                     n->subtype = AT_DetachPartitionFinalize;
    2360          20 :                     cmd->name = $3;
    2361          20 :                     cmd->bound = NULL;
    2362          20 :                     cmd->concurrent = false;
    2363          20 :                     n->def = (Node *) cmd;
    2364          20 :                     $$ = (Node *) n;
    2365             :                 }
    2366             :         ;
    2367             : 
    2368             : index_partition_cmd:
    2369             :             /* ALTER INDEX <name> ATTACH PARTITION <index_name> */
    2370             :             ATTACH PARTITION qualified_name
    2371             :                 {
    2372         398 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2373         398 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2374             : 
    2375         398 :                     n->subtype = AT_AttachPartition;
    2376         398 :                     cmd->name = $3;
    2377         398 :                     cmd->bound = NULL;
    2378         398 :                     cmd->concurrent = false;
    2379         398 :                     n->def = (Node *) cmd;
    2380             : 
    2381         398 :                     $$ = (Node *) n;
    2382             :                 }
    2383             :         ;
    2384             : 
    2385             : alter_table_cmd:
    2386             :             /* ALTER TABLE <name> ADD <coldef> */
    2387             :             ADD_P columnDef
    2388             :                 {
    2389         168 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2390             : 
    2391         168 :                     n->subtype = AT_AddColumn;
    2392         168 :                     n->def = $2;
    2393         168 :                     n->missing_ok = false;
    2394         168 :                     $$ = (Node *) n;
    2395             :                 }
    2396             :             /* ALTER TABLE <name> ADD IF NOT EXISTS <coldef> */
    2397             :             | ADD_P IF_P NOT EXISTS columnDef
    2398             :                 {
    2399           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2400             : 
    2401           0 :                     n->subtype = AT_AddColumn;
    2402           0 :                     n->def = $5;
    2403           0 :                     n->missing_ok = true;
    2404           0 :                     $$ = (Node *) n;
    2405             :                 }
    2406             :             /* ALTER TABLE <name> ADD COLUMN <coldef> */
    2407             :             | ADD_P COLUMN columnDef
    2408             :                 {
    2409        1746 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2410             : 
    2411        1746 :                     n->subtype = AT_AddColumn;
    2412        1746 :                     n->def = $3;
    2413        1746 :                     n->missing_ok = false;
    2414        1746 :                     $$ = (Node *) n;
    2415             :                 }
    2416             :             /* ALTER TABLE <name> ADD COLUMN IF NOT EXISTS <coldef> */
    2417             :             | ADD_P COLUMN IF_P NOT EXISTS columnDef
    2418             :                 {
    2419          60 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2420             : 
    2421          60 :                     n->subtype = AT_AddColumn;
    2422          60 :                     n->def = $6;
    2423          60 :                     n->missing_ok = true;
    2424          60 :                     $$ = (Node *) n;
    2425             :                 }
    2426             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
    2427             :             | ALTER opt_column ColId alter_column_default
    2428             :                 {
    2429         528 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2430             : 
    2431         528 :                     n->subtype = AT_ColumnDefault;
    2432         528 :                     n->name = $3;
    2433         528 :                     n->def = $4;
    2434         528 :                     $$ = (Node *) n;
    2435             :                 }
    2436             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
    2437             :             | ALTER opt_column ColId DROP NOT NULL_P
    2438             :                 {
    2439         282 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2440             : 
    2441         282 :                     n->subtype = AT_DropNotNull;
    2442         282 :                     n->name = $3;
    2443         282 :                     $$ = (Node *) n;
    2444             :                 }
    2445             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
    2446             :             | ALTER opt_column ColId SET NOT NULL_P
    2447             :                 {
    2448         404 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2449             : 
    2450         404 :                     n->subtype = AT_SetNotNull;
    2451         404 :                     n->name = $3;
    2452         404 :                     $$ = (Node *) n;
    2453             :                 }
    2454             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET EXPRESSION AS <expr> */
    2455             :             | ALTER opt_column ColId SET EXPRESSION AS '(' a_expr ')'
    2456             :                 {
    2457          66 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2458             : 
    2459          66 :                     n->subtype = AT_SetExpression;
    2460          66 :                     n->name = $3;
    2461          66 :                     n->def = $8;
    2462          66 :                     $$ = (Node *) n;
    2463             :                 }
    2464             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
    2465             :             | ALTER opt_column ColId DROP EXPRESSION
    2466             :                 {
    2467          32 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2468             : 
    2469          32 :                     n->subtype = AT_DropExpression;
    2470          32 :                     n->name = $3;
    2471          32 :                     $$ = (Node *) n;
    2472             :                 }
    2473             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION IF EXISTS */
    2474             :             | ALTER opt_column ColId DROP EXPRESSION IF_P EXISTS
    2475             :                 {
    2476           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2477             : 
    2478           6 :                     n->subtype = AT_DropExpression;
    2479           6 :                     n->name = $3;
    2480           6 :                     n->missing_ok = true;
    2481           6 :                     $$ = (Node *) n;
    2482             :                 }
    2483             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS */
    2484             :             | ALTER opt_column ColId SET STATISTICS set_statistics_value
    2485             :                 {
    2486          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2487             : 
    2488          62 :                     n->subtype = AT_SetStatistics;
    2489          62 :                     n->name = $3;
    2490          62 :                     n->def = $6;
    2491          62 :                     $$ = (Node *) n;
    2492             :                 }
    2493             :             /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS */
    2494             :             | ALTER opt_column Iconst SET STATISTICS set_statistics_value
    2495             :                 {
    2496          70 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2497             : 
    2498          70 :                     if ($3 <= 0 || $3 > PG_INT16_MAX)
    2499           6 :                         ereport(ERROR,
    2500             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
    2501             :                                  errmsg("column number must be in range from 1 to %d", PG_INT16_MAX),
    2502             :                                  parser_errposition(@3)));
    2503             : 
    2504          64 :                     n->subtype = AT_SetStatistics;
    2505          64 :                     n->num = (int16) $3;
    2506          64 :                     n->def = $6;
    2507          64 :                     $$ = (Node *) n;
    2508             :                 }
    2509             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
    2510             :             | ALTER opt_column ColId SET reloptions
    2511             :                 {
    2512          38 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2513             : 
    2514          38 :                     n->subtype = AT_SetOptions;
    2515          38 :                     n->name = $3;
    2516          38 :                     n->def = (Node *) $5;
    2517          38 :                     $$ = (Node *) n;
    2518             :                 }
    2519             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> RESET ( column_parameter [, ... ] ) */
    2520             :             | ALTER opt_column ColId RESET reloptions
    2521             :                 {
    2522           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2523             : 
    2524           6 :                     n->subtype = AT_ResetOptions;
    2525           6 :                     n->name = $3;
    2526           6 :                     n->def = (Node *) $5;
    2527           6 :                     $$ = (Node *) n;
    2528             :                 }
    2529             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
    2530             :             | ALTER opt_column ColId SET column_storage
    2531             :                 {
    2532         212 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2533             : 
    2534         212 :                     n->subtype = AT_SetStorage;
    2535         212 :                     n->name = $3;
    2536         212 :                     n->def = (Node *) makeString($5);
    2537         212 :                     $$ = (Node *) n;
    2538             :                 }
    2539             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET COMPRESSION <cm> */
    2540             :             | ALTER opt_column ColId SET column_compression
    2541             :                 {
    2542          68 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2543             : 
    2544          68 :                     n->subtype = AT_SetCompression;
    2545          68 :                     n->name = $3;
    2546          68 :                     n->def = (Node *) makeString($5);
    2547          68 :                     $$ = (Node *) n;
    2548             :                 }
    2549             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> ADD GENERATED ... AS IDENTITY ... */
    2550             :             | ALTER opt_column ColId ADD_P GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    2551             :                 {
    2552         166 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2553         166 :                     Constraint *c = makeNode(Constraint);
    2554             : 
    2555         166 :                     c->contype = CONSTR_IDENTITY;
    2556         166 :                     c->generated_when = $6;
    2557         166 :                     c->options = $9;
    2558         166 :                     c->location = @5;
    2559             : 
    2560         166 :                     n->subtype = AT_AddIdentity;
    2561         166 :                     n->name = $3;
    2562         166 :                     n->def = (Node *) c;
    2563             : 
    2564         166 :                     $$ = (Node *) n;
    2565             :                 }
    2566             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET <sequence options>/RESET */
    2567             :             | ALTER opt_column ColId alter_identity_column_option_list
    2568             :                 {
    2569          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2570             : 
    2571          62 :                     n->subtype = AT_SetIdentity;
    2572          62 :                     n->name = $3;
    2573          62 :                     n->def = (Node *) $4;
    2574          62 :                     $$ = (Node *) n;
    2575             :                 }
    2576             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY */
    2577             :             | ALTER opt_column ColId DROP IDENTITY_P
    2578             :                 {
    2579          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2580             : 
    2581          50 :                     n->subtype = AT_DropIdentity;
    2582          50 :                     n->name = $3;
    2583          50 :                     n->missing_ok = false;
    2584          50 :                     $$ = (Node *) n;
    2585             :                 }
    2586             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY IF EXISTS */
    2587             :             | ALTER opt_column ColId DROP IDENTITY_P IF_P EXISTS
    2588             :                 {
    2589           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2590             : 
    2591           6 :                     n->subtype = AT_DropIdentity;
    2592           6 :                     n->name = $3;
    2593           6 :                     n->missing_ok = true;
    2594           6 :                     $$ = (Node *) n;
    2595             :                 }
    2596             :             /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
    2597             :             | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
    2598             :                 {
    2599          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2600             : 
    2601          18 :                     n->subtype = AT_DropColumn;
    2602          18 :                     n->name = $5;
    2603          18 :                     n->behavior = $6;
    2604          18 :                     n->missing_ok = true;
    2605          18 :                     $$ = (Node *) n;
    2606             :                 }
    2607             :             /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
    2608             :             | DROP opt_column ColId opt_drop_behavior
    2609             :                 {
    2610        1528 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2611             : 
    2612        1528 :                     n->subtype = AT_DropColumn;
    2613        1528 :                     n->name = $3;
    2614        1528 :                     n->behavior = $4;
    2615        1528 :                     n->missing_ok = false;
    2616        1528 :                     $$ = (Node *) n;
    2617             :                 }
    2618             :             /*
    2619             :              * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
    2620             :              *      [ USING <expression> ]
    2621             :              */
    2622             :             | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using
    2623             :                 {
    2624         874 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2625         874 :                     ColumnDef *def = makeNode(ColumnDef);
    2626             : 
    2627         874 :                     n->subtype = AT_AlterColumnType;
    2628         874 :                     n->name = $3;
    2629         874 :                     n->def = (Node *) def;
    2630             :                     /* We only use these fields of the ColumnDef node */
    2631         874 :                     def->typeName = $6;
    2632         874 :                     def->collClause = (CollateClause *) $7;
    2633         874 :                     def->raw_default = $8;
    2634         874 :                     def->location = @3;
    2635         874 :                     $$ = (Node *) n;
    2636             :                 }
    2637             :             /* ALTER FOREIGN TABLE <name> ALTER [COLUMN] <colname> OPTIONS */
    2638             :             | ALTER opt_column ColId alter_generic_options
    2639             :                 {
    2640          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2641             : 
    2642          50 :                     n->subtype = AT_AlterColumnGenericOptions;
    2643          50 :                     n->name = $3;
    2644          50 :                     n->def = (Node *) $4;
    2645          50 :                     $$ = (Node *) n;
    2646             :                 }
    2647             :             /* ALTER TABLE <name> ADD CONSTRAINT ... */
    2648             :             | ADD_P TableConstraint
    2649             :                 {
    2650       13094 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2651             : 
    2652       13094 :                     n->subtype = AT_AddConstraint;
    2653       13094 :                     n->def = $2;
    2654       13094 :                     $$ = (Node *) n;
    2655             :                 }
    2656             :             /* ALTER TABLE <name> ALTER CONSTRAINT ... */
    2657             :             | ALTER CONSTRAINT name ConstraintAttributeSpec
    2658             :                 {
    2659         144 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2660         144 :                     Constraint *c = makeNode(Constraint);
    2661             : 
    2662         144 :                     n->subtype = AT_AlterConstraint;
    2663         144 :                     n->def = (Node *) c;
    2664         144 :                     c->contype = CONSTR_FOREIGN; /* others not supported, yet */
    2665         144 :                     c->conname = $3;
    2666         144 :                     processCASbits($4, @4, "ALTER CONSTRAINT statement",
    2667             :                                     &c->deferrable,
    2668             :                                     &c->initdeferred,
    2669             :                                     NULL, NULL, NULL, yyscanner);
    2670         132 :                     $$ = (Node *) n;
    2671             :                 }
    2672             :             /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
    2673             :             | VALIDATE CONSTRAINT name
    2674             :                 {
    2675         394 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2676             : 
    2677         394 :                     n->subtype = AT_ValidateConstraint;
    2678         394 :                     n->name = $3;
    2679         394 :                     $$ = (Node *) n;
    2680             :                 }
    2681             :             /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
    2682             :             | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
    2683             :                 {
    2684          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2685             : 
    2686          18 :                     n->subtype = AT_DropConstraint;
    2687          18 :                     n->name = $5;
    2688          18 :                     n->behavior = $6;
    2689          18 :                     n->missing_ok = true;
    2690          18 :                     $$ = (Node *) n;
    2691             :                 }
    2692             :             /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
    2693             :             | DROP CONSTRAINT name opt_drop_behavior
    2694             :                 {
    2695         822 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2696             : 
    2697         822 :                     n->subtype = AT_DropConstraint;
    2698         822 :                     n->name = $3;
    2699         822 :                     n->behavior = $4;
    2700         822 :                     n->missing_ok = false;
    2701         822 :                     $$ = (Node *) n;
    2702             :                 }
    2703             :             /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat */
    2704             :             | SET WITHOUT OIDS
    2705             :                 {
    2706           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2707             : 
    2708           6 :                     n->subtype = AT_DropOids;
    2709           6 :                     $$ = (Node *) n;
    2710             :                 }
    2711             :             /* ALTER TABLE <name> CLUSTER ON <indexname> */
    2712             :             | CLUSTER ON name
    2713             :                 {
    2714          46 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2715             : 
    2716          46 :                     n->subtype = AT_ClusterOn;
    2717          46 :                     n->name = $3;
    2718          46 :                     $$ = (Node *) n;
    2719             :                 }
    2720             :             /* ALTER TABLE <name> SET WITHOUT CLUSTER */
    2721             :             | SET WITHOUT CLUSTER
    2722             :                 {
    2723          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2724             : 
    2725          18 :                     n->subtype = AT_DropCluster;
    2726          18 :                     n->name = NULL;
    2727          18 :                     $$ = (Node *) n;
    2728             :                 }
    2729             :             /* ALTER TABLE <name> SET LOGGED */
    2730             :             | SET LOGGED
    2731             :                 {
    2732          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2733             : 
    2734          50 :                     n->subtype = AT_SetLogged;
    2735          50 :                     $$ = (Node *) n;
    2736             :                 }
    2737             :             /* ALTER TABLE <name> SET UNLOGGED */
    2738             :             | SET UNLOGGED
    2739             :                 {
    2740          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2741             : 
    2742          62 :                     n->subtype = AT_SetUnLogged;
    2743          62 :                     $$ = (Node *) n;
    2744             :                 }
    2745             :             /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
    2746             :             | ENABLE_P TRIGGER name
    2747             :                 {
    2748         122 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2749             : 
    2750         122 :                     n->subtype = AT_EnableTrig;
    2751         122 :                     n->name = $3;
    2752         122 :                     $$ = (Node *) n;
    2753             :                 }
    2754             :             /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
    2755             :             | ENABLE_P ALWAYS TRIGGER name
    2756             :                 {
    2757          40 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2758             : 
    2759          40 :                     n->subtype = AT_EnableAlwaysTrig;
    2760          40 :                     n->name = $4;
    2761          40 :                     $$ = (Node *) n;
    2762             :                 }
    2763             :             /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
    2764             :             | ENABLE_P REPLICA TRIGGER name
    2765             :                 {
    2766          16 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2767             : 
    2768          16 :                     n->subtype = AT_EnableReplicaTrig;
    2769          16 :                     n->name = $4;
    2770          16 :                     $$ = (Node *) n;
    2771             :                 }
    2772             :             /* ALTER TABLE <name> ENABLE TRIGGER ALL */
    2773             :             | ENABLE_P TRIGGER ALL
    2774             :                 {
    2775           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2776             : 
    2777           0 :                     n->subtype = AT_EnableTrigAll;
    2778           0 :                     $$ = (Node *) n;
    2779             :                 }
    2780             :             /* ALTER TABLE <name> ENABLE TRIGGER USER */
    2781             :             | ENABLE_P TRIGGER USER
    2782             :                 {
    2783           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2784             : 
    2785           0 :                     n->subtype = AT_EnableTrigUser;
    2786           0 :                     $$ = (Node *) n;
    2787             :                 }
    2788             :             /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
    2789             :             | DISABLE_P TRIGGER name
    2790             :                 {
    2791         138 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2792             : 
    2793         138 :                     n->subtype = AT_DisableTrig;
    2794         138 :                     n->name = $3;
    2795         138 :                     $$ = (Node *) n;
    2796             :                 }
    2797             :             /* ALTER TABLE <name> DISABLE TRIGGER ALL */
    2798             :             | DISABLE_P TRIGGER ALL
    2799             :                 {
    2800          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2801             : 
    2802          12 :                     n->subtype = AT_DisableTrigAll;
    2803          12 :                     $$ = (Node *) n;
    2804             :                 }
    2805             :             /* ALTER TABLE <name> DISABLE TRIGGER USER */
    2806             :             | DISABLE_P TRIGGER USER
    2807             :                 {
    2808          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2809             : 
    2810          12 :                     n->subtype = AT_DisableTrigUser;
    2811          12 :                     $$ = (Node *) n;
    2812             :                 }
    2813             :             /* ALTER TABLE <name> ENABLE RULE <rule> */
    2814             :             | ENABLE_P RULE name
    2815             :                 {
    2816           8 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2817             : 
    2818           8 :                     n->subtype = AT_EnableRule;
    2819           8 :                     n->name = $3;
    2820           8 :                     $$ = (Node *) n;
    2821             :                 }
    2822             :             /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
    2823             :             | ENABLE_P ALWAYS RULE name
    2824             :                 {
    2825           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2826             : 
    2827           0 :                     n->subtype = AT_EnableAlwaysRule;
    2828           0 :                     n->name = $4;
    2829           0 :                     $$ = (Node *) n;
    2830             :                 }
    2831             :             /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
    2832             :             | ENABLE_P REPLICA RULE name
    2833             :                 {
    2834           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2835             : 
    2836           6 :                     n->subtype = AT_EnableReplicaRule;
    2837           6 :                     n->name = $4;
    2838           6 :                     $$ = (Node *) n;
    2839             :                 }
    2840             :             /* ALTER TABLE <name> DISABLE RULE <rule> */
    2841             :             | DISABLE_P RULE name
    2842             :                 {
    2843          32 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2844             : 
    2845          32 :                     n->subtype = AT_DisableRule;
    2846          32 :                     n->name = $3;
    2847          32 :                     $$ = (Node *) n;
    2848             :                 }
    2849             :             /* ALTER TABLE <name> INHERIT <parent> */
    2850             :             | INHERIT qualified_name
    2851             :                 {
    2852         346 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2853             : 
    2854         346 :                     n->subtype = AT_AddInherit;
    2855         346 :                     n->def = (Node *) $2;
    2856         346 :                     $$ = (Node *) n;
    2857             :                 }
    2858             :             /* ALTER TABLE <name> NO INHERIT <parent> */
    2859             :             | NO INHERIT qualified_name
    2860             :                 {
    2861          86 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2862             : 
    2863          86 :                     n->subtype = AT_DropInherit;
    2864          86 :                     n->def = (Node *) $3;
    2865          86 :                     $$ = (Node *) n;
    2866             :                 }
    2867             :             /* ALTER TABLE <name> OF <type_name> */
    2868             :             | OF any_name
    2869             :                 {
    2870          66 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2871          66 :                     TypeName   *def = makeTypeNameFromNameList($2);
    2872             : 
    2873          66 :                     def->location = @2;
    2874          66 :                     n->subtype = AT_AddOf;
    2875          66 :                     n->def = (Node *) def;
    2876          66 :                     $$ = (Node *) n;
    2877             :                 }
    2878             :             /* ALTER TABLE <name> NOT OF */
    2879             :             | NOT OF
    2880             :                 {
    2881           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2882             : 
    2883           6 :                     n->subtype = AT_DropOf;
    2884           6 :                     $$ = (Node *) n;
    2885             :                 }
    2886             :             /* ALTER TABLE <name> OWNER TO RoleSpec */
    2887             :             | OWNER TO RoleSpec
    2888             :                 {
    2889        1820 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2890             : 
    2891        1820 :                     n->subtype = AT_ChangeOwner;
    2892        1820 :                     n->newowner = $3;
    2893        1820 :                     $$ = (Node *) n;
    2894             :                 }
    2895             :             /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
    2896             :             | SET ACCESS METHOD set_access_method_name
    2897             :                 {
    2898         128 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2899             : 
    2900         128 :                     n->subtype = AT_SetAccessMethod;
    2901         128 :                     n->name = $4;
    2902         128 :                     $$ = (Node *) n;
    2903             :                 }
    2904             :             /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
    2905             :             | SET TABLESPACE name
    2906             :                 {
    2907         104 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2908             : 
    2909         104 :                     n->subtype = AT_SetTableSpace;
    2910         104 :                     n->name = $3;
    2911         104 :                     $$ = (Node *) n;
    2912             :                 }
    2913             :             /* ALTER TABLE <name> SET (...) */
    2914             :             | SET reloptions
    2915             :                 {
    2916         588 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2917             : 
    2918         588 :                     n->subtype = AT_SetRelOptions;
    2919         588 :                     n->def = (Node *) $2;
    2920         588 :                     $$ = (Node *) n;
    2921             :                 }
    2922             :             /* ALTER TABLE <name> RESET (...) */
    2923             :             | RESET reloptions
    2924             :                 {
    2925         164 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2926             : 
    2927         164 :                     n->subtype = AT_ResetRelOptions;
    2928         164 :                     n->def = (Node *) $2;
    2929         164 :                     $$ = (Node *) n;
    2930             :                 }
    2931             :             /* ALTER TABLE <name> REPLICA IDENTITY */
    2932             :             | REPLICA IDENTITY_P replica_identity
    2933             :                 {
    2934         484 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2935             : 
    2936         484 :                     n->subtype = AT_ReplicaIdentity;
    2937         484 :                     n->def = $3;
    2938         484 :                     $$ = (Node *) n;
    2939             :                 }
    2940             :             /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
    2941             :             | ENABLE_P ROW LEVEL SECURITY
    2942             :                 {
    2943         284 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2944             : 
    2945         284 :                     n->subtype = AT_EnableRowSecurity;
    2946         284 :                     $$ = (Node *) n;
    2947             :                 }
    2948             :             /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
    2949             :             | DISABLE_P ROW LEVEL SECURITY
    2950             :                 {
    2951          10 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2952             : 
    2953          10 :                     n->subtype = AT_DisableRowSecurity;
    2954          10 :                     $$ = (Node *) n;
    2955             :                 }
    2956             :             /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
    2957             :             | FORCE ROW LEVEL SECURITY
    2958             :                 {
    2959          88 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2960             : 
    2961          88 :                     n->subtype = AT_ForceRowSecurity;
    2962          88 :                     $$ = (Node *) n;
    2963             :                 }
    2964             :             /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
    2965             :             | NO FORCE ROW LEVEL SECURITY
    2966             :                 {
    2967          32 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2968             : 
    2969          32 :                     n->subtype = AT_NoForceRowSecurity;
    2970          32 :                     $$ = (Node *) n;
    2971             :                 }
    2972             :             | alter_generic_options
    2973             :                 {
    2974          64 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2975             : 
    2976          64 :                     n->subtype = AT_GenericOptions;
    2977          64 :                     n->def = (Node *) $1;
    2978          64 :                     $$ = (Node *) n;
    2979             :                 }
    2980             :         ;
    2981             : 
    2982             : alter_column_default:
    2983         362 :             SET DEFAULT a_expr          { $$ = $3; }
    2984         180 :             | DROP DEFAULT              { $$ = NULL; }
    2985             :         ;
    2986             : 
    2987             : opt_collate_clause:
    2988             :             COLLATE any_name
    2989             :                 {
    2990          18 :                     CollateClause *n = makeNode(CollateClause);
    2991             : 
    2992          18 :                     n->arg = NULL;
    2993          18 :                     n->collname = $2;
    2994          18 :                     n->location = @1;
    2995          18 :                     $$ = (Node *) n;
    2996             :                 }
    2997        4496 :             | /* EMPTY */               { $$ = NULL; }
    2998             :         ;
    2999             : 
    3000             : alter_using:
    3001         168 :             USING a_expr                { $$ = $2; }
    3002         706 :             | /* EMPTY */               { $$ = NULL; }
    3003             :         ;
    3004             : 
    3005             : replica_identity:
    3006             :             NOTHING
    3007             :                 {
    3008          48 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3009             : 
    3010          48 :                     n->identity_type = REPLICA_IDENTITY_NOTHING;
    3011          48 :                     n->name = NULL;
    3012          48 :                     $$ = (Node *) n;
    3013             :                 }
    3014             :             | FULL
    3015             :                 {
    3016         160 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3017             : 
    3018         160 :                     n->identity_type = REPLICA_IDENTITY_FULL;
    3019         160 :                     n->name = NULL;
    3020         160 :                     $$ = (Node *) n;
    3021             :                 }
    3022             :             | DEFAULT
    3023             :                 {
    3024           6 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3025             : 
    3026           6 :                     n->identity_type = REPLICA_IDENTITY_DEFAULT;
    3027           6 :                     n->name = NULL;
    3028           6 :                     $$ = (Node *) n;
    3029             :                 }
    3030             :             | USING INDEX name
    3031             :                 {
    3032         270 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3033             : 
    3034         270 :                     n->identity_type = REPLICA_IDENTITY_INDEX;
    3035         270 :                     n->name = $3;
    3036         270 :                     $$ = (Node *) n;
    3037             :                 }
    3038             : ;
    3039             : 
    3040             : reloptions:
    3041        2554 :             '(' reloption_list ')'                  { $$ = $2; }
    3042             :         ;
    3043             : 
    3044         934 : opt_reloptions:     WITH reloptions                 { $$ = $2; }
    3045       21370 :              |      /* EMPTY */                     { $$ = NIL; }
    3046             :         ;
    3047             : 
    3048             : reloption_list:
    3049        2554 :             reloption_elem                          { $$ = list_make1($1); }
    3050         220 :             | reloption_list ',' reloption_elem     { $$ = lappend($1, $3); }
    3051             :         ;
    3052             : 
    3053             : /* This should match def_elem and also allow qualified names */
    3054             : reloption_elem:
    3055             :             ColLabel '=' def_arg
    3056             :                 {
    3057        2158 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    3058             :                 }
    3059             :             | ColLabel
    3060             :                 {
    3061         548 :                     $$ = makeDefElem($1, NULL, @1);
    3062             :                 }
    3063             :             | ColLabel '.' ColLabel '=' def_arg
    3064             :                 {
    3065          62 :                     $$ = makeDefElemExtended($1, $3, (Node *) $5,
    3066          62 :                                              DEFELEM_UNSPEC, @1);
    3067             :                 }
    3068             :             | ColLabel '.' ColLabel
    3069             :                 {
    3070           6 :                     $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC, @1);
    3071             :                 }
    3072             :         ;
    3073             : 
    3074             : alter_identity_column_option_list:
    3075             :             alter_identity_column_option
    3076          62 :                 { $$ = list_make1($1); }
    3077             :             | alter_identity_column_option_list alter_identity_column_option
    3078          60 :                 { $$ = lappend($1, $2); }
    3079             :         ;
    3080             : 
    3081             : alter_identity_column_option:
    3082             :             RESTART
    3083             :                 {
    3084          24 :                     $$ = makeDefElem("restart", NULL, @1);
    3085             :                 }
    3086             :             | RESTART opt_with NumericOnly
    3087             :                 {
    3088           0 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    3089             :                 }
    3090             :             | SET SeqOptElem
    3091             :                 {
    3092          54 :                     if (strcmp($2->defname, "as") == 0 ||
    3093          54 :                         strcmp($2->defname, "restart") == 0 ||
    3094          54 :                         strcmp($2->defname, "owned_by") == 0)
    3095           0 :                         ereport(ERROR,
    3096             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3097             :                                  errmsg("sequence option \"%s\" not supported here", $2->defname),
    3098             :                                  parser_errposition(@2)));
    3099          54 :                     $$ = $2;
    3100             :                 }
    3101             :             | SET GENERATED generated_when
    3102             :                 {
    3103          44 :                     $$ = makeDefElem("generated", (Node *) makeInteger($3), @1);
    3104             :                 }
    3105             :         ;
    3106             : 
    3107             : set_statistics_value:
    3108         158 :             SignedIconst                    { $$ = (Node *) makeInteger($1); }
    3109           0 :             | DEFAULT                       { $$ = NULL; }
    3110             :         ;
    3111             : 
    3112             : set_access_method_name:
    3113          92 :             ColId                           { $$ = $1; }
    3114          36 :             | DEFAULT                       { $$ = NULL; }
    3115             :         ;
    3116             : 
    3117             : PartitionBoundSpec:
    3118             :             /* a HASH partition */
    3119             :             FOR VALUES WITH '(' hash_partbound ')'
    3120             :                 {
    3121             :                     ListCell   *lc;
    3122         704 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3123             : 
    3124         704 :                     n->strategy = PARTITION_STRATEGY_HASH;
    3125         704 :                     n->modulus = n->remainder = -1;
    3126             : 
    3127        2112 :                     foreach (lc, $5)
    3128             :                     {
    3129        1408 :                         DefElem    *opt = lfirst_node(DefElem, lc);
    3130             : 
    3131        1408 :                         if (strcmp(opt->defname, "modulus") == 0)
    3132             :                         {
    3133         704 :                             if (n->modulus != -1)
    3134           0 :                                 ereport(ERROR,
    3135             :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    3136             :                                          errmsg("modulus for hash partition provided more than once"),
    3137             :                                          parser_errposition(opt->location)));
    3138         704 :                             n->modulus = defGetInt32(opt);
    3139             :                         }
    3140         704 :                         else if (strcmp(opt->defname, "remainder") == 0)
    3141             :                         {
    3142         704 :                             if (n->remainder != -1)
    3143           0 :                                 ereport(ERROR,
    3144             :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    3145             :                                          errmsg("remainder for hash partition provided more than once"),
    3146             :                                          parser_errposition(opt->location)));
    3147         704 :                             n->remainder = defGetInt32(opt);
    3148             :                         }
    3149             :                         else
    3150           0 :                             ereport(ERROR,
    3151             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    3152             :                                      errmsg("unrecognized hash partition bound specification \"%s\"",
    3153             :                                             opt->defname),
    3154             :                                      parser_errposition(opt->location)));
    3155             :                     }
    3156             : 
    3157         704 :                     if (n->modulus == -1)
    3158           0 :                         ereport(ERROR,
    3159             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3160             :                                  errmsg("modulus for hash partition must be specified"),
    3161             :                                  parser_errposition(@3)));
    3162         704 :                     if (n->remainder == -1)
    3163           0 :                         ereport(ERROR,
    3164             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3165             :                                  errmsg("remainder for hash partition must be specified"),
    3166             :                                  parser_errposition(@3)));
    3167             : 
    3168         704 :                     n->location = @3;
    3169             : 
    3170         704 :                     $$ = n;
    3171             :                 }
    3172             : 
    3173             :             /* a LIST partition */
    3174             :             | FOR VALUES IN_P '(' expr_list ')'
    3175             :                 {
    3176        4802 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3177             : 
    3178        4802 :                     n->strategy = PARTITION_STRATEGY_LIST;
    3179        4802 :                     n->is_default = false;
    3180        4802 :                     n->listdatums = $5;
    3181        4802 :                     n->location = @3;
    3182             : 
    3183        4802 :                     $$ = n;
    3184             :                 }
    3185             : 
    3186             :             /* a RANGE partition */
    3187             :             | FOR VALUES FROM '(' expr_list ')' TO '(' expr_list ')'
    3188             :                 {
    3189        3946 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3190             : 
    3191        3946 :                     n->strategy = PARTITION_STRATEGY_RANGE;
    3192        3946 :                     n->is_default = false;
    3193        3946 :                     n->lowerdatums = $5;
    3194        3946 :                     n->upperdatums = $9;
    3195        3946 :                     n->location = @3;
    3196             : 
    3197        3946 :                     $$ = n;
    3198             :                 }
    3199             : 
    3200             :             /* a DEFAULT partition */
    3201             :             | DEFAULT
    3202             :                 {
    3203         590 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3204             : 
    3205         590 :                     n->is_default = true;
    3206         590 :                     n->location = @1;
    3207             : 
    3208         590 :                     $$ = n;
    3209             :                 }
    3210             :         ;
    3211             : 
    3212             : hash_partbound_elem:
    3213             :         NonReservedWord Iconst
    3214             :             {
    3215        1408 :                 $$ = makeDefElem($1, (Node *) makeInteger($2), @1);
    3216             :             }
    3217             :         ;
    3218             : 
    3219             : hash_partbound:
    3220             :         hash_partbound_elem
    3221             :             {
    3222         704 :                 $$ = list_make1($1);
    3223             :             }
    3224             :         | hash_partbound ',' hash_partbound_elem
    3225             :             {
    3226         704 :                 $$ = lappend($1, $3);
    3227             :             }
    3228             :         ;
    3229             : 
    3230             : /*****************************************************************************
    3231             :  *
    3232             :  *  ALTER TYPE
    3233             :  *
    3234             :  * really variants of the ALTER TABLE subcommands with different spellings
    3235             :  *****************************************************************************/
    3236             : 
    3237             : AlterCompositeTypeStmt:
    3238             :             ALTER TYPE_P any_name alter_type_cmds
    3239             :                 {
    3240         208 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    3241             : 
    3242             :                     /* can't use qualified_name, sigh */
    3243         208 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
    3244         208 :                     n->cmds = $4;
    3245         208 :                     n->objtype = OBJECT_TYPE;
    3246         208 :                     $$ = (Node *) n;
    3247             :                 }
    3248             :             ;
    3249             : 
    3250             : alter_type_cmds:
    3251         208 :             alter_type_cmd                          { $$ = list_make1($1); }
    3252          12 :             | alter_type_cmds ',' alter_type_cmd    { $$ = lappend($1, $3); }
    3253             :         ;
    3254             : 
    3255             : alter_type_cmd:
    3256             :             /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
    3257             :             ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
    3258             :                 {
    3259          64 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3260             : 
    3261          64 :                     n->subtype = AT_AddColumn;
    3262          64 :                     n->def = $3;
    3263          64 :                     n->behavior = $4;
    3264          64 :                     $$ = (Node *) n;
    3265             :                 }
    3266             :             /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
    3267             :             | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
    3268             :                 {
    3269           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3270             : 
    3271           6 :                     n->subtype = AT_DropColumn;
    3272           6 :                     n->name = $5;
    3273           6 :                     n->behavior = $6;
    3274           6 :                     n->missing_ok = true;
    3275           6 :                     $$ = (Node *) n;
    3276             :                 }
    3277             :             /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
    3278             :             | DROP ATTRIBUTE ColId opt_drop_behavior
    3279             :                 {
    3280          76 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3281             : 
    3282          76 :                     n->subtype = AT_DropColumn;
    3283          76 :                     n->name = $3;
    3284          76 :                     n->behavior = $4;
    3285          76 :                     n->missing_ok = false;
    3286          76 :                     $$ = (Node *) n;
    3287             :                 }
    3288             :             /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
    3289             :             | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
    3290             :                 {
    3291          74 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3292          74 :                     ColumnDef *def = makeNode(ColumnDef);
    3293             : 
    3294          74 :                     n->subtype = AT_AlterColumnType;
    3295          74 :                     n->name = $3;
    3296          74 :                     n->def = (Node *) def;
    3297          74 :                     n->behavior = $8;
    3298             :                     /* We only use these fields of the ColumnDef node */
    3299          74 :                     def->typeName = $6;
    3300          74 :                     def->collClause = (CollateClause *) $7;
    3301          74 :                     def->raw_default = NULL;
    3302          74 :                     def->location = @3;
    3303          74 :                     $$ = (Node *) n;
    3304             :                 }
    3305             :         ;
    3306             : 
    3307             : 
    3308             : /*****************************************************************************
    3309             :  *
    3310             :  *      QUERY :
    3311             :  *              close <portalname>
    3312             :  *
    3313             :  *****************************************************************************/
    3314             : 
    3315             : ClosePortalStmt:
    3316             :             CLOSE cursor_name
    3317             :                 {
    3318        2182 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3319             : 
    3320        2182 :                     n->portalname = $2;
    3321        2182 :                     $$ = (Node *) n;
    3322             :                 }
    3323             :             | CLOSE ALL
    3324             :                 {
    3325          12 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3326             : 
    3327          12 :                     n->portalname = NULL;
    3328          12 :                     $$ = (Node *) n;
    3329             :                 }
    3330             :         ;
    3331             : 
    3332             : 
    3333             : /*****************************************************************************
    3334             :  *
    3335             :  *      QUERY :
    3336             :  *              COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
    3337             :  *              COPY ( query ) TO file  [WITH] [(options)]
    3338             :  *
    3339             :  *              where 'query' can be one of:
    3340             :  *              { SELECT | UPDATE | INSERT | DELETE }
    3341             :  *
    3342             :  *              and 'file' can be one of:
    3343             :  *              { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
    3344             :  *
    3345             :  *              In the preferred syntax the options are comma-separated
    3346             :  *              and use generic identifiers instead of keywords.  The pre-9.0
    3347             :  *              syntax had a hard-wired, space-separated set of options.
    3348             :  *
    3349             :  *              Really old syntax, from versions 7.2 and prior:
    3350             :  *              COPY [ BINARY ] table FROM/TO file
    3351             :  *                  [ [ USING ] DELIMITERS 'delimiter' ] ]
    3352             :  *                  [ WITH NULL AS 'null string' ]
    3353             :  *              This option placement is not supported with COPY (query...).
    3354             :  *
    3355             :  *****************************************************************************/
    3356             : 
    3357             : CopyStmt:   COPY opt_binary qualified_name opt_column_list
    3358             :             copy_from opt_program copy_file_name copy_delimiter opt_with
    3359             :             copy_options where_clause
    3360             :                 {
    3361        9470 :                     CopyStmt *n = makeNode(CopyStmt);
    3362             : 
    3363        9470 :                     n->relation = $3;
    3364        9470 :                     n->query = NULL;
    3365        9470 :                     n->attlist = $4;
    3366        9470 :                     n->is_from = $5;
    3367        9470 :                     n->is_program = $6;
    3368        9470 :                     n->filename = $7;
    3369        9470 :                     n->whereClause = $11;
    3370             : 
    3371        9470 :                     if (n->is_program && n->filename == NULL)
    3372           0 :                         ereport(ERROR,
    3373             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3374             :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3375             :                                  parser_errposition(@8)));
    3376             : 
    3377        9470 :                     if (!n->is_from && n->whereClause != NULL)
    3378           6 :                         ereport(ERROR,
    3379             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3380             :                                  errmsg("WHERE clause not allowed with COPY TO"),
    3381             :                                  parser_errposition(@11)));
    3382             : 
    3383        9464 :                     n->options = NIL;
    3384             :                     /* Concatenate user-supplied flags */
    3385        9464 :                     if ($2)
    3386          12 :                         n->options = lappend(n->options, $2);
    3387        9464 :                     if ($8)
    3388           0 :                         n->options = lappend(n->options, $8);
    3389        9464 :                     if ($10)
    3390         902 :                         n->options = list_concat(n->options, $10);
    3391        9464 :                     $$ = (Node *) n;
    3392             :                 }
    3393             :             | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
    3394             :                 {
    3395         460 :                     CopyStmt *n = makeNode(CopyStmt);
    3396             : 
    3397         460 :                     updatePreparableStmtEnd($3, @4);
    3398         460 :                     n->relation = NULL;
    3399         460 :                     n->query = $3;
    3400         460 :                     n->attlist = NIL;
    3401         460 :                     n->is_from = false;
    3402         460 :                     n->is_program = $6;
    3403         460 :                     n->filename = $7;
    3404         460 :                     n->options = $9;
    3405             : 
    3406         460 :                     if (n->is_program && n->filename == NULL)
    3407           0 :                         ereport(ERROR,
    3408             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3409             :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3410             :                                  parser_errposition(@5)));
    3411             : 
    3412         460 :                     $$ = (Node *) n;
    3413             :                 }
    3414             :         ;
    3415             : 
    3416             : copy_from:
    3417        1660 :             FROM                                    { $$ = true; }
    3418        7810 :             | TO                                    { $$ = false; }
    3419             :         ;
    3420             : 
    3421             : opt_program:
    3422           0 :             PROGRAM                                 { $$ = true; }
    3423        9930 :             | /* EMPTY */                           { $$ = false; }
    3424             :         ;
    3425             : 
    3426             : /*
    3427             :  * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
    3428             :  * used depends on the direction. (It really doesn't make sense to copy from
    3429             :  * stdout. We silently correct the "typo".)        - AY 9/94
    3430             :  */
    3431             : copy_file_name:
    3432         442 :             Sconst                                  { $$ = $1; }
    3433        1282 :             | STDIN                                 { $$ = NULL; }
    3434        8206 :             | STDOUT                                { $$ = NULL; }
    3435             :         ;
    3436             : 
    3437        9298 : copy_options: copy_opt_list                         { $$ = $1; }
    3438         632 :             | '(' copy_generic_opt_list ')'         { $$ = $2; }
    3439             :         ;
    3440             : 
    3441             : /* old COPY option syntax */
    3442             : copy_opt_list:
    3443         504 :             copy_opt_list copy_opt_item             { $$ = lappend($1, $2); }
    3444        9298 :             | /* EMPTY */                           { $$ = NIL; }
    3445             :         ;
    3446             : 
    3447             : copy_opt_item:
    3448             :             BINARY
    3449             :                 {
    3450           0 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3451             :                 }
    3452             :             | FREEZE
    3453             :                 {
    3454          50 :                     $$ = makeDefElem("freeze", (Node *) makeBoolean(true), @1);
    3455             :                 }
    3456             :             | DELIMITER opt_as Sconst
    3457             :                 {
    3458         172 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @1);
    3459             :                 }
    3460             :             | NULL_P opt_as Sconst
    3461             :                 {
    3462          48 :                     $$ = makeDefElem("null", (Node *) makeString($3), @1);
    3463             :                 }
    3464             :             | CSV
    3465             :                 {
    3466         150 :                     $$ = makeDefElem("format", (Node *) makeString("csv"), @1);
    3467             :                 }
    3468             :             | HEADER_P
    3469             :                 {
    3470          18 :                     $$ = makeDefElem("header", (Node *) makeBoolean(true), @1);
    3471             :                 }
    3472             :             | QUOTE opt_as Sconst
    3473             :                 {
    3474          18 :                     $$ = makeDefElem("quote", (Node *) makeString($3), @1);
    3475             :                 }
    3476             :             | ESCAPE opt_as Sconst
    3477             :                 {
    3478          18 :                     $$ = makeDefElem("escape", (Node *) makeString($3), @1);
    3479             :                 }
    3480             :             | FORCE QUOTE columnList
    3481             :                 {
    3482          12 :                     $$ = makeDefElem("force_quote", (Node *) $3, @1);
    3483             :                 }
    3484             :             | FORCE QUOTE '*'
    3485             :                 {
    3486           6 :                     $$ = makeDefElem("force_quote", (Node *) makeNode(A_Star), @1);
    3487             :                 }
    3488             :             | FORCE NOT NULL_P columnList
    3489             :                 {
    3490           0 :                     $$ = makeDefElem("force_not_null", (Node *) $4, @1);
    3491             :                 }
    3492             :             | FORCE NOT NULL_P '*'
    3493             :                 {
    3494           0 :                     $$ = makeDefElem("force_not_null", (Node *) makeNode(A_Star), @1);
    3495             :                 }
    3496             :             | FORCE NULL_P columnList
    3497             :                 {
    3498           0 :                     $$ = makeDefElem("force_null", (Node *) $3, @1);
    3499             :                 }
    3500             :             | FORCE NULL_P '*'
    3501             :                 {
    3502           0 :                     $$ = makeDefElem("force_null", (Node *) makeNode(A_Star), @1);
    3503             :                 }
    3504             :             | ENCODING Sconst
    3505             :                 {
    3506          12 :                     $$ = makeDefElem("encoding", (Node *) makeString($2), @1);
    3507             :                 }
    3508             :         ;
    3509             : 
    3510             : /* The following exist for backward compatibility with very old versions */
    3511             : 
    3512             : opt_binary:
    3513             :             BINARY
    3514             :                 {
    3515          12 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3516             :                 }
    3517        9458 :             | /*EMPTY*/                             { $$ = NULL; }
    3518             :         ;
    3519             : 
    3520             : copy_delimiter:
    3521             :             opt_using DELIMITERS Sconst
    3522             :                 {
    3523           0 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @2);
    3524             :                 }
    3525        9470 :             | /*EMPTY*/                             { $$ = NULL; }
    3526             :         ;
    3527             : 
    3528             : opt_using:
    3529             :             USING
    3530             :             | /*EMPTY*/
    3531             :         ;
    3532             : 
    3533             : /* new COPY option syntax */
    3534             : copy_generic_opt_list:
    3535             :             copy_generic_opt_elem
    3536             :                 {
    3537         632 :                     $$ = list_make1($1);
    3538             :                 }
    3539             :             | copy_generic_opt_list ',' copy_generic_opt_elem
    3540             :                 {
    3541         450 :                     $$ = lappend($1, $3);
    3542             :                 }
    3543             :         ;
    3544             : 
    3545             : copy_generic_opt_elem:
    3546             :             ColLabel copy_generic_opt_arg
    3547             :                 {
    3548        1082 :                     $$ = makeDefElem($1, $2, @1);
    3549             :                 }
    3550             :         ;
    3551             : 
    3552             : copy_generic_opt_arg:
    3553         794 :             opt_boolean_or_string           { $$ = (Node *) makeString($1); }
    3554          24 :             | NumericOnly                   { $$ = (Node *) $1; }
    3555          90 :             | '*'                           { $$ = (Node *) makeNode(A_Star); }
    3556           6 :             | DEFAULT                       { $$ = (Node *) makeString("default"); }
    3557         150 :             | '(' copy_generic_opt_arg_list ')'     { $$ = (Node *) $2; }
    3558          18 :             | /* EMPTY */                   { $$ = NULL; }
    3559             :         ;
    3560             : 
    3561             : copy_generic_opt_arg_list:
    3562             :               copy_generic_opt_arg_list_item
    3563             :                 {
    3564         150 :                     $$ = list_make1($1);
    3565             :                 }
    3566             :             | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
    3567             :                 {
    3568          12 :                     $$ = lappend($1, $3);
    3569             :                 }
    3570             :         ;
    3571             : 
    3572             : /* beware of emitting non-string list elements here; see commands/define.c */
    3573             : copy_generic_opt_arg_list_item:
    3574         162 :             opt_boolean_or_string   { $$ = (Node *) makeString($1); }
    3575             :         ;
    3576             : 
    3577             : 
    3578             : /*****************************************************************************
    3579             :  *
    3580             :  *      QUERY :
    3581             :  *              CREATE TABLE relname
    3582             :  *
    3583             :  *****************************************************************************/
    3584             : 
    3585             : CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
    3586             :             OptInherit OptPartitionSpec table_access_method_clause OptWith
    3587             :             OnCommitOption OptTableSpace
    3588             :                 {
    3589       27638 :                     CreateStmt *n = makeNode(CreateStmt);
    3590             : 
    3591       27638 :                     $4->relpersistence = $2;
    3592       27638 :                     n->relation = $4;
    3593       27638 :                     n->tableElts = $6;
    3594       27638 :                     n->inhRelations = $8;
    3595       27638 :                     n->partspec = $9;
    3596       27638 :                     n->ofTypename = NULL;
    3597       27638 :                     n->constraints = NIL;
    3598       27638 :                     n->accessMethod = $10;
    3599       27638 :                     n->options = $11;
    3600       27638 :                     n->oncommit = $12;
    3601       27638 :                     n->tablespacename = $13;
    3602       27638 :                     n->if_not_exists = false;
    3603       27638 :                     $$ = (Node *) n;
    3604             :                 }
    3605             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
    3606             :             OptTableElementList ')' OptInherit OptPartitionSpec table_access_method_clause
    3607             :             OptWith OnCommitOption OptTableSpace
    3608             :                 {
    3609          30 :                     CreateStmt *n = makeNode(CreateStmt);
    3610             : 
    3611          30 :                     $7->relpersistence = $2;
    3612          30 :                     n->relation = $7;
    3613          30 :                     n->tableElts = $9;
    3614          30 :                     n->inhRelations = $11;
    3615          30 :                     n->partspec = $12;
    3616          30 :                     n->ofTypename = NULL;
    3617          30 :                     n->constraints = NIL;
    3618          30 :                     n->accessMethod = $13;
    3619          30 :                     n->options = $14;
    3620          30 :                     n->oncommit = $15;
    3621          30 :                     n->tablespacename = $16;
    3622          30 :                     n->if_not_exists = true;
    3623          30 :                     $$ = (Node *) n;
    3624             :                 }
    3625             :         | CREATE OptTemp TABLE qualified_name OF any_name
    3626             :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3627             :             OptWith OnCommitOption OptTableSpace
    3628             :                 {
    3629         116 :                     CreateStmt *n = makeNode(CreateStmt);
    3630             : 
    3631         116 :                     $4->relpersistence = $2;
    3632         116 :                     n->relation = $4;
    3633         116 :                     n->tableElts = $7;
    3634         116 :                     n->inhRelations = NIL;
    3635         116 :                     n->partspec = $8;
    3636         116 :                     n->ofTypename = makeTypeNameFromNameList($6);
    3637         116 :                     n->ofTypename->location = @6;
    3638         116 :                     n->constraints = NIL;
    3639         116 :                     n->accessMethod = $9;
    3640         116 :                     n->options = $10;
    3641         116 :                     n->oncommit = $11;
    3642         116 :                     n->tablespacename = $12;
    3643         116 :                     n->if_not_exists = false;
    3644         116 :                     $$ = (Node *) n;
    3645             :                 }
    3646             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
    3647             :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3648             :             OptWith OnCommitOption OptTableSpace
    3649             :                 {
    3650           6 :                     CreateStmt *n = makeNode(CreateStmt);
    3651             : 
    3652           6 :                     $7->relpersistence = $2;
    3653           6 :                     n->relation = $7;
    3654           6 :                     n->tableElts = $10;
    3655           6 :                     n->inhRelations = NIL;
    3656           6 :                     n->partspec = $11;
    3657           6 :                     n->ofTypename = makeTypeNameFromNameList($9);
    3658           6 :                     n->ofTypename->location = @9;
    3659           6 :                     n->constraints = NIL;
    3660           6 :                     n->accessMethod = $12;
    3661           6 :                     n->options = $13;
    3662           6 :                     n->oncommit = $14;
    3663           6 :                     n->tablespacename = $15;
    3664           6 :                     n->if_not_exists = true;
    3665           6 :                     $$ = (Node *) n;
    3666             :                 }
    3667             :         | CREATE OptTemp TABLE qualified_name PARTITION OF qualified_name
    3668             :             OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3669             :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3670             :                 {
    3671        7712 :                     CreateStmt *n = makeNode(CreateStmt);
    3672             : 
    3673        7712 :                     $4->relpersistence = $2;
    3674        7712 :                     n->relation = $4;
    3675        7712 :                     n->tableElts = $8;
    3676        7712 :                     n->inhRelations = list_make1($7);
    3677        7712 :                     n->partbound = $9;
    3678        7712 :                     n->partspec = $10;
    3679        7712 :                     n->ofTypename = NULL;
    3680        7712 :                     n->constraints = NIL;
    3681        7712 :                     n->accessMethod = $11;
    3682        7712 :                     n->options = $12;
    3683        7712 :                     n->oncommit = $13;
    3684        7712 :                     n->tablespacename = $14;
    3685        7712 :                     n->if_not_exists = false;
    3686        7712 :                     $$ = (Node *) n;
    3687             :                 }
    3688             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name PARTITION OF
    3689             :             qualified_name OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3690             :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3691             :                 {
    3692           0 :                     CreateStmt *n = makeNode(CreateStmt);
    3693             : 
    3694           0 :                     $7->relpersistence = $2;
    3695           0 :                     n->relation = $7;
    3696           0 :                     n->tableElts = $11;
    3697           0 :                     n->inhRelations = list_make1($10);
    3698           0 :                     n->partbound = $12;
    3699           0 :                     n->partspec = $13;
    3700           0 :                     n->ofTypename = NULL;
    3701           0 :                     n->constraints = NIL;
    3702           0 :                     n->accessMethod = $14;
    3703           0 :                     n->options = $15;
    3704           0 :                     n->oncommit = $16;
    3705           0 :                     n->tablespacename = $17;
    3706           0 :                     n->if_not_exists = true;
    3707           0 :                     $$ = (Node *) n;
    3708             :                 }
    3709             :         ;
    3710             : 
    3711             : /*
    3712             :  * Redundancy here is needed to avoid shift/reduce conflicts,
    3713             :  * since TEMP is not a reserved word.  See also OptTempTableName.
    3714             :  *
    3715             :  * NOTE: we accept both GLOBAL and LOCAL options.  They currently do nothing,
    3716             :  * but future versions might consider GLOBAL to request SQL-spec-compliant
    3717             :  * temp table behavior, so warn about that.  Since we have no modules the
    3718             :  * LOCAL keyword is really meaningless; furthermore, some other products
    3719             :  * implement LOCAL as meaning the same as our default temp table behavior,
    3720             :  * so we'll probably continue to treat LOCAL as a noise word.
    3721             :  */
    3722         306 : OptTemp:    TEMPORARY                   { $$ = RELPERSISTENCE_TEMP; }
    3723        2672 :             | TEMP                      { $$ = RELPERSISTENCE_TEMP; }
    3724           0 :             | LOCAL TEMPORARY           { $$ = RELPERSISTENCE_TEMP; }
    3725           0 :             | LOCAL TEMP                { $$ = RELPERSISTENCE_TEMP; }
    3726             :             | GLOBAL TEMPORARY
    3727             :                 {
    3728           0 :                     ereport(WARNING,
    3729             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3730             :                              parser_errposition(@1)));
    3731           0 :                     $$ = RELPERSISTENCE_TEMP;
    3732             :                 }
    3733             :             | GLOBAL TEMP
    3734             :                 {
    3735           0 :                     ereport(WARNING,
    3736             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3737             :                              parser_errposition(@1)));
    3738           0 :                     $$ = RELPERSISTENCE_TEMP;
    3739             :                 }
    3740         152 :             | UNLOGGED                  { $$ = RELPERSISTENCE_UNLOGGED; }
    3741       49604 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    3742             :         ;
    3743             : 
    3744             : OptTableElementList:
    3745       26604 :             TableElementList                    { $$ = $1; }
    3746        1478 :             | /*EMPTY*/                         { $$ = NIL; }
    3747             :         ;
    3748             : 
    3749             : OptTypedTableElementList:
    3750         306 :             '(' TypedTableElementList ')'       { $$ = $2; }
    3751        7624 :             | /*EMPTY*/                         { $$ = NIL; }
    3752             :         ;
    3753             : 
    3754             : TableElementList:
    3755             :             TableElement
    3756             :                 {
    3757       26652 :                     $$ = list_make1($1);
    3758             :                 }
    3759             :             | TableElementList ',' TableElement
    3760             :                 {
    3761       38310 :                     $$ = lappend($1, $3);
    3762             :                 }
    3763             :         ;
    3764             : 
    3765             : TypedTableElementList:
    3766             :             TypedTableElement
    3767             :                 {
    3768         306 :                     $$ = list_make1($1);
    3769             :                 }
    3770             :             | TypedTableElementList ',' TypedTableElement
    3771             :                 {
    3772          68 :                     $$ = lappend($1, $3);
    3773             :                 }
    3774             :         ;
    3775             : 
    3776             : TableElement:
    3777       61630 :             columnDef                           { $$ = $1; }
    3778         750 :             | TableLikeClause                   { $$ = $1; }
    3779        2582 :             | TableConstraint                   { $$ = $1; }
    3780             :         ;
    3781             : 
    3782             : TypedTableElement:
    3783         304 :             columnOptions                       { $$ = $1; }
    3784          70 :             | TableConstraint                   { $$ = $1; }
    3785             :         ;
    3786             : 
    3787             : columnDef:  ColId Typename opt_column_storage opt_column_compression create_generic_options ColQualList
    3788             :                 {
    3789       63604 :                     ColumnDef *n = makeNode(ColumnDef);
    3790             : 
    3791       63604 :                     n->colname = $1;
    3792       63604 :                     n->typeName = $2;
    3793       63604 :                     n->storage_name = $3;
    3794       63604 :                     n->compression = $4;
    3795       63604 :                     n->inhcount = 0;
    3796       63604 :                     n->is_local = true;
    3797       63604 :                     n->is_not_null = false;
    3798       63604 :                     n->is_from_type = false;
    3799       63604 :                     n->storage = 0;
    3800       63604 :                     n->raw_default = NULL;
    3801       63604 :                     n->cooked_default = NULL;
    3802       63604 :                     n->collOid = InvalidOid;
    3803       63604 :                     n->fdwoptions = $5;
    3804       63604 :                     SplitColQualList($6, &n->constraints, &n->collClause,
    3805             :                                      yyscanner);
    3806       63604 :                     n->location = @1;
    3807       63604 :                     $$ = (Node *) n;
    3808             :                 }
    3809             :         ;
    3810             : 
    3811             : columnOptions:  ColId ColQualList
    3812             :                 {
    3813         120 :                     ColumnDef *n = makeNode(ColumnDef);
    3814             : 
    3815         120 :                     n->colname = $1;
    3816         120 :                     n->typeName = NULL;
    3817         120 :                     n->inhcount = 0;
    3818         120 :                     n->is_local = true;
    3819         120 :                     n->is_not_null = false;
    3820         120 :                     n->is_from_type = false;
    3821         120 :                     n->storage = 0;
    3822         120 :                     n->raw_default = NULL;
    3823         120 :                     n->cooked_default = NULL;
    3824         120 :                     n->collOid = InvalidOid;
    3825         120 :                     SplitColQualList($2, &n->constraints, &n->collClause,
    3826             :                                      yyscanner);
    3827         120 :                     n->location = @1;
    3828         120 :                     $$ = (Node *) n;
    3829             :                 }
    3830             :                 | ColId WITH OPTIONS ColQualList
    3831             :                 {
    3832         184 :                     ColumnDef *n = makeNode(ColumnDef);
    3833             : 
    3834         184 :                     n->colname = $1;
    3835         184 :                     n->typeName = NULL;
    3836         184 :                     n->inhcount = 0;
    3837         184 :                     n->is_local = true;
    3838         184 :                     n->is_not_null = false;
    3839         184 :                     n->is_from_type = false;
    3840         184 :                     n->storage = 0;
    3841         184 :                     n->raw_default = NULL;
    3842         184 :                     n->cooked_default = NULL;
    3843         184 :                     n->collOid = InvalidOid;
    3844         184 :                     SplitColQualList($4, &n->constraints, &n->collClause,
    3845             :                                      yyscanner);
    3846         184 :                     n->location = @1;
    3847         184 :                     $$ = (Node *) n;
    3848             :                 }
    3849             :         ;
    3850             : 
    3851             : column_compression:
    3852         138 :             COMPRESSION ColId                       { $$ = $2; }
    3853           6 :             | COMPRESSION DEFAULT                   { $$ = pstrdup("default"); }
    3854             :         ;
    3855             : 
    3856             : opt_column_compression:
    3857          76 :             column_compression                      { $$ = $1; }
    3858       63588 :             | /*EMPTY*/                             { $$ = NULL; }
    3859             :         ;
    3860             : 
    3861             : column_storage:
    3862         226 :             STORAGE ColId                           { $$ = $2; }
    3863           6 :             | STORAGE DEFAULT                       { $$ = pstrdup("default"); }
    3864             :         ;
    3865             : 
    3866             : opt_column_storage:
    3867          20 :             column_storage                          { $$ = $1; }
    3868       63644 :             | /*EMPTY*/                             { $$ = NULL; }
    3869             :         ;
    3870             : 
    3871             : ColQualList:
    3872       17826 :             ColQualList ColConstraint               { $$ = lappend($1, $2); }
    3873       65308 :             | /*EMPTY*/                             { $$ = NIL; }
    3874             :         ;
    3875             : 
    3876             : ColConstraint:
    3877             :             CONSTRAINT name ColConstraintElem
    3878             :                 {
    3879         722 :                     Constraint *n = castNode(Constraint, $3);
    3880             : 
    3881         722 :                     n->conname = $2;
    3882         722 :                     n->location = @1;
    3883         722 :                     $$ = (Node *) n;
    3884             :                 }
    3885       16098 :             | ColConstraintElem                     { $$ = $1; }
    3886         276 :             | ConstraintAttr                        { $$ = $1; }
    3887             :             | COLLATE any_name
    3888             :                 {
    3889             :                     /*
    3890             :                      * Note: the CollateClause is momentarily included in
    3891             :                      * the list built by ColQualList, but we split it out
    3892             :                      * again in SplitColQualList.
    3893             :                      */
    3894         730 :                     CollateClause *n = makeNode(CollateClause);
    3895             : 
    3896         730 :                     n->arg = NULL;
    3897         730 :                     n->collname = $2;
    3898         730 :                     n->location = @1;
    3899         730 :                     $$ = (Node *) n;
    3900             :                 }
    3901             :         ;
    3902             : 
    3903             : /* DEFAULT NULL is already the default for Postgres.
    3904             :  * But define it here and carry it forward into the system
    3905             :  * to make it explicit.
    3906             :  * - thomas 1998-09-13
    3907             :  *
    3908             :  * WITH NULL and NULL are not SQL-standard syntax elements,
    3909             :  * so leave them out. Use DEFAULT NULL to explicitly indicate
    3910             :  * that a column may have that value. WITH NULL leads to
    3911             :  * shift/reduce conflicts with WITH TIME ZONE anyway.
    3912             :  * - thomas 1999-01-08
    3913             :  *
    3914             :  * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
    3915             :  * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
    3916             :  * or be part of a_expr NOT LIKE or similar constructs).
    3917             :  */
    3918             : ColConstraintElem:
    3919             :             NOT NULL_P opt_no_inherit
    3920             :                 {
    3921        6300 :                     Constraint *n = makeNode(Constraint);
    3922             : 
    3923        6300 :                     n->contype = CONSTR_NOTNULL;
    3924        6300 :                     n->location = @1;
    3925        6300 :                     n->is_no_inherit = $3;
    3926        6300 :                     n->is_enforced = true;
    3927        6300 :                     n->skip_validation = false;
    3928        6300 :                     n->initially_valid = true;
    3929        6300 :                     $$ = (Node *) n;
    3930             :                 }
    3931             :             | NULL_P
    3932             :                 {
    3933          30 :                     Constraint *n = makeNode(Constraint);
    3934             : 
    3935          30 :                     n->contype = CONSTR_NULL;
    3936          30 :                     n->location = @1;
    3937          30 :                     $$ = (Node *) n;
    3938             :                 }
    3939             :             | UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace
    3940             :                 {
    3941         410 :                     Constraint *n = makeNode(Constraint);
    3942             : 
    3943         410 :                     n->contype = CONSTR_UNIQUE;
    3944         410 :                     n->location = @1;
    3945         410 :                     n->nulls_not_distinct = !$2;
    3946         410 :                     n->keys = NULL;
    3947         410 :                     n->options = $3;
    3948         410 :                     n->indexname = NULL;
    3949         410 :                     n->indexspace = $4;
    3950         410 :                     $$ = (Node *) n;
    3951             :                 }
    3952             :             | PRIMARY KEY opt_definition OptConsTableSpace
    3953             :                 {
    3954        5436 :                     Constraint *n = makeNode(Constraint);
    3955             : 
    3956        5436 :                     n->contype = CONSTR_PRIMARY;
    3957        5436 :                     n->location = @1;
    3958        5436 :                     n->keys = NULL;
    3959        5436 :                     n->options = $3;
    3960        5436 :                     n->indexname = NULL;
    3961        5436 :                     n->indexspace = $4;
    3962        5436 :                     $$ = (Node *) n;
    3963             :                 }
    3964             :             | CHECK '(' a_expr ')' opt_no_inherit
    3965             :                 {
    3966        1000 :                     Constraint *n = makeNode(Constraint);
    3967             : 
    3968        1000 :                     n->contype = CONSTR_CHECK;
    3969        1000 :                     n->location = @1;
    3970        1000 :                     n->is_no_inherit = $5;
    3971        1000 :                     n->raw_expr = $3;
    3972        1000 :                     n->cooked_expr = NULL;
    3973        1000 :                     n->is_enforced = true;
    3974        1000 :                     n->skip_validation = false;
    3975        1000 :                     n->initially_valid = true;
    3976        1000 :                     $$ = (Node *) n;
    3977             :                 }
    3978             :             | DEFAULT b_expr
    3979             :                 {
    3980        1668 :                     Constraint *n = makeNode(Constraint);
    3981             : 
    3982        1668 :                     n->contype = CONSTR_DEFAULT;
    3983        1668 :                     n->location = @1;
    3984        1668 :                     n->raw_expr = $2;
    3985        1668 :                     n->cooked_expr = NULL;
    3986        1668 :                     $$ = (Node *) n;
    3987             :                 }
    3988             :             | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    3989             :                 {
    3990         302 :                     Constraint *n = makeNode(Constraint);
    3991             : 
    3992         302 :                     n->contype = CONSTR_IDENTITY;
    3993         302 :                     n->generated_when = $2;
    3994         302 :                     n->options = $5;
    3995         302 :                     n->location = @1;
    3996         302 :                     $$ = (Node *) n;
    3997             :                 }
    3998             :             | GENERATED generated_when AS '(' a_expr ')' STORED
    3999             :                 {
    4000         894 :                     Constraint *n = makeNode(Constraint);
    4001             : 
    4002         894 :                     n->contype = CONSTR_GENERATED;
    4003         894 :                     n->generated_when = $2;
    4004         894 :                     n->raw_expr = $5;
    4005         894 :                     n->cooked_expr = NULL;
    4006         894 :                     n->location = @1;
    4007             : 
    4008             :                     /*
    4009             :                      * Can't do this in the grammar because of shift/reduce
    4010             :                      * conflicts.  (IDENTITY allows both ALWAYS and BY
    4011             :                      * DEFAULT, but generated columns only allow ALWAYS.)  We
    4012             :                      * can also give a more useful error message and location.
    4013             :                      */
    4014         894 :                     if ($2 != ATTRIBUTE_IDENTITY_ALWAYS)
    4015           6 :                         ereport(ERROR,
    4016             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    4017             :                                  errmsg("for a generated column, GENERATED ALWAYS must be specified"),
    4018             :                                  parser_errposition(@2)));
    4019             : 
    4020         888 :                     $$ = (Node *) n;
    4021             :                 }
    4022             :             | REFERENCES qualified_name opt_column_list key_match key_actions
    4023             :                 {
    4024         786 :                     Constraint *n = makeNode(Constraint);
    4025             : 
    4026         786 :                     n->contype = CONSTR_FOREIGN;
    4027         786 :                     n->location = @1;
    4028         786 :                     n->pktable = $2;
    4029         786 :                     n->fk_attrs = NIL;
    4030         786 :                     n->pk_attrs = $3;
    4031         786 :                     n->fk_matchtype = $4;
    4032         786 :                     n->fk_upd_action = ($5)->updateAction->action;
    4033         786 :                     n->fk_del_action = ($5)->deleteAction->action;
    4034         786 :                     n->fk_del_set_cols = ($5)->deleteAction->cols;
    4035         786 :                     n->is_enforced = true;
    4036         786 :                     n->skip_validation = false;
    4037         786 :                     n->initially_valid = true;
    4038         786 :                     $$ = (Node *) n;
    4039             :                 }
    4040             :         ;
    4041             : 
    4042             : opt_unique_null_treatment:
    4043          12 :             NULLS_P DISTINCT        { $$ = true; }
    4044          36 :             | NULLS_P NOT DISTINCT  { $$ = false; }
    4045        7420 :             | /*EMPTY*/             { $$ = true; }
    4046             :         ;
    4047             : 
    4048             : generated_when:
    4049        1230 :             ALWAYS          { $$ = ATTRIBUTE_IDENTITY_ALWAYS; }
    4050         176 :             | BY DEFAULT    { $$ = ATTRIBUTE_IDENTITY_BY_DEFAULT; }
    4051             :         ;
    4052             : 
    4053             : /*
    4054             :  * ConstraintAttr represents constraint attributes, which we parse as if
    4055             :  * they were independent constraint clauses, in order to avoid shift/reduce
    4056             :  * conflicts (since NOT might start either an independent NOT NULL clause
    4057             :  * or an attribute).  parse_utilcmd.c is responsible for attaching the
    4058             :  * attribute information to the preceding "real" constraint node, and for
    4059             :  * complaining if attribute clauses appear in the wrong place or wrong
    4060             :  * combinations.
    4061             :  *
    4062             :  * See also ConstraintAttributeSpec, which can be used in places where
    4063             :  * there is no parsing conflict.  (Note: currently, NOT VALID and NO INHERIT
    4064             :  * are allowed clauses in ConstraintAttributeSpec, but not here.  Someday we
    4065             :  * might need to allow them here too, but for the moment it doesn't seem
    4066             :  * useful in the statements that use ConstraintAttr.)
    4067             :  */
    4068             : ConstraintAttr:
    4069             :             DEFERRABLE
    4070             :                 {
    4071         102 :                     Constraint *n = makeNode(Constraint);
    4072             : 
    4073         102 :                     n->contype = CONSTR_ATTR_DEFERRABLE;
    4074         102 :                     n->location = @1;
    4075         102 :                     $$ = (Node *) n;
    4076             :                 }
    4077             :             | NOT DEFERRABLE
    4078             :                 {
    4079           0 :                     Constraint *n = makeNode(Constraint);
    4080             : 
    4081           0 :                     n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
    4082           0 :                     n->location = @1;
    4083           0 :                     $$ = (Node *) n;
    4084             :                 }
    4085             :             | INITIALLY DEFERRED
    4086             :                 {
    4087          78 :                     Constraint *n = makeNode(Constraint);
    4088             : 
    4089          78 :                     n->contype = CONSTR_ATTR_DEFERRED;
    4090          78 :                     n->location = @1;
    4091          78 :                     $$ = (Node *) n;
    4092             :                 }
    4093             :             | INITIALLY IMMEDIATE
    4094             :                 {
    4095           6 :                     Constraint *n = makeNode(Constraint);
    4096             : 
    4097           6 :                     n->contype = CONSTR_ATTR_IMMEDIATE;
    4098           6 :                     n->location = @1;
    4099           6 :                     $$ = (Node *) n;
    4100             :                 }
    4101             :             | ENFORCED
    4102             :                 {
    4103          36 :                     Constraint *n = makeNode(Constraint);
    4104             : 
    4105          36 :                     n->contype = CONSTR_ATTR_ENFORCED;
    4106          36 :                     n->location = @1;
    4107          36 :                     $$ = (Node *) n;
    4108             :                 }
    4109             :             | NOT ENFORCED
    4110             :                 {
    4111          54 :                     Constraint *n = makeNode(Constraint);
    4112             : 
    4113          54 :                     n->contype = CONSTR_ATTR_NOT_ENFORCED;
    4114          54 :                     n->location = @1;
    4115          54 :                     $$ = (Node *) n;
    4116             :                 }
    4117             :         ;
    4118             : 
    4119             : 
    4120             : TableLikeClause:
    4121             :             LIKE qualified_name TableLikeOptionList
    4122             :                 {
    4123         750 :                     TableLikeClause *n = makeNode(TableLikeClause);
    4124             : 
    4125         750 :                     n->relation = $2;
    4126         750 :                     n->options = $3;
    4127         750 :                     n->relationOid = InvalidOid;
    4128         750 :                     $$ = (Node *) n;
    4129             :                 }
    4130             :         ;
    4131             : 
    4132             : TableLikeOptionList:
    4133         270 :                 TableLikeOptionList INCLUDING TableLikeOption   { $$ = $1 | $3; }
    4134           2 :                 | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
    4135         750 :                 | /* EMPTY */                       { $$ = 0; }
    4136             :         ;
    4137             : 
    4138             : TableLikeOption:
    4139          24 :                 COMMENTS            { $$ = CREATE_TABLE_LIKE_COMMENTS; }
    4140           6 :                 | COMPRESSION       { $$ = CREATE_TABLE_LIKE_COMPRESSION; }
    4141          54 :                 | CONSTRAINTS       { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
    4142          20 :                 | DEFAULTS          { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
    4143          12 :                 | IDENTITY_P        { $$ = CREATE_TABLE_LIKE_IDENTITY; }
    4144          24 :                 | GENERATED         { $$ = CREATE_TABLE_LIKE_GENERATED; }
    4145          50 :                 | INDEXES           { $$ = CREATE_TABLE_LIKE_INDEXES; }
    4146           0 :                 | STATISTICS        { $$ = CREATE_TABLE_LIKE_STATISTICS; }
    4147          26 :                 | STORAGE           { $$ = CREATE_TABLE_LIKE_STORAGE; }
    4148          56 :                 | ALL               { $$ = CREATE_TABLE_LIKE_ALL; }
    4149             :         ;
    4150             : 
    4151             : 
    4152             : /* ConstraintElem specifies constraint syntax which is not embedded into
    4153             :  *  a column definition. ColConstraintElem specifies the embedded form.
    4154             :  * - thomas 1997-12-03
    4155             :  */
    4156             : TableConstraint:
    4157             :             CONSTRAINT name ConstraintElem
    4158             :                 {
    4159        3780 :                     Constraint *n = castNode(Constraint, $3);
    4160             : 
    4161        3780 :                     n->conname = $2;
    4162        3780 :                     n->location = @1;
    4163        3780 :                     $$ = (Node *) n;
    4164             :                 }
    4165       11966 :             | ConstraintElem                        { $$ = $1; }
    4166             :         ;
    4167             : 
    4168             : ConstraintElem:
    4169             :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    4170             :                 {
    4171        1158 :                     Constraint *n = makeNode(Constraint);
    4172             : 
    4173        1158 :                     n->contype = CONSTR_CHECK;
    4174        1158 :                     n->location = @1;
    4175        1158 :                     n->raw_expr = $3;
    4176        1158 :                     n->cooked_expr = NULL;
    4177        1158 :                     processCASbits($5, @5, "CHECK",
    4178             :                                    NULL, NULL, &n->is_enforced, &n->skip_validation,
    4179             :                                    &n->is_no_inherit, yyscanner);
    4180        1158 :                     n->initially_valid = !n->skip_validation;
    4181        1158 :                     $$ = (Node *) n;
    4182             :                 }
    4183             :             | NOT NULL_P ColId ConstraintAttributeSpec
    4184             :                 {
    4185         386 :                     Constraint *n = makeNode(Constraint);
    4186             : 
    4187         386 :                     n->contype = CONSTR_NOTNULL;
    4188         386 :                     n->location = @1;
    4189         386 :                     n->keys = list_make1(makeString($3));
    4190             :                     /* no NOT VALID support yet */
    4191         386 :                     processCASbits($4, @4, "NOT NULL",
    4192             :                                    NULL, NULL, NULL, NULL,
    4193             :                                    &n->is_no_inherit, yyscanner);
    4194         386 :                     n->initially_valid = true;
    4195         386 :                     $$ = (Node *) n;
    4196             :                 }
    4197             :             | UNIQUE opt_unique_null_treatment '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
    4198             :                 ConstraintAttributeSpec
    4199             :                 {
    4200         610 :                     Constraint *n = makeNode(Constraint);
    4201             : 
    4202         610 :                     n->contype = CONSTR_UNIQUE;
    4203         610 :                     n->location = @1;
    4204         610 :                     n->nulls_not_distinct = !$2;
    4205         610 :                     n->keys = $4;
    4206         610 :                     n->without_overlaps = $5;
    4207         610 :                     n->including = $7;
    4208         610 :                     n->options = $8;
    4209         610 :                     n->indexname = NULL;
    4210         610 :                     n->indexspace = $9;
    4211         610 :                     processCASbits($10, @10, "UNIQUE",
    4212             :                                    &n->deferrable, &n->initdeferred, NULL,
    4213             :                                    NULL, NULL, yyscanner);
    4214         610 :                     $$ = (Node *) n;
    4215             :                 }
    4216             :             | UNIQUE ExistingIndex ConstraintAttributeSpec
    4217             :                 {
    4218        4168 :                     Constraint *n = makeNode(Constraint);
    4219             : 
    4220        4168 :                     n->contype = CONSTR_UNIQUE;
    4221        4168 :                     n->location = @1;
    4222        4168 :                     n->keys = NIL;
    4223        4168 :                     n->including = NIL;
    4224        4168 :                     n->options = NIL;
    4225        4168 :                     n->indexname = $2;
    4226        4168 :                     n->indexspace = NULL;
    4227        4168 :                     processCASbits($3, @3, "UNIQUE",
    4228             :                                    &n->deferrable, &n->initdeferred, NULL,
    4229             :                                    NULL, NULL, yyscanner);
    4230        4168 :                     $$ = (Node *) n;
    4231             :                 }
    4232             :             | PRIMARY KEY '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
    4233             :                 ConstraintAttributeSpec
    4234             :                 {
    4235        2042 :                     Constraint *n = makeNode(Constraint);
    4236             : 
    4237        2042 :                     n->contype = CONSTR_PRIMARY;
    4238        2042 :                     n->location = @1;
    4239        2042 :                     n->keys = $4;
    4240        2042 :                     n->without_overlaps = $5;
    4241        2042 :                     n->including = $7;
    4242        2042 :                     n->options = $8;
    4243        2042 :                     n->indexname = NULL;
    4244        2042 :                     n->indexspace = $9;
    4245        2042 :                     processCASbits($10, @10, "PRIMARY KEY",
    4246             :                                    &n->deferrable, &n->initdeferred, NULL,
    4247             :                                    NULL, NULL, yyscanner);
    4248        2042 :                     $$ = (Node *) n;
    4249             :                 }
    4250             :             | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
    4251             :                 {
    4252        5398 :                     Constraint *n = makeNode(Constraint);
    4253             : 
    4254        5398 :                     n->contype = CONSTR_PRIMARY;
    4255        5398 :                     n->location = @1;
    4256        5398 :                     n->keys = NIL;
    4257        5398 :                     n->including = NIL;
    4258        5398 :                     n->options = NIL;
    4259        5398 :                     n->indexname = $3;
    4260        5398 :                     n->indexspace = NULL;
    4261        5398 :                     processCASbits($4, @4, "PRIMARY KEY",
    4262             :                                    &n->deferrable, &n->initdeferred, NULL,
    4263             :                                    NULL, NULL, yyscanner);
    4264        5398 :                     $$ = (Node *) n;
    4265             :                 }
    4266             :             | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
    4267             :                 opt_c_include opt_definition OptConsTableSpace OptWhereClause
    4268             :                 ConstraintAttributeSpec
    4269             :                 {
    4270         234 :                     Constraint *n = makeNode(Constraint);
    4271             : 
    4272         234 :                     n->contype = CONSTR_EXCLUSION;
    4273         234 :                     n->location = @1;
    4274         234 :                     n->access_method = $2;
    4275         234 :                     n->exclusions = $4;
    4276         234 :                     n->including = $6;
    4277         234 :                     n->options = $7;
    4278         234 :                     n->indexname = NULL;
    4279         234 :                     n->indexspace = $8;
    4280         234 :                     n->where_clause = $9;
    4281         234 :                     processCASbits($10, @10, "EXCLUDE",
    4282             :                                    &n->deferrable, &n->initdeferred, NULL,
    4283             :                                    NULL, NULL, yyscanner);
    4284         234 :                     $$ = (Node *) n;
    4285             :                 }
    4286             :             | FOREIGN KEY '(' columnList optionalPeriodName ')' REFERENCES qualified_name
    4287             :                 opt_column_and_period_list key_match key_actions ConstraintAttributeSpec
    4288             :                 {
    4289        1750 :                     Constraint *n = makeNode(Constraint);
    4290             : 
    4291        1750 :                     n->contype = CONSTR_FOREIGN;
    4292        1750 :                     n->location = @1;
    4293        1750 :                     n->pktable = $8;
    4294        1750 :                     n->fk_attrs = $4;
    4295        1750 :                     if ($5)
    4296             :                     {
    4297         310 :                         n->fk_attrs = lappend(n->fk_attrs, $5);
    4298         310 :                         n->fk_with_period = true;
    4299             :                     }
    4300        1750 :                     n->pk_attrs = linitial($9);
    4301        1750 :                     if (lsecond($9))
    4302             :                     {
    4303         178 :                         n->pk_attrs = lappend(n->pk_attrs, lsecond($9));
    4304         178 :                         n->pk_with_period = true;
    4305             :                     }
    4306        1750 :                     n->fk_matchtype = $10;
    4307        1750 :                     n->fk_upd_action = ($11)->updateAction->action;
    4308        1750 :                     n->fk_del_action = ($11)->deleteAction->action;
    4309        1750 :                     n->fk_del_set_cols = ($11)->deleteAction->cols;
    4310        1750 :                     processCASbits($12, @12, "FOREIGN KEY",
    4311             :                                    &n->deferrable, &n->initdeferred,
    4312             :                                    NULL, &n->skip_validation, NULL,
    4313             :                                    yyscanner);
    4314        1750 :                     n->initially_valid = !n->skip_validation;
    4315        1750 :                     $$ = (Node *) n;
    4316             :                 }
    4317             :         ;
    4318             : 
    4319             : /*
    4320             :  * DomainConstraint is separate from TableConstraint because the syntax for
    4321             :  * NOT NULL constraints is different.  For table constraints, we need to
    4322             :  * accept a column name, but for domain constraints, we don't.  (We could
    4323             :  * accept something like NOT NULL VALUE, but that seems weird.)  CREATE DOMAIN
    4324             :  * (which uses ColQualList) has for a long time accepted NOT NULL without a
    4325             :  * column name, so it makes sense that ALTER DOMAIN (which uses
    4326             :  * DomainConstraint) does as well.  None of these syntaxes are per SQL
    4327             :  * standard; we are just living with the bits of inconsistency that have built
    4328             :  * up over time.
    4329             :  */
    4330             : DomainConstraint:
    4331             :             CONSTRAINT name DomainConstraintElem
    4332             :                 {
    4333         156 :                     Constraint *n = castNode(Constraint, $3);
    4334             : 
    4335         156 :                     n->conname = $2;
    4336         156 :                     n->location = @1;
    4337         156 :                     $$ = (Node *) n;
    4338             :                 }
    4339          18 :             | DomainConstraintElem                  { $$ = $1; }
    4340             :         ;
    4341             : 
    4342             : DomainConstraintElem:
    4343             :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    4344             :                 {
    4345         156 :                     Constraint *n = makeNode(Constraint);
    4346             : 
    4347         156 :                     n->contype = CONSTR_CHECK;
    4348         156 :                     n->location = @1;
    4349         156 :                     n->raw_expr = $3;
    4350         156 :                     n->cooked_expr = NULL;
    4351         156 :                     processCASbits($5, @5, "CHECK",
    4352             :                                    NULL, NULL, NULL, &n->skip_validation,
    4353             :                                    &n->is_no_inherit, yyscanner);
    4354         144 :                     n->is_enforced = true;
    4355         144 :                     n->initially_valid = !n->skip_validation;
    4356         144 :                     $$ = (Node *) n;
    4357             :                 }
    4358             :             | NOT NULL_P ConstraintAttributeSpec
    4359             :                 {
    4360          30 :                     Constraint *n = makeNode(Constraint);
    4361             : 
    4362          30 :                     n->contype = CONSTR_NOTNULL;
    4363          30 :                     n->location = @1;
    4364          30 :                     n->keys = list_make1(makeString("value"));
    4365             :                     /* no NOT VALID, NO INHERIT support */
    4366          30 :                     processCASbits($3, @3, "NOT NULL",
    4367             :                                    NULL, NULL, NULL,
    4368             :                                    NULL, NULL, yyscanner);
    4369          30 :                     n->initially_valid = true;
    4370          30 :                     $$ = (Node *) n;
    4371             :                 }
    4372             :         ;
    4373             : 
    4374         114 : opt_no_inherit: NO INHERIT                          {  $$ = true; }
    4375        7186 :             | /* EMPTY */                           {  $$ = false; }
    4376             :         ;
    4377             : 
    4378             : opt_without_overlaps:
    4379         554 :             WITHOUT OVERLAPS                        { $$ = true; }
    4380        2098 :             | /*EMPTY*/                             { $$ = false; }
    4381             :     ;
    4382             : 
    4383             : opt_column_list:
    4384        9054 :             '(' columnList ')'                      { $$ = $2; }
    4385       38266 :             | /*EMPTY*/                             { $$ = NIL; }
    4386             :         ;
    4387             : 
    4388             : columnList:
    4389       15152 :             columnElem                              { $$ = list_make1($1); }
    4390       27064 :             | columnList ',' columnElem             { $$ = lappend($1, $3); }
    4391             :         ;
    4392             : 
    4393             : optionalPeriodName:
    4394         488 :             ',' PERIOD columnElem { $$ = $3; }
    4395        2400 :             | /*EMPTY*/               { $$ = NULL; }
    4396             :     ;
    4397             : 
    4398             : opt_column_and_period_list:
    4399        1132 :             '(' columnList optionalPeriodName ')'           { $$ = list_make2($2, $3); }
    4400         624 :             | /*EMPTY*/                             { $$ = list_make2(NIL, NULL); }
    4401             :         ;
    4402             : 
    4403             : columnElem: ColId
    4404             :                 {
    4405       42704 :                     $$ = (Node *) makeString($1);
    4406             :                 }
    4407             :         ;
    4408             : 
    4409         168 : opt_c_include:  INCLUDE '(' columnList ')'          { $$ = $3; }
    4410        2718 :              |      /* EMPTY */                     { $$ = NIL; }
    4411             :         ;
    4412             : 
    4413             : key_match:  MATCH FULL
    4414             :             {
    4415          98 :                 $$ = FKCONSTR_MATCH_FULL;
    4416             :             }
    4417             :         | MATCH PARTIAL
    4418             :             {
    4419           0 :                 ereport(ERROR,
    4420             :                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4421             :                          errmsg("MATCH PARTIAL not yet implemented"),
    4422             :                          parser_errposition(@1)));
    4423             :                 $$ = FKCONSTR_MATCH_PARTIAL;
    4424             :             }
    4425             :         | MATCH SIMPLE
    4426             :             {
    4427           6 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4428             :             }
    4429             :         | /*EMPTY*/
    4430             :             {
    4431        2438 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4432             :             }
    4433             :         ;
    4434             : 
    4435             : ExclusionConstraintList:
    4436         234 :             ExclusionConstraintElem                 { $$ = list_make1($1); }
    4437             :             | ExclusionConstraintList ',' ExclusionConstraintElem
    4438         106 :                                                     { $$ = lappend($1, $3); }
    4439             :         ;
    4440             : 
    4441             : ExclusionConstraintElem: index_elem WITH any_operator
    4442             :             {
    4443         340 :                 $$ = list_make2($1, $3);
    4444             :             }
    4445             :             /* allow OPERATOR() decoration for the benefit of ruleutils.c */
    4446             :             | index_elem WITH OPERATOR '(' any_operator ')'
    4447             :             {
    4448           0 :                 $$ = list_make2($1, $5);
    4449             :             }
    4450             :         ;
    4451             : 
    4452             : OptWhereClause:
    4453         426 :             WHERE '(' a_expr ')'                    { $$ = $3; }
    4454        1202 :             | /*EMPTY*/                             { $$ = NULL; }
    4455             :         ;
    4456             : 
    4457             : key_actions:
    4458             :             key_update
    4459             :                 {
    4460          68 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4461             : 
    4462          68 :                     n->updateAction = $1;
    4463          68 :                     n->deleteAction = palloc(sizeof(KeyAction));
    4464          68 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4465          68 :                     n->deleteAction->cols = NIL;
    4466          68 :                     $$ = n;
    4467             :                 }
    4468             :             | key_delete
    4469             :                 {
    4470         166 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4471             : 
    4472         166 :                     n->updateAction = palloc(sizeof(KeyAction));
    4473         166 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4474         166 :                     n->updateAction->cols = NIL;
    4475         166 :                     n->deleteAction = $1;
    4476         166 :                     $$ = n;
    4477             :                 }
    4478             :             | key_update key_delete
    4479             :                 {
    4480         150 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4481             : 
    4482         150 :                     n->updateAction = $1;
    4483         150 :                     n->deleteAction = $2;
    4484         150 :                     $$ = n;
    4485             :                 }
    4486             :             | key_delete key_update
    4487             :                 {
    4488         150 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4489             : 
    4490         150 :                     n->updateAction = $2;
    4491         150 :                     n->deleteAction = $1;
    4492         150 :                     $$ = n;
    4493             :                 }
    4494             :             | /*EMPTY*/
    4495             :                 {
    4496        2002 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4497             : 
    4498        2002 :                     n->updateAction = palloc(sizeof(KeyAction));
    4499        2002 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4500        2002 :                     n->updateAction->cols = NIL;
    4501        2002 :                     n->deleteAction = palloc(sizeof(KeyAction));
    4502        2002 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4503        2002 :                     n->deleteAction->cols = NIL;
    4504        2002 :                     $$ = n;
    4505             :                 }
    4506             :         ;
    4507             : 
    4508             : key_update: ON UPDATE key_action
    4509             :                 {
    4510         374 :                     if (($3)->cols)
    4511           6 :                         ereport(ERROR,
    4512             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4513             :                                  errmsg("a column list with %s is only supported for ON DELETE actions",
    4514             :                                         ($3)->action == FKCONSTR_ACTION_SETNULL ? "SET NULL" : "SET DEFAULT"),
    4515             :                                  parser_errposition(@1)));
    4516         368 :                     $$ = $3;
    4517             :                 }
    4518             :         ;
    4519             : 
    4520             : key_delete: ON DELETE_P key_action
    4521             :                 {
    4522         466 :                     $$ = $3;
    4523             :                 }
    4524             :         ;
    4525             : 
    4526             : key_action:
    4527             :             NO ACTION
    4528             :                 {
    4529          80 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4530             : 
    4531          80 :                     n->action = FKCONSTR_ACTION_NOACTION;
    4532          80 :                     n->cols = NIL;
    4533          80 :                     $$ = n;
    4534             :                 }
    4535             :             | RESTRICT
    4536             :                 {
    4537          70 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4538             : 
    4539          70 :                     n->action = FKCONSTR_ACTION_RESTRICT;
    4540          70 :                     n->cols = NIL;
    4541          70 :                     $$ = n;
    4542             :                 }
    4543             :             | CASCADE
    4544             :                 {
    4545         404 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4546             : 
    4547         404 :                     n->action = FKCONSTR_ACTION_CASCADE;
    4548         404 :                     n->cols = NIL;
    4549         404 :                     $$ = n;
    4550             :                 }
    4551             :             | SET NULL_P opt_column_list
    4552             :                 {
    4553         184 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4554             : 
    4555         184 :                     n->action = FKCONSTR_ACTION_SETNULL;
    4556         184 :                     n->cols = $3;
    4557         184 :                     $$ = n;
    4558             :                 }
    4559             :             | SET DEFAULT opt_column_list
    4560             :                 {
    4561         102 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4562             : 
    4563         102 :                     n->action = FKCONSTR_ACTION_SETDEFAULT;
    4564         102 :                     n->cols = $3;
    4565         102 :                     $$ = n;
    4566             :                 }
    4567             :         ;
    4568             : 
    4569        1890 : OptInherit: INHERITS '(' qualified_name_list ')'    { $$ = $3; }
    4570       26174 :             | /*EMPTY*/                             { $$ = NIL; }
    4571             :         ;
    4572             : 
    4573             : /* Optional partition key specification */
    4574        4814 : OptPartitionSpec: PartitionSpec { $$ = $1; }
    4575       30700 :             | /*EMPTY*/         { $$ = NULL; }
    4576             :         ;
    4577             : 
    4578             : PartitionSpec: PARTITION BY ColId '(' part_params ')'
    4579             :                 {
    4580        4820 :                     PartitionSpec *n = makeNode(PartitionSpec);
    4581             : 
    4582        4820 :                     n->strategy = parsePartitionStrategy($3, @3, yyscanner);
    4583        4814 :                     n->partParams = $5;
    4584        4814 :                     n->location = @1;
    4585             : 
    4586        4814 :                     $$ = n;
    4587             :                 }
    4588             :         ;
    4589             : 
    4590        4820 : part_params:    part_elem                       { $$ = list_make1($1); }
    4591         438 :             | part_params ',' part_elem         { $$ = lappend($1, $3); }
    4592             :         ;
    4593             : 
    4594             : part_elem: ColId opt_collate opt_qualified_name
    4595             :                 {
    4596        4960 :                     PartitionElem *n = makeNode(PartitionElem);
    4597             : 
    4598        4960 :                     n->name = $1;
    4599        4960 :                     n->expr = NULL;
    4600        4960 :                     n->collation = $2;
    4601        4960 :                     n->opclass = $3;
    4602        4960 :                     n->location = @1;
    4603        4960 :                     $$ = n;
    4604             :                 }
    4605             :             | func_expr_windowless opt_collate opt_qualified_name
    4606             :                 {
    4607         130 :                     PartitionElem *n = makeNode(PartitionElem);
    4608             : 
    4609         130 :                     n->name = NULL;
    4610         130 :                     n->expr = $1;
    4611         130 :                     n->collation = $2;
    4612         130 :                     n->opclass = $3;
    4613         130 :                     n->location = @1;
    4614         130 :                     $$ = n;
    4615             :                 }
    4616             :             | '(' a_expr ')' opt_collate opt_qualified_name
    4617             :                 {
    4618         168 :                     PartitionElem *n = makeNode(PartitionElem);
    4619             : 
    4620         168 :                     n->name = NULL;
    4621         168 :                     n->expr = $2;
    4622         168 :                     n->collation = $4;
    4623         168 :                     n->opclass = $5;
    4624         168 :                     n->location = @1;
    4625         168 :                     $$ = n;
    4626             :                 }
    4627             :         ;
    4628             : 
    4629             : table_access_method_clause:
    4630         122 :             USING name                          { $$ = $2; }
    4631       37246 :             | /*EMPTY*/                         { $$ = NULL; }
    4632             :         ;
    4633             : 
    4634             : /* WITHOUT OIDS is legacy only */
    4635             : OptWith:
    4636         658 :             WITH reloptions             { $$ = $2; }
    4637          24 :             | WITHOUT OIDS              { $$ = NIL; }
    4638       36106 :             | /*EMPTY*/                 { $$ = NIL; }
    4639             :         ;
    4640             : 
    4641          56 : OnCommitOption:  ON COMMIT DROP             { $$ = ONCOMMIT_DROP; }
    4642          98 :             | ON COMMIT DELETE_P ROWS       { $$ = ONCOMMIT_DELETE_ROWS; }
    4643          24 :             | ON COMMIT PRESERVE ROWS       { $$ = ONCOMMIT_PRESERVE_ROWS; }
    4644       36610 :             | /*EMPTY*/                     { $$ = ONCOMMIT_NOOP; }
    4645             :         ;
    4646             : 
    4647         206 : OptTableSpace:   TABLESPACE name                    { $$ = $2; }
    4648       43604 :             | /*EMPTY*/                             { $$ = NULL; }
    4649             :         ;
    4650             : 
    4651          66 : OptConsTableSpace:   USING INDEX TABLESPACE name    { $$ = $4; }
    4652        8666 :             | /*EMPTY*/                             { $$ = NULL; }
    4653             :         ;
    4654             : 
    4655        9566 : ExistingIndex:   USING INDEX name                   { $$ = $3; }
    4656             :         ;
    4657             : 
    4658             : /*****************************************************************************
    4659             :  *
    4660             :  *      QUERY :
    4661             :  *              CREATE STATISTICS [[IF NOT EXISTS] stats_name] [(stat types)]
    4662             :  *                  ON expression-list FROM from_list
    4663             :  *
    4664             :  * Note: the expectation here is that the clauses after ON are a subset of
    4665             :  * SELECT syntax, allowing for expressions and joined tables, and probably
    4666             :  * someday a WHERE clause.  Much less than that is currently implemented,
    4667             :  * but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
    4668             :  * errors as necessary at execution.
    4669             :  *
    4670             :  * Statistics name is optional unless IF NOT EXISTS is specified.
    4671             :  *
    4672             :  *****************************************************************************/
    4673             : 
    4674             : CreateStatsStmt:
    4675             :             CREATE STATISTICS opt_qualified_name
    4676             :             opt_name_list ON stats_params FROM from_list
    4677             :                 {
    4678         584 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4679             : 
    4680         584 :                     n->defnames = $3;
    4681         584 :                     n->stat_types = $4;
    4682         584 :                     n->exprs = $6;
    4683         584 :                     n->relations = $8;
    4684         584 :                     n->stxcomment = NULL;
    4685         584 :                     n->if_not_exists = false;
    4686         584 :                     $$ = (Node *) n;
    4687             :                 }
    4688             :             | CREATE STATISTICS IF_P NOT EXISTS any_name
    4689             :             opt_name_list ON stats_params FROM from_list
    4690             :                 {
    4691          12 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4692             : 
    4693          12 :                     n->defnames = $6;
    4694          12 :                     n->stat_types = $7;
    4695          12 :                     n->exprs = $9;
    4696          12 :                     n->relations = $11;
    4697          12 :                     n->stxcomment = NULL;
    4698          12 :                     n->if_not_exists = true;
    4699          12 :                     $$ = (Node *) n;
    4700             :                 }
    4701             :             ;
    4702             : 
    4703             : /*
    4704             :  * Statistics attributes can be either simple column references, or arbitrary
    4705             :  * expressions in parens.  For compatibility with index attributes permitted
    4706             :  * in CREATE INDEX, we allow an expression that's just a function call to be
    4707             :  * written without parens.
    4708             :  */
    4709             : 
    4710         608 : stats_params:   stats_param                         { $$ = list_make1($1); }
    4711         952 :             | stats_params ',' stats_param          { $$ = lappend($1, $3); }
    4712             :         ;
    4713             : 
    4714             : stats_param:    ColId
    4715             :                 {
    4716        1110 :                     $$ = makeNode(StatsElem);
    4717        1110 :                     $$->name = $1;
    4718        1110 :                     $$->expr = NULL;
    4719             :                 }
    4720             :             | func_expr_windowless
    4721             :                 {
    4722          32 :                     $$ = makeNode(StatsElem);
    4723          32 :                     $$->name = NULL;
    4724          32 :                     $$->expr = $1;
    4725             :                 }
    4726             :             | '(' a_expr ')'
    4727             :                 {
    4728         418 :                     $$ = makeNode(StatsElem);
    4729         418 :                     $$->name = NULL;
    4730         418 :                     $$->expr = $2;
    4731             :                 }
    4732             :         ;
    4733             : 
    4734             : /*****************************************************************************
    4735             :  *
    4736             :  *      QUERY :
    4737             :  *              ALTER STATISTICS [IF EXISTS] stats_name
    4738             :  *                  SET STATISTICS  <SignedIconst>
    4739             :  *
    4740             :  *****************************************************************************/
    4741             : 
    4742             : AlterStatsStmt:
    4743             :             ALTER STATISTICS any_name SET STATISTICS set_statistics_value
    4744             :                 {
    4745          20 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4746             : 
    4747          20 :                     n->defnames = $3;
    4748          20 :                     n->missing_ok = false;
    4749          20 :                     n->stxstattarget = $6;
    4750          20 :                     $$ = (Node *) n;
    4751             :                 }
    4752             :             | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
    4753             :                 {
    4754           6 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4755             : 
    4756           6 :                     n->defnames = $5;
    4757           6 :                     n->missing_ok = true;
    4758           6 :                     n->stxstattarget = $8;
    4759           6 :                     $$ = (Node *) n;
    4760             :                 }
    4761             :             ;
    4762             : 
    4763             : /*****************************************************************************
    4764             :  *
    4765             :  *      QUERY :
    4766             :  *              CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
    4767             :  *
    4768             :  *
    4769             :  * Note: SELECT ... INTO is a now-deprecated alternative for this.
    4770             :  *
    4771             :  *****************************************************************************/
    4772             : 
    4773             : CreateAsStmt:
    4774             :         CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
    4775             :                 {
    4776        1146 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4777             : 
    4778        1146 :                     ctas->query = $6;
    4779        1146 :                     ctas->into = $4;
    4780        1146 :                     ctas->objtype = OBJECT_TABLE;
    4781        1146 :                     ctas->is_select_into = false;
    4782        1146 :                     ctas->if_not_exists = false;
    4783             :                     /* cram additional flags into the IntoClause */
    4784        1146 :                     $4->rel->relpersistence = $2;
    4785        1146 :                     $4->skipData = !($7);
    4786        1146 :                     $$ = (Node *) ctas;
    4787             :                 }
    4788             :         | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
    4789             :                 {
    4790          52 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4791             : 
    4792          52 :                     ctas->query = $9;
    4793          52 :                     ctas->into = $7;
    4794          52 :                     ctas->objtype = OBJECT_TABLE;
    4795          52 :                     ctas->is_select_into = false;
    4796          52 :                     ctas->if_not_exists = true;
    4797             :                     /* cram additional flags into the IntoClause */
    4798          52 :                     $7->rel->relpersistence = $2;
    4799          52 :                     $7->skipData = !($10);
    4800          52 :                     $$ = (Node *) ctas;
    4801             :                 }
    4802             :         ;
    4803             : 
    4804             : create_as_target:
    4805             :             qualified_name opt_column_list table_access_method_clause
    4806             :             OptWith OnCommitOption OptTableSpace
    4807             :                 {
    4808        1286 :                     $$ = makeNode(IntoClause);
    4809        1286 :                     $$->rel = $1;
    4810        1286 :                     $$->colNames = $2;
    4811        1286 :                     $$->accessMethod = $3;
    4812        1286 :                     $$->options = $4;
    4813        1286 :                     $$->onCommit = $5;
    4814        1286 :                     $$->tableSpaceName = $6;
    4815        1286 :                     $$->viewQuery = NULL;
    4816        1286 :                     $$->skipData = false;        /* might get changed later */
    4817             :                 }
    4818             :         ;
    4819             : 
    4820             : opt_with_data:
    4821          36 :             WITH DATA_P                             { $$ = true; }
    4822         212 :             | WITH NO DATA_P                        { $$ = false; }
    4823        1874 :             | /*EMPTY*/                             { $$ = true; }
    4824             :         ;
    4825             : 
    4826             : 
    4827             : /*****************************************************************************
    4828             :  *
    4829             :  *      QUERY :
    4830             :  *              CREATE MATERIALIZED VIEW relname AS SelectStmt
    4831             :  *
    4832             :  *****************************************************************************/
    4833             : 
    4834             : CreateMatViewStmt:
    4835             :         CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
    4836             :                 {
    4837         526 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4838             : 
    4839         526 :                     ctas->query = $7;
    4840         526 :                     ctas->into = $5;
    4841         526 :                     ctas->objtype = OBJECT_MATVIEW;
    4842         526 :                     ctas->is_select_into = false;
    4843         526 :                     ctas->if_not_exists = false;
    4844             :                     /* cram additional flags into the IntoClause */
    4845         526 :                     $5->rel->relpersistence = $2;
    4846         526 :                     $5->skipData = !($8);
    4847         526 :                     $$ = (Node *) ctas;
    4848             :                 }
    4849             :         | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
    4850             :                 {
    4851          48 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4852             : 
    4853          48 :                     ctas->query = $10;
    4854          48 :                     ctas->into = $8;
    4855          48 :                     ctas->objtype = OBJECT_MATVIEW;
    4856          48 :                     ctas->is_select_into = false;
    4857          48 :                     ctas->if_not_exists = true;
    4858             :                     /* cram additional flags into the IntoClause */
    4859          48 :                     $8->rel->relpersistence = $2;
    4860          48 :                     $8->skipData = !($11);
    4861          48 :                     $$ = (Node *) ctas;
    4862             :                 }
    4863             :         ;
    4864             : 
    4865             : create_mv_target:
    4866             :             qualified_name opt_column_list table_access_method_clause opt_reloptions OptTableSpace
    4867             :                 {
    4868         574 :                     $$ = makeNode(IntoClause);
    4869         574 :                     $$->rel = $1;
    4870         574 :                     $$->colNames = $2;
    4871         574 :                     $$->accessMethod = $3;
    4872         574 :                     $$->options = $4;
    4873         574 :                     $$->onCommit = ONCOMMIT_NOOP;
    4874         574 :                     $$->tableSpaceName = $5;
    4875         574 :                     $$->viewQuery = NULL;        /* filled at analysis time */
    4876         574 :                     $$->skipData = false;        /* might get changed later */
    4877             :                 }
    4878             :         ;
    4879             : 
    4880           0 : OptNoLog:   UNLOGGED                    { $$ = RELPERSISTENCE_UNLOGGED; }
    4881         574 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    4882             :         ;
    4883             : 
    4884             : 
    4885             : /*****************************************************************************
    4886             :  *
    4887             :  *      QUERY :
    4888             :  *              REFRESH MATERIALIZED VIEW qualified_name
    4889             :  *
    4890             :  *****************************************************************************/
    4891             : 
    4892             : RefreshMatViewStmt:
    4893             :             REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
    4894             :                 {
    4895         262 :                     RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
    4896             : 
    4897         262 :                     n->concurrent = $4;
    4898         262 :                     n->relation = $5;
    4899         262 :                     n->skipData = !($6);
    4900         262 :                     $$ = (Node *) n;
    4901             :                 }
    4902             :         ;
    4903             : 
    4904             : 
    4905             : /*****************************************************************************
    4906             :  *
    4907             :  *      QUERY :
    4908             :  *              CREATE SEQUENCE seqname
    4909             :  *              ALTER SEQUENCE seqname
    4910             :  *
    4911             :  *****************************************************************************/
    4912             : 
    4913             : CreateSeqStmt:
    4914             :             CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
    4915             :                 {
    4916         632 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    4917             : 
    4918         632 :                     $4->relpersistence = $2;
    4919         632 :                     n->sequence = $4;
    4920         632 :                     n->options = $5;
    4921         632 :                     n->ownerId = InvalidOid;
    4922         632 :                     n->if_not_exists = false;
    4923         632 :                     $$ = (Node *) n;
    4924             :                 }
    4925             :             | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
    4926             :                 {
    4927          24 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    4928             : 
    4929          24 :                     $7->relpersistence = $2;
    4930          24 :                     n->sequence = $7;
    4931          24 :                     n->options = $8;
    4932          24 :                     n->ownerId = InvalidOid;
    4933          24 :                     n->if_not_exists = true;
    4934          24 :                     $$ = (Node *) n;
    4935             :                 }
    4936             :         ;
    4937             : 
    4938             : AlterSeqStmt:
    4939             :             ALTER SEQUENCE qualified_name SeqOptList
    4940             :                 {
    4941         174 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    4942             : 
    4943         174 :                     n->sequence = $3;
    4944         174 :                     n->options = $4;
    4945         174 :                     n->missing_ok = false;
    4946         174 :                     $$ = (Node *) n;
    4947             :                 }
    4948             :             | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
    4949             :                 {
    4950          12 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    4951             : 
    4952          12 :                     n->sequence = $5;
    4953          12 :                     n->options = $6;
    4954          12 :                     n->missing_ok = true;
    4955          12 :                     $$ = (Node *) n;
    4956             :                 }
    4957             : 
    4958             :         ;
    4959             : 
    4960         238 : OptSeqOptList: SeqOptList                           { $$ = $1; }
    4961         418 :             | /*EMPTY*/                             { $$ = NIL; }
    4962             :         ;
    4963             : 
    4964          74 : OptParenthesizedSeqOptList: '(' SeqOptList ')'      { $$ = $2; }
    4965         394 :             | /*EMPTY*/                             { $$ = NIL; }
    4966             :         ;
    4967             : 
    4968         498 : SeqOptList: SeqOptElem                              { $$ = list_make1($1); }
    4969         728 :             | SeqOptList SeqOptElem                 { $$ = lappend($1, $2); }
    4970             :         ;
    4971             : 
    4972             : SeqOptElem: AS SimpleTypename
    4973             :                 {
    4974         180 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    4975             :                 }
    4976             :             | CACHE NumericOnly
    4977             :                 {
    4978         112 :                     $$ = makeDefElem("cache", (Node *) $2, @1);
    4979             :                 }
    4980             :             | CYCLE
    4981             :                 {
    4982          34 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(true), @1);
    4983             :                 }
    4984             :             | NO CYCLE
    4985             :                 {
    4986          14 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(false), @1);
    4987             :                 }
    4988             :             | INCREMENT opt_by NumericOnly
    4989             :                 {
    4990         232 :                     $$ = makeDefElem("increment", (Node *) $3, @1);
    4991             :                 }
    4992             :             | LOGGED
    4993             :                 {
    4994           2 :                     $$ = makeDefElem("logged", NULL, @1);
    4995             :                 }
    4996             :             | MAXVALUE NumericOnly
    4997             :                 {
    4998          68 :                     $$ = makeDefElem("maxvalue", (Node *) $2, @1);
    4999             :                 }
    5000             :             | MINVALUE NumericOnly
    5001             :                 {
    5002          72 :                     $$ = makeDefElem("minvalue", (Node *) $2, @1);
    5003             :                 }
    5004             :             | NO MAXVALUE
    5005             :                 {
    5006          90 :                     $$ = makeDefElem("maxvalue", NULL, @1);
    5007             :                 }
    5008             :             | NO MINVALUE
    5009             :                 {
    5010          90 :                     $$ = makeDefElem("minvalue", NULL, @1);
    5011             :                 }
    5012             :             | OWNED BY any_name
    5013             :                 {
    5014          62 :                     $$ = makeDefElem("owned_by", (Node *) $3, @1);
    5015             :                 }
    5016             :             | SEQUENCE NAME_P any_name
    5017             :                 {
    5018          44 :                     $$ = makeDefElem("sequence_name", (Node *) $3, @1);
    5019             :                 }
    5020             :             | START opt_with NumericOnly
    5021             :                 {
    5022         212 :                     $$ = makeDefElem("start", (Node *) $3, @1);
    5023             :                 }
    5024             :             | RESTART
    5025             :                 {
    5026           6 :                     $$ = makeDefElem("restart", NULL, @1);
    5027             :                 }
    5028             :             | RESTART opt_with NumericOnly
    5029             :                 {
    5030          60 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    5031             :                 }
    5032             :             | UNLOGGED
    5033             :                 {
    5034           2 :                     $$ = makeDefElem("unlogged", NULL, @1);
    5035             :                 }
    5036             :         ;
    5037             : 
    5038             : opt_by:     BY
    5039             :             | /* EMPTY */
    5040             :       ;
    5041             : 
    5042             : NumericOnly:
    5043         318 :             FCONST                              { $$ = (Node *) makeFloat($1); }
    5044           0 :             | '+' FCONST                        { $$ = (Node *) makeFloat($2); }
    5045             :             | '-' FCONST
    5046             :                 {
    5047          20 :                     Float      *f = makeFloat($2);
    5048             : 
    5049          20 :                     doNegateFloat(f);
    5050          20 :                     $$ = (Node *) f;
    5051             :                 }
    5052       11338 :             | SignedIconst                      { $$ = (Node *) makeInteger($1); }
    5053             :         ;
    5054             : 
    5055          80 : NumericOnly_list:   NumericOnly                     { $$ = list_make1($1); }
    5056           6 :                 | NumericOnly_list ',' NumericOnly  { $$ = lappend($1, $3); }
    5057             :         ;
    5058             : 
    5059             : /*****************************************************************************
    5060             :  *
    5061             :  *      QUERIES :
    5062             :  *              CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
    5063             :  *              DROP [PROCEDURAL] LANGUAGE ...
    5064             :  *
    5065             :  *****************************************************************************/
    5066             : 
    5067             : CreatePLangStmt:
    5068             :             CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
    5069             :             {
    5070             :                 /*
    5071             :                  * We now interpret parameterless CREATE LANGUAGE as
    5072             :                  * CREATE EXTENSION.  "OR REPLACE" is silently translated
    5073             :                  * to "IF NOT EXISTS", which isn't quite the same, but
    5074             :                  * seems more useful than throwing an error.  We just
    5075             :                  * ignore TRUSTED, as the previous code would have too.
    5076             :                  */
    5077           0 :                 CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5078             : 
    5079           0 :                 n->if_not_exists = $2;
    5080           0 :                 n->extname = $6;
    5081           0 :                 n->options = NIL;
    5082           0 :                 $$ = (Node *) n;
    5083             :             }
    5084             :             | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
    5085             :               HANDLER handler_name opt_inline_handler opt_validator
    5086             :             {
    5087         132 :                 CreatePLangStmt *n = makeNode(CreatePLangStmt);
    5088             : 
    5089         132 :                 n->replace = $2;
    5090         132 :                 n->plname = $6;
    5091         132 :                 n->plhandler = $8;
    5092         132 :                 n->plinline = $9;
    5093         132 :                 n->plvalidator = $10;
    5094         132 :                 n->pltrusted = $3;
    5095         132 :                 $$ = (Node *) n;
    5096             :             }
    5097             :         ;
    5098             : 
    5099             : opt_trusted:
    5100         102 :             TRUSTED                                 { $$ = true; }
    5101          38 :             | /*EMPTY*/                             { $$ = false; }
    5102             :         ;
    5103             : 
    5104             : /* This ought to be just func_name, but that causes reduce/reduce conflicts
    5105             :  * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
    5106             :  * Work around by using simple names, instead.
    5107             :  */
    5108             : handler_name:
    5109         522 :             name                        { $$ = list_make1(makeString($1)); }
    5110           2 :             | name attrs                { $$ = lcons(makeString($1), $2); }
    5111             :         ;
    5112             : 
    5113             : opt_inline_handler:
    5114         114 :             INLINE_P handler_name                   { $$ = $2; }
    5115          18 :             | /*EMPTY*/                             { $$ = NIL; }
    5116             :         ;
    5117             : 
    5118             : validator_clause:
    5119         114 :             VALIDATOR handler_name                  { $$ = $2; }
    5120           0 :             | NO VALIDATOR                          { $$ = NIL; }
    5121             :         ;
    5122             : 
    5123             : opt_validator:
    5124         114 :             validator_clause                        { $$ = $1; }
    5125          18 :             | /*EMPTY*/                             { $$ = NIL; }
    5126             :         ;
    5127             : 
    5128             : opt_procedural:
    5129             :             PROCEDURAL
    5130             :             | /*EMPTY*/
    5131             :         ;
    5132             : 
    5133             : /*****************************************************************************
    5134             :  *
    5135             :  *      QUERY:
    5136             :  *             CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
    5137             :  *
    5138             :  *****************************************************************************/
    5139             : 
    5140             : CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
    5141             :                 {
    5142         112 :                     CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
    5143             : 
    5144         112 :                     n->tablespacename = $3;
    5145         112 :                     n->owner = $4;
    5146         112 :                     n->location = $6;
    5147         112 :                     n->options = $7;
    5148         112 :                     $$ = (Node *) n;
    5149             :                 }
    5150             :         ;
    5151             : 
    5152           2 : OptTableSpaceOwner: OWNER RoleSpec      { $$ = $2; }
    5153         110 :             | /*EMPTY */                { $$ = NULL; }
    5154             :         ;
    5155             : 
    5156             : /*****************************************************************************
    5157             :  *
    5158             :  *      QUERY :
    5159             :  *              DROP TABLESPACE <tablespace>
    5160             :  *
    5161             :  *      No need for drop behaviour as we cannot implement dependencies for
    5162             :  *      objects in other databases; we can only support RESTRICT.
    5163             :  *
    5164             :  ****************************************************************************/
    5165             : 
    5166             : DropTableSpaceStmt: DROP TABLESPACE name
    5167             :                 {
    5168          64 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    5169             : 
    5170          64 :                     n->tablespacename = $3;
    5171          64 :                     n->missing_ok = false;
    5172          64 :                     $$ = (Node *) n;
    5173             :                 }
    5174             :                 |  DROP TABLESPACE IF_P EXISTS name
    5175             :                 {
    5176           0 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    5177             : 
    5178           0 :                     n->tablespacename = $5;
    5179           0 :                     n->missing_ok = true;
    5180           0 :                     $$ = (Node *) n;
    5181             :                 }
    5182             :         ;
    5183             : 
    5184             : /*****************************************************************************
    5185             :  *
    5186             :  *      QUERY:
    5187             :  *             CREATE EXTENSION extension
    5188             :  *             [ WITH ] [ SCHEMA schema ] [ VERSION version ]
    5189             :  *
    5190             :  *****************************************************************************/
    5191             : 
    5192             : CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
    5193             :                 {
    5194         460 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5195             : 
    5196         460 :                     n->extname = $3;
    5197         460 :                     n->if_not_exists = false;
    5198         460 :                     n->options = $5;
    5199         460 :                     $$ = (Node *) n;
    5200             :                 }
    5201             :                 | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
    5202             :                 {
    5203          16 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5204             : 
    5205          16 :                     n->extname = $6;
    5206          16 :                     n->if_not_exists = true;
    5207          16 :                     n->options = $8;
    5208          16 :                     $$ = (Node *) n;
    5209             :                 }
    5210             :         ;
    5211             : 
    5212             : create_extension_opt_list:
    5213             :             create_extension_opt_list create_extension_opt_item
    5214          98 :                 { $$ = lappend($1, $2); }
    5215             :             | /* EMPTY */
    5216         476 :                 { $$ = NIL; }
    5217             :         ;
    5218             : 
    5219             : create_extension_opt_item:
    5220             :             SCHEMA name
    5221             :                 {
    5222          46 :                     $$ = makeDefElem("schema", (Node *) makeString($2), @1);
    5223             :                 }
    5224             :             | VERSION_P NonReservedWord_or_Sconst
    5225             :                 {
    5226          12 :                     $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
    5227             :                 }
    5228             :             | FROM NonReservedWord_or_Sconst
    5229             :                 {
    5230           0 :                     ereport(ERROR,
    5231             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    5232             :                              errmsg("CREATE EXTENSION ... FROM is no longer supported"),
    5233             :                              parser_errposition(@1)));
    5234             :                 }
    5235             :             | CASCADE
    5236             :                 {
    5237          40 :                     $$ = makeDefElem("cascade", (Node *) makeBoolean(true), @1);
    5238             :                 }
    5239             :         ;
    5240             : 
    5241             : /*****************************************************************************
    5242             :  *
    5243             :  * ALTER EXTENSION name UPDATE [ TO version ]
    5244             :  *
    5245             :  *****************************************************************************/
    5246             : 
    5247             : AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
    5248             :                 {
    5249          38 :                     AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
    5250             : 
    5251          38 :                     n->extname = $3;
    5252          38 :                     n->options = $5;
    5253          38 :                     $$ = (Node *) n;
    5254             :                 }
    5255             :         ;
    5256             : 
    5257             : alter_extension_opt_list:
    5258             :             alter_extension_opt_list alter_extension_opt_item
    5259          38 :                 { $$ = lappend($1, $2); }
    5260             :             | /* EMPTY */
    5261          38 :                 { $$ = NIL; }
    5262             :         ;
    5263             : 
    5264             : alter_extension_opt_item:
    5265             :             TO NonReservedWord_or_Sconst
    5266             :                 {
    5267          38 :                     $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
    5268             :                 }
    5269             :         ;
    5270             : 
    5271             : /*****************************************************************************
    5272             :  *
    5273             :  * ALTER EXTENSION name ADD/DROP object-identifier
    5274             :  *
    5275             :  *****************************************************************************/
    5276             : 
    5277             : AlterExtensionContentsStmt:
    5278             :             ALTER EXTENSION name add_drop object_type_name name
    5279             :                 {
    5280          18 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5281             : 
    5282          18 :                     n->extname = $3;
    5283          18 :                     n->action = $4;
    5284          18 :                     n->objtype = $5;
    5285          18 :                     n->object = (Node *) makeString($6);
    5286          18 :                     $$ = (Node *) n;
    5287             :                 }
    5288             :             | ALTER EXTENSION name add_drop object_type_any_name any_name
    5289             :                 {
    5290          68 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5291             : 
    5292          68 :                     n->extname = $3;
    5293          68 :                     n->action = $4;
    5294          68 :                     n->objtype = $5;
    5295          68 :                     n->object = (Node *) $6;
    5296          68 :                     $$ = (Node *) n;
    5297             :                 }
    5298             :             | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
    5299             :                 {
    5300           8 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5301             : 
    5302           8 :                     n->extname = $3;
    5303           8 :                     n->action = $4;
    5304           8 :                     n->objtype = OBJECT_AGGREGATE;
    5305           8 :                     n->object = (Node *) $6;
    5306           8 :                     $$ = (Node *) n;
    5307             :                 }
    5308             :             | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
    5309             :                 {
    5310           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5311             : 
    5312           4 :                     n->extname = $3;
    5313           4 :                     n->action = $4;
    5314           4 :                     n->objtype = OBJECT_CAST;
    5315           4 :                     n->object = (Node *) list_make2($7, $9);
    5316           4 :                     $$ = (Node *) n;
    5317             :                 }
    5318             :             | ALTER EXTENSION name add_drop DOMAIN_P Typename
    5319             :                 {
    5320           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5321             : 
    5322           0 :                     n->extname = $3;
    5323           0 :                     n->action = $4;
    5324           0 :                     n->objtype = OBJECT_DOMAIN;
    5325           0 :                     n->object = (Node *) $6;
    5326           0 :                     $$ = (Node *) n;
    5327             :                 }
    5328             :             | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
    5329             :                 {
    5330          88 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5331             : 
    5332          88 :                     n->extname = $3;
    5333          88 :                     n->action = $4;
    5334          88 :                     n->objtype = OBJECT_FUNCTION;
    5335          88 :                     n->object = (Node *) $6;
    5336          88 :                     $$ = (Node *) n;
    5337             :                 }
    5338             :             | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
    5339             :                 {
    5340          18 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5341             : 
    5342          18 :                     n->extname = $3;
    5343          18 :                     n->action = $4;
    5344          18 :                     n->objtype = OBJECT_OPERATOR;
    5345          18 :                     n->object = (Node *) $6;
    5346          18 :                     $$ = (Node *) n;
    5347             :                 }
    5348             :             | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING name
    5349             :                 {
    5350           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5351             : 
    5352           4 :                     n->extname = $3;
    5353           4 :                     n->action = $4;
    5354           4 :                     n->objtype = OBJECT_OPCLASS;
    5355           4 :                     n->object = (Node *) lcons(makeString($9), $7);
    5356           4 :                     $$ = (Node *) n;
    5357             :                 }
    5358             :             | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING name
    5359             :                 {
    5360           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5361             : 
    5362           4 :                     n->extname = $3;
    5363           4 :                     n->action = $4;
    5364           4 :                     n->objtype = OBJECT_OPFAMILY;
    5365           4 :                     n->object = (Node *) lcons(makeString($9), $7);
    5366           4 :                     $$ = (Node *) n;
    5367             :                 }
    5368             :             | ALTER EXTENSION name add_drop PROCEDURE function_with_argtypes
    5369             :                 {
    5370           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5371             : 
    5372           0 :                     n->extname = $3;
    5373           0 :                     n->action = $4;
    5374           0 :                     n->objtype = OBJECT_PROCEDURE;
    5375           0 :                     n->object = (Node *) $6;
    5376           0 :                     $$ = (Node *) n;
    5377             :                 }
    5378             :             | ALTER EXTENSION name add_drop ROUTINE function_with_argtypes
    5379             :                 {
    5380           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5381             : 
    5382           0 :                     n->extname = $3;
    5383           0 :                     n->action = $4;
    5384           0 :                     n->objtype = OBJECT_ROUTINE;
    5385           0 :                     n->object = (Node *) $6;
    5386           0 :                     $$ = (Node *) n;
    5387             :                 }
    5388             :             | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
    5389             :                 {
    5390           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5391             : 
    5392           4 :                     n->extname = $3;
    5393           4 :                     n->action = $4;
    5394           4 :                     n->objtype = OBJECT_TRANSFORM;
    5395           4 :                     n->object = (Node *) list_make2($7, makeString($9));
    5396           4 :                     $$ = (Node *) n;
    5397             :                 }
    5398             :             | ALTER EXTENSION name add_drop TYPE_P Typename
    5399             :                 {
    5400           8 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5401             : 
    5402           8 :                     n->extname = $3;
    5403           8 :                     n->action = $4;
    5404           8 :                     n->objtype = OBJECT_TYPE;
    5405           8 :                     n->object = (Node *) $6;
    5406           8 :                     $$ = (Node *) n;
    5407             :                 }
    5408             :         ;
    5409             : 
    5410             : /*****************************************************************************
    5411             :  *
    5412             :  *      QUERY:
    5413             :  *             CREATE FOREIGN DATA WRAPPER name options
    5414             :  *
    5415             :  *****************************************************************************/
    5416             : 
    5417             : CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
    5418             :                 {
    5419         192 :                     CreateFdwStmt *n = makeNode(CreateFdwStmt);
    5420             : 
    5421         192 :                     n->fdwname = $5;
    5422         192 :                     n->func_options = $6;
    5423         192 :                     n->options = $7;
    5424         192 :                     $$ = (Node *) n;
    5425             :                 }
    5426             :         ;
    5427             : 
    5428             : fdw_option:
    5429          56 :             HANDLER handler_name                { $$ = makeDefElem("handler", (Node *) $2, @1); }
    5430           0 :             | NO HANDLER                        { $$ = makeDefElem("handler", NULL, @1); }
    5431          46 :             | VALIDATOR handler_name            { $$ = makeDefElem("validator", (Node *) $2, @1); }
    5432           6 :             | NO VALIDATOR                      { $$ = makeDefElem("validator", NULL, @1); }
    5433             :         ;
    5434             : 
    5435             : fdw_options:
    5436          88 :             fdw_option                          { $$ = list_make1($1); }
    5437          20 :             | fdw_options fdw_option            { $$ = lappend($1, $2); }
    5438             :         ;
    5439             : 
    5440             : opt_fdw_options:
    5441          52 :             fdw_options                         { $$ = $1; }
    5442         232 :             | /*EMPTY*/                         { $$ = NIL; }
    5443             :         ;
    5444             : 
    5445             : /*****************************************************************************
    5446             :  *
    5447             :  *      QUERY :
    5448             :  *              ALTER FOREIGN DATA WRAPPER name options
    5449             :  *
    5450             :  ****************************************************************************/
    5451             : 
    5452             : AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
    5453             :                 {
    5454          86 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5455             : 
    5456          86 :                     n->fdwname = $5;
    5457          86 :                     n->func_options = $6;
    5458          86 :                     n->options = $7;
    5459          86 :                     $$ = (Node *) n;
    5460             :                 }
    5461             :             | ALTER FOREIGN DATA_P WRAPPER name fdw_options
    5462             :                 {
    5463          36 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5464             : 
    5465          36 :                     n->fdwname = $5;
    5466          36 :                     n->func_options = $6;
    5467          36 :                     n->options = NIL;
    5468          36 :                     $$ = (Node *) n;
    5469             :                 }
    5470             :         ;
    5471             : 
    5472             : /* Options definition for CREATE FDW, SERVER and USER MAPPING */
    5473             : create_generic_options:
    5474         716 :             OPTIONS '(' generic_option_list ')'         { $$ = $3; }
    5475       64168 :             | /*EMPTY*/                                 { $$ = NIL; }
    5476             :         ;
    5477             : 
    5478             : generic_option_list:
    5479             :             generic_option_elem
    5480             :                 {
    5481         716 :                     $$ = list_make1($1);
    5482             :                 }
    5483             :             | generic_option_list ',' generic_option_elem
    5484             :                 {
    5485         450 :                     $$ = lappend($1, $3);
    5486             :                 }
    5487             :         ;
    5488             : 
    5489             : /* Options definition for ALTER FDW, SERVER and USER MAPPING */
    5490             : alter_generic_options:
    5491         488 :             OPTIONS '(' alter_generic_option_list ')'       { $$ = $3; }
    5492             :         ;
    5493             : 
    5494             : alter_generic_option_list:
    5495             :             alter_generic_option_elem
    5496             :                 {
    5497         488 :                     $$ = list_make1($1);
    5498             :                 }
    5499             :             | alter_generic_option_list ',' alter_generic_option_elem
    5500             :                 {
    5501         168 :                     $$ = lappend($1, $3);
    5502             :                 }
    5503             :         ;
    5504             : 
    5505             : alter_generic_option_elem:
    5506             :             generic_option_elem
    5507             :                 {
    5508         200 :                     $$ = $1;
    5509             :                 }
    5510             :             | SET generic_option_elem
    5511             :                 {
    5512         128 :                     $$ = $2;
    5513         128 :                     $$->defaction = DEFELEM_SET;
    5514             :                 }
    5515             :             | ADD_P generic_option_elem
    5516             :                 {
    5517         202 :                     $$ = $2;
    5518         202 :                     $$->defaction = DEFELEM_ADD;
    5519             :                 }
    5520             :             | DROP generic_option_name
    5521             :                 {
    5522         126 :                     $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP, @2);
    5523             :                 }
    5524             :         ;
    5525             : 
    5526             : generic_option_elem:
    5527             :             generic_option_name generic_option_arg
    5528             :                 {
    5529        1696 :                     $$ = makeDefElem($1, $2, @1);
    5530             :                 }
    5531             :         ;
    5532             : 
    5533             : generic_option_name:
    5534        1822 :                 ColLabel            { $$ = $1; }
    5535             :         ;
    5536             : 
    5537             : /* We could use def_arg here, but the spec only requires string literals */
    5538             : generic_option_arg:
    5539        1696 :                 Sconst              { $$ = (Node *) makeString($1); }
    5540             :         ;
    5541             : 
    5542             : /*****************************************************************************
    5543             :  *
    5544             :  *      QUERY:
    5545             :  *             CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
    5546             :  *
    5547             :  *****************************************************************************/
    5548             : 
    5549             : CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
    5550             :                          FOREIGN DATA_P WRAPPER name create_generic_options
    5551             :                 {
    5552         252 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5553             : 
    5554         252 :                     n->servername = $3;
    5555         252 :                     n->servertype = $4;
    5556         252 :                     n->version = $5;
    5557         252 :                     n->fdwname = $9;
    5558         252 :                     n->options = $10;
    5559         252 :                     n->if_not_exists = false;
    5560         252 :                     $$ = (Node *) n;
    5561             :                 }
    5562             :                 | CREATE SERVER IF_P NOT EXISTS name opt_type opt_foreign_server_version
    5563             :                          FOREIGN DATA_P WRAPPER name create_generic_options
    5564             :                 {
    5565          24 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5566             : 
    5567          24 :                     n->servername = $6;
    5568          24 :                     n->servertype = $7;
    5569          24 :                     n->version = $8;
    5570          24 :                     n->fdwname = $12;
    5571          24 :                     n->options = $13;
    5572          24 :                     n->if_not_exists = true;
    5573          24 :                     $$ = (Node *) n;
    5574             :                 }
    5575             :         ;
    5576             : 
    5577             : opt_type:
    5578          18 :             TYPE_P Sconst           { $$ = $2; }
    5579         258 :             | /*EMPTY*/             { $$ = NULL; }
    5580             :         ;
    5581             : 
    5582             : 
    5583             : foreign_server_version:
    5584          66 :             VERSION_P Sconst        { $$ = $2; }
    5585           0 :         |   VERSION_P NULL_P        { $$ = NULL; }
    5586             :         ;
    5587             : 
    5588             : opt_foreign_server_version:
    5589          18 :             foreign_server_version  { $$ = $1; }
    5590         258 :             | /*EMPTY*/             { $$ = NULL; }
    5591             :         ;
    5592             : 
    5593             : /*****************************************************************************
    5594             :  *
    5595             :  *      QUERY :
    5596             :  *              ALTER SERVER name [VERSION] [OPTIONS]
    5597             :  *
    5598             :  ****************************************************************************/
    5599             : 
    5600             : AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
    5601             :                 {
    5602           6 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5603             : 
    5604           6 :                     n->servername = $3;
    5605           6 :                     n->version = $4;
    5606           6 :                     n->options = $5;
    5607           6 :                     n->has_version = true;
    5608           6 :                     $$ = (Node *) n;
    5609             :                 }
    5610             :             | ALTER SERVER name foreign_server_version
    5611             :                 {
    5612          42 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5613             : 
    5614          42 :                     n->servername = $3;
    5615          42 :                     n->version = $4;
    5616          42 :                     n->has_version = true;
    5617          42 :                     $$ = (Node *) n;
    5618             :                 }
    5619             :             | ALTER SERVER name alter_generic_options
    5620             :                 {
    5621         172 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5622             : 
    5623         172 :                     n->servername = $3;
    5624         172 :                     n->options = $4;
    5625         172 :                     $$ = (Node *) n;
    5626             :                 }
    5627             :         ;
    5628             : 
    5629             : /*****************************************************************************
    5630             :  *
    5631             :  *      QUERY:
    5632             :  *             CREATE FOREIGN TABLE relname (...) SERVER name (...)
    5633             :  *
    5634             :  *****************************************************************************/
    5635             : 
    5636             : CreateForeignTableStmt:
    5637             :         CREATE FOREIGN TABLE qualified_name
    5638             :             '(' OptTableElementList ')'
    5639             :             OptInherit SERVER name create_generic_options
    5640             :                 {
    5641         372 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5642             : 
    5643         372 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5644         372 :                     n->base.relation = $4;
    5645         372 :                     n->base.tableElts = $6;
    5646         372 :                     n->base.inhRelations = $8;
    5647         372 :                     n->base.ofTypename = NULL;
    5648         372 :                     n->base.constraints = NIL;
    5649         372 :                     n->base.options = NIL;
    5650         372 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5651         372 :                     n->base.tablespacename = NULL;
    5652         372 :                     n->base.if_not_exists = false;
    5653             :                     /* FDW-specific data */
    5654         372 :                     n->servername = $10;
    5655         372 :                     n->options = $11;
    5656         372 :                     $$ = (Node *) n;
    5657             :                 }
    5658             :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5659             :             '(' OptTableElementList ')'
    5660             :             OptInherit SERVER name create_generic_options
    5661             :                 {
    5662           0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5663             : 
    5664           0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5665           0 :                     n->base.relation = $7;
    5666           0 :                     n->base.tableElts = $9;
    5667           0 :                     n->base.inhRelations = $11;
    5668           0 :                     n->base.ofTypename = NULL;
    5669           0 :                     n->base.constraints = NIL;
    5670           0 :                     n->base.options = NIL;
    5671           0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5672           0 :                     n->base.tablespacename = NULL;
    5673           0 :                     n->base.if_not_exists = true;
    5674             :                     /* FDW-specific data */
    5675           0 :                     n->servername = $13;
    5676           0 :                     n->options = $14;
    5677           0 :                     $$ = (Node *) n;
    5678             :                 }
    5679             :         | CREATE FOREIGN TABLE qualified_name
    5680             :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5681             :             SERVER name create_generic_options
    5682             :                 {
    5683          90 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5684             : 
    5685          90 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5686          90 :                     n->base.relation = $4;
    5687          90 :                     n->base.inhRelations = list_make1($7);
    5688          90 :                     n->base.tableElts = $8;
    5689          90 :                     n->base.partbound = $9;
    5690          90 :                     n->base.ofTypename = NULL;
    5691          90 :                     n->base.constraints = NIL;
    5692          90 :                     n->base.options = NIL;
    5693          90 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5694          90 :                     n->base.tablespacename = NULL;
    5695          90 :                     n->base.if_not_exists = false;
    5696             :                     /* FDW-specific data */
    5697          90 :                     n->servername = $11;
    5698          90 :                     n->options = $12;
    5699          90 :                     $$ = (Node *) n;
    5700             :                 }
    5701             :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5702             :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5703             :             SERVER name create_generic_options
    5704             :                 {
    5705           0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5706             : 
    5707           0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5708           0 :                     n->base.relation = $7;
    5709           0 :                     n->base.inhRelations = list_make1($10);
    5710           0 :                     n->base.tableElts = $11;
    5711           0 :                     n->base.partbound = $12;
    5712           0 :                     n->base.ofTypename = NULL;
    5713           0 :                     n->base.constraints = NIL;
    5714           0 :                     n->base.options = NIL;
    5715           0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5716           0 :                     n->base.tablespacename = NULL;
    5717           0 :                     n->base.if_not_exists = true;
    5718             :                     /* FDW-specific data */
    5719           0 :                     n->servername = $14;
    5720           0 :                     n->options = $15;
    5721           0 :                     $$ = (Node *) n;
    5722             :                 }
    5723             :         ;
    5724             : 
    5725             : /*****************************************************************************
    5726             :  *
    5727             :  *      QUERY:
    5728             :  *              IMPORT FOREIGN SCHEMA remote_schema
    5729             :  *              [ { LIMIT TO | EXCEPT } ( table_list ) ]
    5730             :  *              FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
    5731             :  *
    5732             :  ****************************************************************************/
    5733             : 
    5734             : ImportForeignSchemaStmt:
    5735             :         IMPORT_P FOREIGN SCHEMA name import_qualification
    5736             :           FROM SERVER name INTO name create_generic_options
    5737             :             {
    5738          48 :                 ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
    5739             : 
    5740          48 :                 n->server_name = $8;
    5741          48 :                 n->remote_schema = $4;
    5742          48 :                 n->local_schema = $10;
    5743          48 :                 n->list_type = $5->type;
    5744          48 :                 n->table_list = $5->table_names;
    5745          48 :                 n->options = $11;
    5746          48 :                 $$ = (Node *) n;
    5747             :             }
    5748             :         ;
    5749             : 
    5750             : import_qualification_type:
    5751          14 :         LIMIT TO                { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
    5752          14 :         | EXCEPT                { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
    5753             :         ;
    5754             : 
    5755             : import_qualification:
    5756             :         import_qualification_type '(' relation_expr_list ')'
    5757             :             {
    5758          28 :                 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
    5759             : 
    5760          28 :                 n->type = $1;
    5761          28 :                 n->table_names = $3;
    5762          28 :                 $$ = n;
    5763             :             }
    5764             :         | /*EMPTY*/
    5765             :             {
    5766          20 :                 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
    5767          20 :                 n->type = FDW_IMPORT_SCHEMA_ALL;
    5768          20 :                 n->table_names = NIL;
    5769          20 :                 $$ = n;
    5770             :             }
    5771             :         ;
    5772             : 
    5773             : /*****************************************************************************
    5774             :  *
    5775             :  *      QUERY:
    5776             :  *             CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
    5777             :  *
    5778             :  *****************************************************************************/
    5779             : 
    5780             : CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
    5781             :                 {
    5782         236 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5783             : 
    5784         236 :                     n->user = $5;
    5785         236 :                     n->servername = $7;
    5786         236 :                     n->options = $8;
    5787         236 :                     n->if_not_exists = false;
    5788         236 :                     $$ = (Node *) n;
    5789             :                 }
    5790             :                 | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
    5791             :                 {
    5792           6 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5793             : 
    5794           6 :                     n->user = $8;
    5795           6 :                     n->servername = $10;
    5796           6 :                     n->options = $11;
    5797           6 :                     n->if_not_exists = true;
    5798           6 :                     $$ = (Node *) n;
    5799             :                 }
    5800             :         ;
    5801             : 
    5802             : /* User mapping authorization identifier */
    5803         432 : auth_ident: RoleSpec            { $$ = $1; }
    5804          46 :             | USER              { $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1); }
    5805             :         ;
    5806             : 
    5807             : /*****************************************************************************
    5808             :  *
    5809             :  *      QUERY :
    5810             :  *              DROP USER MAPPING FOR auth_ident SERVER name
    5811             :  *
    5812             :  * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
    5813             :  * only pro forma; but the SQL standard doesn't show one.
    5814             :  ****************************************************************************/
    5815             : 
    5816             : DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
    5817             :                 {
    5818          88 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5819             : 
    5820          88 :                     n->user = $5;
    5821          88 :                     n->servername = $7;
    5822          88 :                     n->missing_ok = false;
    5823          88 :                     $$ = (Node *) n;
    5824             :                 }
    5825             :                 |  DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
    5826             :                 {
    5827          38 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5828             : 
    5829          38 :                     n->user = $7;
    5830          38 :                     n->servername = $9;
    5831          38 :                     n->missing_ok = true;
    5832          38 :                     $$ = (Node *) n;
    5833             :                 }
    5834             :         ;
    5835             : 
    5836             : /*****************************************************************************
    5837             :  *
    5838             :  *      QUERY :
    5839             :  *              ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
    5840             :  *
    5841             :  ****************************************************************************/
    5842             : 
    5843             : AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
    5844             :                 {
    5845         110 :                     AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
    5846             : 
    5847         110 :                     n->user = $5;
    5848         110 :                     n->servername = $7;
    5849         110 :                     n->options = $8;
    5850         110 :                     $$ = (Node *) n;
    5851             :                 }
    5852             :         ;
    5853             : 
    5854             : /*****************************************************************************
    5855             :  *
    5856             :  *      QUERIES:
    5857             :  *              CREATE POLICY name ON table
    5858             :  *                  [AS { PERMISSIVE | RESTRICTIVE } ]
    5859             :  *                  [FOR { SELECT | INSERT | UPDATE | DELETE } ]
    5860             :  *                  [TO role, ...]
    5861             :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    5862             :  *              ALTER POLICY name ON table [TO role, ...]
    5863             :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    5864             :  *
    5865             :  *****************************************************************************/
    5866             : 
    5867             : CreatePolicyStmt:
    5868             :             CREATE POLICY name ON qualified_name RowSecurityDefaultPermissive
    5869             :                 RowSecurityDefaultForCmd RowSecurityDefaultToRole
    5870             :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    5871             :                 {
    5872         658 :                     CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
    5873             : 
    5874         658 :                     n->policy_name = $3;
    5875         658 :                     n->table = $5;
    5876         658 :                     n->permissive = $6;
    5877         658 :                     n->cmd_name = $7;
    5878         658 :                     n->roles = $8;
    5879         658 :                     n->qual = $9;
    5880         658 :                     n->with_check = $10;
    5881         658 :                     $$ = (Node *) n;
    5882             :                 }
    5883             :         ;
    5884             : 
    5885             : AlterPolicyStmt:
    5886             :             ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
    5887             :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    5888             :                 {
    5889          84 :                     AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
    5890             : 
    5891          84 :                     n->policy_name = $3;
    5892          84 :                     n->table = $5;
    5893          84 :                     n->roles = $6;
    5894          84 :                     n->qual = $7;
    5895          84 :                     n->with_check = $8;
    5896          84 :                     $$ = (Node *) n;
    5897             :                 }
    5898             :         ;
    5899             : 
    5900             : RowSecurityOptionalExpr:
    5901         684 :             USING '(' a_expr ')'    { $$ = $3; }
    5902          58 :             | /* EMPTY */           { $$ = NULL; }
    5903             :         ;
    5904             : 
    5905             : RowSecurityOptionalWithCheck:
    5906         122 :             WITH CHECK '(' a_expr ')'       { $$ = $4; }
    5907         620 :             | /* EMPTY */                   { $$ = NULL; }
    5908             :         ;
    5909             : 
    5910             : RowSecurityDefaultToRole:
    5911         124 :             TO role_list            { $$ = $2; }
    5912         534 :             | /* EMPTY */           { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
    5913             :         ;
    5914             : 
    5915             : RowSecurityOptionalToRole:
    5916          12 :             TO role_list            { $$ = $2; }
    5917          72 :             | /* EMPTY */           { $$ = NULL; }
    5918             :         ;
    5919             : 
    5920             : RowSecurityDefaultPermissive:
    5921             :             AS IDENT
    5922             :                 {
    5923          86 :                     if (strcmp($2, "permissive") == 0)
    5924          24 :                         $$ = true;
    5925          62 :                     else if (strcmp($2, "restrictive") == 0)
    5926          56 :                         $$ = false;
    5927             :                     else
    5928           6 :                         ereport(ERROR,
    5929             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    5930             :                                  errmsg("unrecognized row security option \"%s\"", $2),
    5931             :                                  errhint("Only PERMISSIVE or RESTRICTIVE policies are supported currently."),
    5932             :                                  parser_errposition(@2)));
    5933             : 
    5934             :                 }
    5935         578 :             | /* EMPTY */           { $$ = true; }
    5936             :         ;
    5937             : 
    5938             : RowSecurityDefaultForCmd:
    5939         314 :             FOR row_security_cmd    { $$ = $2; }
    5940         344 :             | /* EMPTY */           { $$ = "all"; }
    5941             :         ;
    5942             : 
    5943             : row_security_cmd:
    5944          44 :             ALL             { $$ = "all"; }
    5945         106 :         |   SELECT          { $$ = "select"; }
    5946          44 :         |   INSERT          { $$ = "insert"; }
    5947          78 :         |   UPDATE          { $$ = "update"; }
    5948          42 :         |   DELETE_P        { $$ = "delete"; }
    5949             :         ;
    5950             : 
    5951             : /*****************************************************************************
    5952             :  *
    5953             :  *      QUERY:
    5954             :  *             CREATE ACCESS METHOD name HANDLER handler_name
    5955             :  *
    5956             :  *****************************************************************************/
    5957             : 
    5958             : CreateAmStmt: CREATE ACCESS METHOD name TYPE_P am_type HANDLER handler_name
    5959             :                 {
    5960          62 :                     CreateAmStmt *n = makeNode(CreateAmStmt);
    5961             : 
    5962          62 :                     n->amname = $4;
    5963          62 :                     n->handler_name = $8;
    5964          62 :                     n->amtype = $6;
    5965          62 :                     $$ = (Node *) n;
    5966             :                 }
    5967             :         ;
    5968             : 
    5969             : am_type:
    5970          34 :             INDEX           { $$ = AMTYPE_INDEX; }
    5971          28 :         |   TABLE           { $$ = AMTYPE_TABLE; }
    5972             :         ;
    5973             : 
    5974             : /*****************************************************************************
    5975             :  *
    5976             :  *      QUERIES :
    5977             :  *              CREATE TRIGGER ...
    5978             :  *
    5979             :  *****************************************************************************/
    5980             : 
    5981             : CreateTrigStmt:
    5982             :             CREATE opt_or_replace TRIGGER name TriggerActionTime TriggerEvents ON
    5983             :             qualified_name TriggerReferencing TriggerForSpec TriggerWhen
    5984             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    5985             :                 {
    5986        3064 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    5987             : 
    5988        3064 :                     n->replace = $2;
    5989        3064 :                     n->isconstraint = false;
    5990        3064 :                     n->trigname = $4;
    5991        3064 :                     n->relation = $8;
    5992        3064 :                     n->funcname = $14;
    5993        3064 :                     n->args = $16;
    5994        3064 :                     n->row = $10;
    5995        3064 :                     n->timing = $5;
    5996        3064 :                     n->events = intVal(linitial($6));
    5997        3064 :                     n->columns = (List *) lsecond($6);
    5998        3064 :                     n->whenClause = $11;
    5999        3064 :                     n->transitionRels = $9;
    6000        3064 :                     n->deferrable = false;
    6001        3064 :                     n->initdeferred = false;
    6002        3064 :                     n->constrrel = NULL;
    6003        3064 :                     $$ = (Node *) n;
    6004             :                 }
    6005             :           | CREATE opt_or_replace CONSTRAINT TRIGGER name AFTER TriggerEvents ON
    6006             :             qualified_name OptConstrFromTable ConstraintAttributeSpec
    6007             :             FOR EACH ROW TriggerWhen
    6008             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    6009             :                 {
    6010          54 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    6011             : 
    6012          54 :                     n->replace = $2;
    6013          54 :                     if (n->replace) /* not supported, see CreateTrigger */
    6014           0 :                         ereport(ERROR,
    6015             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6016             :                                  errmsg("CREATE OR REPLACE CONSTRAINT TRIGGER is not supported"),
    6017             :                                  parser_errposition(@1)));
    6018          54 :                     n->isconstraint = true;
    6019          54 :                     n->trigname = $5;
    6020          54 :                     n->relation = $9;
    6021          54 :                     n->funcname = $18;
    6022          54 :                     n->args = $20;
    6023          54 :                     n->row = true;
    6024          54 :                     n->timing = TRIGGER_TYPE_AFTER;
    6025          54 :                     n->events = intVal(linitial($7));
    6026          54 :                     n->columns = (List *) lsecond($7);
    6027          54 :                     n->whenClause = $15;
    6028          54 :                     n->transitionRels = NIL;
    6029          54 :                     processCASbits($11, @11, "TRIGGER",
    6030             :                                    &n->deferrable, &n->initdeferred, NULL,
    6031             :                                    NULL, NULL, yyscanner);
    6032          54 :                     n->constrrel = $10;
    6033          54 :                     $$ = (Node *) n;
    6034             :                 }
    6035             :         ;
    6036             : 
    6037             : TriggerActionTime:
    6038        1392 :             BEFORE                              { $$ = TRIGGER_TYPE_BEFORE; }
    6039        1540 :             | AFTER                             { $$ = TRIGGER_TYPE_AFTER; }
    6040         144 :             | INSTEAD OF                        { $$ = TRIGGER_TYPE_INSTEAD; }
    6041             :         ;
    6042             : 
    6043             : TriggerEvents:
    6044             :             TriggerOneEvent
    6045        3130 :                 { $$ = $1; }
    6046             :             | TriggerEvents OR TriggerOneEvent
    6047             :                 {
    6048        1078 :                     int         events1 = intVal(linitial($1));
    6049        1078 :                     int         events2 = intVal(linitial($3));
    6050        1078 :                     List       *columns1 = (List *) lsecond($1);
    6051        1078 :                     List       *columns2 = (List *) lsecond($3);
    6052             : 
    6053        1078 :                     if (events1 & events2)
    6054           6 :                         parser_yyerror("duplicate trigger events specified");
    6055             :                     /*
    6056             :                      * concat'ing the columns lists loses information about
    6057             :                      * which columns went with which event, but so long as
    6058             :                      * only UPDATE carries columns and we disallow multiple
    6059             :                      * UPDATE items, it doesn't matter.  Command execution
    6060             :                      * should just ignore the columns for non-UPDATE events.
    6061             :                      */
    6062        1072 :                     $$ = list_make2(makeInteger(events1 | events2),
    6063             :                                     list_concat(columns1, columns2));
    6064             :                 }
    6065             :         ;
    6066             : 
    6067             : TriggerOneEvent:
    6068             :             INSERT
    6069        1558 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
    6070             :             | DELETE_P
    6071         864 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
    6072             :             | UPDATE
    6073        1654 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
    6074             :             | UPDATE OF columnList
    6075          94 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
    6076             :             | TRUNCATE
    6077          38 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
    6078             :         ;
    6079             : 
    6080             : TriggerReferencing:
    6081         430 :             REFERENCING TriggerTransitions          { $$ = $2; }
    6082        2634 :             | /*EMPTY*/                             { $$ = NIL; }
    6083             :         ;
    6084             : 
    6085             : TriggerTransitions:
    6086         430 :             TriggerTransition                       { $$ = list_make1($1); }
    6087         138 :             | TriggerTransitions TriggerTransition  { $$ = lappend($1, $2); }
    6088             :         ;
    6089             : 
    6090             : TriggerTransition:
    6091             :             TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
    6092             :                 {
    6093         568 :                     TriggerTransition *n = makeNode(TriggerTransition);
    6094             : 
    6095         568 :                     n->name = $4;
    6096         568 :                     n->isNew = $1;
    6097         568 :                     n->isTable = $2;
    6098         568 :                     $$ = (Node *) n;
    6099             :                 }
    6100             :         ;
    6101             : 
    6102             : TransitionOldOrNew:
    6103         312 :             NEW                                     { $$ = true; }
    6104         256 :             | OLD                                   { $$ = false; }
    6105             :         ;
    6106             : 
    6107             : TransitionRowOrTable:
    6108         568 :             TABLE                                   { $$ = true; }
    6109             :             /*
    6110             :              * According to the standard, lack of a keyword here implies ROW.
    6111             :              * Support for that would require prohibiting ROW entirely here,
    6112             :              * reserving the keyword ROW, and/or requiring AS (instead of
    6113             :              * allowing it to be optional, as the standard specifies) as the
    6114             :              * next token.  Requiring ROW seems cleanest and easiest to
    6115             :              * explain.
    6116             :              */
    6117           0 :             | ROW                                   { $$ = false; }
    6118             :         ;
    6119             : 
    6120             : TransitionRelName:
    6121         568 :             ColId                                   { $$ = $1; }
    6122             :         ;
    6123             : 
    6124             : TriggerForSpec:
    6125             :             FOR TriggerForOptEach TriggerForType
    6126             :                 {
    6127        2836 :                     $$ = $3;
    6128             :                 }
    6129             :             | /* EMPTY */
    6130             :                 {
    6131             :                     /*
    6132             :                      * If ROW/STATEMENT not specified, default to
    6133             :                      * STATEMENT, per SQL
    6134             :                      */
    6135         228 :                     $$ = false;
    6136             :                 }
    6137             :         ;
    6138             : 
    6139             : TriggerForOptEach:
    6140             :             EACH
    6141             :             | /*EMPTY*/
    6142             :         ;
    6143             : 
    6144             : TriggerForType:
    6145        2050 :             ROW                                     { $$ = true; }
    6146         786 :             | STATEMENT                             { $$ = false; }
    6147             :         ;
    6148             : 
    6149             : TriggerWhen:
    6150         152 :             WHEN '(' a_expr ')'                     { $$ = $3; }
    6151        2966 :             | /*EMPTY*/                             { $$ = NULL; }
    6152             :         ;
    6153             : 
    6154             : FUNCTION_or_PROCEDURE:
    6155             :             FUNCTION
    6156             :         |   PROCEDURE
    6157             :         ;
    6158             : 
    6159             : TriggerFuncArgs:
    6160         574 :             TriggerFuncArg                          { $$ = list_make1($1); }
    6161         264 :             | TriggerFuncArgs ',' TriggerFuncArg    { $$ = lappend($1, $3); }
    6162        2544 :             | /*EMPTY*/                             { $$ = NIL; }
    6163             :         ;
    6164             : 
    6165             : TriggerFuncArg:
    6166             :             Iconst
    6167             :                 {
    6168         102 :                     $$ = (Node *) makeString(psprintf("%d", $1));
    6169             :                 }
    6170           0 :             | FCONST                                { $$ = (Node *) makeString($1); }
    6171         696 :             | Sconst                                { $$ = (Node *) makeString($1); }
    6172          40 :             | ColLabel                              { $$ = (Node *) makeString($1); }
    6173             :         ;
    6174             : 
    6175             : OptConstrFromTable:
    6176          12 :             FROM qualified_name                     { $$ = $2; }
    6177          42 :             | /*EMPTY*/                             { $$ = NULL; }
    6178             :         ;
    6179             : 
    6180             : ConstraintAttributeSpec:
    6181             :             /*EMPTY*/
    6182       16136 :                 { $$ = 0; }
    6183             :             | ConstraintAttributeSpec ConstraintAttributeElem
    6184             :                 {
    6185             :                     /*
    6186             :                      * We must complain about conflicting options.
    6187             :                      * We could, but choose not to, complain about redundant
    6188             :                      * options (ie, where $2's bit is already set in $1).
    6189             :                      */
    6190        1270 :                     int     newspec = $1 | $2;
    6191             : 
    6192             :                     /* special message for this case */
    6193        1270 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
    6194           6 :                         ereport(ERROR,
    6195             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6196             :                                  errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
    6197             :                                  parser_errposition(@2)));
    6198             :                     /* generic message for other conflicts */
    6199        1264 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
    6200        1264 :                         (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED) ||
    6201        1264 :                         (newspec & (CAS_NOT_ENFORCED | CAS_ENFORCED)) == (CAS_NOT_ENFORCED | CAS_ENFORCED))
    6202           0 :                         ereport(ERROR,
    6203             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6204             :                                  errmsg("conflicting constraint properties"),
    6205             :                                  parser_errposition(@2)));
    6206        1264 :                     $$ = newspec;
    6207             :                 }
    6208             :         ;
    6209             : 
    6210             : ConstraintAttributeElem:
    6211          36 :             NOT DEFERRABLE                  { $$ = CAS_NOT_DEFERRABLE; }
    6212         210 :             | DEFERRABLE                    { $$ = CAS_DEFERRABLE; }
    6213          30 :             | INITIALLY IMMEDIATE           { $$ = CAS_INITIALLY_IMMEDIATE; }
    6214         162 :             | INITIALLY DEFERRED            { $$ = CAS_INITIALLY_DEFERRED; }
    6215         516 :             | NOT VALID                     { $$ = CAS_NOT_VALID; }
    6216         190 :             | NO INHERIT                    { $$ = CAS_NO_INHERIT; }
    6217          84 :             | NOT ENFORCED                  { $$ = CAS_NOT_ENFORCED; }
    6218          42 :             | ENFORCED                      { $$ = CAS_ENFORCED; }
    6219             :         ;
    6220             : 
    6221             : 
    6222             : /*****************************************************************************
    6223             :  *
    6224             :  *      QUERIES :
    6225             :  *              CREATE EVENT TRIGGER ...
    6226             :  *              ALTER EVENT TRIGGER ...
    6227             :  *
    6228             :  *****************************************************************************/
    6229             : 
    6230             : CreateEventTrigStmt:
    6231             :             CREATE EVENT TRIGGER name ON ColLabel
    6232             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    6233             :                 {
    6234          98 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6235             : 
    6236          98 :                     n->trigname = $4;
    6237          98 :                     n->eventname = $6;
    6238          98 :                     n->whenclause = NULL;
    6239          98 :                     n->funcname = $9;
    6240          98 :                     $$ = (Node *) n;
    6241             :                 }
    6242             :           | CREATE EVENT TRIGGER name ON ColLabel
    6243             :             WHEN event_trigger_when_list
    6244             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    6245             :                 {
    6246          98 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6247             : 
    6248          98 :                     n->trigname = $4;
    6249          98 :                     n->eventname = $6;
    6250          98 :                     n->whenclause = $8;
    6251          98 :                     n->funcname = $11;
    6252          98 :                     $$ = (Node *) n;
    6253             :                 }
    6254             :         ;
    6255             : 
    6256             : event_trigger_when_list:
    6257             :           event_trigger_when_item
    6258          98 :             { $$ = list_make1($1); }
    6259             :         | event_trigger_when_list AND event_trigger_when_item
    6260           6 :             { $$ = lappend($1, $3); }
    6261             :         ;
    6262             : 
    6263             : event_trigger_when_item:
    6264             :         ColId IN_P '(' event_trigger_value_list ')'
    6265         104 :             { $$ = makeDefElem($1, (Node *) $4, @1); }
    6266             :         ;
    6267             : 
    6268             : event_trigger_value_list:
    6269             :           SCONST
    6270         104 :             { $$ = list_make1(makeString($1)); }
    6271             :         | event_trigger_value_list ',' SCONST
    6272          66 :             { $$ = lappend($1, makeString($3)); }
    6273             :         ;
    6274             : 
    6275             : AlterEventTrigStmt:
    6276             :             ALTER EVENT TRIGGER name enable_trigger
    6277             :                 {
    6278          48 :                     AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
    6279             : 
    6280          48 :                     n->trigname = $4;
    6281          48 :                     n->tgenabled = $5;
    6282          48 :                     $$ = (Node *) n;
    6283             :                 }
    6284             :         ;
    6285             : 
    6286             : enable_trigger:
    6287           6 :             ENABLE_P                    { $$ = TRIGGER_FIRES_ON_ORIGIN; }
    6288           6 :             | ENABLE_P REPLICA          { $$ = TRIGGER_FIRES_ON_REPLICA; }
    6289          16 :             | ENABLE_P ALWAYS           { $$ = TRIGGER_FIRES_ALWAYS; }
    6290          20 :             | DISABLE_P                 { $$ = TRIGGER_DISABLED; }
    6291             :         ;
    6292             : 
    6293             : /*****************************************************************************
    6294             :  *
    6295             :  *      QUERY :
    6296             :  *              CREATE ASSERTION ...
    6297             :  *
    6298             :  *****************************************************************************/
    6299             : 
    6300             : CreateAssertionStmt:
    6301             :             CREATE ASSERTION any_name CHECK '(' a_expr ')' ConstraintAttributeSpec
    6302             :                 {
    6303           0 :                     ereport(ERROR,
    6304             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6305             :                              errmsg("CREATE ASSERTION is not yet implemented"),
    6306             :                              parser_errposition(@1)));
    6307             : 
    6308             :                     $$ = NULL;
    6309             :                 }
    6310             :         ;
    6311             : 
    6312             : 
    6313             : /*****************************************************************************
    6314             :  *
    6315             :  *      QUERY :
    6316             :  *              define (aggregate,operator,type)
    6317             :  *
    6318             :  *****************************************************************************/
    6319             : 
    6320             : DefineStmt:
    6321             :             CREATE opt_or_replace AGGREGATE func_name aggr_args definition
    6322             :                 {
    6323         544 :                     DefineStmt *n = makeNode(DefineStmt);
    6324             : 
    6325         544 :                     n->kind = OBJECT_AGGREGATE;
    6326         544 :                     n->oldstyle = false;
    6327         544 :                     n->replace = $2;
    6328         544 :                     n->defnames = $4;
    6329         544 :                     n->args = $5;
    6330         544 :                     n->definition = $6;
    6331         544 :                     $$ = (Node *) n;
    6332             :                 }
    6333             :             | CREATE opt_or_replace AGGREGATE func_name old_aggr_definition
    6334             :                 {
    6335             :                     /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
    6336         362 :                     DefineStmt *n = makeNode(DefineStmt);
    6337             : 
    6338         362 :                     n->kind = OBJECT_AGGREGATE;
    6339         362 :                     n->oldstyle = true;
    6340         362 :                     n->replace = $2;
    6341         362 :                     n->defnames = $4;
    6342         362 :                     n->args = NIL;
    6343         362 :                     n->definition = $5;
    6344         362 :                     $$ = (Node *) n;
    6345             :                 }
    6346             :             | CREATE OPERATOR any_operator definition
    6347             :                 {
    6348        1586 :                     DefineStmt *n = makeNode(DefineStmt);
    6349             : 
    6350        1586 :                     n->kind = OBJECT_OPERATOR;
    6351        1586 :                     n->oldstyle = false;
    6352        1586 :                     n->defnames = $3;
    6353        1586 :                     n->args = NIL;
    6354        1586 :                     n->definition = $4;
    6355        1586 :                     $$ = (Node *) n;
    6356             :                 }
    6357             :             | CREATE TYPE_P any_name definition
    6358             :                 {
    6359         214 :                     DefineStmt *n = makeNode(DefineStmt);
    6360             : 
    6361         214 :                     n->kind = OBJECT_TYPE;
    6362         214 :                     n->oldstyle = false;
    6363         214 :                     n->defnames = $3;
    6364         214 :                     n->args = NIL;
    6365         214 :                     n->definition = $4;
    6366         214 :                     $$ = (Node *) n;
    6367             :                 }
    6368             :             | CREATE TYPE_P any_name
    6369             :                 {
    6370             :                     /* Shell type (identified by lack of definition) */
    6371         154 :                     DefineStmt *n = makeNode(DefineStmt);
    6372             : 
    6373         154 :                     n->kind = OBJECT_TYPE;
    6374         154 :                     n->oldstyle = false;
    6375         154 :                     n->defnames = $3;
    6376         154 :                     n->args = NIL;
    6377         154 :                     n->definition = NIL;
    6378         154 :                     $$ = (Node *) n;
    6379             :                 }
    6380             :             | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
    6381             :                 {
    6382        3486 :                     CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
    6383             : 
    6384             :                     /* can't use qualified_name, sigh */
    6385        3486 :                     n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
    6386        3486 :                     n->coldeflist = $6;
    6387        3486 :                     $$ = (Node *) n;
    6388             :                 }
    6389             :             | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
    6390             :                 {
    6391         194 :                     CreateEnumStmt *n = makeNode(CreateEnumStmt);
    6392             : 
    6393         194 :                     n->typeName = $3;
    6394         194 :                     n->vals = $7;
    6395         194 :                     $$ = (Node *) n;
    6396             :                 }
    6397             :             | CREATE TYPE_P any_name AS RANGE definition
    6398             :                 {
    6399         168 :                     CreateRangeStmt *n = makeNode(CreateRangeStmt);
    6400             : 
    6401         168 :                     n->typeName = $3;
    6402         168 :                     n->params = $6;
    6403         168 :                     $$ = (Node *) n;
    6404             :                 }
    6405             :             | CREATE TEXT_P SEARCH PARSER any_name definition
    6406             :                 {
    6407          40 :                     DefineStmt *n = makeNode(DefineStmt);
    6408             : 
    6409          40 :                     n->kind = OBJECT_TSPARSER;
    6410          40 :                     n->args = NIL;
    6411          40 :                     n->defnames = $5;
    6412          40 :                     n->definition = $6;
    6413          40 :                     $$ = (Node *) n;
    6414             :                 }
    6415             :             | CREATE TEXT_P SEARCH DICTIONARY any_name definition
    6416             :                 {
    6417        2554 :                     DefineStmt *n = makeNode(DefineStmt);
    6418             : 
    6419        2554 :                     n->kind = OBJECT_TSDICTIONARY;
    6420        2554 :                     n->args = NIL;
    6421        2554 :                     n->defnames = $5;
    6422        2554 :                     n->definition = $6;
    6423        2554 :                     $$ = (Node *) n;
    6424             :                 }
    6425             :             | CREATE TEXT_P SEARCH TEMPLATE any_name definition
    6426             :                 {
    6427         130 :                     DefineStmt *n = makeNode(DefineStmt);
    6428             : 
    6429         130 :                     n->kind = OBJECT_TSTEMPLATE;
    6430         130 :                     n->args = NIL;
    6431         130 :                     n->defnames = $5;
    6432         130 :                     n->definition = $6;
    6433         130 :                     $$ = (Node *) n;
    6434             :                 }
    6435             :             | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
    6436             :                 {
    6437        2496 :                     DefineStmt *n = makeNode(DefineStmt);
    6438             : 
    6439        2496 :                     n->kind = OBJECT_TSCONFIGURATION;
    6440        2496 :                     n->args = NIL;
    6441        2496 :                     n->defnames = $5;
    6442        2496 :                     n->definition = $6;
    6443        2496 :                     $$ = (Node *) n;
    6444             :                 }
    6445             :             | CREATE COLLATION any_name definition
    6446             :                 {
    6447         292 :                     DefineStmt *n = makeNode(DefineStmt);
    6448             : 
    6449         292 :                     n->kind = OBJECT_COLLATION;
    6450         292 :                     n->args = NIL;
    6451         292 :                     n->defnames = $3;
    6452         292 :                     n->definition = $4;
    6453         292 :                     $$ = (Node *) n;
    6454             :                 }
    6455             :             | CREATE COLLATION IF_P NOT EXISTS any_name definition
    6456             :                 {
    6457          18 :                     DefineStmt *n = makeNode(DefineStmt);
    6458             : 
    6459          18 :                     n->kind = OBJECT_COLLATION;
    6460          18 :                     n->args = NIL;
    6461          18 :                     n->defnames = $6;
    6462          18 :                     n->definition = $7;
    6463          18 :                     n->if_not_exists = true;
    6464          18 :                     $$ = (Node *) n;
    6465             :                 }
    6466             :             | CREATE COLLATION any_name FROM any_name
    6467             :                 {
    6468          54 :                     DefineStmt *n = makeNode(DefineStmt);
    6469             : 
    6470          54 :                     n->kind = OBJECT_COLLATION;
    6471          54 :                     n->args = NIL;
    6472          54 :                     n->defnames = $3;
    6473          54 :                     n->definition = list_make1(makeDefElem("from", (Node *) $5, @5));
    6474          54 :                     $$ = (Node *) n;
    6475             :                 }
    6476             :             | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
    6477             :                 {
    6478           0 :                     DefineStmt *n = makeNode(DefineStmt);
    6479             : 
    6480           0 :                     n->kind = OBJECT_COLLATION;
    6481           0 :                     n->args = NIL;
    6482           0 :                     n->defnames = $6;
    6483           0 :                     n->definition = list_make1(makeDefElem("from", (Node *) $8, @8));
    6484           0 :                     n->if_not_exists = true;
    6485           0 :                     $$ = (Node *) n;
    6486             :                 }
    6487             :         ;
    6488             : 
    6489        8994 : definition: '(' def_list ')'                        { $$ = $2; }
    6490             :         ;
    6491             : 
    6492        8994 : def_list:   def_elem                                { $$ = list_make1($1); }
    6493       14004 :             | def_list ',' def_elem                 { $$ = lappend($1, $3); }
    6494             :         ;
    6495             : 
    6496             : def_elem:   ColLabel '=' def_arg
    6497             :                 {
    6498       22668 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6499             :                 }
    6500             :             | ColLabel
    6501             :                 {
    6502         330 :                     $$ = makeDefElem($1, NULL, @1);
    6503             :                 }
    6504             :         ;
    6505             : 
    6506             : /* Note: any simple identifier will be returned as a type name! */
    6507       18468 : def_arg:    func_type                       { $$ = (Node *) $1; }
    6508        3626 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
    6509        1174 :             | qual_all_Op                   { $$ = (Node *) $1; }
    6510        1294 :             | NumericOnly                   { $$ = (Node *) $1; }
    6511        1848 :             | Sconst                        { $$ = (Node *) makeString($1); }
    6512         132 :             | NONE                          { $$ = (Node *) makeString(pstrdup($1)); }
    6513             :         ;
    6514             : 
    6515         362 : old_aggr_definition: '(' old_aggr_list ')'          { $$ = $2; }
    6516             :         ;
    6517             : 
    6518         362 : old_aggr_list: old_aggr_elem                        { $$ = list_make1($1); }
    6519        1292 :             | old_aggr_list ',' old_aggr_elem       { $$ = lappend($1, $3); }
    6520             :         ;
    6521             : 
    6522             : /*
    6523             :  * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
    6524             :  * the item names needed in old aggregate definitions are likely to become
    6525             :  * SQL keywords.
    6526             :  */
    6527             : old_aggr_elem:  IDENT '=' def_arg
    6528             :                 {
    6529        1654 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6530             :                 }
    6531             :         ;
    6532             : 
    6533             : opt_enum_val_list:
    6534         186 :         enum_val_list                           { $$ = $1; }
    6535           8 :         | /*EMPTY*/                             { $$ = NIL; }
    6536             :         ;
    6537             : 
    6538             : enum_val_list:  Sconst
    6539         186 :                 { $$ = list_make1(makeString($1)); }
    6540             :             | enum_val_list ',' Sconst
    6541       10394 :                 { $$ = lappend($1, makeString($3)); }
    6542             :         ;
    6543             : 
    6544             : /*****************************************************************************
    6545             :  *
    6546             :  *  ALTER TYPE enumtype ADD ...
    6547             :  *
    6548             :  *****************************************************************************/
    6549             : 
    6550             : AlterEnumStmt:
    6551             :         ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
    6552             :             {
    6553         154 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6554             : 
    6555         154 :                 n->typeName = $3;
    6556         154 :                 n->oldVal = NULL;
    6557         154 :                 n->newVal = $7;
    6558         154 :                 n->newValNeighbor = NULL;
    6559         154 :                 n->newValIsAfter = true;
    6560         154 :                 n->skipIfNewValExists = $6;
    6561         154 :                 $$ = (Node *) n;
    6562             :             }
    6563             :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
    6564             :             {
    6565         194 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6566             : 
    6567         194 :                 n->typeName = $3;
    6568         194 :                 n->oldVal = NULL;
    6569         194 :                 n->newVal = $7;
    6570         194 :                 n->newValNeighbor = $9;
    6571         194 :                 n->newValIsAfter = false;
    6572         194 :                 n->skipIfNewValExists = $6;
    6573         194 :                 $$ = (Node *) n;
    6574             :             }
    6575             :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
    6576             :             {
    6577          22 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6578             : 
    6579          22 :                 n->typeName = $3;
    6580          22 :                 n->oldVal = NULL;
    6581          22 :                 n->newVal = $7;
    6582          22 :                 n->newValNeighbor = $9;
    6583          22 :                 n->newValIsAfter = true;
    6584          22 :                 n->skipIfNewValExists = $6;
    6585          22 :                 $$ = (Node *) n;
    6586             :             }
    6587             :          | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
    6588             :             {
    6589          24 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6590             : 
    6591          24 :                 n->typeName = $3;
    6592          24 :                 n->oldVal = $6;
    6593          24 :                 n->newVal = $8;
    6594          24 :                 n->newValNeighbor = NULL;
    6595          24 :                 n->newValIsAfter = false;
    6596          24 :                 n->skipIfNewValExists = false;
    6597          24 :                 $$ = (Node *) n;
    6598             :             }
    6599             :          | ALTER TYPE_P any_name DROP VALUE_P Sconst
    6600             :             {
    6601             :                 /*
    6602             :                  * The following problems must be solved before this can be
    6603             :                  * implemented:
    6604             :                  *
    6605             :                  * - There must be no instance of the target value in
    6606             :                  *   any table.
    6607             :                  *
    6608             :                  * - The value must not appear in any catalog metadata,
    6609             :                  *   such as stored view expressions or column defaults.
    6610             :                  *
    6611             :                  * - The value must not appear in any non-leaf page of a
    6612             :                  *   btree (and similar issues with other index types).
    6613             :                  *   This is problematic because a value could persist
    6614             :                  *   there long after it's gone from user-visible data.
    6615             :                  *
    6616             :                  * - Concurrent sessions must not be able to insert the
    6617             :                  *   value while the preceding conditions are being checked.
    6618             :                  *
    6619             :                  * - Possibly more...
    6620             :                  */
    6621           0 :                 ereport(ERROR,
    6622             :                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6623             :                          errmsg("dropping an enum value is not implemented"),
    6624             :                          parser_errposition(@4)));
    6625             :             }
    6626             :          ;
    6627             : 
    6628          12 : opt_if_not_exists: IF_P NOT EXISTS              { $$ = true; }
    6629         358 :         | /* EMPTY */                          { $$ = false; }
    6630             :         ;
    6631             : 
    6632             : 
    6633             : /*****************************************************************************
    6634             :  *
    6635             :  *      QUERIES :
    6636             :  *              CREATE OPERATOR CLASS ...
    6637             :  *              CREATE OPERATOR FAMILY ...
    6638             :  *              ALTER OPERATOR FAMILY ...
    6639             :  *              DROP OPERATOR CLASS ...
    6640             :  *              DROP OPERATOR FAMILY ...
    6641             :  *
    6642             :  *****************************************************************************/
    6643             : 
    6644             : CreateOpClassStmt:
    6645             :             CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
    6646             :             USING name opt_opfamily AS opclass_item_list
    6647             :                 {
    6648         388 :                     CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
    6649             : 
    6650         388 :                     n->opclassname = $4;
    6651         388 :                     n->isDefault = $5;
    6652         388 :                     n->datatype = $8;
    6653         388 :                     n->amname = $10;
    6654         388 :                     n->opfamilyname = $11;
    6655         388 :                     n->items = $13;
    6656         388 :                     $$ = (Node *) n;
    6657             :                 }
    6658             :         ;
    6659             : 
    6660             : opclass_item_list:
    6661         838 :             opclass_item                            { $$ = list_make1($1); }
    6662        3088 :             | opclass_item_list ',' opclass_item    { $$ = lappend($1, $3); }
    6663             :         ;
    6664             : 
    6665             : opclass_item:
    6666             :             OPERATOR Iconst any_operator opclass_purpose
    6667             :                 {
    6668        1092 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6669        1092 :                     ObjectWithArgs *owa = makeNode(ObjectWithArgs);
    6670             : 
    6671        1092 :                     owa->objname = $3;
    6672        1092 :                     owa->objargs = NIL;
    6673        1092 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6674        1092 :                     n->name = owa;
    6675        1092 :                     n->number = $2;
    6676        1092 :                     n->order_family = $4;
    6677        1092 :                     $$ = (Node *) n;
    6678             :                 }
    6679             :             | OPERATOR Iconst operator_with_argtypes opclass_purpose
    6680             :                 {
    6681        1062 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6682             : 
    6683        1062 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6684        1062 :                     n->name = $3;
    6685        1062 :                     n->number = $2;
    6686        1062 :                     n->order_family = $4;
    6687        1062 :                     $$ = (Node *) n;
    6688             :                 }
    6689             :             | FUNCTION Iconst function_with_argtypes
    6690             :                 {
    6691        1386 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6692             : 
    6693        1386 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6694        1386 :                     n->name = $3;
    6695        1386 :                     n->number = $2;
    6696        1386 :                     $$ = (Node *) n;
    6697             :                 }
    6698             :             | FUNCTION Iconst '(' type_list ')' function_with_argtypes
    6699             :                 {
    6700         188 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6701             : 
    6702         188 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6703         188 :                     n->name = $6;
    6704         188 :                     n->number = $2;
    6705         188 :                     n->class_args = $4;
    6706         188 :                     $$ = (Node *) n;
    6707             :                 }
    6708             :             | STORAGE Typename
    6709             :                 {
    6710         198 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6711             : 
    6712         198 :                     n->itemtype = OPCLASS_ITEM_STORAGETYPE;
    6713         198 :                     n->storedtype = $2;
    6714         198 :                     $$ = (Node *) n;
    6715             :                 }
    6716             :         ;
    6717             : 
    6718         290 : opt_default:    DEFAULT                     { $$ = true; }
    6719         162 :             | /*EMPTY*/                     { $$ = false; }
    6720             :         ;
    6721             : 
    6722          44 : opt_opfamily:   FAMILY any_name             { $$ = $2; }
    6723         344 :             | /*EMPTY*/                     { $$ = NIL; }
    6724             :         ;
    6725             : 
    6726           0 : opclass_purpose: FOR SEARCH                 { $$ = NIL; }
    6727          72 :             | FOR ORDER BY any_name         { $$ = $4; }
    6728        2082 :             | /*EMPTY*/                     { $$ = NIL; }
    6729             :         ;
    6730             : 
    6731             : 
    6732             : CreateOpFamilyStmt:
    6733             :             CREATE OPERATOR FAMILY any_name USING name
    6734             :                 {
    6735         148 :                     CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
    6736             : 
    6737         148 :                     n->opfamilyname = $4;
    6738         148 :                     n->amname = $6;
    6739         148 :                     $$ = (Node *) n;
    6740             :                 }
    6741             :         ;
    6742             : 
    6743             : AlterOpFamilyStmt:
    6744             :             ALTER OPERATOR FAMILY any_name USING name ADD_P opclass_item_list
    6745             :                 {
    6746         450 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6747             : 
    6748         450 :                     n->opfamilyname = $4;
    6749         450 :                     n->amname = $6;
    6750         450 :                     n->isDrop = false;
    6751         450 :                     n->items = $8;
    6752         450 :                     $$ = (Node *) n;
    6753             :                 }
    6754             :             | ALTER OPERATOR FAMILY any_name USING name DROP opclass_drop_list
    6755             :                 {
    6756          64 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6757             : 
    6758          64 :                     n->opfamilyname = $4;
    6759          64 :                     n->amname = $6;
    6760          64 :                     n->isDrop = true;
    6761          64 :                     n->items = $8;
    6762          64 :                     $$ = (Node *) n;
    6763             :                 }
    6764             :         ;
    6765             : 
    6766             : opclass_drop_list:
    6767          64 :             opclass_drop                            { $$ = list_make1($1); }
    6768          30 :             | opclass_drop_list ',' opclass_drop    { $$ = lappend($1, $3); }
    6769             :         ;
    6770             : 
    6771             : opclass_drop:
    6772             :             OPERATOR Iconst '(' type_list ')'
    6773             :                 {
    6774          56 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6775             : 
    6776          56 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6777          56 :                     n->number = $2;
    6778          56 :                     n->class_args = $4;
    6779          56 :                     $$ = (Node *) n;
    6780             :                 }
    6781             :             | FUNCTION Iconst '(' type_list ')'
    6782             :                 {
    6783          38 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6784             : 
    6785          38 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6786          38 :                     n->number = $2;
    6787          38 :                     n->class_args = $4;
    6788          38 :                     $$ = (Node *) n;
    6789             :                 }
    6790             :         ;
    6791             : 
    6792             : 
    6793             : DropOpClassStmt:
    6794             :             DROP OPERATOR CLASS any_name USING name opt_drop_behavior
    6795             :                 {
    6796          38 :                     DropStmt *n = makeNode(DropStmt);
    6797             : 
    6798          38 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6799          38 :                     n->removeType = OBJECT_OPCLASS;
    6800          38 :                     n->behavior = $7;
    6801          38 :                     n->missing_ok = false;
    6802          38 :                     n->concurrent = false;
    6803          38 :                     $$ = (Node *) n;
    6804             :                 }
    6805             :             | DROP OPERATOR CLASS IF_P EXISTS any_name USING name opt_drop_behavior
    6806             :                 {
    6807          18 :                     DropStmt *n = makeNode(DropStmt);
    6808             : 
    6809          18 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6810          18 :                     n->removeType = OBJECT_OPCLASS;
    6811          18 :                     n->behavior = $9;
    6812          18 :                     n->missing_ok = true;
    6813          18 :                     n->concurrent = false;
    6814          18 :                     $$ = (Node *) n;
    6815             :                 }
    6816             :         ;
    6817             : 
    6818             : DropOpFamilyStmt:
    6819             :             DROP OPERATOR FAMILY any_name USING name opt_drop_behavior
    6820             :                 {
    6821         110 :                     DropStmt *n = makeNode(DropStmt);
    6822             : 
    6823         110 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6824         110 :                     n->removeType = OBJECT_OPFAMILY;
    6825         110 :                     n->behavior = $7;
    6826         110 :                     n->missing_ok = false;
    6827         110 :                     n->concurrent = false;
    6828         110 :                     $$ = (Node *) n;
    6829             :                 }
    6830             :             | DROP OPERATOR FAMILY IF_P EXISTS any_name USING name opt_drop_behavior
    6831             :                 {
    6832          18 :                     DropStmt *n = makeNode(DropStmt);
    6833             : 
    6834          18 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6835          18 :                     n->removeType = OBJECT_OPFAMILY;
    6836          18 :                     n->behavior = $9;
    6837          18 :                     n->missing_ok = true;
    6838          18 :                     n->concurrent = false;
    6839          18 :                     $$ = (Node *) n;
    6840             :                 }
    6841             :         ;
    6842             : 
    6843             : 
    6844             : /*****************************************************************************
    6845             :  *
    6846             :  *      QUERY:
    6847             :  *
    6848             :  *      DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
    6849             :  *      REASSIGN OWNED BY username [, username ...] TO username
    6850             :  *
    6851             :  *****************************************************************************/
    6852             : DropOwnedStmt:
    6853             :             DROP OWNED BY role_list opt_drop_behavior
    6854             :                 {
    6855         148 :                     DropOwnedStmt *n = makeNode(DropOwnedStmt);
    6856             : 
    6857         148 :                     n->roles = $4;
    6858         148 :                     n->behavior = $5;
    6859         148 :                     $$ = (Node *) n;
    6860             :                 }
    6861             :         ;
    6862             : 
    6863             : ReassignOwnedStmt:
    6864             :             REASSIGN OWNED BY role_list TO RoleSpec
    6865             :                 {
    6866          46 :                     ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
    6867             : 
    6868          46 :                     n->roles = $4;
    6869          46 :                     n->newrole = $6;
    6870          46 :                     $$ = (Node *) n;
    6871             :                 }
    6872             :         ;
    6873             : 
    6874             : /*****************************************************************************
    6875             :  *
    6876             :  *      QUERY:
    6877             :  *
    6878             :  *      DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
    6879             :  *           [ RESTRICT | CASCADE ]
    6880             :  *
    6881             :  *****************************************************************************/
    6882             : 
    6883             : DropStmt:   DROP object_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
    6884             :                 {
    6885        1304 :                     DropStmt *n = makeNode(DropStmt);
    6886             : 
    6887        1304 :                     n->removeType = $2;
    6888        1304 :                     n->missing_ok = true;
    6889        1304 :                     n->objects = $5;
    6890        1304 :                     n->behavior = $6;
    6891        1304 :                     n->concurrent = false;
    6892        1304 :                     $$ = (Node *) n;
    6893             :                 }
    6894             :             | DROP object_type_any_name any_name_list opt_drop_behavior
    6895             :                 {
    6896       15422 :                     DropStmt *n = makeNode(DropStmt);
    6897             : 
    6898       15422 :                     n->removeType = $2;
    6899       15422 :                     n->missing_ok = false;
    6900       15422 :                     n->objects = $3;
    6901       15422 :                     n->behavior = $4;
    6902       15422 :                     n->concurrent = false;
    6903       15422 :                     $$ = (Node *) n;
    6904             :                 }
    6905             :             | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
    6906             :                 {
    6907          78 :                     DropStmt *n = makeNode(DropStmt);
    6908             : 
    6909          78 :                     n->removeType = $2;
    6910          78 :                     n->missing_ok = true;
    6911          78 :                     n->objects = $5;
    6912          78 :                     n->behavior = $6;
    6913          78 :                     n->concurrent = false;
    6914          78 :                     $$ = (Node *) n;
    6915             :                 }
    6916             :             | DROP drop_type_name name_list opt_drop_behavior
    6917             :                 {
    6918        1336 :                     DropStmt *n = makeNode(DropStmt);
    6919             : 
    6920        1336 :                     n->removeType = $2;
    6921        1336 :                     n->missing_ok = false;
    6922        1336 :                     n->objects = $3;
    6923        1336 :                     n->behavior = $4;
    6924        1336 :                     n->concurrent = false;
    6925        1336 :                     $$ = (Node *) n;
    6926             :                 }
    6927             :             | DROP object_type_name_on_any_name name ON any_name opt_drop_behavior
    6928             :                 {
    6929        1086 :                     DropStmt *n = makeNode(DropStmt);
    6930             : 
    6931        1086 :                     n->removeType = $2;
    6932        1086 :                     n->objects = list_make1(lappend($5, makeString($3)));
    6933        1086 :                     n->behavior = $6;
    6934        1086 :                     n->missing_ok = false;
    6935        1086 :                     n->concurrent = false;
    6936        1086 :                     $$ = (Node *) n;
    6937             :                 }
    6938             :             | DROP object_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
    6939             :                 {
    6940          48 :                     DropStmt *n = makeNode(DropStmt);
    6941             : 
    6942          48 :                     n->removeType = $2;
    6943          48 :                     n->objects = list_make1(lappend($7, makeString($5)));
    6944          48 :                     n->behavior = $8;
    6945          48 :                     n->missing_ok = true;
    6946          48 :                     n->concurrent = false;
    6947          48 :                     $$ = (Node *) n;
    6948             :                 }
    6949             :             | DROP TYPE_P type_name_list opt_drop_behavior
    6950             :                 {
    6951         536 :                     DropStmt *n = makeNode(DropStmt);
    6952             : 
    6953         536 :                     n->removeType = OBJECT_TYPE;
    6954         536 :                     n->missing_ok = false;
    6955         536 :                     n->objects = $3;
    6956         536 :                     n->behavior = $4;
    6957         536 :                     n->concurrent = false;
    6958         536 :                     $$ = (Node *) n;
    6959             :                 }
    6960             :             | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
    6961             :                 {
    6962          22 :                     DropStmt *n = makeNode(DropStmt);
    6963             : 
    6964          22 :                     n->removeType = OBJECT_TYPE;
    6965          22 :                     n->missing_ok = true;
    6966          22 :                     n->objects = $5;
    6967          22 :                     n->behavior = $6;
    6968          22 :                     n->concurrent = false;
    6969          22 :                     $$ = (Node *) n;
    6970             :                 }
    6971             :             | DROP DOMAIN_P type_name_list opt_drop_behavior
    6972             :                 {
    6973         440 :                     DropStmt *n = makeNode(DropStmt);
    6974             : 
    6975         440 :                     n->removeType = OBJECT_DOMAIN;
    6976         440 :                     n->missing_ok = false;
    6977         440 :                     n->objects = $3;
    6978         440 :                     n->behavior = $4;
    6979         440 :                     n->concurrent = false;
    6980         440 :                     $$ = (Node *) n;
    6981             :                 }
    6982             :             | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
    6983             :                 {
    6984          18 :                     DropStmt *n = makeNode(DropStmt);
    6985             : 
    6986          18 :                     n->removeType = OBJECT_DOMAIN;
    6987          18 :                     n->missing_ok = true;
    6988          18 :                     n->objects = $5;
    6989          18 :                     n->behavior = $6;
    6990          18 :                     n->concurrent = false;
    6991          18 :                     $$ = (Node *) n;
    6992             :                 }
    6993             :             | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
    6994             :                 {
    6995         144 :                     DropStmt *n = makeNode(DropStmt);
    6996             : 
    6997         144 :                     n->removeType = OBJECT_INDEX;
    6998         144 :                     n->missing_ok = false;
    6999         144 :                     n->objects = $4;
    7000         144 :                     n->behavior = $5;
    7001         144 :                     n->concurrent = true;
    7002         144 :                     $$ = (Node *) n;
    7003             :                 }
    7004             :             | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
    7005             :                 {
    7006          12 :                     DropStmt *n = makeNode(DropStmt);
    7007             : 
    7008          12 :                     n->removeType = OBJECT_INDEX;
    7009          12 :                     n->missing_ok = true;
    7010          12 :                     n->objects = $6;
    7011          12 :                     n->behavior = $7;
    7012          12 :                     n->concurrent = true;
    7013          12 :                     $$ = (Node *) n;
    7014             :                 }
    7015             :         ;
    7016             : 
    7017             : /* object types taking any_name/any_name_list */
    7018             : object_type_any_name:
    7019       14406 :             TABLE                                   { $$ = OBJECT_TABLE; }
    7020         198 :             | SEQUENCE                              { $$ = OBJECT_SEQUENCE; }
    7021         980 :             | VIEW                                  { $$ = OBJECT_VIEW; }
    7022         124 :             | MATERIALIZED VIEW                     { $$ = OBJECT_MATVIEW; }
    7023         766 :             | INDEX                                 { $$ = OBJECT_INDEX; }
    7024         172 :             | FOREIGN TABLE                         { $$ = OBJECT_FOREIGN_TABLE; }
    7025          96 :             | COLLATION                             { $$ = OBJECT_COLLATION; }
    7026          56 :             | CONVERSION_P                          { $$ = OBJECT_CONVERSION; }
    7027         192 :             | STATISTICS                            { $$ = OBJECT_STATISTIC_EXT; }
    7028          20 :             | TEXT_P SEARCH PARSER                  { $$ = OBJECT_TSPARSER; }
    7029        2438 :             | TEXT_P SEARCH DICTIONARY              { $$ = OBJECT_TSDICTIONARY; }
    7030         106 :             | TEXT_P SEARCH TEMPLATE                { $$ = OBJECT_TSTEMPLATE; }
    7031        2442 :             | TEXT_P SEARCH CONFIGURATION           { $$ = OBJECT_TSCONFIGURATION; }
    7032             :         ;
    7033             : 
    7034             : /*
    7035             :  * object types taking name/name_list
    7036             :  *
    7037             :  * DROP handles some of them separately
    7038             :  */
    7039             : 
    7040             : object_type_name:
    7041         194 :             drop_type_name                          { $$ = $1; }
    7042         198 :             | DATABASE                              { $$ = OBJECT_DATABASE; }
    7043          52 :             | ROLE                                  { $$ = OBJECT_ROLE; }
    7044          10 :             | SUBSCRIPTION                          { $$ = OBJECT_SUBSCRIPTION; }
    7045           0 :             | TABLESPACE                            { $$ = OBJECT_TABLESPACE; }
    7046             :         ;
    7047             : 
    7048             : drop_type_name:
    7049          46 :             ACCESS METHOD                           { $$ = OBJECT_ACCESS_METHOD; }
    7050         126 :             | EVENT TRIGGER                         { $$ = OBJECT_EVENT_TRIGGER; }
    7051         134 :             | EXTENSION                             { $$ = OBJECT_EXTENSION; }
    7052         148 :             | FOREIGN DATA_P WRAPPER                { $$ = OBJECT_FDW; }
    7053         144 :             | opt_procedural LANGUAGE               { $$ = OBJECT_LANGUAGE; }
    7054         336 :             | PUBLICATION                           { $$ = OBJECT_PUBLICATION; }
    7055         544 :             | SCHEMA                                { $$ = OBJECT_SCHEMA; }
    7056         130 :             | SERVER                                { $$ = OBJECT_FOREIGN_SERVER; }
    7057             :         ;
    7058             : 
    7059             : /* object types attached to a table */
    7060             : object_type_name_on_any_name:
    7061         164 :             POLICY                                  { $$ = OBJECT_POLICY; }
    7062         262 :             | RULE                                  { $$ = OBJECT_RULE; }
    7063         760 :             | TRIGGER                               { $$ = OBJECT_TRIGGER; }
    7064             :         ;
    7065             : 
    7066             : any_name_list:
    7067       24436 :             any_name                                { $$ = list_make1($1); }
    7068        3966 :             | any_name_list ',' any_name            { $$ = lappend($1, $3); }
    7069             :         ;
    7070             : 
    7071       60310 : any_name:   ColId                       { $$ = list_make1(makeString($1)); }
    7072        8572 :             | ColId attrs               { $$ = lcons(makeString($1), $2); }
    7073             :         ;
    7074             : 
    7075             : attrs:      '.' attr_name
    7076      110466 :                     { $$ = list_make1(makeString($2)); }
    7077             :             | attrs '.' attr_name
    7078          54 :                     { $$ = lappend($1, makeString($3)); }
    7079             :         ;
    7080             : 
    7081             : type_name_list:
    7082        1016 :             Typename                                { $$ = list_make1($1); }
    7083          96 :             | type_name_list ',' Typename           { $$ = lappend($1, $3); }
    7084             :         ;
    7085             : 
    7086             : /*****************************************************************************
    7087             :  *
    7088             :  *      QUERY:
    7089             :  *              truncate table relname1, relname2, ...
    7090             :  *
    7091             :  *****************************************************************************/
    7092             : 
    7093             : TruncateStmt:
    7094             :             TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
    7095             :                 {
    7096        1624 :                     TruncateStmt *n = makeNode(TruncateStmt);
    7097             : 
    7098        1624 :                     n->relations = $3;
    7099        1624 :                     n->restart_seqs = $4;
    7100        1624 :                     n->behavior = $5;
    7101        1624 :                     $$ = (Node *) n;
    7102             :                 }
    7103             :         ;
    7104             : 
    7105             : opt_restart_seqs:
    7106          24 :             CONTINUE_P IDENTITY_P       { $$ = false; }
    7107          24 :             | RESTART IDENTITY_P        { $$ = true; }
    7108        1576 :             | /* EMPTY */               { $$ = false; }
    7109             :         ;
    7110             : 
    7111             : /*****************************************************************************
    7112             :  *
    7113             :  * COMMENT ON <object> IS <text>
    7114             :  *
    7115             :  *****************************************************************************/
    7116             : 
    7117             : CommentStmt:
    7118             :             COMMENT ON object_type_any_name any_name IS comment_text
    7119             :                 {
    7120        5136 :                     CommentStmt *n = makeNode(CommentStmt);
    7121             : 
    7122        5136 :                     n->objtype = $3;
    7123        5136 :                     n->object = (Node *) $4;
    7124        5136 :                     n->comment = $6;
    7125        5136 :                     $$ = (Node *) n;
    7126             :                 }
    7127             :             | COMMENT ON COLUMN any_name IS comment_text
    7128             :                 {
    7129         108 :                     CommentStmt *n = makeNode(CommentStmt);
    7130             : 
    7131         108 :                     n->objtype = OBJECT_COLUMN;
    7132         108 :                     n->object = (Node *) $4;
    7133         108 :                     n->comment = $6;
    7134         108 :                     $$ = (Node *) n;
    7135             :                 }
    7136             :             | COMMENT ON object_type_name name IS comment_text
    7137             :                 {
    7138         392 :                     CommentStmt *n = makeNode(CommentStmt);
    7139             : 
    7140         392 :                     n->objtype = $3;
    7141         392 :                     n->object = (Node *) makeString($4);
    7142         392 :                     n->comment = $6;
    7143         392 :                     $$ = (Node *) n;
    7144             :                 }
    7145             :             | COMMENT ON TYPE_P Typename IS comment_text
    7146             :                 {
    7147          56 :                     CommentStmt *n = makeNode(CommentStmt);
    7148             : 
    7149          56 :                     n->objtype = OBJECT_TYPE;
    7150          56 :                     n->object = (Node *) $4;
    7151          56 :                     n->comment = $6;
    7152          56 :                     $$ = (Node *) n;
    7153             :                 }
    7154             :             | COMMENT ON DOMAIN_P Typename IS comment_text
    7155             :                 {
    7156           8 :                     CommentStmt *n = makeNode(CommentStmt);
    7157             : 
    7158           8 :                     n->objtype = OBJECT_DOMAIN;
    7159           8 :                     n->object = (Node *) $4;
    7160           8 :                     n->comment = $6;
    7161           8 :                     $$ = (Node *) n;
    7162             :                 }
    7163             :             | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
    7164             :                 {
    7165          40 :                     CommentStmt *n = makeNode(CommentStmt);
    7166             : 
    7167          40 :                     n->objtype = OBJECT_AGGREGATE;
    7168          40 :                     n->object = (Node *) $4;
    7169          40 :                     n->comment = $6;
    7170          40 :                     $$ = (Node *) n;
    7171             :                 }
    7172             :             | COMMENT ON FUNCTION function_with_argtypes IS comment_text
    7173             :                 {
    7174         170 :                     CommentStmt *n = makeNode(CommentStmt);
    7175             : 
    7176         170 :                     n->objtype = OBJECT_FUNCTION;
    7177         170 :                     n->object = (Node *) $4;
    7178         170 :                     n->comment = $6;
    7179         170 :                     $$ = (Node *) n;
    7180             :                 }
    7181             :             | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
    7182             :                 {
    7183          18 :                     CommentStmt *n = makeNode(CommentStmt);
    7184             : 
    7185          18 :                     n->objtype = OBJECT_OPERATOR;
    7186          18 :                     n->object = (Node *) $4;
    7187          18 :                     n->comment = $6;
    7188          18 :                     $$ = (Node *) n;
    7189             :                 }
    7190             :             | COMMENT ON CONSTRAINT name ON any_name IS comment_text
    7191             :                 {
    7192         110 :                     CommentStmt *n = makeNode(CommentStmt);
    7193             : 
    7194         110 :                     n->objtype = OBJECT_TABCONSTRAINT;
    7195         110 :                     n->object = (Node *) lappend($6, makeString($4));
    7196         110 :                     n->comment = $8;
    7197         110 :                     $$ = (Node *) n;
    7198             :                 }
    7199             :             | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
    7200             :                 {
    7201          38 :                     CommentStmt *n = makeNode(CommentStmt);
    7202             : 
    7203          38 :                     n->objtype = OBJECT_DOMCONSTRAINT;
    7204             :                     /*
    7205             :                      * should use Typename not any_name in the production, but
    7206             :                      * there's a shift/reduce conflict if we do that, so fix it
    7207             :                      * up here.
    7208             :                      */
    7209          38 :                     n->object = (Node *) list_make2(makeTypeNameFromNameList($7), makeString($4));
    7210          38 :                     n->comment = $9;
    7211          38 :                     $$ = (Node *) n;
    7212             :                 }
    7213             :             | COMMENT ON object_type_name_on_any_name name ON any_name IS comment_text
    7214             :                 {
    7215          40 :                     CommentStmt *n = makeNode(CommentStmt);
    7216             : 
    7217          40 :                     n->objtype = $3;
    7218          40 :                     n->object = (Node *) lappend($6, makeString($4));
    7219          40 :                     n->comment = $8;
    7220          40 :                     $$ = (Node *) n;
    7221             :                 }
    7222             :             | COMMENT ON PROCEDURE function_with_argtypes IS comment_text
    7223             :                 {
    7224           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7225             : 
    7226           0 :                     n->objtype = OBJECT_PROCEDURE;
    7227           0 :                     n->object = (Node *) $4;
    7228           0 :                     n->comment = $6;
    7229           0 :                     $$ = (Node *) n;
    7230             :                 }
    7231             :             | COMMENT ON ROUTINE function_with_argtypes IS comment_text
    7232             :                 {
    7233           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7234             : 
    7235           0 :                     n->objtype = OBJECT_ROUTINE;
    7236           0 :                     n->object = (Node *) $4;
    7237           0 :                     n->comment = $6;
    7238           0 :                     $$ = (Node *) n;
    7239             :                 }
    7240             :             | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
    7241             :                 {
    7242          14 :                     CommentStmt *n = makeNode(CommentStmt);
    7243             : 
    7244          14 :                     n->objtype = OBJECT_TRANSFORM;
    7245          14 :                     n->object = (Node *) list_make2($5, makeString($7));
    7246          14 :                     n->comment = $9;
    7247          14 :                     $$ = (Node *) n;
    7248             :                 }
    7249             :             | COMMENT ON OPERATOR CLASS any_name USING name IS comment_text
    7250             :                 {
    7251           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7252             : 
    7253           0 :                     n->objtype = OBJECT_OPCLASS;
    7254           0 :                     n->object = (Node *) lcons(makeString($7), $5);
    7255           0 :                     n->comment = $9;
    7256           0 :                     $$ = (Node *) n;
    7257             :                 }
    7258             :             | COMMENT ON OPERATOR FAMILY any_name USING name IS comment_text
    7259             :                 {
    7260           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7261             : 
    7262           0 :                     n->objtype = OBJECT_OPFAMILY;
    7263           0 :                     n->object = (Node *) lcons(makeString($7), $5);
    7264           0 :                     n->comment = $9;
    7265           0 :                     $$ = (Node *) n;
    7266             :                 }
    7267             :             | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
    7268             :                 {
    7269          24 :                     CommentStmt *n = makeNode(CommentStmt);
    7270             : 
    7271          24 :                     n->objtype = OBJECT_LARGEOBJECT;
    7272          24 :                     n->object = (Node *) $5;
    7273          24 :                     n->comment = $7;
    7274          24 :                     $$ = (Node *) n;
    7275             :                 }
    7276             :             | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
    7277             :                 {
    7278           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7279             : 
    7280           0 :                     n->objtype = OBJECT_CAST;
    7281           0 :                     n->object = (Node *) list_make2($5, $7);
    7282           0 :                     n->comment = $10;
    7283           0 :                     $$ = (Node *) n;
    7284             :                 }
    7285             :         ;
    7286             : 
    7287             : comment_text:
    7288        6050 :             Sconst                              { $$ = $1; }
    7289         104 :             | NULL_P                            { $$ = NULL; }
    7290             :         ;
    7291             : 
    7292             : 
    7293             : /*****************************************************************************
    7294             :  *
    7295             :  *  SECURITY LABEL [FOR <provider>] ON <object> IS <label>
    7296             :  *
    7297             :  *  As with COMMENT ON, <object> can refer to various types of database
    7298             :  *  objects (e.g. TABLE, COLUMN, etc.).
    7299             :  *
    7300             :  *****************************************************************************/
    7301             : 
    7302             : SecLabelStmt:
    7303             :             SECURITY LABEL opt_provider ON object_type_any_name any_name
    7304             :             IS security_label
    7305             :                 {
    7306          48 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7307             : 
    7308          48 :                     n->provider = $3;
    7309          48 :                     n->objtype = $5;
    7310          48 :                     n->object = (Node *) $6;
    7311          48 :                     n->label = $8;
    7312          48 :                     $$ = (Node *) n;
    7313             :                 }
    7314             :             | SECURITY LABEL opt_provider ON COLUMN any_name
    7315             :               IS security_label
    7316             :                 {
    7317           4 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7318             : 
    7319           4 :                     n->provider = $3;
    7320           4 :                     n->objtype = OBJECT_COLUMN;
    7321           4 :                     n->object = (Node *) $6;
    7322           4 :                     n->label = $8;
    7323           4 :                     $$ = (Node *) n;
    7324             :                 }
    7325             :             | SECURITY LABEL opt_provider ON object_type_name name
    7326             :               IS security_label
    7327             :                 {
    7328          44 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7329             : 
    7330          44 :                     n->provider = $3;
    7331          44 :                     n->objtype = $5;
    7332          44 :                     n->object = (Node *) makeString($6);
    7333          44 :                     n->label = $8;
    7334          44 :                     $$ = (Node *) n;
    7335             :                 }
    7336             :             | SECURITY LABEL opt_provider ON TYPE_P Typename
    7337             :               IS security_label
    7338             :                 {
    7339           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7340             : 
    7341           0 :                     n->provider = $3;
    7342           0 :                     n->objtype = OBJECT_TYPE;
    7343           0 :                     n->object = (Node *) $6;
    7344           0 :                     n->label = $8;
    7345           0 :                     $$ = (Node *) n;
    7346             :                 }
    7347             :             | SECURITY LABEL opt_provider ON DOMAIN_P Typename
    7348             :               IS security_label
    7349             :                 {
    7350           2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7351             : 
    7352           2 :                     n->provider = $3;
    7353           2 :                     n->objtype = OBJECT_DOMAIN;
    7354           2 :                     n->object = (Node *) $6;
    7355           2 :                     n->label = $8;
    7356           2 :                     $$ = (Node *) n;
    7357             :                 }
    7358             :             | SECURITY LABEL opt_provider ON AGGREGATE aggregate_with_argtypes
    7359             :               IS security_label
    7360             :                 {
    7361           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7362             : 
    7363           0 :                     n->provider = $3;
    7364           0 :                     n->objtype = OBJECT_AGGREGATE;
    7365           0 :                     n->object = (Node *) $6;
    7366           0 :                     n->label = $8;
    7367           0 :                     $$ = (Node *) n;
    7368             :                 }
    7369             :             | SECURITY LABEL opt_provider ON FUNCTION function_with_argtypes
    7370             :               IS security_label
    7371             :                 {
    7372           2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7373             : 
    7374           2 :                     n->provider = $3;
    7375           2 :                     n->objtype = OBJECT_FUNCTION;
    7376           2 :                     n->object = (Node *) $6;
    7377           2 :                     n->label = $8;
    7378           2 :                     $$ = (Node *) n;
    7379             :                 }
    7380             :             | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
    7381             :               IS security_label
    7382             :                 {
    7383           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7384             : 
    7385           0 :                     n->provider = $3;
    7386           0 :                     n->objtype = OBJECT_LARGEOBJECT;
    7387           0 :                     n->object = (Node *) $7;
    7388           0 :                     n->label = $9;
    7389           0 :                     $$ = (Node *) n;
    7390             :                 }
    7391             :             | SECURITY LABEL opt_provider ON PROCEDURE function_with_argtypes
    7392             :               IS security_label
    7393             :                 {
    7394           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7395             : 
    7396           0 :                     n->provider = $3;
    7397           0 :                     n->objtype = OBJECT_PROCEDURE;
    7398           0 :                     n->object = (Node *) $6;
    7399           0 :                     n->label = $8;
    7400           0 :                     $$ = (Node *) n;
    7401             :                 }
    7402             :             | SECURITY LABEL opt_provider ON ROUTINE function_with_argtypes
    7403             :               IS security_label
    7404             :                 {
    7405           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7406             : 
    7407           0 :                     n->provider = $3;
    7408           0 :                     n->objtype = OBJECT_ROUTINE;
    7409           0 :                     n->object = (Node *) $6;
    7410           0 :                     n->label = $8;
    7411           0 :                     $$ = (Node *) n;
    7412             :                 }
    7413             :         ;
    7414             : 
    7415          20 : opt_provider:   FOR NonReservedWord_or_Sconst   { $$ = $2; }
    7416          80 :                 | /* EMPTY */                   { $$ = NULL; }
    7417             :         ;
    7418             : 
    7419         100 : security_label: Sconst              { $$ = $1; }
    7420           0 :                 | NULL_P            { $$ = NULL; }
    7421             :         ;
    7422             : 
    7423             : /*****************************************************************************
    7424             :  *
    7425             :  *      QUERY:
    7426             :  *          fetch/move
    7427             :  *
    7428             :  *****************************************************************************/
    7429             : 
    7430             : FetchStmt:  FETCH fetch_args
    7431             :                 {
    7432        5680 :                     FetchStmt *n = (FetchStmt *) $2;
    7433             : 
    7434        5680 :                     n->ismove = false;
    7435        5680 :                     $$ = (Node *) n;
    7436             :                 }
    7437             :             | MOVE fetch_args
    7438             :                 {
    7439          68 :                     FetchStmt *n = (FetchStmt *) $2;
    7440             : 
    7441          68 :                     n->ismove = true;
    7442          68 :                     $$ = (Node *) n;
    7443             :                 }
    7444             :         ;
    7445             : 
    7446             : fetch_args: cursor_name
    7447             :                 {
    7448         266 :                     FetchStmt *n = makeNode(FetchStmt);
    7449             : 
    7450         266 :                     n->portalname = $1;
    7451         266 :                     n->direction = FETCH_FORWARD;
    7452         266 :                     n->howMany = 1;
    7453         266 :                     $$ = (Node *) n;
    7454             :                 }
    7455             :             | from_in cursor_name
    7456             :                 {
    7457         216 :                     FetchStmt *n = makeNode(FetchStmt);
    7458             : 
    7459         216 :                     n->portalname = $2;
    7460         216 :                     n->direction = FETCH_FORWARD;
    7461         216 :                     n->howMany = 1;
    7462         216 :                     $$ = (Node *) n;
    7463             :                 }
    7464             :             | NEXT opt_from_in cursor_name
    7465             :                 {
    7466         262 :                     FetchStmt *n = makeNode(FetchStmt);
    7467             : 
    7468         262 :                     n->portalname = $3;
    7469         262 :                     n->direction = FETCH_FORWARD;
    7470         262 :                     n->howMany = 1;
    7471         262 :                     $$ = (Node *) n;
    7472             :                 }
    7473             :             | PRIOR opt_from_in cursor_name
    7474             :                 {
    7475          30 :                     FetchStmt *n = makeNode(FetchStmt);
    7476             : 
    7477          30 :                     n->portalname = $3;
    7478          30 :                     n->direction = FETCH_BACKWARD;
    7479          30 :                     n->howMany = 1;
    7480          30 :                     $$ = (Node *) n;
    7481             :                 }
    7482             :             | FIRST_P opt_from_in cursor_name
    7483             :                 {
    7484          24 :                     FetchStmt *n = makeNode(FetchStmt);
    7485             : 
    7486          24 :                     n->portalname = $3;
    7487          24 :                     n->direction = FETCH_ABSOLUTE;
    7488          24 :                     n->howMany = 1;
    7489          24 :                     $$ = (Node *) n;
    7490             :                 }
    7491             :             | LAST_P opt_from_in cursor_name
    7492             :                 {
    7493          18 :                     FetchStmt *n = makeNode(FetchStmt);
    7494             : 
    7495          18 :                     n->portalname = $3;
    7496          18 :                     n->direction = FETCH_ABSOLUTE;
    7497          18 :                     n->howMany = -1;
    7498          18 :                     $$ = (Node *) n;
    7499             :                 }
    7500             :             | ABSOLUTE_P SignedIconst opt_from_in cursor_name
    7501             :                 {
    7502          88 :                     FetchStmt *n = makeNode(FetchStmt);
    7503             : 
    7504          88 :                     n->portalname = $4;
    7505          88 :                     n->direction = FETCH_ABSOLUTE;
    7506          88 :                     n->howMany = $2;
    7507          88 :                     $$ = (Node *) n;
    7508             :                 }
    7509             :             | RELATIVE_P SignedIconst opt_from_in cursor_name
    7510             :                 {
    7511          30 :                     FetchStmt *n = makeNode(FetchStmt);
    7512             : 
    7513          30 :                     n->portalname = $4;
    7514          30 :                     n->direction = FETCH_RELATIVE;
    7515          30 :                     n->howMany = $2;
    7516          30 :                     $$ = (Node *) n;
    7517             :                 }
    7518             :             | SignedIconst opt_from_in cursor_name
    7519             :                 {
    7520        4112 :                     FetchStmt *n = makeNode(FetchStmt);
    7521             : 
    7522        4112 :                     n->portalname = $3;
    7523        4112 :                     n->direction = FETCH_FORWARD;
    7524        4112 :                     n->howMany = $1;
    7525        4112 :                     $$ = (Node *) n;
    7526             :                 }
    7527             :             | ALL opt_from_in cursor_name
    7528             :                 {
    7529         266 :                     FetchStmt *n = makeNode(FetchStmt);
    7530             : 
    7531         266 :                     n->portalname = $3;
    7532         266 :                     n->direction = FETCH_FORWARD;
    7533         266 :                     n->howMany = FETCH_ALL;
    7534         266 :                     $$ = (Node *) n;
    7535             :                 }
    7536             :             | FORWARD opt_from_in cursor_name
    7537             :                 {
    7538          28 :                     FetchStmt *n = makeNode(FetchStmt);
    7539             : 
    7540          28 :                     n->portalname = $3;
    7541          28 :                     n->direction = FETCH_FORWARD;
    7542          28 :                     n->howMany = 1;
    7543          28 :                     $$ = (Node *) n;
    7544             :                 }
    7545             :             | FORWARD SignedIconst opt_from_in cursor_name
    7546             :                 {
    7547           6 :                     FetchStmt *n = makeNode(FetchStmt);
    7548             : 
    7549           6 :                     n->portalname = $4;
    7550           6 :                     n->direction = FETCH_FORWARD;
    7551           6 :                     n->howMany = $2;
    7552           6 :                     $$ = (Node *) n;
    7553             :                 }
    7554             :             | FORWARD ALL opt_from_in cursor_name
    7555             :                 {
    7556          14 :                     FetchStmt *n = makeNode(FetchStmt);
    7557             : 
    7558          14 :                     n->portalname = $4;
    7559          14 :                     n->direction = FETCH_FORWARD;
    7560          14 :                     n->howMany = FETCH_ALL;
    7561          14 :                     $$ = (Node *) n;
    7562             :                 }
    7563             :             | BACKWARD opt_from_in cursor_name
    7564             :                 {
    7565          78 :                     FetchStmt *n = makeNode(FetchStmt);
    7566             : 
    7567          78 :                     n->portalname = $3;
    7568          78 :                     n->direction = FETCH_BACKWARD;
    7569          78 :                     n->howMany = 1;
    7570          78 :                     $$ = (Node *) n;
    7571             :                 }
    7572             :             | BACKWARD SignedIconst opt_from_in cursor_name
    7573             :                 {
    7574         220 :                     FetchStmt *n = makeNode(FetchStmt);
    7575             : 
    7576         220 :                     n->portalname = $4;
    7577         220 :                     n->direction = FETCH_BACKWARD;
    7578         220 :                     n->howMany = $2;
    7579         220 :                     $$ = (Node *) n;
    7580             :                 }
    7581             :             | BACKWARD ALL opt_from_in cursor_name
    7582             :                 {
    7583          90 :                     FetchStmt *n = makeNode(FetchStmt);
    7584             : 
    7585          90 :                     n->portalname = $4;
    7586          90 :                     n->direction = FETCH_BACKWARD;
    7587          90 :                     n->howMany = FETCH_ALL;
    7588          90 :                     $$ = (Node *) n;
    7589             :                 }
    7590             :         ;
    7591             : 
    7592             : from_in:    FROM
    7593             :             | IN_P
    7594             :         ;
    7595             : 
    7596             : opt_from_in:    from_in
    7597             :             | /* EMPTY */
    7598             :         ;
    7599             : 
    7600             : 
    7601             : /*****************************************************************************
    7602             :  *
    7603             :  * GRANT and REVOKE statements
    7604             :  *
    7605             :  *****************************************************************************/
    7606             : 
    7607             : GrantStmt:  GRANT privileges ON privilege_target TO grantee_list
    7608             :             opt_grant_grant_option opt_granted_by
    7609             :                 {
    7610       10180 :                     GrantStmt *n = makeNode(GrantStmt);
    7611             : 
    7612       10180 :                     n->is_grant = true;
    7613       10180 :                     n->privileges = $2;
    7614       10180 :                     n->targtype = ($4)->targtype;
    7615       10180 :                     n->objtype = ($4)->objtype;
    7616       10180 :                     n->objects = ($4)->objs;
    7617       10180 :                     n->grantees = $6;
    7618       10180 :                     n->grant_option = $7;
    7619       10180 :                     n->grantor = $8;
    7620       10180 :                     $$ = (Node *) n;
    7621             :                 }
    7622             :         ;
    7623             : 
    7624             : RevokeStmt:
    7625             :             REVOKE privileges ON privilege_target
    7626             :             FROM grantee_list opt_granted_by opt_drop_behavior
    7627             :                 {
    7628        8934 :                     GrantStmt *n = makeNode(GrantStmt);
    7629             : 
    7630        8934 :                     n->is_grant = false;
    7631        8934 :                     n->grant_option = false;
    7632        8934 :                     n->privileges = $2;
    7633        8934 :                     n->targtype = ($4)->targtype;
    7634        8934 :                     n->objtype = ($4)->objtype;
    7635        8934 :                     n->objects = ($4)->objs;
    7636        8934 :                     n->grantees = $6;
    7637        8934 :                     n->grantor = $7;
    7638        8934 :                     n->behavior = $8;
    7639        8934 :                     $$ = (Node *) n;
    7640             :                 }
    7641             :             | REVOKE GRANT OPTION FOR privileges ON privilege_target
    7642             :             FROM grantee_list opt_granted_by opt_drop_behavior
    7643             :                 {
    7644          16 :                     GrantStmt *n = makeNode(GrantStmt);
    7645             : 
    7646          16 :                     n->is_grant = false;
    7647          16 :                     n->grant_option = true;
    7648          16 :                     n->privileges = $5;
    7649          16 :                     n->targtype = ($7)->targtype;
    7650          16 :                     n->objtype = ($7)->objtype;
    7651          16 :                     n->objects = ($7)->objs;
    7652          16 :                     n->grantees = $9;
    7653          16 :                     n->grantor = $10;
    7654          16 :                     n->behavior = $11;
    7655          16 :                     $$ = (Node *) n;
    7656             :                 }
    7657             :         ;
    7658             : 
    7659             : 
    7660             : /*
    7661             :  * Privilege names are represented as strings; the validity of the privilege
    7662             :  * names gets checked at execution.  This is a bit annoying but we have little
    7663             :  * choice because of the syntactic conflict with lists of role names in
    7664             :  * GRANT/REVOKE.  What's more, we have to call out in the "privilege"
    7665             :  * production any reserved keywords that need to be usable as privilege names.
    7666             :  */
    7667             : 
    7668             : /* either ALL [PRIVILEGES] or a list of individual privileges */
    7669             : privileges: privilege_list
    7670       16990 :                 { $$ = $1; }
    7671             :             | ALL
    7672        2174 :                 { $$ = NIL; }
    7673             :             | ALL PRIVILEGES
    7674         120 :                 { $$ = NIL; }
    7675             :             | ALL '(' columnList ')'
    7676             :                 {
    7677          18 :                     AccessPriv *n = makeNode(AccessPriv);
    7678             : 
    7679          18 :                     n->priv_name = NULL;
    7680          18 :                     n->cols = $3;
    7681          18 :                     $$ = list_make1(n);
    7682             :                 }
    7683             :             | ALL PRIVILEGES '(' columnList ')'
    7684             :                 {
    7685           0 :                     AccessPriv *n = makeNode(AccessPriv);
    7686             : 
    7687           0 :                     n->priv_name = NULL;
    7688           0 :                     n->cols = $4;
    7689           0 :                     $$ = list_make1(n);
    7690             :                 }
    7691             :         ;
    7692             : 
    7693       17918 : privilege_list: privilege                           { $$ = list_make1($1); }
    7694         474 :             | privilege_list ',' privilege          { $$ = lappend($1, $3); }
    7695             :         ;
    7696             : 
    7697             : privilege:  SELECT opt_column_list
    7698             :             {
    7699        8398 :                 AccessPriv *n = makeNode(AccessPriv);
    7700             : 
    7701        8398 :                 n->priv_name = pstrdup($1);
    7702        8398 :                 n->cols = $2;
    7703        8398 :                 $$ = n;
    7704             :             }
    7705             :         | REFERENCES opt_column_list
    7706             :             {
    7707          14 :                 AccessPriv *n = makeNode(AccessPriv);
    7708             : 
    7709          14 :                 n->priv_name = pstrdup($1);
    7710          14 :                 n->cols = $2;
    7711          14 :                 $$ = n;
    7712             :             }
    7713             :         | CREATE opt_column_list
    7714             :             {
    7715         270 :                 AccessPriv *n = makeNode(AccessPriv);
    7716             : 
    7717         270 :                 n->priv_name = pstrdup($1);
    7718         270 :                 n->cols = $2;
    7719         270 :                 $$ = n;
    7720             :             }
    7721             :         | ALTER SYSTEM_P
    7722             :             {
    7723          24 :                 AccessPriv *n = makeNode(AccessPriv);
    7724          24 :                 n->priv_name = pstrdup("alter system");
    7725          24 :                 n->cols = NIL;
    7726          24 :                 $$ = n;
    7727             :             }
    7728             :         | ColId opt_column_list
    7729             :             {
    7730        9686 :                 AccessPriv *n = makeNode(AccessPriv);
    7731             : 
    7732        9686 :                 n->priv_name = $1;
    7733        9686 :                 n->cols = $2;
    7734        9686 :                 $$ = n;
    7735             :             }
    7736             :         ;
    7737             : 
    7738             : parameter_name_list:
    7739             :         parameter_name
    7740             :             {
    7741          74 :                 $$ = list_make1(makeString($1));
    7742             :             }
    7743             :         | parameter_name_list ',' parameter_name
    7744             :             {
    7745          50 :                 $$ = lappend($1, makeString($3));
    7746             :             }
    7747             :         ;
    7748             : 
    7749             : parameter_name:
    7750             :         ColId
    7751             :             {
    7752         124 :                 $$ = $1;
    7753             :             }
    7754             :         | parameter_name '.' ColId
    7755             :             {
    7756          30 :                 $$ = psprintf("%s.%s", $1, $3);
    7757             :             }
    7758             :         ;
    7759             : 
    7760             : 
    7761             : /* Don't bother trying to fold the first two rules into one using
    7762             :  * opt_table.  You're going to get conflicts.
    7763             :  */
    7764             : privilege_target:
    7765             :             qualified_name_list
    7766             :                 {
    7767       10028 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7768             : 
    7769       10028 :                     n->targtype = ACL_TARGET_OBJECT;
    7770       10028 :                     n->objtype = OBJECT_TABLE;
    7771       10028 :                     n->objs = $1;
    7772       10028 :                     $$ = n;
    7773             :                 }
    7774             :             | TABLE qualified_name_list
    7775             :                 {
    7776         368 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7777             : 
    7778         368 :                     n->targtype = ACL_TARGET_OBJECT;
    7779         368 :                     n->objtype = OBJECT_TABLE;
    7780         368 :                     n->objs = $2;
    7781         368 :                     $$ = n;
    7782             :                 }
    7783             :             | SEQUENCE qualified_name_list
    7784             :                 {
    7785          22 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7786             : 
    7787          22 :                     n->targtype = ACL_TARGET_OBJECT;
    7788          22 :                     n->objtype = OBJECT_SEQUENCE;
    7789          22 :                     n->objs = $2;
    7790          22 :                     $$ = n;
    7791             :                 }
    7792             :             | FOREIGN DATA_P WRAPPER name_list
    7793             :                 {
    7794          92 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7795             : 
    7796          92 :                     n->targtype = ACL_TARGET_OBJECT;
    7797          92 :                     n->objtype = OBJECT_FDW;
    7798          92 :                     n->objs = $4;
    7799          92 :                     $$ = n;
    7800             :                 }
    7801             :             | FOREIGN SERVER name_list
    7802             :                 {
    7803          80 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7804             : 
    7805          80 :                     n->targtype = ACL_TARGET_OBJECT;
    7806          80 :                     n->objtype = OBJECT_FOREIGN_SERVER;
    7807          80 :                     n->objs = $3;
    7808          80 :                     $$ = n;
    7809             :                 }
    7810             :             | FUNCTION function_with_argtypes_list
    7811             :                 {
    7812        7512 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7813             : 
    7814        7512 :                     n->targtype = ACL_TARGET_OBJECT;
    7815        7512 :                     n->objtype = OBJECT_FUNCTION;
    7816        7512 :                     n->objs = $2;
    7817        7512 :                     $$ = n;
    7818             :                 }
    7819             :             | PROCEDURE function_with_argtypes_list
    7820             :                 {
    7821          42 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7822             : 
    7823          42 :                     n->targtype = ACL_TARGET_OBJECT;
    7824          42 :                     n->objtype = OBJECT_PROCEDURE;
    7825          42 :                     n->objs = $2;
    7826          42 :                     $$ = n;
    7827             :                 }
    7828             :             | ROUTINE function_with_argtypes_list
    7829             :                 {
    7830           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7831             : 
    7832           0 :                     n->targtype = ACL_TARGET_OBJECT;
    7833           0 :                     n->objtype = OBJECT_ROUTINE;
    7834           0 :                     n->objs = $2;
    7835           0 :                     $$ = n;
    7836             :                 }
    7837             :             | DATABASE name_list
    7838             :                 {
    7839         306 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7840             : 
    7841         306 :                     n->targtype = ACL_TARGET_OBJECT;
    7842         306 :                     n->objtype = OBJECT_DATABASE;
    7843         306 :                     n->objs = $2;
    7844         306 :                     $$ = n;
    7845             :                 }
    7846             :             | DOMAIN_P any_name_list
    7847             :                 {
    7848          26 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7849             : 
    7850          26 :                     n->targtype = ACL_TARGET_OBJECT;
    7851          26 :                     n->objtype = OBJECT_DOMAIN;
    7852          26 :                     n->objs = $2;
    7853          26 :                     $$ = n;
    7854             :                 }
    7855             :             | LANGUAGE name_list
    7856             :                 {
    7857          42 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7858             : 
    7859          42 :                     n->targtype = ACL_TARGET_OBJECT;
    7860          42 :                     n->objtype = OBJECT_LANGUAGE;
    7861          42 :                     n->objs = $2;
    7862          42 :                     $$ = n;
    7863             :                 }
    7864             :             | LARGE_P OBJECT_P NumericOnly_list
    7865             :                 {
    7866          80 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7867             : 
    7868          80 :                     n->targtype = ACL_TARGET_OBJECT;
    7869          80 :                     n->objtype = OBJECT_LARGEOBJECT;
    7870          80 :                     n->objs = $3;
    7871          80 :                     $$ = n;
    7872             :                 }
    7873             :             | PARAMETER parameter_name_list
    7874             :                 {
    7875          74 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7876          74 :                     n->targtype = ACL_TARGET_OBJECT;
    7877          74 :                     n->objtype = OBJECT_PARAMETER_ACL;
    7878          74 :                     n->objs = $2;
    7879          74 :                     $$ = n;
    7880             :                 }
    7881             :             | SCHEMA name_list
    7882             :                 {
    7883         322 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7884             : 
    7885         322 :                     n->targtype = ACL_TARGET_OBJECT;
    7886         322 :                     n->objtype = OBJECT_SCHEMA;
    7887         322 :                     n->objs = $2;
    7888         322 :                     $$ = n;
    7889             :                 }
    7890             :             | TABLESPACE name_list
    7891             :                 {
    7892           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7893             : 
    7894           6 :                     n->targtype = ACL_TARGET_OBJECT;
    7895           6 :                     n->objtype = OBJECT_TABLESPACE;
    7896           6 :                     n->objs = $2;
    7897           6 :                     $$ = n;
    7898             :                 }
    7899             :             | TYPE_P any_name_list
    7900             :                 {
    7901         112 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7902             : 
    7903         112 :                     n->targtype = ACL_TARGET_OBJECT;
    7904         112 :                     n->objtype = OBJECT_TYPE;
    7905         112 :                     n->objs = $2;
    7906         112 :                     $$ = n;
    7907             :                 }
    7908             :             | ALL TABLES IN_P SCHEMA name_list
    7909             :                 {
    7910          12 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7911             : 
    7912          12 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7913          12 :                     n->objtype = OBJECT_TABLE;
    7914          12 :                     n->objs = $5;
    7915          12 :                     $$ = n;
    7916             :                 }
    7917             :             | ALL SEQUENCES IN_P SCHEMA name_list
    7918             :                 {
    7919           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7920             : 
    7921           0 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7922           0 :                     n->objtype = OBJECT_SEQUENCE;
    7923           0 :                     n->objs = $5;
    7924           0 :                     $$ = n;
    7925             :                 }
    7926             :             | ALL FUNCTIONS IN_P SCHEMA name_list
    7927             :                 {
    7928           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7929             : 
    7930           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7931           6 :                     n->objtype = OBJECT_FUNCTION;
    7932           6 :                     n->objs = $5;
    7933           6 :                     $$ = n;
    7934             :                 }
    7935             :             | ALL PROCEDURES IN_P SCHEMA name_list
    7936             :                 {
    7937           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7938             : 
    7939           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7940           6 :                     n->objtype = OBJECT_PROCEDURE;
    7941           6 :                     n->objs = $5;
    7942           6 :                     $$ = n;
    7943             :                 }
    7944             :             | ALL ROUTINES IN_P SCHEMA name_list
    7945             :                 {
    7946           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7947             : 
    7948           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7949           6 :                     n->objtype = OBJECT_ROUTINE;
    7950           6 :                     n->objs = $5;
    7951           6 :                     $$ = n;
    7952             :                 }
    7953             :         ;
    7954             : 
    7955             : 
    7956             : grantee_list:
    7957       19290 :             grantee                                 { $$ = list_make1($1); }
    7958         108 :             | grantee_list ',' grantee              { $$ = lappend($1, $3); }
    7959             :         ;
    7960             : 
    7961             : grantee:
    7962       19374 :             RoleSpec                                { $$ = $1; }
    7963          24 :             | GROUP_P RoleSpec                      { $$ = $2; }
    7964             :         ;
    7965             : 
    7966             : 
    7967             : opt_grant_grant_option:
    7968          90 :             WITH GRANT OPTION { $$ = true; }
    7969       10190 :             | /*EMPTY*/ { $$ = false; }
    7970             :         ;
    7971             : 
    7972             : /*****************************************************************************
    7973             :  *
    7974             :  * GRANT and REVOKE ROLE statements
    7975             :  *
    7976             :  *****************************************************************************/
    7977             : 
    7978             : GrantRoleStmt:
    7979             :             GRANT privilege_list TO role_list opt_granted_by
    7980             :                 {
    7981         594 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    7982             : 
    7983         594 :                     n->is_grant = true;
    7984         594 :                     n->granted_roles = $2;
    7985         594 :                     n->grantee_roles = $4;
    7986         594 :                     n->opt = NIL;
    7987         594 :                     n->grantor = $5;
    7988         594 :                     $$ = (Node *) n;
    7989             :                 }
    7990             :           | GRANT privilege_list TO role_list WITH grant_role_opt_list opt_granted_by
    7991             :                 {
    7992         178 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    7993             : 
    7994         178 :                     n->is_grant = true;
    7995         178 :                     n->granted_roles = $2;
    7996         178 :                     n->grantee_roles = $4;
    7997         178 :                     n->opt = $6;
    7998         178 :                     n->grantor = $7;
    7999         178 :                     $$ = (Node *) n;
    8000             :                 }
    8001             :         ;
    8002             : 
    8003             : RevokeRoleStmt:
    8004             :             REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
    8005             :                 {
    8006          90 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8007             : 
    8008          90 :                     n->is_grant = false;
    8009          90 :                     n->opt = NIL;
    8010          90 :                     n->granted_roles = $2;
    8011          90 :                     n->grantee_roles = $4;
    8012          90 :                     n->grantor = $5;
    8013          90 :                     n->behavior = $6;
    8014          90 :                     $$ = (Node *) n;
    8015             :                 }
    8016             :             | REVOKE ColId OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
    8017             :                 {
    8018          66 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8019             :                     DefElem *opt;
    8020             : 
    8021          66 :                     opt = makeDefElem(pstrdup($2),
    8022          66 :                                       (Node *) makeBoolean(false), @2);
    8023          66 :                     n->is_grant = false;
    8024          66 :                     n->opt = list_make1(opt);
    8025          66 :                     n->granted_roles = $5;
    8026          66 :                     n->grantee_roles = $7;
    8027          66 :                     n->grantor = $8;
    8028          66 :                     n->behavior = $9;
    8029          66 :                     $$ = (Node *) n;
    8030             :                 }
    8031             :         ;
    8032             : 
    8033             : grant_role_opt_list:
    8034         120 :             grant_role_opt_list ',' grant_role_opt  { $$ = lappend($1, $3); }
    8035         178 :             | grant_role_opt                        { $$ = list_make1($1); }
    8036             :         ;
    8037             : 
    8038             : grant_role_opt:
    8039             :         ColLabel grant_role_opt_value
    8040             :             {
    8041         298 :                 $$ = makeDefElem(pstrdup($1), $2, @1);
    8042             :             }
    8043             :         ;
    8044             : 
    8045             : grant_role_opt_value:
    8046          72 :         OPTION          { $$ = (Node *) makeBoolean(true); }
    8047         112 :         | TRUE_P        { $$ = (Node *) makeBoolean(true); }
    8048         114 :         | FALSE_P       { $$ = (Node *) makeBoolean(false); }
    8049             :         ;
    8050             : 
    8051         138 : opt_granted_by: GRANTED BY RoleSpec                     { $$ = $3; }
    8052       19920 :             | /*EMPTY*/                                 { $$ = NULL; }
    8053             :         ;
    8054             : 
    8055             : /*****************************************************************************
    8056             :  *
    8057             :  * ALTER DEFAULT PRIVILEGES statement
    8058             :  *
    8059             :  *****************************************************************************/
    8060             : 
    8061             : AlterDefaultPrivilegesStmt:
    8062             :             ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
    8063             :                 {
    8064         160 :                     AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
    8065             : 
    8066         160 :                     n->options = $4;
    8067         160 :                     n->action = (GrantStmt *) $5;
    8068         160 :                     $$ = (Node *) n;
    8069             :                 }
    8070             :         ;
    8071             : 
    8072             : DefACLOptionList:
    8073         122 :             DefACLOptionList DefACLOption           { $$ = lappend($1, $2); }
    8074         160 :             | /* EMPTY */                           { $$ = NIL; }
    8075             :         ;
    8076             : 
    8077             : DefACLOption:
    8078             :             IN_P SCHEMA name_list
    8079             :                 {
    8080          54 :                     $$ = makeDefElem("schemas", (Node *) $3, @1);
    8081             :                 }
    8082             :             | FOR ROLE role_list
    8083             :                 {
    8084          68 :                     $$ = makeDefElem("roles", (Node *) $3, @1);
    8085             :                 }
    8086             :             | FOR USER role_list
    8087             :                 {
    8088           0 :                     $$ = makeDefElem("roles", (Node *) $3, @1);
    8089             :                 }
    8090             :         ;
    8091             : 
    8092             : /*
    8093             :  * This should match GRANT/REVOKE, except that individual target objects
    8094             :  * are not mentioned and we only allow a subset of object types.
    8095             :  */
    8096             : DefACLAction:
    8097             :             GRANT privileges ON defacl_privilege_target TO grantee_list
    8098             :             opt_grant_grant_option
    8099             :                 {
    8100         100 :                     GrantStmt *n = makeNode(GrantStmt);
    8101             : 
    8102         100 :                     n->is_grant = true;
    8103         100 :                     n->privileges = $2;
    8104         100 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8105         100 :                     n->objtype = $4;
    8106         100 :                     n->objects = NIL;
    8107         100 :                     n->grantees = $6;
    8108         100 :                     n->grant_option = $7;
    8109         100 :                     $$ = (Node *) n;
    8110             :                 }
    8111             :             | REVOKE privileges ON defacl_privilege_target
    8112             :             FROM grantee_list opt_drop_behavior
    8113             :                 {
    8114          60 :                     GrantStmt *n = makeNode(GrantStmt);
    8115             : 
    8116          60 :                     n->is_grant = false;
    8117          60 :                     n->grant_option = false;
    8118          60 :                     n->privileges = $2;
    8119          60 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8120          60 :                     n->objtype = $4;
    8121          60 :                     n->objects = NIL;
    8122          60 :                     n->grantees = $6;
    8123          60 :                     n->behavior = $7;
    8124          60 :                     $$ = (Node *) n;
    8125             :                 }
    8126             :             | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
    8127             :             FROM grantee_list opt_drop_behavior
    8128             :                 {
    8129           0 :                     GrantStmt *n = makeNode(GrantStmt);
    8130             : 
    8131           0 :                     n->is_grant = false;
    8132           0 :                     n->grant_option = true;
    8133           0 :                     n->privileges = $5;
    8134           0 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8135           0 :                     n->objtype = $7;
    8136           0 :                     n->objects = NIL;
    8137           0 :                     n->grantees = $9;
    8138           0 :                     n->behavior = $10;
    8139           0 :                     $$ = (Node *) n;
    8140             :                 }
    8141             :         ;
    8142             : 
    8143             : defacl_privilege_target:
    8144          78 :             TABLES          { $$ = OBJECT_TABLE; }
    8145          16 :             | FUNCTIONS     { $$ = OBJECT_FUNCTION; }
    8146           6 :             | ROUTINES      { $$ = OBJECT_FUNCTION; }
    8147           6 :             | SEQUENCES     { $$ = OBJECT_SEQUENCE; }
    8148          18 :             | TYPES_P       { $$ = OBJECT_TYPE; }
    8149          36 :             | SCHEMAS       { $$ = OBJECT_SCHEMA; }
    8150             :         ;
    8151             : 
    8152             : 
    8153             : /*****************************************************************************
    8154             :  *
    8155             :  *      QUERY: CREATE INDEX
    8156             :  *
    8157             :  * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
    8158             :  * willing to make TABLESPACE a fully reserved word.
    8159             :  *****************************************************************************/
    8160             : 
    8161             : IndexStmt:  CREATE opt_unique INDEX opt_concurrently opt_single_name
    8162             :             ON relation_expr access_method_clause '(' index_params ')'
    8163             :             opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
    8164             :                 {
    8165        6430 :                     IndexStmt *n = makeNode(IndexStmt);
    8166             : 
    8167        6430 :                     n->unique = $2;
    8168        6430 :                     n->concurrent = $4;
    8169        6430 :                     n->idxname = $5;
    8170        6430 :                     n->relation = $7;
    8171        6430 :                     n->accessMethod = $8;
    8172        6430 :                     n->indexParams = $10;
    8173        6430 :                     n->indexIncludingParams = $12;
    8174        6430 :                     n->nulls_not_distinct = !$13;
    8175        6430 :                     n->options = $14;
    8176        6430 :                     n->tableSpace = $15;
    8177        6430 :                     n->whereClause = $16;
    8178        6430 :                     n->excludeOpNames = NIL;
    8179        6430 :                     n->idxcomment = NULL;
    8180        6430 :                     n->indexOid = InvalidOid;
    8181        6430 :                     n->oldNumber = InvalidRelFileNumber;
    8182        6430 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8183        6430 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8184        6430 :                     n->primary = false;
    8185        6430 :                     n->isconstraint = false;
    8186        6430 :                     n->deferrable = false;
    8187        6430 :                     n->initdeferred = false;
    8188        6430 :                     n->transformed = false;
    8189        6430 :                     n->if_not_exists = false;
    8190        6430 :                     n->reset_default_tblspc = false;
    8191        6430 :                     $$ = (Node *) n;
    8192             :                 }
    8193             :             | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS name
    8194             :             ON relation_expr access_method_clause '(' index_params ')'
    8195             :             opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
    8196             :                 {
    8197          18 :                     IndexStmt *n = makeNode(IndexStmt);
    8198             : 
    8199          18 :                     n->unique = $2;
    8200          18 :                     n->concurrent = $4;
    8201          18 :                     n->idxname = $8;
    8202          18 :                     n->relation = $10;
    8203          18 :                     n->accessMethod = $11;
    8204          18 :                     n->indexParams = $13;
    8205          18 :                     n->indexIncludingParams = $15;
    8206          18 :                     n->nulls_not_distinct = !$16;
    8207          18 :                     n->options = $17;
    8208          18 :                     n->tableSpace = $18;
    8209          18 :                     n->whereClause = $19;
    8210          18 :                     n->excludeOpNames = NIL;
    8211          18 :                     n->idxcomment = NULL;
    8212          18 :                     n->indexOid = InvalidOid;
    8213          18 :                     n->oldNumber = InvalidRelFileNumber;
    8214          18 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8215          18 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8216          18 :                     n->primary = false;
    8217          18 :                     n->isconstraint = false;
    8218          18 :                     n->deferrable = false;
    8219          18 :                     n->initdeferred = false;
    8220          18 :                     n->transformed = false;
    8221          18 :                     n->if_not_exists = true;
    8222          18 :                     n->reset_default_tblspc = false;
    8223          18 :                     $$ = (Node *) n;
    8224             :                 }
    8225             :         ;
    8226             : 
    8227             : opt_unique:
    8228        1248 :             UNIQUE                                  { $$ = true; }
    8229        5206 :             | /*EMPTY*/                             { $$ = false; }
    8230             :         ;
    8231             : 
    8232             : access_method_clause:
    8233        2906 :             USING name                              { $$ = $2; }
    8234        3776 :             | /*EMPTY*/                             { $$ = DEFAULT_INDEX_TYPE; }
    8235             :         ;
    8236             : 
    8237        7878 : index_params:   index_elem                          { $$ = list_make1($1); }
    8238        2118 :             | index_params ',' index_elem           { $$ = lappend($1, $3); }
    8239             :         ;
    8240             : 
    8241             : 
    8242             : index_elem_options:
    8243             :     opt_collate opt_qualified_name opt_asc_desc opt_nulls_order
    8244             :         {
    8245       10578 :             $$ = makeNode(IndexElem);
    8246       10578 :             $$->name = NULL;
    8247       10578 :             $$->expr = NULL;
    8248       10578 :             $$->indexcolname = NULL;
    8249       10578 :             $$->collation = $1;
    8250       10578 :             $$->opclass = $2;
    8251       10578 :             $$->opclassopts = NIL;
    8252       10578 :             $$->ordering = $3;
    8253       10578 :             $$->nulls_ordering = $4;
    8254             :         }
    8255             :     | opt_collate any_name reloptions opt_asc_desc opt_nulls_order
    8256             :         {
    8257         142 :             $$ = makeNode(IndexElem);
    8258         142 :             $$->name = NULL;
    8259         142 :             $$->expr = NULL;
    8260         142 :             $$->indexcolname = NULL;
    8261         142 :             $$->collation = $1;
    8262         142 :             $$->opclass = $2;
    8263         142 :             $$->opclassopts = $3;
    8264         142 :             $$->ordering = $4;
    8265         142 :             $$->nulls_ordering = $5;
    8266             :         }
    8267             :     ;
    8268             : 
    8269             : /*
    8270             :  * Index attributes can be either simple column references, or arbitrary
    8271             :  * expressions in parens.  For backwards-compatibility reasons, we allow
    8272             :  * an expression that's just a function call to be written without parens.
    8273             :  */
    8274             : index_elem: ColId index_elem_options
    8275             :                 {
    8276        9648 :                     $$ = $2;
    8277        9648 :                     $$->name = $1;
    8278             :                 }
    8279             :             | func_expr_windowless index_elem_options
    8280             :                 {
    8281         608 :                     $$ = $2;
    8282         608 :                     $$->expr = $1;
    8283             :                 }
    8284             :             | '(' a_expr ')' index_elem_options
    8285             :                 {
    8286         464 :                     $$ = $4;
    8287         464 :                     $$->expr = $2;
    8288             :                 }
    8289             :         ;
    8290             : 
    8291         218 : opt_include:        INCLUDE '(' index_including_params ')'          { $$ = $3; }
    8292        6230 :              |      /* EMPTY */                     { $$ = NIL; }
    8293             :         ;
    8294             : 
    8295         218 : index_including_params: index_elem                      { $$ = list_make1($1); }
    8296         166 :             | index_including_params ',' index_elem     { $$ = lappend($1, $3); }
    8297             :         ;
    8298             : 
    8299         192 : opt_collate: COLLATE any_name                       { $$ = $2; }
    8300       15786 :             | /*EMPTY*/                             { $$ = NIL; }
    8301             :         ;
    8302             : 
    8303             : 
    8304        1764 : opt_asc_desc: ASC                           { $$ = SORTBY_ASC; }
    8305        2906 :             | DESC                          { $$ = SORTBY_DESC; }
    8306       99844 :             | /*EMPTY*/                     { $$ = SORTBY_DEFAULT; }
    8307             :         ;
    8308             : 
    8309         348 : opt_nulls_order: NULLS_LA FIRST_P           { $$ = SORTBY_NULLS_FIRST; }
    8310        1698 :             | NULLS_LA LAST_P               { $$ = SORTBY_NULLS_LAST; }
    8311      102688 :             | /*EMPTY*/                     { $$ = SORTBY_NULLS_DEFAULT; }
    8312             :         ;
    8313             : 
    8314             : 
    8315             : /*****************************************************************************
    8316             :  *
    8317             :  *      QUERY:
    8318             :  *              create [or replace] function <fname>
    8319             :  *                      [(<type-1> { , <type-n>})]
    8320             :  *                      returns <type-r>
    8321             :  *                      as <filename or code in language as appropriate>
    8322             :  *                      language <lang> [with parameters]
    8323             :  *
    8324             :  *****************************************************************************/
    8325             : 
    8326             : CreateFunctionStmt:
    8327             :             CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8328             :             RETURNS func_return opt_createfunc_opt_list opt_routine_body
    8329             :                 {
    8330       21394 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8331             : 
    8332       21394 :                     n->is_procedure = false;
    8333       21394 :                     n->replace = $2;
    8334       21394 :                     n->funcname = $4;
    8335       21394 :                     n->parameters = $5;
    8336       21394 :                     n->returnType = $7;
    8337       21394 :                     n->options = $8;
    8338       21394 :                     n->sql_body = $9;
    8339       21394 :                     $$ = (Node *) n;
    8340             :                 }
    8341             :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8342             :               RETURNS TABLE '(' table_func_column_list ')' opt_createfunc_opt_list opt_routine_body
    8343             :                 {
    8344         188 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8345             : 
    8346         188 :                     n->is_procedure = false;
    8347         188 :                     n->replace = $2;
    8348         188 :                     n->funcname = $4;
    8349         188 :                     n->parameters = mergeTableFuncParameters($5, $9, yyscanner);
    8350         188 :                     n->returnType = TableFuncTypeName($9);
    8351         188 :                     n->returnType->location = @7;
    8352         188 :                     n->options = $11;
    8353         188 :                     n->sql_body = $12;
    8354         188 :                     $$ = (Node *) n;
    8355             :                 }
    8356             :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8357             :               opt_createfunc_opt_list opt_routine_body
    8358             :                 {
    8359         478 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8360             : 
    8361         478 :                     n->is_procedure = false;
    8362         478 :                     n->replace = $2;
    8363         478 :                     n->funcname = $4;
    8364         478 :                     n->parameters = $5;
    8365         478 :                     n->returnType = NULL;
    8366         478 :                     n->options = $6;
    8367         478 :                     n->sql_body = $7;
    8368         478 :                     $$ = (Node *) n;
    8369             :                 }
    8370             :             | CREATE opt_or_replace PROCEDURE func_name func_args_with_defaults
    8371             :               opt_createfunc_opt_list opt_routine_body
    8372             :                 {
    8373         362 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8374             : 
    8375         362 :                     n->is_procedure = true;
    8376         362 :                     n->replace = $2;
    8377         362 :                     n->funcname = $4;
    8378         362 :                     n->parameters = $5;
    8379         362 :                     n->returnType = NULL;
    8380         362 :                     n->options = $6;
    8381         362 :                     n->sql_body = $7;
    8382         362 :                     $$ = (Node *) n;
    8383             :                 }
    8384             :         ;
    8385             : 
    8386             : opt_or_replace:
    8387        9136 :             OR REPLACE                              { $$ = true; }
    8388       18578 :             | /*EMPTY*/                             { $$ = false; }
    8389             :         ;
    8390             : 
    8391        9374 : func_args:  '(' func_args_list ')'                  { $$ = $2; }
    8392        4904 :             | '(' ')'                               { $$ = NIL; }
    8393             :         ;
    8394             : 
    8395             : func_args_list:
    8396        9374 :             func_arg                                { $$ = list_make1($1); }
    8397        7830 :             | func_args_list ',' func_arg           { $$ = lappend($1, $3); }
    8398             :         ;
    8399             : 
    8400             : function_with_argtypes_list:
    8401       11168 :             function_with_argtypes                  { $$ = list_make1($1); }
    8402             :             | function_with_argtypes_list ',' function_with_argtypes
    8403          78 :                                                     { $$ = lappend($1, $3); }
    8404             :         ;
    8405             : 
    8406             : function_with_argtypes:
    8407             :             func_name func_args
    8408             :                 {
    8409       14278 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8410             : 
    8411       14278 :                     n->objname = $1;
    8412       14278 :                     n->objargs = extractArgTypes($2);
    8413       14278 :                     n->objfuncargs = $2;
    8414       14278 :                     $$ = n;
    8415             :                 }
    8416             :             /*
    8417             :              * Because of reduce/reduce conflicts, we can't use func_name
    8418             :              * below, but we can write it out the long way, which actually
    8419             :              * allows more cases.
    8420             :              */
    8421             :             | type_func_name_keyword
    8422             :                 {
    8423           0 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8424             : 
    8425           0 :                     n->objname = list_make1(makeString(pstrdup($1)));
    8426           0 :                     n->args_unspecified = true;
    8427           0 :                     $$ = n;
    8428             :                 }
    8429             :             | ColId
    8430             :                 {
    8431         328 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8432             : 
    8433         328 :                     n->objname = list_make1(makeString($1));
    8434         328 :                     n->args_unspecified = true;
    8435         328 :                     $$ = n;
    8436             :                 }
    8437             :             | ColId indirection
    8438             :                 {
    8439          28 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8440             : 
    8441          28 :                     n->objname = check_func_name(lcons(makeString($1), $2),
    8442             :                                                   yyscanner);
    8443          28 :                     n->args_unspecified = true;
    8444          28 :                     $$ = n;
    8445             :                 }
    8446             :         ;
    8447             : 
    8448             : /*
    8449             :  * func_args_with_defaults is separate because we only want to accept
    8450             :  * defaults in CREATE FUNCTION, not in ALTER etc.
    8451             :  */
    8452             : func_args_with_defaults:
    8453       18200 :         '(' func_args_with_defaults_list ')'        { $$ = $2; }
    8454        4222 :         | '(' ')'                                   { $$ = NIL; }
    8455             :         ;
    8456             : 
    8457             : func_args_with_defaults_list:
    8458       18200 :         func_arg_with_default                       { $$ = list_make1($1); }
    8459             :         | func_args_with_defaults_list ',' func_arg_with_default
    8460       31866 :                                                     { $$ = lappend($1, $3); }
    8461             :         ;
    8462             : 
    8463             : /*
    8464             :  * The style with arg_class first is SQL99 standard, but Oracle puts
    8465             :  * param_name first; accept both since it's likely people will try both
    8466             :  * anyway.  Don't bother trying to save productions by letting arg_class
    8467             :  * have an empty alternative ... you'll get shift/reduce conflicts.
    8468             :  *
    8469             :  * We can catch over-specified arguments here if we want to,
    8470             :  * but for now better to silently swallow typmod, etc.
    8471             :  * - thomas 2000-03-22
    8472             :  */
    8473             : func_arg:
    8474             :             arg_class param_name func_type
    8475             :                 {
    8476       14530 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8477             : 
    8478       14530 :                     n->name = $2;
    8479       14530 :                     n->argType = $3;
    8480       14530 :                     n->mode = $1;
    8481       14530 :                     n->defexpr = NULL;
    8482       14530 :                     n->location = @1;
    8483       14530 :                     $$ = n;
    8484             :                 }
    8485             :             | param_name arg_class func_type
    8486             :                 {
    8487         412 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8488             : 
    8489         412 :                     n->name = $1;
    8490         412 :                     n->argType = $3;
    8491         412 :                     n->mode = $2;
    8492         412 :                     n->defexpr = NULL;
    8493         412 :                     n->location = @1;
    8494         412 :                     $$ = n;
    8495             :                 }
    8496             :             | param_name func_type
    8497             :                 {
    8498       15530 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8499             : 
    8500       15530 :                     n->name = $1;
    8501       15530 :                     n->argType = $2;
    8502       15530 :                     n->mode = FUNC_PARAM_DEFAULT;
    8503       15530 :                     n->defexpr = NULL;
    8504       15530 :                     n->location = @1;
    8505       15530 :                     $$ = n;
    8506             :                 }
    8507             :             | arg_class func_type
    8508             :                 {
    8509         314 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8510             : 
    8511         314 :                     n->name = NULL;
    8512         314 :                     n->argType = $2;
    8513         314 :                     n->mode = $1;
    8514         314 :                     n->defexpr = NULL;
    8515         314 :                     n->location = @1;
    8516         314 :                     $$ = n;
    8517             :                 }
    8518             :             | func_type
    8519             :                 {
    8520       37384 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8521             : 
    8522       37384 :                     n->name = NULL;
    8523       37384 :                     n->argType = $1;
    8524       37384 :                     n->mode = FUNC_PARAM_DEFAULT;
    8525       37384 :                     n->defexpr = NULL;
    8526       37384 :                     n->location = @1;
    8527       37384 :                     $$ = n;
    8528             :                 }
    8529             :         ;
    8530             : 
    8531             : /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
    8532        3462 : arg_class:  IN_P                                { $$ = FUNC_PARAM_IN; }
    8533       11070 :             | OUT_P                             { $$ = FUNC_PARAM_OUT; }
    8534         198 :             | INOUT                             { $$ = FUNC_PARAM_INOUT; }
    8535           0 :             | IN_P OUT_P                        { $$ = FUNC_PARAM_INOUT; }
    8536         526 :             | VARIADIC                          { $$ = FUNC_PARAM_VARIADIC; }
    8537             :         ;
    8538             : 
    8539             : /*
    8540             :  * Ideally param_name should be ColId, but that causes too many conflicts.
    8541             :  */
    8542             : param_name: type_function_name
    8543             :         ;
    8544             : 
    8545             : func_return:
    8546             :             func_type
    8547             :                 {
    8548             :                     /* We can catch over-specified results here if we want to,
    8549             :                      * but for now better to silently swallow typmod, etc.
    8550             :                      * - thomas 2000-03-22
    8551             :                      */
    8552       21394 :                     $$ = $1;
    8553             :                 }
    8554             :         ;
    8555             : 
    8556             : /*
    8557             :  * We would like to make the %TYPE productions here be ColId attrs etc,
    8558             :  * but that causes reduce/reduce conflicts.  type_function_name
    8559             :  * is next best choice.
    8560             :  */
    8561      109482 : func_type:  Typename                                { $$ = $1; }
    8562             :             | type_function_name attrs '%' TYPE_P
    8563             :                 {
    8564          18 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
    8565          18 :                     $$->pct_type = true;
    8566          18 :                     $$->location = @1;
    8567             :                 }
    8568             :             | SETOF type_function_name attrs '%' TYPE_P
    8569             :                 {
    8570           6 :                     $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
    8571           6 :                     $$->pct_type = true;
    8572           6 :                     $$->setof = true;
    8573           6 :                     $$->location = @2;
    8574             :                 }
    8575             :         ;
    8576             : 
    8577             : func_arg_with_default:
    8578             :         func_arg
    8579             :                 {
    8580       43236 :                     $$ = $1;
    8581             :                 }
    8582             :         | func_arg DEFAULT a_expr
    8583             :                 {
    8584        6634 :                     $$ = $1;
    8585        6634 :                     $$->defexpr = $3;
    8586             :                 }
    8587             :         | func_arg '=' a_expr
    8588             :                 {
    8589         196 :                     $$ = $1;
    8590         196 :                     $$->defexpr = $3;
    8591             :                 }
    8592             :         ;
    8593             : 
    8594             : /* Aggregate args can be most things that function args can be */
    8595             : aggr_arg:   func_arg
    8596             :                 {
    8597         900 :                     if (!($1->mode == FUNC_PARAM_DEFAULT ||
    8598          60 :                           $1->mode == FUNC_PARAM_IN ||
    8599          60 :                           $1->mode == FUNC_PARAM_VARIADIC))
    8600           0 :                         ereport(ERROR,
    8601             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    8602             :                                  errmsg("aggregates cannot have output arguments"),
    8603             :                                  parser_errposition(@1)));
    8604         900 :                     $$ = $1;
    8605             :                 }
    8606             :         ;
    8607             : 
    8608             : /*
    8609             :  * The SQL standard offers no guidance on how to declare aggregate argument
    8610             :  * lists, since it doesn't have CREATE AGGREGATE etc.  We accept these cases:
    8611             :  *
    8612             :  * (*)                                  - normal agg with no args
    8613             :  * (aggr_arg,...)                       - normal agg with args
    8614             :  * (ORDER BY aggr_arg,...)              - ordered-set agg with no direct args
    8615             :  * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
    8616             :  *
    8617             :  * The zero-argument case is spelled with '*' for consistency with COUNT(*).
    8618             :  *
    8619             :  * An additional restriction is that if the direct-args list ends in a
    8620             :  * VARIADIC item, the ordered-args list must contain exactly one item that
    8621             :  * is also VARIADIC with the same type.  This allows us to collapse the two
    8622             :  * VARIADIC items into one, which is necessary to represent the aggregate in
    8623             :  * pg_proc.  We check this at the grammar stage so that we can return a list
    8624             :  * in which the second VARIADIC item is already discarded, avoiding extra work
    8625             :  * in cases such as DROP AGGREGATE.
    8626             :  *
    8627             :  * The return value of this production is a two-element list, in which the
    8628             :  * first item is a sublist of FunctionParameter nodes (with any duplicate
    8629             :  * VARIADIC item already dropped, as per above) and the second is an Integer
    8630             :  * node, containing -1 if there was no ORDER BY and otherwise the number
    8631             :  * of argument declarations before the ORDER BY.  (If this number is equal
    8632             :  * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
    8633             :  * This representation is passed as-is to CREATE AGGREGATE; for operations
    8634             :  * on existing aggregates, we can just apply extractArgTypes to the first
    8635             :  * sublist.
    8636             :  */
    8637             : aggr_args:  '(' '*' ')'
    8638             :                 {
    8639         136 :                     $$ = list_make2(NIL, makeInteger(-1));
    8640             :                 }
    8641             :             | '(' aggr_args_list ')'
    8642             :                 {
    8643         732 :                     $$ = list_make2($2, makeInteger(-1));
    8644             :                 }
    8645             :             | '(' ORDER BY aggr_args_list ')'
    8646             :                 {
    8647           6 :                     $$ = list_make2($4, makeInteger(0));
    8648             :                 }
    8649             :             | '(' aggr_args_list ORDER BY aggr_args_list ')'
    8650             :                 {
    8651             :                     /* this is the only case requiring consistency checking */
    8652          32 :                     $$ = makeOrderedSetArgs($2, $5, yyscanner);
    8653             :                 }
    8654             :         ;
    8655             : 
    8656             : aggr_args_list:
    8657         802 :             aggr_arg                                { $$ = list_make1($1); }
    8658          98 :             | aggr_args_list ',' aggr_arg           { $$ = lappend($1, $3); }
    8659             :         ;
    8660             : 
    8661             : aggregate_with_argtypes:
    8662             :             func_name aggr_args
    8663             :                 {
    8664         362 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8665             : 
    8666         362 :                     n->objname = $1;
    8667         362 :                     n->objargs = extractAggrArgTypes($2);
    8668         362 :                     n->objfuncargs = (List *) linitial($2);
    8669         362 :                     $$ = n;
    8670             :                 }
    8671             :         ;
    8672             : 
    8673             : aggregate_with_argtypes_list:
    8674         104 :             aggregate_with_argtypes                 { $$ = list_make1($1); }
    8675             :             | aggregate_with_argtypes_list ',' aggregate_with_argtypes
    8676           0 :                                                     { $$ = lappend($1, $3); }
    8677             :         ;
    8678             : 
    8679             : opt_createfunc_opt_list:
    8680             :             createfunc_opt_list
    8681          48 :             | /*EMPTY*/ { $$ = NIL; }
    8682             :     ;
    8683             : 
    8684             : createfunc_opt_list:
    8685             :             /* Must be at least one to prevent conflict */
    8686       22374 :             createfunc_opt_item                     { $$ = list_make1($1); }
    8687       58344 :             | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
    8688             :     ;
    8689             : 
    8690             : /*
    8691             :  * Options common to both CREATE FUNCTION and ALTER FUNCTION
    8692             :  */
    8693             : common_func_opt_item:
    8694             :             CALLED ON NULL_P INPUT_P
    8695             :                 {
    8696         460 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(false), @1);
    8697             :                 }
    8698             :             | RETURNS NULL_P ON NULL_P INPUT_P
    8699             :                 {
    8700         792 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8701             :                 }
    8702             :             | STRICT_P
    8703             :                 {
    8704       11292 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8705             :                 }
    8706             :             | IMMUTABLE
    8707             :                 {
    8708        8576 :                     $$ = makeDefElem("volatility", (Node *) makeString("immutable"), @1);
    8709             :                 }
    8710             :             | STABLE
    8711             :                 {
    8712        2100 :                     $$ = makeDefElem("volatility", (Node *) makeString("stable"), @1);
    8713             :                 }
    8714             :             | VOLATILE
    8715             :                 {
    8716        1672 :                     $$ = makeDefElem("volatility", (Node *) makeString("volatile"), @1);
    8717             :                 }
    8718             :             | EXTERNAL SECURITY DEFINER
    8719             :                 {
    8720           0 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8721             :                 }
    8722             :             | EXTERNAL SECURITY INVOKER
    8723             :                 {
    8724           0 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8725             :                 }
    8726             :             | SECURITY DEFINER
    8727             :                 {
    8728          48 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8729             :                 }
    8730             :             | SECURITY INVOKER
    8731             :                 {
    8732          12 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8733             :                 }
    8734             :             | LEAKPROOF
    8735             :                 {
    8736          46 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(true), @1);
    8737             :                 }
    8738             :             | NOT LEAKPROOF
    8739             :                 {
    8740          12 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(false), @1);
    8741             :                 }
    8742             :             | COST NumericOnly
    8743             :                 {
    8744        3908 :                     $$ = makeDefElem("cost", (Node *) $2, @1);
    8745             :                 }
    8746             :             | ROWS NumericOnly
    8747             :                 {
    8748         540 :                     $$ = makeDefElem("rows", (Node *) $2, @1);
    8749             :                 }
    8750             :             | SUPPORT any_name
    8751             :                 {
    8752         104 :                     $$ = makeDefElem("support", (Node *) $2, @1);
    8753             :                 }
    8754             :             | FunctionSetResetClause
    8755             :                 {
    8756             :                     /* we abuse the normal content of a DefElem here */
    8757         140 :                     $$ = makeDefElem("set", (Node *) $1, @1);
    8758             :                 }
    8759             :             | PARALLEL ColId
    8760             :                 {
    8761       11866 :                     $$ = makeDefElem("parallel", (Node *) makeString($2), @1);
    8762             :                 }
    8763             :         ;
    8764             : 
    8765             : createfunc_opt_item:
    8766             :             AS func_as
    8767             :                 {
    8768       17314 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    8769             :                 }
    8770             :             | LANGUAGE NonReservedWord_or_Sconst
    8771             :                 {
    8772       22354 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    8773             :                 }
    8774             :             | TRANSFORM transform_type_list
    8775             :                 {
    8776         118 :                     $$ = makeDefElem("transform", (Node *) $2, @1);
    8777             :                 }
    8778             :             | WINDOW
    8779             :                 {
    8780          20 :                     $$ = makeDefElem("window", (Node *) makeBoolean(true), @1);
    8781             :                 }
    8782             :             | common_func_opt_item
    8783             :                 {
    8784       40912 :                     $$ = $1;
    8785             :                 }
    8786             :         ;
    8787             : 
    8788       14594 : func_as:    Sconst                      { $$ = list_make1(makeString($1)); }
    8789             :             | Sconst ',' Sconst
    8790             :                 {
    8791        2720 :                     $$ = list_make2(makeString($1), makeString($3));
    8792             :                 }
    8793             :         ;
    8794             : 
    8795             : ReturnStmt: RETURN a_expr
    8796             :                 {
    8797        4388 :                     ReturnStmt *r = makeNode(ReturnStmt);
    8798             : 
    8799        4388 :                     r->returnval = (Node *) $2;
    8800        4388 :                     $$ = (Node *) r;
    8801             :                 }
    8802             :         ;
    8803             : 
    8804             : opt_routine_body:
    8805             :             ReturnStmt
    8806             :                 {
    8807        4382 :                     $$ = $1;
    8808             :                 }
    8809             :             | BEGIN_P ATOMIC routine_body_stmt_list END_P
    8810             :                 {
    8811             :                     /*
    8812             :                      * A compound statement is stored as a single-item list
    8813             :                      * containing the list of statements as its member.  That
    8814             :                      * way, the parse analysis code can tell apart an empty
    8815             :                      * body from no body at all.
    8816             :                      */
    8817         732 :                     $$ = (Node *) list_make1($3);
    8818             :                 }
    8819             :             | /*EMPTY*/
    8820             :                 {
    8821       17308 :                     $$ = NULL;
    8822             :                 }
    8823             :         ;
    8824             : 
    8825             : routine_body_stmt_list:
    8826             :             routine_body_stmt_list routine_body_stmt ';'
    8827             :                 {
    8828             :                     /* As in stmtmulti, discard empty statements */
    8829         748 :                     if ($2 != NULL)
    8830         730 :                         $$ = lappend($1, $2);
    8831             :                     else
    8832          18 :                         $$ = $1;
    8833             :                 }
    8834             :             | /*EMPTY*/
    8835             :                 {
    8836         732 :                     $$ = NIL;
    8837             :                 }
    8838             :         ;
    8839             : 
    8840             : routine_body_stmt:
    8841             :             stmt
    8842             :             | ReturnStmt
    8843             :         ;
    8844             : 
    8845             : transform_type_list:
    8846         118 :             FOR TYPE_P Typename { $$ = list_make1($3); }
    8847           4 :             | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
    8848             :         ;
    8849             : 
    8850             : opt_definition:
    8851         588 :             WITH definition                         { $$ = $2; }
    8852        9516 :             | /*EMPTY*/                             { $$ = NIL; }
    8853             :         ;
    8854             : 
    8855             : table_func_column:  param_name func_type
    8856             :                 {
    8857         442 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8858             : 
    8859         442 :                     n->name = $1;
    8860         442 :                     n->argType = $2;
    8861         442 :                     n->mode = FUNC_PARAM_TABLE;
    8862         442 :                     n->defexpr = NULL;
    8863         442 :                     n->location = @1;
    8864         442 :                     $$ = n;
    8865             :                 }
    8866             :         ;
    8867             : 
    8868             : table_func_column_list:
    8869             :             table_func_column
    8870             :                 {
    8871         188 :                     $$ = list_make1($1);
    8872             :                 }
    8873             :             | table_func_column_list ',' table_func_column
    8874             :                 {
    8875         254 :                     $$ = lappend($1, $3);
    8876             :                 }
    8877             :         ;
    8878             : 
    8879             : /*****************************************************************************
    8880             :  * ALTER FUNCTION / ALTER PROCEDURE / ALTER ROUTINE
    8881             :  *
    8882             :  * RENAME and OWNER subcommands are already provided by the generic
    8883             :  * ALTER infrastructure, here we just specify alterations that can
    8884             :  * only be applied to functions.
    8885             :  *
    8886             :  *****************************************************************************/
    8887             : AlterFunctionStmt:
    8888             :             ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
    8889             :                 {
    8890         638 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8891             : 
    8892         638 :                     n->objtype = OBJECT_FUNCTION;
    8893         638 :                     n->func = $3;
    8894         638 :                     n->actions = $4;
    8895         638 :                     $$ = (Node *) n;
    8896             :                 }
    8897             :             | ALTER PROCEDURE function_with_argtypes alterfunc_opt_list opt_restrict
    8898             :                 {
    8899          18 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8900             : 
    8901          18 :                     n->objtype = OBJECT_PROCEDURE;
    8902          18 :                     n->func = $3;
    8903          18 :                     n->actions = $4;
    8904          18 :                     $$ = (Node *) n;
    8905             :                 }
    8906             :             | ALTER ROUTINE function_with_argtypes alterfunc_opt_list opt_restrict
    8907             :                 {
    8908           0 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8909             : 
    8910           0 :                     n->objtype = OBJECT_ROUTINE;
    8911           0 :                     n->func = $3;
    8912           0 :                     n->actions = $4;
    8913           0 :                     $$ = (Node *) n;
    8914             :                 }
    8915             :         ;
    8916             : 
    8917             : alterfunc_opt_list:
    8918             :             /* At least one option must be specified */
    8919         656 :             common_func_opt_item                    { $$ = list_make1($1); }
    8920           0 :             | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
    8921             :         ;
    8922             : 
    8923             : /* Ignored, merely for SQL compliance */
    8924             : opt_restrict:
    8925             :             RESTRICT
    8926             :             | /* EMPTY */
    8927             :         ;
    8928             : 
    8929             : 
    8930             : /*****************************************************************************
    8931             :  *
    8932             :  *      QUERY:
    8933             :  *
    8934             :  *      DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    8935             :  *      DROP PROCEDURE procname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    8936             :  *      DROP ROUTINE routname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    8937             :  *      DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
    8938             :  *      DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
    8939             :  *
    8940             :  *****************************************************************************/
    8941             : 
    8942             : RemoveFuncStmt:
    8943             :             DROP FUNCTION function_with_argtypes_list opt_drop_behavior
    8944             :                 {
    8945        3192 :                     DropStmt *n = makeNode(DropStmt);
    8946             : 
    8947        3192 :                     n->removeType = OBJECT_FUNCTION;
    8948        3192 :                     n->objects = $3;
    8949        3192 :                     n->behavior = $4;
    8950        3192 :                     n->missing_ok = false;
    8951        3192 :                     n->concurrent = false;
    8952        3192 :                     $$ = (Node *) n;
    8953             :                 }
    8954             :             | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    8955             :                 {
    8956         260 :                     DropStmt *n = makeNode(DropStmt);
    8957             : 
    8958         260 :                     n->removeType = OBJECT_FUNCTION;
    8959         260 :                     n->objects = $5;
    8960         260 :                     n->behavior = $6;
    8961         260 :                     n->missing_ok = true;
    8962         260 :                     n->concurrent = false;
    8963         260 :                     $$ = (Node *) n;
    8964             :                 }
    8965             :             | DROP PROCEDURE function_with_argtypes_list opt_drop_behavior
    8966             :                 {
    8967         138 :                     DropStmt *n = makeNode(DropStmt);
    8968             : 
    8969         138 :                     n->removeType = OBJECT_PROCEDURE;
    8970         138 :                     n->objects = $3;
    8971         138 :                     n->behavior = $4;
    8972         138 :                     n->missing_ok = false;
    8973         138 :                     n->concurrent = false;
    8974         138 :                     $$ = (Node *) n;
    8975             :                 }
    8976             :             | DROP PROCEDURE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    8977             :                 {
    8978           6 :                     DropStmt *n = makeNode(DropStmt);
    8979             : 
    8980           6 :                     n->removeType = OBJECT_PROCEDURE;
    8981           6 :                     n->objects = $5;
    8982           6 :                     n->behavior = $6;
    8983           6 :                     n->missing_ok = true;
    8984           6 :                     n->concurrent = false;
    8985           6 :                     $$ = (Node *) n;
    8986             :                 }
    8987             :             | DROP ROUTINE function_with_argtypes_list opt_drop_behavior
    8988             :                 {
    8989          12 :                     DropStmt *n = makeNode(DropStmt);
    8990             : 
    8991          12 :                     n->removeType = OBJECT_ROUTINE;
    8992          12 :                     n->objects = $3;
    8993          12 :                     n->behavior = $4;
    8994          12 :                     n->missing_ok = false;
    8995          12 :                     n->concurrent = false;
    8996          12 :                     $$ = (Node *) n;
    8997             :                 }
    8998             :             | DROP ROUTINE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    8999             :                 {
    9000           6 :                     DropStmt *n = makeNode(DropStmt);
    9001             : 
    9002           6 :                     n->removeType = OBJECT_ROUTINE;
    9003           6 :                     n->objects = $5;
    9004           6 :                     n->behavior = $6;
    9005           6 :                     n->missing_ok = true;
    9006           6 :                     n->concurrent = false;
    9007           6 :                     $$ = (Node *) n;
    9008             :                 }
    9009             :         ;
    9010             : 
    9011             : RemoveAggrStmt:
    9012             :             DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
    9013             :                 {
    9014          74 :                     DropStmt *n = makeNode(DropStmt);
    9015             : 
    9016          74 :                     n->removeType = OBJECT_AGGREGATE;
    9017          74 :                     n->objects = $3;
    9018          74 :                     n->behavior = $4;
    9019          74 :                     n->missing_ok = false;
    9020          74 :                     n->concurrent = false;
    9021          74 :                     $$ = (Node *) n;
    9022             :                 }
    9023             :             | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
    9024             :                 {
    9025          30 :                     DropStmt *n = makeNode(DropStmt);
    9026             : 
    9027          30 :                     n->removeType = OBJECT_AGGREGATE;
    9028          30 :                     n->objects = $5;
    9029          30 :                     n->behavior = $6;
    9030          30 :                     n->missing_ok = true;
    9031          30 :                     n->concurrent = false;
    9032          30 :                     $$ = (Node *) n;
    9033             :                 }
    9034             :         ;
    9035             : 
    9036             : RemoveOperStmt:
    9037             :             DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
    9038             :                 {
    9039         194 :                     DropStmt *n = makeNode(DropStmt);
    9040             : 
    9041         194 :                     n->removeType = OBJECT_OPERATOR;
    9042         194 :                     n->objects = $3;
    9043         194 :                     n->behavior = $4;
    9044         194 :                     n->missing_ok = false;
    9045         194 :                     n->concurrent = false;
    9046         194 :                     $$ = (Node *) n;
    9047             :                 }
    9048             :             | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
    9049             :                 {
    9050          30 :                     DropStmt *n = makeNode(DropStmt);
    9051             : 
    9052          30 :                     n->removeType = OBJECT_OPERATOR;
    9053          30 :                     n->objects = $5;
    9054          30 :                     n->behavior = $6;
    9055          30 :                     n->missing_ok = true;
    9056          30 :                     n->concurrent = false;
    9057          30 :                     $$ = (Node *) n;
    9058             :                 }
    9059             :         ;
    9060             : 
    9061             : oper_argtypes:
    9062             :             '(' Typename ')'
    9063             :                 {
    9064          12 :                    ereport(ERROR,
    9065             :                            (errcode(ERRCODE_SYNTAX_ERROR),
    9066             :                             errmsg("missing argument"),
    9067             :                             errhint("Use NONE to denote the missing argument of a unary operator."),
    9068             :                             parser_errposition(@3)));
    9069             :                 }
    9070             :             | '(' Typename ',' Typename ')'
    9071        1950 :                     { $$ = list_make2($2, $4); }
    9072             :             | '(' NONE ',' Typename ')'                 /* left unary */
    9073          32 :                     { $$ = list_make2(NULL, $4); }
    9074             :             | '(' Typename ',' NONE ')'                 /* right unary */
    9075          12 :                     { $$ = list_make2($2, NULL); }
    9076             :         ;
    9077             : 
    9078             : any_operator:
    9079             :             all_Op
    9080       19752 :                     { $$ = list_make1(makeString($1)); }
    9081             :             | ColId '.' any_operator
    9082       14846 :                     { $$ = lcons(makeString($1), $3); }
    9083             :         ;
    9084             : 
    9085             : operator_with_argtypes_list:
    9086         224 :             operator_with_argtypes                  { $$ = list_make1($1); }
    9087             :             | operator_with_argtypes_list ',' operator_with_argtypes
    9088           0 :                                                     { $$ = lappend($1, $3); }
    9089             :         ;
    9090             : 
    9091             : operator_with_argtypes:
    9092             :             any_operator oper_argtypes
    9093             :                 {
    9094        1994 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    9095             : 
    9096        1994 :                     n->objname = $1;
    9097        1994 :                     n->objargs = $2;
    9098        1994 :                     $$ = n;
    9099             :                 }
    9100             :         ;
    9101             : 
    9102             : /*****************************************************************************
    9103             :  *
    9104             :  *      DO <anonymous code block> [ LANGUAGE language ]
    9105             :  *
    9106             :  * We use a DefElem list for future extensibility, and to allow flexibility
    9107             :  * in the clause order.
    9108             :  *
    9109             :  *****************************************************************************/
    9110             : 
    9111             : DoStmt: DO dostmt_opt_list
    9112             :                 {
    9113        1128 :                     DoStmt *n = makeNode(DoStmt);
    9114             : 
    9115        1128 :                     n->args = $2;
    9116        1128 :                     $$ = (Node *) n;
    9117             :                 }
    9118             :         ;
    9119             : 
    9120             : dostmt_opt_list:
    9121        1128 :             dostmt_opt_item                     { $$ = list_make1($1); }
    9122         198 :             | dostmt_opt_list dostmt_opt_item   { $$ = lappend($1, $2); }
    9123             :         ;
    9124             : 
    9125             : dostmt_opt_item:
    9126             :             Sconst
    9127             :                 {
    9128        1128 :                     $$ = makeDefElem("as", (Node *) makeString($1), @1);
    9129             :                 }
    9130             :             | LANGUAGE NonReservedWord_or_Sconst
    9131             :                 {
    9132         198 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    9133             :                 }
    9134             :         ;
    9135             : 
    9136             : /*****************************************************************************
    9137             :  *
    9138             :  *      CREATE CAST / DROP CAST
    9139             :  *
    9140             :  *****************************************************************************/
    9141             : 
    9142             : CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
    9143             :                     WITH FUNCTION function_with_argtypes cast_context
    9144             :                 {
    9145         102 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9146             : 
    9147         102 :                     n->sourcetype = $4;
    9148         102 :                     n->targettype = $6;
    9149         102 :                     n->func = $10;
    9150         102 :                     n->context = (CoercionContext) $11;
    9151         102 :                     n->inout = false;
    9152         102 :                     $$ = (Node *) n;
    9153             :                 }
    9154             :             | CREATE CAST '(' Typename AS Typename ')'
    9155             :                     WITHOUT FUNCTION cast_context
    9156             :                 {
    9157         162 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9158             : 
    9159         162 :                     n->sourcetype = $4;
    9160         162 :                     n->targettype = $6;
    9161         162 :                     n->func = NULL;
    9162         162 :                     n->context = (CoercionContext) $10;
    9163         162 :                     n->inout = false;
    9164         162 :                     $$ = (Node *) n;
    9165             :                 }
    9166             :             | CREATE CAST '(' Typename AS Typename ')'
    9167             :                     WITH INOUT cast_context
    9168             :                 {
    9169           6 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9170             : 
    9171           6 :                     n->sourcetype = $4;
    9172           6 :                     n->targettype = $6;
    9173           6 :                     n->func = NULL;
    9174           6 :                     n->context = (CoercionContext) $10;
    9175           6 :                     n->inout = true;
    9176           6 :                     $$ = (Node *) n;
    9177             :                 }
    9178             :         ;
    9179             : 
    9180          30 : cast_context:  AS IMPLICIT_P                    { $$ = COERCION_IMPLICIT; }
    9181          58 :         | AS ASSIGNMENT                         { $$ = COERCION_ASSIGNMENT; }
    9182         182 :         | /*EMPTY*/                             { $$ = COERCION_EXPLICIT; }
    9183             :         ;
    9184             : 
    9185             : 
    9186             : DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
    9187             :                 {
    9188          54 :                     DropStmt *n = makeNode(DropStmt);
    9189             : 
    9190          54 :                     n->removeType = OBJECT_CAST;
    9191          54 :                     n->objects = list_make1(list_make2($5, $7));
    9192          54 :                     n->behavior = $9;
    9193          54 :                     n->missing_ok = $3;
    9194          54 :                     n->concurrent = false;
    9195          54 :                     $$ = (Node *) n;
    9196             :                 }
    9197             :         ;
    9198             : 
    9199          36 : opt_if_exists: IF_P EXISTS                      { $$ = true; }
    9200          32 :         | /*EMPTY*/                             { $$ = false; }
    9201             :         ;
    9202             : 
    9203             : 
    9204             : /*****************************************************************************
    9205             :  *
    9206             :  *      CREATE TRANSFORM / DROP TRANSFORM
    9207             :  *
    9208             :  *****************************************************************************/
    9209             : 
    9210             : CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name '(' transform_element_list ')'
    9211             :                 {
    9212          50 :                     CreateTransformStmt *n = makeNode(CreateTransformStmt);
    9213             : 
    9214          50 :                     n->replace = $2;
    9215          50 :                     n->type_name = $5;
    9216          50 :                     n->lang = $7;
    9217          50 :                     n->fromsql = linitial($9);
    9218          50 :                     n->tosql = lsecond($9);
    9219          50 :                     $$ = (Node *) n;
    9220             :                 }
    9221             :         ;
    9222             : 
    9223             : transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes ',' TO SQL_P WITH FUNCTION function_with_argtypes
    9224             :                 {
    9225          44 :                     $$ = list_make2($5, $11);
    9226             :                 }
    9227             :                 | TO SQL_P WITH FUNCTION function_with_argtypes ',' FROM SQL_P WITH FUNCTION function_with_argtypes
    9228             :                 {
    9229           0 :                     $$ = list_make2($11, $5);
    9230             :                 }
    9231             :                 | FROM SQL_P WITH FUNCTION function_with_argtypes
    9232             :                 {
    9233           4 :                     $$ = list_make2($5, NULL);
    9234             :                 }
    9235             :                 | TO SQL_P WITH FUNCTION function_with_argtypes
    9236             :                 {
    9237           2 :                     $$ = list_make2(NULL, $5);
    9238             :                 }
    9239             :         ;
    9240             : 
    9241             : 
    9242             : DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
    9243             :                 {
    9244          14 :                     DropStmt *n = makeNode(DropStmt);
    9245             : 
    9246          14 :                     n->removeType = OBJECT_TRANSFORM;
    9247          14 :                     n->objects = list_make1(list_make2($5, makeString($7)));
    9248          14 :                     n->behavior = $8;
    9249          14 :                     n->missing_ok = $3;
    9250          14 :                     $$ = (Node *) n;
    9251             :                 }
    9252             :         ;
    9253             : 
    9254             : 
    9255             : /*****************************************************************************
    9256             :  *
    9257             :  *      QUERY:
    9258             :  *
    9259             :  *      REINDEX [ (options) ] {INDEX | TABLE | SCHEMA} [CONCURRENTLY] <name>
    9260             :  *      REINDEX [ (options) ] {DATABASE | SYSTEM} [CONCURRENTLY] [<name>]
    9261             :  *****************************************************************************/
    9262             : 
    9263             : ReindexStmt:
    9264             :             REINDEX opt_reindex_option_list reindex_target_relation opt_concurrently qualified_name
    9265             :                 {
    9266         908 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9267             : 
    9268         908 :                     n->kind = $3;
    9269         908 :                     n->relation = $5;
    9270         908 :                     n->name = NULL;
    9271         908 :                     n->params = $2;
    9272         908 :                     if ($4)
    9273         508 :                         n->params = lappend(n->params,
    9274         508 :                                             makeDefElem("concurrently", NULL, @4));
    9275         908 :                     $$ = (Node *) n;
    9276             :                 }
    9277             :             | REINDEX opt_reindex_option_list SCHEMA opt_concurrently name
    9278             :                 {
    9279         114 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9280             : 
    9281         114 :                     n->kind = REINDEX_OBJECT_SCHEMA;
    9282         114 :                     n->relation = NULL;
    9283         114 :                     n->name = $5;
    9284         114 :                     n->params = $2;
    9285         114 :                     if ($4)
    9286          40 :                         n->params = lappend(n->params,
    9287          40 :                                             makeDefElem("concurrently", NULL, @4));
    9288         114 :                     $$ = (Node *) n;
    9289             :                 }
    9290             :             | REINDEX opt_reindex_option_list reindex_target_all opt_concurrently opt_single_name
    9291             :                 {
    9292          68 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9293             : 
    9294          68 :                     n->kind = $3;
    9295          68 :                     n->relation = NULL;
    9296          68 :                     n->name = $5;
    9297          68 :                     n->params = $2;
    9298          68 :                     if ($4)
    9299          10 :                         n->params = lappend(n->params,
    9300          10 :                                             makeDefElem("concurrently", NULL, @4));
    9301          68 :                     $$ = (Node *) n;
    9302             :                 }
    9303             :         ;
    9304             : reindex_target_relation:
    9305         392 :             INDEX                   { $$ = REINDEX_OBJECT_INDEX; }
    9306         516 :             | TABLE                 { $$ = REINDEX_OBJECT_TABLE; }
    9307             :         ;
    9308             : reindex_target_all:
    9309          34 :             SYSTEM_P                { $$ = REINDEX_OBJECT_SYSTEM; }
    9310          34 :             | DATABASE              { $$ = REINDEX_OBJECT_DATABASE; }
    9311             :         ;
    9312             : opt_reindex_option_list:
    9313         156 :             '(' utility_option_list ')'             { $$ = $2; }
    9314         934 :             | /* EMPTY */                           { $$ = NULL; }
    9315             :         ;
    9316             : 
    9317             : /*****************************************************************************
    9318             :  *
    9319             :  * ALTER TABLESPACE
    9320             :  *
    9321             :  *****************************************************************************/
    9322             : 
    9323             : AlterTblSpcStmt:
    9324             :             ALTER TABLESPACE name SET reloptions
    9325             :                 {
    9326             :                     AlterTableSpaceOptionsStmt *n =
    9327          12 :                         makeNode(AlterTableSpaceOptionsStmt);
    9328             : 
    9329          12 :                     n->tablespacename = $3;
    9330          12 :                     n->options = $5;
    9331          12 :                     n->isReset = false;
    9332          12 :                     $$ = (Node *) n;
    9333             :                 }
    9334             :             | ALTER TABLESPACE name RESET reloptions
    9335             :                 {
    9336             :                     AlterTableSpaceOptionsStmt *n =
    9337          12 :                         makeNode(AlterTableSpaceOptionsStmt);
    9338             : 
    9339          12 :                     n->tablespacename = $3;
    9340          12 :                     n->options = $5;
    9341          12 :                     n->isReset = true;
    9342          12 :                     $$ = (Node *) n;
    9343             :                 }
    9344             :         ;
    9345             : 
    9346             : /*****************************************************************************
    9347             :  *
    9348             :  * ALTER THING name RENAME TO newname
    9349             :  *
    9350             :  *****************************************************************************/
    9351             : 
    9352             : RenameStmt: ALTER AGGREGATE aggregate_with_argtypes RENAME TO name
    9353             :                 {
    9354          42 :                     RenameStmt *n = makeNode(RenameStmt);
    9355             : 
    9356          42 :                     n->renameType = OBJECT_AGGREGATE;
    9357          42 :                     n->object = (Node *) $3;
    9358          42 :                     n->newname = $6;
    9359          42 :                     n->missing_ok = false;
    9360          42 :                     $$ = (Node *) n;
    9361             :                 }
    9362             :             | ALTER COLLATION any_name RENAME TO name
    9363             :                 {
    9364          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9365             : 
    9366          18 :                     n->renameType = OBJECT_COLLATION;
    9367          18 :                     n->object = (Node *) $3;
    9368          18 :                     n->newname = $6;
    9369          18 :                     n->missing_ok = false;
    9370          18 :                     $$ = (Node *) n;
    9371             :                 }
    9372             :             | ALTER CONVERSION_P any_name RENAME TO name
    9373             :                 {
    9374          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9375             : 
    9376          24 :                     n->renameType = OBJECT_CONVERSION;
    9377          24 :                     n->object = (Node *) $3;
    9378          24 :                     n->newname = $6;
    9379          24 :                     n->missing_ok = false;
    9380          24 :                     $$ = (Node *) n;
    9381             :                 }
    9382             :             | ALTER DATABASE name RENAME TO name
    9383             :                 {
    9384           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9385             : 
    9386           6 :                     n->renameType = OBJECT_DATABASE;
    9387           6 :                     n->subname = $3;
    9388           6 :                     n->newname = $6;
    9389           6 :                     n->missing_ok = false;
    9390           6 :                     $$ = (Node *) n;
    9391             :                 }
    9392             :             | ALTER DOMAIN_P any_name RENAME TO name
    9393             :                 {
    9394           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9395             : 
    9396           6 :                     n->renameType = OBJECT_DOMAIN;
    9397           6 :                     n->object = (Node *) $3;
    9398           6 :                     n->newname = $6;
    9399           6 :                     n->missing_ok = false;
    9400           6 :                     $$ = (Node *) n;
    9401             :                 }
    9402             :             | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
    9403             :                 {
    9404           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9405             : 
    9406           6 :                     n->renameType = OBJECT_DOMCONSTRAINT;
    9407           6 :                     n->object = (Node *) $3;
    9408           6 :                     n->subname = $6;
    9409           6 :                     n->newname = $8;
    9410           6 :                     $$ = (Node *) n;
    9411             :                 }
    9412             :             | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
    9413             :                 {
    9414          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9415             : 
    9416          24 :                     n->renameType = OBJECT_FDW;
    9417          24 :                     n->object = (Node *) makeString($5);
    9418          24 :                     n->newname = $8;
    9419          24 :                     n->missing_ok = false;
    9420          24 :                     $$ = (Node *) n;
    9421             :                 }
    9422             :             | ALTER FUNCTION function_with_argtypes RENAME TO name
    9423             :                 {
    9424          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9425             : 
    9426          24 :                     n->renameType = OBJECT_FUNCTION;
    9427          24 :                     n->object = (Node *) $3;
    9428          24 :                     n->newname = $6;
    9429          24 :                     n->missing_ok = false;
    9430          24 :                     $$ = (Node *) n;
    9431             :                 }
    9432             :             | ALTER GROUP_P RoleId RENAME TO RoleId
    9433             :                 {
    9434           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9435             : 
    9436           0 :                     n->renameType = OBJECT_ROLE;
    9437           0 :                     n->subname = $3;
    9438           0 :                     n->newname = $6;
    9439           0 :                     n->missing_ok = false;
    9440           0 :                     $$ = (Node *) n;
    9441             :                 }
    9442             :             | ALTER opt_procedural LANGUAGE name RENAME TO name
    9443             :                 {
    9444          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9445             : 
    9446          18 :                     n->renameType = OBJECT_LANGUAGE;
    9447          18 :                     n->object = (Node *) makeString($4);
    9448          18 :                     n->newname = $7;
    9449          18 :                     n->missing_ok = false;
    9450          18 :                     $$ = (Node *) n;
    9451             :                 }
    9452             :             | ALTER OPERATOR CLASS any_name USING name RENAME TO name
    9453             :                 {
    9454          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9455             : 
    9456          24 :                     n->renameType = OBJECT_OPCLASS;
    9457          24 :                     n->object = (Node *) lcons(makeString($6), $4);
    9458          24 :                     n->newname = $9;
    9459          24 :                     n->missing_ok = false;
    9460          24 :                     $$ = (Node *) n;
    9461             :                 }
    9462             :             | ALTER OPERATOR FAMILY any_name USING name RENAME TO name
    9463             :                 {
    9464          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9465             : 
    9466          24 :                     n->renameType = OBJECT_OPFAMILY;
    9467          24 :                     n->object = (Node *) lcons(makeString($6), $4);
    9468          24 :                     n->newname = $9;
    9469          24 :                     n->missing_ok = false;
    9470          24 :                     $$ = (Node *) n;
    9471             :                 }
    9472             :             | ALTER POLICY name ON qualified_name RENAME TO name
    9473             :                 {
    9474          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9475             : 
    9476          18 :                     n->renameType = OBJECT_POLICY;
    9477          18 :                     n->relation = $5;
    9478          18 :                     n->subname = $3;
    9479          18 :                     n->newname = $8;
    9480          18 :                     n->missing_ok = false;
    9481          18 :                     $$ = (Node *) n;
    9482             :                 }
    9483             :             | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
    9484             :                 {
    9485           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9486             : 
    9487           0 :                     n->renameType = OBJECT_POLICY;
    9488           0 :                     n->relation = $7;
    9489           0 :                     n->subname = $5;
    9490           0 :                     n->newname = $10;
    9491           0 :                     n->missing_ok = true;
    9492           0 :                     $$ = (Node *) n;
    9493             :                 }
    9494             :             | ALTER PROCEDURE function_with_argtypes RENAME TO name
    9495             :                 {
    9496           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9497             : 
    9498           0 :                     n->renameType = OBJECT_PROCEDURE;
    9499           0 :                     n->object = (Node *) $3;
    9500           0 :                     n->newname = $6;
    9501           0 :                     n->missing_ok = false;
    9502           0 :                     $$ = (Node *) n;
    9503             :                 }
    9504             :             | ALTER PUBLICATION name RENAME TO name
    9505             :                 {
    9506          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9507             : 
    9508          18 :                     n->renameType = OBJECT_PUBLICATION;
    9509          18 :                     n->object = (Node *) makeString($3);
    9510          18 :                     n->newname = $6;
    9511          18 :                     n->missing_ok = false;
    9512          18 :                     $$ = (Node *) n;
    9513             :                 }
    9514             :             | ALTER ROUTINE function_with_argtypes RENAME TO name
    9515             :                 {
    9516          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9517             : 
    9518          24 :                     n->renameType = OBJECT_ROUTINE;
    9519          24 :                     n->object = (Node *) $3;
    9520          24 :                     n->newname = $6;
    9521          24 :                     n->missing_ok = false;
    9522          24 :                     $$ = (Node *) n;
    9523             :                 }
    9524             :             | ALTER SCHEMA name RENAME TO name
    9525             :                 {
    9526          20 :                     RenameStmt *n = makeNode(RenameStmt);
    9527             : 
    9528          20 :                     n->renameType = OBJECT_SCHEMA;
    9529          20 :                     n->subname = $3;
    9530          20 :                     n->newname = $6;
    9531          20 :                     n->missing_ok = false;
    9532          20 :                     $$ = (Node *) n;
    9533             :                 }
    9534             :             | ALTER SERVER name RENAME TO name
    9535             :                 {
    9536          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9537             : 
    9538          24 :                     n->renameType = OBJECT_FOREIGN_SERVER;
    9539          24 :                     n->object = (Node *) makeString($3);
    9540          24 :                     n->newname = $6;
    9541          24 :                     n->missing_ok = false;
    9542          24 :                     $$ = (Node *) n;
    9543             :                 }
    9544             :             | ALTER SUBSCRIPTION name RENAME TO name
    9545             :                 {
    9546          38 :                     RenameStmt *n = makeNode(RenameStmt);
    9547             : 
    9548          38 :                     n->renameType = OBJECT_SUBSCRIPTION;
    9549          38 :                     n->object = (Node *) makeString($3);
    9550          38 :                     n->newname = $6;
    9551          38 :                     n->missing_ok = false;
    9552          38 :                     $$ = (Node *) n;
    9553             :                 }
    9554             :             | ALTER TABLE relation_expr RENAME TO name
    9555             :                 {
    9556         286 :                     RenameStmt *n = makeNode(RenameStmt);
    9557             : 
    9558         286 :                     n->renameType = OBJECT_TABLE;
    9559         286 :                     n->relation = $3;
    9560         286 :                     n->subname = NULL;
    9561         286 :                     n->newname = $6;
    9562         286 :                     n->missing_ok = false;
    9563         286 :                     $$ = (Node *) n;
    9564             :                 }
    9565             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
    9566             :                 {
    9567           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9568             : 
    9569           0 :                     n->renameType = OBJECT_TABLE;
    9570           0 :                     n->relation = $5;
    9571           0 :                     n->subname = NULL;
    9572           0 :                     n->newname = $8;
    9573           0 :                     n->missing_ok = true;
    9574           0 :                     $$ = (Node *) n;
    9575             :                 }
    9576             :             | ALTER SEQUENCE qualified_name RENAME TO name
    9577             :                 {
    9578           2 :                     RenameStmt *n = makeNode(RenameStmt);
    9579             : 
    9580           2 :                     n->renameType = OBJECT_SEQUENCE;
    9581           2 :                     n->relation = $3;
    9582           2 :                     n->subname = NULL;
    9583           2 :                     n->newname = $6;
    9584           2 :                     n->missing_ok = false;
    9585           2 :                     $$ = (Node *) n;
    9586             :                 }
    9587             :             | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
    9588             :                 {
    9589           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9590             : 
    9591           0 :                     n->renameType = OBJECT_SEQUENCE;
    9592           0 :                     n->relation = $5;
    9593           0 :                     n->subname = NULL;
    9594           0 :                     n->newname = $8;
    9595           0 :                     n->missing_ok = true;
    9596           0 :                     $$ = (Node *) n;
    9597             :                 }
    9598             :             | ALTER VIEW qualified_name RENAME TO name
    9599             :                 {
    9600           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9601             : 
    9602           6 :                     n->renameType = OBJECT_VIEW;
    9603           6 :                     n->relation = $3;
    9604           6 :                     n->subname = NULL;
    9605           6 :                     n->newname = $6;
    9606           6 :                     n->missing_ok = false;
    9607           6 :                     $$ = (Node *) n;
    9608             :                 }
    9609             :             | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
    9610             :                 {
    9611           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9612             : 
    9613           0 :                     n->renameType = OBJECT_VIEW;
    9614           0 :                     n->relation = $5;
    9615           0 :                     n->subname = NULL;
    9616           0 :                     n->newname = $8;
    9617           0 :                     n->missing_ok = true;
    9618           0 :                     $$ = (Node *) n;
    9619             :                 }
    9620             :             | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
    9621             :                 {
    9622           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9623             : 
    9624           0 :                     n->renameType = OBJECT_MATVIEW;
    9625           0 :                     n->relation = $4;
    9626           0 :                     n->subname = NULL;
    9627           0 :                     n->newname = $7;
    9628           0 :                     n->missing_ok = false;
    9629           0 :                     $$ = (Node *) n;
    9630             :                 }
    9631             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
    9632             :                 {
    9633           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9634             : 
    9635           0 :                     n->renameType = OBJECT_MATVIEW;
    9636           0 :                     n->relation = $6;
    9637           0 :                     n->subname = NULL;
    9638           0 :                     n->newname = $9;
    9639           0 :                     n->missing_ok = true;
    9640           0 :                     $$ = (Node *) n;
    9641             :                 }
    9642             :             | ALTER INDEX qualified_name RENAME TO name
    9643             :                 {
    9644         192 :                     RenameStmt *n = makeNode(RenameStmt);
    9645             : 
    9646         192 :                     n->renameType = OBJECT_INDEX;
    9647         192 :                     n->relation = $3;
    9648         192 :                     n->subname = NULL;
    9649         192 :                     n->newname = $6;
    9650         192 :                     n->missing_ok = false;
    9651         192 :                     $$ = (Node *) n;
    9652             :                 }
    9653             :             | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
    9654             :                 {
    9655          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9656             : 
    9657          12 :                     n->renameType = OBJECT_INDEX;
    9658          12 :                     n->relation = $5;
    9659          12 :                     n->subname = NULL;
    9660          12 :                     n->newname = $8;
    9661          12 :                     n->missing_ok = true;
    9662          12 :                     $$ = (Node *) n;
    9663             :                 }
    9664             :             | ALTER FOREIGN TABLE relation_expr RENAME TO name
    9665             :                 {
    9666           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9667             : 
    9668           6 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9669           6 :                     n->relation = $4;
    9670           6 :                     n->subname = NULL;
    9671           6 :                     n->newname = $7;
    9672           6 :                     n->missing_ok = false;
    9673           6 :                     $$ = (Node *) n;
    9674             :                 }
    9675             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
    9676             :                 {
    9677           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9678             : 
    9679           6 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9680           6 :                     n->relation = $6;
    9681           6 :                     n->subname = NULL;
    9682           6 :                     n->newname = $9;
    9683           6 :                     n->missing_ok = true;
    9684           6 :                     $$ = (Node *) n;
    9685             :                 }
    9686             :             | ALTER TABLE relation_expr RENAME opt_column name TO name
    9687             :                 {
    9688         238 :                     RenameStmt *n = makeNode(RenameStmt);
    9689             : 
    9690         238 :                     n->renameType = OBJECT_COLUMN;
    9691         238 :                     n->relationType = OBJECT_TABLE;
    9692         238 :                     n->relation = $3;
    9693         238 :                     n->subname = $6;
    9694         238 :                     n->newname = $8;
    9695         238 :                     n->missing_ok = false;
    9696         238 :                     $$ = (Node *) n;
    9697             :                 }
    9698             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9699             :                 {
    9700          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9701             : 
    9702          24 :                     n->renameType = OBJECT_COLUMN;
    9703          24 :                     n->relationType = OBJECT_TABLE;
    9704          24 :                     n->relation = $5;
    9705          24 :                     n->subname = $8;
    9706          24 :                     n->newname = $10;
    9707          24 :                     n->missing_ok = true;
    9708          24 :                     $$ = (Node *) n;
    9709             :                 }
    9710             :             | ALTER VIEW qualified_name RENAME opt_column name TO name
    9711             :                 {
    9712          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9713             : 
    9714          18 :                     n->renameType = OBJECT_COLUMN;
    9715          18 :                     n->relationType = OBJECT_VIEW;
    9716          18 :                     n->relation = $3;
    9717          18 :                     n->subname = $6;
    9718          18 :                     n->newname = $8;
    9719          18 :                     n->missing_ok = false;
    9720          18 :                     $$ = (Node *) n;
    9721             :                 }
    9722             :             | ALTER VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    9723             :                 {
    9724           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9725             : 
    9726           0 :                     n->renameType = OBJECT_COLUMN;
    9727           0 :                     n->relationType = OBJECT_VIEW;
    9728           0 :                     n->relation = $5;
    9729           0 :                     n->subname = $8;
    9730           0 :                     n->newname = $10;
    9731           0 :                     n->missing_ok = true;
    9732           0 :                     $$ = (Node *) n;
    9733             :                 }
    9734             :             | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
    9735             :                 {
    9736           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9737             : 
    9738           0 :                     n->renameType = OBJECT_COLUMN;
    9739           0 :                     n->relationType = OBJECT_MATVIEW;
    9740           0 :                     n->relation = $4;
    9741           0 :                     n->subname = $7;
    9742           0 :                     n->newname = $9;
    9743           0 :                     n->missing_ok = false;
    9744           0 :                     $$ = (Node *) n;
    9745             :                 }
    9746             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    9747             :                 {
    9748           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9749             : 
    9750           0 :                     n->renameType = OBJECT_COLUMN;
    9751           0 :                     n->relationType = OBJECT_MATVIEW;
    9752           0 :                     n->relation = $6;
    9753           0 :                     n->subname = $9;
    9754           0 :                     n->newname = $11;
    9755           0 :                     n->missing_ok = true;
    9756           0 :                     $$ = (Node *) n;
    9757             :                 }
    9758             :             | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
    9759             :                 {
    9760          72 :                     RenameStmt *n = makeNode(RenameStmt);
    9761             : 
    9762          72 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9763          72 :                     n->relation = $3;
    9764          72 :                     n->subname = $6;
    9765          72 :                     n->newname = $8;
    9766          72 :                     n->missing_ok = false;
    9767          72 :                     $$ = (Node *) n;
    9768             :                 }
    9769             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
    9770             :                 {
    9771           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9772             : 
    9773           6 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9774           6 :                     n->relation = $5;
    9775           6 :                     n->subname = $8;
    9776           6 :                     n->newname = $10;
    9777           6 :                     n->missing_ok = true;
    9778           6 :                     $$ = (Node *) n;
    9779             :                 }
    9780             :             | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
    9781             :                 {
    9782           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9783             : 
    9784           6 :                     n->renameType = OBJECT_COLUMN;
    9785           6 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    9786           6 :                     n->relation = $4;
    9787           6 :                     n->subname = $7;
    9788           6 :                     n->newname = $9;
    9789           6 :                     n->missing_ok = false;
    9790           6 :                     $$ = (Node *) n;
    9791             :                 }
    9792             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9793             :                 {
    9794           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9795             : 
    9796           6 :                     n->renameType = OBJECT_COLUMN;
    9797           6 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    9798           6 :                     n->relation = $6;
    9799           6 :                     n->subname = $9;
    9800           6 :                     n->newname = $11;
    9801           6 :                     n->missing_ok = true;
    9802           6 :                     $$ = (Node *) n;
    9803             :                 }
    9804             :             | ALTER RULE name ON qualified_name RENAME TO name
    9805             :                 {
    9806          34 :                     RenameStmt *n = makeNode(RenameStmt);
    9807             : 
    9808          34 :                     n->renameType = OBJECT_RULE;
    9809          34 :                     n->relation = $5;
    9810          34 :                     n->subname = $3;
    9811          34 :                     n->newname = $8;
    9812          34 :                     n->missing_ok = false;
    9813          34 :                     $$ = (Node *) n;
    9814             :                 }
    9815             :             | ALTER TRIGGER name ON qualified_name RENAME TO name
    9816             :                 {
    9817          40 :                     RenameStmt *n = makeNode(RenameStmt);
    9818             : 
    9819          40 :                     n->renameType = OBJECT_TRIGGER;
    9820          40 :                     n->relation = $5;
    9821          40 :                     n->subname = $3;
    9822          40 :                     n->newname = $8;
    9823          40 :                     n->missing_ok = false;
    9824          40 :                     $$ = (Node *) n;
    9825             :                 }
    9826             :             | ALTER EVENT TRIGGER name RENAME TO name
    9827             :                 {
    9828          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9829             : 
    9830          12 :                     n->renameType = OBJECT_EVENT_TRIGGER;
    9831          12 :                     n->object = (Node *) makeString($4);
    9832          12 :                     n->newname = $7;
    9833          12 :                     $$ = (Node *) n;
    9834             :                 }
    9835             :             | ALTER ROLE RoleId RENAME TO RoleId
    9836             :                 {
    9837          30 :                     RenameStmt *n = makeNode(RenameStmt);
    9838             : 
    9839          30 :                     n->renameType = OBJECT_ROLE;
    9840          30 :                     n->subname = $3;
    9841          30 :                     n->newname = $6;
    9842          30 :                     n->missing_ok = false;
    9843          30 :                     $$ = (Node *) n;
    9844             :                 }
    9845             :             | ALTER USER RoleId RENAME TO RoleId
    9846             :                 {
    9847           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9848             : 
    9849           0 :                     n->renameType = OBJECT_ROLE;
    9850           0 :                     n->subname = $3;
    9851           0 :                     n->newname = $6;
    9852           0 :                     n->missing_ok = false;
    9853           0 :                     $$ = (Node *) n;
    9854             :                 }
    9855             :             | ALTER TABLESPACE name RENAME TO name
    9856             :                 {
    9857           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9858             : 
    9859           6 :                     n->renameType = OBJECT_TABLESPACE;
    9860           6 :                     n->subname = $3;
    9861           6 :                     n->newname = $6;
    9862           6 :                     n->missing_ok = false;
    9863           6 :                     $$ = (Node *) n;
    9864             :                 }
    9865             :             | ALTER STATISTICS any_name RENAME TO name
    9866             :                 {
    9867          30 :                     RenameStmt *n = makeNode(RenameStmt);
    9868             : 
    9869          30 :                     n->renameType = OBJECT_STATISTIC_EXT;
    9870          30 :                     n->object = (Node *) $3;
    9871          30 :                     n->newname = $6;
    9872          30 :                     n->missing_ok = false;
    9873          30 :                     $$ = (Node *) n;
    9874             :                 }
    9875             :             | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
    9876             :                 {
    9877          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9878             : 
    9879          12 :                     n->renameType = OBJECT_TSPARSER;
    9880          12 :                     n->object = (Node *) $5;
    9881          12 :                     n->newname = $8;
    9882          12 :                     n->missing_ok = false;
    9883          12 :                     $$ = (Node *) n;
    9884             :                 }
    9885             :             | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
    9886             :                 {
    9887          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9888             : 
    9889          24 :                     n->renameType = OBJECT_TSDICTIONARY;
    9890          24 :                     n->object = (Node *) $5;
    9891          24 :                     n->newname = $8;
    9892          24 :                     n->missing_ok = false;
    9893          24 :                     $$ = (Node *) n;
    9894             :                 }
    9895             :             | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
    9896             :                 {
    9897          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9898             : 
    9899          12 :                     n->renameType = OBJECT_TSTEMPLATE;
    9900          12 :                     n->object = (Node *) $5;
    9901          12 :                     n->newname = $8;
    9902          12 :                     n->missing_ok = false;
    9903          12 :                     $$ = (Node *) n;
    9904             :                 }
    9905             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
    9906             :                 {
    9907          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9908             : 
    9909          24 :                     n->renameType = OBJECT_TSCONFIGURATION;
    9910          24 :                     n->object = (Node *) $5;
    9911          24 :                     n->newname = $8;
    9912          24 :                     n->missing_ok = false;
    9913          24 :                     $$ = (Node *) n;
    9914             :                 }
    9915             :             | ALTER TYPE_P any_name RENAME TO name
    9916             :                 {
    9917          26 :                     RenameStmt *n = makeNode(RenameStmt);
    9918             : 
    9919          26 :                     n->renameType = OBJECT_TYPE;
    9920          26 :                     n->object = (Node *) $3;
    9921          26 :                     n->newname = $6;
    9922          26 :                     n->missing_ok = false;
    9923          26 :                     $$ = (Node *) n;
    9924             :                 }
    9925             :             | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
    9926             :                 {
    9927          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9928             : 
    9929          24 :                     n->renameType = OBJECT_ATTRIBUTE;
    9930          24 :                     n->relationType = OBJECT_TYPE;
    9931          24 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
    9932          24 :                     n->subname = $6;
    9933          24 :                     n->newname = $8;
    9934          24 :                     n->behavior = $9;
    9935          24 :                     n->missing_ok = false;
    9936          24 :                     $$ = (Node *) n;
    9937             :                 }
    9938             :         ;
    9939             : 
    9940             : opt_column: COLUMN
    9941             :             | /*EMPTY*/
    9942             :         ;
    9943             : 
    9944         172 : opt_set_data: SET DATA_P                            { $$ = 1; }
    9945         776 :             | /*EMPTY*/                             { $$ = 0; }
    9946             :         ;
    9947             : 
    9948             : /*****************************************************************************
    9949             :  *
    9950             :  * ALTER THING name DEPENDS ON EXTENSION name
    9951             :  *
    9952             :  *****************************************************************************/
    9953             : 
    9954             : AlterObjectDependsStmt:
    9955             :             ALTER FUNCTION function_with_argtypes opt_no DEPENDS ON EXTENSION name
    9956             :                 {
    9957          12 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9958             : 
    9959          12 :                     n->objectType = OBJECT_FUNCTION;
    9960          12 :                     n->object = (Node *) $3;
    9961          12 :                     n->extname = makeString($8);
    9962          12 :                     n->remove = $4;
    9963          12 :                     $$ = (Node *) n;
    9964             :                 }
    9965             :             | ALTER PROCEDURE function_with_argtypes opt_no DEPENDS ON EXTENSION name
    9966             :                 {
    9967           0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9968             : 
    9969           0 :                     n->objectType = OBJECT_PROCEDURE;
    9970           0 :                     n->object = (Node *) $3;
    9971           0 :                     n->extname = makeString($8);
    9972           0 :                     n->remove = $4;
    9973           0 :                     $$ = (Node *) n;
    9974             :                 }
    9975             :             | ALTER ROUTINE function_with_argtypes opt_no DEPENDS ON EXTENSION name
    9976             :                 {
    9977           0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9978             : 
    9979           0 :                     n->objectType = OBJECT_ROUTINE;
    9980           0 :                     n->object = (Node *) $3;
    9981           0 :                     n->extname = makeString($8);
    9982           0 :                     n->remove = $4;
    9983           0 :                     $$ = (Node *) n;
    9984             :                 }
    9985             :             | ALTER TRIGGER name ON qualified_name opt_no DEPENDS ON EXTENSION name
    9986             :                 {
    9987          10 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9988             : 
    9989          10 :                     n->objectType = OBJECT_TRIGGER;
    9990          10 :                     n->relation = $5;
    9991          10 :                     n->object = (Node *) list_make1(makeString($3));
    9992          10 :                     n->extname = makeString($10);
    9993          10 :                     n->remove = $6;
    9994          10 :                     $$ = (Node *) n;
    9995             :                 }
    9996             :             | ALTER MATERIALIZED VIEW qualified_name opt_no DEPENDS ON EXTENSION name
    9997             :                 {
    9998          10 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9999             : 
   10000          10 :                     n->objectType = OBJECT_MATVIEW;
   10001          10 :                     n->relation = $4;
   10002          10 :                     n->extname = makeString($9);
   10003          10 :                     n->remove = $5;
   10004          10 :                     $$ = (Node *) n;
   10005             :                 }
   10006             :             | ALTER INDEX qualified_name opt_no DEPENDS ON EXTENSION name
   10007             :                 {
   10008          14 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10009             : 
   10010          14 :                     n->objectType = OBJECT_INDEX;
   10011          14 :                     n->relation = $3;
   10012          14 :                     n->extname = makeString($8);
   10013          14 :                     n->remove = $4;
   10014          14 :                     $$ = (Node *) n;
   10015             :                 }
   10016             :         ;
   10017             : 
   10018           8 : opt_no:     NO              { $$ = true; }
   10019          38 :             | /* EMPTY */   { $$ = false;   }
   10020             :         ;
   10021             : 
   10022             : /*****************************************************************************
   10023             :  *
   10024             :  * ALTER THING name SET SCHEMA name
   10025             :  *
   10026             :  *****************************************************************************/
   10027             : 
   10028             : AlterObjectSchemaStmt:
   10029             :             ALTER AGGREGATE aggregate_with_argtypes SET SCHEMA name
   10030             :                 {
   10031          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10032             : 
   10033          24 :                     n->objectType = OBJECT_AGGREGATE;
   10034          24 :                     n->object = (Node *) $3;
   10035          24 :                     n->newschema = $6;
   10036          24 :                     n->missing_ok = false;
   10037          24 :                     $$ = (Node *) n;
   10038             :                 }
   10039             :             | ALTER COLLATION any_name SET SCHEMA name
   10040             :                 {
   10041           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10042             : 
   10043           6 :                     n->objectType = OBJECT_COLLATION;
   10044           6 :                     n->object = (Node *) $3;
   10045           6 :                     n->newschema = $6;
   10046           6 :                     n->missing_ok = false;
   10047           6 :                     $$ = (Node *) n;
   10048             :                 }
   10049             :             | ALTER CONVERSION_P any_name SET SCHEMA name
   10050             :                 {
   10051          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10052             : 
   10053          24 :                     n->objectType = OBJECT_CONVERSION;
   10054          24 :                     n->object = (Node *) $3;
   10055          24 :                     n->newschema = $6;
   10056          24 :                     n->missing_ok = false;
   10057          24 :                     $$ = (Node *) n;
   10058             :                 }
   10059             :             | ALTER DOMAIN_P any_name SET SCHEMA name
   10060             :                 {
   10061           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10062             : 
   10063           6 :                     n->objectType = OBJECT_DOMAIN;
   10064           6 :                     n->object = (Node *) $3;
   10065           6 :                     n->newschema = $6;
   10066           6 :                     n->missing_ok = false;
   10067           6 :                     $$ = (Node *) n;
   10068             :                 }
   10069             :             | ALTER EXTENSION name SET SCHEMA name
   10070             :                 {
   10071          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10072             : 
   10073          12 :                     n->objectType = OBJECT_EXTENSION;
   10074          12 :                     n->object = (Node *) makeString($3);
   10075          12 :                     n->newschema = $6;
   10076          12 :                     n->missing_ok = false;
   10077          12 :                     $$ = (Node *) n;
   10078             :                 }
   10079             :             | ALTER FUNCTION function_with_argtypes SET SCHEMA name
   10080             :                 {
   10081          42 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10082             : 
   10083          42 :                     n->objectType = OBJECT_FUNCTION;
   10084          42 :                     n->object = (Node *) $3;
   10085          42 :                     n->newschema = $6;
   10086          42 :                     n->missing_ok = false;
   10087          42 :                     $$ = (Node *) n;
   10088             :                 }
   10089             :             | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
   10090             :                 {
   10091          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10092             : 
   10093          18 :                     n->objectType = OBJECT_OPERATOR;
   10094          18 :                     n->object = (Node *) $3;
   10095          18 :                     n->newschema = $6;
   10096          18 :                     n->missing_ok = false;
   10097          18 :                     $$ = (Node *) n;
   10098             :                 }
   10099             :             | ALTER OPERATOR CLASS any_name USING name SET SCHEMA name
   10100             :                 {
   10101          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10102             : 
   10103          24 :                     n->objectType = OBJECT_OPCLASS;
   10104          24 :                     n->object = (Node *) lcons(makeString($6), $4);
   10105          24 :                     n->newschema = $9;
   10106          24 :                     n->missing_ok = false;
   10107          24 :                     $$ = (Node *) n;
   10108             :                 }
   10109             :             | ALTER OPERATOR FAMILY any_name USING name SET SCHEMA name
   10110             :                 {
   10111          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10112             : 
   10113          24 :                     n->objectType = OBJECT_OPFAMILY;
   10114          24 :                     n->object = (Node *) lcons(makeString($6), $4);
   10115          24 :                     n->newschema = $9;
   10116          24 :                     n->missing_ok = false;
   10117          24 :                     $$ = (Node *) n;
   10118             :                 }
   10119             :             | ALTER PROCEDURE function_with_argtypes SET SCHEMA name
   10120             :                 {
   10121           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10122             : 
   10123           0 :                     n->objectType = OBJECT_PROCEDURE;
   10124           0 :                     n->object = (Node *) $3;
   10125           0 :                     n->newschema = $6;
   10126           0 :                     n->missing_ok = false;
   10127           0 :                     $$ = (Node *) n;
   10128             :                 }
   10129             :             | ALTER ROUTINE function_with_argtypes SET SCHEMA name
   10130             :                 {
   10131           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10132             : 
   10133           0 :                     n->objectType = OBJECT_ROUTINE;
   10134           0 :                     n->object = (Node *) $3;
   10135           0 :                     n->newschema = $6;
   10136           0 :                     n->missing_ok = false;
   10137           0 :                     $$ = (Node *) n;
   10138             :                 }
   10139             :             | ALTER TABLE relation_expr SET SCHEMA name
   10140             :                 {
   10141          66 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10142             : 
   10143          66 :                     n->objectType = OBJECT_TABLE;
   10144          66 :                     n->relation = $3;
   10145          66 :                     n->newschema = $6;
   10146          66 :                     n->missing_ok = false;
   10147          66 :                     $$ = (Node *) n;
   10148             :                 }
   10149             :             | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10150             :                 {
   10151          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10152             : 
   10153          12 :                     n->objectType = OBJECT_TABLE;
   10154          12 :                     n->relation = $5;
   10155          12 :                     n->newschema = $8;
   10156          12 :                     n->missing_ok = true;
   10157          12 :                     $$ = (Node *) n;
   10158             :                 }
   10159             :             | ALTER STATISTICS any_name SET SCHEMA name
   10160             :                 {
   10161          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10162             : 
   10163          18 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10164          18 :                     n->object = (Node *) $3;
   10165          18 :                     n->newschema = $6;
   10166          18 :                     n->missing_ok = false;
   10167          18 :                     $$ = (Node *) n;
   10168             :                 }
   10169             :             | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
   10170             :                 {
   10171          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10172             : 
   10173          18 :                     n->objectType = OBJECT_TSPARSER;
   10174          18 :                     n->object = (Node *) $5;
   10175          18 :                     n->newschema = $8;
   10176          18 :                     n->missing_ok = false;
   10177          18 :                     $$ = (Node *) n;
   10178             :                 }
   10179             :             | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
   10180             :                 {
   10181          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10182             : 
   10183          24 :                     n->objectType = OBJECT_TSDICTIONARY;
   10184          24 :                     n->object = (Node *) $5;
   10185          24 :                     n->newschema = $8;
   10186          24 :                     n->missing_ok = false;
   10187          24 :                     $$ = (Node *) n;
   10188             :                 }
   10189             :             | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
   10190             :                 {
   10191          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10192             : 
   10193          18 :                     n->objectType = OBJECT_TSTEMPLATE;
   10194          18 :                     n->object = (Node *) $5;
   10195          18 :                     n->newschema = $8;
   10196          18 :                     n->missing_ok = false;
   10197          18 :                     $$ = (Node *) n;
   10198             :                 }
   10199             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
   10200             :                 {
   10201          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10202             : 
   10203          24 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10204          24 :                     n->object = (Node *) $5;
   10205          24 :                     n->newschema = $8;
   10206          24 :                     n->missing_ok = false;
   10207          24 :                     $$ = (Node *) n;
   10208             :                 }
   10209             :             | ALTER SEQUENCE qualified_name SET SCHEMA name
   10210             :                 {
   10211           8 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10212             : 
   10213           8 :                     n->objectType = OBJECT_SEQUENCE;
   10214           8 :                     n->relation = $3;
   10215           8 :                     n->newschema = $6;
   10216           8 :                     n->missing_ok = false;
   10217           8 :                     $$ = (Node *) n;
   10218             :                 }
   10219             :             | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
   10220             :                 {
   10221           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10222             : 
   10223           0 :                     n->objectType = OBJECT_SEQUENCE;
   10224           0 :                     n->relation = $5;
   10225           0 :                     n->newschema = $8;
   10226           0 :                     n->missing_ok = true;
   10227           0 :                     $$ = (Node *) n;
   10228             :                 }
   10229             :             | ALTER VIEW qualified_name SET SCHEMA name
   10230             :                 {
   10231           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10232             : 
   10233           0 :                     n->objectType = OBJECT_VIEW;
   10234           0 :                     n->relation = $3;
   10235           0 :                     n->newschema = $6;
   10236           0 :                     n->missing_ok = false;
   10237           0 :                     $$ = (Node *) n;
   10238             :                 }
   10239             :             | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
   10240             :                 {
   10241           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10242             : 
   10243           0 :                     n->objectType = OBJECT_VIEW;
   10244           0 :                     n->relation = $5;
   10245           0 :                     n->newschema = $8;
   10246           0 :                     n->missing_ok = true;
   10247           0 :                     $$ = (Node *) n;
   10248             :                 }
   10249             :             | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
   10250             :                 {
   10251           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10252             : 
   10253           6 :                     n->objectType = OBJECT_MATVIEW;
   10254           6 :                     n->relation = $4;
   10255           6 :                     n->newschema = $7;
   10256           6 :                     n->missing_ok = false;
   10257           6 :                     $$ = (Node *) n;
   10258             :                 }
   10259             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
   10260             :                 {
   10261           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10262             : 
   10263           0 :                     n->objectType = OBJECT_MATVIEW;
   10264           0 :                     n->relation = $6;
   10265           0 :                     n->newschema = $9;
   10266           0 :                     n->missing_ok = true;
   10267           0 :                     $$ = (Node *) n;
   10268             :                 }
   10269             :             | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
   10270             :                 {
   10271           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10272             : 
   10273           6 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10274           6 :                     n->relation = $4;
   10275           6 :                     n->newschema = $7;
   10276           6 :                     n->missing_ok = false;
   10277           6 :                     $$ = (Node *) n;
   10278             :                 }
   10279             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10280             :                 {
   10281           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10282             : 
   10283           6 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10284           6 :                     n->relation = $6;
   10285           6 :                     n->newschema = $9;
   10286           6 :                     n->missing_ok = true;
   10287           6 :                     $$ = (Node *) n;
   10288             :                 }
   10289             :             | ALTER TYPE_P any_name SET SCHEMA name
   10290             :                 {
   10291          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10292             : 
   10293          12 :                     n->objectType = OBJECT_TYPE;
   10294          12 :                     n->object = (Node *) $3;
   10295          12 :                     n->newschema = $6;
   10296          12 :                     n->missing_ok = false;
   10297          12 :                     $$ = (Node *) n;
   10298             :                 }
   10299             :         ;
   10300             : 
   10301             : /*****************************************************************************
   10302             :  *
   10303             :  * ALTER OPERATOR name SET define
   10304             :  *
   10305             :  *****************************************************************************/
   10306             : 
   10307             : AlterOperatorStmt:
   10308             :             ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
   10309             :                 {
   10310         608 :                     AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
   10311             : 
   10312         608 :                     n->opername = $3;
   10313         608 :                     n->options = $6;
   10314         608 :                     $$ = (Node *) n;
   10315             :                 }
   10316             :         ;
   10317             : 
   10318         668 : operator_def_list:  operator_def_elem                               { $$ = list_make1($1); }
   10319         506 :             | operator_def_list ',' operator_def_elem               { $$ = lappend($1, $3); }
   10320             :         ;
   10321             : 
   10322             : operator_def_elem: ColLabel '=' NONE
   10323          30 :                         { $$ = makeDefElem($1, NULL, @1); }
   10324             :                    | ColLabel '=' operator_def_arg
   10325        1110 :                         { $$ = makeDefElem($1, (Node *) $3, @1); }
   10326             :                    | ColLabel
   10327          34 :                         { $$ = makeDefElem($1, NULL, @1); }
   10328             :         ;
   10329             : 
   10330             : /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
   10331             : operator_def_arg:
   10332        1032 :             func_type                       { $$ = (Node *) $1; }
   10333          24 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
   10334          54 :             | qual_all_Op                   { $$ = (Node *) $1; }
   10335           0 :             | NumericOnly                   { $$ = (Node *) $1; }
   10336           0 :             | Sconst                        { $$ = (Node *) makeString($1); }
   10337             :         ;
   10338             : 
   10339             : /*****************************************************************************
   10340             :  *
   10341             :  * ALTER TYPE name SET define
   10342             :  *
   10343             :  * We repurpose ALTER OPERATOR's version of "definition" here
   10344             :  *
   10345             :  *****************************************************************************/
   10346             : 
   10347             : AlterTypeStmt:
   10348             :             ALTER TYPE_P any_name SET '(' operator_def_list ')'
   10349             :                 {
   10350          60 :                     AlterTypeStmt *n = makeNode(AlterTypeStmt);
   10351             : 
   10352          60 :                     n->typeName = $3;
   10353          60 :                     n->options = $6;
   10354          60 :                     $$ = (Node *) n;
   10355             :                 }
   10356             :         ;
   10357             : 
   10358             : /*****************************************************************************
   10359             :  *
   10360             :  * ALTER THING name OWNER TO newname
   10361             :  *
   10362             :  *****************************************************************************/
   10363             : 
   10364             : AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec
   10365             :                 {
   10366         142 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10367             : 
   10368         142 :                     n->objectType = OBJECT_AGGREGATE;
   10369         142 :                     n->object = (Node *) $3;
   10370         142 :                     n->newowner = $6;
   10371         142 :                     $$ = (Node *) n;
   10372             :                 }
   10373             :             | ALTER COLLATION any_name OWNER TO RoleSpec
   10374             :                 {
   10375          18 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10376             : 
   10377          18 :                     n->objectType = OBJECT_COLLATION;
   10378          18 :                     n->object = (Node *) $3;
   10379          18 :                     n->newowner = $6;
   10380          18 :                     $$ = (Node *) n;
   10381             :                 }
   10382             :             | ALTER CONVERSION_P any_name OWNER TO RoleSpec
   10383             :                 {
   10384          24 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10385             : 
   10386          24 :                     n->objectType = OBJECT_CONVERSION;
   10387          24 :                     n->object = (Node *) $3;
   10388          24 :                     n->newowner = $6;
   10389          24 :                     $$ = (Node *) n;
   10390             :                 }
   10391             :             | ALTER DATABASE name OWNER TO RoleSpec
   10392             :                 {
   10393          50 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10394             : 
   10395          50 :                     n->objectType = OBJECT_DATABASE;
   10396          50 :                     n->object = (Node *) makeString($3);
   10397          50 :                     n->newowner = $6;
   10398          50 :                     $$ = (Node *) n;
   10399             :                 }
   10400             :             | ALTER DOMAIN_P any_name OWNER TO RoleSpec
   10401             :                 {
   10402          40 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10403             : 
   10404          40 :                     n->objectType = OBJECT_DOMAIN;
   10405          40 :                     n->object = (Node *) $3;
   10406          40 :                     n->newowner = $6;
   10407          40 :                     $$ = (Node *) n;
   10408             :                 }
   10409             :             | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
   10410             :                 {
   10411         576 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10412             : 
   10413         576 :                     n->objectType = OBJECT_FUNCTION;
   10414         576 :                     n->object = (Node *) $3;
   10415         576 :                     n->newowner = $6;
   10416         576 :                     $$ = (Node *) n;
   10417             :                 }
   10418             :             | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
   10419             :                 {
   10420         132 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10421             : 
   10422         132 :                     n->objectType = OBJECT_LANGUAGE;
   10423         132 :                     n->object = (Node *) makeString($4);
   10424         132 :                     n->newowner = $7;
   10425         132 :                     $$ = (Node *) n;
   10426             :                 }
   10427             :             | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
   10428             :                 {
   10429          12 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10430             : 
   10431          12 :                     n->objectType = OBJECT_LARGEOBJECT;
   10432          12 :                     n->object = (Node *) $4;
   10433          12 :                     n->newowner = $7;
   10434          12 :                     $$ = (Node *) n;
   10435             :                 }
   10436             :             | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
   10437             :                 {
   10438          46 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10439             : 
   10440          46 :                     n->objectType = OBJECT_OPERATOR;
   10441          46 :                     n->object = (Node *) $3;
   10442          46 :                     n->newowner = $6;
   10443          46 :                     $$ = (Node *) n;
   10444             :                 }
   10445             :             | ALTER OPERATOR CLASS any_name USING name OWNER TO RoleSpec
   10446             :                 {
   10447          54 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10448             : 
   10449          54 :                     n->objectType = OBJECT_OPCLASS;
   10450          54 :                     n->object = (Node *) lcons(makeString($6), $4);
   10451          54 :                     n->newowner = $9;
   10452          54 :                     $$ = (Node *) n;
   10453             :                 }
   10454             :             | ALTER OPERATOR FAMILY any_name USING name OWNER TO RoleSpec
   10455             :                 {
   10456          62 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10457             : 
   10458          62 :                     n->objectType = OBJECT_OPFAMILY;
   10459          62 :                     n->object = (Node *) lcons(makeString($6), $4);
   10460          62 :                     n->newowner = $9;
   10461          62 :                     $$ = (Node *) n;
   10462             :                 }
   10463             :             | ALTER PROCEDURE function_with_argtypes OWNER TO RoleSpec
   10464             :                 {
   10465          24 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10466             : 
   10467          24 :                     n->objectType = OBJECT_PROCEDURE;
   10468          24 :                     n->object = (Node *) $3;
   10469          24 :                     n->newowner = $6;
   10470          24 :                     $$ = (Node *) n;
   10471             :                 }
   10472             :             | ALTER ROUTINE function_with_argtypes OWNER TO RoleSpec
   10473             :                 {
   10474           0 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10475             : 
   10476           0 :                     n->objectType = OBJECT_ROUTINE;
   10477           0 :                     n->object = (Node *) $3;
   10478           0 :                     n->newowner = $6;
   10479           0 :                     $$ = (Node *) n;
   10480             :                 }
   10481             :             | ALTER SCHEMA name OWNER TO RoleSpec
   10482             :                 {
   10483          54 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10484             : 
   10485          54 :                     n->objectType = OBJECT_SCHEMA;
   10486          54 :                     n->object = (Node *) makeString($3);
   10487          54 :                     n->newowner = $6;
   10488          54 :                     $$ = (Node *) n;
   10489             :                 }
   10490             :             | ALTER TYPE_P any_name OWNER TO RoleSpec
   10491             :                 {
   10492          80 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10493             : 
   10494          80 :                     n->objectType = OBJECT_TYPE;
   10495          80 :                     n->object = (Node *) $3;
   10496          80 :                     n->newowner = $6;
   10497          80 :                     $$ = (Node *) n;
   10498             :                 }
   10499             :             | ALTER TABLESPACE name OWNER TO RoleSpec
   10500             :                 {
   10501           6 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10502             : 
   10503           6 :                     n->objectType = OBJECT_TABLESPACE;
   10504           6 :                     n->object = (Node *) makeString($3);
   10505           6 :                     n->newowner = $6;
   10506           6 :                     $$ = (Node *) n;
   10507             :                 }
   10508             :             | ALTER STATISTICS any_name OWNER TO RoleSpec
   10509             :                 {
   10510          32 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10511             : 
   10512          32 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10513          32 :                     n->object = (Node *) $3;
   10514          32 :                     n->newowner = $6;
   10515          32 :                     $$ = (Node *) n;
   10516             :                 }
   10517             :             | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
   10518             :                 {
   10519          42 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10520             : 
   10521          42 :                     n->objectType = OBJECT_TSDICTIONARY;
   10522          42 :                     n->object = (Node *) $5;
   10523          42 :                     n->newowner = $8;
   10524          42 :                     $$ = (Node *) n;
   10525             :                 }
   10526             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
   10527             :                 {
   10528          32 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10529             : 
   10530          32 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10531          32 :                     n->object = (Node *) $5;
   10532          32 :                     n->newowner = $8;
   10533          32 :                     $$ = (Node *) n;
   10534             :                 }
   10535             :             | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
   10536             :                 {
   10537          20 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10538             : 
   10539          20 :                     n->objectType = OBJECT_FDW;
   10540          20 :                     n->object = (Node *) makeString($5);
   10541          20 :                     n->newowner = $8;
   10542          20 :                     $$ = (Node *) n;
   10543             :                 }
   10544             :             | ALTER SERVER name OWNER TO RoleSpec
   10545             :                 {
   10546          68 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10547             : 
   10548          68 :                     n->objectType = OBJECT_FOREIGN_SERVER;
   10549          68 :                     n->object = (Node *) makeString($3);
   10550          68 :                     n->newowner = $6;
   10551          68 :                     $$ = (Node *) n;
   10552             :                 }
   10553             :             | ALTER EVENT TRIGGER name OWNER TO RoleSpec
   10554             :                 {
   10555          14 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10556             : 
   10557          14 :                     n->objectType = OBJECT_EVENT_TRIGGER;
   10558          14 :                     n->object = (Node *) makeString($4);
   10559          14 :                     n->newowner = $7;
   10560          14 :                     $$ = (Node *) n;
   10561             :                 }
   10562             :             | ALTER PUBLICATION name OWNER TO RoleSpec
   10563             :                 {
   10564          26 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10565             : 
   10566          26 :                     n->objectType = OBJECT_PUBLICATION;
   10567          26 :                     n->object = (Node *) makeString($3);
   10568          26 :                     n->newowner = $6;
   10569          26 :                     $$ = (Node *) n;
   10570             :                 }
   10571             :             | ALTER SUBSCRIPTION name OWNER TO RoleSpec
   10572             :                 {
   10573          18 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10574             : 
   10575          18 :                     n->objectType = OBJECT_SUBSCRIPTION;
   10576          18 :                     n->object = (Node *) makeString($3);
   10577          18 :                     n->newowner = $6;
   10578          18 :                     $$ = (Node *) n;
   10579             :                 }
   10580             :         ;
   10581             : 
   10582             : 
   10583             : /*****************************************************************************
   10584             :  *
   10585             :  * CREATE PUBLICATION name [WITH options]
   10586             :  *
   10587             :  * CREATE PUBLICATION FOR ALL TABLES [WITH options]
   10588             :  *
   10589             :  * CREATE PUBLICATION FOR pub_obj [, ...] [WITH options]
   10590             :  *
   10591             :  * pub_obj is one of:
   10592             :  *
   10593             :  *      TABLE table [, ...]
   10594             :  *      TABLES IN SCHEMA schema [, ...]
   10595             :  *
   10596             :  *****************************************************************************/
   10597             : 
   10598             : CreatePublicationStmt:
   10599             :             CREATE PUBLICATION name opt_definition
   10600             :                 {
   10601         122 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10602             : 
   10603         122 :                     n->pubname = $3;
   10604         122 :                     n->options = $4;
   10605         122 :                     $$ = (Node *) n;
   10606             :                 }
   10607             :             | CREATE PUBLICATION name FOR ALL TABLES opt_definition
   10608             :                 {
   10609          82 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10610             : 
   10611          82 :                     n->pubname = $3;
   10612          82 :                     n->options = $7;
   10613          82 :                     n->for_all_tables = true;
   10614          82 :                     $$ = (Node *) n;
   10615             :                 }
   10616             :             | CREATE PUBLICATION name FOR pub_obj_list opt_definition
   10617             :                 {
   10618         584 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10619             : 
   10620         584 :                     n->pubname = $3;
   10621         584 :                     n->options = $6;
   10622         584 :                     n->pubobjects = (List *) $5;
   10623         584 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10624         554 :                     $$ = (Node *) n;
   10625             :                 }
   10626             :         ;
   10627             : 
   10628             : /*
   10629             :  * FOR TABLE and FOR TABLES IN SCHEMA specifications
   10630             :  *
   10631             :  * This rule parses publication objects with and without keyword prefixes.
   10632             :  *
   10633             :  * The actual type of the object without keyword prefix depends on the previous
   10634             :  * one with keyword prefix. It will be preprocessed in preprocess_pubobj_list().
   10635             :  *
   10636             :  * For the object without keyword prefix, we cannot just use relation_expr here,
   10637             :  * because some extended expressions in relation_expr cannot be used as a
   10638             :  * schemaname and we cannot differentiate it. So, we extract the rules from
   10639             :  * relation_expr here.
   10640             :  */
   10641             : PublicationObjSpec:
   10642             :             TABLE relation_expr opt_column_list OptWhereClause
   10643             :                 {
   10644        1228 :                     $$ = makeNode(PublicationObjSpec);
   10645        1228 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLE;
   10646        1228 :                     $$->pubtable = makeNode(PublicationTable);
   10647        1228 :                     $$->pubtable->relation = $2;
   10648        1228 :                     $$->pubtable->columns = $3;
   10649        1228 :                     $$->pubtable->whereClause = $4;
   10650             :                 }
   10651             :             | TABLES IN_P SCHEMA ColId
   10652             :                 {
   10653         332 :                     $$ = makeNode(PublicationObjSpec);
   10654         332 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   10655         332 :                     $$->name = $4;
   10656         332 :                     $$->location = @4;
   10657             :                 }
   10658             :             | TABLES IN_P SCHEMA CURRENT_SCHEMA
   10659             :                 {
   10660          18 :                     $$ = makeNode(PublicationObjSpec);
   10661          18 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   10662          18 :                     $$->location = @4;
   10663             :                 }
   10664             :             | ColId opt_column_list OptWhereClause
   10665             :                 {
   10666         128 :                     $$ = makeNode(PublicationObjSpec);
   10667         128 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10668             :                     /*
   10669             :                      * If either a row filter or column list is specified, create
   10670             :                      * a PublicationTable object.
   10671             :                      */
   10672         128 :                     if ($2 || $3)
   10673             :                     {
   10674             :                         /*
   10675             :                          * The OptWhereClause must be stored here but it is
   10676             :                          * valid only for tables. For non-table objects, an
   10677             :                          * error will be thrown later via
   10678             :                          * preprocess_pubobj_list().
   10679             :                          */
   10680          42 :                         $$->pubtable = makeNode(PublicationTable);
   10681          42 :                         $$->pubtable->relation = makeRangeVar(NULL, $1, @1);
   10682          42 :                         $$->pubtable->columns = $2;
   10683          42 :                         $$->pubtable->whereClause = $3;
   10684             :                     }
   10685             :                     else
   10686             :                     {
   10687          86 :                         $$->name = $1;
   10688             :                     }
   10689         128 :                     $$->location = @1;
   10690             :                 }
   10691             :             | ColId indirection opt_column_list OptWhereClause
   10692             :                 {
   10693          32 :                     $$ = makeNode(PublicationObjSpec);
   10694          32 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10695          32 :                     $$->pubtable = makeNode(PublicationTable);
   10696          32 :                     $$->pubtable->relation = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   10697          32 :                     $$->pubtable->columns = $3;
   10698          32 :                     $$->pubtable->whereClause = $4;
   10699          32 :                     $$->location = @1;
   10700             :                 }
   10701             :             /* grammar like tablename * , ONLY tablename, ONLY ( tablename ) */
   10702             :             | extended_relation_expr opt_column_list OptWhereClause
   10703             :                 {
   10704           6 :                     $$ = makeNode(PublicationObjSpec);
   10705           6 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10706           6 :                     $$->pubtable = makeNode(PublicationTable);
   10707           6 :                     $$->pubtable->relation = $1;
   10708           6 :                     $$->pubtable->columns = $2;
   10709           6 :                     $$->pubtable->whereClause = $3;
   10710             :                 }
   10711             :             | CURRENT_SCHEMA
   10712             :                 {
   10713          18 :                     $$ = makeNode(PublicationObjSpec);
   10714          18 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10715          18 :                     $$->location = @1;
   10716             :                 }
   10717             :                 ;
   10718             : 
   10719             : pub_obj_list:   PublicationObjSpec
   10720        1540 :                     { $$ = list_make1($1); }
   10721             :             | pub_obj_list ',' PublicationObjSpec
   10722         222 :                     { $$ = lappend($1, $3); }
   10723             :     ;
   10724             : 
   10725             : /*****************************************************************************
   10726             :  *
   10727             :  * ALTER PUBLICATION name SET ( options )
   10728             :  *
   10729             :  * ALTER PUBLICATION name ADD pub_obj [, ...]
   10730             :  *
   10731             :  * ALTER PUBLICATION name DROP pub_obj [, ...]
   10732             :  *
   10733             :  * ALTER PUBLICATION name SET pub_obj [, ...]
   10734             :  *
   10735             :  * pub_obj is one of:
   10736             :  *
   10737             :  *      TABLE table_name [, ...]
   10738             :  *      TABLES IN SCHEMA schema_name [, ...]
   10739             :  *
   10740             :  *****************************************************************************/
   10741             : 
   10742             : AlterPublicationStmt:
   10743             :             ALTER PUBLICATION name SET definition
   10744             :                 {
   10745         116 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10746             : 
   10747         116 :                     n->pubname = $3;
   10748         116 :                     n->options = $5;
   10749         116 :                     $$ = (Node *) n;
   10750             :                 }
   10751             :             | ALTER PUBLICATION name ADD_P pub_obj_list
   10752             :                 {
   10753         338 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10754             : 
   10755         338 :                     n->pubname = $3;
   10756         338 :                     n->pubobjects = $5;
   10757         338 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10758         332 :                     n->action = AP_AddObjects;
   10759         332 :                     $$ = (Node *) n;
   10760             :                 }
   10761             :             | ALTER PUBLICATION name SET pub_obj_list
   10762             :                 {
   10763         464 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10764             : 
   10765         464 :                     n->pubname = $3;
   10766         464 :                     n->pubobjects = $5;
   10767         464 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10768         464 :                     n->action = AP_SetObjects;
   10769         464 :                     $$ = (Node *) n;
   10770             :                 }
   10771             :             | ALTER PUBLICATION name DROP pub_obj_list
   10772             :                 {
   10773         154 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10774             : 
   10775         154 :                     n->pubname = $3;
   10776         154 :                     n->pubobjects = $5;
   10777         154 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10778         154 :                     n->action = AP_DropObjects;
   10779         154 :                     $$ = (Node *) n;
   10780             :                 }
   10781             :         ;
   10782             : 
   10783             : /*****************************************************************************
   10784             :  *
   10785             :  * CREATE SUBSCRIPTION name ...
   10786             :  *
   10787             :  *****************************************************************************/
   10788             : 
   10789             : CreateSubscriptionStmt:
   10790             :             CREATE SUBSCRIPTION name CONNECTION Sconst PUBLICATION name_list opt_definition
   10791             :                 {
   10792             :                     CreateSubscriptionStmt *n =
   10793         436 :                         makeNode(CreateSubscriptionStmt);
   10794         436 :                     n->subname = $3;
   10795         436 :                     n->conninfo = $5;
   10796         436 :                     n->publication = $7;
   10797         436 :                     n->options = $8;
   10798         436 :                     $$ = (Node *) n;
   10799             :                 }
   10800             :         ;
   10801             : 
   10802             : /*****************************************************************************
   10803             :  *
   10804             :  * ALTER SUBSCRIPTION name ...
   10805             :  *
   10806             :  *****************************************************************************/
   10807             : 
   10808             : AlterSubscriptionStmt:
   10809             :             ALTER SUBSCRIPTION name SET definition
   10810             :                 {
   10811             :                     AlterSubscriptionStmt *n =
   10812         184 :                         makeNode(AlterSubscriptionStmt);
   10813             : 
   10814         184 :                     n->kind = ALTER_SUBSCRIPTION_OPTIONS;
   10815         184 :                     n->subname = $3;
   10816         184 :                     n->options = $5;
   10817         184 :                     $$ = (Node *) n;
   10818             :                 }
   10819             :             | ALTER SUBSCRIPTION name CONNECTION Sconst
   10820             :                 {
   10821             :                     AlterSubscriptionStmt *n =
   10822          26 :                         makeNode(AlterSubscriptionStmt);
   10823             : 
   10824          26 :                     n->kind = ALTER_SUBSCRIPTION_CONNECTION;
   10825          26 :                     n->subname = $3;
   10826          26 :                     n->conninfo = $5;
   10827          26 :                     $$ = (Node *) n;
   10828             :                 }
   10829             :             | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
   10830             :                 {
   10831             :                     AlterSubscriptionStmt *n =
   10832          54 :                         makeNode(AlterSubscriptionStmt);
   10833             : 
   10834          54 :                     n->kind = ALTER_SUBSCRIPTION_REFRESH;
   10835          54 :                     n->subname = $3;
   10836          54 :                     n->options = $6;
   10837          54 :                     $$ = (Node *) n;
   10838             :                 }
   10839             :             | ALTER SUBSCRIPTION name ADD_P PUBLICATION name_list opt_definition
   10840             :                 {
   10841             :                     AlterSubscriptionStmt *n =
   10842          28 :                         makeNode(AlterSubscriptionStmt);
   10843             : 
   10844          28 :                     n->kind = ALTER_SUBSCRIPTION_ADD_PUBLICATION;
   10845          28 :                     n->subname = $3;
   10846          28 :                     n->publication = $6;
   10847          28 :                     n->options = $7;
   10848          28 :                     $$ = (Node *) n;
   10849             :                 }
   10850             :             | ALTER SUBSCRIPTION name DROP PUBLICATION name_list opt_definition
   10851             :                 {
   10852             :                     AlterSubscriptionStmt *n =
   10853          26 :                         makeNode(AlterSubscriptionStmt);
   10854             : 
   10855          26 :                     n->kind = ALTER_SUBSCRIPTION_DROP_PUBLICATION;
   10856          26 :                     n->subname = $3;
   10857          26 :                     n->publication = $6;
   10858          26 :                     n->options = $7;
   10859          26 :                     $$ = (Node *) n;
   10860             :                 }
   10861             :             | ALTER SUBSCRIPTION name SET PUBLICATION name_list opt_definition
   10862             :                 {
   10863             :                     AlterSubscriptionStmt *n =
   10864          40 :                         makeNode(AlterSubscriptionStmt);
   10865             : 
   10866          40 :                     n->kind = ALTER_SUBSCRIPTION_SET_PUBLICATION;
   10867          40 :                     n->subname = $3;
   10868          40 :                     n->publication = $6;
   10869          40 :                     n->options = $7;
   10870          40 :                     $$ = (Node *) n;
   10871             :                 }
   10872             :             | ALTER SUBSCRIPTION name ENABLE_P
   10873             :                 {
   10874             :                     AlterSubscriptionStmt *n =
   10875          48 :                         makeNode(AlterSubscriptionStmt);
   10876             : 
   10877          48 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   10878          48 :                     n->subname = $3;
   10879          48 :                     n->options = list_make1(makeDefElem("enabled",
   10880             :                                             (Node *) makeBoolean(true), @1));
   10881          48 :                     $$ = (Node *) n;
   10882             :                 }
   10883             :             | ALTER SUBSCRIPTION name DISABLE_P
   10884             :                 {
   10885             :                     AlterSubscriptionStmt *n =
   10886          32 :                         makeNode(AlterSubscriptionStmt);
   10887             : 
   10888          32 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   10889          32 :                     n->subname = $3;
   10890          32 :                     n->options = list_make1(makeDefElem("enabled",
   10891             :                                             (Node *) makeBoolean(false), @1));
   10892          32 :                     $$ = (Node *) n;
   10893             :                 }
   10894             :             | ALTER SUBSCRIPTION name SKIP definition
   10895             :                 {
   10896             :                     AlterSubscriptionStmt *n =
   10897          24 :                         makeNode(AlterSubscriptionStmt);
   10898             : 
   10899          24 :                     n->kind = ALTER_SUBSCRIPTION_SKIP;
   10900          24 :                     n->subname = $3;
   10901          24 :                     n->options = $5;
   10902          24 :                     $$ = (Node *) n;
   10903             :                 }
   10904             :         ;
   10905             : 
   10906             : /*****************************************************************************
   10907             :  *
   10908             :  * DROP SUBSCRIPTION [ IF EXISTS ] name
   10909             :  *
   10910             :  *****************************************************************************/
   10911             : 
   10912             : DropSubscriptionStmt: DROP SUBSCRIPTION name opt_drop_behavior
   10913             :                 {
   10914         208 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   10915             : 
   10916         208 :                     n->subname = $3;
   10917         208 :                     n->missing_ok = false;
   10918         208 :                     n->behavior = $4;
   10919         208 :                     $$ = (Node *) n;
   10920             :                 }
   10921             :                 |  DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
   10922             :                 {
   10923           6 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   10924             : 
   10925           6 :                     n->subname = $5;
   10926           6 :                     n->missing_ok = true;
   10927           6 :                     n->behavior = $6;
   10928           6 :                     $$ = (Node *) n;
   10929             :                 }
   10930             :         ;
   10931             : 
   10932             : /*****************************************************************************
   10933             :  *
   10934             :  *      QUERY:  Define Rewrite Rule
   10935             :  *
   10936             :  *****************************************************************************/
   10937             : 
   10938             : RuleStmt:   CREATE opt_or_replace RULE name AS
   10939             :             ON event TO qualified_name where_clause
   10940             :             DO opt_instead RuleActionList
   10941             :                 {
   10942        1066 :                     RuleStmt   *n = makeNode(RuleStmt);
   10943             : 
   10944        1066 :                     n->replace = $2;
   10945        1066 :                     n->relation = $9;
   10946        1066 :                     n->rulename = $4;
   10947        1066 :                     n->whereClause = $10;
   10948        1066 :                     n->event = $7;
   10949        1066 :                     n->instead = $12;
   10950        1066 :                     n->actions = $13;
   10951        1066 :                     $$ = (Node *) n;
   10952             :                 }
   10953             :         ;
   10954             : 
   10955             : RuleActionList:
   10956         152 :             NOTHING                                 { $$ = NIL; }
   10957         868 :             | RuleActionStmt                        { $$ = list_make1($1); }
   10958          46 :             | '(' RuleActionMulti ')'               { $$ = $2; }
   10959             :         ;
   10960             : 
   10961             : /* the thrashing around here is to discard "empty" statements... */
   10962             : RuleActionMulti:
   10963             :             RuleActionMulti ';' RuleActionStmtOrEmpty
   10964          62 :                 { if ($3 != NULL)
   10965          46 :                     $$ = lappend($1, $3);
   10966             :                   else
   10967          16 :                     $$ = $1;
   10968             :                 }
   10969             :             | RuleActionStmtOrEmpty
   10970          46 :                 { if ($1 != NULL)
   10971          46 :                     $$ = list_make1($1);
   10972             :                   else
   10973           0 :                     $$ = NIL;
   10974             :                 }
   10975             :         ;
   10976             : 
   10977             : RuleActionStmt:
   10978             :             SelectStmt
   10979             :             | InsertStmt
   10980             :             | UpdateStmt
   10981             :             | DeleteStmt
   10982             :             | NotifyStmt
   10983             :         ;
   10984             : 
   10985             : RuleActionStmtOrEmpty:
   10986          92 :             RuleActionStmt                          { $$ = $1; }
   10987          16 :             |   /*EMPTY*/                           { $$ = NULL; }
   10988             :         ;
   10989             : 
   10990          18 : event:      SELECT                                  { $$ = CMD_SELECT; }
   10991         412 :             | UPDATE                                { $$ = CMD_UPDATE; }
   10992         158 :             | DELETE_P                              { $$ = CMD_DELETE; }
   10993         478 :             | INSERT                                { $$ = CMD_INSERT; }
   10994             :          ;
   10995             : 
   10996             : opt_instead:
   10997         736 :             INSTEAD                                 { $$ = true; }
   10998         156 :             | ALSO                                  { $$ = false; }
   10999         174 :             | /*EMPTY*/                             { $$ = false; }
   11000             :         ;
   11001             : 
   11002             : 
   11003             : /*****************************************************************************
   11004             :  *
   11005             :  *      QUERY:
   11006             :  *              NOTIFY <identifier> can appear both in rule bodies and
   11007             :  *              as a query-level command
   11008             :  *
   11009             :  *****************************************************************************/
   11010             : 
   11011             : NotifyStmt: NOTIFY ColId notify_payload
   11012             :                 {
   11013         128 :                     NotifyStmt *n = makeNode(NotifyStmt);
   11014             : 
   11015         128 :                     n->conditionname = $2;
   11016         128 :                     n->payload = $3;
   11017         128 :                     $$ = (Node *) n;
   11018             :                 }
   11019             :         ;
   11020             : 
   11021             : notify_payload:
   11022          62 :             ',' Sconst                          { $$ = $2; }
   11023          66 :             | /*EMPTY*/                         { $$ = NULL; }
   11024             :         ;
   11025             : 
   11026             : ListenStmt: LISTEN ColId
   11027             :                 {
   11028          74 :                     ListenStmt *n = makeNode(ListenStmt);
   11029             : 
   11030          74 :                     n->conditionname = $2;
   11031          74 :                     $$ = (Node *) n;
   11032             :                 }
   11033             :         ;
   11034             : 
   11035             : UnlistenStmt:
   11036             :             UNLISTEN ColId
   11037             :                 {
   11038           6 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   11039             : 
   11040           6 :                     n->conditionname = $2;
   11041           6 :                     $$ = (Node *) n;
   11042             :                 }
   11043             :             | UNLISTEN '*'
   11044             :                 {
   11045          32 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   11046             : 
   11047          32 :                     n->conditionname = NULL;
   11048          32 :                     $$ = (Node *) n;
   11049             :                 }
   11050             :         ;
   11051             : 
   11052             : 
   11053             : /*****************************************************************************
   11054             :  *
   11055             :  *      Transactions:
   11056             :  *
   11057             :  *      BEGIN / COMMIT / ROLLBACK
   11058             :  *      (also older versions END / ABORT)
   11059             :  *
   11060             :  *****************************************************************************/
   11061             : 
   11062             : TransactionStmt:
   11063             :             ABORT_P opt_transaction opt_transaction_chain
   11064             :                 {
   11065         234 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11066             : 
   11067         234 :                     n->kind = TRANS_STMT_ROLLBACK;
   11068         234 :                     n->options = NIL;
   11069         234 :                     n->chain = $3;
   11070         234 :                     n->location = -1;
   11071         234 :                     $$ = (Node *) n;
   11072             :                 }
   11073             :             | START TRANSACTION transaction_mode_list_or_empty
   11074             :                 {
   11075        1600 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11076             : 
   11077        1600 :                     n->kind = TRANS_STMT_START;
   11078        1600 :                     n->options = $3;
   11079        1600 :                     n->location = -1;
   11080        1600 :                     $$ = (Node *) n;
   11081             :                 }
   11082             :             | COMMIT opt_transaction opt_transaction_chain
   11083             :                 {
   11084       11534 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11085             : 
   11086       11534 :                     n->kind = TRANS_STMT_COMMIT;
   11087       11534 :                     n->options = NIL;
   11088       11534 :                     n->chain = $3;
   11089       11534 :                     n->location = -1;
   11090       11534 :                     $$ = (Node *) n;
   11091             :                 }
   11092             :             | ROLLBACK opt_transaction opt_transaction_chain
   11093             :                 {
   11094        2530 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11095             : 
   11096        2530 :                     n->kind = TRANS_STMT_ROLLBACK;
   11097        2530 :                     n->options = NIL;
   11098        2530 :                     n->chain = $3;
   11099        2530 :                     n->location = -1;
   11100        2530 :                     $$ = (Node *) n;
   11101             :                 }
   11102             :             | SAVEPOINT ColId
   11103             :                 {
   11104        2052 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11105             : 
   11106        2052 :                     n->kind = TRANS_STMT_SAVEPOINT;
   11107        2052 :                     n->savepoint_name = $2;
   11108        2052 :                     n->location = @2;
   11109        2052 :                     $$ = (Node *) n;
   11110             :                 }
   11111             :             | RELEASE SAVEPOINT ColId
   11112             :                 {
   11113         208 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11114             : 
   11115         208 :                     n->kind = TRANS_STMT_RELEASE;
   11116         208 :                     n->savepoint_name = $3;
   11117         208 :                     n->location = @3;
   11118         208 :                     $$ = (Node *) n;
   11119             :                 }
   11120             :             | RELEASE ColId
   11121             :                 {
   11122          86 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11123             : 
   11124          86 :                     n->kind = TRANS_STMT_RELEASE;
   11125          86 :                     n->savepoint_name = $2;
   11126          86 :                     n->location = @2;
   11127          86 :                     $$ = (Node *) n;
   11128             :                 }
   11129             :             | ROLLBACK opt_transaction TO SAVEPOINT ColId
   11130             :                 {
   11131         218 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11132             : 
   11133         218 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   11134         218 :                     n->savepoint_name = $5;
   11135         218 :                     n->location = @5;
   11136         218 :                     $$ = (Node *) n;
   11137             :                 }
   11138             :             | ROLLBACK opt_transaction TO ColId
   11139             :                 {
   11140         496 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11141             : 
   11142         496 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   11143         496 :                     n->savepoint_name = $4;
   11144         496 :                     n->location = @4;
   11145         496 :                     $$ = (Node *) n;
   11146             :                 }
   11147             :             | PREPARE TRANSACTION Sconst
   11148             :                 {
   11149         812 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11150             : 
   11151         812 :                     n->kind = TRANS_STMT_PREPARE;
   11152         812 :                     n->gid = $3;
   11153         812 :                     n->location = @3;
   11154         812 :                     $$ = (Node *) n;
   11155             :                 }
   11156             :             | COMMIT PREPARED Sconst
   11157             :                 {
   11158         658 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11159             : 
   11160         658 :                     n->kind = TRANS_STMT_COMMIT_PREPARED;
   11161         658 :                     n->gid = $3;
   11162         658 :                     n->location = @3;
   11163         658 :                     $$ = (Node *) n;
   11164             :                 }
   11165             :             | ROLLBACK PREPARED Sconst
   11166             :                 {
   11167          74 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11168             : 
   11169          74 :                     n->kind = TRANS_STMT_ROLLBACK_PREPARED;
   11170          74 :                     n->gid = $3;
   11171          74 :                     n->location = @3;
   11172          74 :                     $$ = (Node *) n;
   11173             :                 }
   11174             :         ;
   11175             : 
   11176             : TransactionStmtLegacy:
   11177             :             BEGIN_P opt_transaction transaction_mode_list_or_empty
   11178             :                 {
   11179       14162 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11180             : 
   11181       14162 :                     n->kind = TRANS_STMT_BEGIN;
   11182       14162 :                     n->options = $3;
   11183       14162 :                     n->location = -1;
   11184       14162 :                     $$ = (Node *) n;
   11185             :                 }
   11186             :             | END_P opt_transaction opt_transaction_chain
   11187             :                 {
   11188         360 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11189             : 
   11190         360 :                     n->kind = TRANS_STMT_COMMIT;
   11191         360 :                     n->options = NIL;
   11192         360 :                     n->chain = $3;
   11193         360 :                     n->location = -1;
   11194         360 :                     $$ = (Node *) n;
   11195             :                 }
   11196             :         ;
   11197             : 
   11198             : opt_transaction:    WORK
   11199             :             | TRANSACTION
   11200             :             | /*EMPTY*/
   11201             :         ;
   11202             : 
   11203             : transaction_mode_item:
   11204             :             ISOLATION LEVEL iso_level
   11205        6590 :                     { $$ = makeDefElem("transaction_isolation",
   11206        6590 :                                        makeStringConst($3, @3), @1); }
   11207             :             | READ ONLY
   11208        1328 :                     { $$ = makeDefElem("transaction_read_only",
   11209        1328 :                                        makeIntConst(true, @1), @1); }
   11210             :             | READ WRITE
   11211          90 :                     { $$ = makeDefElem("transaction_read_only",
   11212          90 :                                        makeIntConst(false, @1), @1); }
   11213             :             | DEFERRABLE
   11214          44 :                     { $$ = makeDefElem("transaction_deferrable",
   11215             :                                        makeIntConst(true, @1), @1); }
   11216             :             | NOT DEFERRABLE
   11217          10 :                     { $$ = makeDefElem("transaction_deferrable",
   11218          10 :                                        makeIntConst(false, @1), @1); }
   11219             :         ;
   11220             : 
   11221             : /* Syntax with commas is SQL-spec, without commas is Postgres historical */
   11222             : transaction_mode_list:
   11223             :             transaction_mode_item
   11224        6806 :                     { $$ = list_make1($1); }
   11225             :             | transaction_mode_list ',' transaction_mode_item
   11226         878 :                     { $$ = lappend($1, $3); }
   11227             :             | transaction_mode_list transaction_mode_item
   11228         378 :                     { $$ = lappend($1, $2); }
   11229             :         ;
   11230             : 
   11231             : transaction_mode_list_or_empty:
   11232             :             transaction_mode_list
   11233             :             | /* EMPTY */
   11234        9494 :                     { $$ = NIL; }
   11235             :         ;
   11236             : 
   11237             : opt_transaction_chain:
   11238         120 :             AND CHAIN       { $$ = true; }
   11239           2 :             | AND NO CHAIN  { $$ = false; }
   11240       14536 :             | /* EMPTY */   { $$ = false; }
   11241             :         ;
   11242             : 
   11243             : 
   11244             : /*****************************************************************************
   11245             :  *
   11246             :  *  QUERY:
   11247             :  *      CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
   11248             :  *          AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
   11249             :  *
   11250             :  *****************************************************************************/
   11251             : 
   11252             : ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11253             :                 AS SelectStmt opt_check_option
   11254             :                 {
   11255       14906 :                     ViewStmt   *n = makeNode(ViewStmt);
   11256             : 
   11257       14906 :                     n->view = $4;
   11258       14906 :                     n->view->relpersistence = $2;
   11259       14906 :                     n->aliases = $5;
   11260       14906 :                     n->query = $8;
   11261       14906 :                     n->replace = false;
   11262       14906 :                     n->options = $6;
   11263       14906 :                     n->withCheckOption = $9;
   11264       14906 :                     $$ = (Node *) n;
   11265             :                 }
   11266             :         | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11267             :                 AS SelectStmt opt_check_option
   11268             :                 {
   11269         244 :                     ViewStmt   *n = makeNode(ViewStmt);
   11270             : 
   11271         244 :                     n->view = $6;
   11272         244 :                     n->view->relpersistence = $4;
   11273         244 :                     n->aliases = $7;
   11274         244 :                     n->query = $10;
   11275         244 :                     n->replace = true;
   11276         244 :                     n->options = $8;
   11277         244 :                     n->withCheckOption = $11;
   11278         244 :                     $$ = (Node *) n;
   11279             :                 }
   11280             :         | CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11281             :                 AS SelectStmt opt_check_option
   11282             :                 {
   11283           8 :                     ViewStmt   *n = makeNode(ViewStmt);
   11284             : 
   11285           8 :                     n->view = $5;
   11286           8 :                     n->view->relpersistence = $2;
   11287           8 :                     n->aliases = $7;
   11288           8 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
   11289           8 :                     n->replace = false;
   11290           8 :                     n->options = $9;
   11291           8 :                     n->withCheckOption = $12;
   11292           8 :                     if (n->withCheckOption != NO_CHECK_OPTION)
   11293           0 :                         ereport(ERROR,
   11294             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   11295             :                                  errmsg("WITH CHECK OPTION not supported on recursive views"),
   11296             :                                  parser_errposition(@12)));
   11297           8 :                     $$ = (Node *) n;
   11298             :                 }
   11299             :         | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11300             :                 AS SelectStmt opt_check_option
   11301             :                 {
   11302           6 :                     ViewStmt   *n = makeNode(ViewStmt);
   11303             : 
   11304           6 :                     n->view = $7;
   11305           6 :                     n->view->relpersistence = $4;
   11306           6 :                     n->aliases = $9;
   11307           6 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
   11308           6 :                     n->replace = true;
   11309           6 :                     n->options = $11;
   11310           6 :                     n->withCheckOption = $14;
   11311           6 :                     if (n->withCheckOption != NO_CHECK_OPTION)
   11312           0 :                         ereport(ERROR,
   11313             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   11314             :                                  errmsg("WITH CHECK OPTION not supported on recursive views"),
   11315             :                                  parser_errposition(@14)));
   11316           6 :                     $$ = (Node *) n;
   11317             :                 }
   11318             :         ;
   11319             : 
   11320             : opt_check_option:
   11321          90 :         WITH CHECK OPTION               { $$ = CASCADED_CHECK_OPTION; }
   11322           6 :         | WITH CASCADED CHECK OPTION    { $$ = CASCADED_CHECK_OPTION; }
   11323          24 :         | WITH LOCAL CHECK OPTION       { $$ = LOCAL_CHECK_OPTION; }
   11324       15044 :         | /* EMPTY */                   { $$ = NO_CHECK_OPTION; }
   11325             :         ;
   11326             : 
   11327             : /*****************************************************************************
   11328             :  *
   11329             :  *      QUERY:
   11330             :  *              LOAD "filename"
   11331             :  *
   11332             :  *****************************************************************************/
   11333             : 
   11334             : LoadStmt:   LOAD file_name
   11335             :                 {
   11336          58 :                     LoadStmt   *n = makeNode(LoadStmt);
   11337             : 
   11338          58 :                     n->filename = $2;
   11339          58 :                     $$ = (Node *) n;
   11340             :                 }
   11341             :         ;
   11342             : 
   11343             : 
   11344             : /*****************************************************************************
   11345             :  *
   11346             :  *      CREATE DATABASE
   11347             :  *
   11348             :  *****************************************************************************/
   11349             : 
   11350             : CreatedbStmt:
   11351             :             CREATE DATABASE name opt_with createdb_opt_list
   11352             :                 {
   11353         684 :                     CreatedbStmt *n = makeNode(CreatedbStmt);
   11354             : 
   11355         684 :                     n->dbname = $3;
   11356         684 :                     n->options = $5;
   11357         684 :                     $$ = (Node *) n;
   11358             :                 }
   11359             :         ;
   11360             : 
   11361             : createdb_opt_list:
   11362         532 :             createdb_opt_items                      { $$ = $1; }
   11363         182 :             | /* EMPTY */                           { $$ = NIL; }
   11364             :         ;
   11365             : 
   11366             : createdb_opt_items:
   11367         532 :             createdb_opt_item                       { $$ = list_make1($1); }
   11368         716 :             | createdb_opt_items createdb_opt_item  { $$ = lappend($1, $2); }
   11369             :         ;
   11370             : 
   11371             : createdb_opt_item:
   11372             :             createdb_opt_name opt_equal NumericOnly
   11373             :                 {
   11374         210 :                     $$ = makeDefElem($1, $3, @1);
   11375             :                 }
   11376             :             | createdb_opt_name opt_equal opt_boolean_or_string
   11377             :                 {
   11378        1038 :                     $$ = makeDefElem($1, (Node *) makeString($3), @1);
   11379             :                 }
   11380             :             | createdb_opt_name opt_equal DEFAULT
   11381             :                 {
   11382           0 :                     $$ = makeDefElem($1, NULL, @1);
   11383             :                 }
   11384             :         ;
   11385             : 
   11386             : /*
   11387             :  * Ideally we'd use ColId here, but that causes shift/reduce conflicts against
   11388             :  * the ALTER DATABASE SET/RESET syntaxes.  Instead call out specific keywords
   11389             :  * we need, and allow IDENT so that database option names don't have to be
   11390             :  * parser keywords unless they are already keywords for other reasons.
   11391             :  *
   11392             :  * XXX this coding technique is fragile since if someone makes a formerly
   11393             :  * non-keyword option name into a keyword and forgets to add it here, the
   11394             :  * option will silently break.  Best defense is to provide a regression test
   11395             :  * exercising every such option, at least at the syntax level.
   11396             :  */
   11397             : createdb_opt_name:
   11398         866 :             IDENT                           { $$ = $1; }
   11399           2 :             | CONNECTION LIMIT              { $$ = pstrdup("connection_limit"); }
   11400          66 :             | ENCODING                      { $$ = pstrdup($1); }
   11401           0 :             | LOCATION                      { $$ = pstrdup($1); }
   11402           2 :             | OWNER                         { $$ = pstrdup($1); }
   11403          16 :             | TABLESPACE                    { $$ = pstrdup($1); }
   11404         296 :             | TEMPLATE                      { $$ = pstrdup($1); }
   11405             :         ;
   11406             : 
   11407             : /*
   11408             :  *  Though the equals sign doesn't match other WITH options, pg_dump uses
   11409             :  *  equals for backward compatibility, and it doesn't seem worth removing it.
   11410             :  */
   11411             : opt_equal:  '='
   11412             :             | /*EMPTY*/
   11413             :         ;
   11414             : 
   11415             : 
   11416             : /*****************************************************************************
   11417             :  *
   11418             :  *      ALTER DATABASE
   11419             :  *
   11420             :  *****************************************************************************/
   11421             : 
   11422             : AlterDatabaseStmt:
   11423             :             ALTER DATABASE name WITH createdb_opt_list
   11424             :                  {
   11425           0 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11426             : 
   11427           0 :                     n->dbname = $3;
   11428           0 :                     n->options = $5;
   11429           0 :                     $$ = (Node *) n;
   11430             :                  }
   11431             :             | ALTER DATABASE name createdb_opt_list
   11432             :                  {
   11433          30 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11434             : 
   11435          30 :                     n->dbname = $3;
   11436          30 :                     n->options = $4;
   11437          30 :                     $$ = (Node *) n;
   11438             :                  }
   11439             :             | ALTER DATABASE name SET TABLESPACE name
   11440             :                  {
   11441          16 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11442             : 
   11443          16 :                     n->dbname = $3;
   11444          16 :                     n->options = list_make1(makeDefElem("tablespace",
   11445             :                                                         (Node *) makeString($6), @6));
   11446          16 :                     $$ = (Node *) n;
   11447             :                  }
   11448             :             | ALTER DATABASE name REFRESH COLLATION VERSION_P
   11449             :                  {
   11450           6 :                     AlterDatabaseRefreshCollStmt *n = makeNode(AlterDatabaseRefreshCollStmt);
   11451             : 
   11452           6 :                     n->dbname = $3;
   11453           6 :                     $$ = (Node *) n;
   11454             :                  }
   11455             :         ;
   11456             : 
   11457             : AlterDatabaseSetStmt:
   11458             :             ALTER DATABASE name SetResetClause
   11459             :                 {
   11460        1138 :                     AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
   11461             : 
   11462        1138 :                     n->dbname = $3;
   11463        1138 :                     n->setstmt = $4;
   11464        1138 :                     $$ = (Node *) n;
   11465             :                 }
   11466             :         ;
   11467             : 
   11468             : 
   11469             : /*****************************************************************************
   11470             :  *
   11471             :  *      DROP DATABASE [ IF EXISTS ] dbname [ [ WITH ] ( options ) ]
   11472             :  *
   11473             :  * This is implicitly CASCADE, no need for drop behavior
   11474             :  *****************************************************************************/
   11475             : 
   11476             : DropdbStmt: DROP DATABASE name
   11477             :                 {
   11478          72 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11479             : 
   11480          72 :                     n->dbname = $3;
   11481          72 :                     n->missing_ok = false;
   11482          72 :                     n->options = NULL;
   11483          72 :                     $$ = (Node *) n;
   11484             :                 }
   11485             :             | DROP DATABASE IF_P EXISTS name
   11486             :                 {
   11487           4 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11488             : 
   11489           4 :                     n->dbname = $5;
   11490           4 :                     n->missing_ok = true;
   11491           4 :                     n->options = NULL;
   11492           4 :                     $$ = (Node *) n;
   11493             :                 }
   11494             :             | DROP DATABASE name opt_with '(' drop_option_list ')'
   11495             :                 {
   11496          14 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11497             : 
   11498          14 :                     n->dbname = $3;
   11499          14 :                     n->missing_ok = false;
   11500          14 :                     n->options = $6;
   11501          14 :                     $$ = (Node *) n;
   11502             :                 }
   11503             :             | DROP DATABASE IF_P EXISTS name opt_with '(' drop_option_list ')'
   11504             :                 {
   11505          12 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11506             : 
   11507          12 :                     n->dbname = $5;
   11508          12 :                     n->missing_ok = true;
   11509          12 :                     n->options = $8;
   11510          12 :                     $$ = (Node *) n;
   11511             :                 }
   11512             :         ;
   11513             : 
   11514             : drop_option_list:
   11515             :             drop_option
   11516             :                 {
   11517          26 :                     $$ = list_make1((Node *) $1);
   11518             :                 }
   11519             :             | drop_option_list ',' drop_option
   11520             :                 {
   11521           0 :                     $$ = lappend($1, (Node *) $3);
   11522             :                 }
   11523             :         ;
   11524             : 
   11525             : /*
   11526             :  * Currently only the FORCE option is supported, but the syntax is designed
   11527             :  * to be extensible so that we can add more options in the future if required.
   11528             :  */
   11529             : drop_option:
   11530             :             FORCE
   11531             :                 {
   11532          26 :                     $$ = makeDefElem("force", NULL, @1);
   11533             :                 }
   11534             :         ;
   11535             : 
   11536             : /*****************************************************************************
   11537             :  *
   11538             :  *      ALTER COLLATION
   11539             :  *
   11540             :  *****************************************************************************/
   11541             : 
   11542             : AlterCollationStmt: ALTER COLLATION any_name REFRESH VERSION_P
   11543             :                 {
   11544           6 :                     AlterCollationStmt *n = makeNode(AlterCollationStmt);
   11545             : 
   11546           6 :                     n->collname = $3;
   11547           6 :                     $$ = (Node *) n;
   11548             :                 }
   11549             :         ;
   11550             : 
   11551             : 
   11552             : /*****************************************************************************
   11553             :  *
   11554             :  *      ALTER SYSTEM
   11555             :  *
   11556             :  * This is used to change configuration parameters persistently.
   11557             :  *****************************************************************************/
   11558             : 
   11559             : AlterSystemStmt:
   11560             :             ALTER SYSTEM_P SET generic_set
   11561             :                 {
   11562         112 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11563             : 
   11564         112 :                     n->setstmt = $4;
   11565         112 :                     $$ = (Node *) n;
   11566             :                 }
   11567             :             | ALTER SYSTEM_P RESET generic_reset
   11568             :                 {
   11569          54 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11570             : 
   11571          54 :                     n->setstmt = $4;
   11572          54 :                     $$ = (Node *) n;
   11573             :                 }
   11574             :         ;
   11575             : 
   11576             : 
   11577             : /*****************************************************************************
   11578             :  *
   11579             :  * Manipulate a domain
   11580             :  *
   11581             :  *****************************************************************************/
   11582             : 
   11583             : CreateDomainStmt:
   11584             :             CREATE DOMAIN_P any_name opt_as Typename ColQualList
   11585             :                 {
   11586        1340 :                     CreateDomainStmt *n = makeNode(CreateDomainStmt);
   11587             : 
   11588        1340 :                     n->domainname = $3;
   11589        1340 :                     n->typeName = $5;
   11590        1340 :                     SplitColQualList($6, &n->constraints, &n->collClause,
   11591             :                                      yyscanner);
   11592        1340 :                     $$ = (Node *) n;
   11593             :                 }
   11594             :         ;
   11595             : 
   11596             : AlterDomainStmt:
   11597             :             /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
   11598             :             ALTER DOMAIN_P any_name alter_column_default
   11599             :                 {
   11600          14 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11601             : 
   11602          14 :                     n->subtype = 'T';
   11603          14 :                     n->typeName = $3;
   11604          14 :                     n->def = $4;
   11605          14 :                     $$ = (Node *) n;
   11606             :                 }
   11607             :             /* ALTER DOMAIN <domain> DROP NOT NULL */
   11608             :             | ALTER DOMAIN_P any_name DROP NOT NULL_P
   11609             :                 {
   11610          12 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11611             : 
   11612          12 :                     n->subtype = 'N';
   11613          12 :                     n->typeName = $3;
   11614          12 :                     $$ = (Node *) n;
   11615             :                 }
   11616             :             /* ALTER DOMAIN <domain> SET NOT NULL */
   11617             :             | ALTER DOMAIN_P any_name SET NOT NULL_P
   11618             :                 {
   11619          24 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11620             : 
   11621          24 :                     n->subtype = 'O';
   11622          24 :                     n->typeName = $3;
   11623          24 :                     $$ = (Node *) n;
   11624             :                 }
   11625             :             /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
   11626             :             | ALTER DOMAIN_P any_name ADD_P DomainConstraint
   11627             :                 {
   11628         174 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11629             : 
   11630         174 :                     n->subtype = 'C';
   11631         174 :                     n->typeName = $3;
   11632         174 :                     n->def = $5;
   11633         174 :                     $$ = (Node *) n;
   11634             :                 }
   11635             :             /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
   11636             :             | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
   11637             :                 {
   11638          54 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11639             : 
   11640          54 :                     n->subtype = 'X';
   11641          54 :                     n->typeName = $3;
   11642          54 :                     n->name = $6;
   11643          54 :                     n->behavior = $7;
   11644          54 :                     n->missing_ok = false;
   11645          54 :                     $$ = (Node *) n;
   11646             :                 }
   11647             :             /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
   11648             :             | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
   11649             :                 {
   11650           6 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11651             : 
   11652           6 :                     n->subtype = 'X';
   11653           6 :                     n->typeName = $3;
   11654           6 :                     n->name = $8;
   11655           6 :                     n->behavior = $9;
   11656           6 :                     n->missing_ok = true;
   11657           6 :                     $$ = (Node *) n;
   11658             :                 }
   11659             :             /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
   11660             :             | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
   11661             :                 {
   11662          12 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11663             : 
   11664          12 :                     n->subtype = 'V';
   11665          12 :                     n->typeName = $3;
   11666          12 :                     n->name = $6;
   11667          12 :                     $$ = (Node *) n;
   11668             :                 }
   11669             :             ;
   11670             : 
   11671             : opt_as:     AS
   11672             :             | /* EMPTY */
   11673             :         ;
   11674             : 
   11675             : 
   11676             : /*****************************************************************************
   11677             :  *
   11678             :  * Manipulate a text search dictionary or configuration
   11679             :  *
   11680             :  *****************************************************************************/
   11681             : 
   11682             : AlterTSDictionaryStmt:
   11683             :             ALTER TEXT_P SEARCH DICTIONARY any_name definition
   11684             :                 {
   11685          40 :                     AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
   11686             : 
   11687          40 :                     n->dictname = $5;
   11688          40 :                     n->options = $6;
   11689          40 :                     $$ = (Node *) n;
   11690             :                 }
   11691             :         ;
   11692             : 
   11693             : AlterTSConfigurationStmt:
   11694             :             ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
   11695             :                 {
   11696        7390 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11697             : 
   11698        7390 :                     n->kind = ALTER_TSCONFIG_ADD_MAPPING;
   11699        7390 :                     n->cfgname = $5;
   11700        7390 :                     n->tokentype = $9;
   11701        7390 :                     n->dicts = $11;
   11702        7390 :                     n->override = false;
   11703        7390 :                     n->replace = false;
   11704        7390 :                     $$ = (Node *) n;
   11705             :                 }
   11706             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
   11707             :                 {
   11708          26 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11709             : 
   11710          26 :                     n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
   11711          26 :                     n->cfgname = $5;
   11712          26 :                     n->tokentype = $9;
   11713          26 :                     n->dicts = $11;
   11714          26 :                     n->override = true;
   11715          26 :                     n->replace = false;
   11716          26 :                     $$ = (Node *) n;
   11717             :                 }
   11718             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
   11719             :                 {
   11720          18 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11721             : 
   11722          18 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT;
   11723          18 :                     n->cfgname = $5;
   11724          18 :                     n->tokentype = NIL;
   11725          18 :                     n->dicts = list_make2($9,$11);
   11726          18 :                     n->override = false;
   11727          18 :                     n->replace = true;
   11728          18 :                     $$ = (Node *) n;
   11729             :                 }
   11730             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
   11731             :                 {
   11732           0 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11733             : 
   11734           0 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN;
   11735           0 :                     n->cfgname = $5;
   11736           0 :                     n->tokentype = $9;
   11737           0 :                     n->dicts = list_make2($11,$13);
   11738           0 :                     n->override = false;
   11739           0 :                     n->replace = true;
   11740           0 :                     $$ = (Node *) n;
   11741             :                 }
   11742             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
   11743             :                 {
   11744          18 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11745             : 
   11746          18 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   11747          18 :                     n->cfgname = $5;
   11748          18 :                     n->tokentype = $9;
   11749          18 :                     n->missing_ok = false;
   11750          18 :                     $$ = (Node *) n;
   11751             :                 }
   11752             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
   11753             :                 {
   11754          12 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11755             : 
   11756          12 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   11757          12 :                     n->cfgname = $5;
   11758          12 :                     n->tokentype = $11;
   11759          12 :                     n->missing_ok = true;
   11760          12 :                     $$ = (Node *) n;
   11761             :                 }
   11762             :         ;
   11763             : 
   11764             : /* Use this if TIME or ORDINALITY after WITH should be taken as an identifier */
   11765             : any_with:   WITH
   11766             :             | WITH_LA
   11767             :         ;
   11768             : 
   11769             : 
   11770             : /*****************************************************************************
   11771             :  *
   11772             :  * Manipulate a conversion
   11773             :  *
   11774             :  *      CREATE [DEFAULT] CONVERSION <conversion_name>
   11775             :  *      FOR <encoding_name> TO <encoding_name> FROM <func_name>
   11776             :  *
   11777             :  *****************************************************************************/
   11778             : 
   11779             : CreateConversionStmt:
   11780             :             CREATE opt_default CONVERSION_P any_name FOR Sconst
   11781             :             TO Sconst FROM any_name
   11782             :             {
   11783          64 :                 CreateConversionStmt *n = makeNode(CreateConversionStmt);
   11784             : 
   11785          64 :                 n->conversion_name = $4;
   11786          64 :                 n->for_encoding_name = $6;
   11787          64 :                 n->to_encoding_name = $8;
   11788          64 :                 n->func_name = $10;
   11789          64 :                 n->def = $2;
   11790          64 :                 $$ = (Node *) n;
   11791             :             }
   11792             :         ;
   11793             : 
   11794             : /*****************************************************************************
   11795             :  *
   11796             :  *      QUERY:
   11797             :  *              CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
   11798             :  *              CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
   11799             :  *              CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
   11800             :  *
   11801             :  *****************************************************************************/
   11802             : 
   11803             : ClusterStmt:
   11804             :             CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
   11805             :                 {
   11806           0 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11807             : 
   11808           0 :                     n->relation = $5;
   11809           0 :                     n->indexname = $6;
   11810           0 :                     n->params = $3;
   11811           0 :                     $$ = (Node *) n;
   11812             :                 }
   11813             :             | CLUSTER '(' utility_option_list ')'
   11814             :                 {
   11815           0 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11816             : 
   11817           0 :                     n->relation = NULL;
   11818           0 :                     n->indexname = NULL;
   11819           0 :                     n->params = $3;
   11820           0 :                     $$ = (Node *) n;
   11821             :                 }
   11822             :             /* unparenthesized VERBOSE kept for pre-14 compatibility */
   11823             :             | CLUSTER opt_verbose qualified_name cluster_index_specification
   11824             :                 {
   11825         190 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11826             : 
   11827         190 :                     n->relation = $3;
   11828         190 :                     n->indexname = $4;
   11829         190 :                     n->params = NIL;
   11830         190 :                     if ($2)
   11831           0 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11832         190 :                     $$ = (Node *) n;
   11833             :                 }
   11834             :             /* unparenthesized VERBOSE kept for pre-17 compatibility */
   11835             :             | CLUSTER opt_verbose
   11836             :                 {
   11837          28 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11838             : 
   11839          28 :                     n->relation = NULL;
   11840          28 :                     n->indexname = NULL;
   11841          28 :                     n->params = NIL;
   11842          28 :                     if ($2)
   11843          12 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11844          28 :                     $$ = (Node *) n;
   11845             :                 }
   11846             :             /* kept for pre-8.3 compatibility */
   11847             :             | CLUSTER opt_verbose name ON qualified_name
   11848             :                 {
   11849          18 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11850             : 
   11851          18 :                     n->relation = $5;
   11852          18 :                     n->indexname = $3;
   11853          18 :                     n->params = NIL;
   11854          18 :                     if ($2)
   11855           0 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11856          18 :                     $$ = (Node *) n;
   11857             :                 }
   11858             :         ;
   11859             : 
   11860             : cluster_index_specification:
   11861         156 :             USING name              { $$ = $2; }
   11862          34 :             | /*EMPTY*/             { $$ = NULL; }
   11863             :         ;
   11864             : 
   11865             : 
   11866             : /*****************************************************************************
   11867             :  *
   11868             :  *      QUERY:
   11869             :  *              VACUUM
   11870             :  *              ANALYZE
   11871             :  *
   11872             :  *****************************************************************************/
   11873             : 
   11874             : VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relation_list
   11875             :                 {
   11876        1152 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11877             : 
   11878        1152 :                     n->options = NIL;
   11879        1152 :                     if ($2)
   11880         130 :                         n->options = lappend(n->options,
   11881         130 :                                              makeDefElem("full", NULL, @2));
   11882        1152 :                     if ($3)
   11883         152 :                         n->options = lappend(n->options,
   11884         152 :                                              makeDefElem("freeze", NULL, @3));
   11885        1152 :                     if ($4)
   11886          18 :                         n->options = lappend(n->options,
   11887          18 :                                              makeDefElem("verbose", NULL, @4));
   11888        1152 :                     if ($5)
   11889         278 :                         n->options = lappend(n->options,
   11890         278 :                                              makeDefElem("analyze", NULL, @5));
   11891        1152 :                     n->rels = $6;
   11892        1152 :                     n->is_vacuumcmd = true;
   11893        1152 :                     $$ = (Node *) n;
   11894             :                 }
   11895             :             | VACUUM '(' utility_option_list ')' opt_vacuum_relation_list
   11896             :                 {
   11897        4964 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11898             : 
   11899        4964 :                     n->options = $3;
   11900        4964 :                     n->rels = $5;
   11901        4964 :                     n->is_vacuumcmd = true;
   11902        4964 :                     $$ = (Node *) n;
   11903             :                 }
   11904             :         ;
   11905             : 
   11906             : AnalyzeStmt: analyze_keyword opt_verbose opt_vacuum_relation_list
   11907             :                 {
   11908        4406 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11909             : 
   11910        4406 :                     n->options = NIL;
   11911        4406 :                     if ($2)
   11912           0 :                         n->options = lappend(n->options,
   11913           0 :                                              makeDefElem("verbose", NULL, @2));
   11914        4406 :                     n->rels = $3;
   11915        4406 :                     n->is_vacuumcmd = false;
   11916        4406 :                     $$ = (Node *) n;
   11917             :                 }
   11918             :             | analyze_keyword '(' utility_option_list ')' opt_vacuum_relation_list
   11919             :                 {
   11920         186 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11921             : 
   11922         186 :                     n->options = $3;
   11923         186 :                     n->rels = $5;
   11924         186 :                     n->is_vacuumcmd = false;
   11925         186 :                     $$ = (Node *) n;
   11926             :                 }
   11927             :         ;
   11928             : 
   11929             : utility_option_list:
   11930             :             utility_option_elem
   11931             :                 {
   11932       18186 :                     $$ = list_make1($1);
   11933             :                 }
   11934             :             | utility_option_list ',' utility_option_elem
   11935             :                 {
   11936        9430 :                     $$ = lappend($1, $3);
   11937             :                 }
   11938             :         ;
   11939             : 
   11940             : analyze_keyword:
   11941             :             ANALYZE
   11942             :             | ANALYSE /* British */
   11943             :         ;
   11944             : 
   11945             : utility_option_elem:
   11946             :             utility_option_name utility_option_arg
   11947             :                 {
   11948       27616 :                     $$ = makeDefElem($1, $2, @1);
   11949             :                 }
   11950             :         ;
   11951             : 
   11952             : utility_option_name:
   11953       25234 :             NonReservedWord                         { $$ = $1; }
   11954        2240 :             | analyze_keyword                       { $$ = "analyze"; }
   11955         148 :             | FORMAT_LA                             { $$ = "format"; }
   11956             :         ;
   11957             : 
   11958             : utility_option_arg:
   11959       16344 :             opt_boolean_or_string                   { $$ = (Node *) makeString($1); }
   11960         368 :             | NumericOnly                           { $$ = (Node *) $1; }
   11961       10904 :             | /* EMPTY */                           { $$ = NULL; }
   11962             :         ;
   11963             : 
   11964             : opt_analyze:
   11965         278 :             analyze_keyword                         { $$ = true; }
   11966         874 :             | /*EMPTY*/                             { $$ = false; }
   11967             :         ;
   11968             : 
   11969             : opt_verbose:
   11970          30 :             VERBOSE                                 { $$ = true; }
   11971        8056 :             | /*EMPTY*/                             { $$ = false; }
   11972             :         ;
   11973             : 
   11974         130 : opt_full:   FULL                                    { $$ = true; }
   11975        1022 :             | /*EMPTY*/                             { $$ = false; }
   11976             :         ;
   11977             : 
   11978         152 : opt_freeze: FREEZE                                  { $$ = true; }
   11979        1000 :             | /*EMPTY*/                             { $$ = false; }
   11980             :         ;
   11981             : 
   11982             : opt_name_list:
   11983        2494 :             '(' name_list ')'                       { $$ = $2; }
   11984       12632 :             | /*EMPTY*/                             { $$ = NIL; }
   11985             :         ;
   11986             : 
   11987             : vacuum_relation:
   11988             :             relation_expr opt_name_list
   11989             :                 {
   11990       10540 :                     $$ = (Node *) makeVacuumRelation($1, InvalidOid, $2);
   11991             :                 }
   11992             :         ;
   11993             : 
   11994             : vacuum_relation_list:
   11995             :             vacuum_relation
   11996       10392 :                     { $$ = list_make1($1); }
   11997             :             | vacuum_relation_list ',' vacuum_relation
   11998         148 :                     { $$ = lappend($1, $3); }
   11999             :         ;
   12000             : 
   12001             : opt_vacuum_relation_list:
   12002       10392 :             vacuum_relation_list                    { $$ = $1; }
   12003         316 :             | /*EMPTY*/                             { $$ = NIL; }
   12004             :         ;
   12005             : 
   12006             : 
   12007             : /*****************************************************************************
   12008             :  *
   12009             :  *      QUERY:
   12010             :  *              EXPLAIN [ANALYZE] [VERBOSE] query
   12011             :  *              EXPLAIN ( options ) query
   12012             :  *
   12013             :  *****************************************************************************/
   12014             : 
   12015             : ExplainStmt:
   12016             :         EXPLAIN ExplainableStmt
   12017             :                 {
   12018        7646 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12019             : 
   12020        7646 :                     n->query = $2;
   12021        7646 :                     n->options = NIL;
   12022        7646 :                     $$ = (Node *) n;
   12023             :                 }
   12024             :         | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
   12025             :                 {
   12026        2292 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12027             : 
   12028        2292 :                     n->query = $4;
   12029        2292 :                     n->options = list_make1(makeDefElem("analyze", NULL, @2));
   12030        2292 :                     if ($3)
   12031           0 :                         n->options = lappend(n->options,
   12032           0 :                                              makeDefElem("verbose", NULL, @3));
   12033        2292 :                     $$ = (Node *) n;
   12034             :                 }
   12035             :         | EXPLAIN VERBOSE ExplainableStmt
   12036             :                 {
   12037           0 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12038             : 
   12039           0 :                     n->query = $3;
   12040           0 :                     n->options = list_make1(makeDefElem("verbose", NULL, @2));
   12041           0 :                     $$ = (Node *) n;
   12042             :                 }
   12043             :         | EXPLAIN '(' utility_option_list ')' ExplainableStmt
   12044             :                 {
   12045       12880 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12046             : 
   12047       12880 :                     n->query = $5;
   12048       12880 :                     n->options = $3;
   12049       12880 :                     $$ = (Node *) n;
   12050             :                 }
   12051             :         ;
   12052             : 
   12053             : ExplainableStmt:
   12054             :             SelectStmt
   12055             :             | InsertStmt
   12056             :             | UpdateStmt
   12057             :             | DeleteStmt
   12058             :             | MergeStmt
   12059             :             | DeclareCursorStmt
   12060             :             | CreateAsStmt
   12061             :             | CreateMatViewStmt
   12062             :             | RefreshMatViewStmt
   12063             :             | ExecuteStmt                   /* by default all are $$=$1 */
   12064             :         ;
   12065             : 
   12066             : /*****************************************************************************
   12067             :  *
   12068             :  *      QUERY:
   12069             :  *              PREPARE <plan_name> [(args, ...)] AS <query>
   12070             :  *
   12071             :  *****************************************************************************/
   12072             : 
   12073             : PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
   12074             :                 {
   12075        1720 :                     PrepareStmt *n = makeNode(PrepareStmt);
   12076             : 
   12077        1720 :                     n->name = $2;
   12078        1720 :                     n->argtypes = $3;
   12079        1720 :                     n->query = $5;
   12080        1720 :                     $$ = (Node *) n;
   12081             :                 }
   12082             :         ;
   12083             : 
   12084        1418 : prep_type_clause: '(' type_list ')'         { $$ = $2; }
   12085         320 :                 | /* EMPTY */               { $$ = NIL; }
   12086             :         ;
   12087             : 
   12088             : PreparableStmt:
   12089             :             SelectStmt
   12090             :             | InsertStmt
   12091             :             | UpdateStmt
   12092             :             | DeleteStmt
   12093             :             | MergeStmt                     /* by default all are $$=$1 */
   12094             :         ;
   12095             : 
   12096             : /*****************************************************************************
   12097             :  *
   12098             :  * EXECUTE <plan_name> [(params, ...)]
   12099             :  * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
   12100             :  *
   12101             :  *****************************************************************************/
   12102             : 
   12103             : ExecuteStmt: EXECUTE name execute_param_clause
   12104             :                 {
   12105       15348 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12106             : 
   12107       15348 :                     n->name = $2;
   12108       15348 :                     n->params = $3;
   12109       15348 :                     $$ = (Node *) n;
   12110             :                 }
   12111             :             | CREATE OptTemp TABLE create_as_target AS
   12112             :                 EXECUTE name execute_param_clause opt_with_data
   12113             :                 {
   12114          76 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   12115          76 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12116             : 
   12117          76 :                     n->name = $7;
   12118          76 :                     n->params = $8;
   12119          76 :                     ctas->query = (Node *) n;
   12120          76 :                     ctas->into = $4;
   12121          76 :                     ctas->objtype = OBJECT_TABLE;
   12122          76 :                     ctas->is_select_into = false;
   12123          76 :                     ctas->if_not_exists = false;
   12124             :                     /* cram additional flags into the IntoClause */
   12125          76 :                     $4->rel->relpersistence = $2;
   12126          76 :                     $4->skipData = !($9);
   12127          76 :                     $$ = (Node *) ctas;
   12128             :                 }
   12129             :             | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS
   12130             :                 EXECUTE name execute_param_clause opt_with_data
   12131             :                 {
   12132          12 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   12133          12 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12134             : 
   12135          12 :                     n->name = $10;
   12136          12 :                     n->params = $11;
   12137          12 :                     ctas->query = (Node *) n;
   12138          12 :                     ctas->into = $7;
   12139          12 :                     ctas->objtype = OBJECT_TABLE;
   12140          12 :                     ctas->is_select_into = false;
   12141          12 :                     ctas->if_not_exists = true;
   12142             :                     /* cram additional flags into the IntoClause */
   12143          12 :                     $7->rel->relpersistence = $2;
   12144          12 :                     $7->skipData = !($12);
   12145          12 :                     $$ = (Node *) ctas;
   12146             :                 }
   12147             :         ;
   12148             : 
   12149       14294 : execute_param_clause: '(' expr_list ')'             { $$ = $2; }
   12150        1142 :                     | /* EMPTY */                   { $$ = NIL; }
   12151             :                     ;
   12152             : 
   12153             : /*****************************************************************************
   12154             :  *
   12155             :  *      QUERY:
   12156             :  *              DEALLOCATE [PREPARE] <plan_name>
   12157             :  *
   12158             :  *****************************************************************************/
   12159             : 
   12160             : DeallocateStmt: DEALLOCATE name
   12161             :                     {
   12162        3972 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12163             : 
   12164        3972 :                         n->name = $2;
   12165        3972 :                         n->isall = false;
   12166        3972 :                         n->location = @2;
   12167        3972 :                         $$ = (Node *) n;
   12168             :                     }
   12169             :                 | DEALLOCATE PREPARE name
   12170             :                     {
   12171          20 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12172             : 
   12173          20 :                         n->name = $3;
   12174          20 :                         n->isall = false;
   12175          20 :                         n->location = @3;
   12176          20 :                         $$ = (Node *) n;
   12177             :                     }
   12178             :                 | DEALLOCATE ALL
   12179             :                     {
   12180          54 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12181             : 
   12182          54 :                         n->name = NULL;
   12183          54 :                         n->isall = true;
   12184          54 :                         n->location = -1;
   12185          54 :                         $$ = (Node *) n;
   12186             :                     }
   12187             :                 | DEALLOCATE PREPARE ALL
   12188             :                     {
   12189           2 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12190             : 
   12191           2 :                         n->name = NULL;
   12192           2 :                         n->isall = true;
   12193           2 :                         n->location = -1;
   12194           2 :                         $$ = (Node *) n;
   12195             :                     }
   12196             :         ;
   12197             : 
   12198             : /*****************************************************************************
   12199             :  *
   12200             :  *      QUERY:
   12201             :  *              INSERT STATEMENTS
   12202             :  *
   12203             :  *****************************************************************************/
   12204             : 
   12205             : InsertStmt:
   12206             :             opt_with_clause INSERT INTO insert_target insert_rest
   12207             :             opt_on_conflict returning_clause
   12208             :                 {
   12209       73218 :                     $5->relation = $4;
   12210       73218 :                     $5->onConflictClause = $6;
   12211       73218 :                     $5->returningClause = $7;
   12212       73218 :                     $5->withClause = $1;
   12213       73218 :                     $5->stmt_location = @$;
   12214       73218 :                     $$ = (Node *) $5;
   12215             :                 }
   12216             :         ;
   12217             : 
   12218             : /*
   12219             :  * Can't easily make AS optional here, because VALUES in insert_rest would
   12220             :  * have a shift/reduce conflict with VALUES as an optional alias.  We could
   12221             :  * easily allow unreserved_keywords as optional aliases, but that'd be an odd
   12222             :  * divergence from other places.  So just require AS for now.
   12223             :  */
   12224             : insert_target:
   12225             :             qualified_name
   12226             :                 {
   12227       73092 :                     $$ = $1;
   12228             :                 }
   12229             :             | qualified_name AS ColId
   12230             :                 {
   12231         132 :                     $1->alias = makeAlias($3, NIL);
   12232         132 :                     $$ = $1;
   12233             :                 }
   12234             :         ;
   12235             : 
   12236             : insert_rest:
   12237             :             SelectStmt
   12238             :                 {
   12239       48358 :                     $$ = makeNode(InsertStmt);
   12240       48358 :                     $$->cols = NIL;
   12241       48358 :                     $$->selectStmt = $1;
   12242             :                 }
   12243             :             | OVERRIDING override_kind VALUE_P SelectStmt
   12244             :                 {
   12245          96 :                     $$ = makeNode(InsertStmt);
   12246          96 :                     $$->cols = NIL;
   12247          96 :                     $$->override = $2;
   12248          96 :                     $$->selectStmt = $4;
   12249             :                 }
   12250             :             | '(' insert_column_list ')' SelectStmt
   12251             :                 {
   12252       13956 :                     $$ = makeNode(InsertStmt);
   12253       13956 :                     $$->cols = $2;
   12254       13956 :                     $$->selectStmt = $4;
   12255             :                 }
   12256             :             | '(' insert_column_list ')' OVERRIDING override_kind VALUE_P SelectStmt
   12257             :                 {
   12258           0 :                     $$ = makeNode(InsertStmt);
   12259           0 :                     $$->cols = $2;
   12260           0 :                     $$->override = $5;
   12261           0 :                     $$->selectStmt = $7;
   12262             :                 }
   12263             :             | DEFAULT VALUES
   12264             :                 {
   12265       10814 :                     $$ = makeNode(InsertStmt);
   12266       10814 :                     $$->cols = NIL;
   12267       10814 :                     $$->selectStmt = NULL;
   12268             :                 }
   12269             :         ;
   12270             : 
   12271             : override_kind:
   12272          66 :             USER        { $$ = OVERRIDING_USER_VALUE; }
   12273          60 :             | SYSTEM_P  { $$ = OVERRIDING_SYSTEM_VALUE; }
   12274             :         ;
   12275             : 
   12276             : insert_column_list:
   12277             :             insert_column_item
   12278       14254 :                     { $$ = list_make1($1); }
   12279             :             | insert_column_list ',' insert_column_item
   12280       15686 :                     { $$ = lappend($1, $3); }
   12281             :         ;
   12282             : 
   12283             : insert_column_item:
   12284             :             ColId opt_indirection
   12285             :                 {
   12286       29940 :                     $$ = makeNode(ResTarget);
   12287       29940 :                     $$->name = $1;
   12288       29940 :                     $$->indirection = check_indirection($2, yyscanner);
   12289       29940 :                     $$->val = NULL;
   12290       29940 :                     $$->location = @1;
   12291             :                 }
   12292             :         ;
   12293             : 
   12294             : opt_on_conflict:
   12295             :             ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
   12296             :                 {
   12297        1306 :                     $$ = makeNode(OnConflictClause);
   12298        1306 :                     $$->action = ONCONFLICT_UPDATE;
   12299        1306 :                     $$->infer = $3;
   12300        1306 :                     $$->targetList = $7;
   12301        1306 :                     $$->whereClause = $8;
   12302        1306 :                     $$->location = @1;
   12303             :                 }
   12304             :             |
   12305             :             ON CONFLICT opt_conf_expr DO NOTHING
   12306             :                 {
   12307         550 :                     $$ = makeNode(OnConflictClause);
   12308         550 :                     $$->action = ONCONFLICT_NOTHING;
   12309         550 :                     $$->infer = $3;
   12310         550 :                     $$->targetList = NIL;
   12311         550 :                     $$->whereClause = NULL;
   12312         550 :                     $$->location = @1;
   12313             :                 }
   12314             :             | /*EMPTY*/
   12315             :                 {
   12316       71368 :                     $$ = NULL;
   12317             :                 }
   12318             :         ;
   12319             : 
   12320             : opt_conf_expr:
   12321             :             '(' index_params ')' where_clause
   12322             :                 {
   12323        1430 :                     $$ = makeNode(InferClause);
   12324        1430 :                     $$->indexElems = $2;
   12325        1430 :                     $$->whereClause = $4;
   12326        1430 :                     $$->conname = NULL;
   12327        1430 :                     $$->location = @1;
   12328             :                 }
   12329             :             |
   12330             :             ON CONSTRAINT name
   12331             :                 {
   12332         192 :                     $$ = makeNode(InferClause);
   12333         192 :                     $$->indexElems = NIL;
   12334         192 :                     $$->whereClause = NULL;
   12335         192 :                     $$->conname = $3;
   12336         192 :                     $$->location = @1;
   12337             :                 }
   12338             :             | /*EMPTY*/
   12339             :                 {
   12340         234 :                     $$ = NULL;
   12341             :                 }
   12342             :         ;
   12343             : 
   12344             : returning_clause:
   12345             :             RETURNING returning_with_clause target_list
   12346             :                 {
   12347        3016 :                     ReturningClause *n = makeNode(ReturningClause);
   12348             : 
   12349        3016 :                     n->options = $2;
   12350        3016 :                     n->exprs = $3;
   12351        3016 :                     $$ = n;
   12352             :                 }
   12353             :             | /* EMPTY */
   12354             :                 {
   12355       90260 :                     $$ = NULL;
   12356             :                 }
   12357             :         ;
   12358             : 
   12359             : returning_with_clause:
   12360          72 :             WITH '(' returning_options ')'      { $$ = $3; }
   12361        2944 :             | /* EMPTY */                       { $$ = NIL; }
   12362             :         ;
   12363             : 
   12364             : returning_options:
   12365          72 :             returning_option                            { $$ = list_make1($1); }
   12366          54 :             | returning_options ',' returning_option    { $$ = lappend($1, $3); }
   12367             :         ;
   12368             : 
   12369             : returning_option:
   12370             :             returning_option_kind AS ColId
   12371             :                 {
   12372         126 :                     ReturningOption *n = makeNode(ReturningOption);
   12373             : 
   12374         126 :                     n->option = $1;
   12375         126 :                     n->value = $3;
   12376         126 :                     n->location = @1;
   12377         126 :                     $$ = (Node *) n;
   12378             :                 }
   12379             :         ;
   12380             : 
   12381             : returning_option_kind:
   12382          54 :             OLD         { $$ = RETURNING_OPTION_OLD; }
   12383          72 :             | NEW       { $$ = RETURNING_OPTION_NEW; }
   12384             :         ;
   12385             : 
   12386             : 
   12387             : /*****************************************************************************
   12388             :  *
   12389             :  *      QUERY:
   12390             :  *              DELETE STATEMENTS
   12391             :  *
   12392             :  *****************************************************************************/
   12393             : 
   12394             : DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
   12395             :             using_clause where_or_current_clause returning_clause
   12396             :                 {
   12397        4644 :                     DeleteStmt *n = makeNode(DeleteStmt);
   12398             : 
   12399        4644 :                     n->relation = $4;
   12400        4644 :                     n->usingClause = $5;
   12401        4644 :                     n->whereClause = $6;
   12402        4644 :                     n->returningClause = $7;
   12403        4644 :                     n->withClause = $1;
   12404        4644 :                     n->stmt_location = @$;
   12405        4644 :                     $$ = (Node *) n;
   12406             :                 }
   12407             :         ;
   12408             : 
   12409             : using_clause:
   12410         108 :                 USING from_list                     { $$ = $2; }
   12411        4536 :             | /*EMPTY*/                             { $$ = NIL; }
   12412             :         ;
   12413             : 
   12414             : 
   12415             : /*****************************************************************************
   12416             :  *
   12417             :  *      QUERY:
   12418             :  *              LOCK TABLE
   12419             :  *
   12420             :  *****************************************************************************/
   12421             : 
   12422             : LockStmt:   LOCK_P opt_table relation_expr_list opt_lock opt_nowait
   12423             :                 {
   12424        1088 :                     LockStmt   *n = makeNode(LockStmt);
   12425             : 
   12426        1088 :                     n->relations = $3;
   12427        1088 :                     n->mode = $4;
   12428        1088 :                     n->nowait = $5;
   12429        1088 :                     $$ = (Node *) n;
   12430             :                 }
   12431             :         ;
   12432             : 
   12433         992 : opt_lock:   IN_P lock_type MODE             { $$ = $2; }
   12434          96 :             | /*EMPTY*/                     { $$ = AccessExclusiveLock; }
   12435             :         ;
   12436             : 
   12437         502 : lock_type:  ACCESS SHARE                    { $$ = AccessShareLock; }
   12438          14 :             | ROW SHARE                     { $$ = RowShareLock; }
   12439          88 :             | ROW EXCLUSIVE                 { $$ = RowExclusiveLock; }
   12440          66 :             | SHARE UPDATE EXCLUSIVE        { $$ = ShareUpdateExclusiveLock; }
   12441          80 :             | SHARE                         { $$ = ShareLock; }
   12442          14 :             | SHARE ROW EXCLUSIVE           { $$ = ShareRowExclusiveLock; }
   12443         102 :             | EXCLUSIVE                     { $$ = ExclusiveLock; }
   12444         126 :             | ACCESS EXCLUSIVE              { $$ = AccessExclusiveLock; }
   12445             :         ;
   12446             : 
   12447         286 : opt_nowait: NOWAIT                          { $$ = true; }
   12448         832 :             | /*EMPTY*/                     { $$ = false; }
   12449             :         ;
   12450             : 
   12451             : opt_nowait_or_skip:
   12452          50 :             NOWAIT                          { $$ = LockWaitError; }
   12453         190 :             | SKIP LOCKED                   { $$ = LockWaitSkip; }
   12454        5040 :             | /*EMPTY*/                     { $$ = LockWaitBlock; }
   12455             :         ;
   12456             : 
   12457             : 
   12458             : /*****************************************************************************
   12459             :  *
   12460             :  *      QUERY:
   12461             :  *              UpdateStmt (UPDATE)
   12462             :  *
   12463             :  *****************************************************************************/
   12464             : 
   12465             : UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
   12466             :             SET set_clause_list
   12467             :             from_clause
   12468             :             where_or_current_clause
   12469             :             returning_clause
   12470             :                 {
   12471       13434 :                     UpdateStmt *n = makeNode(UpdateStmt);
   12472             : 
   12473       13434 :                     n->relation = $3;
   12474       13434 :                     n->targetList = $5;
   12475       13434 :                     n->fromClause = $6;
   12476       13434 :                     n->whereClause = $7;
   12477       13434 :                     n->returningClause = $8;
   12478       13434 :                     n->withClause = $1;
   12479       13434 :                     n->stmt_location = @$;
   12480       13434 :                     $$ = (Node *) n;
   12481             :                 }
   12482             :         ;
   12483             : 
   12484             : set_clause_list:
   12485       16284 :             set_clause                          { $$ = $1; }
   12486        3788 :             | set_clause_list ',' set_clause    { $$ = list_concat($1,$3); }
   12487             :         ;
   12488             : 
   12489             : set_clause:
   12490             :             set_target '=' a_expr
   12491             :                 {
   12492       19888 :                     $1->val = (Node *) $3;
   12493       19888 :                     $$ = list_make1($1);
   12494             :                 }
   12495             :             | '(' set_target_list ')' '=' a_expr
   12496             :                 {
   12497         184 :                     int         ncolumns = list_length($2);
   12498         184 :                     int         i = 1;
   12499             :                     ListCell   *col_cell;
   12500             : 
   12501             :                     /* Create a MultiAssignRef source for each target */
   12502         568 :                     foreach(col_cell, $2)
   12503             :                     {
   12504         384 :                         ResTarget  *res_col = (ResTarget *) lfirst(col_cell);
   12505         384 :                         MultiAssignRef *r = makeNode(MultiAssignRef);
   12506             : 
   12507         384 :                         r->source = (Node *) $5;
   12508         384 :                         r->colno = i;
   12509         384 :                         r->ncolumns = ncolumns;
   12510         384 :                         res_col->val = (Node *) r;
   12511         384 :                         i++;
   12512             :                     }
   12513             : 
   12514         184 :                     $$ = $2;
   12515             :                 }
   12516             :         ;
   12517             : 
   12518             : set_target:
   12519             :             ColId opt_indirection
   12520             :                 {
   12521       20278 :                     $$ = makeNode(ResTarget);
   12522       20278 :                     $$->name = $1;
   12523       20278 :                     $$->indirection = check_indirection($2, yyscanner);
   12524       20278 :                     $$->val = NULL;  /* upper production sets this */
   12525       20278 :                     $$->location = @1;
   12526             :                 }
   12527             :         ;
   12528             : 
   12529             : set_target_list:
   12530         190 :             set_target                              { $$ = list_make1($1); }
   12531         200 :             | set_target_list ',' set_target        { $$ = lappend($1,$3); }
   12532             :         ;
   12533             : 
   12534             : 
   12535             : /*****************************************************************************
   12536             :  *
   12537             :  *      QUERY:
   12538             :  *              MERGE
   12539             :  *
   12540             :  *****************************************************************************/
   12541             : 
   12542             : MergeStmt:
   12543             :             opt_with_clause MERGE INTO relation_expr_opt_alias
   12544             :             USING table_ref
   12545             :             ON a_expr
   12546             :             merge_when_list
   12547             :             returning_clause
   12548             :                 {
   12549        1980 :                     MergeStmt  *m = makeNode(MergeStmt);
   12550             : 
   12551        1980 :                     m->withClause = $1;
   12552        1980 :                     m->relation = $4;
   12553        1980 :                     m->sourceRelation = $6;
   12554        1980 :                     m->joinCondition = $8;
   12555        1980 :                     m->mergeWhenClauses = $9;
   12556        1980 :                     m->returningClause = $10;
   12557        1980 :                     m->stmt_location = @$;
   12558             : 
   12559        1980 :                     $$ = (Node *) m;
   12560             :                 }
   12561             :         ;
   12562             : 
   12563             : merge_when_list:
   12564        1980 :             merge_when_clause                       { $$ = list_make1($1); }
   12565        1152 :             | merge_when_list merge_when_clause     { $$ = lappend($1,$2); }
   12566             :         ;
   12567             : 
   12568             : /*
   12569             :  * A WHEN clause may be WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, or WHEN NOT
   12570             :  * MATCHED [BY TARGET]. The first two cases match target tuples, and support
   12571             :  * UPDATE/DELETE/DO NOTHING actions. The third case does not match target
   12572             :  * tuples, and only supports INSERT/DO NOTHING actions.
   12573             :  */
   12574             : merge_when_clause:
   12575             :             merge_when_tgt_matched opt_merge_when_condition THEN merge_update
   12576             :                 {
   12577        1544 :                     $4->matchKind = $1;
   12578        1544 :                     $4->condition = $2;
   12579             : 
   12580        1544 :                     $$ = (Node *) $4;
   12581             :                 }
   12582             :             | merge_when_tgt_matched opt_merge_when_condition THEN merge_delete
   12583             :                 {
   12584         482 :                     $4->matchKind = $1;
   12585         482 :                     $4->condition = $2;
   12586             : 
   12587         482 :                     $$ = (Node *) $4;
   12588             :                 }
   12589             :             | merge_when_tgt_not_matched opt_merge_when_condition THEN merge_insert
   12590             :                 {
   12591        1028 :                     $4->matchKind = $1;
   12592        1028 :                     $4->condition = $2;
   12593             : 
   12594        1028 :                     $$ = (Node *) $4;
   12595             :                 }
   12596             :             | merge_when_tgt_matched opt_merge_when_condition THEN DO NOTHING
   12597             :                 {
   12598          58 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12599             : 
   12600          58 :                     m->matchKind = $1;
   12601          58 :                     m->commandType = CMD_NOTHING;
   12602          58 :                     m->condition = $2;
   12603             : 
   12604          58 :                     $$ = (Node *) m;
   12605             :                 }
   12606             :             | merge_when_tgt_not_matched opt_merge_when_condition THEN DO NOTHING
   12607             :                 {
   12608          20 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12609             : 
   12610          20 :                     m->matchKind = $1;
   12611          20 :                     m->commandType = CMD_NOTHING;
   12612          20 :                     m->condition = $2;
   12613             : 
   12614          20 :                     $$ = (Node *) m;
   12615             :                 }
   12616             :         ;
   12617             : 
   12618             : merge_when_tgt_matched:
   12619        1922 :             WHEN MATCHED                    { $$ = MERGE_WHEN_MATCHED; }
   12620         180 :             | WHEN NOT MATCHED BY SOURCE    { $$ = MERGE_WHEN_NOT_MATCHED_BY_SOURCE; }
   12621             :         ;
   12622             : 
   12623             : merge_when_tgt_not_matched:
   12624        1054 :             WHEN NOT MATCHED                { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
   12625          18 :             | WHEN NOT MATCHED BY TARGET    { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
   12626             :         ;
   12627             : 
   12628             : opt_merge_when_condition:
   12629         808 :             AND a_expr              { $$ = $2; }
   12630        2366 :             |                       { $$ = NULL; }
   12631             :         ;
   12632             : 
   12633             : merge_update:
   12634             :             UPDATE SET set_clause_list
   12635             :                 {
   12636        1544 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12637        1544 :                     n->commandType = CMD_UPDATE;
   12638        1544 :                     n->override = OVERRIDING_NOT_SET;
   12639        1544 :                     n->targetList = $3;
   12640        1544 :                     n->values = NIL;
   12641             : 
   12642        1544 :                     $$ = n;
   12643             :                 }
   12644             :         ;
   12645             : 
   12646             : merge_delete:
   12647             :             DELETE_P
   12648             :                 {
   12649         482 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12650         482 :                     n->commandType = CMD_DELETE;
   12651         482 :                     n->override = OVERRIDING_NOT_SET;
   12652         482 :                     n->targetList = NIL;
   12653         482 :                     n->values = NIL;
   12654             : 
   12655         482 :                     $$ = n;
   12656             :                 }
   12657             :         ;
   12658             : 
   12659             : merge_insert:
   12660             :             INSERT merge_values_clause
   12661             :                 {
   12662         694 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12663         694 :                     n->commandType = CMD_INSERT;
   12664         694 :                     n->override = OVERRIDING_NOT_SET;
   12665         694 :                     n->targetList = NIL;
   12666         694 :                     n->values = $2;
   12667         694 :                     $$ = n;
   12668             :                 }
   12669             :             | INSERT OVERRIDING override_kind VALUE_P merge_values_clause
   12670             :                 {
   12671           0 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12672           0 :                     n->commandType = CMD_INSERT;
   12673           0 :                     n->override = $3;
   12674           0 :                     n->targetList = NIL;
   12675           0 :                     n->values = $5;
   12676           0 :                     $$ = n;
   12677             :                 }
   12678             :             | INSERT '(' insert_column_list ')' merge_values_clause
   12679             :                 {
   12680         268 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12681         268 :                     n->commandType = CMD_INSERT;
   12682         268 :                     n->override = OVERRIDING_NOT_SET;
   12683         268 :                     n->targetList = $3;
   12684         268 :                     n->values = $5;
   12685         268 :                     $$ = n;
   12686             :                 }
   12687             :             | INSERT '(' insert_column_list ')' OVERRIDING override_kind VALUE_P merge_values_clause
   12688             :                 {
   12689          30 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12690          30 :                     n->commandType = CMD_INSERT;
   12691          30 :                     n->override = $6;
   12692          30 :                     n->targetList = $3;
   12693          30 :                     n->values = $8;
   12694          30 :                     $$ = n;
   12695             :                 }
   12696             :             | INSERT DEFAULT VALUES
   12697             :                 {
   12698          36 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12699          36 :                     n->commandType = CMD_INSERT;
   12700          36 :                     n->override = OVERRIDING_NOT_SET;
   12701          36 :                     n->targetList = NIL;
   12702          36 :                     n->values = NIL;
   12703          36 :                     $$ = n;
   12704             :                 }
   12705             :         ;
   12706             : 
   12707             : merge_values_clause:
   12708             :             VALUES '(' expr_list ')'
   12709             :                 {
   12710         992 :                     $$ = $3;
   12711             :                 }
   12712             :         ;
   12713             : 
   12714             : /*****************************************************************************
   12715             :  *
   12716             :  *      QUERY:
   12717             :  *              CURSOR STATEMENTS
   12718             :  *
   12719             :  *****************************************************************************/
   12720             : DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
   12721             :                 {
   12722        2810 :                     DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
   12723             : 
   12724        2810 :                     n->portalname = $2;
   12725             :                     /* currently we always set FAST_PLAN option */
   12726        2810 :                     n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
   12727        2810 :                     n->query = $7;
   12728        2810 :                     $$ = (Node *) n;
   12729             :                 }
   12730             :         ;
   12731             : 
   12732       11006 : cursor_name:    name                        { $$ = $1; }
   12733             :         ;
   12734             : 
   12735        2810 : cursor_options: /*EMPTY*/                   { $$ = 0; }
   12736          24 :             | cursor_options NO SCROLL      { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
   12737         240 :             | cursor_options SCROLL         { $$ = $1 | CURSOR_OPT_SCROLL; }
   12738          14 :             | cursor_options BINARY         { $$ = $1 | CURSOR_OPT_BINARY; }
   12739           0 :             | cursor_options ASENSITIVE     { $$ = $1 | CURSOR_OPT_ASENSITIVE; }
   12740           6 :             | cursor_options INSENSITIVE    { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
   12741             :         ;
   12742             : 
   12743        2712 : opt_hold: /* EMPTY */                       { $$ = 0; }
   12744          92 :             | WITH HOLD                     { $$ = CURSOR_OPT_HOLD; }
   12745           6 :             | WITHOUT HOLD                  { $$ = 0; }
   12746             :         ;
   12747             : 
   12748             : /*****************************************************************************
   12749             :  *
   12750             :  *      QUERY:
   12751             :  *              SELECT STATEMENTS
   12752             :  *
   12753             :  *****************************************************************************/
   12754             : 
   12755             : /* A complete SELECT statement looks like this.
   12756             :  *
   12757             :  * The rule returns either a single SelectStmt node or a tree of them,
   12758             :  * representing a set-operation tree.
   12759             :  *
   12760             :  * There is an ambiguity when a sub-SELECT is within an a_expr and there
   12761             :  * are excess parentheses: do the parentheses belong to the sub-SELECT or
   12762             :  * to the surrounding a_expr?  We don't really care, but bison wants to know.
   12763             :  * To resolve the ambiguity, we are careful to define the grammar so that
   12764             :  * the decision is staved off as long as possible: as long as we can keep
   12765             :  * absorbing parentheses into the sub-SELECT, we will do so, and only when
   12766             :  * it's no longer possible to do that will we decide that parens belong to
   12767             :  * the expression.  For example, in "SELECT (((SELECT 2)) + 3)" the extra
   12768             :  * parentheses are treated as part of the sub-select.  The necessity of doing
   12769             :  * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)".    Had we
   12770             :  * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
   12771             :  * SELECT viewpoint when we see the UNION.
   12772             :  *
   12773             :  * This approach is implemented by defining a nonterminal select_with_parens,
   12774             :  * which represents a SELECT with at least one outer layer of parentheses,
   12775             :  * and being careful to use select_with_parens, never '(' SelectStmt ')',
   12776             :  * in the expression grammar.  We will then have shift-reduce conflicts
   12777             :  * which we can resolve in favor of always treating '(' <select> ')' as
   12778             :  * a select_with_parens.  To resolve the conflicts, the productions that
   12779             :  * conflict with the select_with_parens productions are manually given
   12780             :  * precedences lower than the precedence of ')', thereby ensuring that we
   12781             :  * shift ')' (and then reduce to select_with_parens) rather than trying to
   12782             :  * reduce the inner <select> nonterminal to something else.  We use UMINUS
   12783             :  * precedence for this, which is a fairly arbitrary choice.
   12784             :  *
   12785             :  * To be able to define select_with_parens itself without ambiguity, we need
   12786             :  * a nonterminal select_no_parens that represents a SELECT structure with no
   12787             :  * outermost parentheses.  This is a little bit tedious, but it works.
   12788             :  *
   12789             :  * In non-expression contexts, we use SelectStmt which can represent a SELECT
   12790             :  * with or without outer parentheses.
   12791             :  */
   12792             : 
   12793             : SelectStmt: select_no_parens            %prec UMINUS
   12794             :             | select_with_parens        %prec UMINUS
   12795             :         ;
   12796             : 
   12797             : select_with_parens:
   12798             :             '(' select_no_parens ')'
   12799             :                 {
   12800       56298 :                     SelectStmt *n = (SelectStmt *) $2;
   12801             : 
   12802             :                     /*
   12803             :                      * As SelectStmt's location starts at the SELECT keyword,
   12804             :                      * we need to track the length of the SelectStmt within
   12805             :                      * parentheses to be able to extract the relevant part
   12806             :                      * of the query.  Without this, the RawStmt's length would
   12807             :                      * be used and would include the closing parenthesis.
   12808             :                      */
   12809       56298 :                     n->stmt_len = @3 - @2;
   12810       56298 :                     $$ = $2;
   12811             :                 }
   12812         150 :             | '(' select_with_parens ')'            { $$ = $2; }
   12813             :         ;
   12814             : 
   12815             : /*
   12816             :  * This rule parses the equivalent of the standard's <query expression>.
   12817             :  * The duplicative productions are annoying, but hard to get rid of without
   12818             :  * creating shift/reduce conflicts.
   12819             :  *
   12820             :  *  The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
   12821             :  *  In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
   12822             :  *  We now support both orderings, but prefer LIMIT/OFFSET before the locking
   12823             :  * clause.
   12824             :  *  2002-08-28 bjm
   12825             :  */
   12826             : select_no_parens:
   12827      409824 :             simple_select                       { $$ = $1; }
   12828             :             | select_clause sort_clause
   12829             :                 {
   12830       60478 :                     insertSelectOptions((SelectStmt *) $1, $2, NIL,
   12831             :                                         NULL, NULL,
   12832             :                                         yyscanner);
   12833       60478 :                     $$ = $1;
   12834             :                 }
   12835             :             | select_clause opt_sort_clause for_locking_clause opt_select_limit
   12836             :                 {
   12837        4836 :                     insertSelectOptions((SelectStmt *) $1, $2, $3,
   12838        4836 :                                         $4,
   12839             :                                         NULL,
   12840             :                                         yyscanner);
   12841        4836 :                     $$ = $1;
   12842             :                 }
   12843             :             | select_clause opt_sort_clause select_limit opt_for_locking_clause
   12844             :                 {
   12845        4700 :                     insertSelectOptions((SelectStmt *) $1, $2, $4,
   12846        4700 :                                         $3,
   12847             :                                         NULL,
   12848             :                                         yyscanner);
   12849        4688 :                     $$ = $1;
   12850             :                 }
   12851             :             | with_clause select_clause
   12852             :                 {
   12853        1952 :                     insertSelectOptions((SelectStmt *) $2, NULL, NIL,
   12854             :                                         NULL,
   12855        1952 :                                         $1,
   12856             :                                         yyscanner);
   12857        1952 :                     $$ = $2;
   12858             :                 }
   12859             :             | with_clause select_clause sort_clause
   12860             :                 {
   12861         480 :                     insertSelectOptions((SelectStmt *) $2, $3, NIL,
   12862             :                                         NULL,
   12863         480 :                                         $1,
   12864             :                                         yyscanner);
   12865         480 :                     $$ = $2;
   12866             :                 }
   12867             :             | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
   12868             :                 {
   12869           6 :                     insertSelectOptions((SelectStmt *) $2, $3, $4,
   12870           6 :                                         $5,
   12871           6 :                                         $1,
   12872             :                                         yyscanner);
   12873           6 :                     $$ = $2;
   12874             :                 }
   12875             :             | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
   12876             :                 {
   12877          64 :                     insertSelectOptions((SelectStmt *) $2, $3, $5,
   12878          64 :                                         $4,
   12879          64 :                                         $1,
   12880             :                                         yyscanner);
   12881          64 :                     $$ = $2;
   12882             :                 }
   12883             :         ;
   12884             : 
   12885             : select_clause:
   12886      101926 :             simple_select                           { $$ = $1; }
   12887         578 :             | select_with_parens                    { $$ = $1; }
   12888             :         ;
   12889             : 
   12890             : /*
   12891             :  * This rule parses SELECT statements that can appear within set operations,
   12892             :  * including UNION, INTERSECT and EXCEPT.  '(' and ')' can be used to specify
   12893             :  * the ordering of the set operations.  Without '(' and ')' we want the
   12894             :  * operations to be ordered per the precedence specs at the head of this file.
   12895             :  *
   12896             :  * As with select_no_parens, simple_select cannot have outer parentheses,
   12897             :  * but can have parenthesized subclauses.
   12898             :  *
   12899             :  * It might appear that we could fold the first two alternatives into one
   12900             :  * by using opt_distinct_clause.  However, that causes a shift/reduce conflict
   12901             :  * against INSERT ... SELECT ... ON CONFLICT.  We avoid the ambiguity by
   12902             :  * requiring SELECT DISTINCT [ON] to be followed by a non-empty target_list.
   12903             :  *
   12904             :  * Note that sort clauses cannot be included at this level --- SQL requires
   12905             :  *      SELECT foo UNION SELECT bar ORDER BY baz
   12906             :  * to be parsed as
   12907             :  *      (SELECT foo UNION SELECT bar) ORDER BY baz
   12908             :  * not
   12909             :  *      SELECT foo UNION (SELECT bar ORDER BY baz)
   12910             :  * Likewise for WITH, FOR UPDATE and LIMIT.  Therefore, those clauses are
   12911             :  * described as part of the select_no_parens production, not simple_select.
   12912             :  * This does not limit functionality, because you can reintroduce these
   12913             :  * clauses inside parentheses.
   12914             :  *
   12915             :  * NOTE: only the leftmost component SelectStmt should have INTO.
   12916             :  * However, this is not checked by the grammar; parse analysis must check it.
   12917             :  */
   12918             : simple_select:
   12919             :             SELECT opt_all_clause opt_target_list
   12920             :             into_clause from_clause where_clause
   12921             :             group_clause having_clause window_clause
   12922             :                 {
   12923      431948 :                     SelectStmt *n = makeNode(SelectStmt);
   12924             : 
   12925      431948 :                     n->targetList = $3;
   12926      431948 :                     n->intoClause = $4;
   12927      431948 :                     n->fromClause = $5;
   12928      431948 :                     n->whereClause = $6;
   12929      431948 :                     n->groupClause = ($7)->list;
   12930      431948 :                     n->groupDistinct = ($7)->distinct;
   12931      431948 :                     n->havingClause = $8;
   12932      431948 :                     n->windowClause = $9;
   12933      431948 :                     n->stmt_location = @1;
   12934      431948 :                     $$ = (Node *) n;
   12935             :                 }
   12936             :             | SELECT distinct_clause target_list
   12937             :             into_clause from_clause where_clause
   12938             :             group_clause having_clause window_clause
   12939             :                 {
   12940        3352 :                     SelectStmt *n = makeNode(SelectStmt);
   12941             : 
   12942        3352 :                     n->distinctClause = $2;
   12943        3352 :                     n->targetList = $3;
   12944        3352 :                     n->intoClause = $4;
   12945        3352 :                     n->fromClause = $5;
   12946        3352 :                     n->whereClause = $6;
   12947        3352 :                     n->groupClause = ($7)->list;
   12948        3352 :                     n->groupDistinct = ($7)->distinct;
   12949        3352 :                     n->havingClause = $8;
   12950        3352 :                     n->windowClause = $9;
   12951        3352 :                     n->stmt_location = @1;
   12952        3352 :                     $$ = (Node *) n;
   12953             :                 }
   12954       61208 :             | values_clause                         { $$ = $1; }
   12955             :             | TABLE relation_expr
   12956             :                 {
   12957             :                     /* same as SELECT * FROM relation_expr */
   12958         254 :                     ColumnRef  *cr = makeNode(ColumnRef);
   12959         254 :                     ResTarget  *rt = makeNode(ResTarget);
   12960         254 :                     SelectStmt *n = makeNode(SelectStmt);
   12961             : 
   12962         254 :                     cr->fields = list_make1(makeNode(A_Star));
   12963         254 :                     cr->location = -1;
   12964             : 
   12965         254 :                     rt->name = NULL;
   12966         254 :                     rt->indirection = NIL;
   12967         254 :                     rt->val = (Node *) cr;
   12968         254 :                     rt->location = -1;
   12969             : 
   12970         254 :                     n->targetList = list_make1(rt);
   12971         254 :                     n->fromClause = list_make1($2);
   12972         254 :                     n->stmt_location = @1;
   12973         254 :                     $$ = (Node *) n;
   12974             :                 }
   12975             :             | select_clause UNION set_quantifier select_clause
   12976             :                 {
   12977       14236 :                     $$ = makeSetOp(SETOP_UNION, $3 == SET_QUANTIFIER_ALL, $1, $4, @1);
   12978             :                 }
   12979             :             | select_clause INTERSECT set_quantifier select_clause
   12980             :                 {
   12981         258 :                     $$ = makeSetOp(SETOP_INTERSECT, $3 == SET_QUANTIFIER_ALL, $1, $4, @1);
   12982             :                 }
   12983             :             | select_clause EXCEPT set_quantifier select_clause
   12984             :                 {
   12985         494 :                     $$ = makeSetOp(SETOP_EXCEPT, $3 == SET_QUANTIFIER_ALL, $1, $4, @1);
   12986             :                 }
   12987             :         ;
   12988             : 
   12989             : /*
   12990             :  * SQL standard WITH clause looks like:
   12991             :  *
   12992             :  * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
   12993             :  *      AS (query) [ SEARCH or CYCLE clause ]
   12994             :  *
   12995             :  * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
   12996             :  */
   12997             : with_clause:
   12998             :         WITH cte_list
   12999             :             {
   13000        1774 :                 $$ = makeNode(WithClause);
   13001        1774 :                 $$->ctes = $2;
   13002        1774 :                 $$->recursive = false;
   13003        1774 :                 $$->location = @1;
   13004             :             }
   13005             :         | WITH_LA cte_list
   13006             :             {
   13007           6 :                 $$ = makeNode(WithClause);
   13008           6 :                 $$->ctes = $2;
   13009           6 :                 $$->recursive = false;
   13010           6 :                 $$->location = @1;
   13011             :             }
   13012             :         | WITH RECURSIVE cte_list
   13013             :             {
   13014        1132 :                 $$ = makeNode(WithClause);
   13015        1132 :                 $$->ctes = $3;
   13016        1132 :                 $$->recursive = true;
   13017        1132 :                 $$->location = @1;
   13018             :             }
   13019             :         ;
   13020             : 
   13021             : cte_list:
   13022        2912 :         common_table_expr                       { $$ = list_make1($1); }
   13023        1048 :         | cte_list ',' common_table_expr        { $$ = lappend($1, $3); }
   13024             :         ;
   13025             : 
   13026             : common_table_expr:  name opt_name_list AS opt_materialized '(' PreparableStmt ')' opt_search_clause opt_cycle_clause
   13027             :             {
   13028        3960 :                 CommonTableExpr *n = makeNode(CommonTableExpr);
   13029             : 
   13030        3960 :                 n->ctename = $1;
   13031        3960 :                 n->aliascolnames = $2;
   13032        3960 :                 n->ctematerialized = $4;
   13033        3960 :                 n->ctequery = $6;
   13034        3960 :                 n->search_clause = castNode(CTESearchClause, $8);
   13035        3960 :                 n->cycle_clause = castNode(CTECycleClause, $9);
   13036        3960 :                 n->location = @1;
   13037        3960 :                 $$ = (Node *) n;
   13038             :             }
   13039             :         ;
   13040             : 
   13041             : opt_materialized:
   13042         178 :         MATERIALIZED                            { $$ = CTEMaterializeAlways; }
   13043          48 :         | NOT MATERIALIZED                      { $$ = CTEMaterializeNever; }
   13044        3734 :         | /*EMPTY*/                             { $$ = CTEMaterializeDefault; }
   13045             :         ;
   13046             : 
   13047             : opt_search_clause:
   13048             :         SEARCH DEPTH FIRST_P BY columnList SET ColId
   13049             :             {
   13050          90 :                 CTESearchClause *n = makeNode(CTESearchClause);
   13051             : 
   13052          90 :                 n->search_col_list = $5;
   13053          90 :                 n->search_breadth_first = false;
   13054          90 :                 n->search_seq_column = $7;
   13055          90 :                 n->location = @1;
   13056          90 :                 $$ = (Node *) n;
   13057             :             }
   13058             :         | SEARCH BREADTH FIRST_P BY columnList SET ColId
   13059             :             {
   13060          36 :                 CTESearchClause *n = makeNode(CTESearchClause);
   13061             : 
   13062          36 :                 n->search_col_list = $5;
   13063          36 :                 n->search_breadth_first = true;
   13064          36 :                 n->search_seq_column = $7;
   13065          36 :                 n->location = @1;
   13066          36 :                 $$ = (Node *) n;
   13067             :             }
   13068             :         | /*EMPTY*/
   13069             :             {
   13070        3834 :                 $$ = NULL;
   13071             :             }
   13072             :         ;
   13073             : 
   13074             : opt_cycle_clause:
   13075             :         CYCLE columnList SET ColId TO AexprConst DEFAULT AexprConst USING ColId
   13076             :             {
   13077          66 :                 CTECycleClause *n = makeNode(CTECycleClause);
   13078             : 
   13079          66 :                 n->cycle_col_list = $2;
   13080          66 :                 n->cycle_mark_column = $4;
   13081          66 :                 n->cycle_mark_value = $6;
   13082          66 :                 n->cycle_mark_default = $8;
   13083          66 :                 n->cycle_path_column = $10;
   13084          66 :                 n->location = @1;
   13085          66 :                 $$ = (Node *) n;
   13086             :             }
   13087             :         | CYCLE columnList SET ColId USING ColId
   13088             :             {
   13089          60 :                 CTECycleClause *n = makeNode(CTECycleClause);
   13090             : 
   13091          60 :                 n->cycle_col_list = $2;
   13092          60 :                 n->cycle_mark_column = $4;
   13093          60 :                 n->cycle_mark_value = makeBoolAConst(true, -1);
   13094          60 :                 n->cycle_mark_default = makeBoolAConst(false, -1);
   13095          60 :                 n->cycle_path_column = $6;
   13096          60 :                 n->location = @1;
   13097          60 :                 $$ = (Node *) n;
   13098             :             }
   13099             :         | /*EMPTY*/
   13100             :             {
   13101        3834 :                 $$ = NULL;
   13102             :             }
   13103             :         ;
   13104             : 
   13105             : opt_with_clause:
   13106         410 :         with_clause                             { $$ = $1; }
   13107       92982 :         | /*EMPTY*/                             { $$ = NULL; }
   13108             :         ;
   13109             : 
   13110             : into_clause:
   13111             :             INTO OptTempTableName
   13112             :                 {
   13113         132 :                     $$ = makeNode(IntoClause);
   13114         132 :                     $$->rel = $2;
   13115         132 :                     $$->colNames = NIL;
   13116         132 :                     $$->options = NIL;
   13117         132 :                     $$->onCommit = ONCOMMIT_NOOP;
   13118         132 :                     $$->tableSpaceName = NULL;
   13119         132 :                     $$->viewQuery = NULL;
   13120         132 :                     $$->skipData = false;
   13121             :                 }
   13122             :             | /*EMPTY*/
   13123      435192 :                 { $$ = NULL; }
   13124             :         ;
   13125             : 
   13126             : /*
   13127             :  * Redundancy here is needed to avoid shift/reduce conflicts,
   13128             :  * since TEMP is not a reserved word.  See also OptTemp.
   13129             :  */
   13130             : OptTempTableName:
   13131             :             TEMPORARY opt_table qualified_name
   13132             :                 {
   13133           0 :                     $$ = $3;
   13134           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13135             :                 }
   13136             :             | TEMP opt_table qualified_name
   13137             :                 {
   13138           6 :                     $$ = $3;
   13139           6 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13140             :                 }
   13141             :             | LOCAL TEMPORARY opt_table qualified_name
   13142             :                 {
   13143           0 :                     $$ = $4;
   13144           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13145             :                 }
   13146             :             | LOCAL TEMP opt_table qualified_name
   13147             :                 {
   13148           0 :                     $$ = $4;
   13149           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13150             :                 }
   13151             :             | GLOBAL TEMPORARY opt_table qualified_name
   13152             :                 {
   13153           0 :                     ereport(WARNING,
   13154             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   13155             :                              parser_errposition(@1)));
   13156           0 :                     $$ = $4;
   13157           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13158             :                 }
   13159             :             | GLOBAL TEMP opt_table qualified_name
   13160             :                 {
   13161           0 :                     ereport(WARNING,
   13162             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   13163             :                              parser_errposition(@1)));
   13164           0 :                     $$ = $4;
   13165           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13166             :                 }
   13167             :             | UNLOGGED opt_table qualified_name
   13168             :                 {
   13169           0 :                     $$ = $3;
   13170           0 :                     $$->relpersistence = RELPERSISTENCE_UNLOGGED;
   13171             :                 }
   13172             :             | TABLE qualified_name
   13173             :                 {
   13174          30 :                     $$ = $2;
   13175          30 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   13176             :                 }
   13177             :             | qualified_name
   13178             :                 {
   13179          96 :                     $$ = $1;
   13180          96 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   13181             :                 }
   13182             :         ;
   13183             : 
   13184             : opt_table:  TABLE
   13185             :             | /*EMPTY*/
   13186             :         ;
   13187             : 
   13188             : set_quantifier:
   13189        6958 :             ALL                                     { $$ = SET_QUANTIFIER_ALL; }
   13190          32 :             | DISTINCT                              { $$ = SET_QUANTIFIER_DISTINCT; }
   13191       12560 :             | /*EMPTY*/                             { $$ = SET_QUANTIFIER_DEFAULT; }
   13192             :         ;
   13193             : 
   13194             : /* We use (NIL) as a placeholder to indicate that all target expressions
   13195             :  * should be placed in the DISTINCT list during parsetree analysis.
   13196             :  */
   13197             : distinct_clause:
   13198        3106 :             DISTINCT                                { $$ = list_make1(NIL); }
   13199         252 :             | DISTINCT ON '(' expr_list ')'         { $$ = $4; }
   13200             :         ;
   13201             : 
   13202             : opt_all_clause:
   13203             :             ALL
   13204             :             | /*EMPTY*/
   13205             :         ;
   13206             : 
   13207             : opt_distinct_clause:
   13208           0 :             distinct_clause                         { $$ = $1; }
   13209       39296 :             | opt_all_clause                        { $$ = NIL; }
   13210             :         ;
   13211             : 
   13212             : opt_sort_clause:
   13213        6676 :             sort_clause                             { $$ = $1; }
   13214      342480 :             | /*EMPTY*/                             { $$ = NIL; }
   13215             :         ;
   13216             : 
   13217             : sort_clause:
   13218       67982 :             ORDER BY sortby_list                    { $$ = $3; }
   13219             :         ;
   13220             : 
   13221             : sortby_list:
   13222       68000 :             sortby                                  { $$ = list_make1($1); }
   13223       26014 :             | sortby_list ',' sortby                { $$ = lappend($1, $3); }
   13224             :         ;
   13225             : 
   13226             : sortby:     a_expr USING qual_all_Op opt_nulls_order
   13227             :                 {
   13228         220 :                     $$ = makeNode(SortBy);
   13229         220 :                     $$->node = $1;
   13230         220 :                     $$->sortby_dir = SORTBY_USING;
   13231         220 :                     $$->sortby_nulls = $4;
   13232         220 :                     $$->useOp = $3;
   13233         220 :                     $$->location = @3;
   13234             :                 }
   13235             :             | a_expr opt_asc_desc opt_nulls_order
   13236             :                 {
   13237       93794 :                     $$ = makeNode(SortBy);
   13238       93794 :                     $$->node = $1;
   13239       93794 :                     $$->sortby_dir = $2;
   13240       93794 :                     $$->sortby_nulls = $3;
   13241       93794 :                     $$->useOp = NIL;
   13242       93794 :                     $$->location = -1;       /* no operator */
   13243             :                 }
   13244             :         ;
   13245             : 
   13246             : 
   13247             : select_limit:
   13248             :             limit_clause offset_clause
   13249             :                 {
   13250         168 :                     $$ = $1;
   13251         168 :                     ($$)->limitOffset = $2;
   13252         168 :                     ($$)->offsetLoc = @2;
   13253             :                 }
   13254             :             | offset_clause limit_clause
   13255             :                 {
   13256         214 :                     $$ = $2;
   13257         214 :                     ($$)->limitOffset = $1;
   13258         214 :                     ($$)->offsetLoc = @1;
   13259             :                 }
   13260             :             | limit_clause
   13261             :                 {
   13262        4198 :                     $$ = $1;
   13263             :                 }
   13264             :             | offset_clause
   13265             :                 {
   13266         374 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13267             : 
   13268         374 :                     n->limitOffset = $1;
   13269         374 :                     n->limitCount = NULL;
   13270         374 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13271         374 :                     n->offsetLoc = @1;
   13272         374 :                     n->countLoc = -1;
   13273         374 :                     n->optionLoc = -1;
   13274         374 :                     $$ = n;
   13275             :                 }
   13276             :         ;
   13277             : 
   13278             : opt_select_limit:
   13279         190 :             select_limit                        { $$ = $1; }
   13280       43948 :             | /* EMPTY */                       { $$ = NULL; }
   13281             :         ;
   13282             : 
   13283             : limit_clause:
   13284             :             LIMIT select_limit_value
   13285             :                 {
   13286        4496 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13287             : 
   13288        4496 :                     n->limitOffset = NULL;
   13289        4496 :                     n->limitCount = $2;
   13290        4496 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13291        4496 :                     n->offsetLoc = -1;
   13292        4496 :                     n->countLoc = @1;
   13293        4496 :                     n->optionLoc = -1;
   13294        4496 :                     $$ = n;
   13295             :                 }
   13296             :             | LIMIT select_limit_value ',' select_offset_value
   13297             :                 {
   13298             :                     /* Disabled because it was too confusing, bjm 2002-02-18 */
   13299           0 :                     ereport(ERROR,
   13300             :                             (errcode(ERRCODE_SYNTAX_ERROR),
   13301             :                              errmsg("LIMIT #,# syntax is not supported"),
   13302             :                              errhint("Use separate LIMIT and OFFSET clauses."),
   13303             :                              parser_errposition(@1)));
   13304             :                 }
   13305             :             /* SQL:2008 syntax */
   13306             :             /* to avoid shift/reduce conflicts, handle the optional value with
   13307             :              * a separate production rather than an opt_ expression.  The fact
   13308             :              * that ONLY is fully reserved means that this way, we defer any
   13309             :              * decision about what rule reduces ROW or ROWS to the point where
   13310             :              * we can see the ONLY token in the lookahead slot.
   13311             :              */
   13312             :             | FETCH first_or_next select_fetch_first_value row_or_rows ONLY
   13313             :                 {
   13314          20 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13315             : 
   13316          20 :                     n->limitOffset = NULL;
   13317          20 :                     n->limitCount = $3;
   13318          20 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13319          20 :                     n->offsetLoc = -1;
   13320          20 :                     n->countLoc = @1;
   13321          20 :                     n->optionLoc = -1;
   13322          20 :                     $$ = n;
   13323             :                 }
   13324             :             | FETCH first_or_next select_fetch_first_value row_or_rows WITH TIES
   13325             :                 {
   13326          58 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13327             : 
   13328          58 :                     n->limitOffset = NULL;
   13329          58 :                     n->limitCount = $3;
   13330          58 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13331          58 :                     n->offsetLoc = -1;
   13332          58 :                     n->countLoc = @1;
   13333          58 :                     n->optionLoc = @5;
   13334          58 :                     $$ = n;
   13335             :                 }
   13336             :             | FETCH first_or_next row_or_rows ONLY
   13337             :                 {
   13338           0 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13339             : 
   13340           0 :                     n->limitOffset = NULL;
   13341           0 :                     n->limitCount = makeIntConst(1, -1);
   13342           0 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13343           0 :                     n->offsetLoc = -1;
   13344           0 :                     n->countLoc = @1;
   13345           0 :                     n->optionLoc = -1;
   13346           0 :                     $$ = n;
   13347             :                 }
   13348             :             | FETCH first_or_next row_or_rows WITH TIES
   13349             :                 {
   13350           6 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13351             : 
   13352           6 :                     n->limitOffset = NULL;
   13353           6 :                     n->limitCount = makeIntConst(1, -1);
   13354           6 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13355           6 :                     n->offsetLoc = -1;
   13356           6 :                     n->countLoc = @1;
   13357           6 :                     n->optionLoc = @4;
   13358           6 :                     $$ = n;
   13359             :                 }
   13360             :         ;
   13361             : 
   13362             : offset_clause:
   13363             :             OFFSET select_offset_value
   13364         756 :                 { $$ = $2; }
   13365             :             /* SQL:2008 syntax */
   13366             :             | OFFSET select_fetch_first_value row_or_rows
   13367           0 :                 { $$ = $2; }
   13368             :         ;
   13369             : 
   13370             : select_limit_value:
   13371        4494 :             a_expr                                  { $$ = $1; }
   13372             :             | ALL
   13373             :                 {
   13374             :                     /* LIMIT ALL is represented as a NULL constant */
   13375           2 :                     $$ = makeNullAConst(@1);
   13376             :                 }
   13377             :         ;
   13378             : 
   13379             : select_offset_value:
   13380         756 :             a_expr                                  { $$ = $1; }
   13381             :         ;
   13382             : 
   13383             : /*
   13384             :  * Allowing full expressions without parentheses causes various parsing
   13385             :  * problems with the trailing ROW/ROWS key words.  SQL spec only calls for
   13386             :  * <simple value specification>, which is either a literal or a parameter (but
   13387             :  * an <SQL parameter reference> could be an identifier, bringing up conflicts
   13388             :  * with ROW/ROWS). We solve this by leveraging the presence of ONLY (see above)
   13389             :  * to determine whether the expression is missing rather than trying to make it
   13390             :  * optional in this rule.
   13391             :  *
   13392             :  * c_expr covers almost all the spec-required cases (and more), but it doesn't
   13393             :  * cover signed numeric literals, which are allowed by the spec. So we include
   13394             :  * those here explicitly. We need FCONST as well as ICONST because values that
   13395             :  * don't fit in the platform's "long", but do fit in bigint, should still be
   13396             :  * accepted here. (This is possible in 64-bit Windows as well as all 32-bit
   13397             :  * builds.)
   13398             :  */
   13399             : select_fetch_first_value:
   13400          78 :             c_expr                                  { $$ = $1; }
   13401             :             | '+' I_or_F_const
   13402           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   13403             :             | '-' I_or_F_const
   13404           0 :                 { $$ = doNegate($2, @1); }
   13405             :         ;
   13406             : 
   13407             : I_or_F_const:
   13408           0 :             Iconst                                  { $$ = makeIntConst($1,@1); }
   13409           0 :             | FCONST                                { $$ = makeFloatConst($1,@1); }
   13410             :         ;
   13411             : 
   13412             : /* noise words */
   13413          32 : row_or_rows: ROW                                    { $$ = 0; }
   13414          52 :             | ROWS                                  { $$ = 0; }
   13415             :         ;
   13416             : 
   13417          84 : first_or_next: FIRST_P                              { $$ = 0; }
   13418           0 :             | NEXT                                  { $$ = 0; }
   13419             :         ;
   13420             : 
   13421             : 
   13422             : /*
   13423             :  * This syntax for group_clause tries to follow the spec quite closely.
   13424             :  * However, the spec allows only column references, not expressions,
   13425             :  * which introduces an ambiguity between implicit row constructors
   13426             :  * (a,b) and lists of column references.
   13427             :  *
   13428             :  * We handle this by using the a_expr production for what the spec calls
   13429             :  * <ordinary grouping set>, which in the spec represents either one column
   13430             :  * reference or a parenthesized list of column references. Then, we check the
   13431             :  * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
   13432             :  * grab and use the list, discarding the node. (this is done in parse analysis,
   13433             :  * not here)
   13434             :  *
   13435             :  * (we abuse the row_format field of RowExpr to distinguish implicit and
   13436             :  * explicit row constructors; it's debatable if anyone sanely wants to use them
   13437             :  * in a group clause, but if they have a reason to, we make it possible.)
   13438             :  *
   13439             :  * Each item in the group_clause list is either an expression tree or a
   13440             :  * GroupingSet node of some type.
   13441             :  */
   13442             : group_clause:
   13443             :             GROUP_P BY set_quantifier group_by_list
   13444             :                 {
   13445        4550 :                     GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
   13446             : 
   13447        4550 :                     n->distinct = $3 == SET_QUANTIFIER_DISTINCT;
   13448        4550 :                     n->list = $4;
   13449        4550 :                     $$ = n;
   13450             :                 }
   13451             :             | /*EMPTY*/
   13452             :                 {
   13453      470046 :                     GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
   13454             : 
   13455      470046 :                     n->distinct = false;
   13456      470046 :                     n->list = NIL;
   13457      470046 :                     $$ = n;
   13458             :                 }
   13459             :         ;
   13460             : 
   13461             : group_by_list:
   13462        5124 :             group_by_item                           { $$ = list_make1($1); }
   13463        2926 :             | group_by_list ',' group_by_item       { $$ = lappend($1,$3); }
   13464             :         ;
   13465             : 
   13466             : group_by_item:
   13467        6784 :             a_expr                                  { $$ = $1; }
   13468         222 :             | empty_grouping_set                    { $$ = $1; }
   13469         184 :             | cube_clause                           { $$ = $1; }
   13470         286 :             | rollup_clause                         { $$ = $1; }
   13471         574 :             | grouping_sets_clause                  { $$ = $1; }
   13472             :         ;
   13473             : 
   13474             : empty_grouping_set:
   13475             :             '(' ')'
   13476             :                 {
   13477         222 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, @1);
   13478             :                 }
   13479             :         ;
   13480             : 
   13481             : /*
   13482             :  * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
   13483             :  * so that they shift in these rules rather than reducing the conflicting
   13484             :  * unreserved_keyword rule.
   13485             :  */
   13486             : 
   13487             : rollup_clause:
   13488             :             ROLLUP '(' expr_list ')'
   13489             :                 {
   13490         286 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_ROLLUP, $3, @1);
   13491             :                 }
   13492             :         ;
   13493             : 
   13494             : cube_clause:
   13495             :             CUBE '(' expr_list ')'
   13496             :                 {
   13497         184 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_CUBE, $3, @1);
   13498             :                 }
   13499             :         ;
   13500             : 
   13501             : grouping_sets_clause:
   13502             :             GROUPING SETS '(' group_by_list ')'
   13503             :                 {
   13504         574 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_SETS, $4, @1);
   13505             :                 }
   13506             :         ;
   13507             : 
   13508             : having_clause:
   13509         836 :             HAVING a_expr                           { $$ = $2; }
   13510      473760 :             | /*EMPTY*/                             { $$ = NULL; }
   13511             :         ;
   13512             : 
   13513             : for_locking_clause:
   13514        5182 :             for_locking_items                       { $$ = $1; }
   13515           0 :             | FOR READ ONLY                         { $$ = NIL; }
   13516             :         ;
   13517             : 
   13518             : opt_for_locking_clause:
   13519         340 :             for_locking_clause                      { $$ = $1; }
   13520       43720 :             | /* EMPTY */                           { $$ = NIL; }
   13521             :         ;
   13522             : 
   13523             : for_locking_items:
   13524        5182 :             for_locking_item                        { $$ = list_make1($1); }
   13525          98 :             | for_locking_items for_locking_item    { $$ = lappend($1, $2); }
   13526             :         ;
   13527             : 
   13528             : for_locking_item:
   13529             :             for_locking_strength locked_rels_list opt_nowait_or_skip
   13530             :                 {
   13531        5280 :                     LockingClause *n = makeNode(LockingClause);
   13532             : 
   13533        5280 :                     n->lockedRels = $2;
   13534        5280 :                     n->strength = $1;
   13535        5280 :                     n->waitPolicy = $3;
   13536        5280 :                     $$ = (Node *) n;
   13537             :                 }
   13538             :         ;
   13539             : 
   13540             : for_locking_strength:
   13541        1510 :             FOR UPDATE                          { $$ = LCS_FORUPDATE; }
   13542          76 :             | FOR NO KEY UPDATE                 { $$ = LCS_FORNOKEYUPDATE; }
   13543         214 :             | FOR SHARE                         { $$ = LCS_FORSHARE; }
   13544        3480 :             | FOR KEY SHARE                     { $$ = LCS_FORKEYSHARE; }
   13545             :         ;
   13546             : 
   13547             : locked_rels_list:
   13548        3500 :             OF qualified_name_list                  { $$ = $2; }
   13549        1780 :             | /* EMPTY */                           { $$ = NIL; }
   13550             :         ;
   13551             : 
   13552             : 
   13553             : /*
   13554             :  * We should allow ROW '(' expr_list ')' too, but that seems to require
   13555             :  * making VALUES a fully reserved word, which will probably break more apps
   13556             :  * than allowing the noise-word is worth.
   13557             :  */
   13558             : values_clause:
   13559             :             VALUES '(' expr_list ')'
   13560             :                 {
   13561       61208 :                     SelectStmt *n = makeNode(SelectStmt);
   13562             : 
   13563       61208 :                     n->stmt_location = @1;
   13564       61208 :                     n->valuesLists = list_make1($3);
   13565       61208 :                     $$ = (Node *) n;
   13566             :                 }
   13567             :             | values_clause ',' '(' expr_list ')'
   13568             :                 {
   13569       24770 :                     SelectStmt *n = (SelectStmt *) $1;
   13570             : 
   13571       24770 :                     n->valuesLists = lappend(n->valuesLists, $4);
   13572       24770 :                     $$ = (Node *) n;
   13573             :                 }
   13574             :         ;
   13575             : 
   13576             : 
   13577             : /*****************************************************************************
   13578             :  *
   13579             :  *  clauses common to all Optimizable Stmts:
   13580             :  *      from_clause     - allow list of both JOIN expressions and table names
   13581             :  *      where_clause    - qualifications for joins or restrictions
   13582             :  *
   13583             :  *****************************************************************************/
   13584             : 
   13585             : from_clause:
   13586      285562 :             FROM from_list                          { $$ = $2; }
   13587      202468 :             | /*EMPTY*/                             { $$ = NIL; }
   13588             :         ;
   13589             : 
   13590             : from_list:
   13591      286266 :             table_ref                               { $$ = list_make1($1); }
   13592       57208 :             | from_list ',' table_ref               { $$ = lappend($1, $3); }
   13593             :         ;
   13594             : 
   13595             : /*
   13596             :  * table_ref is where an alias clause can be attached.
   13597             :  */
   13598             : table_ref:  relation_expr opt_alias_clause
   13599             :                 {
   13600      361790 :                     $1->alias = $2;
   13601      361790 :                     $$ = (Node *) $1;
   13602             :                 }
   13603             :             | relation_expr opt_alias_clause tablesample_clause
   13604             :                 {
   13605         254 :                     RangeTableSample *n = (RangeTableSample *) $3;
   13606             : 
   13607         254 :                     $1->alias = $2;
   13608             :                     /* relation_expr goes inside the RangeTableSample node */
   13609         254 :                     n->relation = (Node *) $1;
   13610         254 :                     $$ = (Node *) n;
   13611             :                 }
   13612             :             | func_table func_alias_clause
   13613             :                 {
   13614       42492 :                     RangeFunction *n = (RangeFunction *) $1;
   13615             : 
   13616       42492 :                     n->alias = linitial($2);
   13617       42492 :                     n->coldeflist = lsecond($2);
   13618       42492 :                     $$ = (Node *) n;
   13619             :                 }
   13620             :             | LATERAL_P func_table func_alias_clause
   13621             :                 {
   13622        1078 :                     RangeFunction *n = (RangeFunction *) $2;
   13623             : 
   13624        1078 :                     n->lateral = true;
   13625        1078 :                     n->alias = linitial($3);
   13626        1078 :                     n->coldeflist = lsecond($3);
   13627        1078 :                     $$ = (Node *) n;
   13628             :                 }
   13629             :             | xmltable opt_alias_clause
   13630             :                 {
   13631          80 :                     RangeTableFunc *n = (RangeTableFunc *) $1;
   13632             : 
   13633          80 :                     n->alias = $2;
   13634          80 :                     $$ = (Node *) n;
   13635             :                 }
   13636             :             | LATERAL_P xmltable opt_alias_clause
   13637             :                 {
   13638         140 :                     RangeTableFunc *n = (RangeTableFunc *) $2;
   13639             : 
   13640         140 :                     n->lateral = true;
   13641         140 :                     n->alias = $3;
   13642         140 :                     $$ = (Node *) n;
   13643             :                 }
   13644             :             | select_with_parens opt_alias_clause
   13645             :                 {
   13646       13176 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13647             : 
   13648       13176 :                     n->lateral = false;
   13649       13176 :                     n->subquery = $1;
   13650       13176 :                     n->alias = $2;
   13651       13176 :                     $$ = (Node *) n;
   13652             :                 }
   13653             :             | LATERAL_P select_with_parens opt_alias_clause
   13654             :                 {
   13655        1560 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13656             : 
   13657        1560 :                     n->lateral = true;
   13658        1560 :                     n->subquery = $2;
   13659        1560 :                     n->alias = $3;
   13660        1560 :                     $$ = (Node *) n;
   13661             :                 }
   13662             :             | joined_table
   13663             :                 {
   13664       75424 :                     $$ = (Node *) $1;
   13665             :                 }
   13666             :             | '(' joined_table ')' alias_clause
   13667             :                 {
   13668         174 :                     $2->alias = $4;
   13669         174 :                     $$ = (Node *) $2;
   13670             :                 }
   13671             :             | json_table opt_alias_clause
   13672             :                 {
   13673         524 :                     JsonTable  *jt = castNode(JsonTable, $1);
   13674             : 
   13675         524 :                     jt->alias = $2;
   13676         524 :                     $$ = (Node *) jt;
   13677             :                 }
   13678             :             | LATERAL_P json_table opt_alias_clause
   13679             :                 {
   13680           0 :                     JsonTable  *jt = castNode(JsonTable, $2);
   13681             : 
   13682           0 :                     jt->alias = $3;
   13683           0 :                     jt->lateral = true;
   13684           0 :                     $$ = (Node *) jt;
   13685             :                 }
   13686             :         ;
   13687             : 
   13688             : 
   13689             : /*
   13690             :  * It may seem silly to separate joined_table from table_ref, but there is
   13691             :  * method in SQL's madness: if you don't do it this way you get reduce-
   13692             :  * reduce conflicts, because it's not clear to the parser generator whether
   13693             :  * to expect alias_clause after ')' or not.  For the same reason we must
   13694             :  * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
   13695             :  * join_type to expand to empty; if we try it, the parser generator can't
   13696             :  * figure out when to reduce an empty join_type right after table_ref.
   13697             :  *
   13698             :  * Note that a CROSS JOIN is the same as an unqualified
   13699             :  * INNER JOIN, and an INNER JOIN/ON has the same shape
   13700             :  * but a qualification expression to limit membership.
   13701             :  * A NATURAL JOIN implicitly matches column names between
   13702             :  * tables and the shape is determined by which columns are
   13703             :  * in common. We'll collect columns during the later transformations.
   13704             :  */
   13705             : 
   13706             : joined_table:
   13707             :             '(' joined_table ')'
   13708             :                 {
   13709        3682 :                     $$ = $2;
   13710             :                 }
   13711             :             | table_ref CROSS JOIN table_ref
   13712             :                 {
   13713             :                     /* CROSS JOIN is same as unqualified inner join */
   13714         322 :                     JoinExpr   *n = makeNode(JoinExpr);
   13715             : 
   13716         322 :                     n->jointype = JOIN_INNER;
   13717         322 :                     n->isNatural = false;
   13718         322 :                     n->larg = $1;
   13719         322 :                     n->rarg = $4;
   13720         322 :                     n->usingClause = NIL;
   13721         322 :                     n->join_using_alias = NULL;
   13722         322 :                     n->quals = NULL;
   13723         322 :                     $$ = n;
   13724             :                 }
   13725             :             | table_ref join_type JOIN table_ref join_qual
   13726             :                 {
   13727       43312 :                     JoinExpr   *n = makeNode(JoinExpr);
   13728             : 
   13729       43312 :                     n->jointype = $2;
   13730       43312 :                     n->isNatural = false;
   13731       43312 :                     n->larg = $1;
   13732       43312 :                     n->rarg = $4;
   13733       43312 :                     if ($5 != NULL && IsA($5, List))
   13734             :                     {
   13735             :                          /* USING clause */
   13736         486 :                         n->usingClause = linitial_node(List, castNode(List, $5));
   13737         486 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $5));
   13738             :                     }
   13739             :                     else
   13740             :                     {
   13741             :                         /* ON clause */
   13742       42826 :                         n->quals = $5;
   13743             :                     }
   13744       43312 :                     $$ = n;
   13745             :                 }
   13746             :             | table_ref JOIN table_ref join_qual
   13747             :                 {
   13748             :                     /* letting join_type reduce to empty doesn't work */
   13749       31706 :                     JoinExpr   *n = makeNode(JoinExpr);
   13750             : 
   13751       31706 :                     n->jointype = JOIN_INNER;
   13752       31706 :                     n->isNatural = false;
   13753       31706 :                     n->larg = $1;
   13754       31706 :                     n->rarg = $3;
   13755       31706 :                     if ($4 != NULL && IsA($4, List))
   13756             :                     {
   13757             :                         /* USING clause */
   13758         708 :                         n->usingClause = linitial_node(List, castNode(List, $4));
   13759         708 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $4));
   13760             :                     }
   13761             :                     else
   13762             :                     {
   13763             :                         /* ON clause */
   13764       30998 :                         n->quals = $4;
   13765             :                     }
   13766       31706 :                     $$ = n;
   13767             :                 }
   13768             :             | table_ref NATURAL join_type JOIN table_ref
   13769             :                 {
   13770          78 :                     JoinExpr   *n = makeNode(JoinExpr);
   13771             : 
   13772          78 :                     n->jointype = $3;
   13773          78 :                     n->isNatural = true;
   13774          78 :                     n->larg = $1;
   13775          78 :                     n->rarg = $5;
   13776          78 :                     n->usingClause = NIL; /* figure out which columns later... */
   13777          78 :                     n->join_using_alias = NULL;
   13778          78 :                     n->quals = NULL; /* fill later */
   13779          78 :                     $$ = n;
   13780             :                 }
   13781             :             | table_ref NATURAL JOIN table_ref
   13782             :                 {
   13783             :                     /* letting join_type reduce to empty doesn't work */
   13784         180 :                     JoinExpr   *n = makeNode(JoinExpr);
   13785             : 
   13786         180 :                     n->jointype = JOIN_INNER;
   13787         180 :                     n->isNatural = true;
   13788         180 :                     n->larg = $1;
   13789         180 :                     n->rarg = $4;
   13790         180 :                     n->usingClause = NIL; /* figure out which columns later... */
   13791         180 :                     n->join_using_alias = NULL;
   13792         180 :                     n->quals = NULL; /* fill later */
   13793         180 :                     $$ = n;
   13794             :                 }
   13795             :         ;
   13796             : 
   13797             : alias_clause:
   13798             :             AS ColId '(' name_list ')'
   13799             :                 {
   13800        5736 :                     $$ = makeNode(Alias);
   13801        5736 :                     $$->aliasname = $2;
   13802        5736 :                     $$->colnames = $4;
   13803             :                 }
   13804             :             | AS ColId
   13805             :                 {
   13806       10166 :                     $$ = makeNode(Alias);
   13807       10166 :                     $$->aliasname = $2;
   13808             :                 }
   13809             :             | ColId '(' name_list ')'
   13810             :                 {
   13811        5654 :                     $$ = makeNode(Alias);
   13812        5654 :                     $$->aliasname = $1;
   13813        5654 :                     $$->colnames = $3;
   13814             :                 }
   13815             :             | ColId
   13816             :                 {
   13817      242338 :                     $$ = makeNode(Alias);
   13818      242338 :                     $$->aliasname = $1;
   13819             :                 }
   13820             :         ;
   13821             : 
   13822      234350 : opt_alias_clause: alias_clause                      { $$ = $1; }
   13823      143174 :             | /*EMPTY*/                             { $$ = NULL; }
   13824             :         ;
   13825             : 
   13826             : /*
   13827             :  * The alias clause after JOIN ... USING only accepts the AS ColId spelling,
   13828             :  * per SQL standard.  (The grammar could parse the other variants, but they
   13829             :  * don't seem to be useful, and it might lead to parser problems in the
   13830             :  * future.)
   13831             :  */
   13832             : opt_alias_clause_for_join_using:
   13833             :             AS ColId
   13834             :                 {
   13835          84 :                     $$ = makeNode(Alias);
   13836          84 :                     $$->aliasname = $2;
   13837             :                     /* the column name list will be inserted later */
   13838             :                 }
   13839        1110 :             | /*EMPTY*/                             { $$ = NULL; }
   13840             :         ;
   13841             : 
   13842             : /*
   13843             :  * func_alias_clause can include both an Alias and a coldeflist, so we make it
   13844             :  * return a 2-element list that gets disassembled by calling production.
   13845             :  */
   13846             : func_alias_clause:
   13847             :             alias_clause
   13848             :                 {
   13849       29370 :                     $$ = list_make2($1, NIL);
   13850             :                 }
   13851             :             | AS '(' TableFuncElementList ')'
   13852             :                 {
   13853         114 :                     $$ = list_make2(NULL, $3);
   13854             :                 }
   13855             :             | AS ColId '(' TableFuncElementList ')'
   13856             :                 {
   13857         586 :                     Alias      *a = makeNode(Alias);
   13858             : 
   13859         586 :                     a->aliasname = $2;
   13860         586 :                     $$ = list_make2(a, $4);
   13861             :                 }
   13862             :             | ColId '(' TableFuncElementList ')'
   13863             :                 {
   13864          50 :                     Alias      *a = makeNode(Alias);
   13865             : 
   13866          50 :                     a->aliasname = $1;
   13867          50 :                     $$ = list_make2(a, $3);
   13868             :                 }
   13869             :             | /*EMPTY*/
   13870             :                 {
   13871       13450 :                     $$ = list_make2(NULL, NIL);
   13872             :                 }
   13873             :         ;
   13874             : 
   13875        1018 : join_type:  FULL opt_outer                          { $$ = JOIN_FULL; }
   13876       38150 :             | LEFT opt_outer                        { $$ = JOIN_LEFT; }
   13877         356 :             | RIGHT opt_outer                       { $$ = JOIN_RIGHT; }
   13878        3866 :             | INNER_P                               { $$ = JOIN_INNER; }
   13879             :         ;
   13880             : 
   13881             : /* OUTER is just noise... */
   13882             : opt_outer: OUTER_P
   13883             :             | /*EMPTY*/
   13884             :         ;
   13885             : 
   13886             : /* JOIN qualification clauses
   13887             :  * Possibilities are:
   13888             :  *  USING ( column list ) [ AS alias ]
   13889             :  *                        allows only unqualified column names,
   13890             :  *                        which must match between tables.
   13891             :  *  ON expr allows more general qualifications.
   13892             :  *
   13893             :  * We return USING as a two-element List (the first item being a sub-List
   13894             :  * of the common column names, and the second either an Alias item or NULL).
   13895             :  * An ON-expr will not be a List, so it can be told apart that way.
   13896             :  */
   13897             : 
   13898             : join_qual: USING '(' name_list ')' opt_alias_clause_for_join_using
   13899             :                 {
   13900        1194 :                     $$ = (Node *) list_make2($3, $5);
   13901             :                 }
   13902             :             | ON a_expr
   13903             :                 {
   13904       73824 :                     $$ = $2;
   13905             :                 }
   13906             :         ;
   13907             : 
   13908             : 
   13909             : relation_expr:
   13910             :             qualified_name
   13911             :                 {
   13912             :                     /* inheritance query, implicitly */
   13913      434140 :                     $$ = $1;
   13914      434140 :                     $$->inh = true;
   13915      434140 :                     $$->alias = NULL;
   13916             :                 }
   13917             :             | extended_relation_expr
   13918             :                 {
   13919        6898 :                     $$ = $1;
   13920             :                 }
   13921             :         ;
   13922             : 
   13923             : extended_relation_expr:
   13924             :             qualified_name '*'
   13925             :                 {
   13926             :                     /* inheritance query, explicitly */
   13927         204 :                     $$ = $1;
   13928         204 :                     $$->inh = true;
   13929         204 :                     $$->alias = NULL;
   13930             :                 }
   13931             :             | ONLY qualified_name
   13932             :                 {
   13933             :                     /* no inheritance */
   13934        6700 :                     $$ = $2;
   13935        6700 :                     $$->inh = false;
   13936        6700 :                     $$->alias = NULL;
   13937             :                 }
   13938             :             | ONLY '(' qualified_name ')'
   13939             :                 {
   13940             :                     /* no inheritance, SQL99-style syntax */
   13941           0 :                     $$ = $3;
   13942           0 :                     $$->inh = false;
   13943           0 :                     $$->alias = NULL;
   13944             :                 }
   13945             :         ;
   13946             : 
   13947             : 
   13948             : relation_expr_list:
   13949        2740 :             relation_expr                           { $$ = list_make1($1); }
   13950        9810 :             | relation_expr_list ',' relation_expr  { $$ = lappend($1, $3); }
   13951             :         ;
   13952             : 
   13953             : 
   13954             : /*
   13955             :  * Given "UPDATE foo set set ...", we have to decide without looking any
   13956             :  * further ahead whether the first "set" is an alias or the UPDATE's SET
   13957             :  * keyword.  Since "set" is allowed as a column name both interpretations
   13958             :  * are feasible.  We resolve the shift/reduce conflict by giving the first
   13959             :  * relation_expr_opt_alias production a higher precedence than the SET token
   13960             :  * has, causing the parser to prefer to reduce, in effect assuming that the
   13961             :  * SET is not an alias.
   13962             :  */
   13963             : relation_expr_opt_alias: relation_expr                  %prec UMINUS
   13964             :                 {
   13965       17914 :                     $$ = $1;
   13966             :                 }
   13967             :             | relation_expr ColId
   13968             :                 {
   13969        2108 :                     Alias      *alias = makeNode(Alias);
   13970             : 
   13971        2108 :                     alias->aliasname = $2;
   13972        2108 :                     $1->alias = alias;
   13973        2108 :                     $$ = $1;
   13974             :                 }
   13975             :             | relation_expr AS ColId
   13976             :                 {
   13977          90 :                     Alias      *alias = makeNode(Alias);
   13978             : 
   13979          90 :                     alias->aliasname = $3;
   13980          90 :                     $1->alias = alias;
   13981          90 :                     $$ = $1;
   13982             :                 }
   13983             :         ;
   13984             : 
   13985             : /*
   13986             :  * TABLESAMPLE decoration in a FROM item
   13987             :  */
   13988             : tablesample_clause:
   13989             :             TABLESAMPLE func_name '(' expr_list ')' opt_repeatable_clause
   13990             :                 {
   13991         254 :                     RangeTableSample *n = makeNode(RangeTableSample);
   13992             : 
   13993             :                     /* n->relation will be filled in later */
   13994         254 :                     n->method = $2;
   13995         254 :                     n->args = $4;
   13996         254 :                     n->repeatable = $6;
   13997         254 :                     n->location = @2;
   13998         254 :                     $$ = (Node *) n;
   13999             :                 }
   14000             :         ;
   14001             : 
   14002             : opt_repeatable_clause:
   14003         108 :             REPEATABLE '(' a_expr ')'   { $$ = (Node *) $3; }
   14004         146 :             | /*EMPTY*/                 { $$ = NULL; }
   14005             :         ;
   14006             : 
   14007             : /*
   14008             :  * func_table represents a function invocation in a FROM list. It can be
   14009             :  * a plain function call, like "foo(...)", or a ROWS FROM expression with
   14010             :  * one or more function calls, "ROWS FROM (foo(...), bar(...))",
   14011             :  * optionally with WITH ORDINALITY attached.
   14012             :  * In the ROWS FROM syntax, a column definition list can be given for each
   14013             :  * function, for example:
   14014             :  *     ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
   14015             :  *                bar() AS (bar_res_a text, bar_res_b text))
   14016             :  * It's also possible to attach a column definition list to the RangeFunction
   14017             :  * as a whole, but that's handled by the table_ref production.
   14018             :  */
   14019             : func_table: func_expr_windowless opt_ordinality
   14020             :                 {
   14021       43444 :                     RangeFunction *n = makeNode(RangeFunction);
   14022             : 
   14023       43444 :                     n->lateral = false;
   14024       43444 :                     n->ordinality = $2;
   14025       43444 :                     n->is_rowsfrom = false;
   14026       43444 :                     n->functions = list_make1(list_make2($1, NIL));
   14027             :                     /* alias and coldeflist are set by table_ref production */
   14028       43444 :                     $$ = (Node *) n;
   14029             :                 }
   14030             :             | ROWS FROM '(' rowsfrom_list ')' opt_ordinality
   14031             :                 {
   14032         132 :                     RangeFunction *n = makeNode(RangeFunction);
   14033             : 
   14034         132 :                     n->lateral = false;
   14035         132 :                     n->ordinality = $6;
   14036         132 :                     n->is_rowsfrom = true;
   14037         132 :                     n->functions = $4;
   14038             :                     /* alias and coldeflist are set by table_ref production */
   14039         132 :                     $$ = (Node *) n;
   14040             :                 }
   14041             :         ;
   14042             : 
   14043             : rowsfrom_item: func_expr_windowless opt_col_def_list
   14044         318 :                 { $$ = list_make2($1, $2); }
   14045             :         ;
   14046             : 
   14047             : rowsfrom_list:
   14048         132 :             rowsfrom_item                       { $$ = list_make1($1); }
   14049         186 :             | rowsfrom_list ',' rowsfrom_item   { $$ = lappend($1, $3); }
   14050             :         ;
   14051             : 
   14052          54 : opt_col_def_list: AS '(' TableFuncElementList ')'   { $$ = $3; }
   14053         264 :             | /*EMPTY*/                             { $$ = NIL; }
   14054             :         ;
   14055             : 
   14056         784 : opt_ordinality: WITH_LA ORDINALITY                  { $$ = true; }
   14057       42792 :             | /*EMPTY*/                             { $$ = false; }
   14058             :         ;
   14059             : 
   14060             : 
   14061             : where_clause:
   14062      191600 :             WHERE a_expr                            { $$ = $2; }
   14063      302716 :             | /*EMPTY*/                             { $$ = NULL; }
   14064             :         ;
   14065             : 
   14066             : /* variant for UPDATE and DELETE */
   14067             : where_or_current_clause:
   14068       12898 :             WHERE a_expr                            { $$ = $2; }
   14069             :             | WHERE CURRENT_P OF cursor_name
   14070             :                 {
   14071         266 :                     CurrentOfExpr *n = makeNode(CurrentOfExpr);
   14072             : 
   14073             :                     /* cvarno is filled in by parse analysis */
   14074         266 :                     n->cursor_name = $4;
   14075         266 :                     n->cursor_param = 0;
   14076         266 :                     $$ = (Node *) n;
   14077             :                 }
   14078        4914 :             | /*EMPTY*/                             { $$ = NULL; }
   14079             :         ;
   14080             : 
   14081             : 
   14082             : OptTableFuncElementList:
   14083         694 :             TableFuncElementList                { $$ = $1; }
   14084        2792 :             | /*EMPTY*/                         { $$ = NIL; }
   14085             :         ;
   14086             : 
   14087             : TableFuncElementList:
   14088             :             TableFuncElement
   14089             :                 {
   14090        1498 :                     $$ = list_make1($1);
   14091             :                 }
   14092             :             | TableFuncElementList ',' TableFuncElement
   14093             :                 {
   14094        2004 :                     $$ = lappend($1, $3);
   14095             :                 }
   14096             :         ;
   14097             : 
   14098             : TableFuncElement:   ColId Typename opt_collate_clause
   14099             :                 {
   14100        3566 :                     ColumnDef *n = makeNode(ColumnDef);
   14101             : 
   14102        3566 :                     n->colname = $1;
   14103        3566 :                     n->typeName = $2;
   14104        3566 :                     n->inhcount = 0;
   14105        3566 :                     n->is_local = true;
   14106        3566 :                     n->is_not_null = false;
   14107        3566 :                     n->is_from_type = false;
   14108        3566 :                     n->storage = 0;
   14109        3566 :                     n->raw_default = NULL;
   14110        3566 :                     n->cooked_default = NULL;
   14111        3566 :                     n->collClause = (CollateClause *) $3;
   14112        3566 :                     n->collOid = InvalidOid;
   14113        3566 :                     n->constraints = NIL;
   14114        3566 :                     n->location = @1;
   14115        3566 :                     $$ = (Node *) n;
   14116             :                 }
   14117             :         ;
   14118             : 
   14119             : /*
   14120             :  * XMLTABLE
   14121             :  */
   14122             : xmltable:
   14123             :             XMLTABLE '(' c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   14124             :                 {
   14125         200 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   14126             : 
   14127         200 :                     n->rowexpr = $3;
   14128         200 :                     n->docexpr = $4;
   14129         200 :                     n->columns = $6;
   14130         200 :                     n->namespaces = NIL;
   14131         200 :                     n->location = @1;
   14132         200 :                     $$ = (Node *) n;
   14133             :                 }
   14134             :             | XMLTABLE '(' XMLNAMESPACES '(' xml_namespace_list ')' ','
   14135             :                 c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   14136             :                 {
   14137          20 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   14138             : 
   14139          20 :                     n->rowexpr = $8;
   14140          20 :                     n->docexpr = $9;
   14141          20 :                     n->columns = $11;
   14142          20 :                     n->namespaces = $5;
   14143          20 :                     n->location = @1;
   14144          20 :                     $$ = (Node *) n;
   14145             :                 }
   14146             :         ;
   14147             : 
   14148         220 : xmltable_column_list: xmltable_column_el                    { $$ = list_make1($1); }
   14149         530 :             | xmltable_column_list ',' xmltable_column_el   { $$ = lappend($1, $3); }
   14150             :         ;
   14151             : 
   14152             : xmltable_column_el:
   14153             :             ColId Typename
   14154             :                 {
   14155         198 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14156             : 
   14157         198 :                     fc->colname = $1;
   14158         198 :                     fc->for_ordinality = false;
   14159         198 :                     fc->typeName = $2;
   14160         198 :                     fc->is_not_null = false;
   14161         198 :                     fc->colexpr = NULL;
   14162         198 :                     fc->coldefexpr = NULL;
   14163         198 :                     fc->location = @1;
   14164             : 
   14165         198 :                     $$ = (Node *) fc;
   14166             :                 }
   14167             :             | ColId Typename xmltable_column_option_list
   14168             :                 {
   14169         490 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14170             :                     ListCell   *option;
   14171         490 :                     bool        nullability_seen = false;
   14172             : 
   14173         490 :                     fc->colname = $1;
   14174         490 :                     fc->typeName = $2;
   14175         490 :                     fc->for_ordinality = false;
   14176         490 :                     fc->is_not_null = false;
   14177         490 :                     fc->colexpr = NULL;
   14178         490 :                     fc->coldefexpr = NULL;
   14179         490 :                     fc->location = @1;
   14180             : 
   14181        1092 :                     foreach(option, $3)
   14182             :                     {
   14183         602 :                         DefElem   *defel = (DefElem *) lfirst(option);
   14184             : 
   14185         602 :                         if (strcmp(defel->defname, "default") == 0)
   14186             :                         {
   14187          56 :                             if (fc->coldefexpr != NULL)
   14188           0 :                                 ereport(ERROR,
   14189             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14190             :                                          errmsg("only one DEFAULT value is allowed"),
   14191             :                                          parser_errposition(defel->location)));
   14192          56 :                             fc->coldefexpr = defel->arg;
   14193             :                         }
   14194         546 :                         else if (strcmp(defel->defname, "path") == 0)
   14195             :                         {
   14196         490 :                             if (fc->colexpr != NULL)
   14197           0 :                                 ereport(ERROR,
   14198             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14199             :                                          errmsg("only one PATH value per column is allowed"),
   14200             :                                          parser_errposition(defel->location)));
   14201         490 :                             fc->colexpr = defel->arg;
   14202             :                         }
   14203          56 :                         else if (strcmp(defel->defname, "is_not_null") == 0)
   14204             :                         {
   14205          56 :                             if (nullability_seen)
   14206           0 :                                 ereport(ERROR,
   14207             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14208             :                                          errmsg("conflicting or redundant NULL / NOT NULL declarations for column \"%s\"", fc->colname),
   14209             :                                          parser_errposition(defel->location)));
   14210          56 :                             fc->is_not_null = boolVal(defel->arg);
   14211          56 :                             nullability_seen = true;
   14212             :                         }
   14213             :                         else
   14214             :                         {
   14215           0 :                             ereport(ERROR,
   14216             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   14217             :                                      errmsg("unrecognized column option \"%s\"",
   14218             :                                             defel->defname),
   14219             :                                      parser_errposition(defel->location)));
   14220             :                         }
   14221             :                     }
   14222         490 :                     $$ = (Node *) fc;
   14223             :                 }
   14224             :             | ColId FOR ORDINALITY
   14225             :                 {
   14226          62 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14227             : 
   14228          62 :                     fc->colname = $1;
   14229          62 :                     fc->for_ordinality = true;
   14230             :                     /* other fields are ignored, initialized by makeNode */
   14231          62 :                     fc->location = @1;
   14232             : 
   14233          62 :                     $$ = (Node *) fc;
   14234             :                 }
   14235             :         ;
   14236             : 
   14237             : xmltable_column_option_list:
   14238             :             xmltable_column_option_el
   14239         490 :                 { $$ = list_make1($1); }
   14240             :             | xmltable_column_option_list xmltable_column_option_el
   14241         112 :                 { $$ = lappend($1, $2); }
   14242             :         ;
   14243             : 
   14244             : xmltable_column_option_el:
   14245             :             IDENT b_expr
   14246           0 :                 { $$ = makeDefElem($1, $2, @1); }
   14247             :             | DEFAULT b_expr
   14248          56 :                 { $$ = makeDefElem("default", $2, @1); }
   14249             :             | NOT NULL_P
   14250          56 :                 { $$ = makeDefElem("is_not_null", (Node *) makeBoolean(true), @1); }
   14251             :             | NULL_P
   14252           0 :                 { $$ = makeDefElem("is_not_null", (Node *) makeBoolean(false), @1); }
   14253             :             | PATH b_expr
   14254         490 :                 { $$ = makeDefElem("path", $2, @1); }
   14255             :         ;
   14256             : 
   14257             : xml_namespace_list:
   14258             :             xml_namespace_el
   14259          20 :                 { $$ = list_make1($1); }
   14260             :             | xml_namespace_list ',' xml_namespace_el
   14261           0 :                 { $$ = lappend($1, $3); }
   14262             :         ;
   14263             : 
   14264             : xml_namespace_el:
   14265             :             b_expr AS ColLabel
   14266             :                 {
   14267          14 :                     $$ = makeNode(ResTarget);
   14268          14 :                     $$->name = $3;
   14269          14 :                     $$->indirection = NIL;
   14270          14 :                     $$->val = $1;
   14271          14 :                     $$->location = @1;
   14272             :                 }
   14273             :             | DEFAULT b_expr
   14274             :                 {
   14275           6 :                     $$ = makeNode(ResTarget);
   14276           6 :                     $$->name = NULL;
   14277           6 :                     $$->indirection = NIL;
   14278           6 :                     $$->val = $2;
   14279           6 :                     $$->location = @1;
   14280             :                 }
   14281             :         ;
   14282             : 
   14283             : json_table:
   14284             :             JSON_TABLE '('
   14285             :                 json_value_expr ',' a_expr json_table_path_name_opt
   14286             :                 json_passing_clause_opt
   14287             :                 COLUMNS '(' json_table_column_definition_list ')'
   14288             :                 json_on_error_clause_opt
   14289             :             ')'
   14290             :                 {
   14291         530 :                     JsonTable *n = makeNode(JsonTable);
   14292             :                     char      *pathstring;
   14293             : 
   14294         530 :                     n->context_item = (JsonValueExpr *) $3;
   14295         530 :                     if (!IsA($5, A_Const) ||
   14296         524 :                         castNode(A_Const, $5)->val.node.type != T_String)
   14297           6 :                         ereport(ERROR,
   14298             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   14299             :                                 errmsg("only string constants are supported in JSON_TABLE path specification"),
   14300             :                                 parser_errposition(@5));
   14301         524 :                     pathstring = castNode(A_Const, $5)->val.sval.sval;
   14302         524 :                     n->pathspec = makeJsonTablePathSpec(pathstring, $6, @5, @6);
   14303         524 :                     n->passing = $7;
   14304         524 :                     n->columns = $10;
   14305         524 :                     n->on_error = (JsonBehavior *) $12;
   14306         524 :                     n->location = @1;
   14307         524 :                     $$ = (Node *) n;
   14308             :                 }
   14309             :         ;
   14310             : 
   14311             : json_table_path_name_opt:
   14312          62 :             AS name         { $$ = $2; }
   14313         480 :             | /* empty */   { $$ = NULL; }
   14314             :         ;
   14315             : 
   14316             : json_table_column_definition_list:
   14317             :             json_table_column_definition
   14318         820 :                 { $$ = list_make1($1); }
   14319             :             | json_table_column_definition_list ',' json_table_column_definition
   14320         528 :                 { $$ = lappend($1, $3); }
   14321             :         ;
   14322             : 
   14323             : json_table_column_definition:
   14324             :             ColId FOR ORDINALITY
   14325             :                 {
   14326          84 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14327             : 
   14328          84 :                     n->coltype = JTC_FOR_ORDINALITY;
   14329          84 :                     n->name = $1;
   14330          84 :                     n->location = @1;
   14331          84 :                     $$ = (Node *) n;
   14332             :                 }
   14333             :             | ColId Typename
   14334             :                 json_table_column_path_clause_opt
   14335             :                 json_wrapper_behavior
   14336             :                 json_quotes_clause_opt
   14337             :                 json_behavior_clause_opt
   14338             :                 {
   14339         728 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14340             : 
   14341         728 :                     n->coltype = JTC_REGULAR;
   14342         728 :                     n->name = $1;
   14343         728 :                     n->typeName = $2;
   14344         728 :                     n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   14345         728 :                     n->pathspec = (JsonTablePathSpec *) $3;
   14346         728 :                     n->wrapper = $4;
   14347         728 :                     n->quotes = $5;
   14348         728 :                     n->on_empty = (JsonBehavior *) linitial($6);
   14349         728 :                     n->on_error = (JsonBehavior *) lsecond($6);
   14350         728 :                     n->location = @1;
   14351         728 :                     $$ = (Node *) n;
   14352             :                 }
   14353             :             | ColId Typename json_format_clause
   14354             :                 json_table_column_path_clause_opt
   14355             :                 json_wrapper_behavior
   14356             :                 json_quotes_clause_opt
   14357             :                 json_behavior_clause_opt
   14358             :                 {
   14359         108 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14360             : 
   14361         108 :                     n->coltype = JTC_FORMATTED;
   14362         108 :                     n->name = $1;
   14363         108 :                     n->typeName = $2;
   14364         108 :                     n->format = (JsonFormat *) $3;
   14365         108 :                     n->pathspec = (JsonTablePathSpec *) $4;
   14366         108 :                     n->wrapper = $5;
   14367         108 :                     n->quotes = $6;
   14368         108 :                     n->on_empty = (JsonBehavior *) linitial($7);
   14369         108 :                     n->on_error = (JsonBehavior *) lsecond($7);
   14370         108 :                     n->location = @1;
   14371         108 :                     $$ = (Node *) n;
   14372             :                 }
   14373             :             | ColId Typename
   14374             :                 EXISTS json_table_column_path_clause_opt
   14375             :                 json_on_error_clause_opt
   14376             :                 {
   14377         138 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14378             : 
   14379         138 :                     n->coltype = JTC_EXISTS;
   14380         138 :                     n->name = $1;
   14381         138 :                     n->typeName = $2;
   14382         138 :                     n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   14383         138 :                     n->wrapper = JSW_NONE;
   14384         138 :                     n->quotes = JS_QUOTES_UNSPEC;
   14385         138 :                     n->pathspec = (JsonTablePathSpec *) $4;
   14386         138 :                     n->on_empty = NULL;
   14387         138 :                     n->on_error = (JsonBehavior *) $5;
   14388         138 :                     n->location = @1;
   14389         138 :                     $$ = (Node *) n;
   14390             :                 }
   14391             :             | NESTED path_opt Sconst
   14392             :                 COLUMNS '(' json_table_column_definition_list ')'
   14393             :                 {
   14394         144 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14395             : 
   14396         144 :                     n->coltype = JTC_NESTED;
   14397         288 :                     n->pathspec = (JsonTablePathSpec *)
   14398         144 :                         makeJsonTablePathSpec($3, NULL, @3, -1);
   14399         144 :                     n->columns = $6;
   14400         144 :                     n->location = @1;
   14401         144 :                     $$ = (Node *) n;
   14402             :                 }
   14403             :             | NESTED path_opt Sconst AS name
   14404             :                 COLUMNS '(' json_table_column_definition_list ')'
   14405             :                 {
   14406         146 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14407             : 
   14408         146 :                     n->coltype = JTC_NESTED;
   14409         292 :                     n->pathspec = (JsonTablePathSpec *)
   14410         146 :                         makeJsonTablePathSpec($3, $5, @3, @5);
   14411         146 :                     n->columns = $8;
   14412         146 :                     n->location = @1;
   14413         146 :                     $$ = (Node *) n;
   14414             :                 }
   14415             :         ;
   14416             : 
   14417             : path_opt:
   14418             :             PATH
   14419             :             | /* EMPTY */
   14420             :         ;
   14421             : 
   14422             : json_table_column_path_clause_opt:
   14423             :             PATH Sconst
   14424         828 :                 { $$ = (Node *) makeJsonTablePathSpec($2, NULL, @2, -1); }
   14425             :             | /* EMPTY */
   14426         152 :                 { $$ = NULL; }
   14427             :         ;
   14428             : 
   14429             : /*****************************************************************************
   14430             :  *
   14431             :  *  Type syntax
   14432             :  *      SQL introduces a large amount of type-specific syntax.
   14433             :  *      Define individual clauses to handle these cases, and use
   14434             :  *       the generic case to handle regular type-extensible Postgres syntax.
   14435             :  *      - thomas 1997-10-10
   14436             :  *
   14437             :  *****************************************************************************/
   14438             : 
   14439             : Typename:   SimpleTypename opt_array_bounds
   14440             :                 {
   14441      449108 :                     $$ = $1;
   14442      449108 :                     $$->arrayBounds = $2;
   14443             :                 }
   14444             :             | SETOF SimpleTypename opt_array_bounds
   14445             :                 {
   14446        2116 :                     $$ = $2;
   14447        2116 :                     $$->arrayBounds = $3;
   14448        2116 :                     $$->setof = true;
   14449             :                 }
   14450             :             /* SQL standard syntax, currently only one-dimensional */
   14451             :             | SimpleTypename ARRAY '[' Iconst ']'
   14452             :                 {
   14453           6 :                     $$ = $1;
   14454           6 :                     $$->arrayBounds = list_make1(makeInteger($4));
   14455             :                 }
   14456             :             | SETOF SimpleTypename ARRAY '[' Iconst ']'
   14457             :                 {
   14458           0 :                     $$ = $2;
   14459           0 :                     $$->arrayBounds = list_make1(makeInteger($5));
   14460           0 :                     $$->setof = true;
   14461             :                 }
   14462             :             | SimpleTypename ARRAY
   14463             :                 {
   14464           0 :                     $$ = $1;
   14465           0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   14466             :                 }
   14467             :             | SETOF SimpleTypename ARRAY
   14468             :                 {
   14469           0 :                     $$ = $2;
   14470           0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   14471           0 :                     $$->setof = true;
   14472             :                 }
   14473             :         ;
   14474             : 
   14475             : opt_array_bounds:
   14476             :             opt_array_bounds '[' ']'
   14477       12426 :                     {  $$ = lappend($1, makeInteger(-1)); }
   14478             :             | opt_array_bounds '[' Iconst ']'
   14479          62 :                     {  $$ = lappend($1, makeInteger($3)); }
   14480             :             | /*EMPTY*/
   14481      451224 :                     {  $$ = NIL; }
   14482             :         ;
   14483             : 
   14484             : SimpleTypename:
   14485      362058 :             GenericType                             { $$ = $1; }
   14486       74976 :             | Numeric                               { $$ = $1; }
   14487        1894 :             | Bit                                   { $$ = $1; }
   14488        2906 :             | Character                             { $$ = $1; }
   14489        4600 :             | ConstDatetime                         { $$ = $1; }
   14490             :             | ConstInterval opt_interval
   14491             :                 {
   14492        3518 :                     $$ = $1;
   14493        3518 :                     $$->typmods = $2;
   14494             :                 }
   14495             :             | ConstInterval '(' Iconst ')'
   14496             :                 {
   14497           0 :                     $$ = $1;
   14498           0 :                     $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   14499             :                                              makeIntConst($3, @3));
   14500             :                 }
   14501        1660 :             | JsonType                              { $$ = $1; }
   14502             :         ;
   14503             : 
   14504             : /* We have a separate ConstTypename to allow defaulting fixed-length
   14505             :  * types such as CHAR() and BIT() to an unspecified length.
   14506             :  * SQL9x requires that these default to a length of one, but this
   14507             :  * makes no sense for constructs like CHAR 'hi' and BIT '0101',
   14508             :  * where there is an obvious better choice to make.
   14509             :  * Note that ConstInterval is not included here since it must
   14510             :  * be pushed up higher in the rules to accommodate the postfix
   14511             :  * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
   14512             :  * the generic-type-name case in AexprConst to avoid premature
   14513             :  * reduce/reduce conflicts against function names.
   14514             :  */
   14515             : ConstTypename:
   14516          78 :             Numeric                                 { $$ = $1; }
   14517           0 :             | ConstBit                              { $$ = $1; }
   14518          34 :             | ConstCharacter                        { $$ = $1; }
   14519        2738 :             | ConstDatetime                         { $$ = $1; }
   14520         264 :             | JsonType                              { $$ = $1; }
   14521             :         ;
   14522             : 
   14523             : /*
   14524             :  * GenericType covers all type names that don't have special syntax mandated
   14525             :  * by the standard, including qualified names.  We also allow type modifiers.
   14526             :  * To avoid parsing conflicts against function invocations, the modifiers
   14527             :  * have to be shown as expr_list here, but parse analysis will only accept
   14528             :  * constants for them.
   14529             :  */
   14530             : GenericType:
   14531             :             type_function_name opt_type_modifiers
   14532             :                 {
   14533      260190 :                     $$ = makeTypeName($1);
   14534      260190 :                     $$->typmods = $2;
   14535      260190 :                     $$->location = @1;
   14536             :                 }
   14537             :             | type_function_name attrs opt_type_modifiers
   14538             :                 {
   14539      101868 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
   14540      101868 :                     $$->typmods = $3;
   14541      101868 :                     $$->location = @1;
   14542             :                 }
   14543             :         ;
   14544             : 
   14545        1348 : opt_type_modifiers: '(' expr_list ')'               { $$ = $2; }
   14546      366658 :                     | /* EMPTY */                   { $$ = NIL; }
   14547             :         ;
   14548             : 
   14549             : /*
   14550             :  * SQL numeric data types
   14551             :  */
   14552             : Numeric:    INT_P
   14553             :                 {
   14554       35450 :                     $$ = SystemTypeName("int4");
   14555       35450 :                     $$->location = @1;
   14556             :                 }
   14557             :             | INTEGER
   14558             :                 {
   14559       14326 :                     $$ = SystemTypeName("int4");
   14560       14326 :                     $$->location = @1;
   14561             :                 }
   14562             :             | SMALLINT
   14563             :                 {
   14564        1226 :                     $$ = SystemTypeName("int2");
   14565        1226 :                     $$->location = @1;
   14566             :                 }
   14567             :             | BIGINT
   14568             :                 {
   14569        4458 :                     $$ = SystemTypeName("int8");
   14570        4458 :                     $$->location = @1;
   14571             :                 }
   14572             :             | REAL
   14573             :                 {
   14574        1956 :                     $$ = SystemTypeName("float4");
   14575        1956 :                     $$->location = @1;
   14576             :                 }
   14577             :             | FLOAT_P opt_float
   14578             :                 {
   14579         500 :                     $$ = $2;
   14580         500 :                     $$->location = @1;
   14581             :                 }
   14582             :             | DOUBLE_P PRECISION
   14583             :                 {
   14584         514 :                     $$ = SystemTypeName("float8");
   14585         514 :                     $$->location = @1;
   14586             :                 }
   14587             :             | DECIMAL_P opt_type_modifiers
   14588             :                 {
   14589          36 :                     $$ = SystemTypeName("numeric");
   14590          36 :                     $$->typmods = $2;
   14591          36 :                     $$->location = @1;
   14592             :                 }
   14593             :             | DEC opt_type_modifiers
   14594             :                 {
   14595           0 :                     $$ = SystemTypeName("numeric");
   14596           0 :                     $$->typmods = $2;
   14597           0 :                     $$->location = @1;
   14598             :                 }
   14599             :             | NUMERIC opt_type_modifiers
   14600             :                 {
   14601        5912 :                     $$ = SystemTypeName("numeric");
   14602        5912 :                     $$->typmods = $2;
   14603        5912 :                     $$->location = @1;
   14604             :                 }
   14605             :             | BOOLEAN_P
   14606             :                 {
   14607       10676 :                     $$ = SystemTypeName("bool");
   14608       10676 :                     $$->location = @1;
   14609             :                 }
   14610             :         ;
   14611             : 
   14612             : opt_float:  '(' Iconst ')'
   14613             :                 {
   14614             :                     /*
   14615             :                      * Check FLOAT() precision limits assuming IEEE floating
   14616             :                      * types - thomas 1997-09-18
   14617             :                      */
   14618           2 :                     if ($2 < 1)
   14619           0 :                         ereport(ERROR,
   14620             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   14621             :                                  errmsg("precision for type float must be at least 1 bit"),
   14622             :                                  parser_errposition(@2)));
   14623           2 :                     else if ($2 <= 24)
   14624           2 :                         $$ = SystemTypeName("float4");
   14625           0 :                     else if ($2 <= 53)
   14626           0 :                         $$ = SystemTypeName("float8");
   14627             :                     else
   14628           0 :                         ereport(ERROR,
   14629             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   14630             :                                  errmsg("precision for type float must be less than 54 bits"),
   14631             :                                  parser_errposition(@2)));
   14632             :                 }
   14633             :             | /*EMPTY*/
   14634             :                 {
   14635         498 :                     $$ = SystemTypeName("float8");
   14636             :                 }
   14637             :         ;
   14638             : 
   14639             : /*
   14640             :  * SQL bit-field data types
   14641             :  * The following implements BIT() and BIT VARYING().
   14642             :  */
   14643             : Bit:        BitWithLength
   14644             :                 {
   14645        1696 :                     $$ = $1;
   14646             :                 }
   14647             :             | BitWithoutLength
   14648             :                 {
   14649         198 :                     $$ = $1;
   14650             :                 }
   14651             :         ;
   14652             : 
   14653             : /* ConstBit is like Bit except "BIT" defaults to unspecified length */
   14654             : /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
   14655             : ConstBit:   BitWithLength
   14656             :                 {
   14657           0 :                     $$ = $1;
   14658             :                 }
   14659             :             | BitWithoutLength
   14660             :                 {
   14661           0 :                     $$ = $1;
   14662           0 :                     $$->typmods = NIL;
   14663             :                 }
   14664             :         ;
   14665             : 
   14666             : BitWithLength:
   14667             :             BIT opt_varying '(' expr_list ')'
   14668             :                 {
   14669             :                     char *typname;
   14670             : 
   14671        1696 :                     typname = $2 ? "varbit" : "bit";
   14672        1696 :                     $$ = SystemTypeName(typname);
   14673        1696 :                     $$->typmods = $4;
   14674        1696 :                     $$->location = @1;
   14675             :                 }
   14676             :         ;
   14677             : 
   14678             : BitWithoutLength:
   14679             :             BIT opt_varying
   14680             :                 {
   14681             :                     /* bit defaults to bit(1), varbit to no limit */
   14682         198 :                     if ($2)
   14683             :                     {
   14684          20 :                         $$ = SystemTypeName("varbit");
   14685             :                     }
   14686             :                     else
   14687             :                     {
   14688         178 :                         $$ = SystemTypeName("bit");
   14689         178 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   14690             :                     }
   14691         198 :                     $$->location = @1;
   14692             :                 }
   14693             :         ;
   14694             : 
   14695             : 
   14696             : /*
   14697             :  * SQL character data types
   14698             :  * The following implements CHAR() and VARCHAR().
   14699             :  */
   14700             : Character:  CharacterWithLength
   14701             :                 {
   14702        1700 :                     $$ = $1;
   14703             :                 }
   14704             :             | CharacterWithoutLength
   14705             :                 {
   14706        1206 :                     $$ = $1;
   14707             :                 }
   14708             :         ;
   14709             : 
   14710             : ConstCharacter:  CharacterWithLength
   14711             :                 {
   14712          12 :                     $$ = $1;
   14713             :                 }
   14714             :             | CharacterWithoutLength
   14715             :                 {
   14716             :                     /* Length was not specified so allow to be unrestricted.
   14717             :                      * This handles problems with fixed-length (bpchar) strings
   14718             :                      * which in column definitions must default to a length
   14719             :                      * of one, but should not be constrained if the length
   14720             :                      * was not specified.
   14721             :                      */
   14722          22 :                     $$ = $1;
   14723          22 :                     $$->typmods = NIL;
   14724             :                 }
   14725             :         ;
   14726             : 
   14727             : CharacterWithLength:  character '(' Iconst ')'
   14728             :                 {
   14729        1712 :                     $$ = SystemTypeName($1);
   14730        1712 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14731        1712 :                     $$->location = @1;
   14732             :                 }
   14733             :         ;
   14734             : 
   14735             : CharacterWithoutLength:  character
   14736             :                 {
   14737        1228 :                     $$ = SystemTypeName($1);
   14738             :                     /* char defaults to char(1), varchar to no limit */
   14739        1228 :                     if (strcmp($1, "bpchar") == 0)
   14740         252 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   14741        1228 :                     $$->location = @1;
   14742             :                 }
   14743             :         ;
   14744             : 
   14745             : character:  CHARACTER opt_varying
   14746         522 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14747             :             | CHAR_P opt_varying
   14748        1164 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14749             :             | VARCHAR
   14750        1250 :                                         { $$ = "varchar"; }
   14751             :             | NATIONAL CHARACTER opt_varying
   14752           0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   14753             :             | NATIONAL CHAR_P opt_varying
   14754           0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   14755             :             | NCHAR opt_varying
   14756           4 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14757             :         ;
   14758             : 
   14759             : opt_varying:
   14760         418 :             VARYING                                 { $$ = true; }
   14761        3166 :             | /*EMPTY*/                             { $$ = false; }
   14762             :         ;
   14763             : 
   14764             : /*
   14765             :  * SQL date/time types
   14766             :  */
   14767             : ConstDatetime:
   14768             :             TIMESTAMP '(' Iconst ')' opt_timezone
   14769             :                 {
   14770         124 :                     if ($5)
   14771         100 :                         $$ = SystemTypeName("timestamptz");
   14772             :                     else
   14773          24 :                         $$ = SystemTypeName("timestamp");
   14774         124 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14775         124 :                     $$->location = @1;
   14776             :                 }
   14777             :             | TIMESTAMP opt_timezone
   14778             :                 {
   14779        4840 :                     if ($2)
   14780        1352 :                         $$ = SystemTypeName("timestamptz");
   14781             :                     else
   14782        3488 :                         $$ = SystemTypeName("timestamp");
   14783        4840 :                     $$->location = @1;
   14784             :                 }
   14785             :             | TIME '(' Iconst ')' opt_timezone
   14786             :                 {
   14787          22 :                     if ($5)
   14788           8 :                         $$ = SystemTypeName("timetz");
   14789             :                     else
   14790          14 :                         $$ = SystemTypeName("time");
   14791          22 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14792          22 :                     $$->location = @1;
   14793             :                 }
   14794             :             | TIME opt_timezone
   14795             :                 {
   14796        2352 :                     if ($2)
   14797         344 :                         $$ = SystemTypeName("timetz");
   14798             :                     else
   14799        2008 :                         $$ = SystemTypeName("time");
   14800        2352 :                     $$->location = @1;
   14801             :                 }
   14802             :         ;
   14803             : 
   14804             : ConstInterval:
   14805             :             INTERVAL
   14806             :                 {
   14807        6828 :                     $$ = SystemTypeName("interval");
   14808        6828 :                     $$->location = @1;
   14809             :                 }
   14810             :         ;
   14811             : 
   14812             : opt_timezone:
   14813        1804 :             WITH_LA TIME ZONE                       { $$ = true; }
   14814         592 :             | WITHOUT_LA TIME ZONE                  { $$ = false; }
   14815        4942 :             | /*EMPTY*/                             { $$ = false; }
   14816             :         ;
   14817             : 
   14818             : opt_interval:
   14819             :             YEAR_P
   14820          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
   14821             :             | MONTH_P
   14822          18 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
   14823             :             | DAY_P
   14824          18 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
   14825             :             | HOUR_P
   14826          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
   14827             :             | MINUTE_P
   14828          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
   14829             :             | interval_second
   14830          36 :                 { $$ = $1; }
   14831             :             | YEAR_P TO MONTH_P
   14832             :                 {
   14833          18 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
   14834             :                                                  INTERVAL_MASK(MONTH), @1));
   14835             :                 }
   14836             :             | DAY_P TO HOUR_P
   14837             :                 {
   14838          24 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   14839             :                                                  INTERVAL_MASK(HOUR), @1));
   14840             :                 }
   14841             :             | DAY_P TO MINUTE_P
   14842             :                 {
   14843          24 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   14844             :                                                  INTERVAL_MASK(HOUR) |
   14845             :                                                  INTERVAL_MASK(MINUTE), @1));
   14846             :                 }
   14847             :             | DAY_P TO interval_second
   14848             :                 {
   14849          48 :                     $$ = $3;
   14850          48 :                     linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
   14851             :                                                 INTERVAL_MASK(HOUR) |
   14852             :                                                 INTERVAL_MASK(MINUTE) |
   14853          48 :                                                 INTERVAL_MASK(SECOND), @1);
   14854             :                 }
   14855             :             | HOUR_P TO MINUTE_P
   14856             :                 {
   14857          18 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
   14858             :                                                  INTERVAL_MASK(MINUTE), @1));
   14859             :                 }
   14860             :             | HOUR_P TO interval_second
   14861             :                 {
   14862          36 :                     $$ = $3;
   14863          36 :                     linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
   14864             :                                                 INTERVAL_MASK(MINUTE) |
   14865          36 :                                                 INTERVAL_MASK(SECOND), @1);
   14866             :                 }
   14867             :             | MINUTE_P TO interval_second
   14868             :                 {
   14869          66 :                     $$ = $3;
   14870          66 :                     linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
   14871          66 :                                                 INTERVAL_MASK(SECOND), @1);
   14872             :                 }
   14873             :             | /*EMPTY*/
   14874        6474 :                 { $$ = NIL; }
   14875             :         ;
   14876             : 
   14877             : interval_second:
   14878             :             SECOND_P
   14879             :                 {
   14880         102 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
   14881             :                 }
   14882             :             | SECOND_P '(' Iconst ')'
   14883             :                 {
   14884          84 :                     $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
   14885             :                                     makeIntConst($3, @3));
   14886             :                 }
   14887             :         ;
   14888             : 
   14889             : JsonType:
   14890             :             JSON
   14891             :                 {
   14892        1924 :                     $$ = SystemTypeName("json");
   14893        1924 :                     $$->location = @1;
   14894             :                 }
   14895             :         ;
   14896             : 
   14897             : /*****************************************************************************
   14898             :  *
   14899             :  *  expression grammar
   14900             :  *
   14901             :  *****************************************************************************/
   14902             : 
   14903             : /*
   14904             :  * General expressions
   14905             :  * This is the heart of the expression syntax.
   14906             :  *
   14907             :  * We have two expression types: a_expr is the unrestricted kind, and
   14908             :  * b_expr is a subset that must be used in some places to avoid shift/reduce
   14909             :  * conflicts.  For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
   14910             :  * because that use of AND conflicts with AND as a boolean operator.  So,
   14911             :  * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
   14912             :  *
   14913             :  * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
   14914             :  * always be used by surrounding it with parens.
   14915             :  *
   14916             :  * c_expr is all the productions that are common to a_expr and b_expr;
   14917             :  * it's factored out just to eliminate redundant coding.
   14918             :  *
   14919             :  * Be careful of productions involving more than one terminal token.
   14920             :  * By default, bison will assign such productions the precedence of their
   14921             :  * last terminal, but in nearly all cases you want it to be the precedence
   14922             :  * of the first terminal instead; otherwise you will not get the behavior
   14923             :  * you expect!  So we use %prec annotations freely to set precedences.
   14924             :  */
   14925     3491778 : a_expr:     c_expr                                  { $$ = $1; }
   14926             :             | a_expr TYPECAST Typename
   14927      194688 :                     { $$ = makeTypeCast($1, $3, @2); }
   14928             :             | a_expr COLLATE any_name
   14929             :                 {
   14930        8516 :                     CollateClause *n = makeNode(CollateClause);
   14931             : 
   14932        8516 :                     n->arg = $1;
   14933        8516 :                     n->collname = $3;
   14934        8516 :                     n->location = @2;
   14935        8516 :                     $$ = (Node *) n;
   14936             :                 }
   14937             :             | a_expr AT TIME ZONE a_expr            %prec AT
   14938             :                 {
   14939         402 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   14940         402 :                                                list_make2($5, $1),
   14941             :                                                COERCE_SQL_SYNTAX,
   14942         402 :                                                @2);
   14943             :                 }
   14944             :             | a_expr AT LOCAL                       %prec AT
   14945             :                 {
   14946          42 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   14947          42 :                                                list_make1($1),
   14948             :                                                COERCE_SQL_SYNTAX,
   14949             :                                                -1);
   14950             :                 }
   14951             :         /*
   14952             :          * These operators must be called out explicitly in order to make use
   14953             :          * of bison's automatic operator-precedence handling.  All other
   14954             :          * operator names are handled by the generic productions using "Op",
   14955             :          * below; and all those operators will have the same precedence.
   14956             :          *
   14957             :          * If you add more explicitly-known operators, be sure to add them
   14958             :          * also to b_expr and to the MathOp list below.
   14959             :          */
   14960             :             | '+' a_expr                    %prec UMINUS
   14961          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   14962             :             | '-' a_expr                    %prec UMINUS
   14963       27828 :                 { $$ = doNegate($2, @1); }
   14964             :             | a_expr '+' a_expr
   14965       13884 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   14966             :             | a_expr '-' a_expr
   14967        6196 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   14968             :             | a_expr '*' a_expr
   14969        5396 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   14970             :             | a_expr '/' a_expr
   14971        3082 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   14972             :             | a_expr '%' a_expr
   14973        2758 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   14974             :             | a_expr '^' a_expr
   14975         466 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   14976             :             | a_expr '<' a_expr
   14977       22956 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   14978             :             | a_expr '>' a_expr
   14979       32664 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   14980             :             | a_expr '=' a_expr
   14981      362842 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   14982             :             | a_expr LESS_EQUALS a_expr
   14983        4936 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   14984             :             | a_expr GREATER_EQUALS a_expr
   14985        4894 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   14986             :             | a_expr NOT_EQUALS a_expr
   14987       38630 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   14988             : 
   14989             :             | a_expr qual_Op a_expr             %prec Op
   14990       55772 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   14991             :             | qual_Op a_expr                    %prec Op
   14992         192 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   14993             : 
   14994             :             | a_expr AND a_expr
   14995      212974 :                 { $$ = makeAndExpr($1, $3, @2); }
   14996             :             | a_expr OR a_expr
   14997       15858 :                 { $$ = makeOrExpr($1, $3, @2); }
   14998             :             | NOT a_expr
   14999       14128 :                 { $$ = makeNotExpr($2, @1); }
   15000             :             | NOT_LA a_expr                     %prec NOT
   15001           0 :                 { $$ = makeNotExpr($2, @1); }
   15002             : 
   15003             :             | a_expr LIKE a_expr
   15004             :                 {
   15005        1922 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   15006        1922 :                                                    $1, $3, @2);
   15007             :                 }
   15008             :             | a_expr LIKE a_expr ESCAPE a_expr                  %prec LIKE
   15009             :                 {
   15010          96 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15011          96 :                                                  list_make2($3, $5),
   15012             :                                                  COERCE_EXPLICIT_CALL,
   15013          96 :                                                  @2);
   15014          96 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   15015          96 :                                                    $1, (Node *) n, @2);
   15016             :                 }
   15017             :             | a_expr NOT_LA LIKE a_expr                         %prec NOT_LA
   15018             :                 {
   15019         198 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   15020         198 :                                                    $1, $4, @2);
   15021             :                 }
   15022             :             | a_expr NOT_LA LIKE a_expr ESCAPE a_expr           %prec NOT_LA
   15023             :                 {
   15024          96 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15025          96 :                                                  list_make2($4, $6),
   15026             :                                                  COERCE_EXPLICIT_CALL,
   15027          96 :                                                  @2);
   15028          96 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   15029          96 :                                                    $1, (Node *) n, @2);
   15030             :                 }
   15031             :             | a_expr ILIKE a_expr
   15032             :                 {
   15033         174 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   15034         174 :                                                    $1, $3, @2);
   15035             :                 }
   15036             :             | a_expr ILIKE a_expr ESCAPE a_expr                 %prec ILIKE
   15037             :                 {
   15038           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15039           0 :                                                  list_make2($3, $5),
   15040             :                                                  COERCE_EXPLICIT_CALL,
   15041           0 :                                                  @2);
   15042           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   15043           0 :                                                    $1, (Node *) n, @2);
   15044             :                 }
   15045             :             | a_expr NOT_LA ILIKE a_expr                        %prec NOT_LA
   15046             :                 {
   15047          30 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   15048          30 :                                                    $1, $4, @2);
   15049             :                 }
   15050             :             | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr          %prec NOT_LA
   15051             :                 {
   15052           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15053           0 :                                                  list_make2($4, $6),
   15054             :                                                  COERCE_EXPLICIT_CALL,
   15055           0 :                                                  @2);
   15056           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   15057           0 :                                                    $1, (Node *) n, @2);
   15058             :                 }
   15059             : 
   15060             :             | a_expr SIMILAR TO a_expr                          %prec SIMILAR
   15061             :                 {
   15062          40 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15063          40 :                                                  list_make1($4),
   15064             :                                                  COERCE_EXPLICIT_CALL,
   15065          40 :                                                  @2);
   15066          40 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   15067          40 :                                                    $1, (Node *) n, @2);
   15068             :                 }
   15069             :             | a_expr SIMILAR TO a_expr ESCAPE a_expr            %prec SIMILAR
   15070             :                 {
   15071          30 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15072          30 :                                                  list_make2($4, $6),
   15073             :                                                  COERCE_EXPLICIT_CALL,
   15074          30 :                                                  @2);
   15075          30 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   15076          30 :                                                    $1, (Node *) n, @2);
   15077             :                 }
   15078             :             | a_expr NOT_LA SIMILAR TO a_expr                   %prec NOT_LA
   15079             :                 {
   15080           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15081           0 :                                                  list_make1($5),
   15082             :                                                  COERCE_EXPLICIT_CALL,
   15083           0 :                                                  @2);
   15084           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   15085           0 :                                                    $1, (Node *) n, @2);
   15086             :                 }
   15087             :             | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr     %prec NOT_LA
   15088             :                 {
   15089           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15090           0 :                                                  list_make2($5, $7),
   15091             :                                                  COERCE_EXPLICIT_CALL,
   15092           0 :                                                  @2);
   15093           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   15094           0 :                                                    $1, (Node *) n, @2);
   15095             :                 }
   15096             : 
   15097             :             /* NullTest clause
   15098             :              * Define SQL-style Null test clause.
   15099             :              * Allow two forms described in the standard:
   15100             :              *  a IS NULL
   15101             :              *  a IS NOT NULL
   15102             :              * Allow two SQL extensions
   15103             :              *  a ISNULL
   15104             :              *  a NOTNULL
   15105             :              */
   15106             :             | a_expr IS NULL_P                          %prec IS
   15107             :                 {
   15108        4950 :                     NullTest   *n = makeNode(NullTest);
   15109             : 
   15110        4950 :                     n->arg = (Expr *) $1;
   15111        4950 :                     n->nulltesttype = IS_NULL;
   15112        4950 :                     n->location = @2;
   15113        4950 :                     $$ = (Node *) n;
   15114             :                 }
   15115             :             | a_expr ISNULL
   15116             :                 {
   15117          96 :                     NullTest   *n = makeNode(NullTest);
   15118             : 
   15119          96 :                     n->arg = (Expr *) $1;
   15120          96 :                     n->nulltesttype = IS_NULL;
   15121          96 :                     n->location = @2;
   15122          96 :                     $$ = (Node *) n;
   15123             :                 }
   15124             :             | a_expr IS NOT NULL_P                      %prec IS
   15125             :                 {
   15126       11038 :                     NullTest   *n = makeNode(NullTest);
   15127             : 
   15128       11038 :                     n->arg = (Expr *) $1;
   15129       11038 :                     n->nulltesttype = IS_NOT_NULL;
   15130       11038 :                     n->location = @2;
   15131       11038 :                     $$ = (Node *) n;
   15132             :                 }
   15133             :             | a_expr NOTNULL
   15134             :                 {
   15135           6 :                     NullTest   *n = makeNode(NullTest);
   15136             : 
   15137           6 :                     n->arg = (Expr *) $1;
   15138           6 :                     n->nulltesttype = IS_NOT_NULL;
   15139           6 :                     n->location = @2;
   15140           6 :                     $$ = (Node *) n;
   15141             :                 }
   15142             :             | row OVERLAPS row
   15143             :                 {
   15144         876 :                     if (list_length($1) != 2)
   15145           0 :                         ereport(ERROR,
   15146             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   15147             :                                  errmsg("wrong number of parameters on left side of OVERLAPS expression"),
   15148             :                                  parser_errposition(@1)));
   15149         876 :                     if (list_length($3) != 2)
   15150           0 :                         ereport(ERROR,
   15151             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   15152             :                                  errmsg("wrong number of parameters on right side of OVERLAPS expression"),
   15153             :                                  parser_errposition(@3)));
   15154         876 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
   15155         876 :                                                list_concat($1, $3),
   15156             :                                                COERCE_SQL_SYNTAX,
   15157         876 :                                                @2);
   15158             :                 }
   15159             :             | a_expr IS TRUE_P                          %prec IS
   15160             :                 {
   15161         372 :                     BooleanTest *b = makeNode(BooleanTest);
   15162             : 
   15163         372 :                     b->arg = (Expr *) $1;
   15164         372 :                     b->booltesttype = IS_TRUE;
   15165         372 :                     b->location = @2;
   15166         372 :                     $$ = (Node *) b;
   15167             :                 }
   15168             :             | a_expr IS NOT TRUE_P                      %prec IS
   15169             :                 {
   15170         140 :                     BooleanTest *b = makeNode(BooleanTest);
   15171             : 
   15172         140 :                     b->arg = (Expr *) $1;
   15173         140 :                     b->booltesttype = IS_NOT_TRUE;
   15174         140 :                     b->location = @2;
   15175         140 :                     $$ = (Node *) b;
   15176             :                 }
   15177             :             | a_expr IS FALSE_P                         %prec IS
   15178             :                 {
   15179         102 :                     BooleanTest *b = makeNode(BooleanTest);
   15180             : 
   15181         102 :                     b->arg = (Expr *) $1;
   15182         102 :                     b->booltesttype = IS_FALSE;
   15183         102 :                     b->location = @2;
   15184         102 :                     $$ = (Node *) b;
   15185             :                 }
   15186             :             | a_expr IS NOT FALSE_P                     %prec IS
   15187             :                 {
   15188          92 :                     BooleanTest *b = makeNode(BooleanTest);
   15189             : 
   15190          92 :                     b->arg = (Expr *) $1;
   15191          92 :                     b->booltesttype = IS_NOT_FALSE;
   15192          92 :                     b->location = @2;
   15193          92 :                     $$ = (Node *) b;
   15194             :                 }
   15195             :             | a_expr IS UNKNOWN                         %prec IS
   15196             :                 {
   15197          52 :                     BooleanTest *b = makeNode(BooleanTest);
   15198             : 
   15199          52 :                     b->arg = (Expr *) $1;
   15200          52 :                     b->booltesttype = IS_UNKNOWN;
   15201          52 :                     b->location = @2;
   15202          52 :                     $$ = (Node *) b;
   15203             :                 }
   15204             :             | a_expr IS NOT UNKNOWN                     %prec IS
   15205             :                 {
   15206          48 :                     BooleanTest *b = makeNode(BooleanTest);
   15207             : 
   15208          48 :                     b->arg = (Expr *) $1;
   15209          48 :                     b->booltesttype = IS_NOT_UNKNOWN;
   15210          48 :                     b->location = @2;
   15211          48 :                     $$ = (Node *) b;
   15212             :                 }
   15213             :             | a_expr IS DISTINCT FROM a_expr            %prec IS
   15214             :                 {
   15215         874 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   15216             :                 }
   15217             :             | a_expr IS NOT DISTINCT FROM a_expr        %prec IS
   15218             :                 {
   15219          68 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   15220             :                 }
   15221             :             | a_expr BETWEEN opt_asymmetric b_expr AND a_expr       %prec BETWEEN
   15222             :                 {
   15223         466 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN,
   15224             :                                                    "BETWEEN",
   15225         466 :                                                    $1,
   15226         466 :                                                    (Node *) list_make2($4, $6),
   15227         466 :                                                    @2);
   15228             :                 }
   15229             :             | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
   15230             :                 {
   15231          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN,
   15232             :                                                    "NOT BETWEEN",
   15233          12 :                                                    $1,
   15234          12 :                                                    (Node *) list_make2($5, $7),
   15235          12 :                                                    @2);
   15236             :                 }
   15237             :             | a_expr BETWEEN SYMMETRIC b_expr AND a_expr            %prec BETWEEN
   15238             :                 {
   15239          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN_SYM,
   15240             :                                                    "BETWEEN SYMMETRIC",
   15241          12 :                                                    $1,
   15242          12 :                                                    (Node *) list_make2($4, $6),
   15243          12 :                                                    @2);
   15244             :                 }
   15245             :             | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr     %prec NOT_LA
   15246             :                 {
   15247          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN_SYM,
   15248             :                                                    "NOT BETWEEN SYMMETRIC",
   15249          12 :                                                    $1,
   15250          12 :                                                    (Node *) list_make2($5, $7),
   15251          12 :                                                    @2);
   15252             :                 }
   15253             :             | a_expr IN_P in_expr
   15254             :                 {
   15255             :                     /* in_expr returns a SubLink or a list of a_exprs */
   15256       18730 :                     if (IsA($3, SubLink))
   15257             :                     {
   15258             :                         /* generate foo = ANY (subquery) */
   15259        2418 :                         SubLink    *n = (SubLink *) $3;
   15260             : 
   15261        2418 :                         n->subLinkType = ANY_SUBLINK;
   15262        2418 :                         n->subLinkId = 0;
   15263        2418 :                         n->testexpr = $1;
   15264        2418 :                         n->operName = NIL;       /* show it's IN not = ANY */
   15265        2418 :                         n->location = @2;
   15266        2418 :                         $$ = (Node *) n;
   15267             :                     }
   15268             :                     else
   15269             :                     {
   15270             :                         /* generate scalar IN expression */
   15271       16312 :                         $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
   15272             :                     }
   15273             :                 }
   15274             :             | a_expr NOT_LA IN_P in_expr                        %prec NOT_LA
   15275             :                 {
   15276             :                     /* in_expr returns a SubLink or a list of a_exprs */
   15277        2302 :                     if (IsA($4, SubLink))
   15278             :                     {
   15279             :                         /* generate NOT (foo = ANY (subquery)) */
   15280             :                         /* Make an = ANY node */
   15281         120 :                         SubLink    *n = (SubLink *) $4;
   15282             : 
   15283         120 :                         n->subLinkType = ANY_SUBLINK;
   15284         120 :                         n->subLinkId = 0;
   15285         120 :                         n->testexpr = $1;
   15286         120 :                         n->operName = NIL;       /* show it's IN not = ANY */
   15287         120 :                         n->location = @2;
   15288             :                         /* Stick a NOT on top; must have same parse location */
   15289         120 :                         $$ = makeNotExpr((Node *) n, @2);
   15290             :                     }
   15291             :                     else
   15292             :                     {
   15293             :                         /* generate scalar NOT IN expression */
   15294        2182 :                         $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
   15295             :                     }
   15296             :                 }
   15297             :             | a_expr subquery_Op sub_type select_with_parens    %prec Op
   15298             :                 {
   15299         166 :                     SubLink    *n = makeNode(SubLink);
   15300             : 
   15301         166 :                     n->subLinkType = $3;
   15302         166 :                     n->subLinkId = 0;
   15303         166 :                     n->testexpr = $1;
   15304         166 :                     n->operName = $2;
   15305         166 :                     n->subselect = $4;
   15306         166 :                     n->location = @2;
   15307         166 :                     $$ = (Node *) n;
   15308             :                 }
   15309             :             | a_expr subquery_Op sub_type '(' a_expr ')'        %prec Op
   15310             :                 {
   15311       15372 :                     if ($3 == ANY_SUBLINK)
   15312       15072 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
   15313             :                     else
   15314         300 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
   15315             :                 }
   15316             :             | UNIQUE opt_unique_null_treatment select_with_parens
   15317             :                 {
   15318             :                     /* Not sure how to get rid of the parentheses
   15319             :                      * but there are lots of shift/reduce errors without them.
   15320             :                      *
   15321             :                      * Should be able to implement this by plopping the entire
   15322             :                      * select into a node, then transforming the target expressions
   15323             :                      * from whatever they are into count(*), and testing the
   15324             :                      * entire result equal to one.
   15325             :                      * But, will probably implement a separate node in the executor.
   15326             :                      */
   15327           0 :                     ereport(ERROR,
   15328             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   15329             :                              errmsg("UNIQUE predicate is not yet implemented"),
   15330             :                              parser_errposition(@1)));
   15331             :                 }
   15332             :             | a_expr IS DOCUMENT_P                  %prec IS
   15333             :                 {
   15334          18 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15335          18 :                                      list_make1($1), @2);
   15336             :                 }
   15337             :             | a_expr IS NOT DOCUMENT_P              %prec IS
   15338             :                 {
   15339          18 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15340          18 :                                                  list_make1($1), @2),
   15341          18 :                                      @2);
   15342             :                 }
   15343             :             | a_expr IS NORMALIZED                              %prec IS
   15344             :                 {
   15345          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15346          12 :                                                list_make1($1),
   15347             :                                                COERCE_SQL_SYNTAX,
   15348          12 :                                                @2);
   15349             :                 }
   15350             :             | a_expr IS unicode_normal_form NORMALIZED          %prec IS
   15351             :                 {
   15352          36 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15353          36 :                                                list_make2($1, makeStringConst($3, @3)),
   15354             :                                                COERCE_SQL_SYNTAX,
   15355          36 :                                                @2);
   15356             :                 }
   15357             :             | a_expr IS NOT NORMALIZED                          %prec IS
   15358             :                 {
   15359           0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15360           0 :                                                            list_make1($1),
   15361             :                                                            COERCE_SQL_SYNTAX,
   15362           0 :                                                            @2),
   15363           0 :                                      @2);
   15364             :                 }
   15365             :             | a_expr IS NOT unicode_normal_form NORMALIZED      %prec IS
   15366             :                 {
   15367           0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15368           0 :                                                            list_make2($1, makeStringConst($4, @4)),
   15369             :                                                            COERCE_SQL_SYNTAX,
   15370           0 :                                                            @2),
   15371           0 :                                      @2);
   15372             :                 }
   15373             :             | a_expr IS json_predicate_type_constraint
   15374             :                     json_key_uniqueness_constraint_opt      %prec IS
   15375             :                 {
   15376         304 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   15377             : 
   15378         304 :                     $$ = makeJsonIsPredicate($1, format, $3, $4, @1);
   15379             :                 }
   15380             :             /*
   15381             :              * Required by SQL/JSON, but there are conflicts
   15382             :             | a_expr
   15383             :                 json_format_clause
   15384             :                 IS  json_predicate_type_constraint
   15385             :                     json_key_uniqueness_constraint_opt      %prec IS
   15386             :                 {
   15387             :                     $$ = makeJsonIsPredicate($1, $2, $4, $5, @1);
   15388             :                 }
   15389             :             */
   15390             :             | a_expr IS NOT
   15391             :                     json_predicate_type_constraint
   15392             :                     json_key_uniqueness_constraint_opt      %prec IS
   15393             :                 {
   15394          46 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   15395             : 
   15396          46 :                     $$ = makeNotExpr(makeJsonIsPredicate($1, format, $4, $5, @1), @1);
   15397             :                 }
   15398             :             /*
   15399             :              * Required by SQL/JSON, but there are conflicts
   15400             :             | a_expr
   15401             :                 json_format_clause
   15402             :                 IS NOT
   15403             :                     json_predicate_type_constraint
   15404             :                     json_key_uniqueness_constraint_opt      %prec IS
   15405             :                 {
   15406             :                     $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, @1), @1);
   15407             :                 }
   15408             :             */
   15409             :             | DEFAULT
   15410             :                 {
   15411             :                     /*
   15412             :                      * The SQL spec only allows DEFAULT in "contextually typed
   15413             :                      * expressions", but for us, it's easier to allow it in
   15414             :                      * any a_expr and then throw error during parse analysis
   15415             :                      * if it's in an inappropriate context.  This way also
   15416             :                      * lets us say something smarter than "syntax error".
   15417             :                      */
   15418        1402 :                     SetToDefault *n = makeNode(SetToDefault);
   15419             : 
   15420             :                     /* parse analysis will fill in the rest */
   15421        1402 :                     n->location = @1;
   15422        1402 :                     $$ = (Node *) n;
   15423             :                 }
   15424             :         ;
   15425             : 
   15426             : /*
   15427             :  * Restricted expressions
   15428             :  *
   15429             :  * b_expr is a subset of the complete expression syntax defined by a_expr.
   15430             :  *
   15431             :  * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
   15432             :  * cause trouble in the places where b_expr is used.  For simplicity, we
   15433             :  * just eliminate all the boolean-keyword-operator productions from b_expr.
   15434             :  */
   15435             : b_expr:     c_expr
   15436        3534 :                 { $$ = $1; }
   15437             :             | b_expr TYPECAST Typename
   15438         134 :                 { $$ = makeTypeCast($1, $3, @2); }
   15439             :             | '+' b_expr                    %prec UMINUS
   15440           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   15441             :             | '-' b_expr                    %prec UMINUS
   15442          66 :                 { $$ = doNegate($2, @1); }
   15443             :             | b_expr '+' b_expr
   15444          36 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   15445             :             | b_expr '-' b_expr
   15446          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   15447             :             | b_expr '*' b_expr
   15448          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   15449             :             | b_expr '/' b_expr
   15450           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   15451             :             | b_expr '%' b_expr
   15452           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   15453             :             | b_expr '^' b_expr
   15454           6 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   15455             :             | b_expr '<' b_expr
   15456           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   15457             :             | b_expr '>' b_expr
   15458           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   15459             :             | b_expr '=' b_expr
   15460           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   15461             :             | b_expr LESS_EQUALS b_expr
   15462           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   15463             :             | b_expr GREATER_EQUALS b_expr
   15464           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   15465             :             | b_expr NOT_EQUALS b_expr
   15466           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   15467             :             | b_expr qual_Op b_expr             %prec Op
   15468          12 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   15469             :             | qual_Op b_expr                    %prec Op
   15470           0 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   15471             :             | b_expr IS DISTINCT FROM b_expr        %prec IS
   15472             :                 {
   15473           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   15474             :                 }
   15475             :             | b_expr IS NOT DISTINCT FROM b_expr    %prec IS
   15476             :                 {
   15477           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   15478             :                 }
   15479             :             | b_expr IS DOCUMENT_P                  %prec IS
   15480             :                 {
   15481           0 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15482           0 :                                      list_make1($1), @2);
   15483             :                 }
   15484             :             | b_expr IS NOT DOCUMENT_P              %prec IS
   15485             :                 {
   15486           0 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15487           0 :                                                  list_make1($1), @2),
   15488           0 :                                      @2);
   15489             :                 }
   15490             :         ;
   15491             : 
   15492             : /*
   15493             :  * Productions that can be used in both a_expr and b_expr.
   15494             :  *
   15495             :  * Note: productions that refer recursively to a_expr or b_expr mostly
   15496             :  * cannot appear here.  However, it's OK to refer to a_exprs that occur
   15497             :  * inside parentheses, such as function arguments; that cannot introduce
   15498             :  * ambiguity to the b_expr syntax.
   15499             :  */
   15500     1623614 : c_expr:     columnref                               { $$ = $1; }
   15501     1157018 :             | AexprConst                            { $$ = $1; }
   15502             :             | PARAM opt_indirection
   15503             :                 {
   15504      145056 :                     ParamRef   *p = makeNode(ParamRef);
   15505             : 
   15506      145056 :                     p->number = $1;
   15507      145056 :                     p->location = @1;
   15508      145056 :                     if ($2)
   15509             :                     {
   15510        1198 :                         A_Indirection *n = makeNode(A_Indirection);
   15511             : 
   15512        1198 :                         n->arg = (Node *) p;
   15513        1198 :                         n->indirection = check_indirection($2, yyscanner);
   15514        1198 :                         $$ = (Node *) n;
   15515             :                     }
   15516             :                     else
   15517      143858 :                         $$ = (Node *) p;
   15518             :                 }
   15519             :             | '(' a_expr ')' opt_indirection
   15520             :                 {
   15521       84164 :                     if ($4)
   15522             :                     {
   15523       11128 :                         A_Indirection *n = makeNode(A_Indirection);
   15524             : 
   15525       11128 :                         n->arg = $2;
   15526       11128 :                         n->indirection = check_indirection($4, yyscanner);
   15527       11128 :                         $$ = (Node *) n;
   15528             :                     }
   15529             :                     else
   15530       73036 :                         $$ = $2;
   15531             :                 }
   15532             :             | case_expr
   15533       54798 :                 { $$ = $1; }
   15534             :             | func_expr
   15535      379580 :                 { $$ = $1; }
   15536             :             | select_with_parens            %prec UMINUS
   15537             :                 {
   15538       24848 :                     SubLink    *n = makeNode(SubLink);
   15539             : 
   15540       24848 :                     n->subLinkType = EXPR_SUBLINK;
   15541       24848 :                     n->subLinkId = 0;
   15542       24848 :                     n->testexpr = NULL;
   15543       24848 :                     n->operName = NIL;
   15544       24848 :                     n->subselect = $1;
   15545       24848 :                     n->location = @1;
   15546       24848 :                     $$ = (Node *) n;
   15547             :                 }
   15548             :             | select_with_parens indirection
   15549             :                 {
   15550             :                     /*
   15551             :                      * Because the select_with_parens nonterminal is designed
   15552             :                      * to "eat" as many levels of parens as possible, the
   15553             :                      * '(' a_expr ')' opt_indirection production above will
   15554             :                      * fail to match a sub-SELECT with indirection decoration;
   15555             :                      * the sub-SELECT won't be regarded as an a_expr as long
   15556             :                      * as there are parens around it.  To support applying
   15557             :                      * subscripting or field selection to a sub-SELECT result,
   15558             :                      * we need this redundant-looking production.
   15559             :                      */
   15560          18 :                     SubLink    *n = makeNode(SubLink);
   15561          18 :                     A_Indirection *a = makeNode(A_Indirection);
   15562             : 
   15563          18 :                     n->subLinkType = EXPR_SUBLINK;
   15564          18 :                     n->subLinkId = 0;
   15565          18 :                     n->testexpr = NULL;
   15566          18 :                     n->operName = NIL;
   15567          18 :                     n->subselect = $1;
   15568          18 :                     n->location = @1;
   15569          18 :                     a->arg = (Node *) n;
   15570          18 :                     a->indirection = check_indirection($2, yyscanner);
   15571          18 :                     $$ = (Node *) a;
   15572             :                 }
   15573             :             | EXISTS select_with_parens
   15574             :                 {
   15575        5324 :                     SubLink    *n = makeNode(SubLink);
   15576             : 
   15577        5324 :                     n->subLinkType = EXISTS_SUBLINK;
   15578        5324 :                     n->subLinkId = 0;
   15579        5324 :                     n->testexpr = NULL;
   15580        5324 :                     n->operName = NIL;
   15581        5324 :                     n->subselect = $2;
   15582        5324 :                     n->location = @1;
   15583        5324 :                     $$ = (Node *) n;
   15584             :                 }
   15585             :             | ARRAY select_with_parens
   15586             :                 {
   15587        7708 :                     SubLink    *n = makeNode(SubLink);
   15588             : 
   15589        7708 :                     n->subLinkType = ARRAY_SUBLINK;
   15590        7708 :                     n->subLinkId = 0;
   15591        7708 :                     n->testexpr = NULL;
   15592        7708 :                     n->operName = NIL;
   15593        7708 :                     n->subselect = $2;
   15594        7708 :                     n->location = @1;
   15595        7708 :                     $$ = (Node *) n;
   15596             :                 }
   15597             :             | ARRAY array_expr
   15598             :                 {
   15599        7146 :                     A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
   15600             : 
   15601             :                     /* point outermost A_ArrayExpr to the ARRAY keyword */
   15602        7146 :                     n->location = @1;
   15603        7146 :                     $$ = (Node *) n;
   15604             :                 }
   15605             :             | explicit_row
   15606             :                 {
   15607        3894 :                     RowExpr    *r = makeNode(RowExpr);
   15608             : 
   15609        3894 :                     r->args = $1;
   15610        3894 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15611        3894 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15612        3894 :                     r->row_format = COERCE_EXPLICIT_CALL; /* abuse */
   15613        3894 :                     r->location = @1;
   15614        3894 :                     $$ = (Node *) r;
   15615             :                 }
   15616             :             | implicit_row
   15617             :                 {
   15618        2432 :                     RowExpr    *r = makeNode(RowExpr);
   15619             : 
   15620        2432 :                     r->args = $1;
   15621        2432 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15622        2432 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15623        2432 :                     r->row_format = COERCE_IMPLICIT_CAST; /* abuse */
   15624        2432 :                     r->location = @1;
   15625        2432 :                     $$ = (Node *) r;
   15626             :                 }
   15627             :             | GROUPING '(' expr_list ')'
   15628             :               {
   15629         362 :                   GroupingFunc *g = makeNode(GroupingFunc);
   15630             : 
   15631         362 :                   g->args = $3;
   15632         362 :                   g->location = @1;
   15633         362 :                   $$ = (Node *) g;
   15634             :               }
   15635             :         ;
   15636             : 
   15637             : func_application: func_name '(' ')'
   15638             :                 {
   15639       45468 :                     $$ = (Node *) makeFuncCall($1, NIL,
   15640             :                                                COERCE_EXPLICIT_CALL,
   15641       45468 :                                                @1);
   15642             :                 }
   15643             :             | func_name '(' func_arg_list opt_sort_clause ')'
   15644             :                 {
   15645      295944 :                     FuncCall   *n = makeFuncCall($1, $3,
   15646             :                                                  COERCE_EXPLICIT_CALL,
   15647      295944 :                                                  @1);
   15648             : 
   15649      295944 :                     n->agg_order = $4;
   15650      295944 :                     $$ = (Node *) n;
   15651             :                 }
   15652             :             | func_name '(' VARIADIC func_arg_expr opt_sort_clause ')'
   15653             :                 {
   15654         594 :                     FuncCall   *n = makeFuncCall($1, list_make1($4),
   15655             :                                                  COERCE_EXPLICIT_CALL,
   15656         594 :                                                  @1);
   15657             : 
   15658         594 :                     n->func_variadic = true;
   15659         594 :                     n->agg_order = $5;
   15660         594 :                     $$ = (Node *) n;
   15661             :                 }
   15662             :             | func_name '(' func_arg_list ',' VARIADIC func_arg_expr opt_sort_clause ')'
   15663             :                 {
   15664         120 :                     FuncCall   *n = makeFuncCall($1, lappend($3, $6),
   15665             :                                                  COERCE_EXPLICIT_CALL,
   15666         120 :                                                  @1);
   15667             : 
   15668         120 :                     n->func_variadic = true;
   15669         120 :                     n->agg_order = $7;
   15670         120 :                     $$ = (Node *) n;
   15671             :                 }
   15672             :             | func_name '(' ALL func_arg_list opt_sort_clause ')'
   15673             :                 {
   15674           0 :                     FuncCall   *n = makeFuncCall($1, $4,
   15675             :                                                  COERCE_EXPLICIT_CALL,
   15676           0 :                                                  @1);
   15677             : 
   15678           0 :                     n->agg_order = $5;
   15679             :                     /* Ideally we'd mark the FuncCall node to indicate
   15680             :                      * "must be an aggregate", but there's no provision
   15681             :                      * for that in FuncCall at the moment.
   15682             :                      */
   15683           0 :                     $$ = (Node *) n;
   15684             :                 }
   15685             :             | func_name '(' DISTINCT func_arg_list opt_sort_clause ')'
   15686             :                 {
   15687         538 :                     FuncCall   *n = makeFuncCall($1, $4,
   15688             :                                                  COERCE_EXPLICIT_CALL,
   15689         538 :                                                  @1);
   15690             : 
   15691         538 :                     n->agg_order = $5;
   15692         538 :                     n->agg_distinct = true;
   15693         538 :                     $$ = (Node *) n;
   15694             :                 }
   15695             :             | func_name '(' '*' ')'
   15696             :                 {
   15697             :                     /*
   15698             :                      * We consider AGGREGATE(*) to invoke a parameterless
   15699             :                      * aggregate.  This does the right thing for COUNT(*),
   15700             :                      * and there are no other aggregates in SQL that accept
   15701             :                      * '*' as parameter.
   15702             :                      *
   15703             :                      * The FuncCall node is also marked agg_star = true,
   15704             :                      * so that later processing can detect what the argument
   15705             :                      * really was.
   15706             :                      */
   15707       12186 :                     FuncCall   *n = makeFuncCall($1, NIL,
   15708             :                                                  COERCE_EXPLICIT_CALL,
   15709       12186 :                                                  @1);
   15710             : 
   15711       12186 :                     n->agg_star = true;
   15712       12186 :                     $$ = (Node *) n;
   15713             :                 }
   15714             :         ;
   15715             : 
   15716             : 
   15717             : /*
   15718             :  * func_expr and its cousin func_expr_windowless are split out from c_expr just
   15719             :  * so that we have classifications for "everything that is a function call or
   15720             :  * looks like one".  This isn't very important, but it saves us having to
   15721             :  * document which variants are legal in places like "FROM function()" or the
   15722             :  * backwards-compatible functional-index syntax for CREATE INDEX.
   15723             :  * (Note that many of the special SQL functions wouldn't actually make any
   15724             :  * sense as functional index entries, but we ignore that consideration here.)
   15725             :  */
   15726             : func_expr: func_application within_group_clause filter_clause over_clause
   15727             :                 {
   15728      310112 :                     FuncCall   *n = (FuncCall *) $1;
   15729             : 
   15730             :                     /*
   15731             :                      * The order clause for WITHIN GROUP and the one for
   15732             :                      * plain-aggregate ORDER BY share a field, so we have to
   15733             :                      * check here that at most one is present.  We also check
   15734             :                      * for DISTINCT and VARIADIC here to give a better error
   15735             :                      * location.  Other consistency checks are deferred to
   15736             :                      * parse analysis.
   15737             :                      */
   15738      310112 :                     if ($2 != NIL)
   15739             :                     {
   15740         348 :                         if (n->agg_order != NIL)
   15741           6 :                             ereport(ERROR,
   15742             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15743             :                                      errmsg("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
   15744             :                                      parser_errposition(@2)));
   15745         342 :                         if (n->agg_distinct)
   15746           0 :                             ereport(ERROR,
   15747             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15748             :                                      errmsg("cannot use DISTINCT with WITHIN GROUP"),
   15749             :                                      parser_errposition(@2)));
   15750         342 :                         if (n->func_variadic)
   15751           0 :                             ereport(ERROR,
   15752             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15753             :                                      errmsg("cannot use VARIADIC with WITHIN GROUP"),
   15754             :                                      parser_errposition(@2)));
   15755         342 :                         n->agg_order = $2;
   15756         342 :                         n->agg_within_group = true;
   15757             :                     }
   15758      310106 :                     n->agg_filter = $3;
   15759      310106 :                     n->over = $4;
   15760      310106 :                     $$ = (Node *) n;
   15761             :                 }
   15762             :             | json_aggregate_func filter_clause over_clause
   15763             :                 {
   15764         720 :                     JsonAggConstructor *n = IsA($1, JsonObjectAgg) ?
   15765         360 :                         ((JsonObjectAgg *) $1)->constructor :
   15766         156 :                         ((JsonArrayAgg *) $1)->constructor;
   15767             : 
   15768         360 :                     n->agg_filter = $2;
   15769         360 :                     n->over = $3;
   15770         360 :                     $$ = (Node *) $1;
   15771             :                 }
   15772             :             | func_expr_common_subexpr
   15773       69114 :                 { $$ = $1; }
   15774             :         ;
   15775             : 
   15776             : /*
   15777             :  * Like func_expr but does not accept WINDOW functions directly
   15778             :  * (but they can still be contained in arguments for functions etc).
   15779             :  * Use this when window expressions are not allowed, where needed to
   15780             :  * disambiguate the grammar (e.g. in CREATE INDEX).
   15781             :  */
   15782             : func_expr_windowless:
   15783       44130 :             func_application                        { $$ = $1; }
   15784         402 :             | func_expr_common_subexpr              { $$ = $1; }
   15785           0 :             | json_aggregate_func                   { $$ = $1; }
   15786             :         ;
   15787             : 
   15788             : /*
   15789             :  * Special expressions that are considered to be functions.
   15790             :  */
   15791             : func_expr_common_subexpr:
   15792             :             COLLATION FOR '(' a_expr ')'
   15793             :                 {
   15794          30 :                     $$ = (Node *) makeFuncCall(SystemFuncName("pg_collation_for"),
   15795          30 :                                                list_make1($4),
   15796             :                                                COERCE_SQL_SYNTAX,
   15797          30 :                                                @1);
   15798             :                 }
   15799             :             | CURRENT_DATE
   15800             :                 {
   15801         288 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_DATE, -1, @1);
   15802             :                 }
   15803             :             | CURRENT_TIME
   15804             :                 {
   15805          24 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME, -1, @1);
   15806             :                 }
   15807             :             | CURRENT_TIME '(' Iconst ')'
   15808             :                 {
   15809          24 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME_N, $3, @1);
   15810             :                 }
   15811             :             | CURRENT_TIMESTAMP
   15812             :                 {
   15813         288 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP, -1, @1);
   15814             :                 }
   15815             :             | CURRENT_TIMESTAMP '(' Iconst ')'
   15816             :                 {
   15817         116 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP_N, $3, @1);
   15818             :                 }
   15819             :             | LOCALTIME
   15820             :                 {
   15821          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIME, -1, @1);
   15822             :                 }
   15823             :             | LOCALTIME '(' Iconst ')'
   15824             :                 {
   15825          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIME_N, $3, @1);
   15826             :                 }
   15827             :             | LOCALTIMESTAMP
   15828             :                 {
   15829          36 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP, -1, @1);
   15830             :                 }
   15831             :             | LOCALTIMESTAMP '(' Iconst ')'
   15832             :                 {
   15833          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP_N, $3, @1);
   15834             :                 }
   15835             :             | CURRENT_ROLE
   15836             :                 {
   15837         116 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_ROLE, -1, @1);
   15838             :                 }
   15839             :             | CURRENT_USER
   15840             :                 {
   15841         992 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_USER, -1, @1);
   15842             :                 }
   15843             :             | SESSION_USER
   15844             :                 {
   15845         620 :                     $$ = makeSQLValueFunction(SVFOP_SESSION_USER, -1, @1);
   15846             :                 }
   15847             :             | SYSTEM_USER
   15848             :                 {
   15849          20 :                     $$ = (Node *) makeFuncCall(SystemFuncName("system_user"),
   15850             :                                                NIL,
   15851             :                                                COERCE_SQL_SYNTAX,
   15852             :                                                @1);
   15853             :                 }
   15854             :             | USER
   15855             :                 {
   15856          24 :                     $$ = makeSQLValueFunction(SVFOP_USER, -1, @1);
   15857             :                 }
   15858             :             | CURRENT_CATALOG
   15859             :                 {
   15860          52 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_CATALOG, -1, @1);
   15861             :                 }
   15862             :             | CURRENT_SCHEMA
   15863             :                 {
   15864          30 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_SCHEMA, -1, @1);
   15865             :                 }
   15866             :             | CAST '(' a_expr AS Typename ')'
   15867       56042 :                 { $$ = makeTypeCast($3, $5, @1); }
   15868             :             | EXTRACT '(' extract_list ')'
   15869             :                 {
   15870        1282 :                     $$ = (Node *) makeFuncCall(SystemFuncName("extract"),
   15871        1282 :                                                $3,
   15872             :                                                COERCE_SQL_SYNTAX,
   15873        1282 :                                                @1);
   15874             :                 }
   15875             :             | NORMALIZE '(' a_expr ')'
   15876             :                 {
   15877          18 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   15878          18 :                                                list_make1($3),
   15879             :                                                COERCE_SQL_SYNTAX,
   15880          18 :                                                @1);
   15881             :                 }
   15882             :             | NORMALIZE '(' a_expr ',' unicode_normal_form ')'
   15883             :                 {
   15884          36 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   15885          36 :                                                list_make2($3, makeStringConst($5, @5)),
   15886             :                                                COERCE_SQL_SYNTAX,
   15887          36 :                                                @1);
   15888             :                 }
   15889             :             | OVERLAY '(' overlay_list ')'
   15890             :                 {
   15891          82 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlay"),
   15892          82 :                                                $3,
   15893             :                                                COERCE_SQL_SYNTAX,
   15894          82 :                                                @1);
   15895             :                 }
   15896             :             | OVERLAY '(' func_arg_list_opt ')'
   15897             :                 {
   15898             :                     /*
   15899             :                      * allow functions named overlay() to be called without
   15900             :                      * special syntax
   15901             :                      */
   15902           0 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("overlay")),
   15903           0 :                                                $3,
   15904             :                                                COERCE_EXPLICIT_CALL,
   15905           0 :                                                @1);
   15906             :                 }
   15907             :             | POSITION '(' position_list ')'
   15908             :                 {
   15909             :                     /*
   15910             :                      * position(A in B) is converted to position(B, A)
   15911             :                      *
   15912             :                      * We deliberately don't offer a "plain syntax" option
   15913             :                      * for position(), because the reversal of the arguments
   15914             :                      * creates too much risk of confusion.
   15915             :                      */
   15916         360 :                     $$ = (Node *) makeFuncCall(SystemFuncName("position"),
   15917         360 :                                                $3,
   15918             :                                                COERCE_SQL_SYNTAX,
   15919         360 :                                                @1);
   15920             :                 }
   15921             :             | SUBSTRING '(' substr_list ')'
   15922             :                 {
   15923             :                     /* substring(A from B for C) is converted to
   15924             :                      * substring(A, B, C) - thomas 2000-11-28
   15925             :                      */
   15926         670 :                     $$ = (Node *) makeFuncCall(SystemFuncName("substring"),
   15927         670 :                                                $3,
   15928             :                                                COERCE_SQL_SYNTAX,
   15929         670 :                                                @1);
   15930             :                 }
   15931             :             | SUBSTRING '(' func_arg_list_opt ')'
   15932             :                 {
   15933             :                     /*
   15934             :                      * allow functions named substring() to be called without
   15935             :                      * special syntax
   15936             :                      */
   15937         198 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("substring")),
   15938         198 :                                                $3,
   15939             :                                                COERCE_EXPLICIT_CALL,
   15940         198 :                                                @1);
   15941             :                 }
   15942             :             | TREAT '(' a_expr AS Typename ')'
   15943             :                 {
   15944             :                     /* TREAT(expr AS target) converts expr of a particular type to target,
   15945             :                      * which is defined to be a subtype of the original expression.
   15946             :                      * In SQL99, this is intended for use with structured UDTs,
   15947             :                      * but let's make this a generally useful form allowing stronger
   15948             :                      * coercions than are handled by implicit casting.
   15949             :                      *
   15950             :                      * Convert SystemTypeName() to SystemFuncName() even though
   15951             :                      * at the moment they result in the same thing.
   15952             :                      */
   15953           0 :                     $$ = (Node *) makeFuncCall(SystemFuncName(strVal(llast($5->names))),
   15954           0 :                                                list_make1($3),
   15955             :                                                COERCE_EXPLICIT_CALL,
   15956           0 :                                                @1);
   15957             :                 }
   15958             :             | TRIM '(' BOTH trim_list ')'
   15959             :                 {
   15960             :                     /* various trim expressions are defined in SQL
   15961             :                      * - thomas 1997-07-19
   15962             :                      */
   15963          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   15964          12 :                                                $4,
   15965             :                                                COERCE_SQL_SYNTAX,
   15966          12 :                                                @1);
   15967             :                 }
   15968             :             | TRIM '(' LEADING trim_list ')'
   15969             :                 {
   15970          24 :                     $$ = (Node *) makeFuncCall(SystemFuncName("ltrim"),
   15971          24 :                                                $4,
   15972             :                                                COERCE_SQL_SYNTAX,
   15973          24 :                                                @1);
   15974             :                 }
   15975             :             | TRIM '(' TRAILING trim_list ')'
   15976             :                 {
   15977         564 :                     $$ = (Node *) makeFuncCall(SystemFuncName("rtrim"),
   15978         564 :                                                $4,
   15979             :                                                COERCE_SQL_SYNTAX,
   15980         564 :                                                @1);
   15981             :                 }
   15982             :             | TRIM '(' trim_list ')'
   15983             :                 {
   15984          98 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   15985          98 :                                                $3,
   15986             :                                                COERCE_SQL_SYNTAX,
   15987          98 :                                                @1);
   15988             :                 }
   15989             :             | NULLIF '(' a_expr ',' a_expr ')'
   15990             :                 {
   15991         258 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
   15992             :                 }
   15993             :             | COALESCE '(' expr_list ')'
   15994             :                 {
   15995        2978 :                     CoalesceExpr *c = makeNode(CoalesceExpr);
   15996             : 
   15997        2978 :                     c->args = $3;
   15998        2978 :                     c->location = @1;
   15999        2978 :                     $$ = (Node *) c;
   16000             :                 }
   16001             :             | GREATEST '(' expr_list ')'
   16002             :                 {
   16003         140 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   16004             : 
   16005         140 :                     v->args = $3;
   16006         140 :                     v->op = IS_GREATEST;
   16007         140 :                     v->location = @1;
   16008         140 :                     $$ = (Node *) v;
   16009             :                 }
   16010             :             | LEAST '(' expr_list ')'
   16011             :                 {
   16012         142 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   16013             : 
   16014         142 :                     v->args = $3;
   16015         142 :                     v->op = IS_LEAST;
   16016         142 :                     v->location = @1;
   16017         142 :                     $$ = (Node *) v;
   16018             :                 }
   16019             :             | XMLCONCAT '(' expr_list ')'
   16020             :                 {
   16021          62 :                     $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
   16022             :                 }
   16023             :             | XMLELEMENT '(' NAME_P ColLabel ')'
   16024             :                 {
   16025           6 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
   16026             :                 }
   16027             :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
   16028             :                 {
   16029          36 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
   16030             :                 }
   16031             :             | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
   16032             :                 {
   16033         116 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
   16034             :                 }
   16035             :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
   16036             :                 {
   16037          20 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
   16038             :                 }
   16039             :             | XMLEXISTS '(' c_expr xmlexists_argument ')'
   16040             :                 {
   16041             :                     /* xmlexists(A PASSING [BY REF] B [BY REF]) is
   16042             :                      * converted to xmlexists(A, B)*/
   16043          54 :                     $$ = (Node *) makeFuncCall(SystemFuncName("xmlexists"),
   16044          54 :                                                list_make2($3, $4),
   16045             :                                                COERCE_SQL_SYNTAX,
   16046          54 :                                                @1);
   16047             :                 }
   16048             :             | XMLFOREST '(' xml_attribute_list ')'
   16049             :                 {
   16050          32 :                     $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
   16051             :                 }
   16052             :             | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
   16053             :                 {
   16054             :                     XmlExpr *x = (XmlExpr *)
   16055         140 :                         makeXmlExpr(IS_XMLPARSE, NULL, NIL,
   16056         140 :                                     list_make2($4, makeBoolAConst($5, -1)),
   16057         140 :                                     @1);
   16058             : 
   16059         140 :                     x->xmloption = $3;
   16060         140 :                     $$ = (Node *) x;
   16061             :                 }
   16062             :             | XMLPI '(' NAME_P ColLabel ')'
   16063             :                 {
   16064          30 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
   16065             :                 }
   16066             :             | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
   16067             :                 {
   16068          50 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
   16069             :                 }
   16070             :             | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
   16071             :                 {
   16072          68 :                     $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
   16073          68 :                                      list_make3($3, $5, $6), @1);
   16074             :                 }
   16075             :             | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename xml_indent_option ')'
   16076             :                 {
   16077         202 :                     XmlSerialize *n = makeNode(XmlSerialize);
   16078             : 
   16079         202 :                     n->xmloption = $3;
   16080         202 :                     n->expr = $4;
   16081         202 :                     n->typeName = $6;
   16082         202 :                     n->indent = $7;
   16083         202 :                     n->location = @1;
   16084         202 :                     $$ = (Node *) n;
   16085             :                 }
   16086             :             | JSON_OBJECT '(' func_arg_list ')'
   16087             :                 {
   16088             :                     /* Support for legacy (non-standard) json_object() */
   16089          90 :                     $$ = (Node *) makeFuncCall(SystemFuncName("json_object"),
   16090          90 :                                                $3, COERCE_EXPLICIT_CALL, @1);
   16091             :                 }
   16092             :             | JSON_OBJECT '(' json_name_and_value_list
   16093             :                 json_object_constructor_null_clause_opt
   16094             :                 json_key_uniqueness_constraint_opt
   16095             :                 json_returning_clause_opt ')'
   16096             :                 {
   16097         342 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   16098             : 
   16099         342 :                     n->exprs = $3;
   16100         342 :                     n->absent_on_null = $4;
   16101         342 :                     n->unique = $5;
   16102         342 :                     n->output = (JsonOutput *) $6;
   16103         342 :                     n->location = @1;
   16104         342 :                     $$ = (Node *) n;
   16105             :                 }
   16106             :             | JSON_OBJECT '(' json_returning_clause_opt ')'
   16107             :                 {
   16108          92 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   16109             : 
   16110          92 :                     n->exprs = NULL;
   16111          92 :                     n->absent_on_null = false;
   16112          92 :                     n->unique = false;
   16113          92 :                     n->output = (JsonOutput *) $3;
   16114          92 :                     n->location = @1;
   16115          92 :                     $$ = (Node *) n;
   16116             :                 }
   16117             :             | JSON_ARRAY '('
   16118             :                 json_value_expr_list
   16119             :                 json_array_constructor_null_clause_opt
   16120             :                 json_returning_clause_opt
   16121             :             ')'
   16122             :                 {
   16123         108 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   16124             : 
   16125         108 :                     n->exprs = $3;
   16126         108 :                     n->absent_on_null = $4;
   16127         108 :                     n->output = (JsonOutput *) $5;
   16128         108 :                     n->location = @1;
   16129         108 :                     $$ = (Node *) n;
   16130             :                 }
   16131             :             | JSON_ARRAY '('
   16132             :                 select_no_parens
   16133             :                 json_format_clause_opt
   16134             :                 /* json_array_constructor_null_clause_opt */
   16135             :                 json_returning_clause_opt
   16136             :             ')'
   16137             :                 {
   16138          54 :                     JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
   16139             : 
   16140          54 :                     n->query = $3;
   16141          54 :                     n->format = (JsonFormat *) $4;
   16142          54 :                     n->absent_on_null = true;    /* XXX */
   16143          54 :                     n->output = (JsonOutput *) $5;
   16144          54 :                     n->location = @1;
   16145          54 :                     $$ = (Node *) n;
   16146             :                 }
   16147             :             | JSON_ARRAY '('
   16148             :                 json_returning_clause_opt
   16149             :             ')'
   16150             :                 {
   16151          86 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   16152             : 
   16153          86 :                     n->exprs = NIL;
   16154          86 :                     n->absent_on_null = true;
   16155          86 :                     n->output = (JsonOutput *) $3;
   16156          86 :                     n->location = @1;
   16157          86 :                     $$ = (Node *) n;
   16158             :                 }
   16159             :             | JSON '(' json_value_expr json_key_uniqueness_constraint_opt ')'
   16160             :                 {
   16161         164 :                     JsonParseExpr *n = makeNode(JsonParseExpr);
   16162             : 
   16163         164 :                     n->expr = (JsonValueExpr *) $3;
   16164         164 :                     n->unique_keys = $4;
   16165         164 :                     n->output = NULL;
   16166         164 :                     n->location = @1;
   16167         164 :                     $$ = (Node *) n;
   16168             :                 }
   16169             :             | JSON_SCALAR '(' a_expr ')'
   16170             :                 {
   16171         112 :                     JsonScalarExpr *n = makeNode(JsonScalarExpr);
   16172             : 
   16173         112 :                     n->expr = (Expr *) $3;
   16174         112 :                     n->output = NULL;
   16175         112 :                     n->location = @1;
   16176         112 :                     $$ = (Node *) n;
   16177             :                 }
   16178             :             | JSON_SERIALIZE '(' json_value_expr json_returning_clause_opt ')'
   16179             :                 {
   16180         108 :                     JsonSerializeExpr *n = makeNode(JsonSerializeExpr);
   16181             : 
   16182         108 :                     n->expr = (JsonValueExpr *) $3;
   16183         108 :                     n->output = (JsonOutput *) $4;
   16184         108 :                     n->location = @1;
   16185         108 :                     $$ = (Node *) n;
   16186             :                 }
   16187             :             | MERGE_ACTION '(' ')'
   16188             :                 {
   16189         180 :                     MergeSupportFunc *m = makeNode(MergeSupportFunc);
   16190             : 
   16191         180 :                     m->msftype = TEXTOID;
   16192         180 :                     m->location = @1;
   16193         180 :                     $$ = (Node *) m;
   16194             :                 }
   16195             :             | JSON_QUERY '('
   16196             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16197             :                 json_returning_clause_opt
   16198             :                 json_wrapper_behavior
   16199             :                 json_quotes_clause_opt
   16200             :                 json_behavior_clause_opt
   16201             :             ')'
   16202             :                 {
   16203         984 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16204             : 
   16205         984 :                     n->op = JSON_QUERY_OP;
   16206         984 :                     n->context_item = (JsonValueExpr *) $3;
   16207         984 :                     n->pathspec = $5;
   16208         984 :                     n->passing = $6;
   16209         984 :                     n->output = (JsonOutput *) $7;
   16210         984 :                     n->wrapper = $8;
   16211         984 :                     n->quotes = $9;
   16212         984 :                     n->on_empty = (JsonBehavior *) linitial($10);
   16213         984 :                     n->on_error = (JsonBehavior *) lsecond($10);
   16214         984 :                     n->location = @1;
   16215         984 :                     $$ = (Node *) n;
   16216             :                 }
   16217             :             | JSON_EXISTS '('
   16218             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16219             :                 json_on_error_clause_opt
   16220             :             ')'
   16221             :                 {
   16222         168 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16223             : 
   16224         168 :                     n->op = JSON_EXISTS_OP;
   16225         168 :                     n->context_item = (JsonValueExpr *) $3;
   16226         168 :                     n->pathspec = $5;
   16227         168 :                     n->passing = $6;
   16228         168 :                     n->output = NULL;
   16229         168 :                     n->on_error = (JsonBehavior *) $7;
   16230         168 :                     n->location = @1;
   16231         168 :                     $$ = (Node *) n;
   16232             :                 }
   16233             :             | JSON_VALUE '('
   16234             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16235             :                 json_returning_clause_opt
   16236             :                 json_behavior_clause_opt
   16237             :             ')'
   16238             :                 {
   16239         576 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16240             : 
   16241         576 :                     n->op = JSON_VALUE_OP;
   16242         576 :                     n->context_item = (JsonValueExpr *) $3;
   16243         576 :                     n->pathspec = $5;
   16244         576 :                     n->passing = $6;
   16245         576 :                     n->output = (JsonOutput *) $7;
   16246         576 :                     n->on_empty = (JsonBehavior *) linitial($8);
   16247         576 :                     n->on_error = (JsonBehavior *) lsecond($8);
   16248         576 :                     n->location = @1;
   16249         576 :                     $$ = (Node *) n;
   16250             :                 }
   16251             :             ;
   16252             : 
   16253             : 
   16254             : /*
   16255             :  * SQL/XML support
   16256             :  */
   16257             : xml_root_version: VERSION_P a_expr
   16258          24 :                 { $$ = $2; }
   16259             :             | VERSION_P NO VALUE_P
   16260          44 :                 { $$ = makeNullAConst(-1); }
   16261             :         ;
   16262             : 
   16263             : opt_xml_root_standalone: ',' STANDALONE_P YES_P
   16264          26 :                 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
   16265             :             | ',' STANDALONE_P NO
   16266          12 :                 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
   16267             :             | ',' STANDALONE_P NO VALUE_P
   16268          12 :                 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
   16269             :             | /*EMPTY*/
   16270          18 :                 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
   16271             :         ;
   16272             : 
   16273          56 : xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')'    { $$ = $3; }
   16274             :         ;
   16275             : 
   16276          88 : xml_attribute_list: xml_attribute_el                    { $$ = list_make1($1); }
   16277         144 :             | xml_attribute_list ',' xml_attribute_el   { $$ = lappend($1, $3); }
   16278             :         ;
   16279             : 
   16280             : xml_attribute_el: a_expr AS ColLabel
   16281             :                 {
   16282         106 :                     $$ = makeNode(ResTarget);
   16283         106 :                     $$->name = $3;
   16284         106 :                     $$->indirection = NIL;
   16285         106 :                     $$->val = (Node *) $1;
   16286         106 :                     $$->location = @1;
   16287             :                 }
   16288             :             | a_expr
   16289             :                 {
   16290         126 :                     $$ = makeNode(ResTarget);
   16291         126 :                     $$->name = NULL;
   16292         126 :                     $$->indirection = NIL;
   16293         126 :                     $$->val = (Node *) $1;
   16294         126 :                     $$->location = @1;
   16295             :                 }
   16296             :         ;
   16297             : 
   16298         170 : document_or_content: DOCUMENT_P                     { $$ = XMLOPTION_DOCUMENT; }
   16299         188 :             | CONTENT_P                             { $$ = XMLOPTION_CONTENT; }
   16300             :         ;
   16301             : 
   16302         132 : xml_indent_option: INDENT                           { $$ = true; }
   16303          24 :             | NO INDENT                             { $$ = false; }
   16304          46 :             | /*EMPTY*/                             { $$ = false; }
   16305             :         ;
   16306             : 
   16307           0 : xml_whitespace_option: PRESERVE WHITESPACE_P        { $$ = true; }
   16308           2 :             | STRIP_P WHITESPACE_P                  { $$ = false; }
   16309         138 :             | /*EMPTY*/                             { $$ = false; }
   16310             :         ;
   16311             : 
   16312             : /* We allow several variants for SQL and other compatibility. */
   16313             : xmlexists_argument:
   16314             :             PASSING c_expr
   16315             :                 {
   16316         226 :                     $$ = $2;
   16317             :                 }
   16318             :             | PASSING c_expr xml_passing_mech
   16319             :                 {
   16320           0 :                     $$ = $2;
   16321             :                 }
   16322             :             | PASSING xml_passing_mech c_expr
   16323             :                 {
   16324          42 :                     $$ = $3;
   16325             :                 }
   16326             :             | PASSING xml_passing_mech c_expr xml_passing_mech
   16327             :                 {
   16328           6 :                     $$ = $3;
   16329             :                 }
   16330             :         ;
   16331             : 
   16332             : xml_passing_mech:
   16333             :             BY REF_P
   16334             :             | BY VALUE_P
   16335             :         ;
   16336             : 
   16337             : 
   16338             : /*
   16339             :  * Aggregate decoration clauses
   16340             :  */
   16341             : within_group_clause:
   16342         348 :             WITHIN GROUP_P '(' sort_clause ')'      { $$ = $4; }
   16343      309770 :             | /*EMPTY*/                             { $$ = NIL; }
   16344             :         ;
   16345             : 
   16346             : filter_clause:
   16347         836 :             FILTER '(' WHERE a_expr ')'             { $$ = $4; }
   16348      309642 :             | /*EMPTY*/                             { $$ = NULL; }
   16349             :         ;
   16350             : 
   16351             : 
   16352             : /*
   16353             :  * Window Definitions
   16354             :  */
   16355             : window_clause:
   16356         528 :             WINDOW window_definition_list           { $$ = $2; }
   16357      474068 :             | /*EMPTY*/                             { $$ = NIL; }
   16358             :         ;
   16359             : 
   16360             : window_definition_list:
   16361         528 :             window_definition                       { $$ = list_make1($1); }
   16362             :             | window_definition_list ',' window_definition
   16363          12 :                                                     { $$ = lappend($1, $3); }
   16364             :         ;
   16365             : 
   16366             : window_definition:
   16367             :             ColId AS window_specification
   16368             :                 {
   16369         540 :                     WindowDef  *n = $3;
   16370             : 
   16371         540 :                     n->name = $1;
   16372         540 :                     $$ = n;
   16373             :                 }
   16374             :         ;
   16375             : 
   16376             : over_clause: OVER window_specification
   16377        2518 :                 { $$ = $2; }
   16378             :             | OVER ColId
   16379             :                 {
   16380         942 :                     WindowDef  *n = makeNode(WindowDef);
   16381             : 
   16382         942 :                     n->name = $2;
   16383         942 :                     n->refname = NULL;
   16384         942 :                     n->partitionClause = NIL;
   16385         942 :                     n->orderClause = NIL;
   16386         942 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   16387         942 :                     n->startOffset = NULL;
   16388         942 :                     n->endOffset = NULL;
   16389         942 :                     n->location = @2;
   16390         942 :                     $$ = n;
   16391             :                 }
   16392             :             | /*EMPTY*/
   16393      307012 :                 { $$ = NULL; }
   16394             :         ;
   16395             : 
   16396             : window_specification: '(' opt_existing_window_name opt_partition_clause
   16397             :                         opt_sort_clause opt_frame_clause ')'
   16398             :                 {
   16399        3058 :                     WindowDef  *n = makeNode(WindowDef);
   16400             : 
   16401        3058 :                     n->name = NULL;
   16402        3058 :                     n->refname = $2;
   16403        3058 :                     n->partitionClause = $3;
   16404        3058 :                     n->orderClause = $4;
   16405             :                     /* copy relevant fields of opt_frame_clause */
   16406        3058 :                     n->frameOptions = $5->frameOptions;
   16407        3058 :                     n->startOffset = $5->startOffset;
   16408        3058 :                     n->endOffset = $5->endOffset;
   16409        3058 :                     n->location = @1;
   16410        3058 :                     $$ = n;
   16411             :                 }
   16412             :         ;
   16413             : 
   16414             : /*
   16415             :  * If we see PARTITION, RANGE, ROWS or GROUPS as the first token after the '('
   16416             :  * of a window_specification, we want the assumption to be that there is
   16417             :  * no existing_window_name; but those keywords are unreserved and so could
   16418             :  * be ColIds.  We fix this by making them have the same precedence as IDENT
   16419             :  * and giving the empty production here a slightly higher precedence, so
   16420             :  * that the shift/reduce conflict is resolved in favor of reducing the rule.
   16421             :  * These keywords are thus precluded from being an existing_window_name but
   16422             :  * are not reserved for any other purpose.
   16423             :  */
   16424          30 : opt_existing_window_name: ColId                     { $$ = $1; }
   16425        3034 :             | /*EMPTY*/             %prec Op        { $$ = NULL; }
   16426             :         ;
   16427             : 
   16428         850 : opt_partition_clause: PARTITION BY expr_list        { $$ = $3; }
   16429        2208 :             | /*EMPTY*/                             { $$ = NIL; }
   16430             :         ;
   16431             : 
   16432             : /*
   16433             :  * For frame clauses, we return a WindowDef, but only some fields are used:
   16434             :  * frameOptions, startOffset, and endOffset.
   16435             :  */
   16436             : opt_frame_clause:
   16437             :             RANGE frame_extent opt_window_exclusion_clause
   16438             :                 {
   16439         796 :                     WindowDef  *n = $2;
   16440             : 
   16441         796 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
   16442         796 :                     n->frameOptions |= $3;
   16443         796 :                     $$ = n;
   16444             :                 }
   16445             :             | ROWS frame_extent opt_window_exclusion_clause
   16446             :                 {
   16447         618 :                     WindowDef  *n = $2;
   16448             : 
   16449         618 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
   16450         618 :                     n->frameOptions |= $3;
   16451         618 :                     $$ = n;
   16452             :                 }
   16453             :             | GROUPS frame_extent opt_window_exclusion_clause
   16454             :                 {
   16455         204 :                     WindowDef  *n = $2;
   16456             : 
   16457         204 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_GROUPS;
   16458         204 :                     n->frameOptions |= $3;
   16459         204 :                     $$ = n;
   16460             :                 }
   16461             :             | /*EMPTY*/
   16462             :                 {
   16463        1440 :                     WindowDef  *n = makeNode(WindowDef);
   16464             : 
   16465        1440 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   16466        1440 :                     n->startOffset = NULL;
   16467        1440 :                     n->endOffset = NULL;
   16468        1440 :                     $$ = n;
   16469             :                 }
   16470             :         ;
   16471             : 
   16472             : frame_extent: frame_bound
   16473             :                 {
   16474           6 :                     WindowDef  *n = $1;
   16475             : 
   16476             :                     /* reject invalid cases */
   16477           6 :                     if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   16478           0 :                         ereport(ERROR,
   16479             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16480             :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   16481             :                                  parser_errposition(@1)));
   16482           6 :                     if (n->frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING)
   16483           0 :                         ereport(ERROR,
   16484             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16485             :                                  errmsg("frame starting from following row cannot end with current row"),
   16486             :                                  parser_errposition(@1)));
   16487           6 :                     n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
   16488           6 :                     $$ = n;
   16489             :                 }
   16490             :             | BETWEEN frame_bound AND frame_bound
   16491             :                 {
   16492        1612 :                     WindowDef  *n1 = $2;
   16493        1612 :                     WindowDef  *n2 = $4;
   16494             : 
   16495             :                     /* form merged options */
   16496        1612 :                     int     frameOptions = n1->frameOptions;
   16497             :                     /* shift converts START_ options to END_ options */
   16498        1612 :                     frameOptions |= n2->frameOptions << 1;
   16499        1612 :                     frameOptions |= FRAMEOPTION_BETWEEN;
   16500             :                     /* reject invalid cases */
   16501        1612 :                     if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   16502           0 :                         ereport(ERROR,
   16503             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16504             :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   16505             :                                  parser_errposition(@2)));
   16506        1612 :                     if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
   16507           0 :                         ereport(ERROR,
   16508             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16509             :                                  errmsg("frame end cannot be UNBOUNDED PRECEDING"),
   16510             :                                  parser_errposition(@4)));
   16511        1612 :                     if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
   16512         460 :                         (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING))
   16513           0 :                         ereport(ERROR,
   16514             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16515             :                                  errmsg("frame starting from current row cannot have preceding rows"),
   16516             :                                  parser_errposition(@4)));
   16517        1612 :                     if ((frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING) &&
   16518         168 :                         (frameOptions & (FRAMEOPTION_END_OFFSET_PRECEDING |
   16519             :                                          FRAMEOPTION_END_CURRENT_ROW)))
   16520           0 :                         ereport(ERROR,
   16521             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16522             :                                  errmsg("frame starting from following row cannot have preceding rows"),
   16523             :                                  parser_errposition(@4)));
   16524        1612 :                     n1->frameOptions = frameOptions;
   16525        1612 :                     n1->endOffset = n2->startOffset;
   16526        1612 :                     $$ = n1;
   16527             :                 }
   16528             :         ;
   16529             : 
   16530             : /*
   16531             :  * This is used for both frame start and frame end, with output set up on
   16532             :  * the assumption it's frame start; the frame_extent productions must reject
   16533             :  * invalid cases.
   16534             :  */
   16535             : frame_bound:
   16536             :             UNBOUNDED PRECEDING
   16537             :                 {
   16538         198 :                     WindowDef  *n = makeNode(WindowDef);
   16539             : 
   16540         198 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
   16541         198 :                     n->startOffset = NULL;
   16542         198 :                     n->endOffset = NULL;
   16543         198 :                     $$ = n;
   16544             :                 }
   16545             :             | UNBOUNDED FOLLOWING
   16546             :                 {
   16547         376 :                     WindowDef  *n = makeNode(WindowDef);
   16548             : 
   16549         376 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
   16550         376 :                     n->startOffset = NULL;
   16551         376 :                     n->endOffset = NULL;
   16552         376 :                     $$ = n;
   16553             :                 }
   16554             :             | CURRENT_P ROW
   16555             :                 {
   16556         604 :                     WindowDef  *n = makeNode(WindowDef);
   16557             : 
   16558         604 :                     n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
   16559         604 :                     n->startOffset = NULL;
   16560         604 :                     n->endOffset = NULL;
   16561         604 :                     $$ = n;
   16562             :                 }
   16563             :             | a_expr PRECEDING
   16564             :                 {
   16565         900 :                     WindowDef  *n = makeNode(WindowDef);
   16566             : 
   16567         900 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_PRECEDING;
   16568         900 :                     n->startOffset = $1;
   16569         900 :                     n->endOffset = NULL;
   16570         900 :                     $$ = n;
   16571             :                 }
   16572             :             | a_expr FOLLOWING
   16573             :                 {
   16574        1152 :                     WindowDef  *n = makeNode(WindowDef);
   16575             : 
   16576        1152 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_FOLLOWING;
   16577        1152 :                     n->startOffset = $1;
   16578        1152 :                     n->endOffset = NULL;
   16579        1152 :                     $$ = n;
   16580             :                 }
   16581             :         ;
   16582             : 
   16583             : opt_window_exclusion_clause:
   16584          84 :             EXCLUDE CURRENT_P ROW   { $$ = FRAMEOPTION_EXCLUDE_CURRENT_ROW; }
   16585          96 :             | EXCLUDE GROUP_P       { $$ = FRAMEOPTION_EXCLUDE_GROUP; }
   16586         150 :             | EXCLUDE TIES          { $$ = FRAMEOPTION_EXCLUDE_TIES; }
   16587          18 :             | EXCLUDE NO OTHERS     { $$ = 0; }
   16588        1270 :             | /*EMPTY*/             { $$ = 0; }
   16589             :         ;
   16590             : 
   16591             : 
   16592             : /*
   16593             :  * Supporting nonterminals for expressions.
   16594             :  */
   16595             : 
   16596             : /* Explicit row production.
   16597             :  *
   16598             :  * SQL99 allows an optional ROW keyword, so we can now do single-element rows
   16599             :  * without conflicting with the parenthesized a_expr production.  Without the
   16600             :  * ROW keyword, there must be more than one a_expr inside the parens.
   16601             :  */
   16602           0 : row:        ROW '(' expr_list ')'                   { $$ = $3; }
   16603           0 :             | ROW '(' ')'                           { $$ = NIL; }
   16604        1752 :             | '(' expr_list ',' a_expr ')'          { $$ = lappend($2, $4); }
   16605             :         ;
   16606             : 
   16607        3864 : explicit_row:   ROW '(' expr_list ')'               { $$ = $3; }
   16608          30 :             | ROW '(' ')'                           { $$ = NIL; }
   16609             :         ;
   16610             : 
   16611        2432 : implicit_row:   '(' expr_list ',' a_expr ')'        { $$ = lappend($2, $4); }
   16612             :         ;
   16613             : 
   16614       15214 : sub_type:   ANY                                     { $$ = ANY_SUBLINK; }
   16615           0 :             | SOME                                  { $$ = ANY_SUBLINK; }
   16616         324 :             | ALL                                   { $$ = ALL_SUBLINK; }
   16617             :         ;
   16618             : 
   16619       11016 : all_Op:     Op                                      { $$ = $1; }
   16620       25420 :             | MathOp                                { $$ = $1; }
   16621             :         ;
   16622             : 
   16623          40 : MathOp:      '+'                                    { $$ = "+"; }
   16624          46 :             | '-'                                   { $$ = "-"; }
   16625          12 :             | '*'                                   { $$ = "*"; }
   16626           0 :             | '/'                                   { $$ = "/"; }
   16627           8 :             | '%'                                   { $$ = "%"; }
   16628           0 :             | '^'                                   { $$ = "^"; }
   16629         752 :             | '<'                                    { $$ = "<"; }
   16630         594 :             | '>'                                    { $$ = ">"; }
   16631       22160 :             | '='                                   { $$ = "="; }
   16632         618 :             | LESS_EQUALS                           { $$ = "<="; }
   16633         610 :             | GREATER_EQUALS                        { $$ = ">="; }
   16634         580 :             | NOT_EQUALS                            { $$ = "<>"; }
   16635             :         ;
   16636             : 
   16637             : qual_Op:    Op
   16638       41548 :                     { $$ = list_make1(makeString($1)); }
   16639             :             | OPERATOR '(' any_operator ')'
   16640       14434 :                     { $$ = $3; }
   16641             :         ;
   16642             : 
   16643             : qual_all_Op:
   16644             :             all_Op
   16645        1414 :                     { $$ = list_make1(makeString($1)); }
   16646             :             | OPERATOR '(' any_operator ')'
   16647          34 :                     { $$ = $3; }
   16648             :         ;
   16649             : 
   16650             : subquery_Op:
   16651             :             all_Op
   16652       15270 :                     { $$ = list_make1(makeString($1)); }
   16653             :             | OPERATOR '(' any_operator ')'
   16654         236 :                     { $$ = $3; }
   16655             :             | LIKE
   16656          24 :                     { $$ = list_make1(makeString("~~")); }
   16657             :             | NOT_LA LIKE
   16658          12 :                     { $$ = list_make1(makeString("!~~")); }
   16659             :             | ILIKE
   16660          12 :                     { $$ = list_make1(makeString("~~*")); }
   16661             :             | NOT_LA ILIKE
   16662           0 :                     { $$ = list_make1(makeString("!~~*")); }
   16663             : /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
   16664             :  * the regular expression is preprocessed by a function (similar_to_escape),
   16665             :  * and the ~ operator for posix regular expressions is used.
   16666             :  *        x SIMILAR TO y     ->    x ~ similar_to_escape(y)
   16667             :  * this transformation is made on the fly by the parser upwards.
   16668             :  * however the SubLink structure which handles any/some/all stuff
   16669             :  * is not ready for such a thing.
   16670             :  */
   16671             :             ;
   16672             : 
   16673             : expr_list:  a_expr
   16674             :                 {
   16675      157288 :                     $$ = list_make1($1);
   16676             :                 }
   16677             :             | expr_list ',' a_expr
   16678             :                 {
   16679      142054 :                     $$ = lappend($1, $3);
   16680             :                 }
   16681             :         ;
   16682             : 
   16683             : /* function arguments can have names */
   16684             : func_arg_list:  func_arg_expr
   16685             :                 {
   16686      296890 :                     $$ = list_make1($1);
   16687             :                 }
   16688             :             | func_arg_list ',' func_arg_expr
   16689             :                 {
   16690      221848 :                     $$ = lappend($1, $3);
   16691             :                 }
   16692             :         ;
   16693             : 
   16694             : func_arg_expr:  a_expr
   16695             :                 {
   16696      468798 :                     $$ = $1;
   16697             :                 }
   16698             :             | param_name COLON_EQUALS a_expr
   16699             :                 {
   16700       48058 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   16701             : 
   16702       48058 :                     na->name = $1;
   16703       48058 :                     na->arg = (Expr *) $3;
   16704       48058 :                     na->argnumber = -1;      /* until determined */
   16705       48058 :                     na->location = @1;
   16706       48058 :                     $$ = (Node *) na;
   16707             :                 }
   16708             :             | param_name EQUALS_GREATER a_expr
   16709             :                 {
   16710        2596 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   16711             : 
   16712        2596 :                     na->name = $1;
   16713        2596 :                     na->arg = (Expr *) $3;
   16714        2596 :                     na->argnumber = -1;      /* until determined */
   16715        2596 :                     na->location = @1;
   16716        2596 :                     $$ = (Node *) na;
   16717             :                 }
   16718             :         ;
   16719             : 
   16720         198 : func_arg_list_opt:  func_arg_list                   { $$ = $1; }
   16721           0 :             | /*EMPTY*/                             { $$ = NIL; }
   16722             :         ;
   16723             : 
   16724        1700 : type_list:  Typename                                { $$ = list_make1($1); }
   16725         392 :             | type_list ',' Typename                { $$ = lappend($1, $3); }
   16726             :         ;
   16727             : 
   16728             : array_expr: '[' expr_list ']'
   16729             :                 {
   16730        7388 :                     $$ = makeAArrayExpr($2, @1);
   16731             :                 }
   16732             :             | '[' array_expr_list ']'
   16733             :                 {
   16734         406 :                     $$ = makeAArrayExpr($2, @1);
   16735             :                 }
   16736             :             | '[' ']'
   16737             :                 {
   16738          88 :                     $$ = makeAArrayExpr(NIL, @1);
   16739             :                 }
   16740             :         ;
   16741             : 
   16742         406 : array_expr_list: array_expr                         { $$ = list_make1($1); }
   16743         330 :             | array_expr_list ',' array_expr        { $$ = lappend($1, $3); }
   16744             :         ;
   16745             : 
   16746             : 
   16747             : extract_list:
   16748             :             extract_arg FROM a_expr
   16749             :                 {
   16750        1282 :                     $$ = list_make2(makeStringConst($1, @1), $3);
   16751             :                 }
   16752             :         ;
   16753             : 
   16754             : /* Allow delimited string Sconst in extract_arg as an SQL extension.
   16755             :  * - thomas 2001-04-12
   16756             :  */
   16757             : extract_arg:
   16758        1036 :             IDENT                                   { $$ = $1; }
   16759          60 :             | YEAR_P                                { $$ = "year"; }
   16760          42 :             | MONTH_P                               { $$ = "month"; }
   16761          54 :             | DAY_P                                 { $$ = "day"; }
   16762          30 :             | HOUR_P                                { $$ = "hour"; }
   16763          30 :             | MINUTE_P                              { $$ = "minute"; }
   16764          30 :             | SECOND_P                              { $$ = "second"; }
   16765           0 :             | Sconst                                { $$ = $1; }
   16766             :         ;
   16767             : 
   16768             : unicode_normal_form:
   16769          24 :             NFC                                     { $$ = "NFC"; }
   16770          12 :             | NFD                                   { $$ = "NFD"; }
   16771          18 :             | NFKC                                  { $$ = "NFKC"; }
   16772          18 :             | NFKD                                  { $$ = "NFKD"; }
   16773             :         ;
   16774             : 
   16775             : /* OVERLAY() arguments */
   16776             : overlay_list:
   16777             :             a_expr PLACING a_expr FROM a_expr FOR a_expr
   16778             :                 {
   16779             :                     /* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D) */
   16780          34 :                     $$ = list_make4($1, $3, $5, $7);
   16781             :                 }
   16782             :             | a_expr PLACING a_expr FROM a_expr
   16783             :                 {
   16784             :                     /* overlay(A PLACING B FROM C) is converted to overlay(A, B, C) */
   16785          48 :                     $$ = list_make3($1, $3, $5);
   16786             :                 }
   16787             :         ;
   16788             : 
   16789             : /* position_list uses b_expr not a_expr to avoid conflict with general IN */
   16790             : position_list:
   16791         360 :             b_expr IN_P b_expr                      { $$ = list_make2($3, $1); }
   16792             :         ;
   16793             : 
   16794             : /*
   16795             :  * SUBSTRING() arguments
   16796             :  *
   16797             :  * Note that SQL:1999 has both
   16798             :  *     text FROM int FOR int
   16799             :  * and
   16800             :  *     text FROM pattern FOR escape
   16801             :  *
   16802             :  * In the parser we map them both to a call to the substring() function and
   16803             :  * rely on type resolution to pick the right one.
   16804             :  *
   16805             :  * In SQL:2003, the second variant was changed to
   16806             :  *     text SIMILAR pattern ESCAPE escape
   16807             :  * We could in theory map that to a different function internally, but
   16808             :  * since we still support the SQL:1999 version, we don't.  However,
   16809             :  * ruleutils.c will reverse-list the call in the newer style.
   16810             :  */
   16811             : substr_list:
   16812             :             a_expr FROM a_expr FOR a_expr
   16813             :                 {
   16814         122 :                     $$ = list_make3($1, $3, $5);
   16815             :                 }
   16816             :             | a_expr FOR a_expr FROM a_expr
   16817             :                 {
   16818             :                     /* not legal per SQL, but might as well allow it */
   16819           0 :                     $$ = list_make3($1, $5, $3);
   16820             :                 }
   16821             :             | a_expr FROM a_expr
   16822             :                 {
   16823             :                     /*
   16824             :                      * Because we aren't restricting data types here, this
   16825             :                      * syntax can end up resolving to textregexsubstr().
   16826             :                      * We've historically allowed that to happen, so continue
   16827             :                      * to accept it.  However, ruleutils.c will reverse-list
   16828             :                      * such a call in regular function call syntax.
   16829             :                      */
   16830         340 :                     $$ = list_make2($1, $3);
   16831             :                 }
   16832             :             | a_expr FOR a_expr
   16833             :                 {
   16834             :                     /* not legal per SQL */
   16835             : 
   16836             :                     /*
   16837             :                      * Since there are no cases where this syntax allows
   16838             :                      * a textual FOR value, we forcibly cast the argument
   16839             :                      * to int4.  The possible matches in pg_proc are
   16840             :                      * substring(text,int4) and substring(text,text),
   16841             :                      * and we don't want the parser to choose the latter,
   16842             :                      * which it is likely to do if the second argument
   16843             :                      * is unknown or doesn't have an implicit cast to int4.
   16844             :                      */
   16845          36 :                     $$ = list_make3($1, makeIntConst(1, -1),
   16846             :                                     makeTypeCast($3,
   16847             :                                                  SystemTypeName("int4"), -1));
   16848             :                 }
   16849             :             | a_expr SIMILAR a_expr ESCAPE a_expr
   16850             :                 {
   16851         172 :                     $$ = list_make3($1, $3, $5);
   16852             :                 }
   16853             :         ;
   16854             : 
   16855         588 : trim_list:  a_expr FROM expr_list                   { $$ = lappend($3, $1); }
   16856          24 :             | FROM expr_list                        { $$ = $2; }
   16857          86 :             | expr_list                             { $$ = $1; }
   16858             :         ;
   16859             : 
   16860             : in_expr:    select_with_parens
   16861             :                 {
   16862        2538 :                     SubLink    *n = makeNode(SubLink);
   16863             : 
   16864        2538 :                     n->subselect = $1;
   16865             :                     /* other fields will be filled later */
   16866        2538 :                     $$ = (Node *) n;
   16867             :                 }
   16868       18494 :             | '(' expr_list ')'                     { $$ = (Node *) $2; }
   16869             :         ;
   16870             : 
   16871             : /*
   16872             :  * Define SQL-style CASE clause.
   16873             :  * - Full specification
   16874             :  *  CASE WHEN a = b THEN c ... ELSE d END
   16875             :  * - Implicit argument
   16876             :  *  CASE a WHEN b THEN c ... ELSE d END
   16877             :  */
   16878             : case_expr:  CASE case_arg when_clause_list case_default END_P
   16879             :                 {
   16880       54798 :                     CaseExpr   *c = makeNode(CaseExpr);
   16881             : 
   16882       54798 :                     c->casetype = InvalidOid; /* not analyzed yet */
   16883       54798 :                     c->arg = (Expr *) $2;
   16884       54798 :                     c->args = $3;
   16885       54798 :                     c->defresult = (Expr *) $4;
   16886       54798 :                     c->location = @1;
   16887       54798 :                     $$ = (Node *) c;
   16888             :                 }
   16889             :         ;
   16890             : 
   16891             : when_clause_list:
   16892             :             /* There must be at least one */
   16893       54798 :             when_clause                             { $$ = list_make1($1); }
   16894       43158 :             | when_clause_list when_clause          { $$ = lappend($1, $2); }
   16895             :         ;
   16896             : 
   16897             : when_clause:
   16898             :             WHEN a_expr THEN a_expr
   16899             :                 {
   16900       97956 :                     CaseWhen   *w = makeNode(CaseWhen);
   16901             : 
   16902       97956 :                     w->expr = (Expr *) $2;
   16903       97956 :                     w->result = (Expr *) $4;
   16904       97956 :                     w->location = @1;
   16905       97956 :                     $$ = (Node *) w;
   16906             :                 }
   16907             :         ;
   16908             : 
   16909             : case_default:
   16910       46272 :             ELSE a_expr                             { $$ = $2; }
   16911        8526 :             | /*EMPTY*/                             { $$ = NULL; }
   16912             :         ;
   16913             : 
   16914        5814 : case_arg:   a_expr                                  { $$ = $1; }
   16915       48984 :             | /*EMPTY*/                             { $$ = NULL; }
   16916             :         ;
   16917             : 
   16918             : columnref:  ColId
   16919             :                 {
   16920      660480 :                     $$ = makeColumnRef($1, NIL, @1, yyscanner);
   16921             :                 }
   16922             :             | ColId indirection
   16923             :                 {
   16924      963134 :                     $$ = makeColumnRef($1, $2, @1, yyscanner);
   16925             :                 }
   16926             :         ;
   16927             : 
   16928             : indirection_el:
   16929             :             '.' attr_name
   16930             :                 {
   16931     1302848 :                     $$ = (Node *) makeString($2);
   16932             :                 }
   16933             :             | '.' '*'
   16934             :                 {
   16935        6562 :                     $$ = (Node *) makeNode(A_Star);
   16936             :                 }
   16937             :             | '[' a_expr ']'
   16938             :                 {
   16939       12226 :                     A_Indices *ai = makeNode(A_Indices);
   16940             : 
   16941       12226 :                     ai->is_slice = false;
   16942       12226 :                     ai->lidx = NULL;
   16943       12226 :                     ai->uidx = $2;
   16944       12226 :                     $$ = (Node *) ai;
   16945             :                 }
   16946             :             | '[' opt_slice_bound ':' opt_slice_bound ']'
   16947             :                 {
   16948         570 :                     A_Indices *ai = makeNode(A_Indices);
   16949             : 
   16950         570 :                     ai->is_slice = true;
   16951         570 :                     ai->lidx = $2;
   16952         570 :                     ai->uidx = $4;
   16953         570 :                     $$ = (Node *) ai;
   16954             :                 }
   16955             :         ;
   16956             : 
   16957             : opt_slice_bound:
   16958         960 :             a_expr                                  { $$ = $1; }
   16959         180 :             | /*EMPTY*/                             { $$ = NULL; }
   16960             :         ;
   16961             : 
   16962             : indirection:
   16963     1303014 :             indirection_el                          { $$ = list_make1($1); }
   16964        2968 :             | indirection indirection_el            { $$ = lappend($1, $2); }
   16965             :         ;
   16966             : 
   16967             : opt_indirection:
   16968      286318 :             /*EMPTY*/                               { $$ = NIL; }
   16969       16224 :             | opt_indirection indirection_el        { $$ = lappend($1, $2); }
   16970             :         ;
   16971             : 
   16972             : opt_asymmetric: ASYMMETRIC
   16973             :             | /*EMPTY*/
   16974             :         ;
   16975             : 
   16976             : /* SQL/JSON support */
   16977             : json_passing_clause_opt:
   16978         336 :             PASSING json_arguments                  { $$ = $2; }
   16979        1934 :             | /*EMPTY*/                             { $$ = NIL; }
   16980             :         ;
   16981             : 
   16982             : json_arguments:
   16983         336 :             json_argument                           { $$ = list_make1($1); }
   16984         126 :             | json_arguments ',' json_argument      { $$ = lappend($1, $3); }
   16985             :         ;
   16986             : 
   16987             : json_argument:
   16988             :             json_value_expr AS ColLabel
   16989             :             {
   16990         462 :                 JsonArgument *n = makeNode(JsonArgument);
   16991             : 
   16992         462 :                 n->val = (JsonValueExpr *) $1;
   16993         462 :                 n->name = $3;
   16994         462 :                 $$ = (Node *) n;
   16995             :             }
   16996             :         ;
   16997             : 
   16998             : /* ARRAY is a noise word */
   16999             : json_wrapper_behavior:
   17000          42 :               WITHOUT WRAPPER                   { $$ = JSW_NONE; }
   17001           0 :             | WITHOUT ARRAY WRAPPER             { $$ = JSW_NONE; }
   17002          78 :             | WITH WRAPPER                      { $$ = JSW_UNCONDITIONAL; }
   17003          12 :             | WITH ARRAY WRAPPER                { $$ = JSW_UNCONDITIONAL; }
   17004           0 :             | WITH CONDITIONAL ARRAY WRAPPER    { $$ = JSW_CONDITIONAL; }
   17005          12 :             | WITH UNCONDITIONAL ARRAY WRAPPER  { $$ = JSW_UNCONDITIONAL; }
   17006          36 :             | WITH CONDITIONAL WRAPPER          { $$ = JSW_CONDITIONAL; }
   17007           6 :             | WITH UNCONDITIONAL WRAPPER        { $$ = JSW_UNCONDITIONAL; }
   17008        1634 :             | /* empty */                       { $$ = JSW_UNSPEC; }
   17009             :         ;
   17010             : 
   17011             : json_behavior:
   17012             :             DEFAULT a_expr
   17013         384 :                 { $$ = (Node *) makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); }
   17014             :             | json_behavior_type
   17015         702 :                 { $$ = (Node *) makeJsonBehavior($1, NULL, @1); }
   17016             :         ;
   17017             : 
   17018             : json_behavior_type:
   17019         492 :             ERROR_P     { $$ = JSON_BEHAVIOR_ERROR; }
   17020          30 :             | NULL_P    { $$ = JSON_BEHAVIOR_NULL; }
   17021          30 :             | TRUE_P    { $$ = JSON_BEHAVIOR_TRUE; }
   17022          12 :             | FALSE_P   { $$ = JSON_BEHAVIOR_FALSE; }
   17023          12 :             | UNKNOWN   { $$ = JSON_BEHAVIOR_UNKNOWN; }
   17024          30 :             | EMPTY_P ARRAY { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
   17025          72 :             | EMPTY_P OBJECT_P  { $$ = JSON_BEHAVIOR_EMPTY_OBJECT; }
   17026             :             /* non-standard, for Oracle compatibility only */
   17027          24 :             | EMPTY_P   { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
   17028             :         ;
   17029             : 
   17030             : json_behavior_clause_opt:
   17031             :             json_behavior ON EMPTY_P
   17032         174 :                 { $$ = list_make2($1, NULL); }
   17033             :             | json_behavior ON ERROR_P
   17034         552 :                 { $$ = list_make2(NULL, $1); }
   17035             :             | json_behavior ON EMPTY_P json_behavior ON ERROR_P
   17036         102 :                 { $$ = list_make2($1, $4); }
   17037             :             | /* EMPTY */
   17038        1568 :                 { $$ = list_make2(NULL, NULL); }
   17039             :         ;
   17040             : 
   17041             : json_on_error_clause_opt:
   17042             :             json_behavior ON ERROR_P
   17043         150 :                 { $$ = $1; }
   17044             :             | /* EMPTY */
   17045         686 :                 { $$ = NULL; }
   17046             :         ;
   17047             : 
   17048             : json_value_expr:
   17049             :             a_expr json_format_clause_opt
   17050             :             {
   17051             :                 /* formatted_expr will be set during parse-analysis. */
   17052        4196 :                 $$ = (Node *) makeJsonValueExpr((Expr *) $1, NULL,
   17053        4196 :                                                 castNode(JsonFormat, $2));
   17054             :             }
   17055             :         ;
   17056             : 
   17057             : json_format_clause:
   17058             :             FORMAT_LA JSON ENCODING name
   17059             :                 {
   17060             :                     int     encoding;
   17061             : 
   17062         100 :                     if (!pg_strcasecmp($4, "utf8"))
   17063          64 :                         encoding = JS_ENC_UTF8;
   17064          36 :                     else if (!pg_strcasecmp($4, "utf16"))
   17065          12 :                         encoding = JS_ENC_UTF16;
   17066          24 :                     else if (!pg_strcasecmp($4, "utf32"))
   17067          12 :                         encoding = JS_ENC_UTF32;
   17068             :                     else
   17069          12 :                         ereport(ERROR,
   17070             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   17071             :                                  errmsg("unrecognized JSON encoding: %s", $4),
   17072             :                                  parser_errposition(@4)));
   17073             : 
   17074          88 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
   17075             :                 }
   17076             :             | FORMAT_LA JSON
   17077             :                 {
   17078         412 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
   17079             :                 }
   17080             :         ;
   17081             : 
   17082             : json_format_clause_opt:
   17083             :             json_format_clause
   17084             :                 {
   17085         392 :                     $$ = $1;
   17086             :                 }
   17087             :             | /* EMPTY */
   17088             :                 {
   17089        5302 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   17090             :                 }
   17091             :         ;
   17092             : 
   17093             : json_quotes_clause_opt:
   17094          12 :             KEEP QUOTES ON SCALAR STRING_P      { $$ = JS_QUOTES_KEEP; }
   17095          90 :             | KEEP QUOTES                       { $$ = JS_QUOTES_KEEP; }
   17096          12 :             | OMIT QUOTES ON SCALAR STRING_P    { $$ = JS_QUOTES_OMIT; }
   17097         168 :             | OMIT QUOTES                       { $$ = JS_QUOTES_OMIT; }
   17098        1538 :             | /* EMPTY */                       { $$ = JS_QUOTES_UNSPEC; }
   17099             :         ;
   17100             : 
   17101             : json_returning_clause_opt:
   17102             :             RETURNING Typename json_format_clause_opt
   17103             :                 {
   17104        1444 :                     JsonOutput *n = makeNode(JsonOutput);
   17105             : 
   17106        1444 :                     n->typeName = $2;
   17107        1444 :                     n->returning = makeNode(JsonReturning);
   17108        1444 :                     n->returning->format = (JsonFormat *) $3;
   17109        1444 :                     $$ = (Node *) n;
   17110             :                 }
   17111        1266 :             | /* EMPTY */                           { $$ = NULL; }
   17112             :         ;
   17113             : 
   17114             : /*
   17115             :  * We must assign the only-JSON production a precedence less than IDENT in
   17116             :  * order to favor shifting over reduction when JSON is followed by VALUE_P,
   17117             :  * OBJECT_P, or SCALAR.  (ARRAY doesn't need that treatment, because it's a
   17118             :  * fully reserved word.)  Because json_predicate_type_constraint is always
   17119             :  * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
   17120             :  * production to have precedence less than WITH and WITHOUT.  UNBOUNDED isn't
   17121             :  * really related to this syntax, but it's a convenient choice because it
   17122             :  * already has a precedence less than IDENT for other reasons.
   17123             :  */
   17124             : json_predicate_type_constraint:
   17125         202 :             JSON                    %prec UNBOUNDED { $$ = JS_TYPE_ANY; }
   17126          28 :             | JSON VALUE_P                          { $$ = JS_TYPE_ANY; }
   17127          40 :             | JSON ARRAY                            { $$ = JS_TYPE_ARRAY; }
   17128          40 :             | JSON OBJECT_P                         { $$ = JS_TYPE_OBJECT; }
   17129          40 :             | JSON SCALAR                           { $$ = JS_TYPE_SCALAR; }
   17130             :         ;
   17131             : 
   17132             : /*
   17133             :  * KEYS is a noise word here.  To avoid shift/reduce conflicts, assign the
   17134             :  * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
   17135             :  * This prevents reducing them when the next token is KEYS.
   17136             :  */
   17137             : json_key_uniqueness_constraint_opt:
   17138         108 :             WITH UNIQUE KEYS                            { $$ = true; }
   17139         100 :             | WITH UNIQUE               %prec UNBOUNDED { $$ = true; }
   17140          44 :             | WITHOUT UNIQUE KEYS                       { $$ = false; }
   17141          16 :             | WITHOUT UNIQUE            %prec UNBOUNDED { $$ = false; }
   17142         792 :             | /* EMPTY */               %prec UNBOUNDED { $$ = false; }
   17143             :         ;
   17144             : 
   17145             : json_name_and_value_list:
   17146             :             json_name_and_value
   17147         342 :                 { $$ = list_make1($1); }
   17148             :             | json_name_and_value_list ',' json_name_and_value
   17149         256 :                 { $$ = lappend($1, $3); }
   17150             :         ;
   17151             : 
   17152             : json_name_and_value:
   17153             : /* Supporting this syntax seems to require major surgery
   17154             :             KEY c_expr VALUE_P json_value_expr
   17155             :                 { $$ = makeJsonKeyValue($2, $4); }
   17156             :             |
   17157             : */
   17158             :             c_expr VALUE_P json_value_expr
   17159          24 :                 { $$ = makeJsonKeyValue($1, $3); }
   17160             :             |
   17161             :             a_expr ':' json_value_expr
   17162         778 :                 { $$ = makeJsonKeyValue($1, $3); }
   17163             :         ;
   17164             : 
   17165             : /* empty means false for objects, true for arrays */
   17166             : json_object_constructor_null_clause_opt:
   17167          30 :             NULL_P ON NULL_P                    { $$ = false; }
   17168         110 :             | ABSENT ON NULL_P                  { $$ = true; }
   17169         406 :             | /* EMPTY */                       { $$ = false; }
   17170             :         ;
   17171             : 
   17172             : json_array_constructor_null_clause_opt:
   17173          60 :             NULL_P ON NULL_P                        { $$ = false; }
   17174          36 :             | ABSENT ON NULL_P                      { $$ = true; }
   17175         168 :             | /* EMPTY */                           { $$ = true; }
   17176             :         ;
   17177             : 
   17178             : json_value_expr_list:
   17179         108 :             json_value_expr                             { $$ = list_make1($1); }
   17180         126 :             | json_value_expr_list ',' json_value_expr  { $$ = lappend($1, $3);}
   17181             :         ;
   17182             : 
   17183             : json_aggregate_func:
   17184             :             JSON_OBJECTAGG '('
   17185             :                 json_name_and_value
   17186             :                 json_object_constructor_null_clause_opt
   17187             :                 json_key_uniqueness_constraint_opt
   17188             :                 json_returning_clause_opt
   17189             :             ')'
   17190             :                 {
   17191         204 :                     JsonObjectAgg *n = makeNode(JsonObjectAgg);
   17192             : 
   17193         204 :                     n->arg = (JsonKeyValue *) $3;
   17194         204 :                     n->absent_on_null = $4;
   17195         204 :                     n->unique = $5;
   17196         204 :                     n->constructor = makeNode(JsonAggConstructor);
   17197         204 :                     n->constructor->output = (JsonOutput *) $6;
   17198         204 :                     n->constructor->agg_order = NULL;
   17199         204 :                     n->constructor->location = @1;
   17200         204 :                     $$ = (Node *) n;
   17201             :                 }
   17202             :             | JSON_ARRAYAGG '('
   17203             :                 json_value_expr
   17204             :                 json_array_aggregate_order_by_clause_opt
   17205             :                 json_array_constructor_null_clause_opt
   17206             :                 json_returning_clause_opt
   17207             :             ')'
   17208             :                 {
   17209         156 :                     JsonArrayAgg *n = makeNode(JsonArrayAgg);
   17210             : 
   17211         156 :                     n->arg = (JsonValueExpr *) $3;
   17212         156 :                     n->absent_on_null = $5;
   17213         156 :                     n->constructor = makeNode(JsonAggConstructor);
   17214         156 :                     n->constructor->agg_order = $4;
   17215         156 :                     n->constructor->output = (JsonOutput *) $6;
   17216         156 :                     n->constructor->location = @1;
   17217         156 :                     $$ = (Node *) n;
   17218             :                 }
   17219             :         ;
   17220             : 
   17221             : json_array_aggregate_order_by_clause_opt:
   17222          18 :             ORDER BY sortby_list                    { $$ = $3; }
   17223         138 :             | /* EMPTY */                           { $$ = NIL; }
   17224             :         ;
   17225             : 
   17226             : /*****************************************************************************
   17227             :  *
   17228             :  *  target list for SELECT
   17229             :  *
   17230             :  *****************************************************************************/
   17231             : 
   17232      470944 : opt_target_list: target_list                        { $$ = $1; }
   17233         324 :             | /* EMPTY */                           { $$ = NIL; }
   17234             :         ;
   17235             : 
   17236             : target_list:
   17237      477318 :             target_el                               { $$ = list_make1($1); }
   17238      597912 :             | target_list ',' target_el             { $$ = lappend($1, $3); }
   17239             :         ;
   17240             : 
   17241             : target_el:  a_expr AS ColLabel
   17242             :                 {
   17243      200696 :                     $$ = makeNode(ResTarget);
   17244      200696 :                     $$->name = $3;
   17245      200696 :                     $$->indirection = NIL;
   17246      200696 :                     $$->val = (Node *) $1;
   17247      200696 :                     $$->location = @1;
   17248             :                 }
   17249             :             | a_expr BareColLabel
   17250             :                 {
   17251        3242 :                     $$ = makeNode(ResTarget);
   17252        3242 :                     $$->name = $2;
   17253        3242 :                     $$->indirection = NIL;
   17254        3242 :                     $$->val = (Node *) $1;
   17255        3242 :                     $$->location = @1;
   17256             :                 }
   17257             :             | a_expr
   17258             :                 {
   17259      820970 :                     $$ = makeNode(ResTarget);
   17260      820970 :                     $$->name = NULL;
   17261      820970 :                     $$->indirection = NIL;
   17262      820970 :                     $$->val = (Node *) $1;
   17263      820970 :                     $$->location = @1;
   17264             :                 }
   17265             :             | '*'
   17266             :                 {
   17267       50322 :                     ColumnRef  *n = makeNode(ColumnRef);
   17268             : 
   17269       50322 :                     n->fields = list_make1(makeNode(A_Star));
   17270       50322 :                     n->location = @1;
   17271             : 
   17272       50322 :                     $$ = makeNode(ResTarget);
   17273       50322 :                     $$->name = NULL;
   17274       50322 :                     $$->indirection = NIL;
   17275       50322 :                     $$->val = (Node *) n;
   17276       50322 :                     $$->location = @1;
   17277             :                 }
   17278             :         ;
   17279             : 
   17280             : 
   17281             : /*****************************************************************************
   17282             :  *
   17283             :  *  Names and constants
   17284             :  *
   17285             :  *****************************************************************************/
   17286             : 
   17287             : qualified_name_list:
   17288       15856 :             qualified_name                          { $$ = list_make1($1); }
   17289         398 :             | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
   17290             :         ;
   17291             : 
   17292             : /*
   17293             :  * The production for a qualified relation name has to exactly match the
   17294             :  * production for a qualified func_name, because in a FROM clause we cannot
   17295             :  * tell which we are parsing until we see what comes after it ('(' for a
   17296             :  * func_name, something else for a relation). Therefore we allow 'indirection'
   17297             :  * which may contain subscripts, and reject that case in the C code.
   17298             :  */
   17299             : qualified_name:
   17300             :             ColId
   17301             :                 {
   17302      391580 :                     $$ = makeRangeVar(NULL, $1, @1);
   17303             :                 }
   17304             :             | ColId indirection
   17305             :                 {
   17306      224942 :                     $$ = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   17307             :                 }
   17308             :         ;
   17309             : 
   17310             : name_list:  name
   17311       25400 :                     { $$ = list_make1(makeString($1)); }
   17312             :             | name_list ',' name
   17313       53832 :                     { $$ = lappend($1, makeString($3)); }
   17314             :         ;
   17315             : 
   17316             : 
   17317      156376 : name:       ColId                                   { $$ = $1; };
   17318             : 
   17319     1413368 : attr_name:  ColLabel                                { $$ = $1; };
   17320             : 
   17321          58 : file_name:  Sconst                                  { $$ = $1; };
   17322             : 
   17323             : /*
   17324             :  * The production for a qualified func_name has to exactly match the
   17325             :  * production for a qualified columnref, because we cannot tell which we
   17326             :  * are parsing until we see what comes after it ('(' or Sconst for a func_name,
   17327             :  * anything else for a columnref).  Therefore we allow 'indirection' which
   17328             :  * may contain subscripts, and reject that case in the C code.  (If we
   17329             :  * ever implement SQL99-like methods, such syntax may actually become legal!)
   17330             :  */
   17331             : func_name:  type_function_name
   17332      291294 :                     { $$ = list_make1(makeString($1)); }
   17333             :             | ColId indirection
   17334             :                     {
   17335      114860 :                         $$ = check_func_name(lcons(makeString($1), $2),
   17336             :                                              yyscanner);
   17337             :                     }
   17338             :         ;
   17339             : 
   17340             : 
   17341             : /*
   17342             :  * Constants
   17343             :  */
   17344             : AexprConst: Iconst
   17345             :                 {
   17346      423652 :                     $$ = makeIntConst($1, @1);
   17347             :                 }
   17348             :             | FCONST
   17349             :                 {
   17350       11804 :                     $$ = makeFloatConst($1, @1);
   17351             :                 }
   17352             :             | Sconst
   17353             :                 {
   17354      583128 :                     $$ = makeStringConst($1, @1);
   17355             :                 }
   17356             :             | BCONST
   17357             :                 {
   17358         754 :                     $$ = makeBitStringConst($1, @1);
   17359             :                 }
   17360             :             | XCONST
   17361             :                 {
   17362             :                     /* This is a bit constant per SQL99:
   17363             :                      * Without Feature F511, "BIT data type",
   17364             :                      * a <general literal> shall not be a
   17365             :                      * <bit string literal> or a <hex string literal>.
   17366             :                      */
   17367        3302 :                     $$ = makeBitStringConst($1, @1);
   17368             :                 }
   17369             :             | func_name Sconst
   17370             :                 {
   17371             :                     /* generic type 'literal' syntax */
   17372        9762 :                     TypeName   *t = makeTypeNameFromNameList($1);
   17373             : 
   17374        9762 :                     t->location = @1;
   17375        9762 :                     $$ = makeStringConstCast($2, @2, t);
   17376             :                 }
   17377             :             | func_name '(' func_arg_list opt_sort_clause ')' Sconst
   17378             :                 {
   17379             :                     /* generic syntax with a type modifier */
   17380           0 :                     TypeName   *t = makeTypeNameFromNameList($1);
   17381             :                     ListCell   *lc;
   17382             : 
   17383             :                     /*
   17384             :                      * We must use func_arg_list and opt_sort_clause in the
   17385             :                      * production to avoid reduce/reduce conflicts, but we
   17386             :                      * don't actually wish to allow NamedArgExpr in this
   17387             :                      * context, nor ORDER BY.
   17388             :                      */
   17389           0 :                     foreach(lc, $3)
   17390             :                     {
   17391           0 :                         NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
   17392             : 
   17393           0 :                         if (IsA(arg, NamedArgExpr))
   17394           0 :                             ereport(ERROR,
   17395             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17396             :                                      errmsg("type modifier cannot have parameter name"),
   17397             :                                      parser_errposition(arg->location)));
   17398             :                     }
   17399           0 :                     if ($4 != NIL)
   17400           0 :                             ereport(ERROR,
   17401             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17402             :                                      errmsg("type modifier cannot have ORDER BY"),
   17403             :                                      parser_errposition(@4)));
   17404             : 
   17405           0 :                     t->typmods = $3;
   17406           0 :                     t->location = @1;
   17407           0 :                     $$ = makeStringConstCast($6, @6, t);
   17408             :                 }
   17409             :             | ConstTypename Sconst
   17410             :                 {
   17411        3114 :                     $$ = makeStringConstCast($2, @2, $1);
   17412             :                 }
   17413             :             | ConstInterval Sconst opt_interval
   17414             :                 {
   17415        3298 :                     TypeName   *t = $1;
   17416             : 
   17417        3298 :                     t->typmods = $3;
   17418        3298 :                     $$ = makeStringConstCast($2, @2, t);
   17419             :                 }
   17420             :             | ConstInterval '(' Iconst ')' Sconst
   17421             :                 {
   17422          12 :                     TypeName   *t = $1;
   17423             : 
   17424          12 :                     t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   17425             :                                             makeIntConst($3, @3));
   17426          12 :                     $$ = makeStringConstCast($5, @5, t);
   17427             :                 }
   17428             :             | TRUE_P
   17429             :                 {
   17430       23338 :                     $$ = makeBoolAConst(true, @1);
   17431             :                 }
   17432             :             | FALSE_P
   17433             :                 {
   17434       32984 :                     $$ = makeBoolAConst(false, @1);
   17435             :                 }
   17436             :             | NULL_P
   17437             :                 {
   17438       62002 :                     $$ = makeNullAConst(@1);
   17439             :                 }
   17440             :         ;
   17441             : 
   17442      447248 : Iconst:     ICONST                                  { $$ = $1; };
   17443      651690 : Sconst:     SCONST                                  { $$ = $1; };
   17444             : 
   17445       15710 : SignedIconst: Iconst                                { $$ = $1; }
   17446           0 :             | '+' Iconst                            { $$ = + $2; }
   17447         266 :             | '-' Iconst                            { $$ = - $2; }
   17448             :         ;
   17449             : 
   17450             : /* Role specifications */
   17451             : RoleId:     RoleSpec
   17452             :                 {
   17453        1842 :                     RoleSpec   *spc = (RoleSpec *) $1;
   17454             : 
   17455        1842 :                     switch (spc->roletype)
   17456             :                     {
   17457        1832 :                         case ROLESPEC_CSTRING:
   17458        1832 :                             $$ = spc->rolename;
   17459        1832 :                             break;
   17460           4 :                         case ROLESPEC_PUBLIC:
   17461           4 :                             ereport(ERROR,
   17462             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17463             :                                      errmsg("role name \"%s\" is reserved",
   17464             :                                             "public"),
   17465             :                                      parser_errposition(@1)));
   17466             :                             break;
   17467           2 :                         case ROLESPEC_SESSION_USER:
   17468           2 :                             ereport(ERROR,
   17469             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17470             :                                      errmsg("%s cannot be used as a role name here",
   17471             :                                             "SESSION_USER"),
   17472             :                                      parser_errposition(@1)));
   17473             :                             break;
   17474           2 :                         case ROLESPEC_CURRENT_USER:
   17475           2 :                             ereport(ERROR,
   17476             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17477             :                                      errmsg("%s cannot be used as a role name here",
   17478             :                                             "CURRENT_USER"),
   17479             :                                      parser_errposition(@1)));
   17480             :                             break;
   17481           2 :                         case ROLESPEC_CURRENT_ROLE:
   17482           2 :                             ereport(ERROR,
   17483             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17484             :                                      errmsg("%s cannot be used as a role name here",
   17485             :                                             "CURRENT_ROLE"),
   17486             :                                      parser_errposition(@1)));
   17487             :                             break;
   17488             :                     }
   17489        1832 :                 }
   17490             :             ;
   17491             : 
   17492             : RoleSpec:   NonReservedWord
   17493             :                 {
   17494             :                     /*
   17495             :                      * "public" and "none" are not keywords, but they must
   17496             :                      * be treated specially here.
   17497             :                      */
   17498             :                     RoleSpec   *n;
   17499             : 
   17500       29032 :                     if (strcmp($1, "public") == 0)
   17501             :                     {
   17502       15564 :                         n = (RoleSpec *) makeRoleSpec(ROLESPEC_PUBLIC, @1);
   17503       15564 :                         n->roletype = ROLESPEC_PUBLIC;
   17504             :                     }
   17505       13468 :                     else if (strcmp($1, "none") == 0)
   17506             :                     {
   17507          26 :                         ereport(ERROR,
   17508             :                                 (errcode(ERRCODE_RESERVED_NAME),
   17509             :                                  errmsg("role name \"%s\" is reserved",
   17510             :                                         "none"),
   17511             :                                  parser_errposition(@1)));
   17512             :                     }
   17513             :                     else
   17514             :                     {
   17515       13442 :                         n = makeRoleSpec(ROLESPEC_CSTRING, @1);
   17516       13442 :                         n->rolename = pstrdup($1);
   17517             :                     }
   17518       29006 :                     $$ = n;
   17519             :                 }
   17520             :             | CURRENT_ROLE
   17521             :                 {
   17522         130 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_ROLE, @1);
   17523             :                 }
   17524             :             | CURRENT_USER
   17525             :                 {
   17526         228 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
   17527             :                 }
   17528             :             | SESSION_USER
   17529             :                 {
   17530          36 :                     $$ = makeRoleSpec(ROLESPEC_SESSION_USER, @1);
   17531             :                 }
   17532             :         ;
   17533             : 
   17534             : role_list:  RoleSpec
   17535        3194 :                 { $$ = list_make1($1); }
   17536             :             | role_list ',' RoleSpec
   17537         258 :                 { $$ = lappend($1, $3); }
   17538             :         ;
   17539             : 
   17540             : 
   17541             : /*****************************************************************************
   17542             :  *
   17543             :  * PL/pgSQL extensions
   17544             :  *
   17545             :  * You'd think a PL/pgSQL "expression" should be just an a_expr, but
   17546             :  * historically it can include just about anything that can follow SELECT.
   17547             :  * Therefore the returned struct is a SelectStmt.
   17548             :  *****************************************************************************/
   17549             : 
   17550             : PLpgSQL_Expr: opt_distinct_clause opt_target_list
   17551             :             from_clause where_clause
   17552             :             group_clause having_clause window_clause
   17553             :             opt_sort_clause opt_select_limit opt_for_locking_clause
   17554             :                 {
   17555       39296 :                     SelectStmt *n = makeNode(SelectStmt);
   17556             : 
   17557       39296 :                     n->distinctClause = $1;
   17558       39296 :                     n->targetList = $2;
   17559       39296 :                     n->fromClause = $3;
   17560       39296 :                     n->whereClause = $4;
   17561       39296 :                     n->groupClause = ($5)->list;
   17562       39296 :                     n->groupDistinct = ($5)->distinct;
   17563       39296 :                     n->havingClause = $6;
   17564       39296 :                     n->windowClause = $7;
   17565       39296 :                     n->sortClause = $8;
   17566       39296 :                     if ($9)
   17567             :                     {
   17568           4 :                         n->limitOffset = $9->limitOffset;
   17569           4 :                         n->limitCount = $9->limitCount;
   17570           4 :                         if (!n->sortClause &&
   17571           4 :                             $9->limitOption == LIMIT_OPTION_WITH_TIES)
   17572           0 :                             ereport(ERROR,
   17573             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17574             :                                      errmsg("WITH TIES cannot be specified without ORDER BY clause"),
   17575             :                                      parser_errposition($9->optionLoc)));
   17576           4 :                         n->limitOption = $9->limitOption;
   17577             :                     }
   17578       39296 :                     n->lockingClause = $10;
   17579       39296 :                     $$ = (Node *) n;
   17580             :                 }
   17581             :         ;
   17582             : 
   17583             : /*
   17584             :  * PL/pgSQL Assignment statement: name opt_indirection := PLpgSQL_Expr
   17585             :  */
   17586             : 
   17587             : PLAssignStmt: plassign_target opt_indirection plassign_equals PLpgSQL_Expr
   17588             :                 {
   17589        6880 :                     PLAssignStmt *n = makeNode(PLAssignStmt);
   17590             : 
   17591        6880 :                     n->name = $1;
   17592        6880 :                     n->indirection = check_indirection($2, yyscanner);
   17593             :                     /* nnames will be filled by calling production */
   17594        6880 :                     n->val = (SelectStmt *) $4;
   17595        6880 :                     n->location = @1;
   17596        6880 :                     $$ = (Node *) n;
   17597             :                 }
   17598             :         ;
   17599             : 
   17600        6856 : plassign_target: ColId                          { $$ = $1; }
   17601          24 :             | PARAM                             { $$ = psprintf("$%d", $1); }
   17602             :         ;
   17603             : 
   17604             : plassign_equals: COLON_EQUALS
   17605             :             | '='
   17606             :         ;
   17607             : 
   17608             : 
   17609             : /*
   17610             :  * Name classification hierarchy.
   17611             :  *
   17612             :  * IDENT is the lexeme returned by the lexer for identifiers that match
   17613             :  * no known keyword.  In most cases, we can accept certain keywords as
   17614             :  * names, not only IDENTs.  We prefer to accept as many such keywords
   17615             :  * as possible to minimize the impact of "reserved words" on programmers.
   17616             :  * So, we divide names into several possible classes.  The classification
   17617             :  * is chosen in part to make keywords acceptable as names wherever possible.
   17618             :  */
   17619             : 
   17620             : /* Column identifier --- names that can be column, table, etc names.
   17621             :  */
   17622     3055514 : ColId:      IDENT                                   { $$ = $1; }
   17623       53374 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17624        5408 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17625             :         ;
   17626             : 
   17627             : /* Type/function identifier --- names that can be type or function names.
   17628             :  */
   17629      663982 : type_function_name: IDENT                           { $$ = $1; }
   17630       70902 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17631          60 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17632             :         ;
   17633             : 
   17634             : /* Any not-fully-reserved word --- these names can be, eg, role names.
   17635             :  */
   17636       72706 : NonReservedWord:    IDENT                           { $$ = $1; }
   17637       27804 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17638         178 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17639        3696 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17640             :         ;
   17641             : 
   17642             : /* Column label --- allowed labels in "AS" clauses.
   17643             :  * This presently includes *all* Postgres keywords.
   17644             :  */
   17645     1599936 : ColLabel:   IDENT                                   { $$ = $1; }
   17646       36124 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17647         284 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17648        1768 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17649        7250 :             | reserved_keyword                      { $$ = pstrdup($1); }
   17650             :         ;
   17651             : 
   17652             : /* Bare column label --- names that can be column labels without writing "AS".
   17653             :  * This classification is orthogonal to the other keyword categories.
   17654             :  */
   17655        3236 : BareColLabel:   IDENT                               { $$ = $1; }
   17656           6 :             | bare_label_keyword                    { $$ = pstrdup($1); }
   17657             :         ;
   17658             : 
   17659             : 
   17660             : /*
   17661             :  * Keyword category lists.  Generally, every keyword present in
   17662             :  * the Postgres grammar should appear in exactly one of these lists.
   17663             :  *
   17664             :  * Put a new keyword into the first list that it can go into without causing
   17665             :  * shift or reduce conflicts.  The earlier lists define "less reserved"
   17666             :  * categories of keywords.
   17667             :  *
   17668             :  * Make sure that each keyword's category in kwlist.h matches where
   17669             :  * it is listed here.  (Someday we may be able to generate these lists and
   17670             :  * kwlist.h's table from one source of truth.)
   17671             :  */
   17672             : 
   17673             : /* "Unreserved" keywords --- available for use as any kind of name.
   17674             :  */
   17675             : unreserved_keyword:
   17676             :               ABORT_P
   17677             :             | ABSENT
   17678             :             | ABSOLUTE_P
   17679             :             | ACCESS
   17680             :             | ACTION
   17681             :             | ADD_P
   17682             :             | ADMIN
   17683             :             | AFTER
   17684             :             | AGGREGATE
   17685             :             | ALSO
   17686             :             | ALTER
   17687             :             | ALWAYS
   17688             :             | ASENSITIVE
   17689             :             | ASSERTION
   17690             :             | ASSIGNMENT
   17691             :             | AT
   17692             :             | ATOMIC
   17693             :             | ATTACH
   17694             :             | ATTRIBUTE
   17695             :             | BACKWARD
   17696             :             | BEFORE
   17697             :             | BEGIN_P
   17698             :             | BREADTH
   17699             :             | BY
   17700             :             | CACHE
   17701             :             | CALL
   17702             :             | CALLED
   17703             :             | CASCADE
   17704             :             | CASCADED
   17705             :             | CATALOG_P
   17706             :             | CHAIN
   17707             :             | CHARACTERISTICS
   17708             :             | CHECKPOINT
   17709             :             | CLASS
   17710             :             | CLOSE
   17711             :             | CLUSTER
   17712             :             | COLUMNS
   17713             :             | COMMENT
   17714             :             | COMMENTS
   17715             :             | COMMIT
   17716             :             | COMMITTED
   17717             :             | COMPRESSION
   17718             :             | CONDITIONAL
   17719             :             | CONFIGURATION
   17720             :             | CONFLICT
   17721             :             | CONNECTION
   17722             :             | CONSTRAINTS
   17723             :             | CONTENT_P
   17724             :             | CONTINUE_P
   17725             :             | CONVERSION_P
   17726             :             | COPY
   17727             :             | COST
   17728             :             | CSV
   17729             :             | CUBE
   17730             :             | CURRENT_P
   17731             :             | CURSOR
   17732             :             | CYCLE
   17733             :             | DATA_P
   17734             :             | DATABASE
   17735             :             | DAY_P
   17736             :             | DEALLOCATE
   17737             :             | DECLARE
   17738             :             | DEFAULTS
   17739             :             | DEFERRED
   17740             :             | DEFINER
   17741             :             | DELETE_P
   17742             :             | DELIMITER
   17743             :             | DELIMITERS
   17744             :             | DEPENDS
   17745             :             | DEPTH
   17746             :             | DETACH
   17747             :             | DICTIONARY
   17748             :             | DISABLE_P
   17749             :             | DISCARD
   17750             :             | DOCUMENT_P
   17751             :             | DOMAIN_P
   17752             :             | DOUBLE_P
   17753             :             | DROP
   17754             :             | EACH
   17755             :             | EMPTY_P
   17756             :             | ENABLE_P
   17757             :             | ENCODING
   17758             :             | ENCRYPTED
   17759             :             | ENFORCED
   17760             :             | ENUM_P
   17761             :             | ERROR_P
   17762             :             | ESCAPE
   17763             :             | EVENT
   17764             :             | EXCLUDE
   17765             :             | EXCLUDING
   17766             :             | EXCLUSIVE
   17767             :             | EXECUTE
   17768             :             | EXPLAIN
   17769             :             | EXPRESSION
   17770             :             | EXTENSION
   17771             :             | EXTERNAL
   17772             :             | FAMILY
   17773             :             | FILTER
   17774             :             | FINALIZE
   17775             :             | FIRST_P
   17776             :             | FOLLOWING
   17777             :             | FORCE
   17778             :             | FORMAT
   17779             :             | FORWARD
   17780             :             | FUNCTION
   17781             :             | FUNCTIONS
   17782             :             | GENERATED
   17783             :             | GLOBAL
   17784             :             | GRANTED
   17785             :             | GROUPS
   17786             :             | HANDLER
   17787             :             | HEADER_P
   17788             :             | HOLD
   17789             :             | HOUR_P
   17790             :             | IDENTITY_P
   17791             :             | IF_P
   17792             :             | IMMEDIATE
   17793             :             | IMMUTABLE
   17794             :             | IMPLICIT_P
   17795             :             | IMPORT_P
   17796             :             | INCLUDE
   17797             :             | INCLUDING
   17798             :             | INCREMENT
   17799             :             | INDENT
   17800             :             | INDEX
   17801             :             | INDEXES
   17802             :             | INHERIT
   17803             :             | INHERITS
   17804             :             | INLINE_P
   17805             :             | INPUT_P
   17806             :             | INSENSITIVE
   17807             :             | INSERT
   17808             :             | INSTEAD
   17809             :             | INVOKER
   17810             :             | ISOLATION
   17811             :             | KEEP
   17812             :             | KEY
   17813             :             | KEYS
   17814             :             | LABEL
   17815             :             | LANGUAGE
   17816             :             | LARGE_P
   17817             :             | LAST_P
   17818             :             | LEAKPROOF
   17819             :             | LEVEL
   17820             :             | LISTEN
   17821             :             | LOAD
   17822             :             | LOCAL
   17823             :             | LOCATION
   17824             :             | LOCK_P
   17825             :             | LOCKED
   17826             :             | LOGGED
   17827             :             | MAPPING
   17828             :             | MATCH
   17829             :             | MATCHED
   17830             :             | MATERIALIZED
   17831             :             | MAXVALUE
   17832             :             | MERGE
   17833             :             | METHOD
   17834             :             | MINUTE_P
   17835             :             | MINVALUE
   17836             :             | MODE
   17837             :             | MONTH_P
   17838             :             | MOVE
   17839             :             | NAME_P
   17840             :             | NAMES
   17841             :             | NESTED
   17842             :             | NEW
   17843             :             | NEXT
   17844             :             | NFC
   17845             :             | NFD
   17846             :             | NFKC
   17847             :             | NFKD
   17848             :             | NO
   17849             :             | NORMALIZED
   17850             :             | NOTHING
   17851             :             | NOTIFY
   17852             :             | NOWAIT
   17853             :             | NULLS_P
   17854             :             | OBJECT_P
   17855             :             | OF
   17856             :             | OFF
   17857             :             | OIDS
   17858             :             | OLD
   17859             :             | OMIT
   17860             :             | OPERATOR
   17861             :             | OPTION
   17862             :             | OPTIONS
   17863             :             | ORDINALITY
   17864             :             | OTHERS
   17865             :             | OVER
   17866             :             | OVERRIDING
   17867             :             | OWNED
   17868             :             | OWNER
   17869             :             | PARALLEL
   17870             :             | PARAMETER
   17871             :             | PARSER
   17872             :             | PARTIAL
   17873             :             | PARTITION
   17874             :             | PASSING
   17875             :             | PASSWORD
   17876             :             | PATH
   17877             :             | PERIOD
   17878             :             | PLAN
   17879             :             | PLANS
   17880             :             | POLICY
   17881             :             | PRECEDING
   17882             :             | PREPARE
   17883             :             | PREPARED
   17884             :             | PRESERVE
   17885             :             | PRIOR
   17886             :             | PRIVILEGES
   17887             :             | PROCEDURAL
   17888             :             | PROCEDURE
   17889             :             | PROCEDURES
   17890             :             | PROGRAM
   17891             :             | PUBLICATION
   17892             :             | QUOTE
   17893             :             | QUOTES
   17894             :             | RANGE
   17895             :             | READ
   17896             :             | REASSIGN
   17897             :             | RECURSIVE
   17898             :             | REF_P
   17899             :             | REFERENCING
   17900             :             | REFRESH
   17901             :             | REINDEX
   17902             :             | RELATIVE_P
   17903             :             | RELEASE
   17904             :             | RENAME
   17905             :             | REPEATABLE
   17906             :             | REPLACE
   17907             :             | REPLICA
   17908             :             | RESET
   17909             :             | RESTART
   17910             :             | RESTRICT
   17911             :             | RETURN
   17912             :             | RETURNS
   17913             :             | REVOKE
   17914             :             | ROLE
   17915             :             | ROLLBACK
   17916             :             | ROLLUP
   17917             :             | ROUTINE
   17918             :             | ROUTINES
   17919             :             | ROWS
   17920             :             | RULE
   17921             :             | SAVEPOINT
   17922             :             | SCALAR
   17923             :             | SCHEMA
   17924             :             | SCHEMAS
   17925             :             | SCROLL
   17926             :             | SEARCH
   17927             :             | SECOND_P
   17928             :             | SECURITY
   17929             :             | SEQUENCE
   17930             :             | SEQUENCES
   17931             :             | SERIALIZABLE
   17932             :             | SERVER
   17933             :             | SESSION
   17934             :             | SET
   17935             :             | SETS
   17936             :             | SHARE
   17937             :             | SHOW
   17938             :             | SIMPLE
   17939             :             | SKIP
   17940             :             | SNAPSHOT
   17941             :             | SOURCE
   17942             :             | SQL_P
   17943             :             | STABLE
   17944             :             | STANDALONE_P
   17945             :             | START
   17946             :             | STATEMENT
   17947             :             | STATISTICS
   17948             :             | STDIN
   17949             :             | STDOUT
   17950             :             | STORAGE
   17951             :             | STORED
   17952             :             | STRICT_P
   17953             :             | STRING_P
   17954             :             | STRIP_P
   17955             :             | SUBSCRIPTION
   17956             :             | SUPPORT
   17957             :             | SYSID
   17958             :             | SYSTEM_P
   17959             :             | TABLES
   17960             :             | TABLESPACE
   17961             :             | TARGET
   17962             :             | TEMP
   17963             :             | TEMPLATE
   17964             :             | TEMPORARY
   17965             :             | TEXT_P
   17966             :             | TIES
   17967             :             | TRANSACTION
   17968             :             | TRANSFORM
   17969             :             | TRIGGER
   17970             :             | TRUNCATE
   17971             :             | TRUSTED
   17972             :             | TYPE_P
   17973             :             | TYPES_P
   17974             :             | UESCAPE
   17975             :             | UNBOUNDED
   17976             :             | UNCOMMITTED
   17977             :             | UNCONDITIONAL
   17978             :             | UNENCRYPTED
   17979             :             | UNKNOWN
   17980             :             | UNLISTEN
   17981             :             | UNLOGGED
   17982             :             | UNTIL
   17983             :             | UPDATE
   17984             :             | VACUUM
   17985             :             | VALID
   17986             :             | VALIDATE
   17987             :             | VALIDATOR
   17988             :             | VALUE_P
   17989             :             | VARYING
   17990             :             | VERSION_P
   17991             :             | VIEW
   17992             :             | VIEWS
   17993             :             | VOLATILE
   17994             :             | WHITESPACE_P
   17995             :             | WITHIN
   17996             :             | WITHOUT
   17997             :             | WORK
   17998             :             | WRAPPER
   17999             :             | WRITE
   18000             :             | XML_P
   18001             :             | YEAR_P
   18002             :             | YES_P
   18003             :             | ZONE
   18004             :         ;
   18005             : 
   18006             : /* Column identifier --- keywords that can be column, table, etc names.
   18007             :  *
   18008             :  * Many of these keywords will in fact be recognized as type or function
   18009             :  * names too; but they have special productions for the purpose, and so
   18010             :  * can't be treated as "generic" type or function names.
   18011             :  *
   18012             :  * The type names appearing here are not usable as function names
   18013             :  * because they can be followed by '(' in typename productions, which
   18014             :  * looks too much like a function call for an LR(1) parser.
   18015             :  */
   18016             : col_name_keyword:
   18017             :               BETWEEN
   18018             :             | BIGINT
   18019             :             | BIT
   18020             :             | BOOLEAN_P
   18021             :             | CHAR_P
   18022             :             | CHARACTER
   18023             :             | COALESCE
   18024             :             | DEC
   18025             :             | DECIMAL_P
   18026             :             | EXISTS
   18027             :             | EXTRACT
   18028             :             | FLOAT_P
   18029             :             | GREATEST
   18030             :             | GROUPING
   18031             :             | INOUT
   18032             :             | INT_P
   18033             :             | INTEGER
   18034             :             | INTERVAL
   18035             :             | JSON
   18036             :             | JSON_ARRAY
   18037             :             | JSON_ARRAYAGG
   18038             :             | JSON_EXISTS
   18039             :             | JSON_OBJECT
   18040             :             | JSON_OBJECTAGG
   18041             :             | JSON_QUERY
   18042             :             | JSON_SCALAR
   18043             :             | JSON_SERIALIZE
   18044             :             | JSON_TABLE
   18045             :             | JSON_VALUE
   18046             :             | LEAST
   18047             :             | MERGE_ACTION
   18048             :             | NATIONAL
   18049             :             | NCHAR
   18050             :             | NONE
   18051             :             | NORMALIZE
   18052             :             | NULLIF
   18053             :             | NUMERIC
   18054             :             | OUT_P
   18055             :             | OVERLAY
   18056             :             | POSITION
   18057             :             | PRECISION
   18058             :             | REAL
   18059             :             | ROW
   18060             :             | SETOF
   18061             :             | SMALLINT
   18062             :             | SUBSTRING
   18063             :             | TIME
   18064             :             | TIMESTAMP
   18065             :             | TREAT
   18066             :             | TRIM
   18067             :             | VALUES
   18068             :             | VARCHAR
   18069             :             | XMLATTRIBUTES
   18070             :             | XMLCONCAT
   18071             :             | XMLELEMENT
   18072             :             | XMLEXISTS
   18073             :             | XMLFOREST
   18074             :             | XMLNAMESPACES
   18075             :             | XMLPARSE
   18076             :             | XMLPI
   18077             :             | XMLROOT
   18078             :             | XMLSERIALIZE
   18079             :             | XMLTABLE
   18080             :         ;
   18081             : 
   18082             : /* Type/function identifier --- keywords that can be type or function names.
   18083             :  *
   18084             :  * Most of these are keywords that are used as operators in expressions;
   18085             :  * in general such keywords can't be column names because they would be
   18086             :  * ambiguous with variables, but they are unambiguous as function identifiers.
   18087             :  *
   18088             :  * Do not include POSITION, SUBSTRING, etc here since they have explicit
   18089             :  * productions in a_expr to support the goofy SQL9x argument syntax.
   18090             :  * - thomas 2000-11-28
   18091             :  */
   18092             : type_func_name_keyword:
   18093             :               AUTHORIZATION
   18094             :             | BINARY
   18095             :             | COLLATION
   18096             :             | CONCURRENTLY
   18097             :             | CROSS
   18098             :             | CURRENT_SCHEMA
   18099             :             | FREEZE
   18100             :             | FULL
   18101             :             | ILIKE
   18102             :             | INNER_P
   18103             :             | IS
   18104             :             | ISNULL
   18105             :             | JOIN
   18106             :             | LEFT
   18107             :             | LIKE
   18108             :             | NATURAL
   18109             :             | NOTNULL
   18110             :             | OUTER_P
   18111             :             | OVERLAPS
   18112             :             | RIGHT
   18113             :             | SIMILAR
   18114             :             | TABLESAMPLE
   18115             :             | VERBOSE
   18116             :         ;
   18117             : 
   18118             : /* Reserved keyword --- these keywords are usable only as a ColLabel.
   18119             :  *
   18120             :  * Keywords appear here if they could not be distinguished from variable,
   18121             :  * type, or function names in some contexts.  Don't put things here unless
   18122             :  * forced to.
   18123             :  */
   18124             : reserved_keyword:
   18125             :               ALL
   18126             :             | ANALYSE
   18127             :             | ANALYZE
   18128             :             | AND
   18129             :             | ANY
   18130             :             | ARRAY
   18131             :             | AS
   18132             :             | ASC
   18133             :             | ASYMMETRIC
   18134             :             | BOTH
   18135             :             | CASE
   18136             :             | CAST
   18137             :             | CHECK
   18138             :             | COLLATE
   18139             :             | COLUMN
   18140             :             | CONSTRAINT
   18141             :             | CREATE
   18142             :             | CURRENT_CATALOG
   18143             :             | CURRENT_DATE
   18144             :             | CURRENT_ROLE
   18145             :             | CURRENT_TIME
   18146             :             | CURRENT_TIMESTAMP
   18147             :             | CURRENT_USER
   18148             :             | DEFAULT
   18149             :             | DEFERRABLE
   18150             :             | DESC
   18151             :             | DISTINCT
   18152             :             | DO
   18153             :             | ELSE
   18154             :             | END_P
   18155             :             | EXCEPT
   18156             :             | FALSE_P
   18157             :             | FETCH
   18158             :             | FOR
   18159             :             | FOREIGN
   18160             :             | FROM
   18161             :             | GRANT
   18162             :             | GROUP_P
   18163             :             | HAVING
   18164             :             | IN_P
   18165             :             | INITIALLY
   18166             :             | INTERSECT
   18167             :             | INTO
   18168             :             | LATERAL_P
   18169             :             | LEADING
   18170             :             | LIMIT
   18171             :             | LOCALTIME
   18172             :             | LOCALTIMESTAMP
   18173             :             | NOT
   18174             :             | NULL_P
   18175             :             | OFFSET
   18176             :             | ON
   18177             :             | ONLY
   18178             :             | OR
   18179             :             | ORDER
   18180             :             | PLACING
   18181             :             | PRIMARY
   18182             :             | REFERENCES
   18183             :             | RETURNING
   18184             :             | SELECT
   18185             :             | SESSION_USER
   18186             :             | SOME
   18187             :             | SYMMETRIC
   18188             :             | SYSTEM_USER
   18189             :             | TABLE
   18190             :             | THEN
   18191             :             | TO
   18192             :             | TRAILING
   18193             :             | TRUE_P
   18194             :             | UNION
   18195             :             | UNIQUE
   18196             :             | USER
   18197             :             | USING
   18198             :             | VARIADIC
   18199             :             | WHEN
   18200             :             | WHERE
   18201             :             | WINDOW
   18202             :             | WITH
   18203             :         ;
   18204             : 
   18205             : /*
   18206             :  * While all keywords can be used as column labels when preceded by AS,
   18207             :  * not all of them can be used as a "bare" column label without AS.
   18208             :  * Those that can be used as a bare label must be listed here,
   18209             :  * in addition to appearing in one of the category lists above.
   18210             :  *
   18211             :  * Always add a new keyword to this list if possible.  Mark it BARE_LABEL
   18212             :  * in kwlist.h if it is included here, or AS_LABEL if it is not.
   18213             :  */
   18214             : bare_label_keyword:
   18215             :               ABORT_P
   18216             :             | ABSENT
   18217             :             | ABSOLUTE_P
   18218             :             | ACCESS
   18219             :             | ACTION
   18220             :             | ADD_P
   18221             :             | ADMIN
   18222             :             | AFTER
   18223             :             | AGGREGATE
   18224             :             | ALL
   18225             :             | ALSO
   18226             :             | ALTER
   18227             :             | ALWAYS
   18228             :             | ANALYSE
   18229             :             | ANALYZE
   18230             :             | AND
   18231             :             | ANY
   18232             :             | ASC
   18233             :             | ASENSITIVE
   18234             :             | ASSERTION
   18235             :             | ASSIGNMENT
   18236             :             | ASYMMETRIC
   18237             :             | AT
   18238             :             | ATOMIC
   18239             :             | ATTACH
   18240             :             | ATTRIBUTE
   18241             :             | AUTHORIZATION
   18242             :             | BACKWARD
   18243             :             | BEFORE
   18244             :             | BEGIN_P
   18245             :             | BETWEEN
   18246             :             | BIGINT
   18247             :             | BINARY
   18248             :             | BIT
   18249             :             | BOOLEAN_P
   18250             :             | BOTH
   18251             :             | BREADTH
   18252             :             | BY
   18253             :             | CACHE
   18254             :             | CALL
   18255             :             | CALLED
   18256             :             | CASCADE
   18257             :             | CASCADED
   18258             :             | CASE
   18259             :             | CAST
   18260             :             | CATALOG_P
   18261             :             | CHAIN
   18262             :             | CHARACTERISTICS
   18263             :             | CHECK
   18264             :             | CHECKPOINT
   18265             :             | CLASS
   18266             :             | CLOSE
   18267             :             | CLUSTER
   18268             :             | COALESCE
   18269             :             | COLLATE
   18270             :             | COLLATION
   18271             :             | COLUMN
   18272             :             | COLUMNS
   18273             :             | COMMENT
   18274             :             | COMMENTS
   18275             :             | COMMIT
   18276             :             | COMMITTED
   18277             :             | COMPRESSION
   18278             :             | CONCURRENTLY
   18279             :             | CONDITIONAL
   18280             :             | CONFIGURATION
   18281             :             | CONFLICT
   18282             :             | CONNECTION
   18283             :             | CONSTRAINT
   18284             :             | CONSTRAINTS
   18285             :             | CONTENT_P
   18286             :             | CONTINUE_P
   18287             :             | CONVERSION_P
   18288             :             | COPY
   18289             :             | COST
   18290             :             | CROSS
   18291             :             | CSV
   18292             :             | CUBE
   18293             :             | CURRENT_P
   18294             :             | CURRENT_CATALOG
   18295             :             | CURRENT_DATE
   18296             :             | CURRENT_ROLE
   18297             :             | CURRENT_SCHEMA
   18298             :             | CURRENT_TIME
   18299             :             | CURRENT_TIMESTAMP
   18300             :             | CURRENT_USER
   18301             :             | CURSOR
   18302             :             | CYCLE
   18303             :             | DATA_P
   18304             :             | DATABASE
   18305             :             | DEALLOCATE
   18306             :             | DEC
   18307             :             | DECIMAL_P
   18308             :             | DECLARE
   18309             :             | DEFAULT
   18310             :             | DEFAULTS
   18311             :             | DEFERRABLE
   18312             :             | DEFERRED
   18313             :             | DEFINER
   18314             :             | DELETE_P
   18315             :             | DELIMITER
   18316             :             | DELIMITERS
   18317             :             | DEPENDS
   18318             :             | DEPTH
   18319             :             | DESC
   18320             :             | DETACH
   18321             :             | DICTIONARY
   18322             :             | DISABLE_P
   18323             :             | DISCARD
   18324             :             | DISTINCT
   18325             :             | DO
   18326             :             | DOCUMENT_P
   18327             :             | DOMAIN_P
   18328             :             | DOUBLE_P
   18329             :             | DROP
   18330             :             | EACH
   18331             :             | ELSE
   18332             :             | EMPTY_P
   18333             :             | ENABLE_P
   18334             :             | ENCODING
   18335             :             | ENCRYPTED
   18336             :             | END_P
   18337             :             | ENFORCED
   18338             :             | ENUM_P
   18339             :             | ERROR_P
   18340             :             | ESCAPE
   18341             :             | EVENT
   18342             :             | EXCLUDE
   18343             :             | EXCLUDING
   18344             :             | EXCLUSIVE
   18345             :             | EXECUTE
   18346             :             | EXISTS
   18347             :             | EXPLAIN
   18348             :             | EXPRESSION
   18349             :             | EXTENSION
   18350             :             | EXTERNAL
   18351             :             | EXTRACT
   18352             :             | FALSE_P
   18353             :             | FAMILY
   18354             :             | FINALIZE
   18355             :             | FIRST_P
   18356             :             | FLOAT_P
   18357             :             | FOLLOWING
   18358             :             | FORCE
   18359             :             | FOREIGN
   18360             :             | FORMAT
   18361             :             | FORWARD
   18362             :             | FREEZE
   18363             :             | FULL
   18364             :             | FUNCTION
   18365             :             | FUNCTIONS
   18366             :             | GENERATED
   18367             :             | GLOBAL
   18368             :             | GRANTED
   18369             :             | GREATEST
   18370             :             | GROUPING
   18371             :             | GROUPS
   18372             :             | HANDLER
   18373             :             | HEADER_P
   18374             :             | HOLD
   18375             :             | IDENTITY_P
   18376             :             | IF_P
   18377             :             | ILIKE
   18378             :             | IMMEDIATE
   18379             :             | IMMUTABLE
   18380             :             | IMPLICIT_P
   18381             :             | IMPORT_P
   18382             :             | IN_P
   18383             :             | INCLUDE
   18384             :             | INCLUDING
   18385             :             | INCREMENT
   18386             :             | INDENT
   18387             :             | INDEX
   18388             :             | INDEXES
   18389             :             | INHERIT
   18390             :             | INHERITS
   18391             :             | INITIALLY
   18392             :             | INLINE_P
   18393             :             | INNER_P
   18394             :             | INOUT
   18395             :             | INPUT_P
   18396             :             | INSENSITIVE
   18397             :             | INSERT
   18398             :             | INSTEAD
   18399             :             | INT_P
   18400             :             | INTEGER
   18401             :             | INTERVAL
   18402             :             | INVOKER
   18403             :             | IS
   18404             :             | ISOLATION
   18405             :             | JOIN
   18406             :             | JSON
   18407             :             | JSON_ARRAY
   18408             :             | JSON_ARRAYAGG
   18409             :             | JSON_EXISTS
   18410             :             | JSON_OBJECT
   18411             :             | JSON_OBJECTAGG
   18412             :             | JSON_QUERY
   18413             :             | JSON_SCALAR
   18414             :             | JSON_SERIALIZE
   18415             :             | JSON_TABLE
   18416             :             | JSON_VALUE
   18417             :             | KEEP
   18418             :             | KEY
   18419             :             | KEYS
   18420             :             | LABEL
   18421             :             | LANGUAGE
   18422             :             | LARGE_P
   18423             :             | LAST_P
   18424             :             | LATERAL_P
   18425             :             | LEADING
   18426             :             | LEAKPROOF
   18427             :             | LEAST
   18428             :             | LEFT
   18429             :             | LEVEL
   18430             :             | LIKE
   18431             :             | LISTEN
   18432             :             | LOAD
   18433             :             | LOCAL
   18434             :             | LOCALTIME
   18435             :             | LOCALTIMESTAMP
   18436             :             | LOCATION
   18437             :             | LOCK_P
   18438             :             | LOCKED
   18439             :             | LOGGED
   18440             :             | MAPPING
   18441             :             | MATCH
   18442             :             | MATCHED
   18443             :             | MATERIALIZED
   18444             :             | MAXVALUE
   18445             :             | MERGE
   18446             :             | MERGE_ACTION
   18447             :             | METHOD
   18448             :             | MINVALUE
   18449             :             | MODE
   18450             :             | MOVE
   18451             :             | NAME_P
   18452             :             | NAMES
   18453             :             | NATIONAL
   18454             :             | NATURAL
   18455             :             | NCHAR
   18456             :             | NESTED
   18457             :             | NEW
   18458             :             | NEXT
   18459             :             | NFC
   18460             :             | NFD
   18461             :             | NFKC
   18462             :             | NFKD
   18463             :             | NO
   18464             :             | NONE
   18465             :             | NORMALIZE
   18466             :             | NORMALIZED
   18467             :             | NOT
   18468             :             | NOTHING
   18469             :             | NOTIFY
   18470             :             | NOWAIT
   18471             :             | NULL_P
   18472             :             | NULLIF
   18473             :             | NULLS_P
   18474             :             | NUMERIC
   18475             :             | OBJECT_P
   18476             :             | OF
   18477             :             | OFF
   18478             :             | OIDS
   18479             :             | OLD
   18480             :             | OMIT
   18481             :             | ONLY
   18482             :             | OPERATOR
   18483             :             | OPTION
   18484             :             | OPTIONS
   18485             :             | OR
   18486             :             | ORDINALITY
   18487             :             | OTHERS
   18488             :             | OUT_P
   18489             :             | OUTER_P
   18490             :             | OVERLAY
   18491             :             | OVERRIDING
   18492             :             | OWNED
   18493             :             | OWNER
   18494             :             | PARALLEL
   18495             :             | PARAMETER
   18496             :             | PARSER
   18497             :             | PARTIAL
   18498             :             | PARTITION
   18499             :             | PASSING
   18500             :             | PASSWORD
   18501             :             | PATH
   18502             :             | PERIOD
   18503             :             | PLACING
   18504             :             | PLAN
   18505             :             | PLANS
   18506             :             | POLICY
   18507             :             | POSITION
   18508             :             | PRECEDING
   18509             :             | PREPARE
   18510             :             | PREPARED
   18511             :             | PRESERVE
   18512             :             | PRIMARY
   18513             :             | PRIOR
   18514             :             | PRIVILEGES
   18515             :             | PROCEDURAL
   18516             :             | PROCEDURE
   18517             :             | PROCEDURES
   18518             :             | PROGRAM
   18519             :             | PUBLICATION
   18520             :             | QUOTE
   18521             :             | QUOTES
   18522             :             | RANGE
   18523             :             | READ
   18524             :             | REAL
   18525             :             | REASSIGN
   18526             :             | RECURSIVE
   18527             :             | REF_P
   18528             :             | REFERENCES
   18529             :             | REFERENCING
   18530             :             | REFRESH
   18531             :             | REINDEX
   18532             :             | RELATIVE_P
   18533             :             | RELEASE
   18534             :             | RENAME
   18535             :             | REPEATABLE
   18536             :             | REPLACE
   18537             :             | REPLICA
   18538             :             | RESET
   18539             :             | RESTART
   18540             :             | RESTRICT
   18541             :             | RETURN
   18542             :             | RETURNS
   18543             :             | REVOKE
   18544             :             | RIGHT
   18545             :             | ROLE
   18546             :             | ROLLBACK
   18547             :             | ROLLUP
   18548             :             | ROUTINE
   18549             :             | ROUTINES
   18550             :             | ROW
   18551             :             | ROWS
   18552             :             | RULE
   18553             :             | SAVEPOINT
   18554             :             | SCALAR
   18555             :             | SCHEMA
   18556             :             | SCHEMAS
   18557             :             | SCROLL
   18558             :             | SEARCH
   18559             :             | SECURITY
   18560             :             | SELECT
   18561             :             | SEQUENCE
   18562             :             | SEQUENCES
   18563             :             | SERIALIZABLE
   18564             :             | SERVER
   18565             :             | SESSION
   18566             :             | SESSION_USER
   18567             :             | SET
   18568             :             | SETOF
   18569             :             | SETS
   18570             :             | SHARE
   18571             :             | SHOW
   18572             :             | SIMILAR
   18573             :             | SIMPLE
   18574             :             | SKIP
   18575             :             | SMALLINT
   18576             :             | SNAPSHOT
   18577             :             | SOME
   18578             :             | SOURCE
   18579             :             | SQL_P
   18580             :             | STABLE
   18581             :             | STANDALONE_P
   18582             :             | START
   18583             :             | STATEMENT
   18584             :             | STATISTICS
   18585             :             | STDIN
   18586             :             | STDOUT
   18587             :             | STORAGE
   18588             :             | STORED
   18589             :             | STRICT_P
   18590             :             | STRING_P
   18591             :             | STRIP_P
   18592             :             | SUBSCRIPTION
   18593             :             | SUBSTRING
   18594             :             | SUPPORT
   18595             :             | SYMMETRIC
   18596             :             | SYSID
   18597             :             | SYSTEM_P
   18598             :             | SYSTEM_USER
   18599             :             | TABLE
   18600             :             | TABLES
   18601             :             | TABLESAMPLE
   18602             :             | TABLESPACE
   18603             :             | TARGET
   18604             :             | TEMP
   18605             :             | TEMPLATE
   18606             :             | TEMPORARY
   18607             :             | TEXT_P
   18608             :             | THEN
   18609             :             | TIES
   18610             :             | TIME
   18611             :             | TIMESTAMP
   18612             :             | TRAILING
   18613             :             | TRANSACTION
   18614             :             | TRANSFORM
   18615             :             | TREAT
   18616             :             | TRIGGER
   18617             :             | TRIM
   18618             :             | TRUE_P
   18619             :             | TRUNCATE
   18620             :             | TRUSTED
   18621             :             | TYPE_P
   18622             :             | TYPES_P
   18623             :             | UESCAPE
   18624             :             | UNBOUNDED
   18625             :             | UNCOMMITTED
   18626             :             | UNCONDITIONAL
   18627             :             | UNENCRYPTED
   18628             :             | UNIQUE
   18629             :             | UNKNOWN
   18630             :             | UNLISTEN
   18631             :             | UNLOGGED
   18632             :             | UNTIL
   18633             :             | UPDATE
   18634             :             | USER
   18635             :             | USING
   18636             :             | VACUUM
   18637             :             | VALID
   18638             :             | VALIDATE
   18639             :             | VALIDATOR
   18640             :             | VALUE_P
   18641             :             | VALUES
   18642             :             | VARCHAR
   18643             :             | VARIADIC
   18644             :             | VERBOSE
   18645             :             | VERSION_P
   18646             :             | VIEW
   18647             :             | VIEWS
   18648             :             | VOLATILE
   18649             :             | WHEN
   18650             :             | WHITESPACE_P
   18651             :             | WORK
   18652             :             | WRAPPER
   18653             :             | WRITE
   18654             :             | XML_P
   18655             :             | XMLATTRIBUTES
   18656             :             | XMLCONCAT
   18657             :             | XMLELEMENT
   18658             :             | XMLEXISTS
   18659             :             | XMLFOREST
   18660             :             | XMLNAMESPACES
   18661             :             | XMLPARSE
   18662             :             | XMLPI
   18663             :             | XMLROOT
   18664             :             | XMLSERIALIZE
   18665             :             | XMLTABLE
   18666             :             | YES_P
   18667             :             | ZONE
   18668             :         ;
   18669             : 
   18670             : %%
   18671             : 
   18672             : /*
   18673             :  * The signature of this function is required by bison.  However, we
   18674             :  * ignore the passed yylloc and instead use the last token position
   18675             :  * available from the scanner.
   18676             :  */
   18677             : static void
   18678         702 : base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
   18679             : {
   18680         702 :     parser_yyerror(msg);
   18681             : }
   18682             : 
   18683             : static RawStmt *
   18684      796814 : makeRawStmt(Node *stmt, int stmt_location)
   18685             : {
   18686      796814 :     RawStmt    *rs = makeNode(RawStmt);
   18687             : 
   18688      796814 :     rs->stmt = stmt;
   18689      796814 :     rs->stmt_location = stmt_location;
   18690      796814 :     rs->stmt_len = 0;            /* might get changed later */
   18691      796814 :     return rs;
   18692             : }
   18693             : 
   18694             : /* Adjust a RawStmt to reflect that it doesn't run to the end of the string */
   18695             : static void
   18696      564300 : updateRawStmtEnd(RawStmt *rs, int end_location)
   18697             : {
   18698             :     /*
   18699             :      * If we already set the length, don't change it.  This is for situations
   18700             :      * like "select foo ;; select bar" where the same statement will be last
   18701             :      * in the string for more than one semicolon.
   18702             :      */
   18703      564300 :     if (rs->stmt_len > 0)
   18704         302 :         return;
   18705             : 
   18706             :     /* OK, update length of RawStmt */
   18707      563998 :     rs->stmt_len = end_location - rs->stmt_location;
   18708             : }
   18709             : 
   18710             : /*
   18711             :  * Adjust a PreparableStmt to reflect that it doesn't run to the end of the
   18712             :  * string.
   18713             :  */
   18714             : static void
   18715         460 : updatePreparableStmtEnd(Node *n, int end_location)
   18716             : {
   18717         460 :     if (IsA(n, SelectStmt))
   18718             :     {
   18719         272 :         SelectStmt *stmt = (SelectStmt *) n;
   18720             : 
   18721         272 :         stmt->stmt_len = end_location - stmt->stmt_location;
   18722             :     }
   18723         188 :     else if (IsA(n, InsertStmt))
   18724             :     {
   18725          62 :         InsertStmt *stmt = (InsertStmt *) n;
   18726             : 
   18727          62 :         stmt->stmt_len = end_location - stmt->stmt_location;
   18728             :     }
   18729         126 :     else if (IsA(n, UpdateStmt))
   18730             :     {
   18731          56 :         UpdateStmt *stmt = (UpdateStmt *) n;
   18732             : 
   18733          56 :         stmt->stmt_len = end_location - stmt->stmt_location;
   18734             :     }
   18735          70 :     else if (IsA(n, DeleteStmt))
   18736             :     {
   18737          54 :         DeleteStmt *stmt = (DeleteStmt *) n;
   18738             : 
   18739          54 :         stmt->stmt_len = end_location - stmt->stmt_location;
   18740             :     }
   18741          16 :     else if (IsA(n, MergeStmt))
   18742             :     {
   18743          16 :         MergeStmt  *stmt = (MergeStmt *) n;
   18744             : 
   18745          16 :         stmt->stmt_len = end_location - stmt->stmt_location;
   18746             :     }
   18747             :     else
   18748           0 :         elog(ERROR, "unexpected node type %d", (int) n->type);
   18749         460 : }
   18750             : 
   18751             : static Node *
   18752     1623628 : makeColumnRef(char *colname, List *indirection,
   18753             :               int location, core_yyscan_t yyscanner)
   18754             : {
   18755             :     /*
   18756             :      * Generate a ColumnRef node, with an A_Indirection node added if there is
   18757             :      * any subscripting in the specified indirection list.  However, any field
   18758             :      * selection at the start of the indirection list must be transposed into
   18759             :      * the "fields" part of the ColumnRef node.
   18760             :      */
   18761     1623628 :     ColumnRef  *c = makeNode(ColumnRef);
   18762     1623628 :     int         nfields = 0;
   18763             :     ListCell   *l;
   18764             : 
   18765     1623628 :     c->location = location;
   18766     2580212 :     foreach(l, indirection)
   18767             :     {
   18768      965828 :         if (IsA(lfirst(l), A_Indices))
   18769             :         {
   18770        9244 :             A_Indirection *i = makeNode(A_Indirection);
   18771             : 
   18772        9244 :             if (nfields == 0)
   18773             :             {
   18774             :                 /* easy case - all indirection goes to A_Indirection */
   18775        6636 :                 c->fields = list_make1(makeString(colname));
   18776        6636 :                 i->indirection = check_indirection(indirection, yyscanner);
   18777             :             }
   18778             :             else
   18779             :             {
   18780             :                 /* got to split the list in two */
   18781        2608 :                 i->indirection = check_indirection(list_copy_tail(indirection,
   18782             :                                                                   nfields),
   18783             :                                                    yyscanner);
   18784        2608 :                 indirection = list_truncate(indirection, nfields);
   18785        2608 :                 c->fields = lcons(makeString(colname), indirection);
   18786             :             }
   18787        9244 :             i->arg = (Node *) c;
   18788        9244 :             return (Node *) i;
   18789             :         }
   18790      956584 :         else if (IsA(lfirst(l), A_Star))
   18791             :         {
   18792             :             /* We only allow '*' at the end of a ColumnRef */
   18793        5220 :             if (lnext(indirection, l) != NULL)
   18794           0 :                 parser_yyerror("improper use of \"*\"");
   18795             :         }
   18796      956584 :         nfields++;
   18797             :     }
   18798             :     /* No subscripting, so all indirection gets added to field list */
   18799     1614384 :     c->fields = lcons(makeString(colname), indirection);
   18800     1614384 :     return (Node *) c;
   18801             : }
   18802             : 
   18803             : static Node *
   18804      267086 : makeTypeCast(Node *arg, TypeName *typename, int location)
   18805             : {
   18806      267086 :     TypeCast   *n = makeNode(TypeCast);
   18807             : 
   18808      267086 :     n->arg = arg;
   18809      267086 :     n->typeName = typename;
   18810      267086 :     n->location = location;
   18811      267086 :     return (Node *) n;
   18812             : }
   18813             : 
   18814             : static Node *
   18815       16186 : makeStringConstCast(char *str, int location, TypeName *typename)
   18816             : {
   18817       16186 :     Node       *s = makeStringConst(str, location);
   18818             : 
   18819       16186 :     return makeTypeCast(s, typename, -1);
   18820             : }
   18821             : 
   18822             : static Node *
   18823      432358 : makeIntConst(int val, int location)
   18824             : {
   18825      432358 :     A_Const    *n = makeNode(A_Const);
   18826             : 
   18827      432358 :     n->val.ival.type = T_Integer;
   18828      432358 :     n->val.ival.ival = val;
   18829      432358 :     n->location = location;
   18830             : 
   18831      432358 :     return (Node *) n;
   18832             : }
   18833             : 
   18834             : static Node *
   18835       12022 : makeFloatConst(char *str, int location)
   18836             : {
   18837       12022 :     A_Const    *n = makeNode(A_Const);
   18838             : 
   18839       12022 :     n->val.fval.type = T_Float;
   18840       12022 :     n->val.fval.fval = str;
   18841       12022 :     n->location = location;
   18842             : 
   18843       12022 :     return (Node *) n;
   18844             : }
   18845             : 
   18846             : static Node *
   18847       56582 : makeBoolAConst(bool state, int location)
   18848             : {
   18849       56582 :     A_Const    *n = makeNode(A_Const);
   18850             : 
   18851       56582 :     n->val.boolval.type = T_Boolean;
   18852       56582 :     n->val.boolval.boolval = state;
   18853       56582 :     n->location = location;
   18854             : 
   18855       56582 :     return (Node *) n;
   18856             : }
   18857             : 
   18858             : static Node *
   18859        4056 : makeBitStringConst(char *str, int location)
   18860             : {
   18861        4056 :     A_Const    *n = makeNode(A_Const);
   18862             : 
   18863        4056 :     n->val.bsval.type = T_BitString;
   18864        4056 :     n->val.bsval.bsval = str;
   18865        4056 :     n->location = location;
   18866             : 
   18867        4056 :     return (Node *) n;
   18868             : }
   18869             : 
   18870             : static Node *
   18871       62048 : makeNullAConst(int location)
   18872             : {
   18873       62048 :     A_Const    *n = makeNode(A_Const);
   18874             : 
   18875       62048 :     n->isnull = true;
   18876       62048 :     n->location = location;
   18877             : 
   18878       62048 :     return (Node *) n;
   18879             : }
   18880             : 
   18881             : static Node *
   18882        4454 : makeAConst(Node *v, int location)
   18883             : {
   18884             :     Node       *n;
   18885             : 
   18886        4454 :     switch (v->type)
   18887             :     {
   18888         218 :         case T_Float:
   18889         218 :             n = makeFloatConst(castNode(Float, v)->fval, location);
   18890         218 :             break;
   18891             : 
   18892        4236 :         case T_Integer:
   18893        4236 :             n = makeIntConst(castNode(Integer, v)->ival, location);
   18894        4236 :             break;
   18895             : 
   18896           0 :         default:
   18897             :             /* currently not used */
   18898             :             Assert(false);
   18899           0 :             n = NULL;
   18900             :     }
   18901             : 
   18902        4454 :     return n;
   18903             : }
   18904             : 
   18905             : /* makeRoleSpec
   18906             :  * Create a RoleSpec with the given type
   18907             :  */
   18908             : static RoleSpec *
   18909       29980 : makeRoleSpec(RoleSpecType type, int location)
   18910             : {
   18911       29980 :     RoleSpec   *spec = makeNode(RoleSpec);
   18912             : 
   18913       29980 :     spec->roletype = type;
   18914       29980 :     spec->location = location;
   18915             : 
   18916       29980 :     return spec;
   18917             : }
   18918             : 
   18919             : /* check_qualified_name --- check the result of qualified_name production
   18920             :  *
   18921             :  * It's easiest to let the grammar production for qualified_name allow
   18922             :  * subscripts and '*', which we then must reject here.
   18923             :  */
   18924             : static void
   18925      224974 : check_qualified_name(List *names, core_yyscan_t yyscanner)
   18926             : {
   18927             :     ListCell   *i;
   18928             : 
   18929      449948 :     foreach(i, names)
   18930             :     {
   18931      224974 :         if (!IsA(lfirst(i), String))
   18932           0 :             parser_yyerror("syntax error");
   18933             :     }
   18934      224974 : }
   18935             : 
   18936             : /* check_func_name --- check the result of func_name production
   18937             :  *
   18938             :  * It's easiest to let the grammar production for func_name allow subscripts
   18939             :  * and '*', which we then must reject here.
   18940             :  */
   18941             : static List *
   18942      114888 : check_func_name(List *names, core_yyscan_t yyscanner)
   18943             : {
   18944             :     ListCell   *i;
   18945             : 
   18946      344664 :     foreach(i, names)
   18947             :     {
   18948      229776 :         if (!IsA(lfirst(i), String))
   18949           0 :             parser_yyerror("syntax error");
   18950             :     }
   18951      114888 :     return names;
   18952             : }
   18953             : 
   18954             : /* check_indirection --- check the result of indirection production
   18955             :  *
   18956             :  * We only allow '*' at the end of the list, but it's hard to enforce that
   18957             :  * in the grammar, so do it here.
   18958             :  */
   18959             : static List *
   18960       78686 : check_indirection(List *indirection, core_yyscan_t yyscanner)
   18961             : {
   18962             :     ListCell   *l;
   18963             : 
   18964      104446 :     foreach(l, indirection)
   18965             :     {
   18966       25760 :         if (IsA(lfirst(l), A_Star))
   18967             :         {
   18968        1342 :             if (lnext(indirection, l) != NULL)
   18969           0 :                 parser_yyerror("improper use of \"*\"");
   18970             :         }
   18971             :     }
   18972       78686 :     return indirection;
   18973             : }
   18974             : 
   18975             : /* extractArgTypes()
   18976             :  * Given a list of FunctionParameter nodes, extract a list of just the
   18977             :  * argument types (TypeNames) for input parameters only.  This is what
   18978             :  * is needed to look up an existing function, which is what is wanted by
   18979             :  * the productions that use this call.
   18980             :  */
   18981             : static List *
   18982       14640 : extractArgTypes(List *parameters)
   18983             : {
   18984       14640 :     List       *result = NIL;
   18985             :     ListCell   *i;
   18986             : 
   18987       32188 :     foreach(i, parameters)
   18988             :     {
   18989       17548 :         FunctionParameter *p = (FunctionParameter *) lfirst(i);
   18990             : 
   18991       17548 :         if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
   18992       17392 :             result = lappend(result, p->argType);
   18993             :     }
   18994       14640 :     return result;
   18995             : }
   18996             : 
   18997             : /* extractAggrArgTypes()
   18998             :  * As above, but work from the output of the aggr_args production.
   18999             :  */
   19000             : static List *
   19001         362 : extractAggrArgTypes(List *aggrargs)
   19002             : {
   19003             :     Assert(list_length(aggrargs) == 2);
   19004         362 :     return extractArgTypes((List *) linitial(aggrargs));
   19005             : }
   19006             : 
   19007             : /* makeOrderedSetArgs()
   19008             :  * Build the result of the aggr_args production (which see the comments for).
   19009             :  * This handles only the case where both given lists are nonempty, so that
   19010             :  * we have to deal with multiple VARIADIC arguments.
   19011             :  */
   19012             : static List *
   19013          32 : makeOrderedSetArgs(List *directargs, List *orderedargs,
   19014             :                    core_yyscan_t yyscanner)
   19015             : {
   19016          32 :     FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
   19017             :     Integer    *ndirectargs;
   19018             : 
   19019             :     /* No restriction unless last direct arg is VARIADIC */
   19020          32 :     if (lastd->mode == FUNC_PARAM_VARIADIC)
   19021             :     {
   19022          16 :         FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
   19023             : 
   19024             :         /*
   19025             :          * We ignore the names, though the aggr_arg production allows them; it
   19026             :          * doesn't allow default values, so those need not be checked.
   19027             :          */
   19028          16 :         if (list_length(orderedargs) != 1 ||
   19029          16 :             firsto->mode != FUNC_PARAM_VARIADIC ||
   19030          16 :             !equal(lastd->argType, firsto->argType))
   19031           0 :             ereport(ERROR,
   19032             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19033             :                      errmsg("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
   19034             :                      parser_errposition(firsto->location)));
   19035             : 
   19036             :         /* OK, drop the duplicate VARIADIC argument from the internal form */
   19037          16 :         orderedargs = NIL;
   19038             :     }
   19039             : 
   19040             :     /* don't merge into the next line, as list_concat changes directargs */
   19041          32 :     ndirectargs = makeInteger(list_length(directargs));
   19042             : 
   19043          32 :     return list_make2(list_concat(directargs, orderedargs),
   19044             :                       ndirectargs);
   19045             : }
   19046             : 
   19047             : /* insertSelectOptions()
   19048             :  * Insert ORDER BY, etc into an already-constructed SelectStmt.
   19049             :  *
   19050             :  * This routine is just to avoid duplicating code in SelectStmt productions.
   19051             :  */
   19052             : static void
   19053       72516 : insertSelectOptions(SelectStmt *stmt,
   19054             :                     List *sortClause, List *lockingClause,
   19055             :                     SelectLimit *limitClause,
   19056             :                     WithClause *withClause,
   19057             :                     core_yyscan_t yyscanner)
   19058             : {
   19059             :     Assert(IsA(stmt, SelectStmt));
   19060             : 
   19061             :     /*
   19062             :      * Tests here are to reject constructs like
   19063             :      *  (SELECT foo ORDER BY bar) ORDER BY baz
   19064             :      */
   19065       72516 :     if (sortClause)
   19066             :     {
   19067       63446 :         if (stmt->sortClause)
   19068           0 :             ereport(ERROR,
   19069             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19070             :                      errmsg("multiple ORDER BY clauses not allowed"),
   19071             :                      parser_errposition(exprLocation((Node *) sortClause))));
   19072       63446 :         stmt->sortClause = sortClause;
   19073             :     }
   19074             :     /* We can handle multiple locking clauses, though */
   19075       72516 :     stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
   19076       72516 :     if (limitClause && limitClause->limitOffset)
   19077             :     {
   19078         756 :         if (stmt->limitOffset)
   19079           0 :             ereport(ERROR,
   19080             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19081             :                      errmsg("multiple OFFSET clauses not allowed"),
   19082             :                      parser_errposition(limitClause->offsetLoc)));
   19083         756 :         stmt->limitOffset = limitClause->limitOffset;
   19084             :     }
   19085       72516 :     if (limitClause && limitClause->limitCount)
   19086             :     {
   19087        4576 :         if (stmt->limitCount)
   19088           0 :             ereport(ERROR,
   19089             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19090             :                      errmsg("multiple LIMIT clauses not allowed"),
   19091             :                      parser_errposition(limitClause->countLoc)));
   19092        4576 :         stmt->limitCount = limitClause->limitCount;
   19093             :     }
   19094       72516 :     if (limitClause)
   19095             :     {
   19096             :         /* If there was a conflict, we must have detected it above */
   19097             :         Assert(!stmt->limitOption);
   19098        4950 :         if (!stmt->sortClause && limitClause->limitOption == LIMIT_OPTION_WITH_TIES)
   19099           6 :             ereport(ERROR,
   19100             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19101             :                      errmsg("WITH TIES cannot be specified without ORDER BY clause"),
   19102             :                      parser_errposition(limitClause->optionLoc)));
   19103        4944 :         if (limitClause->limitOption == LIMIT_OPTION_WITH_TIES && stmt->lockingClause)
   19104             :         {
   19105             :             ListCell   *lc;
   19106             : 
   19107           6 :             foreach(lc, stmt->lockingClause)
   19108             :             {
   19109           6 :                 LockingClause *lock = lfirst_node(LockingClause, lc);
   19110             : 
   19111           6 :                 if (lock->waitPolicy == LockWaitSkip)
   19112           6 :                     ereport(ERROR,
   19113             :                             (errcode(ERRCODE_SYNTAX_ERROR),
   19114             :                              errmsg("%s and %s options cannot be used together",
   19115             :                                     "SKIP LOCKED", "WITH TIES"),
   19116             :                              parser_errposition(limitClause->optionLoc)));
   19117             :             }
   19118             :         }
   19119        4938 :         stmt->limitOption = limitClause->limitOption;
   19120             :     }
   19121       72504 :     if (withClause)
   19122             :     {
   19123        2502 :         if (stmt->withClause)
   19124           0 :             ereport(ERROR,
   19125             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19126             :                      errmsg("multiple WITH clauses not allowed"),
   19127             :                      parser_errposition(exprLocation((Node *) withClause))));
   19128        2502 :         stmt->withClause = withClause;
   19129             : 
   19130             :         /* Update SelectStmt's location to the start of the WITH clause */
   19131        2502 :         stmt->stmt_location = withClause->location;
   19132             :     }
   19133       72504 : }
   19134             : 
   19135             : static Node *
   19136       14988 : makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg, int location)
   19137             : {
   19138       14988 :     SelectStmt *n = makeNode(SelectStmt);
   19139             : 
   19140       14988 :     n->op = op;
   19141       14988 :     n->all = all;
   19142       14988 :     n->larg = (SelectStmt *) larg;
   19143       14988 :     n->rarg = (SelectStmt *) rarg;
   19144       14988 :     n->stmt_location = location;
   19145       14988 :     return (Node *) n;
   19146             : }
   19147             : 
   19148             : /* SystemFuncName()
   19149             :  * Build a properly-qualified reference to a built-in function.
   19150             :  */
   19151             : List *
   19152       17550 : SystemFuncName(char *name)
   19153             : {
   19154       17550 :     return list_make2(makeString("pg_catalog"), makeString(name));
   19155             : }
   19156             : 
   19157             : /* SystemTypeName()
   19158             :  * Build a properly-qualified reference to a built-in type.
   19159             :  *
   19160             :  * typmod is defaulted, but may be changed afterwards by caller.
   19161             :  * Likewise for the location.
   19162             :  */
   19163             : TypeName *
   19164       96942 : SystemTypeName(char *name)
   19165             : {
   19166       96942 :     return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
   19167             :                                                makeString(name)));
   19168             : }
   19169             : 
   19170             : /* doNegate()
   19171             :  * Handle negation of a numeric constant.
   19172             :  *
   19173             :  * Formerly, we did this here because the optimizer couldn't cope with
   19174             :  * indexquals that looked like "var = -4" --- it wants "var = const"
   19175             :  * and a unary minus operator applied to a constant didn't qualify.
   19176             :  * As of Postgres 7.0, that problem doesn't exist anymore because there
   19177             :  * is a constant-subexpression simplifier in the optimizer.  However,
   19178             :  * there's still a good reason for doing this here, which is that we can
   19179             :  * postpone committing to a particular internal representation for simple
   19180             :  * negative constants.  It's better to leave "-123.456" in string form
   19181             :  * until we know what the desired type is.
   19182             :  */
   19183             : static Node *
   19184       27894 : doNegate(Node *n, int location)
   19185             : {
   19186       27894 :     if (IsA(n, A_Const))
   19187             :     {
   19188       26662 :         A_Const    *con = (A_Const *) n;
   19189             : 
   19190             :         /* report the constant's location as that of the '-' sign */
   19191       26662 :         con->location = location;
   19192             : 
   19193       26662 :         if (IsA(&con->val, Integer))
   19194             :         {
   19195       25710 :             con->val.ival.ival = -con->val.ival.ival;
   19196       25710 :             return n;
   19197             :         }
   19198         952 :         if (IsA(&con->val, Float))
   19199             :         {
   19200         952 :             doNegateFloat(&con->val.fval);
   19201         952 :             return n;
   19202             :         }
   19203             :     }
   19204             : 
   19205        1232 :     return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
   19206             : }
   19207             : 
   19208             : static void
   19209         972 : doNegateFloat(Float *v)
   19210             : {
   19211         972 :     char       *oldval = v->fval;
   19212             : 
   19213         972 :     if (*oldval == '+')
   19214           0 :         oldval++;
   19215         972 :     if (*oldval == '-')
   19216           0 :         v->fval = oldval + 1;    /* just strip the '-' */
   19217             :     else
   19218         972 :         v->fval = psprintf("-%s", oldval);
   19219         972 : }
   19220             : 
   19221             : static Node *
   19222      212974 : makeAndExpr(Node *lexpr, Node *rexpr, int location)
   19223             : {
   19224             :     /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
   19225      212974 :     if (IsA(lexpr, BoolExpr))
   19226             :     {
   19227       99706 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   19228             : 
   19229       99706 :         if (blexpr->boolop == AND_EXPR)
   19230             :         {
   19231       97348 :             blexpr->args = lappend(blexpr->args, rexpr);
   19232       97348 :             return (Node *) blexpr;
   19233             :         }
   19234             :     }
   19235      115626 :     return (Node *) makeBoolExpr(AND_EXPR, list_make2(lexpr, rexpr), location);
   19236             : }
   19237             : 
   19238             : static Node *
   19239       15858 : makeOrExpr(Node *lexpr, Node *rexpr, int location)
   19240             : {
   19241             :     /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
   19242       15858 :     if (IsA(lexpr, BoolExpr))
   19243             :     {
   19244        6538 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   19245             : 
   19246        6538 :         if (blexpr->boolop == OR_EXPR)
   19247             :         {
   19248        3692 :             blexpr->args = lappend(blexpr->args, rexpr);
   19249        3692 :             return (Node *) blexpr;
   19250             :         }
   19251             :     }
   19252       12166 :     return (Node *) makeBoolExpr(OR_EXPR, list_make2(lexpr, rexpr), location);
   19253             : }
   19254             : 
   19255             : static Node *
   19256       14312 : makeNotExpr(Node *expr, int location)
   19257             : {
   19258       14312 :     return (Node *) makeBoolExpr(NOT_EXPR, list_make1(expr), location);
   19259             : }
   19260             : 
   19261             : static Node *
   19262        7882 : makeAArrayExpr(List *elements, int location)
   19263             : {
   19264        7882 :     A_ArrayExpr *n = makeNode(A_ArrayExpr);
   19265             : 
   19266        7882 :     n->elements = elements;
   19267        7882 :     n->location = location;
   19268        7882 :     return (Node *) n;
   19269             : }
   19270             : 
   19271             : static Node *
   19272        2682 : makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod, int location)
   19273             : {
   19274        2682 :     SQLValueFunction *svf = makeNode(SQLValueFunction);
   19275             : 
   19276        2682 :     svf->op = op;
   19277             :     /* svf->type will be filled during parse analysis */
   19278        2682 :     svf->typmod = typmod;
   19279        2682 :     svf->location = location;
   19280        2682 :     return (Node *) svf;
   19281             : }
   19282             : 
   19283             : static Node *
   19284         596 : makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
   19285             :             int location)
   19286             : {
   19287         596 :     XmlExpr    *x = makeNode(XmlExpr);
   19288             : 
   19289         596 :     x->op = op;
   19290         596 :     x->name = name;
   19291             : 
   19292             :     /*
   19293             :      * named_args is a list of ResTarget; it'll be split apart into separate
   19294             :      * expression and name lists in transformXmlExpr().
   19295             :      */
   19296         596 :     x->named_args = named_args;
   19297         596 :     x->arg_names = NIL;
   19298         596 :     x->args = args;
   19299             :     /* xmloption, if relevant, must be filled in by caller */
   19300             :     /* type and typmod will be filled in during parse analysis */
   19301         596 :     x->type = InvalidOid;        /* marks the node as not analyzed */
   19302         596 :     x->location = location;
   19303         596 :     return (Node *) x;
   19304             : }
   19305             : 
   19306             : /*
   19307             :  * Merge the input and output parameters of a table function.
   19308             :  */
   19309             : static List *
   19310         188 : mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner)
   19311             : {
   19312             :     ListCell   *lc;
   19313             : 
   19314             :     /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
   19315         382 :     foreach(lc, func_args)
   19316             :     {
   19317         194 :         FunctionParameter *p = (FunctionParameter *) lfirst(lc);
   19318             : 
   19319         194 :         if (p->mode != FUNC_PARAM_DEFAULT &&
   19320           0 :             p->mode != FUNC_PARAM_IN &&
   19321           0 :             p->mode != FUNC_PARAM_VARIADIC)
   19322           0 :             ereport(ERROR,
   19323             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19324             :                      errmsg("OUT and INOUT arguments aren't allowed in TABLE functions"),
   19325             :                      parser_errposition(p->location)));
   19326             :     }
   19327             : 
   19328         188 :     return list_concat(func_args, columns);
   19329             : }
   19330             : 
   19331             : /*
   19332             :  * Determine return type of a TABLE function.  A single result column
   19333             :  * returns setof that column's type; otherwise return setof record.
   19334             :  */
   19335             : static TypeName *
   19336         188 : TableFuncTypeName(List *columns)
   19337             : {
   19338             :     TypeName   *result;
   19339             : 
   19340         188 :     if (list_length(columns) == 1)
   19341             :     {
   19342          62 :         FunctionParameter *p = (FunctionParameter *) linitial(columns);
   19343             : 
   19344          62 :         result = copyObject(p->argType);
   19345             :     }
   19346             :     else
   19347         126 :         result = SystemTypeName("record");
   19348             : 
   19349         188 :     result->setof = true;
   19350             : 
   19351         188 :     return result;
   19352             : }
   19353             : 
   19354             : /*
   19355             :  * Convert a list of (dotted) names to a RangeVar (like
   19356             :  * makeRangeVarFromNameList, but with position support).  The
   19357             :  * "AnyName" refers to the any_name production in the grammar.
   19358             :  */
   19359             : static RangeVar *
   19360        3718 : makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
   19361             : {
   19362        3718 :     RangeVar   *r = makeNode(RangeVar);
   19363             : 
   19364        3718 :     switch (list_length(names))
   19365             :     {
   19366        3628 :         case 1:
   19367        3628 :             r->catalogname = NULL;
   19368        3628 :             r->schemaname = NULL;
   19369        3628 :             r->relname = strVal(linitial(names));
   19370        3628 :             break;
   19371          90 :         case 2:
   19372          90 :             r->catalogname = NULL;
   19373          90 :             r->schemaname = strVal(linitial(names));
   19374          90 :             r->relname = strVal(lsecond(names));
   19375          90 :             break;
   19376           0 :         case 3:
   19377           0 :             r->catalogname = strVal(linitial(names));
   19378           0 :             r->schemaname = strVal(lsecond(names));
   19379           0 :             r->relname = strVal(lthird(names));
   19380           0 :             break;
   19381           0 :         default:
   19382           0 :             ereport(ERROR,
   19383             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19384             :                      errmsg("improper qualified name (too many dotted names): %s",
   19385             :                             NameListToString(names)),
   19386             :                      parser_errposition(position)));
   19387             :             break;
   19388             :     }
   19389             : 
   19390        3718 :     r->relpersistence = RELPERSISTENCE_PERMANENT;
   19391        3718 :     r->location = position;
   19392             : 
   19393        3718 :     return r;
   19394             : }
   19395             : 
   19396             : /*
   19397             :  * Convert a relation_name with name and namelist to a RangeVar using
   19398             :  * makeRangeVar.
   19399             :  */
   19400             : static RangeVar *
   19401      224974 : makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
   19402             :                               core_yyscan_t yyscanner)
   19403             : {
   19404             :     RangeVar   *r;
   19405             : 
   19406      224974 :     check_qualified_name(namelist, yyscanner);
   19407      224974 :     r = makeRangeVar(NULL, NULL, location);
   19408             : 
   19409      224974 :     switch (list_length(namelist))
   19410             :     {
   19411      224974 :         case 1:
   19412      224974 :             r->catalogname = NULL;
   19413      224974 :             r->schemaname = name;
   19414      224974 :             r->relname = strVal(linitial(namelist));
   19415      224974 :             break;
   19416           0 :         case 2:
   19417           0 :             r->catalogname = name;
   19418           0 :             r->schemaname = strVal(linitial(namelist));
   19419           0 :             r->relname = strVal(lsecond(namelist));
   19420           0 :             break;
   19421           0 :         default:
   19422           0 :             ereport(ERROR,
   19423             :                     errcode(ERRCODE_SYNTAX_ERROR),
   19424             :                     errmsg("improper qualified name (too many dotted names): %s",
   19425             :                            NameListToString(lcons(makeString(name), namelist))),
   19426             :                     parser_errposition(location));
   19427             :             break;
   19428             :     }
   19429             : 
   19430      224974 :     return r;
   19431             : }
   19432             : 
   19433             : /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
   19434             : static void
   19435       65248 : SplitColQualList(List *qualList,
   19436             :                  List **constraintList, CollateClause **collClause,
   19437             :                  core_yyscan_t yyscanner)
   19438             : {
   19439             :     ListCell   *cell;
   19440             : 
   19441       65248 :     *collClause = NULL;
   19442       83074 :     foreach(cell, qualList)
   19443             :     {
   19444       17826 :         Node       *n = (Node *) lfirst(cell);
   19445             : 
   19446       17826 :         if (IsA(n, Constraint))
   19447             :         {
   19448             :             /* keep it in list */
   19449       17096 :             continue;
   19450             :         }
   19451         730 :         if (IsA(n, CollateClause))
   19452             :         {
   19453         730 :             CollateClause *c = (CollateClause *) n;
   19454             : 
   19455         730 :             if (*collClause)
   19456           0 :                 ereport(ERROR,
   19457             :                         (errcode(ERRCODE_SYNTAX_ERROR),
   19458             :                          errmsg("multiple COLLATE clauses not allowed"),
   19459             :                          parser_errposition(c->location)));
   19460         730 :             *collClause = c;
   19461             :         }
   19462             :         else
   19463           0 :             elog(ERROR, "unexpected node type %d", (int) n->type);
   19464             :         /* remove non-Constraint nodes from qualList */
   19465         730 :         qualList = foreach_delete_current(qualList, cell);
   19466             :     }
   19467       65248 :     *constraintList = qualList;
   19468       65248 : }
   19469             : 
   19470             : /*
   19471             :  * Process result of ConstraintAttributeSpec, and set appropriate bool flags
   19472             :  * in the output command node.  Pass NULL for any flags the particular
   19473             :  * command doesn't support.
   19474             :  */
   19475             : static void
   19476       16130 : processCASbits(int cas_bits, int location, const char *constrType,
   19477             :                bool *deferrable, bool *initdeferred, bool *is_enforced,
   19478             :                bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner)
   19479             : {
   19480             :     /* defaults */
   19481       16130 :     if (deferrable)
   19482       14400 :         *deferrable = false;
   19483       16130 :     if (initdeferred)
   19484       14400 :         *initdeferred = false;
   19485       16130 :     if (not_valid)
   19486        3064 :         *not_valid = false;
   19487       16130 :     if (is_enforced)
   19488        1158 :         *is_enforced = true;
   19489             : 
   19490       16130 :     if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
   19491             :     {
   19492         240 :         if (deferrable)
   19493         240 :             *deferrable = true;
   19494             :         else
   19495           0 :             ereport(ERROR,
   19496             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19497             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19498             :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   19499             :                             constrType),
   19500             :                      parser_errposition(location)));
   19501             :     }
   19502             : 
   19503       16130 :     if (cas_bits & CAS_INITIALLY_DEFERRED)
   19504             :     {
   19505         156 :         if (initdeferred)
   19506         156 :             *initdeferred = true;
   19507             :         else
   19508           0 :             ereport(ERROR,
   19509             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19510             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19511             :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   19512             :                             constrType),
   19513             :                      parser_errposition(location)));
   19514             :     }
   19515             : 
   19516       16130 :     if (cas_bits & CAS_NOT_VALID)
   19517             :     {
   19518         516 :         if (not_valid)
   19519         516 :             *not_valid = true;
   19520             :         else
   19521           0 :             ereport(ERROR,
   19522             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19523             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19524             :                      errmsg("%s constraints cannot be marked NOT VALID",
   19525             :                             constrType),
   19526             :                      parser_errposition(location)));
   19527             :     }
   19528             : 
   19529       16130 :     if (cas_bits & CAS_NO_INHERIT)
   19530             :     {
   19531         190 :         if (no_inherit)
   19532         190 :             *no_inherit = true;
   19533             :         else
   19534           0 :             ereport(ERROR,
   19535             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19536             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19537             :                      errmsg("%s constraints cannot be marked NO INHERIT",
   19538             :                             constrType),
   19539             :                      parser_errposition(location)));
   19540             :     }
   19541             : 
   19542       16130 :     if (cas_bits & CAS_NOT_ENFORCED)
   19543             :     {
   19544          84 :         if (is_enforced)
   19545          72 :             *is_enforced = false;
   19546             :         else
   19547          12 :             ereport(ERROR,
   19548             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19549             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19550             :                      errmsg("%s constraints cannot be marked NOT ENFORCED",
   19551             :                             constrType),
   19552             :                      parser_errposition(location)));
   19553             : 
   19554             :         /*
   19555             :          * NB: The validated status is irrelevant when the constraint is set to
   19556             :          * NOT ENFORCED, but for consistency, it should be set accordingly.
   19557             :          * This ensures that if the constraint is later changed to ENFORCED, it
   19558             :          * will automatically be in the correct NOT VALIDATED state.
   19559             :          */
   19560          72 :         if (not_valid)
   19561          72 :             *not_valid = true;
   19562             :     }
   19563             : 
   19564       16118 :     if (cas_bits & CAS_ENFORCED)
   19565             :     {
   19566          42 :         if (is_enforced)
   19567          30 :             *is_enforced = true;
   19568             :         else
   19569          12 :             ereport(ERROR,
   19570             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19571             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19572             :                      errmsg("%s constraints cannot be marked ENFORCED",
   19573             :                             constrType),
   19574             :                      parser_errposition(location)));
   19575             :     }
   19576       16106 : }
   19577             : 
   19578             : /*
   19579             :  * Parse a user-supplied partition strategy string into parse node
   19580             :  * PartitionStrategy representation, or die trying.
   19581             :  */
   19582             : static PartitionStrategy
   19583        4820 : parsePartitionStrategy(char *strategy, int location, core_yyscan_t yyscanner)
   19584             : {
   19585        4820 :     if (pg_strcasecmp(strategy, "list") == 0)
   19586        2466 :         return PARTITION_STRATEGY_LIST;
   19587        2354 :     else if (pg_strcasecmp(strategy, "range") == 0)
   19588        2108 :         return PARTITION_STRATEGY_RANGE;
   19589         246 :     else if (pg_strcasecmp(strategy, "hash") == 0)
   19590         240 :         return PARTITION_STRATEGY_HASH;
   19591             : 
   19592           6 :     ereport(ERROR,
   19593             :             (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   19594             :              errmsg("unrecognized partitioning strategy \"%s\"", strategy),
   19595             :              parser_errposition(location)));
   19596             :     return PARTITION_STRATEGY_LIST; /* keep compiler quiet */
   19597             : 
   19598             : }
   19599             : 
   19600             : /*
   19601             :  * Process pubobjspec_list to check for errors in any of the objects and
   19602             :  * convert PUBLICATIONOBJ_CONTINUATION into appropriate PublicationObjSpecType.
   19603             :  */
   19604             : static void
   19605        1540 : preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
   19606             : {
   19607             :     ListCell   *cell;
   19608             :     PublicationObjSpec *pubobj;
   19609        1540 :     PublicationObjSpecType prevobjtype = PUBLICATIONOBJ_CONTINUATION;
   19610             : 
   19611        1540 :     if (!pubobjspec_list)
   19612           0 :         return;
   19613             : 
   19614        1540 :     pubobj = (PublicationObjSpec *) linitial(pubobjspec_list);
   19615        1540 :     if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   19616          12 :         ereport(ERROR,
   19617             :                 errcode(ERRCODE_SYNTAX_ERROR),
   19618             :                 errmsg("invalid publication object list"),
   19619             :                 errdetail("One of TABLE or TABLES IN SCHEMA must be specified before a standalone table or schema name."),
   19620             :                 parser_errposition(pubobj->location));
   19621             : 
   19622        3254 :     foreach(cell, pubobjspec_list)
   19623             :     {
   19624        1750 :         pubobj = (PublicationObjSpec *) lfirst(cell);
   19625             : 
   19626        1750 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   19627         172 :             pubobj->pubobjtype = prevobjtype;
   19628             : 
   19629        1750 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE)
   19630             :         {
   19631             :             /* relation name or pubtable must be set for this type of object */
   19632        1346 :             if (!pubobj->name && !pubobj->pubtable)
   19633           6 :                 ereport(ERROR,
   19634             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19635             :                         errmsg("invalid table name"),
   19636             :                         parser_errposition(pubobj->location));
   19637             : 
   19638        1340 :             if (pubobj->name)
   19639             :             {
   19640             :                 /* convert it to PublicationTable */
   19641          56 :                 PublicationTable *pubtable = makeNode(PublicationTable);
   19642             : 
   19643          56 :                 pubtable->relation =
   19644          56 :                     makeRangeVar(NULL, pubobj->name, pubobj->location);
   19645          56 :                 pubobj->pubtable = pubtable;
   19646          56 :                 pubobj->name = NULL;
   19647             :             }
   19648             :         }
   19649         404 :         else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
   19650          24 :                  pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA)
   19651             :         {
   19652             :             /* WHERE clause is not allowed on a schema object */
   19653         404 :             if (pubobj->pubtable && pubobj->pubtable->whereClause)
   19654           6 :                 ereport(ERROR,
   19655             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19656             :                         errmsg("WHERE clause not allowed for schema"),
   19657             :                         parser_errposition(pubobj->location));
   19658             : 
   19659             :             /* Column list is not allowed on a schema object */
   19660         398 :             if (pubobj->pubtable && pubobj->pubtable->columns)
   19661           6 :                 ereport(ERROR,
   19662             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19663             :                         errmsg("column specification not allowed for schema"),
   19664             :                         parser_errposition(pubobj->location));
   19665             : 
   19666             :             /*
   19667             :              * We can distinguish between the different type of schema objects
   19668             :              * based on whether name and pubtable is set.
   19669             :              */
   19670         392 :             if (pubobj->name)
   19671         362 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   19672          30 :             else if (!pubobj->name && !pubobj->pubtable)
   19673          24 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   19674             :             else
   19675           6 :                 ereport(ERROR,
   19676             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19677             :                         errmsg("invalid schema name"),
   19678             :                         parser_errposition(pubobj->location));
   19679             :         }
   19680             : 
   19681        1726 :         prevobjtype = pubobj->pubobjtype;
   19682             :     }
   19683             : }
   19684             : 
   19685             : /*----------
   19686             :  * Recursive view transformation
   19687             :  *
   19688             :  * Convert
   19689             :  *
   19690             :  *     CREATE RECURSIVE VIEW relname (aliases) AS query
   19691             :  *
   19692             :  * to
   19693             :  *
   19694             :  *     CREATE VIEW relname (aliases) AS
   19695             :  *         WITH RECURSIVE relname (aliases) AS (query)
   19696             :  *         SELECT aliases FROM relname
   19697             :  *
   19698             :  * Actually, just the WITH ... part, which is then inserted into the original
   19699             :  * view definition as the query.
   19700             :  * ----------
   19701             :  */
   19702             : static Node *
   19703          14 : makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
   19704             : {
   19705          14 :     SelectStmt *s = makeNode(SelectStmt);
   19706          14 :     WithClause *w = makeNode(WithClause);
   19707          14 :     CommonTableExpr *cte = makeNode(CommonTableExpr);
   19708          14 :     List       *tl = NIL;
   19709             :     ListCell   *lc;
   19710             : 
   19711             :     /* create common table expression */
   19712          14 :     cte->ctename = relname;
   19713          14 :     cte->aliascolnames = aliases;
   19714          14 :     cte->ctematerialized = CTEMaterializeDefault;
   19715          14 :     cte->ctequery = query;
   19716          14 :     cte->location = -1;
   19717             : 
   19718             :     /* create WITH clause and attach CTE */
   19719          14 :     w->recursive = true;
   19720          14 :     w->ctes = list_make1(cte);
   19721          14 :     w->location = -1;
   19722             : 
   19723             :     /*
   19724             :      * create target list for the new SELECT from the alias list of the
   19725             :      * recursive view specification
   19726             :      */
   19727          28 :     foreach(lc, aliases)
   19728             :     {
   19729          14 :         ResTarget  *rt = makeNode(ResTarget);
   19730             : 
   19731          14 :         rt->name = NULL;
   19732          14 :         rt->indirection = NIL;
   19733          14 :         rt->val = makeColumnRef(strVal(lfirst(lc)), NIL, -1, 0);
   19734          14 :         rt->location = -1;
   19735             : 
   19736          14 :         tl = lappend(tl, rt);
   19737             :     }
   19738             : 
   19739             :     /*
   19740             :      * create new SELECT combining WITH clause, target list, and fake FROM
   19741             :      * clause
   19742             :      */
   19743          14 :     s->withClause = w;
   19744          14 :     s->targetList = tl;
   19745          14 :     s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));
   19746             : 
   19747          14 :     return (Node *) s;
   19748             : }
   19749             : 
   19750             : /* parser_init()
   19751             :  * Initialize to parse one query string
   19752             :  */
   19753             : void
   19754      758126 : parser_init(base_yy_extra_type *yyext)
   19755             : {
   19756      758126 :     yyext->parsetree = NIL;      /* in case grammar forgets to set it */
   19757      758126 : }

Generated by: LCOV version 1.14